0

Hi I have an icon pack where adaptive icons aren't being listed and converted to PNG files on Android 8 and up. Here's the code from my IconsHelper.java

I know I have to implement the new AdaptiveIconDrawable but am unsure how I would this.

I am using the CandyBar library

@Nullable
public static String saveIcon(List<String> files, File directory, Drawable drawable, String name) {
    String fileName = name.toLowerCase().replaceAll(" ", "_") + ".png";
    File file = new File(directory, fileName);
    try {
        Bitmap bitmap;
        if (drawable instanceof LayerDrawable) {
            bitmap = Bitmap.createBitmap(
                    drawable.getIntrinsicWidth(),
                    drawable.getIntrinsicHeight(),
                    Bitmap.Config.ARGB_8888);
            drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
            drawable.draw(new Canvas(bitmap));
        } else {
            bitmap = ((BitmapDrawable) drawable).getBitmap();
        }

        if (files.contains(file.toString())) {
            fileName = fileName.replace(".png", "_" +System.currentTimeMillis()+ ".png");
            file = new File(directory, fileName);

            LogUtil.e("duplicate file name, renamed: " +fileName);
        }

        FileOutputStream outStream = new FileOutputStream(file);
        bitmap.compress(Bitmap.CompressFormat.PNG, 50, outStream);
        outStream.flush();
        outStream.close();
        return directory.toString() + "/" + fileName;
    } catch (Exception | OutOfMemoryError e) {
        LogUtil.e(Log.getStackTraceString(e));
    }
    return null;
}

0 Answers0