Merge "Removing ViewScrim and cutom drawing code" into ub-launcher3-master
diff --git a/build.gradle b/build.gradle
index 7ac4127..b59f264 100644
--- a/build.gradle
+++ b/build.gradle
@@ -4,7 +4,7 @@
google()
}
dependencies {
- classpath 'com.android.tools.build:gradle:3.2.0-beta05'
+ classpath 'com.android.tools.build:gradle:3.2.0-rc03'
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.6'
}
}
@@ -16,7 +16,7 @@
android {
compileSdkVersion 28
- buildToolsVersion '28.0.0'
+ buildToolsVersion '28.0.2'
defaultConfig {
minSdkVersion 21
diff --git a/proguard.flags b/proguard.flags
index a312b91..bb52a6c 100644
--- a/proguard.flags
+++ b/proguard.flags
@@ -2,80 +2,6 @@
*;
}
--keep class com.android.launcher3.allapps.AllAppsBackgroundDrawable {
- public void setAlpha(int);
- public int getAlpha();
-}
-
--keep class com.android.launcher3.BaseRecyclerViewFastScrollBar {
- public void setThumbWidth(int);
- public int getThumbWidth();
- public void setTrackWidth(int);
- public int getTrackWidth();
-}
-
--keep class com.android.launcher3.BaseRecyclerViewFastScrollPopup {
- public void setAlpha(float);
- public float getAlpha();
-}
-
--keep class com.android.launcher3.ButtonDropTarget {
- public int getTextColor();
-}
-
--keep class com.android.launcher3.CellLayout {
- public float getBackgroundAlpha();
- public void setBackgroundAlpha(float);
-}
-
--keep class com.android.launcher3.CellLayout$LayoutParams {
- public void setWidth(int);
- public int getWidth();
- public void setHeight(int);
- public int getHeight();
- public void setX(int);
- public int getX();
- public void setY(int);
- public int getY();
-}
-
--keep class com.android.launcher3.views.BaseDragLayer$LayoutParams {
- public void setWidth(int);
- public int getWidth();
- public void setHeight(int);
- public int getHeight();
- public void setX(int);
- public int getX();
- public void setY(int);
- public int getY();
-}
-
--keep class com.android.launcher3.FastBitmapDrawable {
- public void setDesaturation(float);
- public float getDesaturation();
- public void setBrightness(float);
- public float getBrightness();
-}
-
--keep class com.android.launcher3.MemoryDumpActivity {
- *;
-}
-
--keep class com.android.launcher3.PreloadIconDrawable {
- public float getAnimationProgress();
- public void setAnimationProgress(float);
-}
-
--keep class com.android.launcher3.pageindicators.CaretDrawable {
- public float getCaretProgress();
- public void setCaretProgress(float);
-}
-
--keep class com.android.launcher3.Workspace {
- public float getBackgroundAlpha();
- public void setBackgroundAlpha(float);
-}
-
# Proguard will strip new callbacks in LauncherApps.Callback from
# WrappedCallback if compiled against an older SDK. Don't let this happen.
-keep class com.android.launcher3.compat.** {
diff --git a/quickstep/src/com/android/launcher3/uioverrides/StatusBarTouchController.java b/quickstep/src/com/android/launcher3/uioverrides/StatusBarTouchController.java
new file mode 100644
index 0000000..4d56786
--- /dev/null
+++ b/quickstep/src/com/android/launcher3/uioverrides/StatusBarTouchController.java
@@ -0,0 +1,118 @@
+/*
+ * 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.
+ */
+package com.android.launcher3.uioverrides;
+
+import static android.view.MotionEvent.ACTION_DOWN;
+import static android.view.MotionEvent.ACTION_MOVE;
+
+import android.os.RemoteException;
+import android.util.Log;
+import android.view.MotionEvent;
+import android.view.ViewConfiguration;
+
+import com.android.launcher3.AbstractFloatingView;
+import com.android.launcher3.DeviceProfile;
+import com.android.launcher3.Launcher;
+import com.android.launcher3.LauncherState;
+import com.android.launcher3.touch.TouchEventTranslator;
+import com.android.launcher3.util.TouchController;
+import com.android.quickstep.RecentsModel;
+import com.android.systemui.shared.recents.ISystemUiProxy;
+
+/**
+ * TouchController for handling touch events that get sent to the StatusBar. Once the
+ * Once the event delta y passes the touch slop, the events start getting forwarded.
+ * All events are offset by initial Y value of the pointer.
+ */
+public class StatusBarTouchController implements TouchController {
+
+ private static final String TAG = "StatusBarController";
+
+ protected final Launcher mLauncher;
+ protected final TouchEventTranslator mTranslator;
+ private final float mTouchSlop;
+ private ISystemUiProxy mSysUiProxy;
+
+ /* If {@code false}, this controller should not handle the input {@link MotionEvent}.*/
+ private boolean mCanIntercept;
+
+ public StatusBarTouchController(Launcher l) {
+ mLauncher = l;
+ mTouchSlop = ViewConfiguration.get(l).getScaledTouchSlop();
+ mTranslator = new TouchEventTranslator((MotionEvent ev)-> dispatchTouchEvent(ev));
+ }
+
+ private void dispatchTouchEvent(MotionEvent ev) {
+ try {
+ if (mSysUiProxy != null) {
+ mSysUiProxy.onStatusBarMotionEvent(ev);
+ }
+ } catch (RemoteException e) {
+ Log.e(TAG, "Remote exception on sysUiProxy.", e);
+ }
+ }
+
+ @Override
+ public final boolean onControllerInterceptTouchEvent(MotionEvent ev) {
+ int action = ev.getActionMasked();
+ if (action == ACTION_DOWN) {
+ mCanIntercept = canInterceptTouch(ev);
+ if (!mCanIntercept) {
+ return false;
+ }
+ mTranslator.reset();
+ mTranslator.setDownParameters(0, ev);
+ } else if (ev.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN) {
+ // Check!! should only set it only when threshold is not entered.
+ mTranslator.setDownParameters(ev.getActionIndex(), ev);
+ }
+ if (!mCanIntercept) {
+ return false;
+ }
+ if (action == ACTION_MOVE) {
+ float dy = ev.getY() - mTranslator.getDownY();
+ if (dy > mTouchSlop) {
+ mTranslator.dispatchDownEvents(ev);
+ mTranslator.processMotionEvent(ev);
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+ @Override
+ public final boolean onControllerTouchEvent(MotionEvent ev) {
+ mTranslator.processMotionEvent(ev);
+ return true;
+ }
+
+ private boolean canInterceptTouch(MotionEvent ev) {
+ if (!mLauncher.isInState(LauncherState.NORMAL) ||
+ AbstractFloatingView.getTopOpenViewWithType(mLauncher,
+ AbstractFloatingView.TYPE_STATUS_BAR_SWIPE_DOWN_DISALLOW) != null) {
+ return false;
+ } else {
+ // For NORMAL state, only listen if the event originated above the navbar height
+ DeviceProfile dp = mLauncher.getDeviceProfile();
+ if (ev.getY() > (mLauncher.getDragLayer().getHeight() - dp.getInsets().bottom)) {
+ return false;
+ }
+ }
+ mSysUiProxy = RecentsModel.INSTANCE.get(mLauncher).getSystemUiProxy();
+ return mSysUiProxy != null;
+ }
+}
diff --git a/quickstep/src/com/android/launcher3/uioverrides/UiFactory.java b/quickstep/src/com/android/launcher3/uioverrides/UiFactory.java
index c939330..5980d85 100644
--- a/quickstep/src/com/android/launcher3/uioverrides/UiFactory.java
+++ b/quickstep/src/com/android/launcher3/uioverrides/UiFactory.java
@@ -42,6 +42,7 @@
import com.android.launcher3.LauncherStateManager.StateHandler;
import com.android.launcher3.Utilities;
import com.android.launcher3.anim.AnimatorPlaybackController;
+import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.util.TouchController;
import com.android.quickstep.OverviewInteractionState;
import com.android.quickstep.RecentsModel;
@@ -52,6 +53,7 @@
import java.io.ByteArrayOutputStream;
import java.io.PrintWriter;
+import java.util.ArrayList;
import java.util.zip.Deflater;
public class UiFactory {
@@ -59,24 +61,25 @@
public static TouchController[] createTouchControllers(Launcher launcher) {
boolean swipeUpEnabled = OverviewInteractionState.INSTANCE.get(launcher)
.isSwipeUpGestureEnabled();
- if (!swipeUpEnabled) {
- return new TouchController[] {
- launcher.getDragController(),
- new OverviewToAllAppsTouchController(launcher),
- new LauncherTaskViewController(launcher)};
+ ArrayList<TouchController> list = new ArrayList<>();
+ list.add(launcher.getDragController());
+
+ if (!swipeUpEnabled || launcher.getDeviceProfile().isVerticalBarLayout()) {
+ list.add(new OverviewToAllAppsTouchController(launcher));
}
+
if (launcher.getDeviceProfile().isVerticalBarLayout()) {
- return new TouchController[] {
- launcher.getDragController(),
- new OverviewToAllAppsTouchController(launcher),
- new LandscapeEdgeSwipeController(launcher),
- new LauncherTaskViewController(launcher)};
+ list.add(new LandscapeEdgeSwipeController(launcher));
} else {
- return new TouchController[] {
- launcher.getDragController(),
- new PortraitStatesTouchController(launcher),
- new LauncherTaskViewController(launcher)};
+ list.add(new PortraitStatesTouchController(launcher));
}
+ if (FeatureFlags.PULL_DOWN_STATUS_BAR && Utilities.IS_DEBUG_DEVICE
+ && !launcher.getDeviceProfile().isMultiWindowMode
+ && !launcher.getDeviceProfile().isVerticalBarLayout()) {
+ list.add(new StatusBarTouchController(launcher));
+ }
+ list.add(new LauncherTaskViewController(launcher));
+ return list.toArray(new TouchController[list.size()]);
}
public static void setOnTouchControllersChangedListener(Context context, Runnable listener) {
diff --git a/src/com/android/launcher3/AbstractFloatingView.java b/src/com/android/launcher3/AbstractFloatingView.java
index 4fe6099..4575132 100644
--- a/src/com/android/launcher3/AbstractFloatingView.java
+++ b/src/com/android/launcher3/AbstractFloatingView.java
@@ -91,6 +91,11 @@
public static final int TYPE_ACCESSIBLE = TYPE_ALL
& ~TYPE_DISCOVERY_BOUNCE & ~TYPE_QUICKSTEP_PREVIEW;
+ // These view all have particular operation associated with swipe down interaction.
+ public static final int TYPE_STATUS_BAR_SWIPE_DOWN_DISALLOW = TYPE_WIDGETS_BOTTOM_SHEET |
+ TYPE_WIDGETS_FULL_SHEET | TYPE_WIDGET_RESIZE_FRAME | TYPE_ON_BOARD_POPUP |
+ TYPE_DISCOVERY_BOUNCE | TYPE_TASK_MENU ;
+
protected boolean mIsOpen;
public AbstractFloatingView(Context context, AttributeSet attrs) {
diff --git a/src/com/android/launcher3/AppWidgetResizeFrame.java b/src/com/android/launcher3/AppWidgetResizeFrame.java
index 0f5317b..8e2ffe9 100644
--- a/src/com/android/launcher3/AppWidgetResizeFrame.java
+++ b/src/com/android/launcher3/AppWidgetResizeFrame.java
@@ -1,5 +1,10 @@
package com.android.launcher3;
+import static com.android.launcher3.LauncherAnimUtils.LAYOUT_HEIGHT;
+import static com.android.launcher3.LauncherAnimUtils.LAYOUT_WIDTH;
+import static com.android.launcher3.views.BaseDragLayer.LAYOUT_X;
+import static com.android.launcher3.views.BaseDragLayer.LAYOUT_Y;
+
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
@@ -429,10 +434,10 @@
requestLayout();
} else {
ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(lp,
- PropertyValuesHolder.ofInt("width", lp.width, newWidth),
- PropertyValuesHolder.ofInt("height", lp.height, newHeight),
- PropertyValuesHolder.ofInt("x", lp.x, newX),
- PropertyValuesHolder.ofInt("y", lp.y, newY));
+ PropertyValuesHolder.ofInt(LAYOUT_WIDTH, lp.width, newWidth),
+ PropertyValuesHolder.ofInt(LAYOUT_HEIGHT, lp.height, newHeight),
+ PropertyValuesHolder.ofInt(LAYOUT_X, lp.x, newX),
+ PropertyValuesHolder.ofInt(LAYOUT_Y, lp.y, newY));
mFirstFrameAnimatorHelper.addTo(oa).addUpdateListener(a -> requestLayout());
AnimatorSet set = new AnimatorSet();
diff --git a/src/com/android/launcher3/ButtonDropTarget.java b/src/com/android/launcher3/ButtonDropTarget.java
index dd63ebc..2b0da43 100644
--- a/src/com/android/launcher3/ButtonDropTarget.java
+++ b/src/com/android/launcher3/ButtonDropTarget.java
@@ -33,6 +33,7 @@
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.AttributeSet;
+import android.util.Property;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
@@ -55,6 +56,20 @@
public abstract class ButtonDropTarget extends TextView
implements DropTarget, DragController.DragListener, OnClickListener {
+ private static final Property<ButtonDropTarget, Integer> TEXT_COLOR =
+ new Property<ButtonDropTarget, Integer>(Integer.TYPE, "textColor") {
+
+ @Override
+ public Integer get(ButtonDropTarget target) {
+ return target.getTextColor();
+ }
+
+ @Override
+ public void set(ButtonDropTarget target, Integer value) {
+ target.setTextColor(value);
+ }
+ };
+
private static final int[] sTempCords = new int[2];
private static final int DRAG_VIEW_DROP_DURATION = 285;
@@ -206,7 +221,7 @@
});
mCurrentColorAnim.play(anim1);
- mCurrentColorAnim.play(ObjectAnimator.ofArgb(this, "textColor", targetColor));
+ mCurrentColorAnim.play(ObjectAnimator.ofArgb(this, TEXT_COLOR, targetColor));
mCurrentColorAnim.start();
}
diff --git a/src/com/android/launcher3/CellLayout.java b/src/com/android/launcher3/CellLayout.java
index f6f1496..a42238e 100644
--- a/src/com/android/launcher3/CellLayout.java
+++ b/src/com/android/launcher3/CellLayout.java
@@ -2678,38 +2678,6 @@
public String toString() {
return "(" + this.cellX + ", " + this.cellY + ")";
}
-
- public void setWidth(int width) {
- this.width = width;
- }
-
- public int getWidth() {
- return width;
- }
-
- public void setHeight(int height) {
- this.height = height;
- }
-
- public int getHeight() {
- return height;
- }
-
- public void setX(int x) {
- this.x = x;
- }
-
- public int getX() {
- return x;
- }
-
- public void setY(int y) {
- this.y = y;
- }
-
- public int getY() {
- return y;
- }
}
// This class stores info for two purposes:
diff --git a/src/com/android/launcher3/LauncherAnimUtils.java b/src/com/android/launcher3/LauncherAnimUtils.java
index ac07e88..aad3449 100644
--- a/src/com/android/launcher3/LauncherAnimUtils.java
+++ b/src/com/android/launcher3/LauncherAnimUtils.java
@@ -19,6 +19,7 @@
import android.graphics.drawable.Drawable;
import android.util.Property;
import android.view.View;
+import android.view.ViewGroup.LayoutParams;
public class LauncherAnimUtils {
/**
@@ -64,4 +65,30 @@
public static int blockedFlingDurationFactor(float velocity) {
return (int) Utilities.boundToRange(Math.abs(velocity) / 2, 2f, 6f);
}
+
+ public static final Property<LayoutParams, Integer> LAYOUT_WIDTH =
+ new Property<LayoutParams, Integer>(Integer.TYPE, "width") {
+ @Override
+ public Integer get(LayoutParams lp) {
+ return lp.width;
+ }
+
+ @Override
+ public void set(LayoutParams lp, Integer width) {
+ lp.width = width;
+ }
+ };
+
+ public static final Property<LayoutParams, Integer> LAYOUT_HEIGHT =
+ new Property<LayoutParams, Integer>(Integer.TYPE, "height") {
+ @Override
+ public Integer get(LayoutParams lp) {
+ return lp.height;
+ }
+
+ @Override
+ public void set(LayoutParams lp, Integer height) {
+ lp.height = height;
+ }
+ };
}
diff --git a/src/com/android/launcher3/SettingsActivity.java b/src/com/android/launcher3/SettingsActivity.java
index 8589b7e..1f80226 100644
--- a/src/com/android/launcher3/SettingsActivity.java
+++ b/src/com/android/launcher3/SettingsActivity.java
@@ -88,6 +88,11 @@
@Override
public boolean onPreferenceStartFragment(
PreferenceFragment preferenceFragment, Preference pref) {
+ if (getFragmentManager().isStateSaved()) {
+ // Sometimes onClick can come after onPause because of being posted on the handler.
+ // Skip starting new fragments in that case.
+ return false;
+ }
Fragment f = Fragment.instantiate(this, pref.getFragment(), pref.getExtras());
if (f instanceof DialogFragment) {
((DialogFragment) f).show(getFragmentManager(), pref.getKey());
@@ -241,8 +246,7 @@
* Content observer which listens for system badging setting changes,
* and updates the launcher badging setting subtext accordingly.
*/
- private static class IconBadgingObserver extends SettingsObserver.Secure
- implements Preference.OnPreferenceClickListener {
+ private static class IconBadgingObserver extends SettingsObserver.Secure {
private final ButtonPreference mBadgingPref;
private final ContentResolver mResolver;
@@ -275,16 +279,11 @@
}
}
mBadgingPref.setWidgetFrameVisible(!serviceEnabled);
- mBadgingPref.setOnPreferenceClickListener(serviceEnabled ? null : this);
+ mBadgingPref.setFragment(
+ serviceEnabled ? null : NotificationAccessConfirmation.class.getName());
mBadgingPref.setSummary(summary);
}
-
- @Override
- public boolean onPreferenceClick(Preference preference) {
- new NotificationAccessConfirmation().show(mFragmentManager, "notification_access");
- return true;
- }
}
public static class NotificationAccessConfirmation
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index 353916f..b5a770f 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -671,9 +671,6 @@
private void fadeAndRemoveEmptyScreen(int delay, int duration, final Runnable onComplete,
final boolean stripEmptyScreens) {
// XXX: Do we need to update LM workspace screens below?
- PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0f);
- PropertyValuesHolder bgAlpha = PropertyValuesHolder.ofFloat("backgroundAlpha", 0f);
-
final CellLayout cl = mWorkspaceScreens.get(EXTRA_EMPTY_SCREEN_ID);
mRemoveEmptyScreenRunnable = new Runnable() {
@@ -692,7 +689,7 @@
}
};
- ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(cl, alpha, bgAlpha);
+ ObjectAnimator oa = ObjectAnimator.ofFloat(cl, ALPHA, 0f);
oa.setDuration(duration);
oa.setStartDelay(delay);
oa.addListener(new AnimatorListenerAdapter() {
diff --git a/src/com/android/launcher3/config/BaseFlags.java b/src/com/android/launcher3/config/BaseFlags.java
index 05fc33f..b67d35b 100644
--- a/src/com/android/launcher3/config/BaseFlags.java
+++ b/src/com/android/launcher3/config/BaseFlags.java
@@ -36,6 +36,10 @@
// Feature flag to enable moving the QSB on the 0th screen of the workspace.
public static final boolean QSB_ON_FIRST_SCREEN = true;
+
+ //Feature flag to enable pulling down navigation shade from workspace.
+ public static final boolean PULL_DOWN_STATUS_BAR = true;
+
// When enabled the all-apps icon is not added to the hotseat.
public static final boolean NO_ALL_APPS_ICON = true;
diff --git a/src/com/android/launcher3/touch/AbstractStateChangeTouchController.java b/src/com/android/launcher3/touch/AbstractStateChangeTouchController.java
index fd9157e..7b09bcc 100644
--- a/src/com/android/launcher3/touch/AbstractStateChangeTouchController.java
+++ b/src/com/android/launcher3/touch/AbstractStateChangeTouchController.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2019 The Android Open Source Project
+ * 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.
diff --git a/src/com/android/launcher3/touch/TouchEventTranslator.java b/src/com/android/launcher3/touch/TouchEventTranslator.java
new file mode 100644
index 0000000..8a5c932
--- /dev/null
+++ b/src/com/android/launcher3/touch/TouchEventTranslator.java
@@ -0,0 +1,274 @@
+/*
+ * 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.
+ */
+package com.android.launcher3.touch;
+
+import android.graphics.PointF;
+import android.util.Log;
+import android.util.Pair;
+import android.util.SparseArray;
+import android.util.SparseLongArray;
+import android.view.MotionEvent;
+import android.view.MotionEvent.PointerCoords;
+import android.view.MotionEvent.PointerProperties;
+
+import com.android.launcher3.Utilities.Consumer;
+
+/**
+ * To minimize the size of the MotionEvent, historic events are not copied and passed via the
+ * listener.
+ */
+public class TouchEventTranslator {
+
+ private static final String TAG = "TouchEventTranslator";
+ private static final boolean DEBUG = false;
+
+ private class DownState {
+ long timeStamp;
+ float downY;
+ public DownState(long timeStamp, float downY) {
+ this.timeStamp = timeStamp;
+ this.downY = downY;
+ }
+ };
+ private final DownState ZERO = new DownState(0, 0f);
+
+ private final Consumer<MotionEvent> mListener;
+
+ private final SparseArray<DownState> mDownEvents;
+ private final SparseArray<PointF> mFingers;
+
+ private final SparseArray<Pair<PointerProperties[], PointerCoords[]>> mCache;
+
+ public TouchEventTranslator(Consumer<MotionEvent> listener) {
+ mDownEvents = new SparseArray<>();
+ mFingers = new SparseArray<>();
+ mCache = new SparseArray<>();
+
+ mListener = listener;
+ }
+
+ public void reset() {
+ mDownEvents.clear();
+ mFingers.clear();
+ }
+
+ public float getDownY() {
+ return mDownEvents.get(0).downY;
+ }
+
+ public void setDownParameters(int idx, MotionEvent e) {
+ DownState ev = new DownState(e.getEventTime(), e.getY(idx));
+ mDownEvents.append(idx, ev);
+ }
+
+ public void dispatchDownEvents(MotionEvent ev) {
+ for(int i = 0; i < ev.getPointerCount() && i < mDownEvents.size(); i++) {
+ int pid = ev.getPointerId(i);
+ put(pid, ev.getX(i), 0, mDownEvents.get(i).timeStamp, ev);
+ }
+ }
+
+ public void processMotionEvent(MotionEvent ev) {
+ if (DEBUG) {
+ printSamples(TAG + " processMotionEvent", ev);
+ }
+ int index = ev.getActionIndex();
+ float x = ev.getX(index);
+ float y = ev.getY(index) - mDownEvents.get(index, ZERO).downY;
+ switch (ev.getActionMasked()) {
+ case MotionEvent.ACTION_POINTER_DOWN:
+ int pid = ev.getPointerId(index);
+ if(mFingers.get(pid, null) != null) {
+ for(int i=0; i < ev.getPointerCount(); i++) {
+ pid = ev.getPointerId(i);
+ position(pid, x, y);
+ }
+ generateEvent(ev.getAction(), ev);
+ } else {
+ put(pid, x, y, ev);
+ }
+ break;
+ case MotionEvent.ACTION_MOVE:
+ for(int i=0; i < ev.getPointerCount(); i++) {
+ pid = ev.getPointerId(i);
+ position(pid, x, y);
+ }
+ generateEvent(ev.getAction(), ev);
+ break;
+ case MotionEvent.ACTION_POINTER_UP:
+ case MotionEvent.ACTION_UP:
+ pid = ev.getPointerId(index);
+ lift(pid, index, x, y, ev);
+ break;
+ case MotionEvent.ACTION_CANCEL:
+ cancel(ev);
+ break;
+ default:
+ Log.v(TAG, "Didn't process ");
+ printSamples(TAG, ev);
+
+ }
+ }
+
+ private TouchEventTranslator put(int id, float x, float y, MotionEvent ev) {
+ return put(id, x, y, ev.getEventTime(), ev);
+ }
+
+ private TouchEventTranslator put(int id, float x, float y, long ms, MotionEvent ev) {
+ checkFingerExistence(id, false);
+ boolean isInitialDown = (mFingers.size() == 0);
+
+ mFingers.put(id, new PointF(x, y));
+ int n = mFingers.size();
+
+ if (mCache.get(n) == null) {
+ PointerProperties[] properties = new PointerProperties[n];
+ PointerCoords[] coords = new PointerCoords[n];
+ for (int i = 0; i < n; i++) {
+ properties[i] = new PointerProperties();
+ coords[i] = new PointerCoords();
+ }
+ mCache.put(n, new Pair(properties, coords));
+ }
+
+ int action;
+ if (isInitialDown) {
+ action = MotionEvent.ACTION_DOWN;
+ } else {
+ action = MotionEvent.ACTION_POINTER_DOWN;
+ // Set the id of the changed pointer.
+ action |= id << MotionEvent.ACTION_POINTER_INDEX_SHIFT;
+ }
+ generateEvent(action, ms, ev);
+ return this;
+ }
+
+ public TouchEventTranslator position(int id, float x, float y) {
+ checkFingerExistence(id, true);
+ mFingers.get(id).set(x, y);
+ return this;
+ }
+
+ private TouchEventTranslator lift(int id, int index, MotionEvent ev) {
+ checkFingerExistence(id, true);
+ boolean isFinalUp = (mFingers.size() == 1);
+ int action;
+ if (isFinalUp) {
+ action = MotionEvent.ACTION_UP;
+ } else {
+ action = MotionEvent.ACTION_POINTER_UP;
+ // Set the id of the changed pointer.
+ action |= index << MotionEvent.ACTION_POINTER_INDEX_SHIFT;
+ }
+ generateEvent(action, ev);
+ mFingers.remove(id);
+ return this;
+ }
+
+ private TouchEventTranslator lift(int id, int index, float x, float y, MotionEvent ev) {
+ checkFingerExistence(id, true);
+ mFingers.get(id).set(x, y);
+ return lift(id, index, ev);
+ }
+
+ public TouchEventTranslator cancel(MotionEvent ev) {
+ generateEvent(MotionEvent.ACTION_CANCEL, ev);
+ mFingers.clear();
+ return this;
+ }
+
+ private void checkFingerExistence(int id, boolean shouldExist) {
+ if (shouldExist != (mFingers.get(id, null) != null)) {
+ throw new IllegalArgumentException(
+ shouldExist ? "Finger does not exist" : "Finger already exists");
+ }
+ }
+
+
+ /**
+ * Used to debug MotionEvents being sent/received.
+ */
+ public void printSamples(String msg, MotionEvent ev) {
+ System.out.printf("%s %s", msg, MotionEvent.actionToString(ev.getActionMasked()));
+ final int pointerCount = ev.getPointerCount();
+ System.out.printf("#%d/%d", ev.getPointerId(ev.getActionIndex()), pointerCount);
+ System.out.printf(" t=%d:", ev.getEventTime());
+ for (int p = 0; p < pointerCount; p++) {
+ System.out.printf(" id=%d: (%f,%f)",
+ ev.getPointerId(p), ev.getX(p), ev.getY(p));
+ }
+ System.out.println();
+ }
+
+ private void generateEvent(int action, MotionEvent ev) {
+ generateEvent(action, ev.getEventTime(), ev);
+ }
+
+ private void generateEvent(int action, long ms, MotionEvent ev) {
+ Pair<PointerProperties[], PointerCoords[]> state = getFingerState();
+ MotionEvent event = MotionEvent.obtain(
+ mDownEvents.get(0).timeStamp,
+ ms,
+ action,
+ state.first.length,
+ state.first,
+ state.second,
+ ev.getMetaState(),
+ ev.getButtonState() /* buttonState */,
+ ev.getXPrecision() /* xPrecision */,
+ ev.getYPrecision() /* yPrecision */,
+ ev.getDeviceId(),
+ ev.getEdgeFlags(),
+ ev.getSource(),
+ ev.getFlags() /* flags */);
+ if (DEBUG) {
+ printSamples(TAG + " generateEvent", event);
+ }
+ mListener.accept(event);
+ event.recycle();
+ }
+
+ /**
+ * Returns the description of the fingers' state expected by MotionEvent.
+ */
+ private Pair<PointerProperties[], PointerCoords[]> getFingerState() {
+ int nFingers = mFingers.size();
+
+ Pair<PointerProperties[], PointerCoords[]> result = mCache.get(nFingers);
+ PointerProperties[] properties = result.first;
+ PointerCoords[] coordinates = result.second;
+
+ int index = 0;
+ for (int i = 0; i < mFingers.size(); i++) {
+ int id = mFingers.keyAt(i);
+ PointF location = mFingers.get(id);
+
+ PointerProperties property = properties[i];
+ property.id = id;
+ property.toolType = MotionEvent.TOOL_TYPE_FINGER;
+ properties[index] = property;
+
+ PointerCoords coordinate = coordinates[i];
+ coordinate.x = location.x;
+ coordinate.y = location.y;
+ coordinate.pressure = 1.0f;
+ coordinates[index] = coordinate;
+
+ index++;
+ }
+ return mCache.get(nFingers);
+ }
+}
diff --git a/src/com/android/launcher3/views/BaseDragLayer.java b/src/com/android/launcher3/views/BaseDragLayer.java
index e8a879f..1faca15 100644
--- a/src/com/android/launcher3/views/BaseDragLayer.java
+++ b/src/com/android/launcher3/views/BaseDragLayer.java
@@ -21,6 +21,7 @@
import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
+import android.util.Property;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
@@ -42,6 +43,32 @@
public abstract class BaseDragLayer<T extends Context & ActivityContext>
extends InsettableFrameLayout {
+ public static final Property<LayoutParams, Integer> LAYOUT_X =
+ new Property<LayoutParams, Integer>(Integer.TYPE, "x") {
+ @Override
+ public Integer get(LayoutParams lp) {
+ return lp.x;
+ }
+
+ @Override
+ public void set(LayoutParams lp, Integer x) {
+ lp.x = x;
+ }
+ };
+
+ public static final Property<LayoutParams, Integer> LAYOUT_Y =
+ new Property<LayoutParams, Integer>(Integer.TYPE, "y") {
+ @Override
+ public Integer get(LayoutParams lp) {
+ return lp.y;
+ }
+
+ @Override
+ public void set(LayoutParams lp, Integer y) {
+ lp.y = y;
+ }
+ };
+
protected final int[] mTmpXY = new int[2];
protected final Rect mHitRect = new Rect();
@@ -307,38 +334,6 @@
public LayoutParams(ViewGroup.LayoutParams lp) {
super(lp);
}
-
- public void setWidth(int width) {
- this.width = width;
- }
-
- public int getWidth() {
- return width;
- }
-
- public void setHeight(int height) {
- this.height = height;
- }
-
- public int getHeight() {
- return height;
- }
-
- public void setX(int x) {
- this.x = x;
- }
-
- public int getX() {
- return x;
- }
-
- public void setY(int y) {
- this.y = y;
- }
-
- public int getY() {
- return y;
- }
}
protected void onLayout(boolean changed, int l, int t, int r, int b) {
diff --git a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java
index d450366..5a3d36d 100644
--- a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java
+++ b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java
@@ -56,6 +56,7 @@
import com.android.launcher3.util.Wait;
import com.android.launcher3.util.rule.LauncherActivityRule;
+import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
@@ -94,6 +95,12 @@
mLauncher = new LauncherInstrumentation(getInstrumentation());
mTargetContext = InstrumentationRegistry.getTargetContext();
mTargetPackage = mTargetContext.getPackageName();
+ mDevice.executeShellCommand("settings put global heads_up_notifications_enabled 0");
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ mDevice.executeShellCommand("settings put global heads_up_notifications_enabled 1");
}
protected void lockRotation(boolean naturalOrientation) throws RemoteException {
diff --git a/tests/src/com/android/launcher3/ui/widget/BindWidgetTest.java b/tests/src/com/android/launcher3/ui/widget/BindWidgetTest.java
index 0dc9b2e..17fdd26 100644
--- a/tests/src/com/android/launcher3/ui/widget/BindWidgetTest.java
+++ b/tests/src/com/android/launcher3/ui/widget/BindWidgetTest.java
@@ -103,6 +103,8 @@
if (mSessionId > -1) {
mTargetContext.getPackageManager().getPackageInstaller().abandonSession(mSessionId);
}
+
+ super.tearDown();
}
@Test
diff --git a/tests/tapl/com/android/launcher3/tapl/AppIcon.java b/tests/tapl/com/android/launcher3/tapl/AppIcon.java
index ea47503..a11f6df 100644
--- a/tests/tapl/com/android/launcher3/tapl/AppIcon.java
+++ b/tests/tapl/com/android/launcher3/tapl/AppIcon.java
@@ -42,6 +42,7 @@
/**
* Clicks the icon to launch its app.
*/
+ @Deprecated
public Background launch() {
LauncherInstrumentation.log("AppIcon.launch before click");
LauncherInstrumentation.assertTrue(
@@ -50,6 +51,20 @@
return new Background(mLauncher);
}
+ /**
+ * Clicks the icon to launch its app.
+ */
+ public Background launch(String packageName) {
+ LauncherInstrumentation.log("AppIcon.launch before click");
+ LauncherInstrumentation.assertTrue(
+ "Launching an app didn't open a new window: " + mIcon.getText(),
+ mIcon.clickAndWait(Until.newWindow(), LauncherInstrumentation.WAIT_TIME_MS));
+ LauncherInstrumentation.assertTrue(
+ "App didn't start: " + packageName, mLauncher.getDevice().wait(Until.hasObject(
+ By.pkg(packageName).depth(0)), LauncherInstrumentation.WAIT_TIME_MS));
+ return new Background(mLauncher);
+ }
+
UiObject2 getIcon() {
return mIcon;
}
diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
index 441fc65..9e4a615 100644
--- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
+++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
@@ -225,7 +225,10 @@
// otherwise waitForIdle may return immediately in case when there was a big enough pause in
// accessibility events prior to pressing Home.
executeAndWaitForEvent(
- () -> getSystemUiObject("home").click(),
+ () -> {
+ log("LauncherInstrumentation.pressHome before clicking");
+ getSystemUiObject("home").click();
+ },
event -> true,
"Pressing Home didn't produce any events");
mDevice.waitForIdle();