Skip to content

Commit

Permalink
Now Gets Highest Quality Icon
Browse files Browse the repository at this point in the history
  • Loading branch information
sarsamurmu committed Aug 12, 2019
1 parent 0c67ea1 commit d9355af
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import candybar.lib.applications.CandyBarApplication;
import candybar.lib.databases.Database;
import candybar.lib.fragments.dialog.IntentChooserFragment;
import candybar.lib.helpers.DrawableHelper;
import candybar.lib.helpers.IconsHelper;
import candybar.lib.helpers.LocaleHelper;
import candybar.lib.helpers.RequestHelper;
Expand All @@ -41,6 +40,8 @@
import candybar.lib.items.Setting;
import candybar.lib.preferences.Preferences;

import static candybar.lib.helpers.DrawableHelper.getReqIcon;

/*
* CandyBar - Material Dashboard
*
Expand Down Expand Up @@ -248,8 +249,7 @@ protected Boolean doInBackground(Void... voids) {
List<String> files = new ArrayList<>();

for (int i = 0; i < requests.size(); i++) {
Drawable drawable = DrawableHelper.getHighQualityIcon(
getActivity(), requests.get(i).getPackageName());
Drawable drawable = getReqIcon(getActivity(), requests.get(i).getPackageName());
String icon = IconsHelper.saveIcon(files, directory, drawable, requests.get(i).getName());
if (icon != null) files.add(icon);
}
Expand Down
24 changes: 19 additions & 5 deletions library/src/main/java/candybar/lib/helpers/DrawableHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,22 @@ public static Drawable getAppIcon(@NonNull Context context, ResolveInfo info) {
public static Drawable getReqIcon(@NonNull Context context, String packageName) {
try {
PackageManager packageManager = context.getPackageManager();
Drawable drawable = packageManager.getApplicationIcon(packageName);
return drawable;

Drawable normalDrawable = packageManager.getApplicationIcon(packageName);

ApplicationInfo info = packageManager.getApplicationInfo(
packageName, PackageManager.GET_META_DATA);

Resources resources = packageManager.getResourcesForApplication(packageName);
int density = DisplayMetrics.DENSITY_XXHIGH;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
density = DisplayMetrics.DENSITY_XXXHIGH;
}
Drawable drawable = ResourcesCompat.getDrawableForDensity(
resources, info.icon, density, null);

if (drawable != null) return drawable;
return normalDrawable;
} catch (Exception | OutOfMemoryError e) {
LogUtil.e(Log.getStackTraceString(e));
}
Expand All @@ -65,18 +79,18 @@ public static Drawable getReqIcon(@NonNull Context context, String packageName)

public static Bitmap getRightIcon(Drawable drawable) {
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.O) {
Log.d("CandyBarIconGeneration", "Made Normal Icon in Low SDK");
Log.d("CandyBar", "Made Normal Icon in Low SDK");
return ((BitmapDrawable) drawable).getBitmap();
} else {
if (drawable instanceof BitmapDrawable) {
Log.d("CandyBarIconGeneration", "Made Normal Icon in High SDK");
Log.d("CandyBar", "Made Normal Icon in High SDK");
return ((BitmapDrawable) drawable).getBitmap();
} else if (drawable instanceof AdaptiveIconDrawable) {
AdaptiveIconDrawable adaptiveID = ((AdaptiveIconDrawable) drawable);
AdaptiveIcon adaptiveIcon = new AdaptiveIcon();
adaptiveIcon.setDrawables(adaptiveID.getForeground(), adaptiveID.getBackground());
Bitmap iconBitmap = adaptiveIcon.render();
Log.d("CandyBarIconGeneration", "Made Adaptive Icon in High SDK");
Log.d("CandyBar", "Made Adaptive Icon in High SDK");
return iconBitmap;
}
}
Expand Down

0 comments on commit d9355af

Please sign in to comment.