diff options
Diffstat (limited to 'src/com/android/launcher3/allapps/AllAppsContainerView.java')
-rw-r--r-- | src/com/android/launcher3/allapps/AllAppsContainerView.java | 240 |
1 files changed, 56 insertions, 184 deletions
diff --git a/src/com/android/launcher3/allapps/AllAppsContainerView.java b/src/com/android/launcher3/allapps/AllAppsContainerView.java index 5892787f3..77e8ad17d 100644 --- a/src/com/android/launcher3/allapps/AllAppsContainerView.java +++ b/src/com/android/launcher3/allapps/AllAppsContainerView.java @@ -15,10 +15,8 @@ */ package com.android.launcher3.allapps; -import android.annotation.SuppressLint; import android.content.Context; import android.content.res.Resources; -import android.graphics.Point; import android.graphics.Rect; import android.support.v7.widget.RecyclerView; import android.text.Selection; @@ -31,18 +29,17 @@ import android.util.AttributeSet; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.View; -import android.view.ViewConfiguration; import android.view.ViewGroup; import com.android.launcher3.AppInfo; import com.android.launcher3.BaseContainerView; -import com.android.launcher3.BubbleTextView; import com.android.launcher3.CellLayout; import com.android.launcher3.DeleteDropTarget; import com.android.launcher3.DeviceProfile; import com.android.launcher3.DragSource; import com.android.launcher3.DropTarget; import com.android.launcher3.ExtendedEditText; +import com.android.launcher3.Insettable; import com.android.launcher3.ItemInfo; import com.android.launcher3.Launcher; import com.android.launcher3.LauncherTransitionable; @@ -50,11 +47,11 @@ import com.android.launcher3.R; import com.android.launcher3.Utilities; import com.android.launcher3.Workspace; import com.android.launcher3.config.FeatureFlags; +import com.android.launcher3.dragndrop.DragController; import com.android.launcher3.dragndrop.DragOptions; import com.android.launcher3.folder.Folder; import com.android.launcher3.graphics.TintedDrawableSpan; import com.android.launcher3.keyboard.FocusedItemDecorator; -import com.android.launcher3.shortcuts.DeepShortcutsContainer; import com.android.launcher3.userevent.nano.LauncherLogProto.Target; import com.android.launcher3.util.ComponentKey; @@ -134,7 +131,8 @@ final class SimpleSectionMergeAlgorithm implements AlphabeticalAppsList.MergeAlg * The all apps view container. */ public class AllAppsContainerView extends BaseContainerView implements DragSource, - LauncherTransitionable, View.OnLongClickListener, AllAppsSearchBarController.Callbacks { + LauncherTransitionable, View.OnLongClickListener, AllAppsSearchBarController.Callbacks, + Insettable { private static final int MIN_ROWS_IN_MERGED_SECTION_PHONE = 3; private static final int MAX_NUM_MERGES_PHONE = 2; @@ -145,25 +143,18 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc private final RecyclerView.LayoutManager mLayoutManager; private final RecyclerView.ItemDecoration mItemDecoration; - // The computed bounds of the container - private final Rect mContentBounds = new Rect(); - private AllAppsRecyclerView mAppsRecyclerView; private AllAppsSearchBarController mSearchBarController; 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); public AllAppsContainerView(Context context) { this(context, null); @@ -184,14 +175,6 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc mApps.setAdapter(mAdapter); 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); } @@ -340,9 +323,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 +350,19 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc getContentView().setVisibility(View.VISIBLE); getContentView().setBackground(null); } + + int maxScrollBarWidth = mAppsRecyclerView.getMaxScrollbarWidth(); + int startInset = Math.max(mSectionNamesMargin, maxScrollBarWidth); + if (Utilities.isRtl(getResources())) { + mAppsRecyclerView.setPadding(maxScrollBarWidth, 0, startInset, 0); + } else { + mAppsRecyclerView.setPadding(startInset, 0, maxScrollBarWidth, 0); + } + } + + @Override + public View getTouchDelegateTargetView() { + return mAppsRecyclerView; } @Override @@ -377,11 +370,6 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc @Override 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(); grid.updateAppsViewNumCols(); if (FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP) { @@ -393,17 +381,12 @@ 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()) { + MarginLayoutParams searchContainerLp = + (MarginLayoutParams) mSearchContainer.getLayoutParams(); + searchContainerLp.height = grid.hotseatBarHeightPx; + mSearchContainer.setLayoutParams(searchContainerLp); } super.onMeasure(widthMeasureSpec, heightMeasureSpec); return; @@ -437,73 +420,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 @@ -526,18 +442,7 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc } @Override - public boolean onInterceptTouchEvent(MotionEvent ev) { - return handleTouchEvent(ev); - } - - @SuppressLint("ClickableViewAccessibility") - @Override - public boolean onTouchEvent(MotionEvent ev) { - return handleTouchEvent(ev); - } - - @Override - public boolean onLongClick(View v) { + public boolean onLongClick(final View v) { // Return early if this is not initiated from a touch if (!v.isInTouchMode()) return false; // When we have exited all apps or are in transition, disregard long clicks @@ -549,22 +454,20 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc if (mLauncher.getDragController().isDragging()) return false; // Start the drag - DragOptions dragOptions = new DragOptions(); - if (v instanceof BubbleTextView) { - final BubbleTextView icon = (BubbleTextView) v; - if (icon.hasDeepShortcuts()) { - DeepShortcutsContainer dsc = DeepShortcutsContainer.showForIcon(icon); - if (dsc != null) { - dragOptions.deferDragCondition = dsc.createDeferDragCondition(new Runnable() { - @Override - public void run() { - icon.setVisibility(VISIBLE); - } - }); - } + final DragController dragController = mLauncher.getDragController(); + dragController.addDragListener(new DragController.DragListener() { + @Override + public void onDragStart(DropTarget.DragObject dragObject, DragOptions options) { + v.setVisibility(INVISIBLE); } - } - mLauncher.getWorkspace().beginDragShared(v, this, dragOptions); + + @Override + public void onDragEnd() { + v.setVisibility(VISIBLE); + dragController.removeDragListener(this); + } + }); + mLauncher.getWorkspace().beginDragShared(v, this, new DragOptions()); if (FeatureFlags.LAUNCHER3_LEGACY_WORKSPACE_DND) { // Enter spring loaded mode (the new workspace does this in // onDragStart(), so we don't want to do it here) @@ -619,7 +522,7 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc // target layout we were dropping on. if (!success) { boolean showOutOfSpaceMessage = false; - if (target instanceof Workspace && !mLauncher.getDragController().isDeferringDrag()) { + if (target instanceof Workspace) { int currentScreen = mLauncher.getCurrentWorkspaceScreen(); Workspace workspace = (Workspace) target; CellLayout layout = (CellLayout) workspace.getChildAt(currentScreen); @@ -660,55 +563,6 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc } } - /** - * Handles the touch events to dismiss all apps when clicking outside the bounds of the - * recycler view. - */ - private boolean handleTouchEvent(MotionEvent ev) { - DeviceProfile grid = mLauncher.getDeviceProfile(); - int x = (int) ev.getX(); - int y = (int) ev.getY(); - - switch (ev.getAction()) { - case MotionEvent.ACTION_DOWN: - if (!mContentBounds.isEmpty()) { - // Outset the fixed bounds and check if the touch is outside all apps - Rect tmpRect = new Rect(mContentBounds); - tmpRect.inset(-grid.allAppsIconSizePx / 2, 0); - if (ev.getX() < tmpRect.left || ev.getX() > tmpRect.right) { - mBoundsCheckLastTouchDownPos.set(x, y); - return true; - } - } else { - // Check if the touch is outside all apps - if (ev.getX() < getPaddingLeft() || - ev.getX() > (getWidth() - getPaddingRight())) { - mBoundsCheckLastTouchDownPos.set(x, y); - return true; - } - } - break; - case MotionEvent.ACTION_UP: - if (mBoundsCheckLastTouchDownPos.x > -1) { - ViewConfiguration viewConfig = ViewConfiguration.get(getContext()); - float dx = ev.getX() - mBoundsCheckLastTouchDownPos.x; - float dy = ev.getY() - mBoundsCheckLastTouchDownPos.y; - float distance = (float) Math.hypot(dx, dy); - if (distance < viewConfig.getScaledTouchSlop()) { - // The background was clicked, so just go home - Launcher launcher = (Launcher) getContext(); - launcher.showWorkspace(true); - return true; - } - } - // Fall through - case MotionEvent.ACTION_CANCEL: - mBoundsCheckLastTouchDownPos.set(-1, -1); - break; - } - return false; - } - @Override public void onSearchResult(String query, ArrayList<ComponentKey> apps) { if (apps != null) { @@ -739,4 +593,22 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc public boolean shouldRestoreImeState() { return !TextUtils.isEmpty(mSearchInput.getText()); } + + @Override + public void setInsets(Rect insets) { + DeviceProfile grid = mLauncher.getDeviceProfile(); + if (grid.isVerticalBarLayout()) { + ViewGroup.MarginLayoutParams mlp = (MarginLayoutParams) getLayoutParams(); + mlp.leftMargin = insets.left; + mlp.topMargin = insets.top; + mlp.rightMargin = insets.right; + setLayoutParams(mlp); + } else { + View navBarBg = findViewById(R.id.nav_bar_bg); + ViewGroup.LayoutParams navBarBgLp = navBarBg.getLayoutParams(); + navBarBgLp.height = insets.bottom; + navBarBg.setLayoutParams(navBarBgLp); + navBarBg.setVisibility(View.VISIBLE); + } + } } |