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