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