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 android.app.Activity;
     20 import android.content.Context;
     21 import android.os.Bundle;
     22 import android.util.AttributeSet;
     23 import android.view.View;
     24 import android.view.ViewTreeObserver;
     25 import android.view.View.OnClickListener;
     26 import android.widget.Button;
     27 import android.widget.LinearLayout;
     28 
     29 import com.android.frameworks.coretests.R;
     30 
     31 
     32 /**
     33  * Tests views with popupWindows becoming invisible
     34  */
     35 public class PreDrawListener extends Activity implements OnClickListener {
     36 
     37     private MyLinearLayout mFrame;
     38 
     39 
     40     static public class MyLinearLayout extends LinearLayout implements
     41             ViewTreeObserver.OnPreDrawListener {
     42 
     43         public boolean mCancelNextDraw;
     44 
     45         public MyLinearLayout(Context context, AttributeSet attrs) {
     46             super(context, attrs);
     47         }
     48 
     49         public MyLinearLayout(Context context) {
     50             super(context);
     51         }
     52 
     53         @Override
     54         protected void onAttachedToWindow() {
     55             super.onAttachedToWindow();
     56             getViewTreeObserver().addOnPreDrawListener(this);
     57         }
     58 
     59         public boolean onPreDraw() {
     60             if (mCancelNextDraw) {
     61                 Button b = new Button(this.getContext());
     62                 b.setText("Hello");
     63                 addView(b, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
     64                         LayoutParams.WRAP_CONTENT));
     65                 mCancelNextDraw = false;
     66                 return false;
     67             }
     68             return true;
     69         }
     70 
     71     }
     72 
     73     @Override
     74     protected void onCreate(Bundle icicle) {
     75         super.onCreate(icicle);
     76         setContentView(R.layout.pre_draw_listener);
     77 
     78         mFrame = (MyLinearLayout) findViewById(R.id.frame);
     79 
     80         Button mGoButton = (Button) findViewById(R.id.go);
     81         mGoButton.setOnClickListener(this);
     82     }
     83 
     84 
     85     public void onClick(View v) {
     86         mFrame.mCancelNextDraw = true;
     87         mFrame.invalidate();
     88     }
     89 
     90 
     91 
     92 }
     93