From 91c3b5321a6aa72e6a3c493eb9991f00bf838217 Mon Sep 17 00:00:00 2001 From: Michel Heily Date: Thu, 1 Oct 2020 00:24:05 +0300 Subject: [PATCH] platform/android: Add menu options to capture a screenshot as the library preview image Former-commit-id: 59d0858d93cb2681bb3e4230c44858a2fe28f208 Former-commit-id: 41b094d2f7971c3ef9e53234bd0c65e56ef99e20 --- .../rustdroid_emu/ui/EmulatorActivity.java | 41 ++++++++++++++++++- .../ui/library/RomListActivity.java | 3 ++ .../main/res/layout-land/content_emulator.xml | 1 + .../src/main/res/layout/content_emulator.xml | 1 + .../app/src/main/res/menu/menu_emulator.xml | 11 +++-- .../app/src/main/res/values/strings.xml | 1 + 6 files changed, 54 insertions(+), 4 deletions(-) diff --git a/platform/android/app/src/main/java/com/mrmichel/rustdroid_emu/ui/EmulatorActivity.java b/platform/android/app/src/main/java/com/mrmichel/rustdroid_emu/ui/EmulatorActivity.java index cae22cd..09cb024 100644 --- a/platform/android/app/src/main/java/com/mrmichel/rustdroid_emu/ui/EmulatorActivity.java +++ b/platform/android/app/src/main/java/com/mrmichel/rustdroid_emu/ui/EmulatorActivity.java @@ -369,7 +369,9 @@ public class EmulatorActivity extends AppCompatActivity implements View.OnClickL } else { int romId = getIntent().getIntExtra("romId", -1); if (-1 != romId) { - this.romMetadata = RomManager.getInstance(this).getRomMetadata(romId); + RomManager romManager = RomManager.getInstance(this); + romManager.updateLastPlayed(romId); + this.romMetadata = romManager.getRomMetadata(romId); byte[] romData; try { @@ -404,6 +406,9 @@ public class EmulatorActivity extends AppCompatActivity implements View.OnClickL case R.id.action_save_snapshot: doSaveSnapshot(); return true; + case R.id.action_set_library_image: + doSaveScreenshotToLibrary(); + return true; case R.id.action_settings: Intent intent = new Intent(this, SettingsActivity.class); startActivity(intent); @@ -436,6 +441,20 @@ public class EmulatorActivity extends AppCompatActivity implements View.OnClickL protected void onDestroy() { super.onDestroy(); pauseEmulation(); + + if (this.romMetadata != null) { + if (this.romMetadata.getScreenshot() == null) { + // Save current screenshot + Bitmap screenshot = Bitmap.createBitmap( + emulator.getFrameBuffer(), + 240, + 160, + Bitmap.Config.RGB_565); + + RomManager.getInstance(this).updateScreenshot(this.romMetadata.getId(), screenshot); + + } + } killThreads(); } @@ -454,6 +473,26 @@ public class EmulatorActivity extends AppCompatActivity implements View.OnClickL audioPlayer.play(); } + public void doSaveScreenshotToLibrary() { + if (!isEmulatorRunning() || null == this.romMetadata) { + Toast.makeText(this, "No game is running!", Toast.LENGTH_LONG).show(); + return; + } + + pauseEmulation(); + + Bitmap screenshot = Bitmap.createBitmap( + emulator.getFrameBuffer(), + 240, + 160, + Bitmap.Config.RGB_565); + + RomManager.getInstance(this).updateScreenshot(this.romMetadata.getId(), screenshot); + + + resumeEmulation(); + } + public void doSaveSnapshot() { if (!isEmulatorRunning()) { Toast.makeText(this, "No game is running!", Toast.LENGTH_LONG).show(); diff --git a/platform/android/app/src/main/java/com/mrmichel/rustdroid_emu/ui/library/RomListActivity.java b/platform/android/app/src/main/java/com/mrmichel/rustdroid_emu/ui/library/RomListActivity.java index 013c715..aa76fbf 100644 --- a/platform/android/app/src/main/java/com/mrmichel/rustdroid_emu/ui/library/RomListActivity.java +++ b/platform/android/app/src/main/java/com/mrmichel/rustdroid_emu/ui/library/RomListActivity.java @@ -105,6 +105,7 @@ public class RomListActivity extends AppCompatActivity { case R.id.action_play: romManager.updateLastPlayed(entry.getId()); Util.startEmulator(this, this.bios, entry.getId()); + this.itemAdapter.notifyDataSetChanged(); return true; case R.id.action_delete: romManager.deleteRomMetadata(itemAdapter.getItem(menuInfo.position)); @@ -214,6 +215,7 @@ public class RomListActivity extends AppCompatActivity { Log.d(TAG, "found bitmap"); romManager.updateScreenshot(romId, bitmap); + break; case REQUEST_IMPORT_SAVE: try { @@ -234,6 +236,7 @@ public class RomListActivity extends AppCompatActivity { } + this.itemAdapter.notifyDataSetChanged(); mGridView.setAdapter(new RomListItemAdapter(this, romManager.getAllRomMetaData())); mGridView.invalidate(); diff --git a/platform/android/app/src/main/res/layout-land/content_emulator.xml b/platform/android/app/src/main/res/layout-land/content_emulator.xml index 9b7a511..704cb45 100644 --- a/platform/android/app/src/main/res/layout-land/content_emulator.xml +++ b/platform/android/app/src/main/res/layout-land/content_emulator.xml @@ -3,6 +3,7 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" + android:keepScreenOn="true" android:background="@color/gbaBackground" android:layout_width="match_parent" android:layout_height="match_parent"> diff --git a/platform/android/app/src/main/res/layout/content_emulator.xml b/platform/android/app/src/main/res/layout/content_emulator.xml index 3bf4d2d..dd481d6 100644 --- a/platform/android/app/src/main/res/layout/content_emulator.xml +++ b/platform/android/app/src/main/res/layout/content_emulator.xml @@ -2,6 +2,7 @@ diff --git a/platform/android/app/src/main/res/menu/menu_emulator.xml b/platform/android/app/src/main/res/menu/menu_emulator.xml index 275e20c..171aa4a 100644 --- a/platform/android/app/src/main/res/menu/menu_emulator.xml +++ b/platform/android/app/src/main/res/menu/menu_emulator.xml @@ -27,13 +27,18 @@ android:orderInCategory="101" android:title="@string/action_view_snapshot" app:showAsAction="ifRoom|withText" /> - - + + + + diff --git a/platform/android/app/src/main/res/values/strings.xml b/platform/android/app/src/main/res/values/strings.xml index 8687a6b..c7d25fb 100644 --- a/platform/android/app/src/main/res/values/strings.xml +++ b/platform/android/app/src/main/res/values/strings.xml @@ -14,6 +14,7 @@ Set Image Delete + Take screenshot for library view Snapshot Manager