1e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy/* 2e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy * Copyright (C) 2010 The Android Open Source Project 3e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy * 4e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy * Licensed under the Apache License, Version 2.0 (the "License"); 5e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy * you may not use this file except in compliance with the License. 6e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy * You may obtain a copy of the License at 7e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy * 8e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy * http://www.apache.org/licenses/LICENSE-2.0 9e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy * 10e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy * Unless required by applicable law or agreed to in writing, software 11e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy * distributed under the License is distributed on an "AS IS" BASIS, 12e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy * See the License for the specific language governing permissions and 14e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy * limitations under the License. 15e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy */ 16e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy 17f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guypackage com.android.test.hwui; 18e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy 19e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guyimport android.app.Activity; 20e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guyimport android.content.Context; 21e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guyimport android.graphics.Bitmap; 22e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guyimport android.graphics.BitmapFactory; 23e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guyimport android.graphics.Canvas; 24e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guyimport android.graphics.Paint; 25e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guyimport android.os.Bundle; 26e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guyimport android.util.Log; 27e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guyimport android.view.Gravity; 28e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guyimport android.view.View; 29e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guyimport android.widget.FrameLayout; 30e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy 31e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy@SuppressWarnings({"UnusedDeclaration"}) 32e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guypublic class BitmapsAlphaActivity extends Activity { 33e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy @Override 34e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy protected void onCreate(Bundle savedInstanceState) { 35e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy super.onCreate(savedInstanceState); 36e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy final BitmapsView view = new BitmapsView(this); 37e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy final FrameLayout layout = new FrameLayout(this); 38e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy layout.addView(view, new FrameLayout.LayoutParams(480, 800, Gravity.CENTER)); 39e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy setContentView(layout); 40e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy } 41e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy 42e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy static class BitmapsView extends View { 43e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy private Paint mBitmapPaint; 44e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy private final Bitmap mBitmap1; 45e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy private final Bitmap mBitmap2; 46e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy private Bitmap mBitmap3; 47e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy 48e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy BitmapsView(Context c) { 49e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy super(c); 50e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy 51e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy Log.d("OpenGLRenderer", "Loading sunset1, default options"); 52e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy mBitmap1 = BitmapFactory.decodeResource(c.getResources(), R.drawable.sunset1); 53e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy Log.d("OpenGLRenderer", "Loading sunset2, default options"); 54e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy mBitmap2 = BitmapFactory.decodeResource(c.getResources(), R.drawable.sunset2); 55e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy Log.d("OpenGLRenderer", "Loading sunset3, forcing ARGB-8888"); 56e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy BitmapFactory.Options opts = new BitmapFactory.Options(); 57e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy opts.inPreferredConfig = Bitmap.Config.ARGB_8888; 58e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy mBitmap3 = BitmapFactory.decodeResource(c.getResources(), R.drawable.sunset3, opts); 59e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy Log.d("OpenGLRenderer", " has bitmap alpha? " + mBitmap3.hasAlpha()); 60e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy 61e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy mBitmapPaint = new Paint(); 62e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy } 63e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy 64e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy @Override 65e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy protected void onDraw(Canvas canvas) { 66e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy super.onDraw(canvas); 67e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy 68e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy Log.d("OpenGLRenderer", "================= Draw"); 69e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy 70e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy canvas.translate(120.0f, 50.0f); 71e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy canvas.drawBitmap(mBitmap1, 0.0f, 0.0f, mBitmapPaint); 72e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy 73e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy canvas.translate(0.0f, mBitmap1.getHeight()); 74e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy canvas.translate(0.0f, 25.0f); 75e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy canvas.drawBitmap(mBitmap2, 0.0f, 0.0f, null); 76e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy 77e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy canvas.translate(0.0f, mBitmap2.getHeight()); 78e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy canvas.translate(0.0f, 25.0f); 79e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy canvas.drawBitmap(mBitmap3, 0.0f, 0.0f, null); 80e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy } 81e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy } 82e9e7fd0813f1485d20c6cd0014d59aff53c35d84Romain Guy} 83