From deb91c46eb0cce056f939f5978eee40fbfd163f6 Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Tue, 24 Mar 2020 02:17:59 -0700 Subject: [PATCH] Decoupling some dragController methods Change-Id: I7c4ab5f1504c49eaa0566afe643d7672faa80205 --- src/com/android/launcher3/Launcher.java | 17 ++++++--- src/com/android/launcher3/Workspace.java | 5 +-- .../launcher3/dragndrop/DragController.java | 37 +++---------------- .../launcher3/dragndrop/DragLayer.java | 31 +++++++++------- 4 files changed, 35 insertions(+), 55 deletions(-) diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index a83a694c9c..dd0745b663 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -1207,7 +1207,6 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, mScrimView = findViewById(R.id.scrim_view); // Setup the drag controller (drop targets have to be added in reverse order in priority) - mDragController.setMoveTarget(mWorkspace); mDropTargetBar.setup(mDragController); mAllAppsController.setupViews(mAppsView); @@ -1507,11 +1506,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, target.pageIndex = mWorkspace.getCurrentPage(); ued.logActionCommand(Action.Command.HOME_INTENT, target, newContainerTarget(ContainerType.WORKSPACE)); - - final View v = getWindow().peekDecorView(); - if (v != null && v.getWindowToken() != null) { - UiThreadHelper.hideKeyboardAsync(this, v.getWindowToken()); - } + hideKeyboard(); if (mLauncherCallbacks != null) { mLauncherCallbacks.onHomeIntent(internalStateHandled); @@ -1522,6 +1517,16 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, TraceHelper.INSTANCE.endSection(traceToken); } + /** + * Hides the keyboard if visible + */ + public void hideKeyboard() { + final View v = getWindow().peekDecorView(); + if (v != null && v.getWindowToken() != null) { + UiThreadHelper.hideKeyboardAsync(this, v.getWindowToken()); + } + } + @Override public void onRestoreInstanceState(Bundle state) { super.onRestoreInstanceState(state); diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index c42e480475..ee08beb858 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -43,7 +43,6 @@ import android.graphics.Point; import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.os.Handler; -import android.os.IBinder; import android.os.Message; import android.os.Parcelable; import android.os.UserHandle; @@ -1224,10 +1223,8 @@ public class Workspace extends PagedView protected void onAttachedToWindow() { super.onAttachedToWindow(); - IBinder windowToken = getWindowToken(); - mWallpaperOffset.setWindowToken(windowToken); + mWallpaperOffset.setWindowToken(getWindowToken()); computeScroll(); - mDragController.setWindowToken(windowToken); } protected void onDetachedFromWindow() { diff --git a/src/com/android/launcher3/dragndrop/DragController.java b/src/com/android/launcher3/dragndrop/DragController.java index d0d9aaf947..d6b9b76114 100644 --- a/src/com/android/launcher3/dragndrop/DragController.java +++ b/src/com/android/launcher3/dragndrop/DragController.java @@ -27,7 +27,6 @@ import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.Point; import android.graphics.Rect; -import android.os.IBinder; import android.view.DragEvent; import android.view.HapticFeedbackConstants; import android.view.KeyEvent; @@ -44,7 +43,6 @@ import com.android.launcher3.WorkspaceItemInfo; import com.android.launcher3.accessibility.DragViewStateAnnouncer; import com.android.launcher3.util.ItemInfoMatcher; import com.android.launcher3.util.TouchController; -import com.android.launcher3.util.UiThreadHelper; import java.util.ArrayList; @@ -86,21 +84,14 @@ public class DragController implements DragDriver.EventListener, TouchController private DropTarget.DragObject mDragObject; /** Who can receive drop events */ - private ArrayList mDropTargets = new ArrayList<>(); - private ArrayList mListeners = new ArrayList<>(); - - /** The window token used as the parent for the DragView. */ - private IBinder mWindowToken; - - private View mMoveTarget; + private final ArrayList mDropTargets = new ArrayList<>(); + private final ArrayList mListeners = new ArrayList<>(); private DropTarget mLastDropTarget; private int mLastTouchClassification; private int mDistanceSinceScroll = 0; - private Rect mDragLayerRect = new Rect(); - private boolean mIsInPreDrag; /** @@ -153,8 +144,7 @@ public class DragController implements DragDriver.EventListener, TouchController android.os.Debug.startMethodTracing("Launcher"); } - // Hide soft keyboard, if visible - UiThreadHelper.hideKeyboardAsync(mLauncher, mWindowToken); + mLauncher.hideKeyboard(); AbstractFloatingView.closeOpenViews(mLauncher, false, TYPE_DISCOVERY_BOUNCE); mOptions = options; @@ -362,9 +352,9 @@ public class DragController implements DragDriver.EventListener, TouchController * Clamps the position to the drag layer bounds. */ private Point getClampedDragLayerPos(float x, float y) { - mLauncher.getDragLayer().getLocalVisibleRect(mDragLayerRect); - mTmpPoint.x = (int) Math.max(mDragLayerRect.left, Math.min(x, mDragLayerRect.right - 1)); - mTmpPoint.y = (int) Math.max(mDragLayerRect.top, Math.min(y, mDragLayerRect.bottom - 1)); + mLauncher.getDragLayer().getLocalVisibleRect(mRectTemp); + mTmpPoint.x = (int) Math.max(mRectTemp.left, Math.min(x, mRectTemp.right - 1)); + mTmpPoint.y = (int) Math.max(mRectTemp.top, Math.min(y, mRectTemp.bottom - 1)); return mTmpPoint; } @@ -439,17 +429,6 @@ public class DragController implements DragDriver.EventListener, TouchController return mDragDriver != null && mDragDriver.onDragEvent(event); } - /** - * Sets the view that should handle move events. - */ - public void setMoveTarget(View view) { - mMoveTarget = view; - } - - public boolean dispatchUnhandledMove(View focused, int direction) { - return mMoveTarget != null && mMoveTarget.dispatchUnhandledMove(focused, direction); - } - private void handleMoveEvent(int x, int y) { mDragObject.dragView.move(x, y); @@ -593,10 +572,6 @@ public class DragController implements DragDriver.EventListener, TouchController return mLauncher.getWorkspace(); } - public void setWindowToken(IBinder token) { - mWindowToken = token; - } - /** * Sets the drag listener which will be notified when a drag starts or ends. */ diff --git a/src/com/android/launcher3/dragndrop/DragLayer.java b/src/com/android/launcher3/dragndrop/DragLayer.java index e18ca547fd..9ece3d3bca 100644 --- a/src/com/android/launcher3/dragndrop/DragLayer.java +++ b/src/com/android/launcher3/dragndrop/DragLayer.java @@ -21,6 +21,7 @@ import static android.view.View.MeasureSpec.EXACTLY; import static android.view.View.MeasureSpec.getMode; import static android.view.View.MeasureSpec.getSize; +import static com.android.launcher3.anim.Interpolators.DEACCEL_1_5; import static com.android.launcher3.compat.AccessibilityManagerCompat.sendCustomAccessibilityEvent; import android.animation.Animator; @@ -49,7 +50,6 @@ import com.android.launcher3.Launcher; import com.android.launcher3.R; import com.android.launcher3.ShortcutAndWidgetContainer; import com.android.launcher3.Workspace; -import com.android.launcher3.anim.Interpolators; import com.android.launcher3.folder.Folder; import com.android.launcher3.graphics.OverviewScrim; import com.android.launcher3.graphics.RotationMode; @@ -74,11 +74,11 @@ public class DragLayer extends BaseDragLayer { public static final int ANIMATION_END_DISAPPEAR = 0; public static final int ANIMATION_END_REMAIN_VISIBLE = 2; - @Thunk DragController mDragController; + private DragController mDragController; // Variables relating to animation of views after drop private ValueAnimator mDropAnim = null; - private final TimeInterpolator mCubicEaseOutInterpolator = Interpolators.DEACCEL_1_5; + @Thunk DragView mDropView = null; @Thunk int mAnchorViewInitialScrollX = 0; @Thunk View mAnchorView = null; @@ -88,13 +88,14 @@ public class DragLayer extends BaseDragLayer { private int mTopViewIndex; private int mChildCountOnLastUpdate = -1; - private Rect mTmpRect = new Rect(); - // Related to adjacent page hints private final ViewGroupFocusHelper mFocusIndicatorHelper; private final WorkspaceAndHotseatScrim mWorkspaceScrim; private final OverviewScrim mOverviewScrim; + // View that should handle move events + private View mMoveTarget; + /** * Used to create a new DragLayer from XML. * @@ -116,6 +117,7 @@ public class DragLayer extends BaseDragLayer { public void setup(DragController dragController, Workspace workspace) { mDragController = dragController; mWorkspaceScrim.setWorkspace(workspace); + mMoveTarget = workspace; recreateControllers(); } @@ -223,7 +225,7 @@ public class DragLayer extends BaseDragLayer { @Override public boolean dispatchUnhandledMove(View focused, int direction) { return super.dispatchUnhandledMove(focused, direction) - || mDragController.dispatchUnhandledMove(focused, direction); + || mMoveTarget.dispatchUnhandledMove(focused, direction); } @Override @@ -260,9 +262,10 @@ public class DragLayer extends BaseDragLayer { parentChildren.measureChild(child); parentChildren.layoutChild(child); - getViewRectRelativeToSelf(dragView, mTmpRect); - final int fromX = mTmpRect.left; - final int fromY = mTmpRect.top; + Rect dragViewBounds = new Rect(); + getViewRectRelativeToSelf(dragView, dragViewBounds); + final int fromX = dragViewBounds.left; + final int fromY = dragViewBounds.top; float coord[] = new float[2]; float childScale = child.getScaleX(); @@ -283,15 +286,15 @@ public class DragLayer extends BaseDragLayer { if (child instanceof DraggableView) { DraggableView d = (DraggableView) child; - d.getVisualDragBounds(mTmpRect); + d.getVisualDragBounds(dragViewBounds); // This accounts for the offset of the DragView created by scaling it about its // center as it animates into place. float scaleShiftX = dragView.getMeasuredWidth() * (1 - scale) / 2; float scaleShiftY = dragView.getMeasuredHeight() * (1 - scale) / 2; - toX += scale * (mTmpRect.left - dragView.getBlurSizeOutline() / 2) - scaleShiftX; - toY += scale * (mTmpRect.top - dragView.getBlurSizeOutline() / 2) - scaleShiftY; + toX += scale * (dragViewBounds.left - dragView.getBlurSizeOutline() / 2) - scaleShiftX; + toY += scale * (dragViewBounds.top - dragView.getBlurSizeOutline() / 2) - scaleShiftY; } child.setVisibility(INVISIBLE); @@ -348,7 +351,7 @@ public class DragLayer extends BaseDragLayer { if (duration < 0) { duration = res.getInteger(R.integer.config_dropAnimMaxDuration); if (dist < maxDist) { - duration *= mCubicEaseOutInterpolator.getInterpolation(dist / maxDist); + duration *= DEACCEL_1_5.getInterpolation(dist / maxDist); } duration = Math.max(duration, res.getInteger(R.integer.config_dropAnimMinDuration)); } @@ -356,7 +359,7 @@ public class DragLayer extends BaseDragLayer { // Fall back to cubic ease out interpolator for the animation if none is specified TimeInterpolator interpolator = null; if (alphaInterpolator == null || motionInterpolator == null) { - interpolator = mCubicEaseOutInterpolator; + interpolator = DEACCEL_1_5; } // Animate the view