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
17package android.view;
18
19import android.app.Activity;
20import android.content.Context;
21import android.os.Bundle;
22import android.util.AttributeSet;
23import android.view.View;
24import android.view.ViewTreeObserver;
25import android.view.View.OnClickListener;
26import android.widget.Button;
27import android.widget.LinearLayout;
28
29import com.android.frameworks.coretests.R;
30
31
32/**
33 * Tests views with popupWindows becoming invisible
34 */
35public 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