Decoupling some dragController methods

Change-Id: I7c4ab5f1504c49eaa0566afe643d7672faa80205
This commit is contained in:
Sunny Goyal
2020-03-24 02:17:59 -07:00
parent ba1a2b9b62
commit deb91c46eb
4 changed files with 35 additions and 55 deletions
+11 -6
View File
@@ -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);
+1 -4
View File
@@ -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<WorkspacePageIndicator>
protected void onAttachedToWindow() {
super.onAttachedToWindow();
IBinder windowToken = getWindowToken();
mWallpaperOffset.setWindowToken(windowToken);
mWallpaperOffset.setWindowToken(getWindowToken());
computeScroll();
mDragController.setWindowToken(windowToken);
}
protected void onDetachedFromWindow() {
@@ -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<DropTarget> mDropTargets = new ArrayList<>();
private ArrayList<DragListener> mListeners = new ArrayList<>();
/** The window token used as the parent for the DragView. */
private IBinder mWindowToken;
private View mMoveTarget;
private final ArrayList<DropTarget> mDropTargets = new ArrayList<>();
private final ArrayList<DragListener> 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.
*/
@@ -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<Launcher> {
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<Launcher> {
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<Launcher> {
public void setup(DragController dragController, Workspace workspace) {
mDragController = dragController;
mWorkspaceScrim.setWorkspace(workspace);
mMoveTarget = workspace;
recreateControllers();
}
@@ -223,7 +225,7 @@ public class DragLayer extends BaseDragLayer<Launcher> {
@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<Launcher> {
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<Launcher> {
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<Launcher> {
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<Launcher> {
// 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