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.util.Log; 24 import android.widget.Button; 25 import android.widget.TextView; 26 27 import com.android.frameworks.coretests.R; 28 29 /** 30 * Exercise View's ability to change their visibility: GONE, INVISIBLE and 31 * VISIBLE. 32 */ 33 public class VisibilityCallback extends Activity { 34 private static final boolean DEBUG = false; 35 36 private MonitoredTextView mVictim; 37 38 @Override onCreate(Bundle icicle)39 protected void onCreate(Bundle icicle) { 40 super.onCreate(icicle); 41 setContentView(R.layout.visibility_callback); 42 43 // Find the view whose visibility will change 44 mVictim = (MonitoredTextView)findViewById(R.id.victim); 45 46 // Find our buttons 47 Button visibleButton = findViewById(R.id.vis); 48 Button invisibleButton = findViewById(R.id.invis); 49 Button goneButton = findViewById(R.id.gone); 50 51 // Wire each button to a click listener 52 visibleButton.setOnClickListener(mVisibleListener); 53 invisibleButton.setOnClickListener(mInvisibleListener); 54 goneButton.setOnClickListener(mGoneListener); 55 } 56 57 58 View.OnClickListener mVisibleListener = new View.OnClickListener() { 59 public void onClick(View v) { 60 mVictim.setVisibility(View.VISIBLE); 61 } 62 }; 63 64 View.OnClickListener mInvisibleListener = new View.OnClickListener() { 65 public void onClick(View v) { 66 mVictim.setVisibility(View.INVISIBLE); 67 } 68 }; 69 70 View.OnClickListener mGoneListener = new View.OnClickListener() { 71 public void onClick(View v) { 72 mVictim.setVisibility(View.GONE); 73 } 74 }; 75 76 public static class MonitoredTextView extends TextView { 77 private View mLastVisChangedView; 78 private int mLastChangedVisibility; 79 MonitoredTextView(Context context)80 public MonitoredTextView(Context context) { 81 super(context); 82 } 83 MonitoredTextView(Context context, AttributeSet attrs)84 public MonitoredTextView(Context context, AttributeSet attrs) { 85 super(context, attrs); 86 } 87 MonitoredTextView(Context context, AttributeSet attrs, int defStyle)88 public MonitoredTextView(Context context, AttributeSet attrs, int defStyle) { 89 super(context, attrs, defStyle); 90 } 91 getLastVisChangedView()92 public View getLastVisChangedView() { 93 return mLastVisChangedView; 94 } 95 getLastChangedVisibility()96 public int getLastChangedVisibility() { 97 return mLastChangedVisibility; 98 } 99 100 @Override onVisibilityChanged(View changedView, int visibility)101 protected void onVisibilityChanged(View changedView, int visibility) { 102 mLastVisChangedView = changedView; 103 mLastChangedVisibility = visibility; 104 105 if (DEBUG) { 106 Log.d("viewVis", "visibility: " + visibility); 107 } 108 } 109 } 110 } 111