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