Added View#dispatchViewVisibilityChanged and View#onDispatchVisibilityChanged; updated api; tests
Reverted a change to InstrumentationTestCase that would have allowed @UiThreadTest on setUp() methods of tests.
This commit is contained in:
@ -93901,7 +93901,7 @@
|
||||
<method name="glPointSizePointerOES"
|
||||
return="void"
|
||||
abstract="false"
|
||||
native="true"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="true"
|
||||
final="false"
|
||||
@ -96924,7 +96924,7 @@
|
||||
<method name="glMatrixIndexPointerOES"
|
||||
return="void"
|
||||
abstract="false"
|
||||
native="true"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="true"
|
||||
final="false"
|
||||
@ -97482,7 +97482,7 @@
|
||||
<method name="glWeightPointerOES"
|
||||
return="void"
|
||||
abstract="false"
|
||||
native="true"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="true"
|
||||
final="false"
|
||||
@ -166662,6 +166662,21 @@
|
||||
<parameter name="direction" type="int">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="dispatchVisibilityChanged"
|
||||
return="void"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="protected"
|
||||
>
|
||||
<parameter name="changedView" type="android.view.View">
|
||||
</parameter>
|
||||
<parameter name="visibility" type="int">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="dispatchWindowFocusChanged"
|
||||
return="void"
|
||||
abstract="false"
|
||||
@ -168522,6 +168537,21 @@
|
||||
<parameter name="event" type="android.view.MotionEvent">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="onVisibilityChanged"
|
||||
return="void"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="protected"
|
||||
>
|
||||
<parameter name="changedView" type="android.view.View">
|
||||
</parameter>
|
||||
<parameter name="visibility" type="int">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="onWindowFocusChanged"
|
||||
return="void"
|
||||
abstract="false"
|
||||
@ -286854,36 +286884,6 @@
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="array" type="short[]">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="sort"
|
||||
return="void"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="true"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="array" type="short[]">
|
||||
</parameter>
|
||||
<parameter name="start" type="int">
|
||||
</parameter>
|
||||
<parameter name="end" type="int">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="sort"
|
||||
return="void"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="true"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="array" type="java.lang.Object[]">
|
||||
</parameter>
|
||||
</method>
|
||||
@ -286938,6 +286938,36 @@
|
||||
<parameter name="comparator" type="java.util.Comparator<? super T>">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="sort"
|
||||
return="void"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="true"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="array" type="short[]">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="sort"
|
||||
return="void"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="true"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="array" type="short[]">
|
||||
</parameter>
|
||||
<parameter name="start" type="int">
|
||||
</parameter>
|
||||
<parameter name="end" type="int">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="toString"
|
||||
return="java.lang.String"
|
||||
abstract="false"
|
||||
|
@ -147,42 +147,6 @@ public class InstrumentationTestCase extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runBare() throws Throwable {
|
||||
runMethod("setUp");
|
||||
|
||||
try {
|
||||
runTest();
|
||||
} finally {
|
||||
runMethod("tearDown");
|
||||
}
|
||||
}
|
||||
|
||||
private Throwable[] runMethod(String name) throws Throwable {
|
||||
final Throwable[] exceptions = new Throwable[1];
|
||||
final Method m = getClass().getMethod(name, (Class[]) null);
|
||||
|
||||
if (m.isAnnotationPresent(UiThreadTest.class)) {
|
||||
getInstrumentation().runOnMainSync(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
m.invoke(InstrumentationTestCase.this);
|
||||
} catch (Throwable throwable) {
|
||||
exceptions[0] = throwable;
|
||||
}
|
||||
}
|
||||
});
|
||||
if (exceptions[0] != null) {
|
||||
throw exceptions[0];
|
||||
}
|
||||
exceptions[0] = null;
|
||||
} else {
|
||||
m.invoke(this);
|
||||
}
|
||||
|
||||
return exceptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the current unit test. If the unit test is annotated with
|
||||
* {@link android.test.UiThreadTest}, the test is run on the UI thread.
|
||||
|
@ -3770,6 +3770,26 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
|
||||
return mAttachInfo != null && mAttachInfo.mHasWindowFocus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch a view visibility change down the view hierarchy.
|
||||
* ViewGroups should override to route to their children.
|
||||
* @param changedView The view whose visibility changed. Could be 'this' or
|
||||
* an ancestor view.
|
||||
* @param visibility The new visibility of changedView.
|
||||
*/
|
||||
protected void dispatchVisibilityChanged(View changedView, int visibility) {
|
||||
onVisibilityChanged(changedView, visibility);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the visibility of the view or an ancestor of the view is changed.
|
||||
* @param changedView The view whose visibility changed. Could be 'this' or
|
||||
* an ancestor view.
|
||||
* @param visibility The new visibility of changedView.
|
||||
*/
|
||||
protected void onVisibilityChanged(View changedView, int visibility) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch a window visibility change down the view hierarchy.
|
||||
* ViewGroups should override to route to their children.
|
||||
@ -4349,6 +4369,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
|
||||
}
|
||||
}
|
||||
|
||||
if ((changed & VISIBILITY_MASK) != 0) {
|
||||
dispatchVisibilityChanged(this, (flags & VISIBILITY_MASK));
|
||||
}
|
||||
|
||||
if ((changed & WILL_NOT_CACHE_DRAWING) != 0) {
|
||||
destroyDrawingCache();
|
||||
}
|
||||
|
@ -680,6 +680,19 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void dispatchVisibilityChanged(View changedView, int visibility) {
|
||||
super.dispatchVisibilityChanged(changedView, visibility);
|
||||
final int count = mChildrenCount;
|
||||
final View[] children = mChildren;
|
||||
for (int i = 0; i < count; i++) {
|
||||
children[i].dispatchVisibilityChanged(changedView, visibility);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
@ -377,6 +377,13 @@
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity android:name=".view.VisibilityCallback" android:label="VisibilityCallback">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity android:name=".view.BigCache" android:label="BigCache">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
80
tests/FrameworkTest/res/layout/visibility_callback.xml
Normal file
80
tests/FrameworkTest/res/layout/visibility_callback.xml
Normal file
@ -0,0 +1,80 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
/*
|
||||
**
|
||||
** Copyright 2007, The Android Open Source Project
|
||||
**
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
** you may not use this file except in compliance with the License.
|
||||
** You may obtain a copy of the License at
|
||||
**
|
||||
** http://www.apache.org/licenses/LICENSE-2.0
|
||||
**
|
||||
** Unless required by applicable law or agreed to in writing, software
|
||||
** distributed under the License is distributed on an "AS IS" BASIS,
|
||||
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
** See the License for the specific language governing permissions and
|
||||
** limitations under the License.
|
||||
*/
|
||||
-->
|
||||
|
||||
<!-- Demonstrates changing view visibility. See corresponding Java code. -->
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:background="@drawable/box"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView android:id="@+id/refUp"
|
||||
android:background="@drawable/red"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/visibility_1_view_1"/>
|
||||
|
||||
<FrameLayout android:id="@+id/parent"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<view class="com.android.frameworktest.view.VisibilityCallback$MonitoredTextView"
|
||||
android:id="@+id/victim"
|
||||
android:background="@drawable/green"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/visibility_1_view_2"/>
|
||||
</FrameLayout>
|
||||
|
||||
<TextView android:id="@+id/refDown"
|
||||
android:background="@drawable/blue"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/visibility_1_view_3"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<Button android:id="@+id/vis"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/visibility_1_vis"/>
|
||||
|
||||
<Button android:id="@+id/invis"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/visibility_1_invis"/>
|
||||
|
||||
<Button android:id="@+id/gone"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/visibility_1_gone"/>
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Copyright (C) 2007 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.frameworktest.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.widget.TextView;
|
||||
import com.android.frameworktest.R;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.widget.Button;
|
||||
import android.view.View;
|
||||
import android.app.Activity;
|
||||
|
||||
/**
|
||||
* Exercise View's ability to change their visibility: GONE, INVISIBLE and
|
||||
* VISIBLE.
|
||||
*/
|
||||
public class VisibilityCallback extends Activity {
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
private MonitoredTextView mVictim;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
setContentView(R.layout.visibility_callback);
|
||||
|
||||
// Find the view whose visibility will change
|
||||
mVictim = (MonitoredTextView)findViewById(R.id.victim);
|
||||
|
||||
// Find our buttons
|
||||
Button visibleButton = (Button) findViewById(R.id.vis);
|
||||
Button invisibleButton = (Button) findViewById(R.id.invis);
|
||||
Button goneButton = (Button) findViewById(R.id.gone);
|
||||
|
||||
// Wire each button to a click listener
|
||||
visibleButton.setOnClickListener(mVisibleListener);
|
||||
invisibleButton.setOnClickListener(mInvisibleListener);
|
||||
goneButton.setOnClickListener(mGoneListener);
|
||||
}
|
||||
|
||||
|
||||
View.OnClickListener mVisibleListener = new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
mVictim.setVisibility(View.VISIBLE);
|
||||
}
|
||||
};
|
||||
|
||||
View.OnClickListener mInvisibleListener = new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
mVictim.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
};
|
||||
|
||||
View.OnClickListener mGoneListener = new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
mVictim.setVisibility(View.GONE);
|
||||
}
|
||||
};
|
||||
|
||||
public static class MonitoredTextView extends TextView {
|
||||
private View mLastVisChangedView;
|
||||
private int mLastChangedVisibility;
|
||||
|
||||
public MonitoredTextView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public MonitoredTextView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public MonitoredTextView(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
}
|
||||
|
||||
public View getLastVisChangedView() {
|
||||
return mLastVisChangedView;
|
||||
}
|
||||
|
||||
public int getLastChangedVisibility() {
|
||||
return mLastChangedVisibility;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onVisibilityChanged(View changedView, int visibility) {
|
||||
mLastVisChangedView = changedView;
|
||||
mLastChangedVisibility = visibility;
|
||||
|
||||
if (DEBUG) {
|
||||
Log.d("viewVis", "visibility: " + visibility);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,112 @@
|
||||
/*
|
||||
* Copyright (C) 2007 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.frameworktest.view;
|
||||
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.test.UiThreadTest;
|
||||
import android.test.suitebuilder.annotation.MediumTest;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import com.android.frameworktest.R;
|
||||
|
||||
/**
|
||||
* Exercises {@link android.view.View}'s ability to change visibility between
|
||||
* GONE, VISIBLE and INVISIBLE.
|
||||
*/
|
||||
public class VisibilityCallbackTest extends ActivityInstrumentationTestCase2<VisibilityCallback> {
|
||||
private TextView mRefUp;
|
||||
private TextView mRefDown;
|
||||
private VisibilityCallback.MonitoredTextView mVictim;
|
||||
private ViewGroup mParent;
|
||||
private Button mVisible;
|
||||
private Button mInvisible;
|
||||
private Button mGone;
|
||||
|
||||
public VisibilityCallbackTest() {
|
||||
super("com.android.frameworktest", VisibilityCallback.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
final VisibilityCallback a = getActivity();
|
||||
mRefUp = (TextView) a.findViewById(R.id.refUp);
|
||||
mRefDown = (TextView) a.findViewById(R.id.refDown);
|
||||
mVictim = (VisibilityCallback.MonitoredTextView) a.findViewById(R.id.victim);
|
||||
mParent = (ViewGroup) a.findViewById(R.id.parent);
|
||||
mVisible = (Button) a.findViewById(R.id.vis);
|
||||
mInvisible = (Button) a.findViewById(R.id.invis);
|
||||
mGone = (Button) a.findViewById(R.id.gone);
|
||||
|
||||
mVictim.post(new Runnable() {
|
||||
public void run() {
|
||||
mVictim.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
});
|
||||
getInstrumentation().waitForIdleSync();
|
||||
}
|
||||
|
||||
@MediumTest
|
||||
@UiThreadTest
|
||||
public void testSetUpConditions() throws Exception {
|
||||
assertNotNull(mRefUp);
|
||||
assertNotNull(mRefDown);
|
||||
assertNotNull(mVictim);
|
||||
assertNotNull(mVisible);
|
||||
assertNotNull(mInvisible);
|
||||
assertNotNull(mGone);
|
||||
|
||||
assertTrue(mVisible.hasFocus());
|
||||
assertEquals(View.INVISIBLE, mVictim.getVisibility());
|
||||
assertEquals(View.VISIBLE, mParent.getVisibility());
|
||||
}
|
||||
|
||||
@MediumTest
|
||||
@UiThreadTest
|
||||
public void testDirect() throws Exception {
|
||||
mVictim.setVisibility(View.VISIBLE);
|
||||
assertEquals(View.VISIBLE, mVictim.getLastChangedVisibility());
|
||||
assertEquals(mVictim, mVictim.getLastVisChangedView());
|
||||
|
||||
mVictim.setVisibility(View.INVISIBLE);
|
||||
assertEquals(View.INVISIBLE, mVictim.getLastChangedVisibility());
|
||||
assertEquals(mVictim, mVictim.getLastVisChangedView());
|
||||
|
||||
mVictim.setVisibility(View.GONE);
|
||||
assertEquals(View.GONE, mVictim.getLastChangedVisibility());
|
||||
assertEquals(mVictim, mVictim.getLastVisChangedView());
|
||||
}
|
||||
|
||||
@MediumTest
|
||||
@UiThreadTest
|
||||
public void testChild() throws Exception {
|
||||
mParent.setVisibility(View.INVISIBLE);
|
||||
assertEquals(View.INVISIBLE, mVictim.getLastChangedVisibility());
|
||||
assertEquals(mParent, mVictim.getLastVisChangedView());
|
||||
|
||||
mParent.setVisibility(View.GONE);
|
||||
assertEquals(View.GONE, mVictim.getLastChangedVisibility());
|
||||
assertEquals(mParent, mVictim.getLastVisChangedView());
|
||||
|
||||
mParent.setVisibility(View.VISIBLE);
|
||||
assertEquals(View.VISIBLE, mVictim.getLastChangedVisibility());
|
||||
assertEquals(mParent, mVictim.getLastVisChangedView());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user