Home | History | Annotate | Download | only in hwui
      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.os.Bundle;
     26 import android.util.Log;
     27 import android.view.Gravity;
     28 import android.view.View;
     29 import android.widget.FrameLayout;
     30 
     31 @SuppressWarnings({"UnusedDeclaration"})
     32 public class BitmapsAlphaActivity extends Activity {
     33     @Override
     34     protected void onCreate(Bundle savedInstanceState) {
     35         super.onCreate(savedInstanceState);
     36         final BitmapsView view = new BitmapsView(this);
     37         final FrameLayout layout = new FrameLayout(this);
     38         layout.addView(view, new FrameLayout.LayoutParams(480, 800, Gravity.CENTER));
     39         setContentView(layout);
     40     }
     41 
     42     static class BitmapsView extends View {
     43         private Paint mBitmapPaint;
     44         private final Bitmap mBitmap1;
     45         private final Bitmap mBitmap2;
     46         private Bitmap mBitmap3;
     47 
     48         BitmapsView(Context c) {
     49             super(c);
     50 
     51             Log.d("OpenGLRenderer", "Loading sunset1, default options");
     52             mBitmap1 = BitmapFactory.decodeResource(c.getResources(), R.drawable.sunset1);
     53             Log.d("OpenGLRenderer", "Loading sunset2, default options");
     54             mBitmap2 = BitmapFactory.decodeResource(c.getResources(), R.drawable.sunset2);
     55             Log.d("OpenGLRenderer", "Loading sunset3, forcing ARGB-8888");
     56             BitmapFactory.Options opts = new BitmapFactory.Options();
     57             opts.inPreferredConfig = Bitmap.Config.ARGB_8888;
     58             mBitmap3 = BitmapFactory.decodeResource(c.getResources(), R.drawable.sunset3, opts);
     59             Log.d("OpenGLRenderer", "    has bitmap alpha? " + mBitmap3.hasAlpha());
     60 
     61             mBitmapPaint = new Paint();
     62         }
     63 
     64         @Override
     65         protected void onDraw(Canvas canvas) {
     66             super.onDraw(canvas);
     67 
     68             Log.d("OpenGLRenderer", "================= Draw");
     69 
     70             canvas.translate(120.0f, 50.0f);
     71             canvas.drawBitmap(mBitmap1, 0.0f, 0.0f, mBitmapPaint);
     72 
     73             canvas.translate(0.0f, mBitmap1.getHeight());
     74             canvas.translate(0.0f, 25.0f);
     75             canvas.drawBitmap(mBitmap2, 0.0f, 0.0f, null);
     76 
     77             canvas.translate(0.0f, mBitmap2.getHeight());
     78             canvas.translate(0.0f, 25.0f);
     79             canvas.drawBitmap(mBitmap3, 0.0f, 0.0f, null);
     80         }
     81     }
     82 }
     83