summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Liran Binyamin <liranb@google.com> 2024-10-08 13:31:53 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2024-10-08 13:31:53 +0000
commit7a54c63ed9cc9f35fa46e7eb71d251c30b79de9a (patch)
treeb3489751cb0a84de5c6302ff817923a1c4b3d934
parent0c402393c99bbadba6a2e8751ddc81f969121d77 (diff)
parent7c93465367edafc44c632e2024a8ebf872e77481 (diff)
Merge "Helper for loading flyout drawable" into main
-rw-r--r--libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/bubbles/FlyoutDrawableLoader.kt47
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleViewInfoTask.java24
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleViewInfoTaskLegacy.java24
3 files changed, 51 insertions, 44 deletions
diff --git a/libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/bubbles/FlyoutDrawableLoader.kt b/libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/bubbles/FlyoutDrawableLoader.kt
new file mode 100644
index 000000000000..5a1733094019
--- /dev/null
+++ b/libs/WindowManager/Shell/shared/src/com/android/wm/shell/shared/bubbles/FlyoutDrawableLoader.kt
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2024 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.wm.shell.shared.bubbles
+
+import android.content.Context
+import android.content.Intent
+import android.graphics.drawable.Drawable
+import android.graphics.drawable.Icon
+import android.util.Log
+
+object FlyoutDrawableLoader {
+
+ private const val TAG = "FlyoutDrawableLoader"
+
+ /** Loads the flyout icon as a [Drawable]. */
+ @JvmStatic
+ fun Icon?.loadFlyoutDrawable(context: Context): Drawable? {
+ if (this == null) return null
+ try {
+ if (this.type == Icon.TYPE_URI || this.type == Icon.TYPE_URI_ADAPTIVE_BITMAP) {
+ context.grantUriPermission(
+ context.packageName,
+ this.uri,
+ Intent.FLAG_GRANT_READ_URI_PERMISSION
+ )
+ }
+ return loadDrawable(context)
+ } catch (e: Exception) {
+ Log.w(TAG, "loadFlyoutDrawable failed: ${e.message}")
+ return null
+ }
+ }
+}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleViewInfoTask.java b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleViewInfoTask.java
index c5e3afda34dd..39fb2f49c1ee 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleViewInfoTask.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleViewInfoTask.java
@@ -21,11 +21,10 @@ import static com.android.wm.shell.bubbles.BadgedImageView.WHITE_SCRIM_ALPHA;
import static com.android.wm.shell.bubbles.BubbleDebugConfig.TAG_BUBBLES;
import static com.android.wm.shell.bubbles.BubbleDebugConfig.TAG_WITH_CLASS_NAME;
import static com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_BUBBLES;
+import static com.android.wm.shell.shared.bubbles.FlyoutDrawableLoader.loadFlyoutDrawable;
-import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.Context;
-import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ShortcutInfo;
@@ -34,7 +33,6 @@ import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Path;
import android.graphics.drawable.Drawable;
-import android.graphics.drawable.Icon;
import android.util.Log;
import android.util.PathParser;
import android.view.LayoutInflater;
@@ -51,7 +49,6 @@ import com.android.wm.shell.bubbles.bar.BubbleBarLayerView;
import com.android.wm.shell.shared.handles.RegionSamplingHelper;
import java.lang.ref.WeakReference;
-import java.util.Objects;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -340,7 +337,7 @@ public class BubbleViewInfoTask {
info.flyoutMessage = b.getFlyoutMessage();
if (info.flyoutMessage != null) {
info.flyoutMessage.senderAvatar =
- loadSenderAvatar(c, info.flyoutMessage.senderIcon);
+ loadFlyoutDrawable(info.flyoutMessage.senderIcon, c);
}
return info;
}
@@ -422,21 +419,4 @@ public class BubbleViewInfoTask {
Color.WHITE, WHITE_SCRIM_ALPHA);
return true;
}
-
- @Nullable
- static Drawable loadSenderAvatar(@NonNull final Context context, @Nullable final Icon icon) {
- Objects.requireNonNull(context);
- if (icon == null) return null;
- try {
- if (icon.getType() == Icon.TYPE_URI
- || icon.getType() == Icon.TYPE_URI_ADAPTIVE_BITMAP) {
- context.grantUriPermission(context.getPackageName(),
- icon.getUri(), Intent.FLAG_GRANT_READ_URI_PERMISSION);
- }
- return icon.loadDrawable(context);
- } catch (Exception e) {
- Log.w(TAG, "loadSenderAvatar failed: " + e.getMessage());
- return null;
- }
- }
}
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleViewInfoTaskLegacy.java b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleViewInfoTaskLegacy.java
index c12822a27662..e9a593392dc2 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleViewInfoTaskLegacy.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleViewInfoTaskLegacy.java
@@ -20,11 +20,10 @@ import static com.android.wm.shell.bubbles.BadgedImageView.DEFAULT_PATH_SIZE;
import static com.android.wm.shell.bubbles.BadgedImageView.WHITE_SCRIM_ALPHA;
import static com.android.wm.shell.bubbles.BubbleDebugConfig.TAG_BUBBLES;
import static com.android.wm.shell.bubbles.BubbleDebugConfig.TAG_WITH_CLASS_NAME;
+import static com.android.wm.shell.shared.bubbles.FlyoutDrawableLoader.loadFlyoutDrawable;
-import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.Context;
-import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ShortcutInfo;
@@ -33,7 +32,6 @@ import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Path;
import android.graphics.drawable.Drawable;
-import android.graphics.drawable.Icon;
import android.os.AsyncTask;
import android.util.Log;
import android.util.PathParser;
@@ -50,7 +48,6 @@ import com.android.wm.shell.bubbles.bar.BubbleBarLayerView;
import com.android.wm.shell.shared.handles.RegionSamplingHelper;
import java.lang.ref.WeakReference;
-import java.util.Objects;
import java.util.concurrent.Executor;
/**
@@ -264,7 +261,7 @@ public class BubbleViewInfoTaskLegacy extends
info.flyoutMessage = b.getFlyoutMessage();
if (info.flyoutMessage != null) {
info.flyoutMessage.senderAvatar =
- loadSenderAvatar(c, info.flyoutMessage.senderIcon);
+ loadFlyoutDrawable(info.flyoutMessage.senderIcon, c);
}
return info;
}
@@ -346,21 +343,4 @@ public class BubbleViewInfoTaskLegacy extends
Color.WHITE, WHITE_SCRIM_ALPHA);
return true;
}
-
- @Nullable
- static Drawable loadSenderAvatar(@NonNull final Context context, @Nullable final Icon icon) {
- Objects.requireNonNull(context);
- if (icon == null) return null;
- try {
- if (icon.getType() == Icon.TYPE_URI
- || icon.getType() == Icon.TYPE_URI_ADAPTIVE_BITMAP) {
- context.grantUriPermission(context.getPackageName(),
- icon.getUri(), Intent.FLAG_GRANT_READ_URI_PERMISSION);
- }
- return icon.loadDrawable(context);
- } catch (Exception e) {
- Log.w(TAG, "loadSenderAvatar failed: " + e.getMessage());
- return null;
- }
- }
}