summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/popup
diff options
context:
space:
mode:
authorVadim Tryshev <vadimt@google.com>2018-10-15 14:01:04 -0700
committerVadim Tryshev <vadimt@google.com>2018-10-19 14:34:00 -0700
commitdc7d25d3e18971e1199075a4b7e58a5ddfdf4d59 (patch)
tree822632cadfe69744231277dba0ac393e6f1d9dba /src/com/android/launcher3/popup
parent3f007ce28612df18d13f4ef19adc2609750c20cc (diff)
downloadandroid_packages_apps_Trebuchet-dc7d25d3e18971e1199075a4b7e58a5ddfdf4d59.tar.gz
android_packages_apps_Trebuchet-dc7d25d3e18971e1199075a4b7e58a5ddfdf4d59.tar.bz2
android_packages_apps_Trebuchet-dc7d25d3e18971e1199075a4b7e58a5ddfdf4d59.zip
Adding SystemShortcut for RemoteAction
Bug: 117888000 Test: manual test with a prototype Change-Id: I10ed0a8c0237a85af5ac32a7fc68e1f9d2ffc5ba
Diffstat (limited to 'src/com/android/launcher3/popup')
-rw-r--r--src/com/android/launcher3/popup/RemoteActionShortcut.java72
-rw-r--r--src/com/android/launcher3/popup/SystemShortcut.java16
2 files changed, 83 insertions, 5 deletions
diff --git a/src/com/android/launcher3/popup/RemoteActionShortcut.java b/src/com/android/launcher3/popup/RemoteActionShortcut.java
new file mode 100644
index 000000000..af0d3daa5
--- /dev/null
+++ b/src/com/android/launcher3/popup/RemoteActionShortcut.java
@@ -0,0 +1,72 @@
+/*
+ * 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.popup;
+
+import android.app.PendingIntent;
+import android.app.RemoteAction;
+import android.os.Handler;
+import android.os.Looper;
+import android.util.Log;
+import android.view.View;
+import android.widget.Toast;
+
+import com.android.launcher3.AbstractFloatingView;
+import com.android.launcher3.ItemInfo;
+import com.android.launcher3.Launcher;
+import com.android.launcher3.R;
+import com.android.launcher3.userevent.nano.LauncherLogProto;
+
+public class RemoteActionShortcut extends SystemShortcut<Launcher> {
+ private static final String TAG = "RemoteActionShortcut";
+
+ private final RemoteAction mAction;
+
+ public RemoteActionShortcut(RemoteAction action) {
+ super(action.getIcon(), action.getTitle(), action.getContentDescription(),
+ R.id.action_remote_action_shortcut);
+ mAction = action;
+ }
+
+ @Override
+ public View.OnClickListener getOnClickListener(
+ final Launcher launcher, final ItemInfo itemInfo) {
+ return view -> {
+ AbstractFloatingView.closeAllOpenViews(launcher);
+
+ try {
+ mAction.getActionIntent().send(0,
+ (pendingIntent, intent, resultCode, resultData, resultExtras) -> {
+ if (resultData != null && !resultData.isEmpty()) {
+ Log.e(TAG, "Remote action returned result: " + mAction.getTitle()
+ + " : " + resultData);
+ Toast.makeText(launcher, resultData, Toast.LENGTH_SHORT).show();
+ }
+ }, new Handler(Looper.getMainLooper()));
+ } catch (PendingIntent.CanceledException e) {
+ Log.e(TAG, "Remote action canceled: " + mAction.getTitle(), e);
+ Toast.makeText(launcher, launcher.getString(
+ R.string.remote_action_failed,
+ mAction.getTitle()),
+ Toast.LENGTH_SHORT)
+ .show();
+ }
+
+ launcher.getUserEventDispatcher().logActionOnControl(LauncherLogProto.Action.Touch.TAP,
+ LauncherLogProto.ControlType.REMOTE_ACTION_SHORTCUT, view);
+ };
+ }
+}
diff --git a/src/com/android/launcher3/popup/SystemShortcut.java b/src/com/android/launcher3/popup/SystemShortcut.java
index b80ba8abe..f9a200793 100644
--- a/src/com/android/launcher3/popup/SystemShortcut.java
+++ b/src/com/android/launcher3/popup/SystemShortcut.java
@@ -6,8 +6,10 @@ import static com.android.launcher3.userevent.nano.LauncherLogProto.ControlType;
import android.content.Context;
import android.content.Intent;
import android.graphics.Rect;
-import android.graphics.drawable.Drawable;
+import android.graphics.drawable.Icon;
import android.os.Bundle;
+import android.os.Handler;
+import android.os.Looper;
import android.view.View;
import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.ImageView;
@@ -36,7 +38,7 @@ import java.util.List;
public abstract class SystemShortcut<T extends BaseDraggingActivity> extends ItemInfo {
private final int mIconResId;
private final int mLabelResId;
- private final Drawable mIcon;
+ private final Icon mIcon;
private final CharSequence mLabel;
private final CharSequence mContentDescription;
private final int mAccessibilityActionId;
@@ -50,7 +52,7 @@ public abstract class SystemShortcut<T extends BaseDraggingActivity> extends Ite
mContentDescription = null;
}
- public SystemShortcut(Drawable icon, CharSequence label, CharSequence contentDescription,
+ public SystemShortcut(Icon icon, CharSequence label, CharSequence contentDescription,
int accessibilityActionId) {
mIcon = icon;
mLabel = label;
@@ -71,7 +73,9 @@ public abstract class SystemShortcut<T extends BaseDraggingActivity> extends Ite
public void setIconAndLabelFor(View iconView, TextView labelView) {
if (mIcon != null) {
- iconView.setBackground(mIcon);
+ mIcon.loadDrawableAsync(iconView.getContext(),
+ iconView::setBackground,
+ new Handler(Looper.getMainLooper()));
} else {
iconView.setBackgroundResource(mIconResId);
}
@@ -85,7 +89,9 @@ public abstract class SystemShortcut<T extends BaseDraggingActivity> extends Ite
public void setIconAndContentDescriptionFor(ImageView view) {
if (mIcon != null) {
- view.setImageDrawable(mIcon);
+ mIcon.loadDrawableAsync(view.getContext(),
+ view::setImageDrawable,
+ new Handler(Looper.getMainLooper()));
} else {
view.setImageResource(mIconResId);
}