Skip to content

Commit

Permalink
Fix: non themes icons in preview
Browse files Browse the repository at this point in the history
  • Loading branch information
ukanth committed Jan 3, 2020
1 parent d50ce92 commit c226cd9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
16 changes: 15 additions & 1 deletion app/src/main/java/dev/ukanth/iconmgr/IconPackUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.AdaptiveIconDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
import android.support.annotation.RequiresApi;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.graphics.Palette;
import android.util.Log;
Expand Down Expand Up @@ -542,6 +545,17 @@ public List<String> getMissingApps(String currentPackage, List<ResolveInfo> list
return requests;
}


@NonNull
private Bitmap getBitmapFromDrawable(@NonNull Drawable drawable) {
final Bitmap bmp = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(bmp);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bmp;
}

@RequiresApi(api = Build.VERSION_CODES.O)
public Set<Icon> getNonThemeIcons(String currentPackage) throws ExecutionException, InterruptedException {
Context context = App.getContext();
PackageManager packageManager = context.getPackageManager();
Expand Down Expand Up @@ -577,7 +591,7 @@ public Set<Icon> getNonThemeIcons(String currentPackage) throws ExecutionExcepti
String label = (String) app.activityInfo.applicationInfo.loadLabel(packageManager);
try {
Drawable drawable = packageManager.getApplicationIcon(packageName);
Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
Bitmap bitmap = getBitmapFromDrawable(drawable);
bitmap = getResizedBitmap(bitmap, 256, 256, true);
bitmap = generateBitmap(bitmap, mBackImages, mPaint, maskImage, frontImage, packageName);
//try to mask icon
Expand Down
25 changes: 11 additions & 14 deletions app/src/main/java/dev/ukanth/iconmgr/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -410,20 +410,17 @@ public boolean onCreateOptionsMenu(Menu menu) {

mainMenu = menu;
//make sure we update sort entry
runOnUiThread(new Runnable() {
@Override
public void run() {
switch (Prefs.sortBy()) {
case "s0":
mainMenu.findItem(R.id.sort_alpha).setChecked(true);
break;
case "s1":
mainMenu.findItem(R.id.sort_lastupdate).setChecked(true);
break;
case "s2":
mainMenu.findItem(R.id.sort_count).setChecked(true);
break;
}
runOnUiThread(() -> {
switch (Prefs.sortBy()) {
case "s0":
mainMenu.findItem(R.id.sort_alpha).setChecked(true);
break;
case "s1":
mainMenu.findItem(R.id.sort_lastupdate).setChecked(true);
break;
case "s2":
mainMenu.findItem(R.id.sort_count).setChecked(true);
break;
}
});

Expand Down

0 comments on commit c226cd9

Please sign in to comment.