ThinPatchesActivity.java revision 8411f336c786379c5a03106e9ed3bc8622b579a5
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.res.Resources; 21import android.graphics.Canvas; 22import android.graphics.drawable.Drawable; 23import android.os.Bundle; 24import android.view.View; 25import android.widget.FrameLayout; 26 27@SuppressWarnings({"UnusedDeclaration"}) 28public class ThinPatchesActivity extends Activity { 29 @Override 30 protected void onCreate(Bundle savedInstanceState) { 31 super.onCreate(savedInstanceState); 32 33 FrameLayout layout = new FrameLayout(this); 34 PatchView b = new PatchView(this); 35 b.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, 36 FrameLayout.LayoutParams.MATCH_PARENT)); 37 layout.addView(b); 38 layout.setBackgroundColor(0xffffffff); 39 40 setContentView(layout); 41 } 42 43 private class PatchView extends View { 44 private Drawable mPatch; 45 46 public PatchView(Activity activity) { 47 super(activity); 48 49 final Resources resources = activity.getResources(); 50 mPatch = resources.getDrawable(R.drawable.btn_toggle_on); 51 } 52 53 @Override 54 protected void onDraw(Canvas canvas) { 55 final int width = 100; 56 final int height = 60; 57 58 final int left = (getWidth() - width) / 2; 59 final int top = (getHeight() - height) / 2; 60 61 mPatch.setBounds(left, top, left + width, top + height); 62 mPatch.draw(canvas); 63 } 64 } 65} 66