Skip to content

Commit b284bb0

Browse files
committed
Retrieve adaptive icons as Square
1 parent 55b9b94 commit b284bb0

File tree

5 files changed

+30
-12
lines changed

5 files changed

+30
-12
lines changed

app/build.gradle

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ android {
99
vectorDrawables.generatedDensities = []
1010
minSdkVersion 23
1111
targetSdk 35
12-
versionName '2.5.6'
13-
versionCode 28
12+
versionName '2.5.7'
13+
versionCode 29
1414
}
1515

1616
dependenciesInfo {
@@ -53,4 +53,5 @@ dependencies {
5353
implementation 'androidx.appcompat:appcompat:1.7.0'
5454
implementation 'androidx.core:core:1.15.0'
5555
implementation 'com.google.android.material:material:1.12.0'
56+
implementation 'com.github.sarsamurmu:AdaptiveIconBitmap:1.0.2'
5657
}

app/src/main/java/de/kaiserdragon/iconrequest/AppAdapter.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package de.kaiserdragon.iconrequest;
22

3+
import static de.kaiserdragon.iconrequest.helper.DrawableHelper.getBitmapFromDrawable;
4+
35
import android.app.Activity;
46
import android.util.Log;
57
import android.view.LayoutInflater;
@@ -113,12 +115,12 @@ public void onBindViewHolder(@NonNull AppViewHolder holder, int position) {
113115
holder.labelView.setText(app.getLabel());
114116
holder.packageNameView.setText(app.packageName);
115117
holder.classNameView.setText(app.className);
116-
holder.imageView.setImageDrawable(app.getIcon());
118+
holder.imageView.setImageBitmap(getBitmapFromDrawable(app.getIcon()));
117119
if (app.selected) holder.checkBox.setDisplayedChild(1);
118120
else holder.checkBox.setDisplayedChild(0);
119121
if (secondIcon) {
120122
holder.apkIconView.setVisibility(View.VISIBLE);
121-
holder.apkIconView.setImageDrawable(app.getIcon2());
123+
holder.apkIconView.setImageBitmap(getBitmapFromDrawable(app.getIcon2()));
122124
}
123125

124126
}

app/src/main/java/de/kaiserdragon/iconrequest/helper/DrawableHelper.java

+12
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@
66
import android.content.res.Resources;
77
import android.graphics.Bitmap;
88
import android.graphics.Canvas;
9+
import android.graphics.drawable.AdaptiveIconDrawable;
910
import android.graphics.drawable.Drawable;
11+
import android.os.Build;
1012
import android.util.Log;
1113

1214
import androidx.core.content.res.ResourcesCompat;
1315

16+
import sarsamurmu.adaptiveicon.AdaptiveIcon;
17+
18+
1419
public class DrawableHelper {
1520
private static final String TAG = "DrawableHelper";
1621

@@ -37,6 +42,13 @@ public static Drawable getHighResIcon(PackageManager pm, ResolveInfo resolveInfo
3742
}
3843

3944
public static Bitmap getBitmapFromDrawable(Drawable drawable) {
45+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && drawable instanceof AdaptiveIconDrawable) {
46+
return new AdaptiveIcon()
47+
.setDrawable((AdaptiveIconDrawable) drawable)
48+
.setPath(AdaptiveIcon.PATH_SQUARE)
49+
.setSize(256)
50+
.render();
51+
}
4052
final Bitmap bmp = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
4153
final Canvas canvas = new Canvas(bmp);
4254
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());

app/src/main/java/de/kaiserdragon/iconrequest/helper/ShareHelper.java

+9-7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import android.content.Context;
99
import android.content.Intent;
1010
import android.graphics.Bitmap;
11+
import android.graphics.drawable.Drawable;
1112
import android.net.Uri;
1213
import android.util.Log;
1314

@@ -52,7 +53,7 @@ public static void actionSend(String[] array, byte[] zipData, Context context) {
5253
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
5354
intent.setType("application/zip");
5455
deleteDirectory(ZipLocation);
55-
if(ZipLocation.mkdir()){
56+
if (ZipLocation.mkdir()) {
5657
File file = new File(ZipLocation, array[0] + ".zip");
5758

5859
try (FileOutputStream fos = new FileOutputStream(file)) {
@@ -75,7 +76,7 @@ public static void actionSend(String[] array, byte[] zipData, Context context) {
7576
makeToast(context.getString(R.string.no_email_clients), context);
7677
Log.e(TAG, "actionSend: ", e);
7778
}
78-
}else CommonHelper.makeToast("Something went wrong", context);
79+
} else CommonHelper.makeToast("Something went wrong", context);
7980
}
8081

8182
public static void actionSendText(String[] array, Context context) {
@@ -150,7 +151,8 @@ public static String[] actionSave(AppAdapter adapter, Boolean updateOnly, Contex
150151
LabelList.add(iconName);
151152

152153
try {
153-
Bitmap bitmap = DrawableHelper.getBitmapFromDrawable(arrayList.get(i).getIcon());
154+
Drawable drawable = arrayList.get(i).getIcon();
155+
Bitmap bitmap = DrawableHelper.getBitmapFromDrawable(drawable);
154156
ByteArrayOutputStream BaOsImg = new ByteArrayOutputStream();
155157
ZipEntry ze = new ZipEntry(iconName + ".png");
156158
bitmap.compress(Bitmap.CompressFormat.PNG, 100, BaOsImg);
@@ -203,14 +205,14 @@ private static void deleteDirectory(File path) {
203205
for (File file : files) {
204206
if (file.isDirectory()) {
205207
deleteDirectory(file);
206-
} else if(file.delete()){
208+
} else if (file.delete()) {
207209
Log.i(TAG, "deleteDirectory: " + file.getName());
208-
}else Log.e(TAG, "deleteDirectory: ", new IOException());
210+
} else Log.e(TAG, "deleteDirectory: ", new IOException());
209211
}
210212
}
211-
if(path.delete()){
213+
if (path.delete()) {
212214
Log.i(TAG, "deleteDirectory: " + path.getName());
213-
}else {
215+
} else {
214216
Log.e(TAG, "deleteDirectory: ", new IOException());
215217
}
216218
}

build.gradle

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ buildscript {
77
}
88

99
dependencies {
10-
classpath 'com.android.tools.build:gradle:8.7.1'
10+
classpath 'com.android.tools.build:gradle:8.7.3'
1111

1212
// NOTE: Do not place your application dependencies here; they belong
1313
// in the individual module build.gradle files
@@ -16,6 +16,7 @@ buildscript {
1616

1717
allprojects {
1818
repositories {
19+
maven { url 'https://jitpack.io' }
1920
mavenCentral()
2021
google()
2122
}

0 commit comments

Comments
 (0)