mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-19 18:58:19 +00:00
Merge "Resize only one widget at a time" into ub-launcher3-master
This commit is contained in:
@@ -15,14 +15,17 @@ import android.graphics.Point;
|
||||
import android.graphics.Rect;
|
||||
import android.view.Gravity;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.android.launcher3.accessibility.DragViewStateAnnouncer;
|
||||
import com.android.launcher3.util.FocusLogic;
|
||||
import com.android.launcher3.util.TouchController;
|
||||
|
||||
public class AppWidgetResizeFrame extends FrameLayout implements View.OnKeyListener {
|
||||
public class AppWidgetResizeFrame extends FrameLayout
|
||||
implements View.OnKeyListener, TouchController {
|
||||
private static final int SNAP_DURATION = 150;
|
||||
private static final float DIMMED_HANDLE_ALPHA = 0f;
|
||||
private static final float RESIZE_THRESHOLD = 0.66f;
|
||||
@@ -76,6 +79,8 @@ public class AppWidgetResizeFrame extends FrameLayout implements View.OnKeyListe
|
||||
private int mTopTouchRegionAdjustment = 0;
|
||||
private int mBottomTouchRegionAdjustment = 0;
|
||||
|
||||
private int mXDown, mYDown;
|
||||
|
||||
public AppWidgetResizeFrame(Context context,
|
||||
LauncherAppWidgetHostView widgetView, CellLayout cellLayout, DragLayer dragLayer) {
|
||||
|
||||
@@ -205,7 +210,7 @@ public class AppWidgetResizeFrame extends FrameLayout implements View.OnKeyListe
|
||||
}
|
||||
}
|
||||
|
||||
public void visualizeResizeForDelta(int deltaX, int deltaY) {
|
||||
private void visualizeResizeForDelta(int deltaX, int deltaY) {
|
||||
visualizeResizeForDelta(deltaX, deltaY, false);
|
||||
}
|
||||
|
||||
@@ -398,7 +403,7 @@ public class AppWidgetResizeFrame extends FrameLayout implements View.OnKeyListe
|
||||
requestLayout();
|
||||
}
|
||||
|
||||
public void onTouchUp() {
|
||||
private void onTouchUp() {
|
||||
int xThreshold = mCellLayout.getCellWidth() + mCellLayout.getWidthGap();
|
||||
int yThreshold = mCellLayout.getCellHeight() + mCellLayout.getHeightGap();
|
||||
|
||||
@@ -493,10 +498,56 @@ public class AppWidgetResizeFrame extends FrameLayout implements View.OnKeyListe
|
||||
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
||||
// Clear the frame and give focus to the widget host view when a directional key is pressed.
|
||||
if (FocusLogic.shouldConsume(keyCode)) {
|
||||
mDragLayer.clearAllResizeFrames();
|
||||
mDragLayer.clearResizeFrame();
|
||||
mWidgetView.requestFocus();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean handleTouchDown(MotionEvent ev) {
|
||||
Rect hitRect = new Rect();
|
||||
int x = (int) ev.getX();
|
||||
int y = (int) ev.getY();
|
||||
|
||||
getHitRect(hitRect);
|
||||
if (hitRect.contains(x, y)) {
|
||||
if (beginResizeIfPointInRegion(x - getLeft(), y - getTop())) {
|
||||
mXDown = x;
|
||||
mYDown = y;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onControllerTouchEvent(MotionEvent ev) {
|
||||
int action = ev.getAction();
|
||||
int x = (int) ev.getX();
|
||||
int y = (int) ev.getY();
|
||||
|
||||
switch (action) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
return handleTouchDown(ev);
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
visualizeResizeForDelta(x - mXDown, y - mYDown);
|
||||
break;
|
||||
case MotionEvent.ACTION_CANCEL:
|
||||
case MotionEvent.ACTION_UP:
|
||||
visualizeResizeForDelta(x - mXDown, y - mYDown);
|
||||
onTouchUp();
|
||||
mXDown = mYDown = 0;
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onControllerInterceptTouchEvent(MotionEvent ev) {
|
||||
if (ev.getAction() == MotionEvent.ACTION_DOWN && handleTouchDown(ev)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1565,7 +1565,7 @@ public class Launcher extends Activity
|
||||
final String action = intent.getAction();
|
||||
if (Intent.ACTION_SCREEN_OFF.equals(action)) {
|
||||
mUserPresent = false;
|
||||
mDragLayer.clearAllResizeFrames();
|
||||
mDragLayer.clearResizeFrame();
|
||||
updateAutoAdvanceState();
|
||||
|
||||
// Reset AllApps to its initial state only if we are not in the middle of
|
||||
|
||||
@@ -61,12 +61,12 @@ public class PinchToOverviewListener extends ScaleGestureDetector.SimpleOnScaleG
|
||||
mPinchDetector = new ScaleGestureDetector((Context) mLauncher, this);
|
||||
}
|
||||
|
||||
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
||||
public boolean onControllerInterceptTouchEvent(MotionEvent ev) {
|
||||
mPinchDetector.onTouchEvent(ev);
|
||||
return mPinchStarted;
|
||||
}
|
||||
|
||||
public boolean onTouchEvent(MotionEvent ev) {
|
||||
public boolean onControllerTouchEvent(MotionEvent ev) {
|
||||
if (mPinchStarted) {
|
||||
if (ev.getPointerCount() > 2) {
|
||||
// Using more than two fingers causes weird behavior, so just cancel the pinch.
|
||||
|
||||
@@ -2012,7 +2012,7 @@ public class Workspace extends PagedView
|
||||
|
||||
public void exitWidgetResizeMode() {
|
||||
DragLayer dragLayer = mLauncher.getDragLayer();
|
||||
dragLayer.clearAllResizeFrames();
|
||||
dragLayer.clearResizeFrame();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2713,7 +2713,7 @@ public class Workspace extends PagedView
|
||||
public void run() {
|
||||
if (!isPageMoving() && !mIsSwitchingState) {
|
||||
DragLayer dragLayer = mLauncher.getDragLayer();
|
||||
dragLayer.addResizeFrame(info, hostView, cellLayout);
|
||||
dragLayer.addResizeFrame(hostView, cellLayout);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -106,7 +106,7 @@ public class AllAppsTransitionController implements TouchController, VerticalPul
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
||||
public boolean onControllerInterceptTouchEvent(MotionEvent ev) {
|
||||
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
mNoIntercept = false;
|
||||
if (!mLauncher.isAllAppsVisible() && mLauncher.getWorkspace().workspaceInModalState()) {
|
||||
@@ -172,7 +172,7 @@ public class AllAppsTransitionController implements TouchController, VerticalPul
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent ev) {
|
||||
public boolean onControllerTouchEvent(MotionEvent ev) {
|
||||
return mDetector.onTouchEvent(ev);
|
||||
}
|
||||
|
||||
|
||||
@@ -439,7 +439,7 @@ public class DragController implements DragDriver.EventListener, TouchController
|
||||
/**
|
||||
* Call this from a drag source view.
|
||||
*/
|
||||
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
||||
public boolean onControllerInterceptTouchEvent(MotionEvent ev) {
|
||||
if (mOptions != null && mOptions.isAccessibleDrag) {
|
||||
return false;
|
||||
}
|
||||
@@ -582,7 +582,7 @@ public class DragController implements DragDriver.EventListener, TouchController
|
||||
/**
|
||||
* Call this from a drag source view.
|
||||
*/
|
||||
public boolean onTouchEvent(MotionEvent ev) {
|
||||
public boolean onControllerTouchEvent(MotionEvent ev) {
|
||||
if (mDragDriver == null || mOptions == null || mOptions.isAccessibleDrag) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,6 @@ import android.graphics.Region;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.DragEvent;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
@@ -53,8 +52,6 @@ import com.android.launcher3.AppWidgetResizeFrame;
|
||||
import com.android.launcher3.CellLayout;
|
||||
import com.android.launcher3.DropTargetBar;
|
||||
import com.android.launcher3.InsettableFrameLayout;
|
||||
import com.android.launcher3.InstallShortcutReceiver;
|
||||
import com.android.launcher3.ItemInfo;
|
||||
import com.android.launcher3.Launcher;
|
||||
import com.android.launcher3.LauncherAppWidgetHostView;
|
||||
import com.android.launcher3.PinchToOverviewListener;
|
||||
@@ -72,7 +69,6 @@ import com.android.launcher3.shortcuts.DeepShortcutsContainer;
|
||||
import com.android.launcher3.util.Thunk;
|
||||
import com.android.launcher3.util.TouchController;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
@@ -90,11 +86,9 @@ public class DragLayer extends InsettableFrameLayout {
|
||||
|
||||
@Thunk DragController mDragController;
|
||||
|
||||
private int mXDown, mYDown;
|
||||
private Launcher mLauncher;
|
||||
|
||||
// Variables relating to resizing widgets
|
||||
private final ArrayList<AppWidgetResizeFrame> mResizeFrames = new ArrayList<>();
|
||||
private final boolean mIsRtl;
|
||||
private AppWidgetResizeFrame mCurrentResizeFrame;
|
||||
|
||||
@@ -209,23 +203,6 @@ public class DragLayer extends InsettableFrameLayout {
|
||||
}
|
||||
|
||||
private boolean handleTouchDown(MotionEvent ev, boolean intercept) {
|
||||
Rect hitRect = new Rect();
|
||||
int x = (int) ev.getX();
|
||||
int y = (int) ev.getY();
|
||||
|
||||
for (AppWidgetResizeFrame child: mResizeFrames) {
|
||||
child.getHitRect(hitRect);
|
||||
if (hitRect.contains(x, y)) {
|
||||
if (child.beginResizeIfPointInRegion(x - child.getLeft(), y - child.getTop())) {
|
||||
mCurrentResizeFrame = child;
|
||||
mXDown = x;
|
||||
mYDown = y;
|
||||
requestDisallowInterceptTouchEvent(true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Remove the shortcuts container when touching outside of it.
|
||||
DeepShortcutsContainer deepShortcutsContainer = mLauncher.getOpenShortcutsContainer();
|
||||
if (deepShortcutsContainer != null) {
|
||||
@@ -289,21 +266,27 @@ public class DragLayer extends InsettableFrameLayout {
|
||||
}
|
||||
mTouchCompleteListener = null;
|
||||
}
|
||||
clearAllResizeFrames();
|
||||
|
||||
mActiveController = null;
|
||||
|
||||
if (mDragController.onInterceptTouchEvent(ev)) {
|
||||
if (mCurrentResizeFrame != null
|
||||
&& mCurrentResizeFrame.onControllerInterceptTouchEvent(ev)) {
|
||||
mActiveController = mCurrentResizeFrame;
|
||||
return true;
|
||||
} else {
|
||||
clearResizeFrame();
|
||||
}
|
||||
|
||||
if (mDragController.onControllerInterceptTouchEvent(ev)) {
|
||||
mActiveController = mDragController;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP && mAllAppsController.onInterceptTouchEvent(ev)) {
|
||||
if (FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP && mAllAppsController.onControllerInterceptTouchEvent(ev)) {
|
||||
mActiveController = mAllAppsController;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (mPinchListener != null && mPinchListener.onInterceptTouchEvent(ev)) {
|
||||
if (mPinchListener != null && mPinchListener.onControllerInterceptTouchEvent(ev)) {
|
||||
// Stop listening for scrolling etc. (onTouchEvent() handles the rest of the pinch.)
|
||||
mActiveController = mPinchListener;
|
||||
return true;
|
||||
@@ -405,12 +388,8 @@ public class DragLayer extends InsettableFrameLayout {
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent ev) {
|
||||
boolean handled = false;
|
||||
int action = ev.getAction();
|
||||
|
||||
int x = (int) ev.getX();
|
||||
int y = (int) ev.getY();
|
||||
|
||||
if (action == MotionEvent.ACTION_DOWN) {
|
||||
if (handleTouchDown(ev, false)) {
|
||||
return true;
|
||||
@@ -422,22 +401,8 @@ public class DragLayer extends InsettableFrameLayout {
|
||||
mTouchCompleteListener = null;
|
||||
}
|
||||
|
||||
if (mCurrentResizeFrame != null) {
|
||||
handled = true;
|
||||
switch (action) {
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
mCurrentResizeFrame.visualizeResizeForDelta(x - mXDown, y - mYDown);
|
||||
break;
|
||||
case MotionEvent.ACTION_CANCEL:
|
||||
case MotionEvent.ACTION_UP:
|
||||
mCurrentResizeFrame.visualizeResizeForDelta(x - mXDown, y - mYDown);
|
||||
mCurrentResizeFrame.onTouchUp();
|
||||
mCurrentResizeFrame = null;
|
||||
}
|
||||
}
|
||||
if (handled) return true;
|
||||
if (mActiveController != null) {
|
||||
return mActiveController.onTouchEvent(ev);
|
||||
return mActiveController.onControllerTouchEvent(ev);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -645,36 +610,24 @@ public class DragLayer extends InsettableFrameLayout {
|
||||
}
|
||||
}
|
||||
|
||||
public void clearAllResizeFrames() {
|
||||
if (mResizeFrames.size() > 0) {
|
||||
for (AppWidgetResizeFrame frame: mResizeFrames) {
|
||||
frame.commitResize();
|
||||
removeView(frame);
|
||||
}
|
||||
mResizeFrames.clear();
|
||||
public void clearResizeFrame() {
|
||||
if (mCurrentResizeFrame != null) {
|
||||
mCurrentResizeFrame.commitResize();
|
||||
removeView(mCurrentResizeFrame);
|
||||
mCurrentResizeFrame = null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasResizeFrames() {
|
||||
return mResizeFrames.size() > 0;
|
||||
}
|
||||
public void addResizeFrame(LauncherAppWidgetHostView widget, CellLayout cellLayout) {
|
||||
clearResizeFrame();
|
||||
|
||||
public boolean isWidgetBeingResized() {
|
||||
return mCurrentResizeFrame != null;
|
||||
}
|
||||
|
||||
public void addResizeFrame(ItemInfo itemInfo, LauncherAppWidgetHostView widget,
|
||||
CellLayout cellLayout) {
|
||||
AppWidgetResizeFrame resizeFrame = new AppWidgetResizeFrame(getContext(),
|
||||
widget, cellLayout, this);
|
||||
mCurrentResizeFrame = new AppWidgetResizeFrame(getContext(), widget, cellLayout, this);
|
||||
|
||||
LayoutParams lp = new LayoutParams(-1, -1);
|
||||
lp.customPosition = true;
|
||||
|
||||
addView(resizeFrame, lp);
|
||||
mResizeFrames.add(resizeFrame);
|
||||
|
||||
resizeFrame.snapToWidget(false);
|
||||
addView(mCurrentResizeFrame, lp);
|
||||
mCurrentResizeFrame.snapToWidget(false);
|
||||
}
|
||||
|
||||
public void animateViewIntoPosition(DragView dragView, final int[] pos, float alpha,
|
||||
|
||||
@@ -458,7 +458,7 @@ public class DeepShortcutsContainer extends LinearLayout implements View.OnLongC
|
||||
cleanupDeferredDrag(true);
|
||||
mDeferredDragIcon.getParent().requestDisallowInterceptTouchEvent(false);
|
||||
mDeferredDragIcon.getOnLongClickListener().onLongClick(mDeferredDragIcon);
|
||||
mLauncher.getDragController().onTouchEvent(ev);
|
||||
mLauncher.getDragController().onControllerTouchEvent(ev);
|
||||
return true;
|
||||
} else if (mDistanceDragged > mDragDeadzone) {
|
||||
// After dragging further than a small deadzone,
|
||||
|
||||
@@ -1,8 +1,32 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.launcher3.util;
|
||||
|
||||
import android.view.MotionEvent;
|
||||
|
||||
public interface TouchController {
|
||||
boolean onTouchEvent(MotionEvent ev);
|
||||
boolean onInterceptTouchEvent(MotionEvent ev);
|
||||
|
||||
/**
|
||||
* Called when the draglayer receives touch event.
|
||||
*/
|
||||
boolean onControllerTouchEvent(MotionEvent ev);
|
||||
|
||||
/**
|
||||
* Called when the draglayer receives a intercept touch event.
|
||||
*/
|
||||
boolean onControllerInterceptTouchEvent(MotionEvent ev);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user