blob: 220016aa8ab729b12a2fb24ef6328a364f02c626 [file] [log] [blame]
John Reck1fedd912017-05-23 14:45:22 -07001/*
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
17package com.android.test.hwui;
18
John Reck1fedd912017-05-23 14:45:22 -070019import android.app.Activity;
20import android.graphics.Bitmap;
21import android.graphics.Canvas;
22import android.graphics.Color;
John Reck1fedd912017-05-23 14:45:22 -070023import android.graphics.Paint;
John Reck519ad482018-02-12 17:08:48 -080024import android.graphics.Picture;
John Reck1fedd912017-05-23 14:45:22 -070025import android.os.Bundle;
John Reck1fedd912017-05-23 14:45:22 -070026import android.widget.ImageView;
27
28public 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() {
John Reck519ad482018-02-12 17:08:48 -080039 Picture picture = new Picture();
40 Canvas canvas = picture.beginRecording(500, 500);
John Reck1fedd912017-05-23 14:45:22 -070041 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);
John Reck519ad482018-02-12 17:08:48 -080049 picture.endRecording();
50 return Bitmap.createBitmap(picture);
John Reck1fedd912017-05-23 14:45:22 -070051 }
52}