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.os.Bundle;
21 import android.widget.TextView;
22 
23 import com.android.frameworks.coretests.R;
24 
25 /**
26  * Tests views using post*() and getViewTreeObserver() before onAttachedToWindow().
27  */
28 public class RunQueue extends Activity implements ViewTreeObserver.OnGlobalLayoutListener {
29     public boolean runnableRan = false;
30     public boolean runnableCancelled = true;
31     public boolean globalLayout = false;
32     public ViewTreeObserver viewTreeObserver;
33 
34     @Override
onCreate(Bundle icicle)35     protected void onCreate(Bundle icicle) {
36         super.onCreate(icicle);
37 
38         TextView textView = new TextView(this);
39         textView.setText("RunQueue");
40         textView.setId(R.id.simple_view);
41 
42         setContentView(textView);
43         final View view = findViewById(R.id.simple_view);
44 
45         view.post(new Runnable() {
46             public void run() {
47                 runnableRan = true;
48             }
49         });
50 
51         final Runnable runnable = new Runnable() {
52             public void run() {
53                 runnableCancelled = false;
54             }
55         };
56         view.post(runnable);
57         view.post(runnable);
58         view.post(runnable);
59         view.post(runnable);
60         view.removeCallbacks(runnable);
61 
62         viewTreeObserver = view.getViewTreeObserver();
63         viewTreeObserver.addOnGlobalLayoutListener(this);
64     }
65 
onGlobalLayout()66     public void onGlobalLayout() {
67         globalLayout = true;
68     }
69 }
70