summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Liran Binyamin <liranb@google.com> 2024-10-07 16:59:02 -0400
committer Liran Binyamin <liranb@google.com> 2024-10-07 19:40:10 -0400
commit7c93465367edafc44c632e2024a8ebf872e77481 (patch)
treec1067d8f3be19c4f846ea78a227ef5dde2af5f3b
parent048c01a323ee7ced7515b4061ed1af3f380a20bd (diff)
Helper for loading flyout drawable
Moves the code that loads the flyout icon as a drawable to a util class to share with launcher. Flag: com.android.wm.shell.enable_bubble_bar Bug: 277815200 Test: builds successfully -- no-op change Change-Id: Iddc4ca7d6fb0994a6c3d3fa184505b00e7395e7b
-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;
- }
- }
}