diff options
author | cretin45 <cretin45@gmail.com> | 2016-02-04 10:44:37 -0800 |
---|---|---|
committer | Tom Powell <zifnab@zifnab06.net> | 2017-03-26 16:15:26 -0700 |
commit | 1a521271a30660a3c1003a012b2f8e6ae6681038 (patch) | |
tree | 8f4524c7357d7b9d3552019f69967deb7de29db7 /src | |
parent | 44432c59564135ee767283ef961ca84a371981f4 (diff) | |
download | android_packages_apps_Trebuchet-1a521271a30660a3c1003a012b2f8e6ae6681038.tar.gz android_packages_apps_Trebuchet-1a521271a30660a3c1003a012b2f8e6ae6681038.tar.bz2 android_packages_apps_Trebuchet-1a521271a30660a3c1003a012b2f8e6ae6681038.zip |
Trebuchet: Don't zoom icons on fast scroll
Issue-id: OPO-424
Change-Id: I2da15761896e5cdaa2cd622086206dbbb9c88bee
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/launcher3/BaseRecyclerViewFastScrollBar.java | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/src/com/android/launcher3/BaseRecyclerViewFastScrollBar.java b/src/com/android/launcher3/BaseRecyclerViewFastScrollBar.java index e7b79927a..2b3217c36 100644 --- a/src/com/android/launcher3/BaseRecyclerViewFastScrollBar.java +++ b/src/com/android/launcher3/BaseRecyclerViewFastScrollBar.java @@ -41,6 +41,122 @@ public class BaseRecyclerViewFastScrollBar { void setFastScrollDimmed(boolean dimmed, boolean animated); } + /** + * Helper class to apply fast scroll focus functionality to any view. + */ + public static class FastScrollFocusApplicator implements FastScrollFocusable { + private static final int FAST_SCROLL_FOCUS_FADE_IN_DURATION = 175; + private static final int FAST_SCROLL_FOCUS_FADE_OUT_DURATION = 125; + private static final float FAST_SCROLL_FOCUS_MAX_SCALE = 1f; + + private final View mView; + private final int mFastScrollMode; + + private ObjectAnimator mFastScrollFocusAnimator; + private ObjectAnimator mFastScrollDimAnimator; + private boolean mFastScrollFocused; + private boolean mFastScrollDimmed; + + public static void createApplicator(final View v, int mode) { + FastScrollFocusApplicator applicator = new FastScrollFocusApplicator(v, mode); + v.setTag(R.id.fast_scroll_focus_applicator_tag, applicator); + } + + public static void setFastScrollFocused(final View v, boolean focused, boolean animated) { + FastScrollFocusable focusable = getFromView(v); + if (focusable == null) return; + + focusable.setFastScrollFocused(focused, animated); + } + + public static void setFastScrollDimmed(final View v, boolean dimmed, boolean animated) { + FastScrollFocusable focusable = getFromView(v); + if (focusable == null) return; + + focusable.setFastScrollDimmed(dimmed, animated); + } + + private static FastScrollFocusable getFromView(final View v) { + Object tag = v.getTag(R.id.fast_scroll_focus_applicator_tag); + if (tag != null) { + return (FastScrollFocusApplicator) tag; + } + return null; + } + + private FastScrollFocusApplicator(final View v, final int mode) { + mView = v; + mFastScrollMode = mode; + } + + public void setFastScrollFocused(boolean focused, boolean animated) { + if ((mFastScrollMode & FAST_SCROLL_FOCUS_SCALABLE) == 0) { + return; + } + + if (mFastScrollFocused != focused) { + mFastScrollFocused = focused; + + if (animated) { + // Clean up the previous focus animator + if (mFastScrollFocusAnimator != null) { + mFastScrollFocusAnimator.cancel(); + } + + // Setup animator for bi-directional scaling. + float value = focused ? FAST_SCROLL_FOCUS_MAX_SCALE : 1f; + PropertyValuesHolder pvhScaleX = + PropertyValuesHolder.ofFloat(View.SCALE_X, value); + PropertyValuesHolder pvhScaleY = + PropertyValuesHolder.ofFloat(View.SCALE_Y, value); + mFastScrollFocusAnimator = ObjectAnimator.ofPropertyValuesHolder(mView, + pvhScaleX, pvhScaleY); + + if (focused) { + mFastScrollFocusAnimator.setInterpolator(new DecelerateInterpolator()); + } else { + mFastScrollFocusAnimator.setInterpolator(new AccelerateInterpolator()); + } + mFastScrollFocusAnimator.setDuration(focused ? + FAST_SCROLL_FOCUS_FADE_IN_DURATION : FAST_SCROLL_FOCUS_FADE_OUT_DURATION); + mFastScrollFocusAnimator.start(); + } + } + + // Let the view do any additional operations if it wants. + if (mView instanceof FastScrollFocusable) { + ((FastScrollFocusable) mView).setFastScrollFocused(focused, animated); + } + } + + public void setFastScrollDimmed(boolean dimmed, boolean animated) { + if ((mFastScrollMode & FAST_SCROLL_FOCUS_DIMMABLE) == 0) { + return; + } + + if (!animated) { + mFastScrollDimmed = dimmed; + mView.setAlpha(dimmed ? 0.4f : 1f); + } else if (mFastScrollDimmed != dimmed) { + mFastScrollDimmed = dimmed; + + // Clean up the previous dim animator + if (mFastScrollDimAnimator != null) { + mFastScrollDimAnimator.cancel(); + } + mFastScrollDimAnimator = ObjectAnimator.ofFloat(mView, View.ALPHA, dimmed ? 0.4f : 1f); + mFastScrollDimAnimator.setDuration(dimmed ? + FAST_SCROLL_FOCUS_FADE_IN_DURATION : FAST_SCROLL_FOCUS_FADE_OUT_DURATION); + mFastScrollDimAnimator.start(); + } + + // Let the view do any additional operations if it wants. + if (mView instanceof FastScrollFocusable) { + ((FastScrollFocusable) mView).setFastScrollDimmed(dimmed, animated); + } + } + } + private final static int MAX_TRACK_ALPHA = 30; private final static int SCROLL_BAR_VIS_DURATION = 150; |