TextGammaActivity.java revision f607bdc167f66b3e7003acaa4736ae46d78c1492
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
17package com.android.test.hwui;
18
19import android.app.Activity;
20import android.content.Context;
21import android.content.Intent;
22import android.graphics.Bitmap;
23import android.graphics.Canvas;
24import android.graphics.PorterDuff;
25import android.graphics.drawable.ColorDrawable;
26import android.os.Bundle;
27import android.view.LayoutInflater;
28import android.widget.ImageView;
29import android.widget.LinearLayout;
30
31@SuppressWarnings({"UnusedDeclaration"})
32public class TextGammaActivity extends Activity {
33    @Override
34    protected void onCreate(Bundle savedInstanceState) {
35        super.onCreate(savedInstanceState);
36
37        final LinearLayout layout = new LinearLayout(this);
38        layout.setOrientation(LinearLayout.VERTICAL);
39
40        final GammaTextView gamma = new GammaTextView(this);
41        layout.addView(gamma, new LinearLayout.LayoutParams(
42                LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT
43        ));
44
45        setContentView(layout);
46
47        layout.post(new Runnable() {
48            @Override
49            public void run() {
50                Bitmap b = Bitmap.createBitmap(gamma.getWidth(), gamma.getHeight(),
51                        Bitmap.Config.ARGB_8888);
52                Canvas c = new Canvas(b);
53                c.drawColor(0, PorterDuff.Mode.CLEAR);
54                gamma.draw(c);
55
56                ImageView image = new ImageView(TextGammaActivity.this);
57                image.setImageBitmap(b);
58
59                layout.addView(image, new LinearLayout.LayoutParams(
60                        LinearLayout.LayoutParams.WRAP_CONTENT,
61                        LinearLayout.LayoutParams.WRAP_CONTENT
62                ));
63
64                startActivity(new Intent(TextGammaActivity.this, SubGammaActivity.class));
65            }
66        });
67
68        getWindow().setBackgroundDrawable(new ColorDrawable(0xffffffff));
69    }
70
71    static class GammaTextView extends LinearLayout {
72        GammaTextView(Context c) {
73            super(c);
74
75            setBackgroundColor(0xffffffff);
76
77            final LayoutInflater inflater = LayoutInflater.from(c);
78            inflater.inflate(R.layout.text_large, this, true);
79            inflater.inflate(R.layout.text_medium, this, true);
80            inflater.inflate(R.layout.text_small, this, true);
81        }
82    }
83
84    public static class SubGammaActivity extends Activity {
85        @Override
86        protected void onCreate(Bundle savedInstanceState) {
87            super.onCreate(savedInstanceState);
88
89            final LinearLayout layout = new LinearLayout(this);
90            layout.setOrientation(LinearLayout.VERTICAL);
91
92            final GammaTextView gamma = new GammaTextView(this);
93            final LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
94                    LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT
95            );
96            lp.setMargins(0, 74, 0, 0);
97            layout.addView(gamma, lp);
98
99            setContentView(layout);
100        }
101    }
102}
103