diff --git a/protos/launcher_log.proto b/protos/launcher_log.proto index 41dd0bda4f..b3ed365b88 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 0efaccf194..85c2e65c51 100644 --- a/res/values/config.xml +++ b/res/values/config.xml @@ -123,6 +123,7 @@ + diff --git a/res/values/strings.xml b/res/values/strings.xml index eb6b28413d..7e5784d0bf 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -347,4 +347,7 @@ Notifications and apps are off Close Closed + + + Failed: %1$s diff --git a/src/com/android/launcher3/popup/RemoteActionShortcut.java b/src/com/android/launcher3/popup/RemoteActionShortcut.java new file mode 100644 index 0000000000..af0d3daa58 --- /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 { + 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 b80ba8abe1..f9a2007930 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 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 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 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 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); }