BitmapMeshActivity.java revision 5a7b466a2b4b7ced739bd5c31e022de61650545a
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.Context; 21import android.graphics.Bitmap; 22import android.graphics.BitmapFactory; 23import android.graphics.Canvas; 24import android.graphics.Paint; 25import android.graphics.PorterDuff; 26import android.graphics.PorterDuffXfermode; 27import android.os.Bundle; 28import android.util.Log; 29import android.view.View; 30 31@SuppressWarnings({"UnusedDeclaration"}) 32public class BitmapMeshActivity extends Activity { 33 @Override 34 protected void onCreate(Bundle savedInstanceState) { 35 super.onCreate(savedInstanceState); 36 final BitmapMeshView view = new BitmapMeshView(this); 37 view.setDrawingCacheEnabled(true); 38 setContentView(view); 39 } 40 41 static class BitmapMeshView extends View { 42 private Paint mBitmapPaint; 43 private final Bitmap mBitmap1; 44 45 BitmapMeshView(Context c) { 46 super(c); 47 48 mBitmap1 = BitmapFactory.decodeResource(c.getResources(), R.drawable.sunset1); 49 } 50 51 @Override 52 protected void onDraw(Canvas canvas) { 53 super.onDraw(canvas); 54 55 canvas.drawARGB(255, 255, 255, 255); 56 canvas.translate(100, 100); 57 final float width = mBitmap1.getWidth() / 3.0f; 58 final float height = mBitmap1.getHeight() / 3.0f; 59 canvas.drawBitmapMesh(mBitmap1, 3, 3, new float[] { 60 0.0f, 0.0f, width, 0.0f, width * 2, 0.0f, width * 3, 0.0f, 61 0.0f, height, width, height, width * 2, height, width * 4, height, 62 0.0f, height * 2, width, height * 2, width * 2, height * 2, width * 3, height * 2, 63 0.0f, height * 4, width, height * 4, width * 2, height * 4, width * 4, height * 4, 64 }, 0, null, 0, null); 65 } 66 } 67} 68