116d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount/*
216d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * Copyright (C) 2010 The Android Open Source Project
316d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount *
416d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * Licensed under the Apache License, Version 2.0 (the "License");
516d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * you may not use this file except in compliance with the License.
616d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * You may obtain a copy of the License at
716d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount *
816d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount *      http://www.apache.org/licenses/LICENSE-2.0
916d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount *
1016d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * Unless required by applicable law or agreed to in writing, software
1116d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * distributed under the License is distributed on an "AS IS" BASIS,
1216d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1316d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * See the License for the specific language governing permissions and
1416d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * limitations under the License.
1516d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount */
1616d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount
1716d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mountpackage com.android.test.hwui;
1816d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount
1916d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mountimport android.app.Activity;
2016d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mountimport android.content.Context;
2116d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mountimport android.graphics.Bitmap;
2216d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mountimport android.graphics.BitmapFactory;
2316d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mountimport android.graphics.Canvas;
2416d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mountimport android.graphics.Paint;
2516d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mountimport android.graphics.PorterDuff;
2616d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mountimport android.graphics.PorterDuffXfermode;
2716d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mountimport android.os.Bundle;
2816d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mountimport android.util.Log;
2916d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mountimport android.view.Gravity;
3016d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mountimport android.view.View;
3116d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mountimport android.view.animation.Animation;
3216d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mountimport android.view.animation.ScaleAnimation;
3316d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mountimport android.widget.FrameLayout;
3416d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount
3516d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount@SuppressWarnings({"UnusedDeclaration"})
3616d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mountpublic class BitmapsActivity extends Activity {
3716d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount    @Override
3816d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount    protected void onCreate(Bundle savedInstanceState) {
3916d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount        super.onCreate(savedInstanceState);
4016d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount        final BitmapsView view = new BitmapsView(this);
4116d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount        final FrameLayout layout = new FrameLayout(this);
4216d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount        layout.addView(view, new FrameLayout.LayoutParams(480, 800, Gravity.CENTER));
4316d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount        setContentView(layout);
4416d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount
4516d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount        ScaleAnimation a = new ScaleAnimation(1.0f, 2.0f, 1.0f, 2.0f,
4616d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount                ScaleAnimation.RELATIVE_TO_SELF, 0.5f,
4716d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount                ScaleAnimation.RELATIVE_TO_SELF,0.5f);
4816d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount        a.setDuration(2000);
4916d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount        a.setRepeatCount(Animation.INFINITE);
5016d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount        a.setRepeatMode(Animation.REVERSE);
5116d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount        view.startAnimation(a);
5216d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount    }
5316d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount
5416d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount    static class BitmapsView extends View {
5516d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount        private Paint mBitmapPaint;
5616d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount        private final Bitmap mBitmap1;
57        private final Bitmap mBitmap2;
58        private final PorterDuffXfermode mDstIn;
59
60        BitmapsView(Context c) {
61            super(c);
62
63            mBitmap1 = BitmapFactory.decodeResource(c.getResources(), R.drawable.sunset1);
64            mBitmap2 = BitmapFactory.decodeResource(c.getResources(), R.drawable.sunset2);
65
66            Log.d("Bitmap", "mBitmap1.isMutable() = " + mBitmap1.isMutable());
67            Log.d("Bitmap", "mBitmap2.isMutable() = " + mBitmap2.isMutable());
68
69            BitmapFactory.Options opts = new BitmapFactory.Options();
70            opts.inMutable = true;
71            Bitmap bitmap = BitmapFactory.decodeResource(c.getResources(), R.drawable.sunset1, opts);
72            Log.d("Bitmap", "bitmap.isMutable() = " + bitmap.isMutable());
73
74            mBitmapPaint = new Paint();
75            mDstIn = new PorterDuffXfermode(PorterDuff.Mode.DST_IN);
76        }
77
78        @Override
79        protected void onDraw(Canvas canvas) {
80            super.onDraw(canvas);
81
82            canvas.translate(120.0f, 50.0f);
83            canvas.drawBitmap(mBitmap1, 0.0f, 0.0f, mBitmapPaint);
84
85            canvas.translate(0.0f, mBitmap1.getHeight());
86            canvas.translate(0.0f, 25.0f);
87            canvas.drawBitmap(mBitmap2, 0.0f, 0.0f, null);
88
89            mBitmapPaint.setAlpha(127);
90            canvas.translate(0.0f, mBitmap2.getHeight());
91            canvas.translate(0.0f, 25.0f);
92            canvas.drawBitmap(mBitmap1, 0.0f, 0.0f, mBitmapPaint);
93
94            mBitmapPaint.setAlpha(255);
95            canvas.translate(0.0f, mBitmap1.getHeight());
96            canvas.translate(0.0f, 25.0f);
97            mBitmapPaint.setColor(0xffff0000);
98            canvas.drawRect(0.0f, 0.0f, mBitmap2.getWidth(), mBitmap2.getHeight(), mBitmapPaint);
99            mBitmapPaint.setXfermode(mDstIn);
100            canvas.drawBitmap(mBitmap2, 0.0f, 0.0f, mBitmapPaint);
101
102            mBitmapPaint.reset();
103        }
104    }
105}
106