summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJin Cao <jinyan@google.com>2014-11-02 19:20:19 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2014-11-02 19:20:19 +0000
commit52d11950cd3e4dce0d4789de891c4b38c50b0591 (patch)
treead8054769d6a421bef7fbf1f99e97cc01772b214
parent97606782d951a5717b8ed2be205e55e9be60b8f2 (diff)
parent379898e75bedf2edc0607a1783156661a358dc47 (diff)
downloadUnifiedEmail-52d11950cd3e4dce0d4789de891c4b38c50b0591.tar.gz
am 379898e7: am fbb0c7f6: Cross-fade the drawer on toggle/drag
* commit '379898e75bedf2edc0607a1783156661a358dc47': Cross-fade the drawer on toggle/drag
-rw-r--r--src/com/android/mail/ui/FolderListFragment.java83
-rw-r--r--src/com/android/mail/ui/TwoPaneController.java12
-rw-r--r--src/com/android/mail/ui/TwoPaneLayout.java10
3 files changed, 97 insertions, 8 deletions
diff --git a/src/com/android/mail/ui/FolderListFragment.java b/src/com/android/mail/ui/FolderListFragment.java
index bd6d0544c..c631b6355 100644
--- a/src/com/android/mail/ui/FolderListFragment.java
+++ b/src/com/android/mail/ui/FolderListFragment.java
@@ -17,6 +17,8 @@
package com.android.mail.ui;
+import android.animation.Animator;
+import android.animation.AnimatorListenerAdapter;
import android.app.Activity;
import android.app.ListFragment;
import android.app.LoaderManager;
@@ -101,6 +103,9 @@ public class FolderListFragment extends ListFragment implements
LoaderManager.LoaderCallbacks<ObjectCursor<Folder>>,
FolderWatcher.UnreadCountChangedListener {
private static final String LOG_TAG = LogTag.getLogTag();
+ // Duration to fade alpha from 0 to 1 and vice versa.
+ private static final long DRAWER_FADE_VELOCITY_MS_PER_ALPHA = TwoPaneLayout.SLIDE_DURATION_MS;
+
/** The parent activity */
protected ControllableActivity mActivity;
/** The underlying list view */
@@ -215,6 +220,37 @@ public class FolderListFragment extends ListFragment implements
// TODO: but Material account switcher doesn't recycle...
private int mMiniDrawerAvatarDecodeSize;
+ private AnimatorListenerAdapter mMiniDrawerFadeOutListener = new AnimatorListenerAdapter() {
+ private boolean mCanceled;
+
+ @Override
+ public void onAnimationCancel(Animator animation) {
+ mCanceled = true;
+ }
+
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ if (!mCanceled) {
+ mMiniDrawerView.setVisibility(View.INVISIBLE);
+ }
+ }
+ };
+ private AnimatorListenerAdapter mListViewFadeOutListener = new AnimatorListenerAdapter() {
+ private boolean mCanceled;
+
+ @Override
+ public void onAnimationCancel(Animator animation) {
+ mCanceled = true;
+ }
+
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ if (!mCanceled) {
+ mListView.setVisibility(View.INVISIBLE);
+ }
+ }
+ };
+
/**
* Constructor needs to be public to handle orientation changes and activity lifecycle events.
*/
@@ -755,14 +791,61 @@ public class FolderListFragment extends ListFragment implements
if (isMinimized()) {
mMiniDrawerView.setVisibility(View.VISIBLE);
+ mMiniDrawerView.setAlpha(1f);
mListView.setVisibility(View.INVISIBLE);
+ mListView.setAlpha(0f);
} else {
mMiniDrawerView.setVisibility(View.INVISIBLE);
+ mMiniDrawerView.setAlpha(0f);
mListView.setVisibility(View.VISIBLE);
+ mListView.setAlpha(1f);
+ }
+ }
+
+ public void animateMinimized(boolean minimized) {
+ if (!mMiniDrawerEnabled) {
+ return;
+ }
+
+ mIsMinimized = minimized;
+
+ if (mIsMinimized) {
+ // From the current state (either maximized or partially dragged) to minimized.
+ final float startAlpha = mListView.getAlpha();
+ final long duration = (long) (startAlpha * DRAWER_FADE_VELOCITY_MS_PER_ALPHA);
+ mMiniDrawerView.setVisibility(View.VISIBLE);
+ mMiniDrawerView.animate()
+ .alpha(1f)
+ .setDuration(duration)
+ .setListener(null);
+ mListView.animate()
+ .alpha(0f)
+ .setDuration(duration)
+ .setListener(mListViewFadeOutListener);
+ } else {
+ // From the current state (either minimized or partially dragged) to maximized.
+ final float startAlpha = mMiniDrawerView.getAlpha();
+ final long duration = (long) (startAlpha * DRAWER_FADE_VELOCITY_MS_PER_ALPHA);
+ mMiniDrawerView.animate()
+ .alpha(0f)
+ .setDuration(duration)
+ .setListener(mMiniDrawerFadeOutListener);
+ mListView.setVisibility(View.VISIBLE);
+ mListView.animate()
+ .alpha(1f)
+ .setDuration(duration)
+ .setListener(null);
mListView.requestFocus();
}
}
+ public void onDrawerDrag(float percent) {
+ mMiniDrawerView.setAlpha(1f - percent);
+ mListView.setAlpha(percent);
+ mMiniDrawerView.setVisibility(View.VISIBLE);
+ mListView.setVisibility(View.VISIBLE);
+ }
+
/**
* Interface for all cursor adapters that allow setting a cursor and being destroyed.
*/
diff --git a/src/com/android/mail/ui/TwoPaneController.java b/src/com/android/mail/ui/TwoPaneController.java
index 61aa05a83..9136da098 100644
--- a/src/com/android/mail/ui/TwoPaneController.java
+++ b/src/com/android/mail/ui/TwoPaneController.java
@@ -282,7 +282,7 @@ public final class TwoPaneController extends AbstractActivityController implemen
return;
}
- flf.setMinimized(minimized);
+ flf.animateMinimized(minimized);
mLayout.animateDrawer(minimized);
resetActionBarIcon();
@@ -301,6 +301,16 @@ public final class TwoPaneController extends AbstractActivityController implemen
}
}
+ protected void onDrawerDrag(float percent) {
+ final FolderListFragment flf = getFolderListFragment();
+ if (flf == null) {
+ LogUtils.w(LOG_TAG, "no drawer to toggle open/closed");
+ return;
+ }
+
+ flf.onDrawerDrag(percent);
+ }
+
@Override
public boolean shouldPreventListSwipesEntirely() {
return isDrawerOpen();
diff --git a/src/com/android/mail/ui/TwoPaneLayout.java b/src/com/android/mail/ui/TwoPaneLayout.java
index 3b0e90874..72244a897 100644
--- a/src/com/android/mail/ui/TwoPaneLayout.java
+++ b/src/com/android/mail/ui/TwoPaneLayout.java
@@ -69,9 +69,9 @@ import com.google.common.collect.Lists;
final class TwoPaneLayout extends FrameLayout implements ModeChangeListener,
GmailDragHelper.GmailDragHelperCallback {
public static final int MISCELLANEOUS_VIEW_ID = R.id.miscellaneous_pane;
+ public static final long SLIDE_DURATION_MS = 300;
private static final String LOG_TAG = "TwoPaneLayout";
- private static final long SLIDE_DURATION_MS = 300;
private final int mDrawerWidthMini;
private final int mDrawerWidthOpen;
@@ -475,12 +475,7 @@ final class TwoPaneLayout extends FrameLayout implements ModeChangeListener,
@Override
public void onDragStarted() {
- if (!isDrawerOpen()) {
- final FolderListFragment flf = mController.getFolderListFragment();
- if (flf != null) {
- flf.setMinimized(!flf.isMinimized());
- }
- }
+ // Do nothing
}
@Override
@@ -492,6 +487,7 @@ final class TwoPaneLayout extends FrameLayout implements ModeChangeListener,
final float translationX = percentDragged *
(mIsRtl ? -mDrawerWidthDelta : mDrawerWidthDelta);
translatePanes(translationX, 0 /* drawerDeltaX */, false /* animate */);
+ mController.onDrawerDrag(percentDragged);
// Invalidate the entire drawers region to ensure that we don't get the "ghosts" of the
// fake shadow for pre-L.
if (mIsRtl) {