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