1 /* 2 * Copyright (C) 2007 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 android.view; 18 19 import android.app.Activity; 20 import android.graphics.drawable.Drawable; 21 import android.os.Bundle; 22 import android.view.View.OnClickListener; 23 import android.widget.AbsoluteLayout; 24 import android.widget.Button; 25 import android.widget.FrameLayout; 26 import android.widget.LinearLayout; 27 import android.widget.RelativeLayout; 28 import android.widget.TextView; 29 30 import com.android.frameworks.coretests.R; 31 32 /** 33 * Views should obey their background {@link Drawable}'s minimum size 34 * requirements ({@link Drawable#getMinimumHeight()} and 35 * {@link Drawable#getMinimumWidth()}) when possible. 36 * <p> 37 * This Activity exercises a few Views with background {@link Drawable}s. 38 */ 39 public class DrawableBgMinSize extends Activity implements OnClickListener { 40 private boolean mUsingBigBg = false; 41 private Drawable mBackgroundDrawable; 42 private Drawable mBigBackgroundDrawable; 43 private Button mChangeBackgroundsButton; 44 45 private TextView mTextView; 46 private LinearLayout mLinearLayout; 47 private RelativeLayout mRelativeLayout; 48 private FrameLayout mFrameLayout; 49 private AbsoluteLayout mAbsoluteLayout; 50 51 @Override onCreate(Bundle icicle)52 protected void onCreate(Bundle icicle) { 53 super.onCreate(icicle); 54 55 setContentView(R.layout.drawable_background_minimum_size); 56 57 mBackgroundDrawable = getResources().getDrawable(R.drawable.drawable_background); 58 mBigBackgroundDrawable = getResources().getDrawable(R.drawable.big_drawable_background); 59 60 mChangeBackgroundsButton = findViewById(R.id.change_backgrounds); 61 mChangeBackgroundsButton.setOnClickListener(this); 62 63 mTextView = findViewById(R.id.text_view); 64 mLinearLayout = findViewById(R.id.linear_layout); 65 mRelativeLayout = findViewById(R.id.relative_layout); 66 mFrameLayout = findViewById(R.id.frame_layout); 67 mAbsoluteLayout = findViewById(R.id.absolute_layout); 68 69 changeBackgrounds(mBackgroundDrawable); 70 } 71 changeBackgrounds(Drawable newBg)72 private void changeBackgrounds(Drawable newBg) { 73 mTextView.setBackgroundDrawable(newBg); 74 mLinearLayout.setBackgroundDrawable(newBg); 75 mRelativeLayout.setBackgroundDrawable(newBg); 76 mFrameLayout.setBackgroundDrawable(newBg); 77 mAbsoluteLayout.setBackgroundDrawable(newBg); 78 } 79 onClick(View v)80 public void onClick(View v) { 81 if (mUsingBigBg) { 82 changeBackgrounds(mBackgroundDrawable); 83 } else { 84 changeBackgrounds(mBigBackgroundDrawable); 85 } 86 87 mUsingBigBg = !mUsingBigBg; 88 } 89 90 } 91