summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Mason Tang <masontang@google.com> 2010-06-14 17:47:24 -0700
committer Mason Tang <masontang@google.com> 2010-06-16 13:38:15 -0700
commitf70036bc91e93cf6834c835beb832861c0dbd9db (patch)
tree6c437ee0a1ebd60a7fd6af9b9c20e516cc091896
parent820c12c924ee27d7e574ce56826e9ba645fa1336 (diff)
Modified first animation and visibility change behavior for ViewFlipper
- Where previously ViewAnimator only exposed inAnimation and outAnimation as XML attributes, modified to also include the animateFirstView flag so that widgets can optionally choose to omit the animation for the first child view. - Changed the behavior of ViewFlipper so that simple visibility changes do not trigger extraneous and distracting animations. Change-Id: I34b3abad33102978a94f0aed5aaab9af30ba49c7
-rw-r--r--api/current.xml11
-rw-r--r--core/java/android/widget/ViewAnimator.java41
-rw-r--r--core/java/android/widget/ViewFlipper.java18
-rwxr-xr-xcore/res/res/values/attrs.xml41
-rw-r--r--core/res/res/values/public.xml21
5 files changed, 90 insertions, 42 deletions
diff --git a/api/current.xml b/api/current.xml
index 098676ec302d..5aeeec6448a4 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -2275,6 +2275,17 @@
visibility="public"
>
</field>
+<field name="animateFirstView"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16843541"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
<field name="animateOnClick"
type="int"
transient="false"
diff --git a/core/java/android/widget/ViewAnimator.java b/core/java/android/widget/ViewAnimator.java
index 907cfb352a41..7b668932fc9a 100644
--- a/core/java/android/widget/ViewAnimator.java
+++ b/core/java/android/widget/ViewAnimator.java
@@ -31,11 +31,13 @@ import android.view.animation.AnimationUtils;
*
* @attr ref android.R.styleable#ViewAnimator_inAnimation
* @attr ref android.R.styleable#ViewAnimator_outAnimation
+ * @attr ref android.R.styleable#ViewAnimator_animateFirstView
*/
public class ViewAnimator extends FrameLayout {
int mWhichChild = 0;
boolean mFirstTime = true;
+
boolean mAnimateFirstTime = true;
Animation mInAnimation;
@@ -59,6 +61,10 @@ public class ViewAnimator extends FrameLayout {
if (resource > 0) {
setOutAnimation(context, resource);
}
+
+ boolean flag = a.getBoolean(com.android.internal.R.styleable.ViewAnimator_animateFirstView, true);
+ setAnimateFirstView(flag);
+
a.recycle();
initViewAnimator(context, attrs);
@@ -84,10 +90,10 @@ public class ViewAnimator extends FrameLayout {
setMeasureAllChildren(measureAllChildren);
a.recycle();
}
-
+
/**
* Sets which child view will be displayed.
- *
+ *
* @param whichChild the index of the child view to display
*/
public void setDisplayedChild(int whichChild) {
@@ -105,14 +111,14 @@ public class ViewAnimator extends FrameLayout {
requestFocus(FOCUS_FORWARD);
}
}
-
+
/**
* Returns the index of the currently displayed child view.
*/
public int getDisplayedChild() {
return mWhichChild;
}
-
+
/**
* Manually shows the next child.
*/
@@ -128,25 +134,27 @@ public class ViewAnimator extends FrameLayout {
}
/**
- * Shows only the specified child. The other displays Views exit the screen
- * with the {@link #getOutAnimation() out animation} and the specified child
- * enters the screen with the {@link #getInAnimation() in animation}.
+ * Shows only the specified child. The other displays Views exit the screen,
+ * optionally with the with the {@link #getOutAnimation() out animation} and
+ * the specified child enters the screen, optionally with the
+ * {@link #getInAnimation() in animation}.
*
* @param childIndex The index of the child to be shown.
+ * @param animate Whether or not to use the in and out animations, defaults
+ * to true.
*/
- void showOnly(int childIndex) {
+ void showOnly(int childIndex, boolean animate) {
final int count = getChildCount();
for (int i = 0; i < count; i++) {
final View child = getChildAt(i);
- final boolean checkForFirst = (!mFirstTime || mAnimateFirstTime);
if (i == childIndex) {
- if (checkForFirst && mInAnimation != null) {
+ if (animate && mInAnimation != null) {
child.startAnimation(mInAnimation);
}
child.setVisibility(View.VISIBLE);
mFirstTime = false;
} else {
- if (checkForFirst && mOutAnimation != null && child.getVisibility() == View.VISIBLE) {
+ if (animate && mOutAnimation != null && child.getVisibility() == View.VISIBLE) {
child.startAnimation(mOutAnimation);
} else if (child.getAnimation() == mInAnimation)
child.clearAnimation();
@@ -154,6 +162,17 @@ public class ViewAnimator extends FrameLayout {
}
}
}
+ /**
+ * Shows only the specified child. The other displays Views exit the screen
+ * with the {@link #getOutAnimation() out animation} and the specified child
+ * enters the screen with the {@link #getInAnimation() in animation}.
+ *
+ * @param childIndex The index of the child to be shown.
+ */
+ void showOnly(int childIndex) {
+ final boolean animate = (!mFirstTime || mAnimateFirstTime);
+ showOnly(childIndex, animate);
+ }
@Override
public void addView(View child, int index, ViewGroup.LayoutParams params) {
diff --git a/core/java/android/widget/ViewFlipper.java b/core/java/android/widget/ViewFlipper.java
index 8034961df50a..c6f6e81d452b 100644
--- a/core/java/android/widget/ViewFlipper.java
+++ b/core/java/android/widget/ViewFlipper.java
@@ -75,7 +75,7 @@ public class ViewFlipper extends ViewAnimator {
updateRunning();
} else if (Intent.ACTION_USER_PRESENT.equals(action)) {
mUserPresent = true;
- updateRunning();
+ updateRunning(false);
}
}
};
@@ -109,7 +109,7 @@ public class ViewFlipper extends ViewAnimator {
protected void onWindowVisibilityChanged(int visibility) {
super.onWindowVisibilityChanged(visibility);
mVisible = visibility == VISIBLE;
- updateRunning();
+ updateRunning(false);
}
/**
@@ -144,10 +144,22 @@ public class ViewFlipper extends ViewAnimator {
* on {@link #mRunning} and {@link #mVisible} state.
*/
private void updateRunning() {
+ updateRunning(true);
+ }
+
+ /**
+ * Internal method to start or stop dispatching flip {@link Message} based
+ * on {@link #mRunning} and {@link #mVisible} state.
+ *
+ * @param flipNow Determines whether or not to execute the animation now, in
+ * addition to queuing future flips. If omitted, defaults to
+ * true.
+ */
+ private void updateRunning(boolean flipNow) {
boolean running = mVisible && mStarted && mUserPresent;
if (running != mRunning) {
if (running) {
- showOnly(mWhichChild);
+ showOnly(mWhichChild, flipNow);
Message msg = mHandler.obtainMessage(FLIP_MSG);
mHandler.sendMessageDelayed(msg, mFlipInterval);
} else {
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index 7814aa858f91..d3e66ee1150a 100755
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -14,8 +14,8 @@
limitations under the License.
-->
-<!-- Formatting note: terminate all comments with a period, to avoid breaking
- the documentation output. To suppress comment lines from the documentation
+<!-- Formatting note: terminate all comments with a period, to avoid breaking
+ the documentation output. To suppress comment lines from the documentation
output, insert an eat-comment element after the comment lines.
-->
@@ -985,7 +985,7 @@
<attr name="windowShowAnimation" format="reference" />
<!-- The animation used when a window is going from VISIBLE to INVISIBLE. -->
<attr name="windowHideAnimation" format="reference" />
-
+
<!-- When opening a new activity, this is the animation that is
run on the next activity (which is entering the screen). -->
<attr name="activityOpenEnterAnimation" format="reference" />
@@ -1026,7 +1026,7 @@
animation that is run on the top activity of the current task
(which is exiting the screen). -->
<attr name="taskToBackExitAnimation" format="reference" />
-
+
<!-- When opening a new activity that shows the wallpaper, while
currently not showing the wallpaper, this is the animation that
is run on the new wallpaper activity (which is entering the screen). -->
@@ -1043,7 +1043,7 @@
currently showing the wallpaper, this is the animation that
is run on the old wallpaper activity (which is exiting the screen). -->
<attr name="wallpaperCloseExitAnimation" format="reference" />
-
+
<!-- When opening a new activity that is on top of the wallpaper
when the current activity is also on top of the wallpaper,
this is the animation that is run on the new activity
@@ -2152,7 +2152,7 @@
<attr name="dropDownAnchor" format="reference" />
<!-- Specifies the basic width of the dropdown. Its value may
be a dimension (such as "12dip") for a constant width,
- fill_parent or match_parent to match the width of the
+ fill_parent or match_parent to match the width of the
screen, or wrap_content to match the width of
the anchored view. -->
<attr name="dropDownWidth" format="dimension">
@@ -2188,8 +2188,13 @@
<attr name="popupBackground" format="reference|color" />
</declare-styleable>
<declare-styleable name="ViewAnimator">
+ <!-- Identifier for the animation to use when a view is shown. -->
<attr name="inAnimation" format="reference" />
+ <!-- Identifier for the animation to use when a view is hidden. -->
<attr name="outAnimation" format="reference" />
+ <!-- Defines whether to animate the current View when the ViewAnimation
+ is first displayed. -->
+ <attr name="animateFirstView" format="boolean" />
</declare-styleable>
<declare-styleable name="ViewFlipper">
<attr name="flipInterval" format="integer" min="0" />
@@ -3545,7 +3550,7 @@
<!-- AppWidget package class attributes -->
<!-- =============================== -->
<eat-comment />
-
+
<!-- Use <code>appwidget-provider</code> as the root tag of the XML resource that
describes an AppWidget provider. See {@link android.appwidget android.appwidget}
package for more info.
@@ -3568,7 +3573,7 @@
<!-- App package class attributes -->
<!-- =============================== -->
<eat-comment />
-
+
<!-- ============================= -->
<!-- View package class attributes -->
<!-- ============================= -->
@@ -3581,7 +3586,7 @@
<declare-styleable name="Fragment">
<!-- Supply the name of the fragment class to instantiate. -->
<attr name="name" />
-
+
<!-- Supply an identifier name for the top-level view, to later retrieve it
with {@link android.view.View#findViewById View.findViewById()} or
{@link android.app.Activity#findViewById Activity.findViewById()}.
@@ -3641,7 +3646,7 @@
<!-- Accounts package class attributes -->
<!-- =============================== -->
<eat-comment />
-
+
<!-- Use <code>account-authenticator</code> as the root tag of the XML resource that
describes an account authenticator.
-->
@@ -3662,7 +3667,7 @@
<!-- Accounts package class attributes -->
<!-- =============================== -->
<eat-comment />
-
+
<!-- Use <code>account-authenticator</code> as the root tag of the XML resource that
describes an account authenticator.
-->
@@ -3678,7 +3683,7 @@
<!-- Contacts meta-data attributes -->
<!-- =============================== -->
<eat-comment />
-
+
<!-- TODO: remove this deprecated styleable. -->
<eat-comment />
<declare-styleable name="Icon">
@@ -3737,12 +3742,12 @@
<declare-styleable name="RecognitionService">
<attr name="settingsActivity" />
</declare-styleable>
-
+
<!-- =============================== -->
<!-- Adapters attributes -->
<!-- =============================== -->
<eat-comment />
-
+
<!-- Adapter used to bind cursors. -->
<declare-styleable name="CursorAdapter">
<!-- URI to get the cursor from. Optional. -->
@@ -3754,7 +3759,7 @@
<!-- Layout resource used to display each row from the cursor. Mandatory. -->
<attr name="layout" />
</declare-styleable>
-
+
<!-- Attributes used in bind items for XML cursor adapters. -->
<declare-styleable name="CursorAdapter_BindItem">
<!-- The name of the column to bind from. Mandatory. -->
@@ -3763,7 +3768,7 @@
<attr name="to" format="reference" />
<!-- The type of binding. If this value is not specified, the type will be
inferred from the type of the "to" target view. Mandatory.
-
+
The type can be one of:
<ul>
<li>string, The content of the column is interpreted as a string.</li>
@@ -3776,7 +3781,7 @@
-->
<attr name="as" format="string" />
</declare-styleable>
-
+
<!-- Attributes used in select items for XML cursor adapters. -->
<declare-styleable name="CursorAdapter_SelectItem">
<!-- The name of the column to select. Mandatory. -->
@@ -3790,7 +3795,7 @@
<!-- The new value from the column. Mandatory. -->
<attr name="toValue" format="string" />
</declare-styleable>
-
+
<!-- Attributes used to map values to new values in XML cursor adapters' bind items. -->
<declare-styleable name="CursorAdapter_TransformItem">
<!-- The transformation expression. Mandatory if "withClass" is not specified. -->
diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml
index f36c473909dd..8b1c9d46f669 100644
--- a/core/res/res/values/public.xml
+++ b/core/res/res/values/public.xml
@@ -1178,7 +1178,7 @@
<public type="attr" name="colorBackgroundCacheHint" id="0x010102ab" />
<public type="attr" name="dropDownHorizontalOffset" id="0x010102ac" />
<public type="attr" name="dropDownVerticalOffset" id="0x010102ad" />
-
+
<public type="style" name="Theme.Wallpaper" id="0x0103005e" />
<public type="style" name="Theme.Wallpaper.NoTitleBar" id="0x0103005f" />
<public type="style" name="Theme.Wallpaper.NoTitleBar.Fullscreen" id="0x01030060" />
@@ -1186,7 +1186,7 @@
<public type="style" name="Theme.Light.WallpaperSettings" id="0x01030062" />
<public type="style" name="TextAppearance.SearchResult.Title" id="0x01030063" />
<public type="style" name="TextAppearance.SearchResult.Subtitle" id="0x01030064" />
-
+
<!-- Semi-transparent background that can be used when placing a dark
themed UI on top of some arbitrary background (such as the
wallpaper). This darkens the background sufficiently that the UI
@@ -1194,7 +1194,7 @@
<public type="drawable" name="screen_background_dark_transparent" id="0x010800a9" />
<public type="drawable" name="screen_background_light_transparent" id="0x010800aa" />
<public type="drawable" name="stat_notify_sdcard_prepare" id="0x010800ab" />
-
+
<!-- ===============================================================
Resources added in version 6 of the platform (Eclair 2.0.1).
=============================================================== -->
@@ -1206,7 +1206,7 @@
<public type="attr" name="quickContactBadgeStyleSmallWindowSmall" id="0x010102b1" />
<public type="attr" name="quickContactBadgeStyleSmallWindowMedium" id="0x010102b2" />
<public type="attr" name="quickContactBadgeStyleSmallWindowLarge" id="0x010102b3" />
-
+
<!-- ===============================================================
Resources added in version 7 of the platform (Eclair MR1).
=============================================================== -->
@@ -1215,7 +1215,7 @@
<public type="attr" name="author" id="0x010102b4" />
<public type="attr" name="autoStart" id="0x010102b5" />
-
+
<!-- ===============================================================
Resources added in version 8 of the platform (Eclair MR2).
=============================================================== -->
@@ -1236,9 +1236,9 @@
<public type="attr" name="tabStripEnabled" id="0x010102bd" />
<public type="id" name="custom" id="0x0102002b" />
-
+
<public type="anim" name="cycle_interpolator" id="0x010a000c" />
-
+
<!-- ===============================================================
Resources introduced in Gingerbread.
=============================================================== -->
@@ -1247,7 +1247,7 @@
<public type="attr" name="xlargeScreens" id="0x010102bf" />
<public type="attr" name="heavyWeight" id="0x010102c0" />
<public-padding type="attr" name="kraken_resource_pad" end="0x01010300" />
-
+
<public-padding type="id" name="kraken_resource_pad" end="0x01020040" />
<public-padding type="anim" name="kraken_resource_pad" end="0x010a0020" />
@@ -1257,9 +1257,9 @@
<public type="drawable" name="presence_video_online" id="0x010800ae" />
<public type="drawable" name="presence_audio_away" id="0x010800af" />
<public type="drawable" name="presence_audio_busy" id="0x010800b0" />
- <public type="drawable" name="presence_audio_online" id="0x010800b1" />
+ <public type="drawable" name="presence_audio_online" id="0x010800b1" />
<public-padding type="drawable" name="kraken_resource_pad" end="0x01080100" />
-
+
<public-padding type="style" name="kraken_resource_pad" end="0x01030090" />
<public-padding type="string" name="kraken_resource_pad" end="0x01040020" />
<public-padding type="integer" name="kraken_resource_pad" end="0x010e0010" />
@@ -1293,6 +1293,7 @@
<public type="attr" name="customNavigationLayout" />
<public type="attr" name="hardwareAccelerated" />
<public type="attr" name="measureWithLargestChild" />
+ <public type="attr" name="animateFirstView" />
<public type="id" name="home" />