Home | History | Annotate | Download | only in hwui
      1 /*
      2  * Copyright (C) 2013 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.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.text_select_handle_left);
     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 }
     67