diff options
author | Sunny Goyal <sunnygoyal@google.com> | 2016-12-29 21:29:31 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2016-12-29 21:29:31 +0000 |
commit | c6b833dcbbbcfbca577705f69cfad1259c88b6e2 (patch) | |
tree | 38889fa9518034152f091599232c7f90cac7ba49 /src/com/android/launcher3/allapps | |
parent | c9c57631a985a8e1a4eac17ef0952bd344e281a2 (diff) | |
parent | a52ecb0390c85afb385371bb844bb496c59ddf87 (diff) | |
download | android_packages_apps_Trebuchet-c6b833dcbbbcfbca577705f69cfad1259c88b6e2.tar.gz android_packages_apps_Trebuchet-c6b833dcbbbcfbca577705f69cfad1259c88b6e2.tar.bz2 android_packages_apps_Trebuchet-c6b833dcbbbcfbca577705f69cfad1259c88b6e2.zip |
Merge "Removing all compatibility code below Lollipop" into ub-launcher3-master
Diffstat (limited to 'src/com/android/launcher3/allapps')
-rw-r--r-- | src/com/android/launcher3/allapps/AllAppsContainerView.java | 4 | ||||
-rw-r--r-- | src/com/android/launcher3/allapps/HeaderElevationController.java | 124 |
2 files changed, 37 insertions, 91 deletions
diff --git a/src/com/android/launcher3/allapps/AllAppsContainerView.java b/src/com/android/launcher3/allapps/AllAppsContainerView.java index 97e0d984a..a2266fef1 100644 --- a/src/com/android/launcher3/allapps/AllAppsContainerView.java +++ b/src/com/android/launcher3/allapps/AllAppsContainerView.java @@ -261,9 +261,7 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc 0, 1, Spannable.SPAN_EXCLUSIVE_INCLUSIVE); mSearchInput.setHint(spanned); - mElevationController = Utilities.ATLEAST_LOLLIPOP - ? new HeaderElevationController.ControllerVL(mSearchContainer) - : new HeaderElevationController.ControllerV16(mSearchContainer); + mElevationController = new HeaderElevationController(mSearchContainer); // Load the all apps recycler view mAppsRecyclerView = (AllAppsRecyclerView) findViewById(R.id.apps_list_view); diff --git a/src/com/android/launcher3/allapps/HeaderElevationController.java b/src/com/android/launcher3/allapps/HeaderElevationController.java index e79e5c762..b167fed33 100644 --- a/src/com/android/launcher3/allapps/HeaderElevationController.java +++ b/src/com/android/launcher3/allapps/HeaderElevationController.java @@ -1,16 +1,10 @@ package com.android.launcher3.allapps; -import android.annotation.TargetApi; import android.content.res.Resources; import android.graphics.Outline; -import android.graphics.Rect; -import android.graphics.drawable.GradientDrawable; -import android.os.Build; import android.support.v7.widget.RecyclerView; import android.view.View; -import android.view.ViewGroup; import android.view.ViewOutlineProvider; -import android.widget.FrameLayout; import com.android.launcher3.BaseRecyclerView; import com.android.launcher3.R; @@ -19,10 +13,40 @@ import com.android.launcher3.Utilities; /** * Helper class for controlling the header elevation in response to RecyclerView scroll. */ -public abstract class HeaderElevationController extends RecyclerView.OnScrollListener { +public class HeaderElevationController extends RecyclerView.OnScrollListener { + + private final View mHeader; + private final float mMaxElevation; + private final float mScrollToElevation; private int mCurrentY = 0; + public HeaderElevationController(View header) { + mHeader = header; + final Resources res = mHeader.getContext().getResources(); + mMaxElevation = res.getDimension(R.dimen.all_apps_header_max_elevation); + mScrollToElevation = res.getDimension(R.dimen.all_apps_header_scroll_to_elevation); + + // We need to provide a custom outline so the shadow only appears on the bottom edge. + // The top, left and right edges are all extended out, and the shadow is clipped + // by the parent. + final ViewOutlineProvider vop = new ViewOutlineProvider() { + @Override + public void getOutline(View view, Outline outline) { + final View parent = (View) mHeader.getParent(); + + final int left = parent.getLeft(); // Use the parent to account for offsets + final int top = view.getTop(); + final int right = left + view.getWidth(); + final int bottom = view.getBottom(); + + final int offset = Utilities.pxFromDp(mMaxElevation, res.getDisplayMetrics()); + outline.setRect(left - offset, top - offset, right + offset, bottom); + } + }; + mHeader.setOutlineProvider(vop); + } + public void reset() { mCurrentY = 0; onScroll(mCurrentY); @@ -34,88 +58,12 @@ public abstract class HeaderElevationController extends RecyclerView.OnScrollLis onScroll(mCurrentY); } - public void updateBackgroundPadding(Rect bgPadding) { } - - abstract void onScroll(int scrollY); - - public static class ControllerV16 extends HeaderElevationController { - - private final View mShadow; - private final float mScrollToElevation; - - public ControllerV16(View header) { - Resources res = header.getContext().getResources(); - mScrollToElevation = res.getDimension(R.dimen.all_apps_header_scroll_to_elevation); - - mShadow = new View(header.getContext()); - mShadow.setBackground(new GradientDrawable( - GradientDrawable.Orientation.TOP_BOTTOM, new int[] {0x1E000000, 0x00000000})); - mShadow.setAlpha(0); - - FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams( - FrameLayout.LayoutParams.MATCH_PARENT, - res.getDimensionPixelSize(R.dimen.all_apps_header_shadow_height)); - lp.topMargin = ((FrameLayout.LayoutParams) header.getLayoutParams()).height; - - ((ViewGroup) header.getParent()).addView(mShadow, lp); - } - - @Override - public void onScroll(int scrollY) { - float elevationPct = (float) Math.min(scrollY, mScrollToElevation) / - mScrollToElevation; - mShadow.setAlpha(elevationPct); - } - - @Override - public void updateBackgroundPadding(Rect bgPadding) { - FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mShadow.getLayoutParams(); - lp.leftMargin = bgPadding.left; - lp.rightMargin = bgPadding.right; - mShadow.requestLayout(); + private void onScroll(int scrollY) { + float elevationPct = Math.min(scrollY, mScrollToElevation) / mScrollToElevation; + float newElevation = mMaxElevation * elevationPct; + if (Float.compare(mHeader.getElevation(), newElevation) != 0) { + mHeader.setElevation(newElevation); } } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public static class ControllerVL extends HeaderElevationController { - - private final View mHeader; - private final float mMaxElevation; - private final float mScrollToElevation; - - public ControllerVL(View header) { - mHeader = header; - final Resources res = mHeader.getContext().getResources(); - mMaxElevation = res.getDimension(R.dimen.all_apps_header_max_elevation); - mScrollToElevation = res.getDimension(R.dimen.all_apps_header_scroll_to_elevation); - - // We need to provide a custom outline so the shadow only appears on the bottom edge. - // The top, left and right edges are all extended out, and the shadow is clipped - // by the parent. - final ViewOutlineProvider vop = new ViewOutlineProvider() { - @Override - public void getOutline(View view, Outline outline) { - final View parent = (View) mHeader.getParent(); - - final int left = parent.getLeft(); // Use the parent to account for offsets - final int top = view.getTop(); - final int right = left + view.getWidth(); - final int bottom = view.getBottom(); - - final int offset = Utilities.pxFromDp(mMaxElevation, res.getDisplayMetrics()); - outline.setRect(left - offset, top - offset, right + offset, bottom); - } - }; - mHeader.setOutlineProvider(vop); - } - - @Override - public void onScroll(int scrollY) { - float elevationPct = Math.min(scrollY, mScrollToElevation) / mScrollToElevation; - float newElevation = mMaxElevation * elevationPct; - if (Float.compare(mHeader.getElevation(), newElevation) != 0) { - mHeader.setElevation(newElevation); - } - } - } } |