summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJin Cao <jinyan@google.com>2014-10-14 01:36:45 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2014-10-14 01:36:45 +0000
commit8d5f3c383c7440c2184163f66b0b4f7ddaf70a03 (patch)
treedc418aa70038bc981a766e726ec1599a34a71579 /src
parent351fe6f75e1f652a038c7643d0cef94b9b89f941 (diff)
parent7b45ff8538067edafe6b3d445e3880cd4858d267 (diff)
downloadandroid_packages_apps_UnifiedEmail-8d5f3c383c7440c2184163f66b0b4f7ddaf70a03.tar.gz
android_packages_apps_UnifiedEmail-8d5f3c383c7440c2184163f66b0b4f7ddaf70a03.tar.bz2
android_packages_apps_UnifiedEmail-8d5f3c383c7440c2184163f66b0b4f7ddaf70a03.zip
Merge "Fade in/out the search bar" into ub-gmail-ur14-dev
Diffstat (limited to 'src')
-rw-r--r--src/com/android/mail/ui/ActivityController.java4
-rw-r--r--src/com/android/mail/ui/MaterialSearchViewController.java139
-rw-r--r--src/com/android/mail/ui/OnePaneController.java4
-rw-r--r--src/com/android/mail/ui/TwoPaneController.java7
4 files changed, 109 insertions, 45 deletions
diff --git a/src/com/android/mail/ui/ActivityController.java b/src/com/android/mail/ui/ActivityController.java
index 3ccdad3f3..ac6b518a5 100644
--- a/src/com/android/mail/ui/ActivityController.java
+++ b/src/com/android/mail/ui/ActivityController.java
@@ -274,8 +274,10 @@ public interface ActivityController extends LayoutListener,
/**
* If the search bar should always be visible on top of the screen (e.g. search result list).
+ * @param viewMode the new view mode. This is passed as a parameter because we don't know
+ * which onViewModeChanged callback gets called first, so the view modes might differ.
*/
- boolean shouldShowSearchBarByDefault();
+ boolean shouldShowSearchBarByDefault(int viewMode);
/**
* If we should show the search menu item.
diff --git a/src/com/android/mail/ui/MaterialSearchViewController.java b/src/com/android/mail/ui/MaterialSearchViewController.java
index 8d8966caa..9e03a6607 100644
--- a/src/com/android/mail/ui/MaterialSearchViewController.java
+++ b/src/com/android/mail/ui/MaterialSearchViewController.java
@@ -17,6 +17,8 @@
package com.android.mail.ui;
+import android.animation.Animator;
+import android.animation.AnimatorListenerAdapter;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
@@ -39,6 +41,8 @@ import java.util.Locale;
*/
public class MaterialSearchViewController implements ViewMode.ModeChangeListener,
TwoPaneLayout.ConversationListLayoutListener {
+ private static final long FADE_IN_OUT_DURATION_MS = 150;
+
// The controller is not in search mode. Both search action bar and the suggestion list
// are not visible to the user.
public static final int SEARCH_VIEW_STATE_GONE = 0;
@@ -112,13 +116,15 @@ public class MaterialSearchViewController implements ViewMode.ModeChangeListener
@Override
public void onViewModeChanged(int newMode) {
+ final int oldMode = mViewMode;
mViewMode = newMode;
- if (mController.shouldShowSearchBarByDefault()) {
- showSearchActionBar(SEARCH_VIEW_STATE_ONLY_ACTIONBAR);
- } else if (mViewMode == 0) {
- showSearchActionBar(mControllerState);
+ // Never animate visibility changes that are caused by view state changes.
+ if (mController.shouldShowSearchBarByDefault(mViewMode)) {
+ showSearchActionBar(SEARCH_VIEW_STATE_ONLY_ACTIONBAR, false /* animate */);
+ } else if (oldMode == ViewMode.UNKNOWN) {
+ showSearchActionBar(mControllerState, false /* animate */);
} else {
- showSearchActionBar(SEARCH_VIEW_STATE_GONE);
+ showSearchActionBar(SEARCH_VIEW_STATE_GONE, false /* animate */);
}
}
@@ -129,16 +135,17 @@ public class MaterialSearchViewController implements ViewMode.ModeChangeListener
// This is called when we get into tablet landscape mode
mEndXCoordForTabletLandscape = xEnd;
if (ViewMode.isSearchMode(mViewMode)) {
- final int defaultVisibility = mController.shouldShowSearchBarByDefault() ?
+ final int defaultVisibility = mController.shouldShowSearchBarByDefault(mViewMode) ?
View.VISIBLE : View.GONE;
- mSearchActionView.setVisibility(drawerOpen ? View.INVISIBLE : defaultVisibility);
+ setViewVisibilityAndAlpha(mSearchActionView,
+ drawerOpen ? View.INVISIBLE : defaultVisibility);
}
adjustViewForTwoPaneLandscape();
}
}
public boolean handleBackPress() {
- final boolean shouldShowSearchBar = mController.shouldShowSearchBarByDefault();
+ final boolean shouldShowSearchBar = mController.shouldShowSearchBarByDefault(mViewMode);
if (shouldShowSearchBar && mSearchSuggestionList.isShown()) {
showSearchActionBar(SEARCH_VIEW_STATE_ONLY_ACTIONBAR);
return true;
@@ -149,41 +156,97 @@ public class MaterialSearchViewController implements ViewMode.ModeChangeListener
return false;
}
- // Should use the view states specified in MaterialSearchViewController
+ /**
+ * Set the new visibility state of the search controller.
+ * @param state the new view state, must be one of the following options:
+ * {@link MaterialSearchViewController#SEARCH_VIEW_STATE_ONLY_ACTIONBAR},
+ * {@link MaterialSearchViewController#SEARCH_VIEW_STATE_VISIBLE},
+ * {@link MaterialSearchViewController#SEARCH_VIEW_STATE_GONE},
+ */
public void showSearchActionBar(int state) {
- if (mControllerState != state) {
- mControllerState = state;
-
- // ACTIONBAR is only applicable in search mode
- final boolean onlyActionBar = state == SEARCH_VIEW_STATE_ONLY_ACTIONBAR &&
- mController.shouldShowSearchBarByDefault();
- final boolean isStateVisible = state == SEARCH_VIEW_STATE_VISIBLE;
-
- final boolean isSearchBarVisible = isStateVisible || onlyActionBar;
- mSearchActionView.setVisibility(isSearchBarVisible ? View.VISIBLE : View.GONE);
- mSearchSuggestionList.setVisibility(isStateVisible ? View.VISIBLE : View.GONE);
- mSearchActionView.focusSearchBar(isStateVisible);
-
- final boolean useDefaultColor = !isSearchBarVisible || shouldAlignWithTl();
- final int statusBarColor = useDefaultColor ? R.color.mail_activity_status_bar_color :
- R.color.search_status_bar_color;
- ViewUtils.setStatusBarColor(mActivity, statusBarColor);
-
- // Specific actions for each view state
- if (onlyActionBar) {
- adjustViewForTwoPaneLandscape();
- } else if (isStateVisible) {
- // Set to default layout/assets
- mSearchActionView.adjustViewForTwoPaneLandscape(false /* do not align */, 0);
- } else {
- // For non-search view mode, clear the query term for search
- if (!ViewMode.isSearchMode(mViewMode)) {
- mSearchActionView.clearSearchQuery();
- }
+ // By default animate the visibility changes
+ showSearchActionBar(state, true /* animate */);
+ }
+
+ /**
+ * @param animate if true, the search bar and suggestion list will fade in/out of view.
+ */
+ public void showSearchActionBar(int state, boolean animate) {
+ mControllerState = state;
+
+ // ACTIONBAR is only applicable in search mode
+ final boolean onlyActionBar = state == SEARCH_VIEW_STATE_ONLY_ACTIONBAR &&
+ mController.shouldShowSearchBarByDefault(mViewMode);
+ final boolean isStateVisible = state == SEARCH_VIEW_STATE_VISIBLE;
+
+ final boolean isSearchBarVisible = isStateVisible || onlyActionBar;
+
+ final int searchBarVisibility = isSearchBarVisible ? View.VISIBLE : View.GONE;
+ final int suggestionListVisibility = isStateVisible ? View.VISIBLE : View.GONE;
+ if (animate) {
+ fadeInOutView(mSearchActionView, searchBarVisibility);
+ fadeInOutView(mSearchSuggestionList, suggestionListVisibility);
+ } else {
+ setViewVisibilityAndAlpha(mSearchActionView, searchBarVisibility);
+ setViewVisibilityAndAlpha(mSearchSuggestionList, suggestionListVisibility);
+ }
+ mSearchActionView.focusSearchBar(isStateVisible);
+
+ final boolean useDefaultColor = !isSearchBarVisible || shouldAlignWithTl();
+ final int statusBarColor = useDefaultColor ? R.color.mail_activity_status_bar_color :
+ R.color.search_status_bar_color;
+ ViewUtils.setStatusBarColor(mActivity, statusBarColor);
+
+ // Specific actions for each view state
+ if (onlyActionBar) {
+ adjustViewForTwoPaneLandscape();
+ } else if (isStateVisible) {
+ // Set to default layout/assets
+ mSearchActionView.adjustViewForTwoPaneLandscape(false /* do not align */, 0);
+ } else {
+ // For non-search view mode, clear the query term for search
+ if (!ViewMode.isSearchMode(mViewMode)) {
+ mSearchActionView.clearSearchQuery();
}
}
}
+ /**
+ * Helper function to fade in/out the provided view by animating alpha.
+ */
+ private void fadeInOutView(final View v, final int visibility) {
+ if (visibility == View.VISIBLE) {
+ v.setVisibility(View.VISIBLE);
+ v.animate()
+ .alpha(1f)
+ .setDuration(FADE_IN_OUT_DURATION_MS)
+ .setListener(null);
+ } else {
+ v.animate()
+ .alpha(0f)
+ .setDuration(FADE_IN_OUT_DURATION_MS)
+ .setListener(new AnimatorListenerAdapter() {
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ v.setVisibility(visibility);
+ }
+ });
+ }
+ }
+
+ /**
+ * Sets the view's visibility and alpha so that we are guaranteed that alpha = 1 when the view
+ * is visible, and alpha = 0 otherwise.
+ */
+ private void setViewVisibilityAndAlpha(View v, int visibility) {
+ v.setVisibility(visibility);
+ if (visibility == View.VISIBLE) {
+ v.setAlpha(1f);
+ } else {
+ v.setAlpha(0f);
+ }
+ }
+
private boolean shouldAlignWithTl() {
return mController.isTwoPaneLandscape() &&
mControllerState == SEARCH_VIEW_STATE_ONLY_ACTIONBAR &&
diff --git a/src/com/android/mail/ui/OnePaneController.java b/src/com/android/mail/ui/OnePaneController.java
index fb6c0c835..582daeeac 100644
--- a/src/com/android/mail/ui/OnePaneController.java
+++ b/src/com/android/mail/ui/OnePaneController.java
@@ -547,8 +547,8 @@ public final class OnePaneController extends AbstractActivityController {
}
@Override
- public boolean shouldShowSearchBarByDefault() {
- return mViewMode.getMode() == ViewMode.SEARCH_RESULTS_LIST;
+ public boolean shouldShowSearchBarByDefault(int viewMode) {
+ return viewMode == ViewMode.SEARCH_RESULTS_LIST;
}
@Override
diff --git a/src/com/android/mail/ui/TwoPaneController.java b/src/com/android/mail/ui/TwoPaneController.java
index 6669adfae..61aa05a83 100644
--- a/src/com/android/mail/ui/TwoPaneController.java
+++ b/src/com/android/mail/ui/TwoPaneController.java
@@ -697,10 +697,9 @@ public final class TwoPaneController extends AbstractActivityController implemen
}
@Override
- public boolean shouldShowSearchBarByDefault() {
- final int mode = mViewMode.getMode();
- return mode == ViewMode.SEARCH_RESULTS_LIST ||
- (mIsTabletLandscape && mode == ViewMode.SEARCH_RESULTS_CONVERSATION);
+ public boolean shouldShowSearchBarByDefault(int viewMode) {
+ return viewMode == ViewMode.SEARCH_RESULTS_LIST ||
+ (mIsTabletLandscape && viewMode == ViewMode.SEARCH_RESULTS_CONVERSATION);
}
@Override