|
| 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 | + |
| 17 | +package com.android.test.hwui; |
| 18 | + |
| 19 | +import android.app.Activity; |
| 20 | +import android.content.Context; |
| 21 | +import android.graphics.Bitmap; |
| 22 | +import android.graphics.BitmapFactory; |
| 23 | +import android.graphics.Canvas; |
| 24 | +import android.graphics.Paint; |
| 25 | +import android.graphics.PorterDuff; |
| 26 | +import android.graphics.PorterDuffXfermode; |
| 27 | +import android.os.Bundle; |
| 28 | +import android.util.Log; |
| 29 | +import android.view.Gravity; |
| 30 | +import android.view.View; |
| 31 | +import android.view.animation.Animation; |
| 32 | +import android.view.animation.ScaleAnimation; |
| 33 | +import android.widget.FrameLayout; |
| 34 | + |
| 35 | +@SuppressWarnings({"UnusedDeclaration"}) |
| 36 | +public class MipMapActivity extends Activity { |
| 37 | + @Override |
| 38 | + protected void onCreate(Bundle savedInstanceState) { |
| 39 | + super.onCreate(savedInstanceState); |
| 40 | + final BitmapsView view = new BitmapsView(this); |
| 41 | + setContentView(view); |
| 42 | + } |
| 43 | + |
| 44 | + static class BitmapsView extends View { |
| 45 | + private Paint mBitmapPaint; |
| 46 | + private final Bitmap mBitmap1; |
| 47 | + private final Bitmap mBitmap2; |
| 48 | + |
| 49 | + BitmapsView(Context c) { |
| 50 | + super(c); |
| 51 | + |
| 52 | + mBitmap1 = BitmapFactory.decodeResource(c.getResources(), R.drawable.very_large_photo); |
| 53 | + mBitmap2 = BitmapFactory.decodeResource(c.getResources(), R.drawable.very_large_photo); |
| 54 | + |
| 55 | + mBitmap1.setHasMipMap(true); |
| 56 | + |
| 57 | + mBitmapPaint = new Paint(); |
| 58 | + mBitmapPaint.setFilterBitmap(true); |
| 59 | + } |
| 60 | + |
| 61 | + @Override |
| 62 | + protected void onDraw(Canvas canvas) { |
| 63 | + super.onDraw(canvas); |
| 64 | + |
| 65 | + canvas.save(); |
| 66 | + canvas.scale(0.3f, 0.3f); |
| 67 | + canvas.drawBitmap(mBitmap1, 0, 0, mBitmapPaint); |
| 68 | + canvas.restore(); |
| 69 | + |
| 70 | + canvas.save(); |
| 71 | + canvas.translate(mBitmap1.getWidth() * 0.3f + 96.0f, 0.0f); |
| 72 | + canvas.scale(0.3f, 0.3f); |
| 73 | + canvas.drawBitmap(mBitmap2, 0, 0, mBitmapPaint); |
| 74 | + canvas.restore(); |
| 75 | + } |
| 76 | + } |
| 77 | +} |
0 commit comments