summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2017-03-30 15:30:47 -0700
committerSunny Goyal <sunnygoyal@google.com>2017-03-30 15:31:44 -0700
commit8a39b42cc84ee8e1e17861692e0e562c714f3d72 (patch)
treee1633a488149b7526534a9122eccd91f9bdea07f
parent6634869bad0eb36b34a52569cbfbe78e1ef3f9be (diff)
downloadandroid_packages_apps_Trebuchet-8a39b42cc84ee8e1e17861692e0e562c714f3d72.tar.gz
android_packages_apps_Trebuchet-8a39b42cc84ee8e1e17861692e0e562c714f3d72.tar.bz2
android_packages_apps_Trebuchet-8a39b42cc84ee8e1e17861692e0e562c714f3d72.zip
Delay the PinItemRequest#accept() call until the drop animation is finished.
This prevents the caller app from taking over the focus while animation it running. Change-Id: I51b6673c59e848c263727502dee90504ed3a2162
-rw-r--r--src/com/android/launcher3/Launcher.java2
-rw-r--r--src/com/android/launcher3/compat/LauncherAppsCompat.java28
-rw-r--r--src/com/android/launcher3/dragndrop/PinShortcutRequestActivityInfo.java10
3 files changed, 36 insertions, 4 deletions
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 0a1810a47..49d03902a 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -1456,7 +1456,7 @@ public class Launcher extends BaseActivity
ShortcutInfo info = null;
if (Utilities.isAtLeastO()) {
info = LauncherAppsCompat.createShortcutInfoFromPinItemRequest(
- this, PinItemRequestCompat.getPinItemRequest(data));
+ this, PinItemRequestCompat.getPinItemRequest(data), 0);
}
if (info == null) {
diff --git a/src/com/android/launcher3/compat/LauncherAppsCompat.java b/src/com/android/launcher3/compat/LauncherAppsCompat.java
index 2eb5b023b..4580b8108 100644
--- a/src/com/android/launcher3/compat/LauncherAppsCompat.java
+++ b/src/com/android/launcher3/compat/LauncherAppsCompat.java
@@ -27,10 +27,12 @@ import android.os.UserHandle;
import android.support.annotation.Nullable;
import com.android.launcher3.LauncherAppState;
+import com.android.launcher3.LauncherModel;
import com.android.launcher3.ShortcutInfo;
import com.android.launcher3.Utilities;
import com.android.launcher3.graphics.LauncherIcons;
import com.android.launcher3.shortcuts.ShortcutInfoCompat;
+import com.android.launcher3.util.LooperExecuter;
import java.util.List;
@@ -100,10 +102,32 @@ public abstract class LauncherAppsCompat {
*/
@Nullable
public static ShortcutInfo createShortcutInfoFromPinItemRequest(
- Context context, PinItemRequestCompat request) {
+ Context context, final PinItemRequestCompat request, final long acceptDelay) {
if (request != null &&
request.getRequestType() == PinItemRequestCompat.REQUEST_TYPE_SHORTCUT &&
- request.isValid() && request.accept()) {
+ request.isValid()) {
+
+ if (acceptDelay <= 0) {
+ if (!request.accept()) {
+ return null;
+ }
+ } else {
+ // Block the worker thread until the accept() is called.
+ new LooperExecuter(LauncherModel.getWorkerLooper()).execute(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ Thread.sleep(acceptDelay);
+ } catch (InterruptedException e) {
+ // Ignore
+ }
+ if (request.isValid()) {
+ request.accept();
+ }
+ }
+ });
+ }
+
ShortcutInfoCompat compat = new ShortcutInfoCompat(request.getShortcutInfo());
ShortcutInfo info = new ShortcutInfo(compat, context);
// Apply the unbadged icon and fetch the actual icon asynchronously.
diff --git a/src/com/android/launcher3/dragndrop/PinShortcutRequestActivityInfo.java b/src/com/android/launcher3/dragndrop/PinShortcutRequestActivityInfo.java
index 26460d776..bb5ac5b02 100644
--- a/src/com/android/launcher3/dragndrop/PinShortcutRequestActivityInfo.java
+++ b/src/com/android/launcher3/dragndrop/PinShortcutRequestActivityInfo.java
@@ -26,8 +26,10 @@ import android.graphics.drawable.Drawable;
import android.os.Build;
import com.android.launcher3.IconCache;
+import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherSettings;
+import com.android.launcher3.R;
import com.android.launcher3.compat.LauncherAppsCompat;
import com.android.launcher3.compat.PinItemRequestCompat;
import com.android.launcher3.compat.ShortcutConfigActivityInfo;
@@ -73,7 +75,13 @@ class PinShortcutRequestActivityInfo extends ShortcutConfigActivityInfo {
@Override
public com.android.launcher3.ShortcutInfo createShortcutInfo() {
- return LauncherAppsCompat.createShortcutInfoFromPinItemRequest(mContext, mRequest);
+ // Total duration for the drop animation to complete.
+ long duration = mContext.getResources().getInteger(R.integer.config_dropAnimMaxDuration) +
+ Launcher.EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT +
+ mContext.getResources().getInteger(R.integer.config_overlayTransitionTime) / 2;
+ // Delay the actual accept() call until the drop animation is complete.
+ return LauncherAppsCompat.createShortcutInfoFromPinItemRequest(
+ mContext, mRequest, duration);
}
@Override