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