From a524ae57ec8fce9532ed998c63a5577fce738fd5 Mon Sep 17 00:00:00 2001 From: Yorke Lee Date: Tue, 5 Aug 2014 18:01:05 -0700 Subject: Fix some action bar logic * Restore action bar slid state only after onCreateOptionsMenu, when it has an effect * ActionBarController is now the only way to make changes to the offset of the action bar so that it can appropriately restore its state Bug: 16710397 Change-Id: Id9e0ebe210c89df0be56b32aa3bbd959cce88621 --- src/com/android/dialer/DialtactsActivity.java | 3 +- src/com/android/dialer/list/ListsFragment.java | 4 +- .../android/dialer/widget/ActionBarController.java | 84 ++++++++++------------ 3 files changed, 41 insertions(+), 50 deletions(-) (limited to 'src/com/android') diff --git a/src/com/android/dialer/DialtactsActivity.java b/src/com/android/dialer/DialtactsActivity.java index 7d4e2d0aa..8033909df 100644 --- a/src/com/android/dialer/DialtactsActivity.java +++ b/src/com/android/dialer/DialtactsActivity.java @@ -755,6 +755,7 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O mSearchView.setText(mPendingSearchViewQuery); mPendingSearchViewQuery = null; } + mActionBarController.restoreActionBarOffset(); return false; } @@ -1155,7 +1156,7 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O @Override public void setActionBarHideOffset(int hideOffset) { - getActionBar().setHideOffset(hideOffset); + mActionBarController.setHideOffset(hideOffset); } /** diff --git a/src/com/android/dialer/list/ListsFragment.java b/src/com/android/dialer/list/ListsFragment.java index 8ca66cf3f..b214836cf 100644 --- a/src/com/android/dialer/list/ListsFragment.java +++ b/src/com/android/dialer/list/ListsFragment.java @@ -76,6 +76,7 @@ public class ListsFragment extends AnalyticsFragment implements CallLogQueryHand public interface HostInterface { public void showCallHistory(); public int getActionBarHeight(); + public void setActionBarHideOffset(int offset); } private ActionBar mActionBar; @@ -152,7 +153,8 @@ public class ListsFragment extends AnalyticsFragment implements CallLogQueryHand final int availableActionBarHeight = Math.min(mActionBar.getHeight(), topPaneHeight); - mActionBar.setHideOffset(mActionBar.getHeight() - availableActionBarHeight); + ((HostInterface) getActivity()).setActionBarHideOffset( + mActionBar.getHeight() - availableActionBarHeight); if (!mActionBar.isShowing()) { mActionBar.show(); diff --git a/src/com/android/dialer/widget/ActionBarController.java b/src/com/android/dialer/widget/ActionBarController.java index 4f1e2e600..265c03f6f 100644 --- a/src/com/android/dialer/widget/ActionBarController.java +++ b/src/com/android/dialer/widget/ActionBarController.java @@ -4,6 +4,7 @@ import com.google.common.annotations.VisibleForTesting; import android.animation.ValueAnimator; import android.animation.ValueAnimator.AnimatorUpdateListener; +import android.app.ActionBar; import android.os.Bundle; import android.util.Log; @@ -31,12 +32,12 @@ public class ActionBarController { private final AnimationCallback mFadeOutCallback = new AnimationCallback() { @Override public void onAnimationEnd() { - slideActionBarUp(false); + slideActionBar(true /* slideUp */, false /* animate */); } @Override public void onAnimationCancel() { - slideActionBarUp(false); + slideActionBar(true /* slideUp */, false /* animate */); } }; @@ -45,8 +46,7 @@ public class ActionBarController { public boolean hasSearchQuery(); public boolean shouldShowActionBar(); public int getActionBarHeight(); - public int getActionBarHideOffset(); - public void setActionBarHideOffset(int hideOffset); + public ActionBar getActionBar(); } public ActionBarController(ActivityUi activityUi, SearchEditTextLayout searchBox) { @@ -54,13 +54,6 @@ public class ActionBarController { mSearchBox = searchBox; } - /** - * @return The offset the action bar is being translated upwards by - */ - public int getHideOffset() { - return mActivityUi.getActionBarHideOffset(); - } - /** * @return Whether or not the action bar is currently showing (both slid down and visible) */ @@ -97,9 +90,9 @@ public class ActionBarController { } if (mActivityUi.shouldShowActionBar()) { - slideActionBarDown(false /* animate */); + slideActionBar(false /* slideUp */, false /* animate */); } else { - slideActionBarUp(false /* animate */); + slideActionBar(true /* slideUp */, false /* animate */); } } @@ -122,7 +115,7 @@ public class ActionBarController { if (!mSearchBox.isExpanded()) { mSearchBox.expand(false /* animate */, false /* requestFocus */); } - slideActionBarDown(true /* animate */); + slideActionBar(false /* slideUp */, true /* animate */); } else { mSearchBox.fadeIn(); } @@ -138,59 +131,51 @@ public class ActionBarController { Log.d(TAG, "OnDialpadUp: isInSearchUi " + mActivityUi.isInSearchUi()); } if (mActivityUi.isInSearchUi()) { - slideActionBarUp(true); + slideActionBar(true /* slideUp */, true /* animate */); } else { // From the lists fragment mSearchBox.fadeOut(mFadeOutCallback); } } - public void slideActionBarUp(boolean animate) { + public void slideActionBar(boolean slideUp, boolean animate) { if (DEBUG) { - Log.d(TAG, "Sliding actionBar up - animate: " + animate); + Log.d(TAG, "Sliding actionBar - up: " + slideUp + " animate: " + animate); } if (animate) { - ValueAnimator animator = ValueAnimator.ofFloat(0, 1); + ValueAnimator animator = + slideUp ? ValueAnimator.ofFloat(0, 1) : ValueAnimator.ofFloat(1, 0); animator.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { final float value = (float) animation.getAnimatedValue(); - mActivityUi.setActionBarHideOffset( + setHideOffset( (int) (mActivityUi.getActionBarHeight() * value)); } }); animator.start(); } else { - mActivityUi.setActionBarHideOffset(mActivityUi.getActionBarHeight()); + setHideOffset(slideUp ? mActivityUi.getActionBarHeight() : 0); } - mIsActionBarSlidUp = true; - } - - public void slideActionBarDown(boolean animate) { - if (DEBUG) { - Log.d(TAG, "Sliding actionBar down - animate: " + animate); - } - if (animate) { - ValueAnimator animator = ValueAnimator.ofFloat(1, 0); - animator.addUpdateListener(new AnimatorUpdateListener() { - @Override - public void onAnimationUpdate(ValueAnimator animation) { - final float value = (float) animation.getAnimatedValue(); - mActivityUi.setActionBarHideOffset( - (int) (mActivityUi.getActionBarHeight() * value)); - } - }); - animator.start(); - } else { - mActivityUi.setActionBarHideOffset(0); - } - mIsActionBarSlidUp = false; + mIsActionBarSlidUp = slideUp; } public void setAlpha(float alphaValue) { mSearchBox.animate().alpha(alphaValue).start(); } + public void setHideOffset(int offset) { + mIsActionBarSlidUp = offset >= mActivityUi.getActionBarHeight(); + mActivityUi.getActionBar().setHideOffset(offset); + } + + /** + * @return The offset the action bar is being translated upwards by + */ + public int getHideOffset() { + return mActivityUi.getActionBar().getHideOffset(); + } + /** * Saves the current state of the action bar into a provided {@link Bundle} */ @@ -201,15 +186,10 @@ public class ActionBarController { } /** - * Restores the action bar state from a provided {@link Bundle} + * Restores the action bar state from a provided {@link Bundle}. */ public void restoreInstanceState(Bundle inState) { mIsActionBarSlidUp = inState.getBoolean(KEY_IS_SLID_UP); - if (mIsActionBarSlidUp) { - slideActionBarUp(false); - } else { - slideActionBarDown(false); - } final boolean isSearchBoxFadedOut = inState.getBoolean(KEY_IS_FADED_OUT); if (isSearchBoxFadedOut) { @@ -230,6 +210,14 @@ public class ActionBarController { } } + /** + * This should be called after onCreateOptionsMenu has been called, when the actionbar has + * been laid out and actually has a height. + */ + public void restoreActionBarOffset() { + slideActionBar(mIsActionBarSlidUp /* slideUp */, false /* animate */); + } + @VisibleForTesting public boolean getIsActionBarSlidUp() { return mIsActionBarSlidUp; -- cgit v1.2.3