8000 Pass context for calling IconCompat.toIcon by Goooler · Pull Request #696 · androidx/androidx · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Pass context for calling IconCompat.toIcon #696

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: androidx-main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions core/core/api/current.txt
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,8 @@ package androidx.core.app {
method public android.app.PendingIntent? getIntent();
method public String? getShortcutId();
method public boolean isNotificationSuppressed();
method public static android.app.Notification.BubbleMetadata? toPlatform(androidx.core.app.NotificationCompat.BubbleMetadata?);
method public static android.app.Notification.BubbleMetadata? toPlatform(android.content.Context, androidx.core.app.NotificationCompat.BubbleMetadata?);
method @Deprecated public static android.app.Notification.BubbleMetadata? toPlatform(androidx.core.app.NotificationCompat.BubbleMetadata?);
}

public static final class NotificationCompat.BubbleMetadata.Builder {
Expand Down Expand Up @@ -941,7 +942,8 @@ package androidx.core.app {
method public void setEnabled(boolean);
method public void setShouldShowIcon(boolean);
method public boolean shouldShowIcon();
method @RequiresApi(26) public android.app.RemoteAction toRemoteAction();
method @Deprecated @RequiresApi(26) public android.app.RemoteAction toRemoteAction();
method @RequiresApi(26) public android.app.RemoteAction toRemoteAction(android.content.Context);
}

public final class RemoteInput {
Expand Down
9 changes: 6 additions & 3 deletions core/core/api/restricted_current.txt
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,8 @@ package androidx.core.app {
method public String? getShortcutId();
method public boolean isNotificationSuppressed();
method @RestrictTo(androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP_PREFIX) public void setFlags(int);
method public static android.app.Notification.BubbleMetadata? toPlatform(androidx.core.app.NotificationCompat.BubbleMetadata?);
method public static android.app.Notification.BubbleMetadata? toPlatform(android.content.Context, androidx.core.app.NotificationCompat.BubbleMetadata?);
method @Deprecated public static android.app.Notification.BubbleMetadata? toPlatform(androidx.core.app.NotificationCompat.BubbleMetadata?);
}

public static final class NotificationCompat.BubbleMetadata.Builder {
Expand Down Expand Up @@ -1010,7 +1011,8 @@ package androidx.core.app {
method public boolean isBot();
method public boolean isImportant();
method @RestrictTo(androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP_PREFIX) public String resolveToLegacyUri();
method @RequiresApi(28) @RestrictTo(androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP_PREFIX) public android.app.Person toAndroidPerson();
method @Deprecated @RequiresApi(28) @RestrictTo(androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP_PREFIX) public android.app.Person toAndroidPerson();
method @RequiresApi(28) @RestrictTo(androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP_PREFIX) public android.app.Person toAndroidPerson(android.content.Context);
method public androidx.core.app.Person.Builder toBuilder();
method public android.os.Bundle toBundle();
method @RequiresApi(22) @RestrictTo(androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP_PREFIX) public android.os.PersistableBundle toPersistableBundle();
Expand Down Expand Up @@ -1049,7 +1051,8 @@ package androidx.core.app {
method public void setEnabled(boolean);
method public void setShouldShowIcon(boolean);
method public boolean shouldShowIcon();
method @RequiresApi(26) public android.app.RemoteAction toRemoteAction();
method @Deprecated @RequiresApi(26) public android.app.RemoteAction toRemoteAction();
method @RequiresApi(26) public android.app.RemoteAction toRemoteAction(android.content.Context);
field @RestrictTo(androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP) @androidx.versionedparcelable.ParcelField(4) public android.app.PendingIntent mActionIntent;
field @RestrictTo(androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP) @androidx.versionedparcelable.ParcelField(3) public CharSequence mContentDescription;
field @RestrictTo(androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP) @androidx.versionedparcelable.ParcelField(5) public boolean mEnabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6811,7 +6811,7 @@ public NotificationCompat.Builder extend(@NonNull NotificationCompat.Builder bui
for (Action action : mActions) {
if (Build.VERSION.SDK_INT >= 20) {
parcelables.add(
WearableExtender.getActionFromActionCompat(action));
WearableExtender.getActionFromActionCompat(builder.mContext, action));
} else {
parcelables.add(NotificationCompatJellybean.getBundleForAction(action));
}
Expand Down Expand Up @@ -6865,12 +6865,12 @@ public NotificationCompat.Builder extend(@NonNull NotificationCompat.Builder bui
}

@RequiresApi(20)
private static Notification.Action getActionFromActionCompat(Action actionCompat) {
private static Notification.Action getActionFromActionCompat(Context context, Action actionCompat) {
Notification.Action.Builder actionBuilder;
if (Build.VERSION.SDK_INT >= 23) {
IconCompat iconCompat = actionCompat.getIconCompat();
actionBuilder = Api23Impl.createBuilder(
iconCompat == null ? null : iconCompat.toIcon(), actionCompat.getTitle(),
iconCompat == null ? null : iconCompat.toIcon(context), actionCompat.getTitle(),
actionCompat.getActionIntent());
} else {
IconCompat icon = actionCompat.getIconCompat();
Expand Down Expand Up @@ -8501,16 +8501,35 @@ public void setFlags(int flags) {
* @param compatMetadata the NotificationCompat.BubbleMetadata to convert
* @return a {@link Notification.BubbleMetadata} containing the same data if compatMetadata
* is non-null, otherwise null.
*
* @deprecated use {@link #toPlatform(Context, BubbleMetadata)} instead.
*/
@Deprecated
public static @Nullable android.app.Notification.BubbleMetadata toPlatform(
@Nullable BubbleMetadata compatMetadata) {
//noinspection DataFlowIssue
return toPlatform(null, compatMetadata);
}

/**
* Converts a {@link NotificationCompat.BubbleMetadata} to a platform-level
* {@link Notification.BubbleMetadata}.
*
* @param context A {@link Context} that will be used to get icon from the bubbleMetadata.
* @param compatMetadata the NotificationCompat.BubbleMetadata to convert
* @return a {@link Notification.BubbleMetadata} containing the same data if compatMetadata
* is non-null, otherwise null.
*/
public static @Nullable android.app.Notification.BubbleMetadata toPlatform(
@NonNull Context context,
@Nullable BubbleMetadata compatMetadata) {
if (compatMetadata == null) {
return null;
}
if (Build.VERSION.SDK_INT >= 30) {
return Api30Impl.toPlatform(compatMetadata);
return Api30Impl.toPlatform(context, compatMetadata);
} else if (Build.VERSION.SDK_INT == 29) {
return Api29Impl.toPlatform(compatMetadata);
return Api29Impl.toPlatform(context, compatMetadata);
}
return null;
}
Expand Down Expand Up @@ -8786,6 +8805,7 @@ private Api29Impl() {
*/
@RequiresApi(29)
@Nullable static android.app.Notification.BubbleMetadata toPlatform(
@NonNull Context context,
@Nullable BubbleMetadata compatMetadata) {
if (compatMetadata == null) {
return null;
Expand All @@ -8797,7 +8817,7 @@ private Api29Impl() {

android.app.Notification.BubbleMetadata.Builder platformMetadataBuilder =
new android.app.Notification.BubbleMetadata.Builder()
.setIcon(compatMetadata.getIcon().toIcon())
.setIcon(compatMetadata.getIcon().toIcon(context))
.setIntent(compatMetadata.getIntent())
.setDeleteIntent(compatMetadata.getDeleteIntent())
.setAutoExpandBubble(compatMetadata.getAutoExpandBubble())
Expand Down Expand Up @@ -8869,6 +8889,7 @@ private Api30Impl() {
*/
@RequiresApi(30)
@Nullable static android.app.Notification.BubbleMetadata toPlatform(
@NonNull Context context,
@Nullable BubbleMetadata compatMetadata) {
if (compatMetadata == null) {
return null;
Expand All @@ -8881,7 +8902,7 @@ private Api30Impl() {
} else {
platformMetadataBuilder =
new android.app.Notification.BubbleMetadata.Builder(
compatMetadata.getIntent(), compatMetadata.getIcon().toIcon());
compatMetadata.getIntent(), compatMetadata.getIcon().toIcon(context));
}
platformMetadataBuilder
.setDeleteIntent(compatMetadata.getDeleteIntent())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ class NotificationCompatBuilder implements NotificationBuilderWithBuilderAccesso
((NotificationCompat.CallStyle) b.mStyle).getActionsListWithSystemActions();
// Adds the actions to the builder in the proper order.
for (NotificationCompat.Action action : actionsList) {
addAction(action);
addAction(mContext, action);
}
} else {
for (NotificationCompat.Action action : b.mActions) {
addAction(action);
addAction(mContext, action);
}
}

Expand Down Expand Up @@ -366,13 +366,13 @@ public Notification build() {
return n;
}

private void addAction(NotificationCompat.Action action) {
private void addAction(Context context, NotificationCompat.Action action) {
if (Build.VERSION.SDK_INT >= 20) {
Notification.Action.Builder actionBuilder;
IconCompat iconCompat = action.getIconCompat();
if (Build.VERSION.SDK_INT >= 23) {
actionBuilder = Api23Impl.createBuilder(
iconCompat != null ? iconCompat.toIcon() : null, action.getTitle(),
iconCompat != null ? iconCompat.toIcon(context) : null, action.getTitle(),
action.getActionIntent());
} else {
actionBuilder = Api20Impl.createBuilder(
Expand Down
23 changes: 19 additions & 4 deletions core/core/src/main/java/androidx/core/app/Person.java
< F438 /tr>
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP_PREFIX;

import android.content.Context;
import android.os.Bundle;
import android.os.PersistableBundle;

Expand Down Expand Up @@ -143,12 +144,27 @@ public Builder toBuilder() {
/**
* Converts this compat {@link Person} to the base Android framework {@link android.app.Person}.
*
* @deprecated Use {@link #toAndroidPerson(Context)} instead.
*/
@RestrictTo(LIBRARY_GROUP_PREFIX)
@NonNull
@RequiresApi(28)
@Deprecated
public android.app.Person toAndroidPerson() {
return Api28Impl.toAndroidPerson(this);
//noinspection DataFlowIssue
return toAndroidPerson(null);
}

/**
* Converts this compat {@link Person} to the base Android framework {@link android.app.Person}.
*
* @param context A {@link Context} that will be used to get icon from the person.
*/
@RestrictTo(LIBRARY_GROUP_PREFIX)
@NonNull
@RequiresApi(28)
public android.app.Person toAndroidPerson(@NonNull Context context) {
return Api28Impl.toAndroidPerson(context, this);
}

/**
Expand Down Expand Up @@ -415,11 +431,10 @@ static Person fromAndroidPerson(android.app.Person person) {
.build();
}

@SuppressWarnings("deprecation")
static android.app.Person toAndroidPerson(Person person) {
static android.app.Person toAndroidPerson(Context context, Person person) {
return new android.app.Person.Builder()
.setName(person.getName())
.setIcon((person.getIcon() != null) ? person.getIcon().toIcon() : null)
.setIcon((person.getIcon() != null) ? person.getIcon().toIcon(context) : null)
.setUri(person.getUri())
.setKey(person.getKey())
.setBot(person.isBot())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.annotation.SuppressLint;
import android.app.PendingIntent;
import android.app.RemoteAction;
import android.content.Context;
import android.graphics.drawable.Icon;
import android.os.Build;

Expand Down Expand Up @@ -189,12 +190,27 @@ public boolean shouldShowIcon() {
* Convert this compat object to {@link RemoteAction} object.
*
* @return {@link RemoteAction} object
*
* @deprecated Use {@link #toRemoteAction(Context)} instead.
*/
@SuppressWarnings("deprecation")
@RequiresApi(26)
@NonNull
@Deprecated
public RemoteAction toRemoteAction() {
RemoteAction action = Api26Impl.createRemoteAction(mIcon.toIcon(), mTitle,
//noinspection DataFlowIssue
return toRemoteAction(null);
}

/**
* Convert this compat object to {@link RemoteAction} object.
*
* @param context A {@link Context} that will be used to get icon from mIcon.
* @return {@link RemoteAction} object
*/
@RequiresApi(26)
@NonNull
public RemoteAction toRemoteAction(@NonNull Context context) {
RemoteAction action = Api26Impl.createRemoteAction(mIcon.toIcon(context), mTitle,
mContentDescription, mActionIntent);
Api26Impl.setEnabled(action, isEnabled());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
Expand Down
0