diff options
author | Winson Chung <winsonc@google.com> | 2015-05-08 13:06:44 -0700 |
---|---|---|
committer | Winson Chung <winsonc@google.com> | 2015-05-08 21:41:40 +0000 |
commit | 9480415d9baf00ecfaac8ab3f608b16a1faa6518 (patch) | |
tree | d5c35dea3f60d64eaa926d48eb8094cd66deb115 /src/com/android/launcher3/widget | |
parent | 4e267f4cdca3ec52aa55982560551ea766adf9be (diff) | |
download | android_packages_apps_Trebuchet-9480415d9baf00ecfaac8ab3f608b16a1faa6518.tar.gz android_packages_apps_Trebuchet-9480415d9baf00ecfaac8ab3f608b16a1faa6518.tar.bz2 android_packages_apps_Trebuchet-9480415d9baf00ecfaac8ab3f608b16a1faa6518.zip |
Make common base class to update container bounds and to handle scroll logic.
Bug: 20763871
Change-Id: I8c2f45cfb10964e4be7e9c07c89dd336585c9989
Diffstat (limited to 'src/com/android/launcher3/widget')
-rw-r--r-- | src/com/android/launcher3/widget/WidgetsContainerRecyclerView.java | 58 | ||||
-rw-r--r-- | src/com/android/launcher3/widget/WidgetsContainerView.java | 24 |
2 files changed, 16 insertions, 66 deletions
diff --git a/src/com/android/launcher3/widget/WidgetsContainerRecyclerView.java b/src/com/android/launcher3/widget/WidgetsContainerRecyclerView.java index 65694bfaa..6f15324c1 100644 --- a/src/com/android/launcher3/widget/WidgetsContainerRecyclerView.java +++ b/src/com/android/launcher3/widget/WidgetsContainerRecyclerView.java @@ -17,26 +17,13 @@ package com.android.launcher3.widget; import android.content.Context; -import android.support.v7.widget.RecyclerView; import android.util.AttributeSet; -import android.view.MotionEvent; - -import com.android.launcher3.util.Thunk; +import com.android.launcher3.BaseContainerRecyclerView; /** * The widgets recycler view container. - * <p> - * Overwritten to NOT intercept a touch sequence that started when the {@link RecycleView} - * scrolling slowing down below the internally defined threshold. */ -public class WidgetsContainerRecyclerView extends RecyclerView - implements RecyclerView.OnItemTouchListener { - - private static final int SCROLL_DELTA_THRESHOLD = 4; - - /** Keeps the last known scrolling delta/velocity along y-axis. */ - @Thunk int mDy = 0; - private float mDeltaThreshold; +public class WidgetsContainerRecyclerView extends BaseContainerRecyclerView { public WidgetsContainerRecyclerView(Context context) { this(context, null); @@ -48,47 +35,6 @@ public class WidgetsContainerRecyclerView extends RecyclerView public WidgetsContainerRecyclerView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); - mDeltaThreshold = getResources().getDisplayMetrics().density * SCROLL_DELTA_THRESHOLD; - - ScrollListener listener = new ScrollListener(); - setOnScrollListener(listener); - } - - private class ScrollListener extends RecyclerView.OnScrollListener { - public ScrollListener() { - } - - @Override - public void onScrolled(RecyclerView recyclerView, int dx, int dy) { - mDy = dy; - } } - @Override - protected void onFinishInflate() { - super.onFinishInflate(); - addOnItemTouchListener(this); - } - - @Override - public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent ev) { - if (ev.getAction() == MotionEvent.ACTION_DOWN) { - if ((Math.abs(mDy) < mDeltaThreshold && - getScrollState() != RecyclerView.SCROLL_STATE_IDLE)) { - // now the touch events are being passed to the {@link WidgetCell} until the - // touch sequence goes over the touch slop. - stopScroll(); - } - } - return false; - } - - @Override - public void onTouchEvent(RecyclerView rv, MotionEvent ev) { - // Do nothing. - } - - public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) { - // DO NOT REMOVE, NEEDED IMPLEMENTATION FOR M BUILDS - } }
\ No newline at end of file diff --git a/src/com/android/launcher3/widget/WidgetsContainerView.java b/src/com/android/launcher3/widget/WidgetsContainerView.java index 22e29f304..439227f52 100644 --- a/src/com/android/launcher3/widget/WidgetsContainerView.java +++ b/src/com/android/launcher3/widget/WidgetsContainerView.java @@ -28,10 +28,9 @@ import android.support.v7.widget.RecyclerView.State; import android.util.AttributeSet; import android.util.Log; import android.view.View; -import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.Toast; - +import com.android.launcher3.BaseContainerView; import com.android.launcher3.CellLayout; import com.android.launcher3.DeleteDropTarget; import com.android.launcher3.DragController; @@ -55,8 +54,8 @@ import java.util.ArrayList; /** * The widgets list view container. */ -public class WidgetsContainerView extends FrameLayout implements Insettable, - View.OnLongClickListener, View.OnClickListener, DragSource{ +public class WidgetsContainerView extends BaseContainerView + implements View.OnLongClickListener, View.OnClickListener, DragSource{ private static final String TAG = "WidgetsContainerView"; private static final boolean DEBUG = false; @@ -129,6 +128,7 @@ public class WidgetsContainerView extends FrameLayout implements Insettable, }); mPadding.set(getPaddingLeft(), getPaddingTop(), getPaddingRight(), getPaddingBottom()); + onUpdatePaddings(); } // @@ -364,13 +364,17 @@ public class WidgetsContainerView extends FrameLayout implements Insettable, // Container rendering related. // - /* - * @see Insettable#setInsets(Rect) - */ @Override - public void setInsets(Rect insets) { - setPadding(mPadding.left + insets.left, mPadding.top + insets.top, - mPadding.right + insets.right, mPadding.bottom + insets.bottom); + protected void onUpdatePaddings() { + if (mFixedBounds.isEmpty()) { + // If there are no fixed bounds, then use the default padding and insets + setPadding(mPadding.left + mInsets.left, mPadding.top + mInsets.top, + mPadding.right + mInsets.right, mPadding.bottom + mInsets.bottom); + } else { + // If there are fixed bounds, then we update the padding to reflect the fixed bounds. + setPadding(mFixedBounds.left, mFixedBounds.top, getMeasuredWidth() - mFixedBounds.right, + mInsets.bottom); + } } /** |