Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f70036bc authored by Mason Tang's avatar Mason Tang
Browse files

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
parent 820c12c9
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -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"
+30 −11
Original line number Diff line number Diff line
@@ -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);
@@ -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) {
+15 −3
Original line number Diff line number Diff line
@@ -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 {
+23 −18
Original line number Diff line number Diff line
@@ -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" />
+11 −10
Original line number Diff line number Diff line
@@ -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" />