summaryrefslogtreecommitdiffstats
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
parent3f007ce28612df18d13f4ef19adc2609750c20cc (diff)
downloadpackages_apps_Trebuchet-dc7d25d3e18971e1199075a4b7e58a5ddfdf4d59.tar.gz
packages_apps_Trebuchet-dc7d25d3e18971e1199075a4b7e58a5ddfdf4d59.tar.bz2
packages_apps_Trebuchet-dc7d25d3e18971e1199075a4b7e58a5ddfdf4d59.zip
Adding SystemShortcut for RemoteAction
Bug: 117888000 Test: manual test with a prototype Change-Id: I10ed0a8c0237a85af5ac32a7fc68e1f9d2ffc5ba
-rw-r--r--protos/launcher_log.proto1
-rw-r--r--res/values/config.xml1
-rw-r--r--res/values/strings.xml3
-rw-r--r--src/com/android/launcher3/popup/RemoteActionShortcut.java72
-rw-r--r--src/com/android/launcher3/popup/SystemShortcut.java16
5 files changed, 88 insertions, 5 deletions
diff --git a/protos/launcher_log.proto b/protos/launcher_log.proto
index 41dd0bda4..b3ed365b8 100644
--- a/protos/launcher_log.proto
+++ b/protos/launcher_log.proto
@@ -112,6 +112,7 @@ enum ControlType {
CANCEL_TARGET = 14;
TASK_PREVIEW = 15;
SPLIT_SCREEN_TARGET = 16;
+ REMOTE_ACTION_SHORTCUT = 17;
}
enum TipType {
diff --git a/res/values/config.xml b/res/values/config.xml
index 0efaccf19..85c2e65c5 100644
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -123,6 +123,7 @@
<item type="id" name="action_deep_shortcuts" />
<item type="id" name="action_shortcuts_and_notifications"/>
<item type="id" name="action_dismiss_notification" />
+ <item type="id" name="action_remote_action_shortcut" />
<!-- QSB IDs. DO not change -->
<item type="id" name="search_container_workspace" />
diff --git a/res/values/strings.xml b/res/values/strings.xml
index eb6b28413..7e5784d0b 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -347,4 +347,7 @@
<string name="work_mode_off_label">Notifications and apps are off</string>
<string name="bottom_work_tab_user_education_close_button">Close</string>
<string name="bottom_work_tab_user_education_closed">Closed</string>
+
+ <!-- Failed action error message: e.g. Failed: Pause -->
+ <string name="remote_action_failed">Failed: <xliff:g id="what" example="Pause">%1$s</xliff:g></string>
</resources>
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);
}