Skip to content

Commit 705b111

Browse files
committed
Add dynamic resource resolution for styles and icons
1 parent 03d2bd6 commit 705b111

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

src/plugins/terminal/src/android/AlpineDocumentProvider.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.util.Collections;
2020
import java.util.LinkedList;
2121
import java.util.Locale;
22-
import com.foxdebug.acode.R;
2322

2423
public class AlpineDocumentProvider extends DocumentsProvider {
2524

@@ -60,7 +59,7 @@ public Cursor queryRoots(String[] projection) {
6059
MatrixCursor result = new MatrixCursor(
6160
projection != null ? projection : DEFAULT_ROOT_PROJECTION
6261
);
63-
String applicationName = "Acode";
62+
String applicationName = getApplicationLabel();
6463

6564
MatrixCursor.RowBuilder row = result.newRow();
6665
row.add(DocumentsContract.Root.COLUMN_ROOT_ID, getDocIdForFile(BASE_DIR));
@@ -75,7 +74,7 @@ public Cursor queryRoots(String[] projection) {
7574
row.add(DocumentsContract.Root.COLUMN_TITLE, applicationName);
7675
row.add(DocumentsContract.Root.COLUMN_MIME_TYPES, ALL_MIME_TYPES);
7776
row.add(DocumentsContract.Root.COLUMN_AVAILABLE_BYTES, BASE_DIR.getFreeSpace());
78-
row.add(DocumentsContract.Root.COLUMN_ICON, R.mipmap.ic_launcher);
77+
row.add(DocumentsContract.Root.COLUMN_ICON, resolveLauncherIcon());
7978
return result;
8079
}
8180

@@ -364,4 +363,22 @@ private static String getMimeType(File file) {
364363
return "application/octet-stream";
365364
}
366365
}
366+
private int resolveLauncherIcon() {
367+
Context context = getContext();
368+
if (context == null) return android.R.mipmap.sym_def_app_icon;
369+
int icon = context.getResources().getIdentifier("ic_launcher", "mipmap", context.getPackageName());
370+
return icon != 0 ? icon : android.R.mipmap.sym_def_app_icon;
371+
}
372+
373+
private String getApplicationLabel() {
374+
Context context = getContext();
375+
if (context == null) return "Acode";
376+
PackageManager pm = context.getPackageManager();
377+
try {
378+
CharSequence label = pm.getApplicationLabel(context.getApplicationInfo());
379+
return label != null ? label.toString() : "Acode";
380+
} catch (Exception ignored) {
381+
return "Acode";
382+
}
383+
}
367384
}

src/plugins/terminal/src/android/TerminalService.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import android.os.PowerManager;
1717
import android.os.RemoteException;
1818
import androidx.core.app.NotificationCompat;
19-
import com.foxdebug.acode.R;
2019
import java.io.BufferedReader;
2120
import java.io.IOException;
2221
import java.io.InputStream;
@@ -360,13 +359,15 @@ private void updateNotification() {
360359
String contentText = "Executor service" + (isWakeLockHeld ? " (wakelock held)" : "");
361360
String wakeLockButtonText = isWakeLockHeld ? "Release Wake Lock" : "Acquire Wake Lock";
362361

362+
int notificationIcon = resolveDrawableId("ic_notification", "ic_launcher_foreground", "ic_launcher");
363+
363364
Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID)
364365
.setContentTitle("Acode Service")
365366
.setContentText(contentText)
366-
.setSmallIcon(R.drawable.ic_launcher_foreground)
367+
.setSmallIcon(notificationIcon)
367368
.setOngoing(true)
368-
.addAction(R.drawable.ic_launcher_foreground, wakeLockButtonText, wakeLockPendingIntent)
369-
.addAction(R.drawable.ic_launcher_foreground, "Exit", exitPendingIntent)
369+
.addAction(notificationIcon, wakeLockButtonText, wakeLockPendingIntent)
370+
.addAction(notificationIcon, "Exit", exitPendingIntent)
370371
.build();
371372

372373
startForeground(1, notification);
@@ -390,4 +391,12 @@ public void onDestroy() {
390391
clientMessengers.clear();
391392
threadPool.shutdown();
392393
}
393-
}
394+
395+
private int resolveDrawableId(String... names) {
396+
for (String name : names) {
397+
int id = getResources().getIdentifier(name, "drawable", getPackageName());
398+
if (id != 0) return id;
399+
}
400+
return android.R.drawable.sym_def_app_icon;
401+
}
402+
}

0 commit comments

Comments
 (0)