Home | History | Annotate | Download | only in hwui
      1 /*
      2  * Copyright (C) 2017 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.graphics.Bitmap;
     21 import android.graphics.Canvas;
     22 import android.graphics.Color;
     23 import android.graphics.Paint;
     24 import android.graphics.Picture;
     25 import android.os.Bundle;
     26 import android.widget.ImageView;
     27 
     28 public class DrawIntoHwBitmapActivity extends Activity {
     29     @Override
     30     protected void onCreate(Bundle savedInstanceState) {
     31         super.onCreate(savedInstanceState);
     32         ImageView view = new ImageView(this);
     33         view.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
     34         setContentView(view);
     35         view.setImageBitmap(createBitmap());
     36     }
     37 
     38     Bitmap createBitmap() {
     39         Picture picture = new Picture();
     40         Canvas canvas = picture.beginRecording(500, 500);
     41         Paint p = new Paint();
     42         p.setColor(Color.BLACK);
     43         p.setTextSize(20 * getResources().getDisplayMetrics().density);
     44         canvas.drawColor(0xFF2196F3);
     45         p.setColor(0xFFBBDEFB);
     46         canvas.drawRect(0, 0, 500, 100, p);
     47         p.setColor(Color.BLACK);
     48         canvas.drawText("Hello, World!", 0, 90, p);
     49         picture.endRecording();
     50         return Bitmap.createBitmap(picture);
     51     }
     52 }
     53