| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 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.Canvas; |
| 23 |
import android.graphics.Matrix; |
| 24 |
import android.graphics.Rect; |
| 25 |
import android.graphics.drawable.BitmapDrawable; |
| 26 |
import android.graphics.drawable.Drawable; |
| 27 |
import android.os.Bundle; |
| 28 |
import android.view.View; |
| 29 |
import com.android.internal.R; |
| 30 |
|
| 31 |
@SuppressWarnings({"UnusedDeclaration"}) |
| 32 |
public class AssetsAtlasActivity extends Activity { |
| 33 |
@Override |
| 34 |
protected void onCreate(Bundle savedInstanceState) { |
| 35 |
super.onCreate(savedInstanceState); |
| 36 |
setContentView(new BitmapsView(this)); |
| 37 |
} |
| 38 |
|
| 39 |
static class BitmapsView extends View { |
| 40 |
private final Bitmap mBitmap; |
| 41 |
|
| 42 |
BitmapsView(Context c) { |
| 43 |
super(c); |
| 44 |
|
| 45 |
Drawable d = c.getResources().getDrawable(R.drawable.star_big_on); |
| 46 |
mBitmap = ((BitmapDrawable) d).getBitmap(); |
| 47 |
} |
| 48 |
|
| 49 |
@Override |
| 50 |
protected void onDraw(Canvas canvas) { |
| 51 |
super.onDraw(canvas); |
| 52 |
|
| 53 |
final Matrix matrix = new Matrix(); |
| 54 |
matrix.setScale(0.5f, 0.5f); |
| 55 |
|
| 56 |
final Rect src = new Rect(0, 0, mBitmap.getWidth() / 2, mBitmap.getHeight() / 2); |
| 57 |
final Rect dst = new Rect(0, 0, mBitmap.getWidth(), mBitmap.getHeight()); |
| 58 |
|
| 59 |
canvas.drawBitmap(mBitmap, 0.0f, 0.0f, null); |
| 60 |
canvas.translate(0.0f, mBitmap.getHeight()); |
| 61 |
canvas.drawBitmap(mBitmap, matrix, null); |
| 62 |
canvas.translate(0.0f, mBitmap.getHeight()); |
| 63 |
canvas.drawBitmap(mBitmap, src, dst, null); |
| 64 |
} |
| 65 |
} |
| 66 |
} |