Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 1 | /* |
Miranda Kephart | 43c0296 | 2020-01-10 17:50:48 -0500 | [diff] [blame] | 2 | * Copyright (C) 2020 The Android Open Source Project |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.systemui.screenshot; |
| 18 | |
Miranda Kephart | df62ee6 | 2020-01-10 18:21:44 -0500 | [diff] [blame] | 19 | import static android.provider.DeviceConfig.NAMESPACE_SYSTEMUI; |
Miranda Kephart | 0148b28 | 2019-10-31 15:36:21 -0400 | [diff] [blame] | 20 | import static android.view.View.VISIBLE; |
Adrian Roos | d122977 | 2018-03-21 14:46:10 +0100 | [diff] [blame] | 21 | import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS; |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 22 | |
Miranda Kephart | df62ee6 | 2020-01-10 18:21:44 -0500 | [diff] [blame] | 23 | import static com.android.internal.config.sysui.SystemUiDeviceConfigFlags.SCREENSHOT_SCROLLING_ENABLED; |
Winson Chung | ed376a3 | 2017-09-07 14:05:42 -0700 | [diff] [blame] | 24 | import static com.android.systemui.statusbar.phone.StatusBar.SYSTEM_DIALOG_REASON_SCREENSHOT; |
| 25 | |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 26 | import android.animation.Animator; |
| 27 | import android.animation.AnimatorListenerAdapter; |
| 28 | import android.animation.AnimatorSet; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 29 | import android.animation.ValueAnimator; |
Miranda Kephart | ea2e67a | 2019-10-29 11:52:56 -0400 | [diff] [blame] | 30 | import android.annotation.Nullable; |
Zak Cohen | ebd3b8b | 2020-01-17 11:16:00 -0800 | [diff] [blame] | 31 | import android.annotation.SuppressLint; |
Miranda Kephart | 43c0296 | 2020-01-10 17:50:48 -0500 | [diff] [blame] | 32 | import android.app.ActivityManager; |
Winson Chung | ed376a3 | 2017-09-07 14:05:42 -0700 | [diff] [blame] | 33 | import android.app.ActivityOptions; |
Winson Chung | c57ccf0 | 2011-10-13 15:04:59 -0700 | [diff] [blame] | 34 | import android.app.Notification; |
Winson Chung | c57ccf0 | 2011-10-13 15:04:59 -0700 | [diff] [blame] | 35 | import android.app.PendingIntent; |
Adam Powell | d4d3415 | 2015-04-17 12:13:40 -0700 | [diff] [blame] | 36 | import android.content.BroadcastReceiver; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 37 | import android.content.Context; |
Winson Chung | c57ccf0 | 2011-10-13 15:04:59 -0700 | [diff] [blame] | 38 | import android.content.Intent; |
| 39 | import android.content.res.Resources; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 40 | import android.graphics.Bitmap; |
Zak Cohen | ebd3b8b | 2020-01-17 11:16:00 -0800 | [diff] [blame] | 41 | import android.graphics.Insets; |
Miranda Kephart | 43c0296 | 2020-01-10 17:50:48 -0500 | [diff] [blame] | 42 | import android.graphics.Outline; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 43 | import android.graphics.PixelFormat; |
Winson Chung | a63bb84 | 2011-10-17 10:26:28 -0700 | [diff] [blame] | 44 | import android.graphics.PointF; |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 45 | import android.graphics.Rect; |
Miranda Kephart | 43c0296 | 2020-01-10 17:50:48 -0500 | [diff] [blame] | 46 | import android.graphics.Region; |
| 47 | import android.graphics.drawable.Icon; |
Eino-Ville Talvala | e690958 | 2012-03-01 11:01:38 -0800 | [diff] [blame] | 48 | import android.media.MediaActionSound; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 49 | import android.net.Uri; |
| 50 | import android.os.AsyncTask; |
Miranda Kephart | ea2e67a | 2019-10-29 11:52:56 -0400 | [diff] [blame] | 51 | import android.os.Handler; |
| 52 | import android.os.Looper; |
| 53 | import android.os.Message; |
Geoffrey Pitsch | ed5de31 | 2017-06-27 11:42:12 -0400 | [diff] [blame] | 54 | import android.os.PowerManager; |
Miranda Kephart | 43c0296 | 2020-01-10 17:50:48 -0500 | [diff] [blame] | 55 | import android.os.RemoteException; |
phweiss | ec3d9ca | 2017-02-09 16:57:39 +0100 | [diff] [blame] | 56 | import android.os.UserHandle; |
Miranda Kephart | df62ee6 | 2020-01-10 18:21:44 -0500 | [diff] [blame] | 57 | import android.provider.DeviceConfig; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 58 | import android.util.DisplayMetrics; |
Miranda Kephart | ea2e67a | 2019-10-29 11:52:56 -0400 | [diff] [blame] | 59 | import android.util.Log; |
Miranda Kephart | 4890f3e | 2020-02-05 15:55:11 -0500 | [diff] [blame] | 60 | import android.util.MathUtils; |
Dan Sandler | 150651b | 2017-06-14 10:43:07 -0400 | [diff] [blame] | 61 | import android.util.Slog; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 62 | import android.view.Display; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 63 | import android.view.LayoutInflater; |
| 64 | import android.view.MotionEvent; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -0800 | [diff] [blame] | 65 | import android.view.SurfaceControl; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 66 | import android.view.View; |
| 67 | import android.view.ViewGroup; |
Miranda Kephart | 43c0296 | 2020-01-10 17:50:48 -0500 | [diff] [blame] | 68 | import android.view.ViewOutlineProvider; |
| 69 | import android.view.ViewTreeObserver; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 70 | import android.view.WindowManager; |
Miranda Kephart | 4890f3e | 2020-02-05 15:55:11 -0500 | [diff] [blame] | 71 | import android.view.animation.AnimationUtils; |
Winson Chung | 22ca095 | 2011-10-20 19:44:32 -0700 | [diff] [blame] | 72 | import android.view.animation.Interpolator; |
Miranda Kephart | a2ebd76 | 2020-02-06 10:23:40 -0500 | [diff] [blame] | 73 | import android.widget.FrameLayout; |
Miranda Kephart | 43c0296 | 2020-01-10 17:50:48 -0500 | [diff] [blame] | 74 | import android.widget.HorizontalScrollView; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 75 | import android.widget.ImageView; |
Miranda Kephart | 0148b28 | 2019-10-31 15:36:21 -0400 | [diff] [blame] | 76 | import android.widget.LinearLayout; |
Geoffrey Pitsch | ed5de31 | 2017-06-27 11:42:12 -0400 | [diff] [blame] | 77 | import android.widget.Toast; |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 78 | |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 79 | import com.android.systemui.R; |
Dave Mankoff | 00e8a2f | 2019-12-18 16:59:49 -0500 | [diff] [blame] | 80 | import com.android.systemui.dagger.qualifiers.Main; |
Winson Chung | 06ca274 | 2018-06-29 12:26:49 -0700 | [diff] [blame] | 81 | import com.android.systemui.shared.system.ActivityManagerWrapper; |
| 82 | import com.android.systemui.statusbar.phone.StatusBar; |
Alison Cichowlas | 3e34050 | 2018-08-07 17:15:01 -0400 | [diff] [blame] | 83 | |
Satakshi | d2010f2 | 2019-10-29 10:57:43 -0700 | [diff] [blame] | 84 | import java.util.List; |
Garfield Tan | a2242397 | 2019-11-04 17:40:26 -0800 | [diff] [blame] | 85 | import java.util.Optional; |
Matt Pietal | 777c82d | 2019-06-11 15:47:10 -0400 | [diff] [blame] | 86 | import java.util.concurrent.ExecutionException; |
| 87 | import java.util.concurrent.TimeUnit; |
| 88 | import java.util.concurrent.TimeoutException; |
Aran Ink | eb565fc | 2019-11-15 15:52:31 -0500 | [diff] [blame] | 89 | import java.util.function.Consumer; |
Matt Pietal | 777c82d | 2019-06-11 15:47:10 -0400 | [diff] [blame] | 90 | |
Dave Mankoff | aefb346 | 2019-11-01 14:21:45 -0400 | [diff] [blame] | 91 | import javax.inject.Inject; |
| 92 | import javax.inject.Singleton; |
Matt Pietal | 777c82d | 2019-06-11 15:47:10 -0400 | [diff] [blame] | 93 | |
Garfield Tan | a2242397 | 2019-11-04 17:40:26 -0800 | [diff] [blame] | 94 | import dagger.Lazy; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 95 | |
| 96 | /** |
Sunny Goyal | af7cddd | 2019-11-05 17:49:17 -0800 | [diff] [blame] | 97 | * Class for handling device screen shots |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 98 | */ |
Sunny Goyal | af7cddd | 2019-11-05 17:49:17 -0800 | [diff] [blame] | 99 | @Singleton |
Miranda Kephart | 43c0296 | 2020-01-10 17:50:48 -0500 | [diff] [blame] | 100 | public class GlobalScreenshot implements ViewTreeObserver.OnComputeInternalInsetsListener { |
Winson Chung | 0e6232c | 2013-01-22 14:11:46 -0800 | [diff] [blame] | 101 | |
Sunny Goyal | af7cddd | 2019-11-05 17:49:17 -0800 | [diff] [blame] | 102 | /** |
| 103 | * POD used in the AsyncTask which saves an image in the background. |
| 104 | */ |
Miranda Kephart | ca6c5eb | 2019-11-14 12:44:11 -0500 | [diff] [blame] | 105 | static class SaveImageInBackgroundData { |
Sunny Goyal | af7cddd | 2019-11-05 17:49:17 -0800 | [diff] [blame] | 106 | public Bitmap image; |
| 107 | public Uri imageUri; |
Aran Ink | eb565fc | 2019-11-15 15:52:31 -0500 | [diff] [blame] | 108 | public Consumer<Uri> finisher; |
Miranda Kephart | 0148b28 | 2019-10-31 15:36:21 -0400 | [diff] [blame] | 109 | public GlobalScreenshot.ActionsReadyListener mActionsReadyListener; |
Sunny Goyal | af7cddd | 2019-11-05 17:49:17 -0800 | [diff] [blame] | 110 | public int errorMsgResId; |
Miranda Kephart | 43c0296 | 2020-01-10 17:50:48 -0500 | [diff] [blame] | 111 | public boolean createDeleteAction; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 112 | |
Sunny Goyal | af7cddd | 2019-11-05 17:49:17 -0800 | [diff] [blame] | 113 | void clearImage() { |
| 114 | image = null; |
| 115 | imageUri = null; |
Sunny Goyal | af7cddd | 2019-11-05 17:49:17 -0800 | [diff] [blame] | 116 | } |
Winson Chung | c57ccf0 | 2011-10-13 15:04:59 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Miranda Kephart | 0148b28 | 2019-10-31 15:36:21 -0400 | [diff] [blame] | 119 | abstract static class ActionsReadyListener { |
Miranda Kephart | 43c0296 | 2020-01-10 17:50:48 -0500 | [diff] [blame] | 120 | abstract void onActionsReady(Uri imageUri, List<Notification.Action> smartActions, |
| 121 | List<Notification.Action> actions); |
Miranda Kephart | 0148b28 | 2019-10-31 15:36:21 -0400 | [diff] [blame] | 122 | } |
| 123 | |
Satakshi | aaf6953 | 2019-11-07 17:54:24 -0800 | [diff] [blame] | 124 | // These strings are used for communicating the action invoked to |
| 125 | // ScreenshotNotificationSmartActionsProvider. |
| 126 | static final String EXTRA_ACTION_TYPE = "android:screenshot_action_type"; |
| 127 | static final String EXTRA_ID = "android:screenshot_id"; |
| 128 | static final String ACTION_TYPE_DELETE = "Delete"; |
| 129 | static final String ACTION_TYPE_SHARE = "Share"; |
| 130 | static final String ACTION_TYPE_EDIT = "Edit"; |
| 131 | static final String EXTRA_SMART_ACTIONS_ENABLED = "android:smart_actions_enabled"; |
Winson Chung | 06ca274 | 2018-06-29 12:26:49 -0700 | [diff] [blame] | 132 | static final String EXTRA_ACTION_INTENT = "android:screenshot_action_intent"; |
Satakshi | aaf6953 | 2019-11-07 17:54:24 -0800 | [diff] [blame] | 133 | |
| 134 | static final String SCREENSHOT_URI_ID = "android:screenshot_uri_id"; |
Winson Chung | 06ca274 | 2018-06-29 12:26:49 -0700 | [diff] [blame] | 135 | static final String EXTRA_CANCEL_NOTIFICATION = "android:screenshot_cancel_notification"; |
| 136 | static final String EXTRA_DISALLOW_ENTER_PIP = "android:screenshot_disallow_enter_pip"; |
Adam Powell | d4d3415 | 2015-04-17 12:13:40 -0700 | [diff] [blame] | 137 | |
Matt Pietal | 777c82d | 2019-06-11 15:47:10 -0400 | [diff] [blame] | 138 | private static final String TAG = "GlobalScreenshot"; |
| 139 | |
Miranda Kephart | 4890f3e | 2020-02-05 15:55:11 -0500 | [diff] [blame] | 140 | private static final long SCREENSHOT_FLASH_IN_DURATION_MS = 133; |
| 141 | private static final long SCREENSHOT_FLASH_OUT_DURATION_MS = 217; |
| 142 | private static final long SCREENSHOT_TO_CORNER_X_DURATION_MS = 234; |
| 143 | private static final long SCREENSHOT_TO_CORNER_Y_DURATION_MS = 500; |
| 144 | private static final long SCREENSHOT_TO_CORNER_SCALE_DURATION_MS = 234; |
Miranda Kephart | 43c0296 | 2020-01-10 17:50:48 -0500 | [diff] [blame] | 145 | private static final float ROUNDED_CORNER_RADIUS = .05f; |
Miranda Kephart | a2ebd76 | 2020-02-06 10:23:40 -0500 | [diff] [blame] | 146 | private static final long SCREENSHOT_CORNER_TIMEOUT_MILLIS = 6000; |
Miranda Kephart | ea2e67a | 2019-10-29 11:52:56 -0400 | [diff] [blame] | 147 | private static final int MESSAGE_CORNER_TIMEOUT = 2; |
Miranda Kephart | 9bbecf3 | 2019-12-06 10:54:58 -0500 | [diff] [blame] | 148 | |
| 149 | private final ScreenshotNotificationsController mNotificationsController; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 150 | |
Miranda Kephart | 43c0296 | 2020-01-10 17:50:48 -0500 | [diff] [blame] | 151 | private final Context mContext; |
| 152 | private final WindowManager mWindowManager; |
| 153 | private final WindowManager.LayoutParams mWindowLayoutParams; |
| 154 | private final Display mDisplay; |
| 155 | private final DisplayMetrics mDisplayMetrics; |
| 156 | |
| 157 | private final View mScreenshotLayout; |
| 158 | private final ScreenshotSelectorView mScreenshotSelectorView; |
| 159 | private final ImageView mBackgroundView; |
| 160 | private final ImageView mScreenshotView; |
| 161 | private final ImageView mScreenshotFlash; |
| 162 | private final HorizontalScrollView mActionsContainer; |
| 163 | private final LinearLayout mActionsView; |
| 164 | private final ImageView mBackgroundProtection; |
Miranda Kephart | a2ebd76 | 2020-02-06 10:23:40 -0500 | [diff] [blame] | 165 | private final FrameLayout mDismissButton; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 166 | |
| 167 | private Bitmap mScreenBitmap; |
Miranda Kephart | 4890f3e | 2020-02-05 15:55:11 -0500 | [diff] [blame] | 168 | private Animator mScreenshotAnimation; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 169 | |
Miranda Kephart | 43c0296 | 2020-01-10 17:50:48 -0500 | [diff] [blame] | 170 | private float mScreenshotOffsetXPx; |
| 171 | private float mScreenshotOffsetYPx; |
| 172 | private float mScreenshotHeightPx; |
Miranda Kephart | a2ebd76 | 2020-02-06 10:23:40 -0500 | [diff] [blame] | 173 | private float mDismissButtonSize; |
Miranda Kephart | 4890f3e | 2020-02-05 15:55:11 -0500 | [diff] [blame] | 174 | private float mCornerSizeX; |
Winson Chung | a63bb84 | 2011-10-17 10:26:28 -0700 | [diff] [blame] | 175 | |
Winson | c7aa65b | 2016-03-10 12:52:27 -0800 | [diff] [blame] | 176 | private AsyncTask<Void, Void, Void> mSaveInBgTask; |
Winson Chung | 0e6232c | 2013-01-22 14:11:46 -0800 | [diff] [blame] | 177 | |
Eino-Ville Talvala | e690958 | 2012-03-01 11:01:38 -0800 | [diff] [blame] | 178 | private MediaActionSound mCameraSound; |
Winson Chung | 8d513ea | 2011-12-01 14:39:12 -0800 | [diff] [blame] | 179 | |
Miranda Kephart | 4890f3e | 2020-02-05 15:55:11 -0500 | [diff] [blame] | 180 | // standard material ease |
| 181 | private final Interpolator mFastOutSlowIn; |
| 182 | |
Miranda Kephart | ea2e67a | 2019-10-29 11:52:56 -0400 | [diff] [blame] | 183 | private final Handler mScreenshotHandler = new Handler(Looper.getMainLooper()) { |
| 184 | @Override |
| 185 | public void handleMessage(Message msg) { |
| 186 | switch (msg.what) { |
| 187 | case MESSAGE_CORNER_TIMEOUT: |
Miranda Kephart | 43c0296 | 2020-01-10 17:50:48 -0500 | [diff] [blame] | 188 | GlobalScreenshot.this.clearScreenshot("timeout"); |
Miranda Kephart | ea2e67a | 2019-10-29 11:52:56 -0400 | [diff] [blame] | 189 | break; |
| 190 | default: |
| 191 | break; |
| 192 | } |
| 193 | } |
| 194 | }; |
| 195 | |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 196 | /** |
| 197 | * @param context everything needs a context :( |
| 198 | */ |
Dave Mankoff | aefb346 | 2019-11-01 14:21:45 -0400 | [diff] [blame] | 199 | @Inject |
Miranda Kephart | 9bbecf3 | 2019-12-06 10:54:58 -0500 | [diff] [blame] | 200 | public GlobalScreenshot( |
Dave Mankoff | 00e8a2f | 2019-12-18 16:59:49 -0500 | [diff] [blame] | 201 | Context context, @Main Resources resources, LayoutInflater layoutInflater, |
Miranda Kephart | 9bbecf3 | 2019-12-06 10:54:58 -0500 | [diff] [blame] | 202 | ScreenshotNotificationsController screenshotNotificationsController) { |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 203 | mContext = context; |
Miranda Kephart | 9bbecf3 | 2019-12-06 10:54:58 -0500 | [diff] [blame] | 204 | mNotificationsController = screenshotNotificationsController; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 205 | |
| 206 | // Inflate the screenshot layout |
Romain Guy | 8279acb | 2011-11-29 13:56:25 -0800 | [diff] [blame] | 207 | mScreenshotLayout = layoutInflater.inflate(R.layout.global_screenshot, null); |
Dave Mankoff | aefb346 | 2019-11-01 14:21:45 -0400 | [diff] [blame] | 208 | mBackgroundView = mScreenshotLayout.findViewById(R.id.global_screenshot_background); |
| 209 | mScreenshotView = mScreenshotLayout.findViewById(R.id.global_screenshot); |
Miranda Kephart | 43c0296 | 2020-01-10 17:50:48 -0500 | [diff] [blame] | 210 | mScreenshotView.setClipToOutline(true); |
| 211 | mScreenshotView.setOutlineProvider(new ViewOutlineProvider() { |
| 212 | @Override |
| 213 | public void getOutline(View view, Outline outline) { |
| 214 | outline.setRoundRect(new Rect(0, 0, view.getWidth(), view.getHeight()), |
| 215 | ROUNDED_CORNER_RADIUS * view.getWidth()); |
| 216 | } |
| 217 | }); |
| 218 | |
| 219 | mActionsContainer = mScreenshotLayout.findViewById( |
| 220 | R.id.global_screenshot_actions_container); |
Miranda Kephart | 0148b28 | 2019-10-31 15:36:21 -0400 | [diff] [blame] | 221 | mActionsView = mScreenshotLayout.findViewById(R.id.global_screenshot_actions); |
Miranda Kephart | 43c0296 | 2020-01-10 17:50:48 -0500 | [diff] [blame] | 222 | mBackgroundProtection = mScreenshotLayout.findViewById( |
| 223 | R.id.global_screenshot_actions_background); |
Miranda Kephart | a2ebd76 | 2020-02-06 10:23:40 -0500 | [diff] [blame] | 224 | mDismissButton = mScreenshotLayout.findViewById(R.id.global_screenshot_dismiss_button); |
| 225 | mDismissButton.setOnClickListener(view -> clearScreenshot("dismiss_button")); |
Miranda Kephart | 0148b28 | 2019-10-31 15:36:21 -0400 | [diff] [blame] | 226 | |
Dave Mankoff | aefb346 | 2019-11-01 14:21:45 -0400 | [diff] [blame] | 227 | mScreenshotFlash = mScreenshotLayout.findViewById(R.id.global_screenshot_flash); |
| 228 | mScreenshotSelectorView = mScreenshotLayout.findViewById(R.id.global_screenshot_selector); |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 229 | mScreenshotLayout.setFocusable(true); |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 230 | mScreenshotSelectorView.setFocusable(true); |
| 231 | mScreenshotSelectorView.setFocusableInTouchMode(true); |
Miranda Kephart | 4890f3e | 2020-02-05 15:55:11 -0500 | [diff] [blame] | 232 | mScreenshotView.setPivotX(0); |
| 233 | mScreenshotView.setPivotY(0); |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 234 | |
| 235 | // Setup the window that we are going to use |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 236 | mWindowLayoutParams = new WindowManager.LayoutParams( |
| 237 | ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 0, 0, |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 238 | WindowManager.LayoutParams.TYPE_SCREENSHOT, |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 239 | WindowManager.LayoutParams.FLAG_FULLSCREEN |
Miranda Kephart | ca6c5eb | 2019-11-14 12:44:11 -0500 | [diff] [blame] | 240 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
Miranda Kephart | 43c0296 | 2020-01-10 17:50:48 -0500 | [diff] [blame] | 241 | | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
| 242 | | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH |
Miranda Kephart | ca6c5eb | 2019-11-14 12:44:11 -0500 | [diff] [blame] | 243 | | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED, |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 244 | PixelFormat.TRANSLUCENT); |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 245 | mWindowLayoutParams.setTitle("ScreenshotAnimation"); |
Adrian Roos | d122977 | 2018-03-21 14:46:10 +0100 | [diff] [blame] | 246 | mWindowLayoutParams.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS; |
Tiger Huang | 5272444 | 2020-01-20 21:38:42 +0800 | [diff] [blame] | 247 | mWindowLayoutParams.setFitInsetsTypes(0 /* types */); |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 248 | mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); |
| 249 | mDisplay = mWindowManager.getDefaultDisplay(); |
Winson Chung | a63bb84 | 2011-10-17 10:26:28 -0700 | [diff] [blame] | 250 | mDisplayMetrics = new DisplayMetrics(); |
| 251 | mDisplay.getRealMetrics(mDisplayMetrics); |
| 252 | |
Miranda Kephart | 43c0296 | 2020-01-10 17:50:48 -0500 | [diff] [blame] | 253 | mScreenshotOffsetXPx = resources.getDimensionPixelSize(R.dimen.screenshot_offset_x); |
| 254 | mScreenshotOffsetYPx = resources.getDimensionPixelSize(R.dimen.screenshot_offset_y); |
| 255 | mScreenshotHeightPx = |
| 256 | resources.getDimensionPixelSize(R.dimen.screenshot_action_container_offset_y); |
Miranda Kephart | a2ebd76 | 2020-02-06 10:23:40 -0500 | [diff] [blame] | 257 | mDismissButtonSize = resources.getDimensionPixelSize( |
| 258 | R.dimen.screenshot_dismiss_button_tappable_size); |
Miranda Kephart | 4890f3e | 2020-02-05 15:55:11 -0500 | [diff] [blame] | 259 | mCornerSizeX = resources.getDimensionPixelSize(R.dimen.global_screenshot_x_scale); |
| 260 | |
| 261 | mFastOutSlowIn = |
| 262 | AnimationUtils.loadInterpolator(mContext, android.R.interpolator.fast_out_slow_in); |
Chris Wren | f63185e | 2014-07-31 13:52:39 +0100 | [diff] [blame] | 263 | |
Winson Chung | 8d513ea | 2011-12-01 14:39:12 -0800 | [diff] [blame] | 264 | // Setup the Camera shutter sound |
Eino-Ville Talvala | e690958 | 2012-03-01 11:01:38 -0800 | [diff] [blame] | 265 | mCameraSound = new MediaActionSound(); |
| 266 | mCameraSound.load(MediaActionSound.SHUTTER_CLICK); |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 267 | } |
| 268 | |
Miranda Kephart | 43c0296 | 2020-01-10 17:50:48 -0500 | [diff] [blame] | 269 | @Override // ViewTreeObserver.OnComputeInternalInsetsListener |
| 270 | public void onComputeInternalInsets(ViewTreeObserver.InternalInsetsInfo inoutInfo) { |
| 271 | inoutInfo.setTouchableInsets(ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION); |
| 272 | Region touchRegion = new Region(); |
| 273 | |
| 274 | Rect screenshotRect = new Rect(); |
| 275 | mScreenshotView.getBoundsOnScreen(screenshotRect); |
| 276 | touchRegion.op(screenshotRect, Region.Op.UNION); |
| 277 | Rect actionsRect = new Rect(); |
| 278 | mActionsContainer.getBoundsOnScreen(actionsRect); |
| 279 | touchRegion.op(actionsRect, Region.Op.UNION); |
Miranda Kephart | a2ebd76 | 2020-02-06 10:23:40 -0500 | [diff] [blame] | 280 | Rect dismissRect = new Rect(); |
| 281 | mDismissButton.getBoundsOnScreen(dismissRect); |
| 282 | touchRegion.op(dismissRect, Region.Op.UNION); |
Miranda Kephart | 43c0296 | 2020-01-10 17:50:48 -0500 | [diff] [blame] | 283 | |
| 284 | inoutInfo.touchableRegion.set(touchRegion); |
| 285 | } |
| 286 | |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 287 | /** |
| 288 | * Creates a new worker thread and saves the screenshot to the media store. |
| 289 | */ |
Miranda Kephart | ea2e67a | 2019-10-29 11:52:56 -0400 | [diff] [blame] | 290 | private void saveScreenshotInWorkerThread( |
Miranda Kephart | 0148b28 | 2019-10-31 15:36:21 -0400 | [diff] [blame] | 291 | Consumer<Uri> finisher, @Nullable ActionsReadyListener actionsReadyListener) { |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 292 | SaveImageInBackgroundData data = new SaveImageInBackgroundData(); |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 293 | data.image = mScreenBitmap; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 294 | data.finisher = finisher; |
Miranda Kephart | 0148b28 | 2019-10-31 15:36:21 -0400 | [diff] [blame] | 295 | data.mActionsReadyListener = actionsReadyListener; |
Miranda Kephart | 43c0296 | 2020-01-10 17:50:48 -0500 | [diff] [blame] | 296 | data.createDeleteAction = false; |
Winson Chung | 0e6232c | 2013-01-22 14:11:46 -0800 | [diff] [blame] | 297 | if (mSaveInBgTask != null) { |
| 298 | mSaveInBgTask.cancel(false); |
| 299 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 300 | |
Miranda Kephart | 9bbecf3 | 2019-12-06 10:54:58 -0500 | [diff] [blame] | 301 | mSaveInBgTask = new SaveImageInBackgroundTask(mContext, data).execute(); |
Miranda Kephart | ea2e67a | 2019-10-29 11:52:56 -0400 | [diff] [blame] | 302 | } |
| 303 | |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 304 | /** |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 305 | * Takes a screenshot of the current display and shows an animation. |
| 306 | */ |
Miranda Kephart | 63e65a9 | 2020-01-10 11:18:51 -0500 | [diff] [blame] | 307 | private void takeScreenshot(Consumer<Uri> finisher, Rect crop) { |
Miranda Kephart | 43c0296 | 2020-01-10 17:50:48 -0500 | [diff] [blame] | 308 | clearScreenshot("new screenshot requested"); |
| 309 | |
chaviw | a69e0a7 | 2017-11-29 17:55:12 -0800 | [diff] [blame] | 310 | int rot = mDisplay.getRotation(); |
| 311 | int width = crop.width(); |
| 312 | int height = crop.height(); |
Winson Chung | a46d778 | 2012-01-04 16:43:10 -0800 | [diff] [blame] | 313 | |
Miranda Kephart | 4890f3e | 2020-02-05 15:55:11 -0500 | [diff] [blame] | 314 | Rect screenRect = new Rect(0, 0, mDisplayMetrics.widthPixels, mDisplayMetrics.heightPixels); |
| 315 | |
| 316 | takeScreenshot(SurfaceControl.screenshot(crop, width, height, rot), finisher, screenRect); |
Zak Cohen | ebd3b8b | 2020-01-17 11:16:00 -0800 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | private void takeScreenshot(Bitmap screenshot, Consumer<Uri> finisher, Rect screenRect) { |
| 320 | mScreenBitmap = screenshot; |
Winson Chung | a46d778 | 2012-01-04 16:43:10 -0800 | [diff] [blame] | 321 | if (mScreenBitmap == null) { |
Miranda Kephart | 9bbecf3 | 2019-12-06 10:54:58 -0500 | [diff] [blame] | 322 | mNotificationsController.notifyScreenshotError( |
Winson | e559171 | 2016-02-18 13:45:54 -0800 | [diff] [blame] | 323 | R.string.screenshot_failed_to_capture_text); |
Aran Ink | eb565fc | 2019-11-15 15:52:31 -0500 | [diff] [blame] | 324 | finisher.accept(null); |
Winson Chung | a46d778 | 2012-01-04 16:43:10 -0800 | [diff] [blame] | 325 | return; |
| 326 | } |
| 327 | |
Winson Chung | a63bb84 | 2011-10-17 10:26:28 -0700 | [diff] [blame] | 328 | // Optimizations |
| 329 | mScreenBitmap.setHasAlpha(false); |
| 330 | mScreenBitmap.prepareToDraw(); |
| 331 | |
Miranda Kephart | 43c0296 | 2020-01-10 17:50:48 -0500 | [diff] [blame] | 332 | mWindowManager.addView(mScreenshotLayout, mWindowLayoutParams); |
| 333 | mScreenshotLayout.getViewTreeObserver().addOnComputeInternalInsetsListener(this); |
| 334 | |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 335 | // Start the post-screenshot animation |
Miranda Kephart | 4890f3e | 2020-02-05 15:55:11 -0500 | [diff] [blame] | 336 | startAnimation(finisher, screenRect.width(), screenRect.height(), |
Zak Cohen | ebd3b8b | 2020-01-17 11:16:00 -0800 | [diff] [blame] | 337 | screenRect); |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 338 | } |
| 339 | |
Miranda Kephart | 63e65a9 | 2020-01-10 11:18:51 -0500 | [diff] [blame] | 340 | void takeScreenshot(Consumer<Uri> finisher) { |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 341 | mDisplay.getRealMetrics(mDisplayMetrics); |
Miranda Kephart | 63e65a9 | 2020-01-10 11:18:51 -0500 | [diff] [blame] | 342 | takeScreenshot( |
| 343 | finisher, |
chaviw | a69e0a7 | 2017-11-29 17:55:12 -0800 | [diff] [blame] | 344 | new Rect(0, 0, mDisplayMetrics.widthPixels, mDisplayMetrics.heightPixels)); |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 345 | } |
| 346 | |
Zak Cohen | ebd3b8b | 2020-01-17 11:16:00 -0800 | [diff] [blame] | 347 | void handleImageAsScreenshot(Bitmap screenshot, Rect screenshotScreenBounds, |
| 348 | Insets visibleInsets, int taskId, Consumer<Uri> finisher) { |
| 349 | // TODO use taskId and visibleInsets |
Miranda Kephart | ab359be | 2020-03-12 16:13:42 -0400 | [diff] [blame] | 350 | clearScreenshot("new screenshot requested"); |
Zak Cohen | ebd3b8b | 2020-01-17 11:16:00 -0800 | [diff] [blame] | 351 | takeScreenshot(screenshot, finisher, screenshotScreenBounds); |
| 352 | } |
| 353 | |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 354 | /** |
| 355 | * Displays a screenshot selector |
| 356 | */ |
Zak Cohen | ebd3b8b | 2020-01-17 11:16:00 -0800 | [diff] [blame] | 357 | @SuppressLint("ClickableViewAccessibility") |
Miranda Kephart | 63e65a9 | 2020-01-10 11:18:51 -0500 | [diff] [blame] | 358 | void takeScreenshotPartial(final Consumer<Uri> finisher) { |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 359 | mWindowManager.addView(mScreenshotLayout, mWindowLayoutParams); |
| 360 | mScreenshotSelectorView.setOnTouchListener(new View.OnTouchListener() { |
| 361 | @Override |
| 362 | public boolean onTouch(View v, MotionEvent event) { |
| 363 | ScreenshotSelectorView view = (ScreenshotSelectorView) v; |
| 364 | switch (event.getAction()) { |
| 365 | case MotionEvent.ACTION_DOWN: |
| 366 | view.startSelection((int) event.getX(), (int) event.getY()); |
| 367 | return true; |
| 368 | case MotionEvent.ACTION_MOVE: |
| 369 | view.updateSelection((int) event.getX(), (int) event.getY()); |
| 370 | return true; |
| 371 | case MotionEvent.ACTION_UP: |
| 372 | view.setVisibility(View.GONE); |
| 373 | mWindowManager.removeView(mScreenshotLayout); |
| 374 | final Rect rect = view.getSelectionRect(); |
| 375 | if (rect != null) { |
| 376 | if (rect.width() != 0 && rect.height() != 0) { |
| 377 | // Need mScreenshotLayout to handle it after the view disappears |
Miranda Kephart | 63e65a9 | 2020-01-10 11:18:51 -0500 | [diff] [blame] | 378 | mScreenshotLayout.post(() -> takeScreenshot(finisher, rect)); |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 379 | } |
| 380 | } |
| 381 | |
| 382 | view.stopSelection(); |
| 383 | return true; |
| 384 | } |
| 385 | |
| 386 | return false; |
| 387 | } |
| 388 | }); |
Miranda Kephart | 43c0296 | 2020-01-10 17:50:48 -0500 | [diff] [blame] | 389 | mScreenshotLayout.post(() -> { |
| 390 | mScreenshotSelectorView.setVisibility(View.VISIBLE); |
| 391 | mScreenshotSelectorView.requestFocus(); |
Muyuan Li | 6ca619f | 2016-03-08 13:30:42 -0800 | [diff] [blame] | 392 | }); |
| 393 | } |
| 394 | |
| 395 | /** |
| 396 | * Cancels screenshot request |
| 397 | */ |
| 398 | void stopScreenshot() { |
| 399 | // If the selector layer still presents on screen, we remove it and resets its state. |
| 400 | if (mScreenshotSelectorView.getSelectionRect() != null) { |
| 401 | mWindowManager.removeView(mScreenshotLayout); |
| 402 | mScreenshotSelectorView.stopSelection(); |
| 403 | } |
| 404 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 405 | |
| 406 | /** |
Miranda Kephart | ea2e67a | 2019-10-29 11:52:56 -0400 | [diff] [blame] | 407 | * Clears current screenshot |
| 408 | */ |
Miranda Kephart | 43c0296 | 2020-01-10 17:50:48 -0500 | [diff] [blame] | 409 | private void clearScreenshot(String reason) { |
| 410 | Log.e(TAG, "clearing screenshot: " + reason); |
Miranda Kephart | ea2e67a | 2019-10-29 11:52:56 -0400 | [diff] [blame] | 411 | if (mScreenshotLayout.isAttachedToWindow()) { |
| 412 | mWindowManager.removeView(mScreenshotLayout); |
| 413 | } |
Miranda Kephart | 43c0296 | 2020-01-10 17:50:48 -0500 | [diff] [blame] | 414 | mScreenshotHandler.removeMessages(MESSAGE_CORNER_TIMEOUT); |
| 415 | mScreenshotLayout.getViewTreeObserver().removeOnComputeInternalInsetsListener(this); |
Miranda Kephart | ea2e67a | 2019-10-29 11:52:56 -0400 | [diff] [blame] | 416 | |
| 417 | // Clear any references to the bitmap |
Miranda Kephart | ea2e67a | 2019-10-29 11:52:56 -0400 | [diff] [blame] | 418 | mScreenshotView.setImageBitmap(null); |
Miranda Kephart | 43c0296 | 2020-01-10 17:50:48 -0500 | [diff] [blame] | 419 | mActionsContainer.setVisibility(View.GONE); |
Miranda Kephart | ea2e67a | 2019-10-29 11:52:56 -0400 | [diff] [blame] | 420 | mBackgroundView.setVisibility(View.GONE); |
Miranda Kephart | 43c0296 | 2020-01-10 17:50:48 -0500 | [diff] [blame] | 421 | mBackgroundProtection.setAlpha(0f); |
Miranda Kephart | a2ebd76 | 2020-02-06 10:23:40 -0500 | [diff] [blame] | 422 | mDismissButton.setVisibility(View.GONE); |
Miranda Kephart | ea2e67a | 2019-10-29 11:52:56 -0400 | [diff] [blame] | 423 | mScreenshotView.setVisibility(View.GONE); |
| 424 | mScreenshotView.setLayerType(View.LAYER_TYPE_NONE, null); |
| 425 | } |
| 426 | |
| 427 | /** |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 428 | * Starts the animation after taking the screenshot |
| 429 | */ |
Zak Cohen | ebd3b8b | 2020-01-17 11:16:00 -0800 | [diff] [blame] | 430 | private void startAnimation(final Consumer<Uri> finisher, int w, int h, |
| 431 | @Nullable Rect screenRect) { |
Geoffrey Pitsch | ed5de31 | 2017-06-27 11:42:12 -0400 | [diff] [blame] | 432 | // If power save is on, show a toast so there is some visual indication that a screenshot |
| 433 | // has been taken. |
| 434 | PowerManager powerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); |
| 435 | if (powerManager.isPowerSaveMode()) { |
| 436 | Toast.makeText(mContext, R.string.screenshot_saved_title, Toast.LENGTH_SHORT).show(); |
| 437 | } |
| 438 | |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 439 | // Add the view for the animation |
| 440 | mScreenshotView.setImageBitmap(mScreenBitmap); |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 441 | |
Miranda Kephart | 4890f3e | 2020-02-05 15:55:11 -0500 | [diff] [blame] | 442 | mScreenshotAnimation = createScreenshotDropInAnimation(w, h, screenRect); |
Miranda Kephart | f50fb5b | 2020-01-28 17:12:28 -0500 | [diff] [blame] | 443 | |
| 444 | saveScreenshotInWorkerThread(finisher, new ActionsReadyListener() { |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 445 | @Override |
Miranda Kephart | f50fb5b | 2020-01-28 17:12:28 -0500 | [diff] [blame] | 446 | void onActionsReady(Uri uri, List<Notification.Action> smartActions, |
| 447 | List<Notification.Action> actions) { |
| 448 | if (uri == null) { |
| 449 | mNotificationsController.notifyScreenshotError( |
| 450 | R.string.screenshot_failed_to_capture_text); |
| 451 | } else { |
| 452 | mScreenshotHandler.post(() -> { |
| 453 | if (mScreenshotAnimation != null && mScreenshotAnimation.isRunning()) { |
| 454 | mScreenshotAnimation.addListener( |
| 455 | new AnimatorListenerAdapter() { |
| 456 | @Override |
| 457 | public void onAnimationEnd(Animator animation) { |
| 458 | super.onAnimationEnd(animation); |
| 459 | createScreenshotActionsShadeAnimation( |
| 460 | smartActions, actions).start(); |
| 461 | } |
| 462 | }); |
Miranda Kephart | 63e65a9 | 2020-01-10 11:18:51 -0500 | [diff] [blame] | 463 | } else { |
Miranda Kephart | f50fb5b | 2020-01-28 17:12:28 -0500 | [diff] [blame] | 464 | createScreenshotActionsShadeAnimation(smartActions, |
| 465 | actions).start(); |
Miranda Kephart | 9bbecf3 | 2019-12-06 10:54:58 -0500 | [diff] [blame] | 466 | } |
Miranda Kephart | f50fb5b | 2020-01-28 17:12:28 -0500 | [diff] [blame] | 467 | }); |
| 468 | } |
Miranda Kephart | 43c0296 | 2020-01-10 17:50:48 -0500 | [diff] [blame] | 469 | mScreenshotHandler.removeMessages(MESSAGE_CORNER_TIMEOUT); |
Miranda Kephart | 63e65a9 | 2020-01-10 11:18:51 -0500 | [diff] [blame] | 470 | mScreenshotHandler.sendMessageDelayed( |
| 471 | mScreenshotHandler.obtainMessage(MESSAGE_CORNER_TIMEOUT), |
| 472 | SCREENSHOT_CORNER_TIMEOUT_MILLIS); |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 473 | } |
| 474 | }); |
Miranda Kephart | ea2e67a | 2019-10-29 11:52:56 -0400 | [diff] [blame] | 475 | mScreenshotHandler.post(() -> { |
| 476 | // Play the shutter sound to notify that we've taken a screenshot |
| 477 | mCameraSound.play(MediaActionSound.SHUTTER_CLICK); |
Winson Chung | 8d513ea | 2011-12-01 14:39:12 -0800 | [diff] [blame] | 478 | |
Miranda Kephart | ea2e67a | 2019-10-29 11:52:56 -0400 | [diff] [blame] | 479 | mScreenshotView.setLayerType(View.LAYER_TYPE_HARDWARE, null); |
| 480 | mScreenshotView.buildLayer(); |
| 481 | mScreenshotAnimation.start(); |
Winson Chung | a63bb84 | 2011-10-17 10:26:28 -0700 | [diff] [blame] | 482 | }); |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 483 | } |
Miranda Kephart | ca6c5eb | 2019-11-14 12:44:11 -0500 | [diff] [blame] | 484 | |
Miranda Kephart | 4890f3e | 2020-02-05 15:55:11 -0500 | [diff] [blame] | 485 | private AnimatorSet createScreenshotDropInAnimation(int width, int height, Rect bounds) { |
| 486 | float cornerScale = mCornerSizeX / (float) width; |
Zak Cohen | ebd3b8b | 2020-01-17 11:16:00 -0800 | [diff] [blame] | 487 | |
Miranda Kephart | 4890f3e | 2020-02-05 15:55:11 -0500 | [diff] [blame] | 488 | AnimatorSet dropInAnimation = new AnimatorSet(); |
| 489 | ValueAnimator flashInAnimator = ValueAnimator.ofFloat(0, 1); |
| 490 | flashInAnimator.setDuration(SCREENSHOT_FLASH_IN_DURATION_MS); |
| 491 | flashInAnimator.setInterpolator(mFastOutSlowIn); |
| 492 | flashInAnimator.addUpdateListener(animation -> |
| 493 | mScreenshotFlash.setAlpha((float) animation.getAnimatedValue())); |
| 494 | |
| 495 | ValueAnimator flashOutAnimator = ValueAnimator.ofFloat(1, 0); |
| 496 | flashOutAnimator.setDuration(SCREENSHOT_FLASH_OUT_DURATION_MS); |
| 497 | flashOutAnimator.setInterpolator(mFastOutSlowIn); |
| 498 | flashOutAnimator.addUpdateListener(animation -> |
| 499 | mScreenshotFlash.setAlpha((float) animation.getAnimatedValue())); |
| 500 | |
Miranda Kephart | 4f150e0 | 2020-02-20 12:49:41 -0500 | [diff] [blame] | 501 | final PointF startPos = new PointF(bounds.centerX(), bounds.centerY()); |
| 502 | final PointF finalPos = new PointF(mScreenshotOffsetXPx + width * cornerScale / 2f, |
| 503 | mDisplayMetrics.heightPixels - mScreenshotOffsetYPx - height * cornerScale / 2f); |
Miranda Kephart | 4890f3e | 2020-02-05 15:55:11 -0500 | [diff] [blame] | 504 | |
| 505 | ValueAnimator toCorner = ValueAnimator.ofFloat(0, 1); |
| 506 | toCorner.setDuration(SCREENSHOT_TO_CORNER_Y_DURATION_MS); |
| 507 | float xPositionPct = |
| 508 | SCREENSHOT_TO_CORNER_X_DURATION_MS / (float) SCREENSHOT_TO_CORNER_Y_DURATION_MS; |
| 509 | float scalePct = |
| 510 | SCREENSHOT_TO_CORNER_SCALE_DURATION_MS / (float) SCREENSHOT_TO_CORNER_Y_DURATION_MS; |
| 511 | toCorner.addUpdateListener(animation -> { |
| 512 | float t = animation.getAnimatedFraction(); |
| 513 | if (t < scalePct) { |
| 514 | float scale = MathUtils.lerp( |
| 515 | 1, cornerScale, mFastOutSlowIn.getInterpolation(t / scalePct)); |
| 516 | mScreenshotView.setScaleX(scale); |
| 517 | mScreenshotView.setScaleY(scale); |
Miranda Kephart | 2750ad0 | 2020-02-24 13:12:41 -0500 | [diff] [blame] | 518 | } else { |
| 519 | mScreenshotView.setScaleX(cornerScale); |
| 520 | mScreenshotView.setScaleY(cornerScale); |
Zak Cohen | ebd3b8b | 2020-01-17 11:16:00 -0800 | [diff] [blame] | 521 | } |
Zak Cohen | ebd3b8b | 2020-01-17 11:16:00 -0800 | [diff] [blame] | 522 | |
Miranda Kephart | 4890f3e | 2020-02-05 15:55:11 -0500 | [diff] [blame] | 523 | if (t < xPositionPct) { |
Miranda Kephart | 4f150e0 | 2020-02-20 12:49:41 -0500 | [diff] [blame] | 524 | float xCenter = MathUtils.lerp(startPos.x, finalPos.x, |
| 525 | mFastOutSlowIn.getInterpolation(t / xPositionPct)); |
| 526 | mScreenshotView.setX(xCenter - width * mScreenshotView.getScaleX() / 2f); |
Miranda Kephart | 2750ad0 | 2020-02-24 13:12:41 -0500 | [diff] [blame] | 527 | } else { |
| 528 | mScreenshotView.setX(finalPos.x - width * mScreenshotView.getScaleX() / 2f); |
Miranda Kephart | 4890f3e | 2020-02-05 15:55:11 -0500 | [diff] [blame] | 529 | } |
Miranda Kephart | 4f150e0 | 2020-02-20 12:49:41 -0500 | [diff] [blame] | 530 | float yCenter = MathUtils.lerp(startPos.y, finalPos.y, |
| 531 | mFastOutSlowIn.getInterpolation(t)); |
| 532 | mScreenshotView.setY(yCenter - height * mScreenshotView.getScaleY() / 2f); |
Miranda Kephart | 4890f3e | 2020-02-05 15:55:11 -0500 | [diff] [blame] | 533 | }); |
| 534 | |
| 535 | toCorner.addListener(new AnimatorListenerAdapter() { |
Zak Cohen | ebd3b8b | 2020-01-17 11:16:00 -0800 | [diff] [blame] | 536 | @Override |
| 537 | public void onAnimationStart(Animator animation) { |
Miranda Kephart | 4890f3e | 2020-02-05 15:55:11 -0500 | [diff] [blame] | 538 | super.onAnimationStart(animation); |
Zak Cohen | ebd3b8b | 2020-01-17 11:16:00 -0800 | [diff] [blame] | 539 | mScreenshotView.setVisibility(View.VISIBLE); |
| 540 | } |
| 541 | }); |
Zak Cohen | ebd3b8b | 2020-01-17 11:16:00 -0800 | [diff] [blame] | 542 | |
Miranda Kephart | 4890f3e | 2020-02-05 15:55:11 -0500 | [diff] [blame] | 543 | mScreenshotFlash.setAlpha(0f); |
| 544 | mScreenshotFlash.setVisibility(View.VISIBLE); |
Beth Thibodeau | d98a945 | 2019-03-08 14:32:51 -0500 | [diff] [blame] | 545 | |
Miranda Kephart | 4890f3e | 2020-02-05 15:55:11 -0500 | [diff] [blame] | 546 | dropInAnimation.play(flashOutAnimator).after(flashInAnimator); |
| 547 | dropInAnimation.play(flashOutAnimator).with(toCorner); |
Miranda Kephart | ca6c5eb | 2019-11-14 12:44:11 -0500 | [diff] [blame] | 548 | |
Miranda Kephart | 4890f3e | 2020-02-05 15:55:11 -0500 | [diff] [blame] | 549 | dropInAnimation.addListener(new AnimatorListenerAdapter() { |
Miranda Kephart | a2ebd76 | 2020-02-06 10:23:40 -0500 | [diff] [blame] | 550 | @Override |
| 551 | public void onAnimationEnd(Animator animation) { |
| 552 | super.onAnimationEnd(animation); |
Miranda Kephart | 2750ad0 | 2020-02-24 13:12:41 -0500 | [diff] [blame] | 553 | mScreenshotView.setScaleX(cornerScale); |
| 554 | mScreenshotView.setScaleY(cornerScale); |
Miranda Kephart | 5fc0317 | 2020-02-27 14:34:47 -0500 | [diff] [blame] | 555 | mScreenshotView.setX(finalPos.x - width * cornerScale / 2f); |
Miranda Kephart | 2750ad0 | 2020-02-24 13:12:41 -0500 | [diff] [blame] | 556 | mScreenshotView.setY(finalPos.y - height * cornerScale / 2f); |
Miranda Kephart | a2ebd76 | 2020-02-06 10:23:40 -0500 | [diff] [blame] | 557 | Rect bounds = new Rect(); |
| 558 | mScreenshotView.getBoundsOnScreen(bounds); |
| 559 | mDismissButton.setX(bounds.right - mDismissButtonSize / 2f); |
| 560 | mDismissButton.setY(bounds.top - mDismissButtonSize / 2f); |
| 561 | mDismissButton.setVisibility(View.VISIBLE); |
| 562 | } |
| 563 | }); |
Miranda Kephart | 4890f3e | 2020-02-05 15:55:11 -0500 | [diff] [blame] | 564 | |
| 565 | return dropInAnimation; |
Miranda Kephart | ea2e67a | 2019-10-29 11:52:56 -0400 | [diff] [blame] | 566 | } |
| 567 | |
Miranda Kephart | 43c0296 | 2020-01-10 17:50:48 -0500 | [diff] [blame] | 568 | private ValueAnimator createScreenshotActionsShadeAnimation( |
| 569 | List<Notification.Action> smartActions, List<Notification.Action> actions) { |
Miranda Kephart | 9bbecf3 | 2019-12-06 10:54:58 -0500 | [diff] [blame] | 570 | LayoutInflater inflater = LayoutInflater.from(mContext); |
| 571 | mActionsView.removeAllViews(); |
Miranda Kephart | 43c0296 | 2020-01-10 17:50:48 -0500 | [diff] [blame] | 572 | mActionsContainer.setScrollX(0); |
| 573 | mScreenshotLayout.invalidate(); |
| 574 | mScreenshotLayout.requestLayout(); |
| 575 | mScreenshotLayout.getViewTreeObserver().dispatchOnGlobalLayout(); |
| 576 | |
| 577 | // By default the activities won't be able to start immediately; override this to keep |
| 578 | // the same behavior as if started from a notification |
| 579 | try { |
| 580 | ActivityManager.getService().resumeAppSwitches(); |
| 581 | } catch (RemoteException e) { |
| 582 | } |
| 583 | |
| 584 | for (Notification.Action smartAction : smartActions) { |
| 585 | ScreenshotActionChip actionChip = (ScreenshotActionChip) inflater.inflate( |
| 586 | R.layout.global_screenshot_action_chip, mActionsView, false); |
| 587 | actionChip.setText(smartAction.title); |
| 588 | actionChip.setIcon(smartAction.getIcon(), false); |
| 589 | actionChip.setPendingIntent(smartAction.actionIntent, |
| 590 | () -> clearScreenshot("chip tapped")); |
| 591 | mActionsView.addView(actionChip); |
| 592 | } |
Miranda Kephart | 9bbecf3 | 2019-12-06 10:54:58 -0500 | [diff] [blame] | 593 | |
| 594 | for (Notification.Action action : actions) { |
Miranda Kephart | 6b655af | 2020-01-13 15:50:32 -0500 | [diff] [blame] | 595 | ScreenshotActionChip actionChip = (ScreenshotActionChip) inflater.inflate( |
Miranda Kephart | 9bbecf3 | 2019-12-06 10:54:58 -0500 | [diff] [blame] | 596 | R.layout.global_screenshot_action_chip, mActionsView, false); |
| 597 | actionChip.setText(action.title); |
Miranda Kephart | 6b655af | 2020-01-13 15:50:32 -0500 | [diff] [blame] | 598 | actionChip.setIcon(action.getIcon(), true); |
Miranda Kephart | 43c0296 | 2020-01-10 17:50:48 -0500 | [diff] [blame] | 599 | actionChip.setPendingIntent(action.actionIntent, () -> clearScreenshot("chip tapped")); |
| 600 | if (action.actionIntent.getIntent().getAction().equals(Intent.ACTION_EDIT)) { |
| 601 | mScreenshotView.setOnClickListener(v -> { |
| 602 | try { |
| 603 | action.actionIntent.send(); |
| 604 | clearScreenshot("screenshot preview tapped"); |
| 605 | } catch (PendingIntent.CanceledException e) { |
| 606 | Log.e(TAG, "Intent cancelled", e); |
| 607 | } |
| 608 | }); |
| 609 | } |
Miranda Kephart | 9bbecf3 | 2019-12-06 10:54:58 -0500 | [diff] [blame] | 610 | mActionsView.addView(actionChip); |
| 611 | } |
Miranda Kephart | df62ee6 | 2020-01-10 18:21:44 -0500 | [diff] [blame] | 612 | |
| 613 | if (DeviceConfig.getBoolean(NAMESPACE_SYSTEMUI, SCREENSHOT_SCROLLING_ENABLED, false)) { |
Miranda Kephart | 6b655af | 2020-01-13 15:50:32 -0500 | [diff] [blame] | 614 | ScreenshotActionChip scrollChip = (ScreenshotActionChip) inflater.inflate( |
Miranda Kephart | df62ee6 | 2020-01-10 18:21:44 -0500 | [diff] [blame] | 615 | R.layout.global_screenshot_action_chip, mActionsView, false); |
| 616 | Toast scrollNotImplemented = Toast.makeText( |
| 617 | mContext, "Not implemented", Toast.LENGTH_SHORT); |
Miranda Kephart | 6b655af | 2020-01-13 15:50:32 -0500 | [diff] [blame] | 618 | scrollChip.setText("Extend"); // TODO (mkephart): add resource and translate |
Miranda Kephart | 43c0296 | 2020-01-10 17:50:48 -0500 | [diff] [blame] | 619 | scrollChip.setIcon( |
| 620 | Icon.createWithResource(mContext, R.drawable.ic_arrow_downward), true); |
Miranda Kephart | df62ee6 | 2020-01-10 18:21:44 -0500 | [diff] [blame] | 621 | scrollChip.setOnClickListener(v -> scrollNotImplemented.show()); |
| 622 | mActionsView.addView(scrollChip); |
| 623 | } |
Miranda Kephart | 9bbecf3 | 2019-12-06 10:54:58 -0500 | [diff] [blame] | 624 | |
Miranda Kephart | 0148b28 | 2019-10-31 15:36:21 -0400 | [diff] [blame] | 625 | ValueAnimator animator = ValueAnimator.ofFloat(0, 1); |
Miranda Kephart | 43c0296 | 2020-01-10 17:50:48 -0500 | [diff] [blame] | 626 | mActionsContainer.setY(mDisplayMetrics.heightPixels); |
| 627 | mActionsContainer.setVisibility(VISIBLE); |
| 628 | mActionsContainer.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); |
| 629 | float actionsViewHeight = mActionsContainer.getMeasuredHeight() + mScreenshotHeightPx; |
Miranda Kephart | 0148b28 | 2019-10-31 15:36:21 -0400 | [diff] [blame] | 630 | |
| 631 | animator.addUpdateListener(animation -> { |
| 632 | float t = animation.getAnimatedFraction(); |
Miranda Kephart | 43c0296 | 2020-01-10 17:50:48 -0500 | [diff] [blame] | 633 | mBackgroundProtection.setAlpha(t); |
| 634 | mActionsContainer.setY(mDisplayMetrics.heightPixels - actionsViewHeight * t); |
Miranda Kephart | 0148b28 | 2019-10-31 15:36:21 -0400 | [diff] [blame] | 635 | }); |
Miranda Kephart | 0148b28 | 2019-10-31 15:36:21 -0400 | [diff] [blame] | 636 | return animator; |
| 637 | } |
| 638 | |
Adam Powell | d4d3415 | 2015-04-17 12:13:40 -0700 | [diff] [blame] | 639 | /** |
Winson Chung | 06ca274 | 2018-06-29 12:26:49 -0700 | [diff] [blame] | 640 | * Receiver to proxy the share or edit intent, used to clean up the notification and send |
| 641 | * appropriate signals to the system (ie. to dismiss the keyguard if necessary). |
Winson Chung | ed376a3 | 2017-09-07 14:05:42 -0700 | [diff] [blame] | 642 | */ |
Winson Chung | 06ca274 | 2018-06-29 12:26:49 -0700 | [diff] [blame] | 643 | public static class ActionProxyReceiver extends BroadcastReceiver { |
Matt Pietal | 777c82d | 2019-06-11 15:47:10 -0400 | [diff] [blame] | 644 | static final int CLOSE_WINDOWS_TIMEOUT_MILLIS = 3000; |
Dave Mankoff | aefb346 | 2019-11-01 14:21:45 -0400 | [diff] [blame] | 645 | private final StatusBar mStatusBar; |
| 646 | |
| 647 | @Inject |
Garfield Tan | a2242397 | 2019-11-04 17:40:26 -0800 | [diff] [blame] | 648 | public ActionProxyReceiver(Optional<Lazy<StatusBar>> statusBarLazy) { |
| 649 | Lazy<StatusBar> statusBar = statusBarLazy.orElse(null); |
| 650 | mStatusBar = statusBar != null ? statusBar.get() : null; |
Dave Mankoff | aefb346 | 2019-11-01 14:21:45 -0400 | [diff] [blame] | 651 | } |
Matt Pietal | 777c82d | 2019-06-11 15:47:10 -0400 | [diff] [blame] | 652 | |
Winson Chung | ed376a3 | 2017-09-07 14:05:42 -0700 | [diff] [blame] | 653 | @Override |
Winson Chung | 06ca274 | 2018-06-29 12:26:49 -0700 | [diff] [blame] | 654 | public void onReceive(Context context, final Intent intent) { |
| 655 | Runnable startActivityRunnable = () -> { |
Matt Pietal | 777c82d | 2019-06-11 15:47:10 -0400 | [diff] [blame] | 656 | try { |
| 657 | ActivityManagerWrapper.getInstance().closeSystemWindows( |
| 658 | SYSTEM_DIALOG_REASON_SCREENSHOT).get( |
| 659 | CLOSE_WINDOWS_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); |
| 660 | } catch (TimeoutException | InterruptedException | ExecutionException e) { |
| 661 | Slog.e(TAG, "Unable to share screenshot", e); |
| 662 | return; |
| 663 | } |
Winson Chung | ed376a3 | 2017-09-07 14:05:42 -0700 | [diff] [blame] | 664 | |
Winson Chung | 06ca274 | 2018-06-29 12:26:49 -0700 | [diff] [blame] | 665 | Intent actionIntent = intent.getParcelableExtra(EXTRA_ACTION_INTENT); |
| 666 | if (intent.getBooleanExtra(EXTRA_CANCEL_NOTIFICATION, false)) { |
Miranda Kephart | 9bbecf3 | 2019-12-06 10:54:58 -0500 | [diff] [blame] | 667 | ScreenshotNotificationsController.cancelScreenshotNotification(context); |
Winson Chung | 06ca274 | 2018-06-29 12:26:49 -0700 | [diff] [blame] | 668 | } |
| 669 | ActivityOptions opts = ActivityOptions.makeBasic(); |
| 670 | opts.setDisallowEnterPictureInPictureWhileLaunching( |
| 671 | intent.getBooleanExtra(EXTRA_DISALLOW_ENTER_PIP, false)); |
Winson Chung | 6c454f6 | 2018-07-09 15:55:56 -0700 | [diff] [blame] | 672 | context.startActivityAsUser(actionIntent, opts.toBundle(), UserHandle.CURRENT); |
Winson Chung | 06ca274 | 2018-06-29 12:26:49 -0700 | [diff] [blame] | 673 | }; |
Dave Mankoff | aefb346 | 2019-11-01 14:21:45 -0400 | [diff] [blame] | 674 | |
Garfield Tan | a2242397 | 2019-11-04 17:40:26 -0800 | [diff] [blame] | 675 | if (mStatusBar != null) { |
| 676 | mStatusBar.executeRunnableDismissingKeyguard(startActivityRunnable, null, |
| 677 | true /* dismissShade */, true /* afterKeyguardGone */, |
| 678 | true /* deferred */); |
| 679 | } else { |
| 680 | startActivityRunnable.run(); |
| 681 | } |
Satakshi | aaf6953 | 2019-11-07 17:54:24 -0800 | [diff] [blame] | 682 | |
| 683 | if (intent.getBooleanExtra(EXTRA_SMART_ACTIONS_ENABLED, false)) { |
| 684 | String actionType = Intent.ACTION_EDIT.equals(intent.getAction()) ? ACTION_TYPE_EDIT |
| 685 | : ACTION_TYPE_SHARE; |
Miranda Kephart | 9bbecf3 | 2019-12-06 10:54:58 -0500 | [diff] [blame] | 686 | ScreenshotSmartActions.notifyScreenshotAction( |
| 687 | context, intent.getStringExtra(EXTRA_ID), actionType, false); |
Satakshi | aaf6953 | 2019-11-07 17:54:24 -0800 | [diff] [blame] | 688 | } |
Winson Chung | ed376a3 | 2017-09-07 14:05:42 -0700 | [diff] [blame] | 689 | } |
| 690 | } |
| 691 | |
| 692 | /** |
Winson Chung | 06ca274 | 2018-06-29 12:26:49 -0700 | [diff] [blame] | 693 | * Removes the notification for a screenshot after a share target is chosen. |
Adam Powell | d4d3415 | 2015-04-17 12:13:40 -0700 | [diff] [blame] | 694 | */ |
| 695 | public static class TargetChosenReceiver extends BroadcastReceiver { |
| 696 | @Override |
| 697 | public void onReceive(Context context, Intent intent) { |
Winson Chung | 06ca274 | 2018-06-29 12:26:49 -0700 | [diff] [blame] | 698 | // Clear the notification only after the user has chosen a share action |
Miranda Kephart | 9bbecf3 | 2019-12-06 10:54:58 -0500 | [diff] [blame] | 699 | ScreenshotNotificationsController.cancelScreenshotNotification(context); |
Adam Powell | d4d3415 | 2015-04-17 12:13:40 -0700 | [diff] [blame] | 700 | } |
| 701 | } |
Winson Chung | 8858e6e | 2015-05-27 17:18:56 -0700 | [diff] [blame] | 702 | |
| 703 | /** |
| 704 | * Removes the last screenshot. |
| 705 | */ |
| 706 | public static class DeleteScreenshotReceiver extends BroadcastReceiver { |
| 707 | @Override |
| 708 | public void onReceive(Context context, Intent intent) { |
Winson | e559171 | 2016-02-18 13:45:54 -0800 | [diff] [blame] | 709 | if (!intent.hasExtra(SCREENSHOT_URI_ID)) { |
Winson Chung | 8858e6e | 2015-05-27 17:18:56 -0700 | [diff] [blame] | 710 | return; |
| 711 | } |
| 712 | |
Winson Chung | 06ca274 | 2018-06-29 12:26:49 -0700 | [diff] [blame] | 713 | // Clear the notification when the image is deleted |
Miranda Kephart | 9bbecf3 | 2019-12-06 10:54:58 -0500 | [diff] [blame] | 714 | ScreenshotNotificationsController.cancelScreenshotNotification(context); |
Winson Chung | 8858e6e | 2015-05-27 17:18:56 -0700 | [diff] [blame] | 715 | |
| 716 | // And delete the image from the media store |
Winson Chung | 06ca274 | 2018-06-29 12:26:49 -0700 | [diff] [blame] | 717 | final Uri uri = Uri.parse(intent.getStringExtra(SCREENSHOT_URI_ID)); |
Winson Chung | 8858e6e | 2015-05-27 17:18:56 -0700 | [diff] [blame] | 718 | new DeleteImageInBackgroundTask(context).execute(uri); |
Satakshi | aaf6953 | 2019-11-07 17:54:24 -0800 | [diff] [blame] | 719 | if (intent.getBooleanExtra(EXTRA_SMART_ACTIONS_ENABLED, false)) { |
Miranda Kephart | 9bbecf3 | 2019-12-06 10:54:58 -0500 | [diff] [blame] | 720 | ScreenshotSmartActions.notifyScreenshotAction( |
| 721 | context, intent.getStringExtra(EXTRA_ID), ACTION_TYPE_DELETE, false); |
Satakshi | aaf6953 | 2019-11-07 17:54:24 -0800 | [diff] [blame] | 722 | } |
| 723 | } |
| 724 | } |
| 725 | |
| 726 | /** |
| 727 | * Executes the smart action tapped by the user in the notification. |
| 728 | */ |
| 729 | public static class SmartActionsReceiver extends BroadcastReceiver { |
| 730 | @Override |
| 731 | public void onReceive(Context context, Intent intent) { |
Satakshi | 386efae | 2019-12-04 16:08:18 -0800 | [diff] [blame] | 732 | PendingIntent pendingIntent = intent.getParcelableExtra(EXTRA_ACTION_INTENT); |
| 733 | Intent actionIntent = pendingIntent.getIntent(); |
| 734 | String actionType = intent.getStringExtra(EXTRA_ACTION_TYPE); |
| 735 | Slog.d(TAG, "Executing smart action [" + actionType + "]:" + actionIntent); |
Satakshi | aaf6953 | 2019-11-07 17:54:24 -0800 | [diff] [blame] | 736 | ActivityOptions opts = ActivityOptions.makeBasic(); |
Miranda Kephart | 63e65a9 | 2020-01-10 11:18:51 -0500 | [diff] [blame] | 737 | context.startActivityAsUser(actionIntent, opts.toBundle(), UserHandle.CURRENT); |
Satakshi | aaf6953 | 2019-11-07 17:54:24 -0800 | [diff] [blame] | 738 | |
Miranda Kephart | 9bbecf3 | 2019-12-06 10:54:58 -0500 | [diff] [blame] | 739 | ScreenshotSmartActions.notifyScreenshotAction( |
| 740 | context, intent.getStringExtra(EXTRA_ID), actionType, true); |
Winson Chung | 8858e6e | 2015-05-27 17:18:56 -0700 | [diff] [blame] | 741 | } |
| 742 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 743 | } |