diff options
author | Yorke Lee <yorkelee@google.com> | 2014-08-06 20:54:15 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-08-05 00:19:02 +0000 |
commit | eefa1c9abd925709356758b64cdca930abc44621 (patch) | |
tree | 2ac00ac6b0ec7ad35e8ddb7dc2baf7f0dda395b4 /src | |
parent | 60df037df56f025e05a8918e13c27479226667ea (diff) | |
parent | a524ae57ec8fce9532ed998c63a5577fce738fd5 (diff) |
Merge "Fix some action bar logic" into lmp-dev
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/dialer/DialtactsActivity.java | 3 | ||||
-rw-r--r-- | src/com/android/dialer/list/ListsFragment.java | 4 | ||||
-rw-r--r-- | src/com/android/dialer/widget/ActionBarController.java | 84 |
3 files changed, 41 insertions, 50 deletions
diff --git a/src/com/android/dialer/DialtactsActivity.java b/src/com/android/dialer/DialtactsActivity.java index 7a9c4c2bb..cb01e8ef0 100644 --- a/src/com/android/dialer/DialtactsActivity.java +++ b/src/com/android/dialer/DialtactsActivity.java @@ -761,6 +761,7 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O mSearchView.setText(mPendingSearchViewQuery); mPendingSearchViewQuery = null; } + mActionBarController.restoreActionBarOffset(); return false; } @@ -1160,7 +1161,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 04e8d8f2a..966d265dd 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) { @@ -55,13 +55,6 @@ public class ActionBarController { } /** - * @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) */ public boolean isActionBarShowing() { @@ -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; |