1189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy/* 2189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy * Copyright (C) 2012 The Android Open Source Project 3189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy * 4189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy * Licensed under the Apache License, Version 2.0 (the "License"); 5189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy * you may not use this file except in compliance with the License. 6189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy * You may obtain a copy of the License at 7189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy * 8189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy * http://www.apache.org/licenses/LICENSE-2.0 9189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy * 10189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy * Unless required by applicable law or agreed to in writing, software 11189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy * distributed under the License is distributed on an "AS IS" BASIS, 12189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy * See the License for the specific language governing permissions and 14189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy * limitations under the License. 15189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy */ 16189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy 17189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guypackage com.android.test.hwui; 18189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy 19189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guyimport android.app.Activity; 20189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guyimport android.content.Context; 21189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guyimport android.graphics.Canvas; 22189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guyimport android.graphics.Paint; 23189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guyimport android.os.Bundle; 24189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guyimport android.view.View; 25189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guyimport android.widget.LinearLayout; 26189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy 27189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy@SuppressWarnings("UnusedDeclaration") 28189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guypublic class MultiLayersActivity extends Activity { 29189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy @Override 30189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy protected void onCreate(Bundle savedInstanceState) { 31189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy super.onCreate(savedInstanceState); 32189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy 33189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy LinearLayout grid = new LinearLayout(this); 34189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy grid.setOrientation(LinearLayout.VERTICAL); 35189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy 36189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy LinearLayout row1 = new LinearLayout(this); 37189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy row1.setOrientation(LinearLayout.HORIZONTAL); 38189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy grid.addView(row1, new LinearLayout.LayoutParams( 39189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.0f)); 40189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy 41189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy LinearLayout row2 = new LinearLayout(this); 42189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy row2.setOrientation(LinearLayout.HORIZONTAL); 43189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy grid.addView(row2, new LinearLayout.LayoutParams( 44189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.0f)); 45189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy 46189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy row1.addView(new LayerView(this, 0xffff0000), new LinearLayout.LayoutParams( 47189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy 0, LinearLayout.LayoutParams.MATCH_PARENT, 1.0f)); 4857b5268708c3b974296c7d4e58a02a957979224aRomain Guy row1.addView(new LayerView(this, 0x0f00ff00), new LinearLayout.LayoutParams( 49189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy 0, LinearLayout.LayoutParams.MATCH_PARENT, 1.0f)); 50189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy 5157b5268708c3b974296c7d4e58a02a957979224aRomain Guy row2.addView(new LayerView(this, 0x0f0000ff), new LinearLayout.LayoutParams( 52189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy 0, LinearLayout.LayoutParams.MATCH_PARENT, 1.0f)); 53189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy row2.addView(new LayerView(this, 0xffffff00), new LinearLayout.LayoutParams( 54189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy 0, LinearLayout.LayoutParams.MATCH_PARENT, 1.0f)); 55189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy 56189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy setContentView(grid); 57189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy } 58189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy 59189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy private class LayerView extends View { 60189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy private final Paint mPaint; 61189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy 62189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy public LayerView(Context context, int color) { 63189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy super(context); 64189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy mPaint = new Paint(); 65189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy mPaint.setColor(color); 66189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy setLayerType(LAYER_TYPE_HARDWARE, null); 67189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy } 68189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy 69189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy @Override 70189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy protected void onDraw(Canvas canvas) { 71189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy canvas.drawRect(0.0f, 0.0f, getWidth(), getHeight(), mPaint); 72189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy invalidate(); 73189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy } 74189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy } 75189ff17caa29e51e3438af59fb33c5cb513018bdRomain Guy} 76