2018-09-10 16:48:47 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2018 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.
|
|
|
|
|
*/
|
2019-03-22 15:44:28 -05:00
|
|
|
package com.android.launcher3.uioverrides.touchcontrollers;
|
2018-09-10 16:48:47 -07:00
|
|
|
|
2020-10-23 09:26:44 -07:00
|
|
|
import static android.view.MotionEvent.ACTION_CANCEL;
|
2018-09-10 16:48:47 -07:00
|
|
|
import static android.view.MotionEvent.ACTION_DOWN;
|
|
|
|
|
import static android.view.MotionEvent.ACTION_MOVE;
|
2019-06-28 23:31:24 +00:00
|
|
|
import static android.view.MotionEvent.ACTION_UP;
|
2021-11-22 16:00:09 -08:00
|
|
|
import static android.view.WindowManager.LayoutParams.FLAG_SLIPPERY;
|
2020-10-23 09:26:44 -07:00
|
|
|
|
|
|
|
|
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_SWIPE_DOWN_WORKSPACE_NOTISHADE_OPEN;
|
2018-09-10 16:48:47 -07:00
|
|
|
|
2019-06-28 23:31:24 +00:00
|
|
|
import android.graphics.PointF;
|
|
|
|
|
import android.util.SparseArray;
|
2018-09-10 16:48:47 -07:00
|
|
|
import android.view.MotionEvent;
|
|
|
|
|
import android.view.ViewConfiguration;
|
2019-06-28 23:31:24 +00:00
|
|
|
import android.view.Window;
|
|
|
|
|
import android.view.WindowManager;
|
2018-09-10 16:48:47 -07:00
|
|
|
|
2023-05-17 14:38:21 -07:00
|
|
|
import androidx.annotation.VisibleForTesting;
|
|
|
|
|
|
2018-09-19 16:06:16 -07:00
|
|
|
import com.android.launcher3.AbstractFloatingView;
|
2018-09-10 16:48:47 -07:00
|
|
|
import com.android.launcher3.DeviceProfile;
|
|
|
|
|
import com.android.launcher3.Launcher;
|
|
|
|
|
import com.android.launcher3.LauncherState;
|
|
|
|
|
import com.android.launcher3.util.TouchController;
|
2020-10-05 14:46:26 +00:00
|
|
|
import com.android.quickstep.SystemUiProxy;
|
2020-10-23 09:26:44 -07:00
|
|
|
|
2019-04-25 13:57:16 -07:00
|
|
|
import java.io.PrintWriter;
|
|
|
|
|
|
2018-09-10 16:48:47 -07:00
|
|
|
/**
|
|
|
|
|
* TouchController for handling touch events that get sent to the StatusBar. Once the
|
2019-06-28 23:31:24 +00:00
|
|
|
* Once the event delta mDownY passes the touch slop, the events start getting forwarded.
|
2018-09-10 16:48:47 -07:00
|
|
|
* All events are offset by initial Y value of the pointer.
|
|
|
|
|
*/
|
|
|
|
|
public class StatusBarTouchController implements TouchController {
|
|
|
|
|
|
|
|
|
|
private static final String TAG = "StatusBarController";
|
|
|
|
|
|
2019-10-01 14:10:37 -07:00
|
|
|
private final Launcher mLauncher;
|
|
|
|
|
private final SystemUiProxy mSystemUiProxy;
|
2023-05-17 14:38:21 -07:00
|
|
|
@VisibleForTesting final float mTouchSlop;
|
2019-04-25 13:57:16 -07:00
|
|
|
private int mLastAction;
|
2019-06-28 23:31:24 +00:00
|
|
|
private final SparseArray<PointF> mDownEvents;
|
2018-09-10 16:48:47 -07:00
|
|
|
|
|
|
|
|
/* If {@code false}, this controller should not handle the input {@link MotionEvent}.*/
|
2023-05-17 14:38:21 -07:00
|
|
|
@VisibleForTesting
|
|
|
|
|
boolean mCanIntercept;
|
2018-09-10 16:48:47 -07:00
|
|
|
|
|
|
|
|
public StatusBarTouchController(Launcher l) {
|
|
|
|
|
mLauncher = l;
|
2019-10-01 14:10:37 -07:00
|
|
|
mSystemUiProxy = SystemUiProxy.INSTANCE.get(mLauncher);
|
2018-10-23 16:00:37 -07:00
|
|
|
// Guard against TAPs by increasing the touch slop.
|
|
|
|
|
mTouchSlop = 2 * ViewConfiguration.get(l).getScaledTouchSlop();
|
2019-06-28 23:31:24 +00:00
|
|
|
mDownEvents = new SparseArray<>();
|
2018-09-10 16:48:47 -07:00
|
|
|
}
|
|
|
|
|
|
2019-04-25 13:57:16 -07:00
|
|
|
@Override
|
|
|
|
|
public void dump(String prefix, PrintWriter writer) {
|
|
|
|
|
writer.println(prefix + "mCanIntercept:" + mCanIntercept);
|
|
|
|
|
writer.println(prefix + "mLastAction:" + MotionEvent.actionToString(mLastAction));
|
2019-10-01 14:10:37 -07:00
|
|
|
writer.println(prefix + "mSysUiProxy available:"
|
|
|
|
|
+ SystemUiProxy.INSTANCE.get(mLauncher).isActive());
|
2019-04-25 13:57:16 -07:00
|
|
|
}
|
|
|
|
|
|
2018-09-10 16:48:47 -07:00
|
|
|
private void dispatchTouchEvent(MotionEvent ev) {
|
2019-10-01 14:10:37 -07:00
|
|
|
if (mSystemUiProxy.isActive()) {
|
|
|
|
|
mLastAction = ev.getActionMasked();
|
|
|
|
|
mSystemUiProxy.onStatusBarMotionEvent(ev);
|
2018-09-10 16:48:47 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public final boolean onControllerInterceptTouchEvent(MotionEvent ev) {
|
2023-05-17 14:38:21 -07:00
|
|
|
final int action = ev.getActionMasked();
|
|
|
|
|
final int idx = ev.getActionIndex();
|
|
|
|
|
final int pid = ev.getPointerId(idx);
|
2018-09-10 16:48:47 -07:00
|
|
|
if (action == ACTION_DOWN) {
|
|
|
|
|
mCanIntercept = canInterceptTouch(ev);
|
|
|
|
|
if (!mCanIntercept) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2023-01-23 22:06:19 -08:00
|
|
|
mDownEvents.clear();
|
2019-06-28 23:31:24 +00:00
|
|
|
mDownEvents.put(pid, new PointF(ev.getX(), ev.getY()));
|
2023-05-17 14:38:21 -07:00
|
|
|
} else if (action == MotionEvent.ACTION_POINTER_DOWN) {
|
2023-01-23 22:06:19 -08:00
|
|
|
// Check!! should only set it only when threshold is not entered.
|
|
|
|
|
mDownEvents.put(pid, new PointF(ev.getX(idx), ev.getY(idx)));
|
2018-09-10 16:48:47 -07:00
|
|
|
}
|
|
|
|
|
if (!mCanIntercept) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2023-05-17 14:38:21 -07:00
|
|
|
if (action == ACTION_MOVE && mDownEvents.contains(pid)) {
|
2019-06-28 23:31:24 +00:00
|
|
|
float dy = ev.getY(idx) - mDownEvents.get(pid).y;
|
|
|
|
|
float dx = ev.getX(idx) - mDownEvents.get(pid).x;
|
|
|
|
|
// Currently input dispatcher will not do touch transfer if there are more than
|
|
|
|
|
// one touch pointer. Hence, even if slope passed, only set the slippery flag
|
|
|
|
|
// when there is single touch event. (context: InputDispatcher.cpp line 1445)
|
2023-04-17 12:56:52 -07:00
|
|
|
if (dy > mTouchSlop && dy > Math.abs(dx) && ev.getPointerCount() == 1) {
|
2019-06-28 23:31:24 +00:00
|
|
|
ev.setAction(ACTION_DOWN);
|
|
|
|
|
dispatchTouchEvent(ev);
|
|
|
|
|
setWindowSlippery(true);
|
2018-09-10 16:48:47 -07:00
|
|
|
return true;
|
|
|
|
|
}
|
2018-10-23 16:00:37 -07:00
|
|
|
if (Math.abs(dx) > mTouchSlop) {
|
|
|
|
|
mCanIntercept = false;
|
|
|
|
|
}
|
2018-09-10 16:48:47 -07:00
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public final boolean onControllerTouchEvent(MotionEvent ev) {
|
2019-07-22 16:04:30 -07:00
|
|
|
int action = ev.getAction();
|
|
|
|
|
if (action == ACTION_UP || action == ACTION_CANCEL) {
|
2019-06-28 23:31:24 +00:00
|
|
|
dispatchTouchEvent(ev);
|
2020-10-23 09:26:44 -07:00
|
|
|
mLauncher.getStatsLogManager().logger()
|
|
|
|
|
.log(LAUNCHER_SWIPE_DOWN_WORKSPACE_NOTISHADE_OPEN);
|
2019-06-28 23:31:24 +00:00
|
|
|
setWindowSlippery(false);
|
|
|
|
|
}
|
2018-09-10 16:48:47 -07:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-22 16:00:09 -08:00
|
|
|
/**
|
|
|
|
|
* FLAG_SLIPPERY enables touches to slide out of a window into neighboring
|
|
|
|
|
* windows in mid-gesture instead of being captured for the duration of
|
|
|
|
|
* the gesture.
|
|
|
|
|
*
|
|
|
|
|
* This flag changes the behavior of touch focus for this window only.
|
|
|
|
|
* Touches can slide out of the window but they cannot necessarily slide
|
|
|
|
|
* back in (unless the other window with touch focus permits it).
|
|
|
|
|
*/
|
2023-05-17 14:38:21 -07:00
|
|
|
@VisibleForTesting
|
|
|
|
|
void setWindowSlippery(boolean enable) {
|
2019-06-28 23:31:24 +00:00
|
|
|
Window w = mLauncher.getWindow();
|
|
|
|
|
WindowManager.LayoutParams wlp = w.getAttributes();
|
|
|
|
|
if (enable) {
|
|
|
|
|
wlp.flags |= FLAG_SLIPPERY;
|
|
|
|
|
} else {
|
|
|
|
|
wlp.flags &= ~FLAG_SLIPPERY;
|
|
|
|
|
}
|
|
|
|
|
w.setAttributes(wlp);
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-10 16:48:47 -07:00
|
|
|
private boolean canInterceptTouch(MotionEvent ev) {
|
2018-09-19 16:06:16 -07:00
|
|
|
if (!mLauncher.isInState(LauncherState.NORMAL) ||
|
|
|
|
|
AbstractFloatingView.getTopOpenViewWithType(mLauncher,
|
|
|
|
|
AbstractFloatingView.TYPE_STATUS_BAR_SWIPE_DOWN_DISALLOW) != null) {
|
2018-09-10 16:48:47 -07:00
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
// For NORMAL state, only listen if the event originated above the navbar height
|
|
|
|
|
DeviceProfile dp = mLauncher.getDeviceProfile();
|
2023-04-17 12:56:52 -07:00
|
|
|
if (ev.getY() > (mLauncher.getDragLayer().getHeight() - dp.getInsets().bottom)) {
|
2018-09-10 16:48:47 -07:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-01 14:10:37 -07:00
|
|
|
return SystemUiProxy.INSTANCE.get(mLauncher).isActive();
|
2018-09-10 16:48:47 -07:00
|
|
|
}
|
2019-06-28 23:31:24 +00:00
|
|
|
}
|