ThinPatchesActivity.java revision 1e59f9d10d164f156221f6d34b932f06cdd29f1f
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.Bitmap;
22import android.graphics.Canvas;
23import android.graphics.Rect;
24import android.graphics.RectF;
25import android.graphics.drawable.Drawable;
26import android.os.Bundle;
27import android.view.View;
28import android.widget.FrameLayout;
29
30@SuppressWarnings({"UnusedDeclaration"})
31public class ThinPatchesActivity extends Activity {
32    @Override
33    protected void onCreate(Bundle savedInstanceState) {
34        super.onCreate(savedInstanceState);
35
36        FrameLayout layout = new FrameLayout(this);
37        PatchView b = new PatchView(this);
38        b.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
39                FrameLayout.LayoutParams.MATCH_PARENT));
40        layout.addView(b);
41        layout.setBackgroundColor(0xffffffff);
42
43        setContentView(layout);
44    }
45
46    private class PatchView extends View {
47        private Drawable mPatch1, mPatch2;
48        private Bitmap mTexture;
49
50        public PatchView(Activity activity) {
51            super(activity);
52
53            final Resources resources = activity.getResources();
54            mPatch1 = resources.getDrawable(R.drawable.patch);
55            mPatch2 = resources.getDrawable(R.drawable.btn_toggle_on);
56
57            mTexture = Bitmap.createBitmap(4, 3, Bitmap.Config.ARGB_8888);
58            mTexture.setPixel(0, 0, 0xffff0000);
59            mTexture.setPixel(1, 0, 0xffffffff);
60            mTexture.setPixel(2, 0, 0xff000000);
61            mTexture.setPixel(3, 0, 0xffff0000);
62            mTexture.setPixel(0, 1, 0xffff0000);
63            mTexture.setPixel(1, 1, 0xff000000);
64            mTexture.setPixel(2, 1, 0xffffffff);
65            mTexture.setPixel(3, 1, 0xffff0000);
66            mTexture.setPixel(0, 2, 0xffff0000);
67            mTexture.setPixel(1, 2, 0xffff0000);
68            mTexture.setPixel(2, 2, 0xffff0000);
69            mTexture.setPixel(3, 2, 0xffff0000);
70        }
71
72        @Override
73        protected void onDraw(Canvas canvas) {
74            final int width = 100;
75            final int height = 60;
76
77            final int left = (getWidth() - width) / 2;
78            final int top  = (getHeight() - height) / 2;
79
80            mPatch1.setBounds(left, top, left + width, top + height);
81            mPatch1.draw(canvas);
82
83            canvas.save();
84            canvas.translate(0.0f, height + 20.0f);
85
86            mPatch2.setBounds(left, top, left + width, top + height);
87            mPatch2.draw(canvas);
88
89            canvas.restore();
90
91//            Rect src = new Rect(1, 0, 3, 2);
92//            RectF dst = new RectF(0, 0, getWidth(), getHeight());
93//            canvas.drawBitmap(mTexture, src, dst, null);
94        }
95    }
96}
97