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.Matrix;
     25 import android.graphics.Paint;
     26 import android.os.Bundle;
     27 import android.view.Gravity;
     28 import android.view.View;
     29 import android.widget.FrameLayout;
     30 
     31 @SuppressWarnings({"UnusedDeclaration"})
     32 public class Bitmaps3dActivity 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(800, 400, Gravity.CENTER));
     39         view.setRotationX(-35.0f);
     40         setContentView(layout);
     41     }
     42 
     43     static class BitmapsView extends View {
     44         private final Paint mBitmapPaint;
     45         private final Bitmap mBitmap1;
     46         private Matrix mMatrix;
     47 
     48         BitmapsView(Context c) {
     49             super(c);
     50 
     51             mBitmap1 = BitmapFactory.decodeResource(c.getResources(), R.drawable.sunset1);
     52             mBitmapPaint = new Paint();
     53 
     54             mMatrix = new Matrix();
     55             mMatrix.setScale(2.0f, 2.0f);
     56             mMatrix.preTranslate(0.0f, -10.0f);
     57         }
     58 
     59         @Override
     60         protected void onDraw(Canvas canvas) {
     61             super.onDraw(canvas);
     62 
     63             canvas.drawColor(0xffffffff);
     64 
     65             canvas.save();
     66             canvas.translate(120.0f, 50.0f);
     67 
     68             canvas.concat(mMatrix);
     69             canvas.drawBitmap(mBitmap1, 0.0f, 0.0f, mBitmapPaint);
     70 
     71             canvas.restore();
     72         }
     73     }
     74 }
     75