Merge "Move TransformingTouchDelegate logic to BaseContainerView." into ub-launcher3-master

This commit is contained in:
Jonathan Miranda
2016-09-22 19:22:50 +00:00
committed by Android (Google) Code Review
3 changed files with 46 additions and 119 deletions
@@ -18,6 +18,7 @@ package com.android.launcher3;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Rect;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.InsetDrawable;
@@ -27,6 +28,7 @@ import android.widget.FrameLayout;
import com.android.launcher3.allapps.AllAppsContainerView;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.util.TransformingTouchDelegate;
/**
* A base container view, which supports resizing.
@@ -39,12 +41,14 @@ public abstract class BaseContainerView extends FrameLayout
protected int mContainerPaddingTop;
protected int mContainerPaddingBottom;
private InsetDrawable mRevealDrawable;
protected final Drawable mBaseDrawable;
private final Rect mBgPaddingRect = new Rect();
private View mRevealView;
private View mContent;
private TransformingTouchDelegate mTouchDelegate;
public BaseContainerView(Context context) {
this(context, null);
}
@@ -72,6 +76,12 @@ public abstract class BaseContainerView extends FrameLayout
DeviceProfile grid = Launcher.getLauncher(getContext()).getDeviceProfile();
grid.addLauncherLayoutChangedListener(this);
View touchDelegateTargetView = getTouchDelegateTargetView();
if (touchDelegateTargetView != null) {
mTouchDelegate = new TransformingTouchDelegate(touchDelegateTargetView);
((View) touchDelegateTargetView.getParent()).setTouchDelegate(mTouchDelegate);
}
}
@Override
@@ -92,6 +102,21 @@ public abstract class BaseContainerView extends FrameLayout
updatePaddings();
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
getRevealView().getBackground().getPadding(mBgPaddingRect);
View touchDelegateTargetView = getTouchDelegateTargetView();
if (touchDelegateTargetView != null) {
mTouchDelegate.setBounds(
touchDelegateTargetView.getLeft() - mBgPaddingRect.left,
touchDelegateTargetView.getTop() - mBgPaddingRect.top,
touchDelegateTargetView.getRight() + mBgPaddingRect.right,
touchDelegateTargetView.getBottom() + mBgPaddingRect.bottom);
}
}
@Override
public void onLauncherLayoutChanged() {
updatePaddings();
@@ -130,14 +155,12 @@ public abstract class BaseContainerView extends FrameLayout
}
}
mRevealDrawable = new InsetDrawable(mBaseDrawable,
InsetDrawable revealDrawable = new InsetDrawable(mBaseDrawable,
mContainerPaddingLeft, mContainerPaddingTop, mContainerPaddingRight,
mContainerPaddingBottom);
mRevealView.setBackground(mRevealDrawable);
if (FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP && this instanceof AllAppsContainerView) {
// Skip updating the content background
} else {
mContent.setBackground(mRevealDrawable);
}
mRevealView.setBackground(revealDrawable);
mContent.setBackground(revealDrawable);
}
public abstract View getTouchDelegateTargetView();
}
@@ -152,14 +152,12 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
private View mSearchContainer;
private ExtendedEditText mSearchInput;
private HeaderElevationController mElevationController;
private int mSearchContainerOffsetTop;
private SpannableStringBuilder mSearchQueryBuilder = null;
private int mSectionNamesMargin;
private int mNumAppsPerRow;
private int mNumPredictedAppsPerRow;
private int mRecyclerViewBottomPadding;
// This coordinate is relative to this container view
private final Point mBoundsCheckLastTouchDownPos = new Point(-1, -1);
@@ -183,13 +181,6 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
mLayoutManager = mAdapter.getLayoutManager();
mItemDecoration = mAdapter.getItemDecoration();
DeviceProfile grid = mLauncher.getDeviceProfile();
if (FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP && !grid.isVerticalBarLayout()) {
mRecyclerViewBottomPadding = 0;
setPadding(0, 0, 0, 0);
} else {
mRecyclerViewBottomPadding =
res.getDimensionPixelSize(R.dimen.all_apps_list_bottom_padding);
}
mSearchQueryBuilder = new SpannableStringBuilder();
Selection.setSelection(mSearchQueryBuilder, 0);
}
@@ -338,9 +329,6 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
0, 1, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
mSearchInput.setHint(spanned);
mSearchContainerOffsetTop = getResources().getDimensionPixelSize(
R.dimen.all_apps_search_bar_margin_top);
mElevationController = Utilities.ATLEAST_LOLLIPOP
? new HeaderElevationController.ControllerVL(mSearchContainer)
: new HeaderElevationController.ControllerV16(mSearchContainer);
@@ -370,6 +358,11 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
}
}
@Override
public View getTouchDelegateTargetView() {
return mAppsRecyclerView;
}
@Override
public void onBoundsChanged(Rect newBounds) { }
@@ -377,7 +370,6 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int widthPx = MeasureSpec.getSize(widthMeasureSpec);
int heightPx = MeasureSpec.getSize(heightMeasureSpec);
updatePaddingsAndMargins(widthPx, heightPx);
mContentBounds.set(mContainerPaddingLeft, 0, widthPx - mContainerPaddingRight, heightPx);
DeviceProfile grid = mLauncher.getDeviceProfile();
@@ -391,17 +383,14 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
mAppsRecyclerView.setNumAppsPerRow(grid, mNumAppsPerRow);
mAdapter.setNumAppsPerRow(mNumAppsPerRow);
mApps.setNumAppsPerRow(mNumAppsPerRow, mNumPredictedAppsPerRow, new FullMergeAlgorithm());
if (mNumAppsPerRow > 0) {
int rvPadding = mAppsRecyclerView.getPaddingStart(); // Assumes symmetry
final int thumbMaxWidth =
getResources().getDimensionPixelSize(
R.dimen.container_fastscroll_thumb_max_width);
mSearchContainer.setPadding(
rvPadding - mContainerPaddingLeft + thumbMaxWidth,
mSearchContainer.getPaddingTop(),
rvPadding - mContainerPaddingRight + thumbMaxWidth,
mSearchContainer.getPaddingBottom());
}
}
if (!grid.isVerticalBarLayout()) {
View navBarBg = findViewById(R.id.nav_bar_bg);
ViewGroup.LayoutParams params = navBarBg.getLayoutParams();
params.height = mLauncher.getDragLayer().getInsets().bottom;
navBarBg.setLayoutParams(params);
navBarBg.setVisibility(View.VISIBLE);
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
return;
@@ -435,73 +424,6 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
/**
* Update the background and padding of the Apps view and children. Instead of insetting the
* container view, we inset the background and padding of the recycler view to allow for the
* recycler view to handle touch events (for fast scrolling) all the way to the edge.
*/
private void updatePaddingsAndMargins(int widthPx, int heightPx) {
Rect bgPadding = new Rect();
getRevealView().getBackground().getPadding(bgPadding);
mAppsRecyclerView.updateBackgroundPadding(bgPadding);
mAdapter.updateBackgroundPadding(bgPadding);
mElevationController.updateBackgroundPadding(bgPadding);
// Pad the recycler view by the background padding plus the start margin (for the section
// names)
int maxScrollBarWidth = mAppsRecyclerView.getMaxScrollbarWidth();
int startInset = Math.max(mSectionNamesMargin, maxScrollBarWidth);
if (Utilities.isRtl(getResources())) {
mAppsRecyclerView.setPadding(bgPadding.left + maxScrollBarWidth, 0, bgPadding.right
+ startInset, mRecyclerViewBottomPadding);
} else {
mAppsRecyclerView.setPadding(bgPadding.left + startInset, 0, bgPadding.right +
maxScrollBarWidth, mRecyclerViewBottomPadding);
}
MarginLayoutParams lp = (MarginLayoutParams) mSearchContainer.getLayoutParams();
lp.leftMargin = bgPadding.left;
lp.rightMargin = bgPadding.right;
// Clip the view to the left and right edge of the background to
// to prevent shadows from rendering beyond the edges
final Rect newClipBounds = new Rect(
bgPadding.left, 0, widthPx - bgPadding.right, heightPx);
setClipBounds(newClipBounds);
// Allow the overscroll effect to reach the edges of the view
mAppsRecyclerView.setClipToPadding(false);
DeviceProfile grid = mLauncher.getDeviceProfile();
if (FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP) {
if (!grid.isVerticalBarLayout()) {
MarginLayoutParams mlp = (MarginLayoutParams) mAppsRecyclerView.getLayoutParams();
Rect insets = mLauncher.getDragLayer().getInsets();
getContentView().setPadding(0, 0, 0, 0);
int height = insets.top + grid.hotseatCellHeightPx;
mlp.topMargin = height;
mAppsRecyclerView.setLayoutParams(mlp);
mSearchContainer.setPadding(
mSearchContainer.getPaddingLeft(),
insets.top + mSearchContainerOffsetTop,
mSearchContainer.getPaddingRight(),
mSearchContainer.getPaddingBottom());
lp.height = height;
View navBarBg = findViewById(R.id.nav_bar_bg);
ViewGroup.LayoutParams params = navBarBg.getLayoutParams();
params.height = insets.bottom;
navBarBg.setLayoutParams(params);
navBarBg.setVisibility(View.VISIBLE);
}
}
mSearchContainer.setLayoutParams(lp);
}
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
// Determine if the key event was actual text, if so, focus the search bar and then dispatch
@@ -21,7 +21,6 @@ import android.graphics.Bitmap;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView.State;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
@@ -50,7 +49,6 @@ import com.android.launcher3.model.WidgetsModel;
import com.android.launcher3.userevent.nano.LauncherLogProto;
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
import com.android.launcher3.util.Thunk;
import com.android.launcher3.util.TransformingTouchDelegate;
/**
* The widgets list view container.
@@ -65,12 +63,9 @@ public class WidgetsContainerView extends BaseContainerView
private DragController mDragController;
private IconCache mIconCache;
private final Rect mTmpBgPaddingRect = new Rect();
/* Recycler view related member variables */
private WidgetsRecyclerView mRecyclerView;
private WidgetsListAdapter mAdapter;
private TransformingTouchDelegate mRecyclerViewTouchDelegate;
/* Touch handling related member variables. */
private Toast mWidgetInstructionToast;
@@ -98,14 +93,8 @@ public class WidgetsContainerView extends BaseContainerView
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
getRevealView().getBackground().getPadding(mTmpBgPaddingRect);
mRecyclerViewTouchDelegate.setBounds(
mRecyclerView.getLeft() - mTmpBgPaddingRect.left,
mRecyclerView.getTop() - mTmpBgPaddingRect.top,
mRecyclerView.getRight() + mTmpBgPaddingRect.right,
mRecyclerView.getBottom() + mTmpBgPaddingRect.bottom);
public View getTouchDelegateTargetView() {
return mRecyclerView;
}
@Override
@@ -114,13 +103,6 @@ public class WidgetsContainerView extends BaseContainerView
mRecyclerView = (WidgetsRecyclerView) getContentView().findViewById(R.id.widgets_list_view);
mRecyclerView.setAdapter(mAdapter);
mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
mRecyclerViewTouchDelegate = new TransformingTouchDelegate(mRecyclerView);
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
((View) mRecyclerView.getParent()).setTouchDelegate(mRecyclerViewTouchDelegate);
}
//