mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-03 17:02:13 +01:00
Deduplicate icon retrieval code
This commit is contained in:
parent
b1a9adadc3
commit
0bba156bec
@ -80,6 +80,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.NotificationType;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.BitmapUtil;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.LimitedQueue;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.NotificationUtils;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.PebbleUtils;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
||||
|
||||
@ -966,7 +967,7 @@ public class NotificationListener extends NotificationListenerService {
|
||||
// Otherwise, we go and attempt to find the color from the app icon.
|
||||
Drawable icon;
|
||||
try {
|
||||
icon = getApplicationContext().getPackageManager().getApplicationIcon(appId);
|
||||
icon = NotificationUtils.getAppIcon(getApplicationContext(), appId);
|
||||
Objects.requireNonNull(icon);
|
||||
} catch (Exception ex) {
|
||||
// If we can't get the icon, we go with the default defined above.
|
||||
|
@ -47,6 +47,7 @@ import android.os.Messenger;
|
||||
import android.os.RemoteException;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.core.content.res.ResourcesCompat;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
|
||||
import org.json.JSONArray;
|
||||
@ -156,6 +157,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fos
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.workout.WorkoutRequestHandler;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.misfit.FactoryResetRequest;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.NotificationUtils;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.UriHelper;
|
||||
@ -1279,11 +1281,10 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
|
||||
Drawable icon = null;
|
||||
if (notificationSpec.iconId != 0) {
|
||||
Context sourcePackageContext = getContext().createPackageContext(sourceAppId, 0);
|
||||
icon = sourcePackageContext.getResources().getDrawable(notificationSpec.iconId);
|
||||
icon = ResourcesCompat.getDrawable(sourcePackageContext.getResources(), notificationSpec.iconId, null);
|
||||
}
|
||||
if (icon == null) {
|
||||
PackageManager pm = getContext().getPackageManager();
|
||||
icon = pm.getApplicationIcon(sourceAppId);
|
||||
icon = NotificationUtils.getAppIcon(getContext(), sourceAppId);
|
||||
}
|
||||
Bitmap iconBitmap = convertDrawableToBitmap(icon);
|
||||
appIconCache.put(sourceAppId, iconBitmap);
|
||||
|
Loading…
Reference in New Issue
Block a user