Skip to content

Commit 3c15dfe

Browse files
NmurtasDevclaude
andcommitted
Improve device card display with user-friendly information
- Replace technical "API" label with readable Android version names (e.g., "Android 14") - Convert API levels to version names: API 36 -> Android 16, API 35 -> Android 15, etc. - Remove confusing "Target" field - Extract and display device type from config.ini (e.g., "Pixel 7") - Add emoji icons for better visual clarity: 📱 for version, 📐 for device, 🟢/⚪ for status - Format device names: pixel_7 -> Pixel 7 - Make version and status labels bold for better readability - Support API levels from 21 (Android 5.0) to 36 (Android 16) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 9e44ef3 commit 3c15dfe

1 file changed

Lines changed: 95 additions & 5 deletions

File tree

src/main/java/net/nicolamurtas/android/emulator/AndroidEmulatorManager.java

Lines changed: 95 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -291,15 +291,23 @@ private JPanel createDeviceCard(EmulatorService.AvdInfo avd) {
291291
JPanel detailsPanel = new JPanel(new GridLayout(0, 1, 2, 2));
292292
detailsPanel.setVisible(false);
293293

294-
// Extract API level from target
294+
// Extract API level and convert to Android version name
295295
String apiLevel = extractApiLevel(avd.target());
296-
detailsPanel.add(new JLabel("API: " + apiLevel));
297-
detailsPanel.add(new JLabel("Target: " + (avd.target() != null && avd.target().length() > 20 ?
298-
avd.target().substring(0, 20) + "..." : avd.target())));
296+
String androidVersion = getAndroidVersionName(apiLevel);
297+
JLabel versionLabel = new JLabel("📱 " + androidVersion);
298+
versionLabel.setFont(versionLabel.getFont().deriveFont(Font.BOLD));
299+
detailsPanel.add(versionLabel);
300+
301+
// Show device type from path (e.g., pixel_7)
302+
String deviceType = extractDeviceType(avd.path());
303+
if (deviceType != null && !deviceType.isEmpty()) {
304+
detailsPanel.add(new JLabel("📐 Device: " + deviceType));
305+
}
299306

300307
// Check if running
301308
boolean isRunning = emulatorService != null && emulatorService.isEmulatorRunning(avd.name());
302-
JLabel statusLabel = new JLabel(isRunning ? "Status: Running" : "Status: Stopped");
309+
JLabel statusLabel = new JLabel(isRunning ? "🟢 Running" : "⚪ Stopped");
310+
statusLabel.setFont(statusLabel.getFont().deriveFont(Font.BOLD));
303311
statusLabel.setForeground(isRunning ? new Color(76, 175, 80) : Color.GRAY);
304312
detailsPanel.add(statusLabel);
305313

@@ -373,6 +381,88 @@ private String extractApiLevel(String target) {
373381
return "Unknown";
374382
}
375383

384+
/**
385+
* Converts API level to Android version name.
386+
*/
387+
private String getAndroidVersionName(String apiLevel) {
388+
if (apiLevel == null || apiLevel.equals("Unknown")) {
389+
return "Android (Unknown)";
390+
}
391+
392+
return switch (apiLevel) {
393+
case "36" -> "Android 16";
394+
case "35" -> "Android 15";
395+
case "34" -> "Android 14";
396+
case "33" -> "Android 13";
397+
case "32" -> "Android 12L";
398+
case "31" -> "Android 12";
399+
case "30" -> "Android 11";
400+
case "29" -> "Android 10";
401+
case "28" -> "Android 9";
402+
case "27" -> "Android 8.1";
403+
case "26" -> "Android 8.0";
404+
case "25" -> "Android 7.1";
405+
case "24" -> "Android 7.0";
406+
case "23" -> "Android 6.0";
407+
case "22" -> "Android 5.1";
408+
case "21" -> "Android 5.0";
409+
default -> "Android API " + apiLevel;
410+
};
411+
}
412+
413+
/**
414+
* Extracts device type from AVD path.
415+
* Example: /home/user/.android/avd/MyDevice.avd -> looks in config.ini for hw.device.name
416+
*/
417+
private String extractDeviceType(String avdPath) {
418+
if (avdPath == null) return null;
419+
420+
try {
421+
Path configIni = Path.of(avdPath).resolve("config.ini");
422+
if (Files.exists(configIni)) {
423+
String content = Files.readString(configIni);
424+
// Look for hw.device.name=pixel_7
425+
for (String line : content.split("\n")) {
426+
if (line.startsWith("hw.device.name=")) {
427+
String deviceName = line.substring(15).trim();
428+
// Format device name: pixel_7 -> Pixel 7
429+
return formatDeviceName(deviceName);
430+
}
431+
}
432+
}
433+
} catch (Exception e) {
434+
logger.debug("Could not extract device type from path: {}", avdPath);
435+
}
436+
437+
return null;
438+
}
439+
440+
/**
441+
* Formats device name for display.
442+
* Example: pixel_7 -> Pixel 7, pixel -> Pixel
443+
*/
444+
private String formatDeviceName(String deviceName) {
445+
if (deviceName == null || deviceName.isEmpty()) {
446+
return deviceName;
447+
}
448+
449+
// Replace underscores with spaces and capitalize words
450+
String[] parts = deviceName.replace("_", " ").split(" ");
451+
StringBuilder formatted = new StringBuilder();
452+
453+
for (String part : parts) {
454+
if (!part.isEmpty()) {
455+
formatted.append(Character.toUpperCase(part.charAt(0)));
456+
if (part.length() > 1) {
457+
formatted.append(part.substring(1));
458+
}
459+
formatted.append(" ");
460+
}
461+
}
462+
463+
return formatted.toString().trim();
464+
}
465+
376466
/**
377467
* Changes the current page of devices.
378468
*/

0 commit comments

Comments
 (0)