diff options
author | Sunny Goyal <sunnygoyal@google.com> | 2017-06-23 16:12:50 -0700 |
---|---|---|
committer | Sunny Goyal <sunnygoyal@google.com> | 2017-06-26 14:56:36 -0700 |
commit | 89d5c5a31bd6cf4caf815b680ec670896b91803d (patch) | |
tree | b9d0a9a9fd6dec880fb6076bc2b8d4f38870839f /src/com/android/launcher3/allapps/search | |
parent | bbe504d24d5e0757d1a7772af822b7a6e274c9b4 (diff) | |
download | android_packages_apps_Trebuchet-89d5c5a31bd6cf4caf815b680ec670896b91803d.tar.gz android_packages_apps_Trebuchet-89d5c5a31bd6cf4caf815b680ec670896b91803d.tar.bz2 android_packages_apps_Trebuchet-89d5c5a31bd6cf4caf815b680ec670896b91803d.zip |
Updating fast scrollbar UI in Landscape
Creating a separate view for FastScrollBar and moving all the relavant logic in
the view.
For protrait, the touch handling is delegated by the recycler view just like before.
For landscape, the dcrollbar does not overlay with recyclerView and handles the touch
itself
Bug: 37015359
Change-Id: Ie1981326457ba739bdf0ac8063db1065f395f133
Diffstat (limited to 'src/com/android/launcher3/allapps/search')
-rw-r--r-- | src/com/android/launcher3/allapps/search/AppsSearchContainerLayout.java | 12 | ||||
-rw-r--r-- | src/com/android/launcher3/allapps/search/HeaderElevationController.java | 32 |
2 files changed, 32 insertions, 12 deletions
diff --git a/src/com/android/launcher3/allapps/search/AppsSearchContainerLayout.java b/src/com/android/launcher3/allapps/search/AppsSearchContainerLayout.java index 3f06ec9dd..5cb12d592 100644 --- a/src/com/android/launcher3/allapps/search/AppsSearchContainerLayout.java +++ b/src/com/android/launcher3/allapps/search/AppsSearchContainerLayout.java @@ -54,12 +54,13 @@ public class AppsSearchContainerLayout extends FrameLayout private final int mSearchBoxHeight; private final AllAppsSearchBarController mSearchBarController; private final SpannableStringBuilder mSearchQueryBuilder; - private final HeaderElevationController mElevationController; private ExtendedEditText mSearchInput; private AlphabeticalAppsList mApps; private AllAppsRecyclerView mAppsRecyclerView; private AllAppsGridAdapter mAdapter; + private View mDivider; + private HeaderElevationController mElevationController; public AppsSearchContainerLayout(Context context) { this(context, null); @@ -77,7 +78,6 @@ public class AppsSearchContainerLayout extends FrameLayout mSearchBoxHeight = getResources() .getDimensionPixelSize(R.dimen.all_apps_search_bar_field_height); mSearchBarController = new AllAppsSearchBarController(); - mElevationController = new HeaderElevationController(this); mSearchQueryBuilder = new SpannableStringBuilder(); Selection.setSelection(mSearchQueryBuilder, 0); @@ -87,6 +87,8 @@ public class AppsSearchContainerLayout extends FrameLayout protected void onFinishInflate() { super.onFinishInflate(); mSearchInput = findViewById(R.id.search_box_input); + mDivider = findViewById(R.id.search_divider); + mElevationController = new HeaderElevationController(mDivider); // Update the hint to contain the icon. // Prefix the original hint with two spaces. The first space gets replaced by the icon @@ -96,6 +98,12 @@ public class AppsSearchContainerLayout extends FrameLayout spanned.setSpan(new TintedDrawableSpan(getContext(), R.drawable.ic_allapps_search), 0, 1, Spannable.SPAN_EXCLUSIVE_INCLUSIVE); mSearchInput.setHint(spanned); + + DeviceProfile dp = mLauncher.getDeviceProfile(); + if (!dp.isVerticalBarLayout()) { + LayoutParams lp = (LayoutParams) mDivider.getLayoutParams(); + lp.leftMargin = lp.rightMargin = dp.edgeMarginPx; + } } @Override diff --git a/src/com/android/launcher3/allapps/search/HeaderElevationController.java b/src/com/android/launcher3/allapps/search/HeaderElevationController.java index ab4e88fc8..7cd32b26e 100644 --- a/src/com/android/launcher3/allapps/search/HeaderElevationController.java +++ b/src/com/android/launcher3/allapps/search/HeaderElevationController.java @@ -4,11 +4,11 @@ import android.content.res.Resources; import android.graphics.Outline; import android.support.v7.widget.RecyclerView; import android.view.View; +import android.view.ViewGroup; import android.view.ViewOutlineProvider; import com.android.launcher3.BaseRecyclerView; import com.android.launcher3.R; -import com.android.launcher3.Utilities; /** * Helper class for controlling the header elevation in response to RecyclerView scroll. @@ -16,6 +16,7 @@ import com.android.launcher3.Utilities; public class HeaderElevationController extends RecyclerView.OnScrollListener { private final View mHeader; + private final View mHeaderChild; private final float mMaxElevation; private final float mScrollToElevation; @@ -28,23 +29,27 @@ public class HeaderElevationController extends RecyclerView.OnScrollListener { 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. + // The top, left and right edges are all extended out to match parent's edge, so that + // 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(); + // Set the left and top to be at the parents edge. Since the coordinates are + // relative to this view, + // (x = -view.getLeft()) for this view => (x = 0) for parent + final int left = -view.getLeft(); + final int top = -view.getTop(); - 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()); + // Since the view is centered align, the spacing on left and right are same. + // Add same spacing on the right to reach parent's edge. + final int right = view.getWidth() - left; + final int bottom = view.getHeight(); + final int offset = (int) mMaxElevation; outline.setRect(left - offset, top - offset, right + offset, bottom); } }; mHeader.setOutlineProvider(vop); + mHeaderChild = ((ViewGroup) mHeader).getChildAt(0); } public void reset() { @@ -63,6 +68,13 @@ public class HeaderElevationController extends RecyclerView.OnScrollListener { float newElevation = mMaxElevation * elevationPct; if (Float.compare(mHeader.getElevation(), newElevation) != 0) { mHeader.setElevation(newElevation); + + // To simulate a scrolling effect for the header, we translate the header down, and + // its content up by the same amount, so that it gets clipped by the parent, making it + // look like the content was scrolled out of the view. + int shift = Math.min(mHeader.getHeight(), scrollY); + mHeader.setTranslationY(-shift); + mHeaderChild.setTranslationY(shift); } } |