ThinPatchesActivity.java revision 6820ac8b14b4558f5d8b833dde80895306a3e137
1/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.test.hwui;
18
19import android.app.Activity;
20import android.content.res.Resources;
21import android.graphics.Canvas;
22import android.graphics.drawable.Drawable;
23import android.os.Bundle;
24import android.view.View;
25import android.widget.FrameLayout;
26
27@SuppressWarnings({"UnusedDeclaration"})
28public class ThinPatchesActivity extends Activity {
29    @Override
30    protected void onCreate(Bundle savedInstanceState) {
31        super.onCreate(savedInstanceState);
32
33        FrameLayout layout = new FrameLayout(this);
34        PatchView b = new PatchView(this);
35        b.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
36                FrameLayout.LayoutParams.MATCH_PARENT));
37        layout.addView(b);
38        layout.setBackgroundColor(0xffffffff);
39
40        setContentView(layout);
41    }
42
43    private class PatchView extends View {
44        private Drawable mPatch1, mPatch2;
45
46        public PatchView(Activity activity) {
47            super(activity);
48
49            final Resources resources = activity.getResources();
50            mPatch1 = resources.getDrawable(R.drawable.patch);
51            mPatch2 = resources.getDrawable(R.drawable.btn_toggle_on);
52        }
53
54        @Override
55        protected void onDraw(Canvas canvas) {
56            final int width = 100;
57            final int height = 60;
58
59            final int left = (getWidth() - width) / 2;
60            final int top  = (getHeight() - height) / 2;
61
62            mPatch1.setBounds(left, top, left + width, top + height);
63            mPatch1.draw(canvas);
64
65            canvas.translate(0.0f, height + 20.0f);
66
67            mPatch2.setBounds(left, top, left + width, top + height);
68            mPatch2.draw(canvas);
69        }
70    }
71}
72