android: WIP snapshot manager
Former-commit-id: 7b39e4ac1ea86262a0a1ccf95639382f20801d92
This commit is contained in:
parent
fc8b066191
commit
e75c3289cd
|
@ -13,10 +13,17 @@
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/AppTheme">
|
android:theme="@style/AppTheme">
|
||||||
<activity
|
<activity
|
||||||
android:name="com.mrmichel.rustdroid_emu.ui.EmulatorActivity"
|
android:name=".ui.snapshots.SnapshotActivity"
|
||||||
|
android:label="@string/title_activity_snapshot"
|
||||||
|
></activity>
|
||||||
|
<activity
|
||||||
|
android:name=".ui.RomListActivity"
|
||||||
|
android:label="@string/title_activity_rom_list" />
|
||||||
|
<activity
|
||||||
|
android:name=".ui.EmulatorActivity"
|
||||||
android:label="@string/title_activity_emulator"
|
android:label="@string/title_activity_emulator"
|
||||||
android:theme="@style/AppTheme.NoActionBar"></activity>
|
android:theme="@style/AppTheme.NoActionBar" />
|
||||||
<activity android:name="com.mrmichel.rustdroid_emu.ui.SplashActivity">
|
<activity android:name=".ui.SplashActivity">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
|
|
|
@ -15,11 +15,12 @@ public class EmulatorBindings {
|
||||||
* Open a new emulator context
|
* Open a new emulator context
|
||||||
* @param bios bytearray of the GBA bios
|
* @param bios bytearray of the GBA bios
|
||||||
* @param rom bytearray of the rom to run
|
* @param rom bytearray of the rom to run
|
||||||
|
* @param frameBuffer frameBuffer render target
|
||||||
* @param save_name name of the save file TODO remove this
|
* @param save_name name of the save file TODO remove this
|
||||||
* @return the emulator context to use pass to other methods in this class
|
* @return the emulator context to use pass to other methods in this class
|
||||||
* @throws NativeBindingException
|
* @throws NativeBindingException
|
||||||
*/
|
*/
|
||||||
public static native long openEmulator(byte[] bios, byte[] rom, String save_name) throws NativeBindingException;
|
public static native long openEmulator(byte[] bios, byte[] rom, int[] frameBuffer, String save_name) throws NativeBindingException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make the emulator boot directly into the cartridge
|
* Make the emulator boot directly into the cartridge
|
||||||
|
@ -41,15 +42,25 @@ public class EmulatorBindings {
|
||||||
* Runs the emulation for a single frame.
|
* Runs the emulation for a single frame.
|
||||||
* @param ctx
|
* @param ctx
|
||||||
* @param frame_buffer will be filled with the frame buffer to render
|
* @param frame_buffer will be filled with the frame buffer to render
|
||||||
* @return
|
|
||||||
* @throws NativeBindingException
|
|
||||||
*/
|
*/
|
||||||
public static native void runFrame(long ctx, int[] frame_buffer) throws NativeBindingException;
|
public static native void runFrame(long ctx, int[] frame_buffer);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param ctx
|
||||||
|
* @return The loaded ROM title
|
||||||
|
*/
|
||||||
|
public static native String getGameTitle(long ctx);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param ctx
|
||||||
|
* @return The loaded ROM game code
|
||||||
|
*/
|
||||||
|
public static native String getGameCode(long ctx);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the keystate
|
* Sets the keystate
|
||||||
* @param keyState
|
* @param keyState
|
||||||
* @return non-zero value on failure
|
|
||||||
*/
|
*/
|
||||||
public static native void setKeyState(long ctx, int keyState);
|
public static native void setKeyState(long ctx, int keyState);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package com.mrmichel.rustdroid_emu.core;
|
package com.mrmichel.rustdroid_emu.core;
|
||||||
|
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
|
||||||
import com.mrmichel.rustboyadvance.EmulatorBindings;
|
import com.mrmichel.rustboyadvance.EmulatorBindings;
|
||||||
|
|
||||||
public class Emulator {
|
public class Emulator {
|
||||||
|
@ -29,7 +31,7 @@ public class Emulator {
|
||||||
return frameBuffer;
|
return frameBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void runFrame() throws EmulatorBindings.NativeBindingException {
|
public synchronized void runFrame() {
|
||||||
EmulatorBindings.setKeyState(this.ctx, this.keypad.getKeyState());
|
EmulatorBindings.setKeyState(this.ctx, this.keypad.getKeyState());
|
||||||
EmulatorBindings.runFrame(this.ctx, this.frameBuffer);
|
EmulatorBindings.runFrame(this.ctx, this.frameBuffer);
|
||||||
}
|
}
|
||||||
|
@ -39,18 +41,18 @@ public class Emulator {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public byte[] saveState() throws EmulatorBindings.NativeBindingException {
|
public synchronized byte[] saveState() throws EmulatorBindings.NativeBindingException {
|
||||||
return EmulatorBindings.saveState(this.ctx);
|
return EmulatorBindings.saveState(this.ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void loadState(byte[] state) throws EmulatorBindings.NativeBindingException {
|
public synchronized void loadState(byte[] state) throws EmulatorBindings.NativeBindingException {
|
||||||
EmulatorBindings.loadState(this.ctx, state);
|
EmulatorBindings.loadState(this.ctx, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public synchronized void open(byte[] bios, byte[] rom, String saveName) throws EmulatorBindings.NativeBindingException {
|
public synchronized void open(byte[] bios, byte[] rom, String saveName) throws EmulatorBindings.NativeBindingException {
|
||||||
this.ctx = EmulatorBindings.openEmulator(bios, rom, saveName);
|
this.ctx = EmulatorBindings.openEmulator(bios, rom, this.frameBuffer, saveName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void close() {
|
public synchronized void close() {
|
||||||
|
@ -61,6 +63,14 @@ public class Emulator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getGameCode() {
|
||||||
|
return EmulatorBindings.getGameCode(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGameTitle() {
|
||||||
|
return EmulatorBindings.getGameTitle(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isOpen() {
|
public boolean isOpen() {
|
||||||
return this.ctx != -1;
|
return this.ctx != -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
package com.mrmichel.rustdroid_emu.core;
|
||||||
|
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class Snapshot {
|
||||||
|
private Bitmap preview;
|
||||||
|
private String gameCode;
|
||||||
|
private String gameTitle;
|
||||||
|
private long timestamp;
|
||||||
|
private File file;
|
||||||
|
|
||||||
|
public Snapshot(File file, String gameCode, String gameTitle, Bitmap preview) {
|
||||||
|
this.file = file;
|
||||||
|
this.gameCode = gameCode;
|
||||||
|
this.gameTitle = gameTitle;
|
||||||
|
this.preview = preview;
|
||||||
|
this.timestamp = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Snapshot(File file, String gameCode, String gameTitle, Bitmap preview, long timestamp) {
|
||||||
|
this.file = file;
|
||||||
|
this.gameCode = gameCode;
|
||||||
|
this.gameTitle = gameTitle;
|
||||||
|
this.preview = preview;
|
||||||
|
this.timestamp = timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGameCode() {
|
||||||
|
return gameCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGameTitle() {
|
||||||
|
return gameTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getTimestamp() {
|
||||||
|
return timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bitmap getPreview() {
|
||||||
|
return preview;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] load() {
|
||||||
|
return SnapshotManager.readCompressedFile(this.file);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,230 @@
|
||||||
|
package com.mrmichel.rustdroid_emu.core;
|
||||||
|
|
||||||
|
import android.content.ContentValues;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
import android.database.sqlite.SQLiteOpenHelper;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.zip.GZIPInputStream;
|
||||||
|
import java.util.zip.GZIPOutputStream;
|
||||||
|
|
||||||
|
public class SnapshotManager {
|
||||||
|
private static final String TAG = "SnapshotManager";
|
||||||
|
|
||||||
|
private static final String SNAPSHOT_ROOT = "snapshots";
|
||||||
|
private static final String DB_NAME = "snapshots";
|
||||||
|
|
||||||
|
static SnapshotManager instance;
|
||||||
|
|
||||||
|
private Context context;
|
||||||
|
|
||||||
|
private SnapshotDatabaseHelper dbHelper;
|
||||||
|
|
||||||
|
public class SnapshotDBEntry {
|
||||||
|
String gameCode;
|
||||||
|
String gameTitle;
|
||||||
|
File previewFile;
|
||||||
|
File snapshotFile;
|
||||||
|
Timestamp timestamp;
|
||||||
|
|
||||||
|
public SnapshotDBEntry(String gameCode, File previewFile, File snapshotFile, Timestamp timestamp) {
|
||||||
|
this.gameCode = gameCode;
|
||||||
|
this.previewFile = previewFile;
|
||||||
|
this.snapshotFile = snapshotFile;
|
||||||
|
this.timestamp = timestamp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class SnapshotDatabaseHelper extends SQLiteOpenHelper {
|
||||||
|
public static final String TABLE_NAME = "snapshot_table";
|
||||||
|
private Context context;
|
||||||
|
|
||||||
|
public SnapshotDatabaseHelper(Context context) {
|
||||||
|
super(context, DB_NAME, null, 1);
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(SQLiteDatabase db) {
|
||||||
|
db.execSQL("create table " + TABLE_NAME +
|
||||||
|
" (id INTEGER PRIMARY KEY, gameCode TEXT, gameTitle TEXT, timestamp DATETIME DEFAULT CURRENT_TIMESTAMP, previewImageFile TEXT, dataFile TEXT)"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void insertSnapshot(String gameCode, String gameTitle, File previewCacheFile, File snapshotDataFile) {
|
||||||
|
SQLiteDatabase db = this.getWritableDatabase();
|
||||||
|
ContentValues values = new ContentValues();
|
||||||
|
values.put("gameCode", gameCode);
|
||||||
|
values.put("gameTitle", gameTitle);
|
||||||
|
values.put("previewImageFile", previewCacheFile.getPath());
|
||||||
|
values.put("dataFile", snapshotDataFile.getPath());
|
||||||
|
db.insertOrThrow(TABLE_NAME, null, values);
|
||||||
|
db.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Snapshot> getEntriesByQuery(String query) {
|
||||||
|
ArrayList<Snapshot> arrayList = new ArrayList<>();
|
||||||
|
|
||||||
|
SQLiteDatabase db = this.getWritableDatabase();
|
||||||
|
Cursor cursor = db.rawQuery(query, null);
|
||||||
|
|
||||||
|
if (cursor.moveToFirst()) {
|
||||||
|
do {
|
||||||
|
String gameCode = cursor.getString(1);
|
||||||
|
String gameTitle = cursor.getString(2);
|
||||||
|
Timestamp timestamp = Timestamp.valueOf(cursor.getString(3));
|
||||||
|
File previewImageFile = new File(cursor.getString(4));
|
||||||
|
File dataFile = new File(cursor.getString(5));
|
||||||
|
|
||||||
|
byte[] previewData = readCompressedFile(previewImageFile);
|
||||||
|
Bitmap previewBitmap = BitmapFactory.decodeByteArray(previewData, 0, previewData.length);
|
||||||
|
|
||||||
|
arrayList.add(new Snapshot(dataFile, gameCode, gameTitle, previewBitmap, timestamp.getTime()));
|
||||||
|
} while (cursor.moveToNext());
|
||||||
|
}
|
||||||
|
|
||||||
|
cursor.close();
|
||||||
|
db.close();
|
||||||
|
return arrayList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Snapshot> getAllEntries() {
|
||||||
|
return getEntriesByQuery("SELECT * FROM " + TABLE_NAME + " ORDER BY timestamp DESC ");
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Snapshot> getAllEntries(String gameCode) {
|
||||||
|
return getEntriesByQuery("SELECT * FROM " + TABLE_NAME + "where gameCode = " + gameCode + " ORDER BY timestamp DESC ");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private SnapshotManager(Context context) {
|
||||||
|
this.context = context;
|
||||||
|
this.dbHelper = new SnapshotDatabaseHelper(this.context);
|
||||||
|
// this.snapshotDB = context.openOrCreateDatabase("snapshots", Context.MODE_PRIVATE, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SnapshotManager getInstance(Context context) {
|
||||||
|
if (instance == null) {
|
||||||
|
instance = new SnapshotManager(context);
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String byteArrayToHexString(final byte[] bytes) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (byte b : bytes) {
|
||||||
|
sb.append(String.format("%02x", b & 0xff));
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getHash(final byte[] bytes) {
|
||||||
|
MessageDigest md;
|
||||||
|
try {
|
||||||
|
md = MessageDigest.getInstance("SHA-256");
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
// impossible
|
||||||
|
Log.e("SnapshotManager", "SHA-256 algo not found");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
md.update(bytes);
|
||||||
|
return byteArrayToHexString(md.digest());
|
||||||
|
}
|
||||||
|
|
||||||
|
private File getPreviewsDir(String gameCode) {
|
||||||
|
File d = new File(context.getFilesDir(), SNAPSHOT_ROOT + "/previews");
|
||||||
|
d.mkdirs();
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private File getSnapshotDir(String gameCode) {
|
||||||
|
File d = new File(context.getFilesDir(), SNAPSHOT_ROOT + "/data");
|
||||||
|
d.mkdirs();
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void writeCompressedFile(File file, byte[] bytes) {
|
||||||
|
try {
|
||||||
|
FileOutputStream fos = new FileOutputStream(file);
|
||||||
|
GZIPOutputStream gos = new GZIPOutputStream(fos);
|
||||||
|
|
||||||
|
gos.write(bytes);
|
||||||
|
gos.close();
|
||||||
|
fos.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "failed to write compressed file " + file.toString() + " error: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] readCompressedFile(File file) {
|
||||||
|
try {
|
||||||
|
byte[] buffer = new byte[8192];
|
||||||
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
|
GZIPInputStream gis = new GZIPInputStream(new FileInputStream(file));
|
||||||
|
|
||||||
|
int len;
|
||||||
|
|
||||||
|
while ( (len = gis.read(buffer, 0, 8192)) != -1) {
|
||||||
|
outputStream.write(buffer, 0, len);
|
||||||
|
}
|
||||||
|
gis.close();
|
||||||
|
return outputStream.toByteArray();
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "failed to read compressed file " + file.toString() + " error: " + e.getMessage());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] compressBitmapToByteArray(Bitmap bitmap) {
|
||||||
|
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||||
|
bitmap.compress(Bitmap.CompressFormat.PNG, 10, byteArrayOutputStream);
|
||||||
|
return byteArrayOutputStream.toByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveSnapshot(String gameCode, String gameTitle, Bitmap previewImage, byte[] data) {
|
||||||
|
byte[] previewImageBytes = compressBitmapToByteArray(previewImage);
|
||||||
|
|
||||||
|
String hash = getHash(data);
|
||||||
|
|
||||||
|
File previewsDir = getPreviewsDir(gameCode);
|
||||||
|
File snapshotsDir = getSnapshotDir(gameCode);
|
||||||
|
|
||||||
|
File previewFile = new File(previewsDir, hash);
|
||||||
|
writeCompressedFile(previewFile, previewImageBytes);
|
||||||
|
|
||||||
|
File snapshotFile = new File(snapshotsDir, hash);
|
||||||
|
writeCompressedFile(snapshotFile, data);
|
||||||
|
|
||||||
|
this.dbHelper.insertSnapshot(gameCode, gameTitle, previewFile, snapshotFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Snapshot> getAllSnapshots() {
|
||||||
|
return this.dbHelper.getAllEntries();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Snapshot> getByGameCode(String gameCode) {
|
||||||
|
return this.dbHelper.getAllEntries(gameCode);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,25 +1,37 @@
|
||||||
package com.mrmichel.rustdroid_emu.ui;
|
package com.mrmichel.rustdroid_emu.ui;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.ContextMenu;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuInflater;
|
||||||
|
import android.view.MenuItem;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.WindowManager;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.ToggleButton;
|
import android.widget.Switch;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.mrmichel.rustboyadvance.EmulatorBindings;
|
import com.mrmichel.rustboyadvance.EmulatorBindings;
|
||||||
import com.mrmichel.rustdroid_emu.core.Emulator;
|
import com.mrmichel.rustdroid_emu.core.Emulator;
|
||||||
import com.mrmichel.rustdroid_emu.core.Keypad;
|
import com.mrmichel.rustdroid_emu.core.Keypad;
|
||||||
import com.mrmichel.rustdroid_emu.R;
|
import com.mrmichel.rustdroid_emu.R;
|
||||||
|
import com.mrmichel.rustdroid_emu.core.Snapshot;
|
||||||
|
import com.mrmichel.rustdroid_emu.core.SnapshotManager;
|
||||||
|
import com.mrmichel.rustdroid_emu.ui.snapshots.ChosenSnapshot;
|
||||||
|
import com.mrmichel.rustdroid_emu.ui.snapshots.SnapshotActivity;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -28,19 +40,20 @@ public class EmulatorActivity extends AppCompatActivity implements View.OnClickL
|
||||||
|
|
||||||
private static final String TAG = "EmulatorActivty";
|
private static final String TAG = "EmulatorActivty";
|
||||||
private static final int LOAD_ROM_REQUESTCODE = 123;
|
private static final int LOAD_ROM_REQUESTCODE = 123;
|
||||||
|
private static final int LOAD_SNAPSHOT_REQUESTCODE = 124;
|
||||||
|
|
||||||
private byte[] bios;
|
private byte[] bios;
|
||||||
private Emulator emulator = null;
|
private Emulator emulator = null;
|
||||||
private EmulationRunnable runnable;
|
private EmulationRunnable runnable;
|
||||||
private Thread emulationThread;
|
private Thread emulationThread;
|
||||||
private byte[] snapshot = null;
|
private byte[] on_resume_saved_state = null;
|
||||||
private ImageView screen;
|
private ImageView screen;
|
||||||
private boolean turboMode = false;
|
private boolean turboMode = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (v.getId() == R.id.tbTurbo) {
|
if (v.getId() == R.id.tbTurbo) {
|
||||||
ToggleButton tbTurbo = (ToggleButton) findViewById(R.id.tbTurbo);
|
Switch tbTurbo = (Switch) findViewById(R.id.tbTurbo);
|
||||||
this.turboMode = tbTurbo.isChecked();
|
this.turboMode = tbTurbo.isChecked();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -131,6 +144,16 @@ public class EmulatorActivity extends AppCompatActivity implements View.OnClickL
|
||||||
showAlertDiaglogAndExit(e);
|
showAlertDiaglogAndExit(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (requestCode == LOAD_SNAPSHOT_REQUESTCODE) {
|
||||||
|
byte[] state = ChosenSnapshot.takeSnapshot().load();
|
||||||
|
if (emulator.isOpen()) {
|
||||||
|
try {
|
||||||
|
emulator.loadState(state);
|
||||||
|
} catch (EmulatorBindings.NativeBindingException e) {
|
||||||
|
showAlertDiaglogAndExit(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.e(TAG, "got error for request code " + requestCode);
|
Log.e(TAG, "got error for request code " + requestCode);
|
||||||
}
|
}
|
||||||
|
@ -187,11 +210,26 @@ public class EmulatorActivity extends AppCompatActivity implements View.OnClickL
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_emulator);
|
setContentView(R.layout.activity_emulator);
|
||||||
|
|
||||||
|
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||||
|
|
||||||
|
|
||||||
this.bios = getIntent().getByteArrayExtra("bios");
|
this.bios = getIntent().getByteArrayExtra("bios");
|
||||||
this.screen = findViewById(R.id.gbaMockImageView);
|
this.screen = findViewById(R.id.gbaMockImageView);
|
||||||
this.emulator = new Emulator();
|
this.emulator = new Emulator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
|
super.onCreateOptionsMenu(menu);
|
||||||
|
getMenuInflater().inflate(R.menu.menu_emulator, menu);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
|
@ -200,31 +238,58 @@ public class EmulatorActivity extends AppCompatActivity implements View.OnClickL
|
||||||
runnable.pauseEmulation();
|
runnable.pauseEmulation();
|
||||||
}
|
}
|
||||||
Log.d(TAG, "onPause - saving emulator state");
|
Log.d(TAG, "onPause - saving emulator state");
|
||||||
try {
|
// try {
|
||||||
snapshot = emulator.saveState();
|
// on_resume_saved_state = emulator.saveState();
|
||||||
} catch (EmulatorBindings.NativeBindingException e) {
|
// } catch (EmulatorBindings.NativeBindingException e) {
|
||||||
showAlertDiaglogAndExit(e);
|
// showAlertDiaglogAndExit(e);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
if (emulator.isOpen() && snapshot != null) {
|
if (emulator.isOpen()) {
|
||||||
Log.d(TAG, "onResume - loading emulator state");
|
Log.d(TAG, "onResume - loading emulator state");
|
||||||
try {
|
// try {
|
||||||
emulator.loadState(snapshot);
|
// emulator.loadState(on_resume_saved_state);
|
||||||
} catch (EmulatorBindings.NativeBindingException e) {
|
// } catch (EmulatorBindings.NativeBindingException e) {
|
||||||
showAlertDiaglogAndExit(e);
|
// showAlertDiaglogAndExit(e);
|
||||||
}
|
// }
|
||||||
snapshot = null;
|
// on_resume_saved_state = null;
|
||||||
if (runnable != null) {
|
if (runnable != null) {
|
||||||
runnable.resumeEmulation();
|
runnable.resumeEmulation();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onSaveSnapshot(View v) {
|
||||||
|
SnapshotManager snapshotManager = SnapshotManager.getInstance(this);
|
||||||
|
|
||||||
|
runnable.pauseEmulation();
|
||||||
|
try {
|
||||||
|
String gameCode = emulator.getGameCode();
|
||||||
|
String gameTitle = emulator.getGameTitle();
|
||||||
|
byte[] saveState = emulator.saveState();
|
||||||
|
Bitmap preview = Bitmap.createBitmap(emulator.getFrameBuffer(), 240, 160, Bitmap.Config.RGB_565);
|
||||||
|
|
||||||
|
snapshotManager.saveSnapshot(gameCode, gameTitle, preview, saveState);
|
||||||
|
Toast.makeText(this, "Snapshot saved", Toast.LENGTH_LONG).show();
|
||||||
|
|
||||||
|
} catch (EmulatorBindings.NativeBindingException e) {
|
||||||
|
Log.e(TAG, e.toString());
|
||||||
|
showAlertDiaglogAndExit(e);
|
||||||
|
} finally {
|
||||||
|
runnable.resumeEmulation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void onViewSnapshots(View v) {
|
||||||
|
Intent intent = new Intent(this, SnapshotActivity.class);
|
||||||
|
startActivityForResult(intent, LOAD_SNAPSHOT_REQUESTCODE);
|
||||||
|
}
|
||||||
|
|
||||||
public void updateScreen(Bitmap bmp) {
|
public void updateScreen(Bitmap bmp) {
|
||||||
this.screen.setImageBitmap(bmp);
|
this.screen.setImageBitmap(bmp);
|
||||||
}
|
}
|
||||||
|
@ -247,19 +312,7 @@ public class EmulatorActivity extends AppCompatActivity implements View.OnClickL
|
||||||
|
|
||||||
private void emulate() {
|
private void emulate() {
|
||||||
long startTimer = System.nanoTime();
|
long startTimer = System.nanoTime();
|
||||||
|
emulator.runFrame();
|
||||||
try {
|
|
||||||
emulator.runFrame();
|
|
||||||
} catch (final EmulatorBindings.NativeBindingException e) {
|
|
||||||
this.running = false;
|
|
||||||
emulatorActivity.runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
showAlertDiaglogAndExit(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!emulatorActivity.turboMode) {
|
if (!emulatorActivity.turboMode) {
|
||||||
long currentTime = System.nanoTime();
|
long currentTime = System.nanoTime();
|
||||||
long timePassed = currentTime - startTimer;
|
long timePassed = currentTime - startTimer;
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.mrmichel.rustdroid_emu.ui;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||||
|
import com.google.android.material.snackbar.Snackbar;
|
||||||
|
import com.mrmichel.rustdroid_emu.R;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.appcompat.widget.Toolbar;
|
||||||
|
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
public class RomListActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_rom_list);
|
||||||
|
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||||
|
setSupportActionBar(toolbar);
|
||||||
|
|
||||||
|
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
|
||||||
|
fab.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
|
||||||
|
.setAction("Action", null).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -46,7 +46,7 @@ public class SplashActivity extends AppCompatActivity {
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.main_activity);
|
setContentView(R.layout.splash_activity);
|
||||||
|
|
||||||
if (ContextCompat.checkSelfPermission(this,
|
if (ContextCompat.checkSelfPermission(this,
|
||||||
Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
package com.mrmichel.rustdroid_emu.ui.snapshots;
|
||||||
|
|
||||||
|
import com.mrmichel.rustdroid_emu.core.Snapshot;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* static class to transfer big byte arrays between activities
|
||||||
|
*/
|
||||||
|
public class ChosenSnapshot {
|
||||||
|
|
||||||
|
static Snapshot snapshot;
|
||||||
|
|
||||||
|
public static void setSnapshot(Snapshot snapshot) {
|
||||||
|
ChosenSnapshot.snapshot = snapshot;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Snapshot takeSnapshot() {
|
||||||
|
Snapshot result = ChosenSnapshot.snapshot;
|
||||||
|
ChosenSnapshot.snapshot = null;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,69 @@
|
||||||
|
package com.mrmichel.rustdroid_emu.ui.snapshots;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||||
|
import com.google.android.material.snackbar.Snackbar;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.appcompat.widget.Toolbar;
|
||||||
|
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.AdapterView;
|
||||||
|
import android.widget.GridView;
|
||||||
|
import android.widget.ListView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.mrmichel.rustdroid_emu.R;
|
||||||
|
import com.mrmichel.rustdroid_emu.core.Snapshot;
|
||||||
|
import com.mrmichel.rustdroid_emu.core.SnapshotManager;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class SnapshotActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
private ArrayList<Snapshot> snapshots;
|
||||||
|
public static final String EXTRA_GAME_CODE = "GAME_CODE";
|
||||||
|
|
||||||
|
public void onChosenSnapshot(Snapshot snapshot) {
|
||||||
|
Toast.makeText(this, "loading snapshot", Toast.LENGTH_SHORT).show();
|
||||||
|
Intent intent = new Intent();
|
||||||
|
setResult(RESULT_OK, intent);
|
||||||
|
ChosenSnapshot.setSnapshot(snapshot);
|
||||||
|
SnapshotActivity.this.finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_snapshot);
|
||||||
|
|
||||||
|
SnapshotManager manager = SnapshotManager.getInstance(this);
|
||||||
|
|
||||||
|
String gameCode = getIntent().getStringExtra(EXTRA_GAME_CODE);
|
||||||
|
|
||||||
|
if (gameCode == null) {
|
||||||
|
snapshots = manager.getAllSnapshots();
|
||||||
|
} else {
|
||||||
|
snapshots = manager.getByGameCode(gameCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
SnapshotItemAdapter adapter = new SnapshotItemAdapter(this, snapshots);
|
||||||
|
|
||||||
|
GridView view = findViewById(R.id.gridview_snapshots);
|
||||||
|
view.setAdapter(adapter);
|
||||||
|
view.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||||
|
final Snapshot snapshot = snapshots.get(position);
|
||||||
|
onChosenSnapshot(snapshot);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,66 @@
|
||||||
|
package com.mrmichel.rustdroid_emu.ui.snapshots;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.ImageButton;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
import com.mrmichel.rustdroid_emu.R;
|
||||||
|
import com.mrmichel.rustdroid_emu.core.Snapshot;
|
||||||
|
|
||||||
|
import org.w3c.dom.Text;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class SnapshotItemAdapter extends ArrayAdapter<Snapshot> {
|
||||||
|
|
||||||
|
Context context;
|
||||||
|
ArrayList<Snapshot> items;
|
||||||
|
|
||||||
|
public SnapshotItemAdapter(Context context, ArrayList<Snapshot> items) {
|
||||||
|
super(context, 0, items);
|
||||||
|
this.context = context;
|
||||||
|
this.items = items;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCount() {
|
||||||
|
return items.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getItemId(int position) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
|
||||||
|
Snapshot snapshot = getItem(position);
|
||||||
|
|
||||||
|
if (convertView == null) {
|
||||||
|
convertView = LayoutInflater.from(getContext()).inflate(R.layout.snapshot_item, parent, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
ImageView preview = (ImageView) convertView.findViewById(R.id.imageview_snapshot_preview);
|
||||||
|
preview.setImageBitmap(snapshot.getPreview());
|
||||||
|
|
||||||
|
|
||||||
|
TextView tvTitle = (TextView) convertView.findViewById(R.id.textview_snapshot_title);
|
||||||
|
tvTitle.setText(snapshot.getGameTitle());
|
||||||
|
|
||||||
|
TextView tvTimestamp = (TextView) convertView.findViewById(R.id.textview_snapshot_timestmap);
|
||||||
|
Timestamp timestamp = new Timestamp(snapshot.getTimestamp());
|
||||||
|
tvTimestamp.setText(timestamp.toString());
|
||||||
|
|
||||||
|
return convertView;
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,18 +6,31 @@
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context=".ui.EmulatorActivity">
|
tools:context=".ui.EmulatorActivity">
|
||||||
|
|
||||||
|
|
||||||
<com.google.android.material.appbar.AppBarLayout
|
<com.google.android.material.appbar.AppBarLayout
|
||||||
|
android:id="@+id/app_bar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="@dimen/app_bar_height"
|
||||||
|
android:fitsSystemWindows="true"
|
||||||
android:theme="@style/AppTheme.AppBarOverlay">
|
android:theme="@style/AppTheme.AppBarOverlay">
|
||||||
|
|
||||||
<!-- <androidx.appcompat.widget.Toolbar-->
|
<com.google.android.material.appbar.CollapsingToolbarLayout
|
||||||
<!-- android:id="@+id/toolbar"-->
|
android:id="@+id/toolbar_layout"
|
||||||
<!-- android:layout_width="match_parent"-->
|
android:layout_width="match_parent"
|
||||||
<!-- android:layout_height="?attr/actionBarSize"-->
|
android:layout_height="match_parent"
|
||||||
<!-- android:background="?attr/colorPrimary"-->
|
android:fitsSystemWindows="true"
|
||||||
<!-- app:popupTheme="@style/AppTheme.PopupOverlay" />-->
|
app:contentScrim="?attr/colorPrimary"
|
||||||
|
app:layout_scrollFlags="scroll|exitUntilCollapsed"
|
||||||
|
app:toolbarId="@+id/toolbar">
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.Toolbar
|
||||||
|
android:id="@+id/toolbar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="?attr/actionBarSize"
|
||||||
|
app:layout_collapseMode="pin"
|
||||||
|
app:popupTheme="@style/AppTheme.PopupOverlay" />
|
||||||
|
|
||||||
|
</com.google.android.material.appbar.CollapsingToolbarLayout>
|
||||||
</com.google.android.material.appbar.AppBarLayout>
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
|
|
||||||
<include layout="@layout/content_emulator" />
|
<include layout="@layout/content_emulator" />
|
||||||
|
|
47
AndroidApp/app/src/main/res/layout/activity_rom_list.xml
Normal file
47
AndroidApp/app/src/main/res/layout/activity_rom_list.xml
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.coordinatorlayout.widget.CoordinatorLayout 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:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:fitsSystemWindows="true"
|
||||||
|
tools:context=".ui.RomListActivity">
|
||||||
|
|
||||||
|
<com.google.android.material.appbar.AppBarLayout
|
||||||
|
android:id="@+id/app_bar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="@dimen/app_bar_height"
|
||||||
|
android:fitsSystemWindows="true"
|
||||||
|
android:theme="@style/AppTheme.AppBarOverlay">
|
||||||
|
|
||||||
|
<com.google.android.material.appbar.CollapsingToolbarLayout
|
||||||
|
android:id="@+id/toolbar_layout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:fitsSystemWindows="true"
|
||||||
|
app:contentScrim="?attr/colorPrimary"
|
||||||
|
app:layout_scrollFlags="scroll|exitUntilCollapsed"
|
||||||
|
app:toolbarId="@+id/toolbar">
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.Toolbar
|
||||||
|
android:id="@+id/toolbar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="?attr/actionBarSize"
|
||||||
|
app:layout_collapseMode="pin"
|
||||||
|
app:popupTheme="@style/AppTheme.PopupOverlay" />
|
||||||
|
|
||||||
|
</com.google.android.material.appbar.CollapsingToolbarLayout>
|
||||||
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
|
|
||||||
|
<include layout="@layout/content_rom_list" />
|
||||||
|
|
||||||
|
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||||
|
android:id="@+id/fab"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="@dimen/fab_margin"
|
||||||
|
app:layout_anchor="@id/app_bar"
|
||||||
|
app:layout_anchorGravity="bottom|end"
|
||||||
|
app:srcCompat="@android:drawable/ic_dialog_email" />
|
||||||
|
|
||||||
|
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
59
AndroidApp/app/src/main/res/layout/activity_snapshot.xml
Normal file
59
AndroidApp/app/src/main/res/layout/activity_snapshot.xml
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="#6c45c0"
|
||||||
|
tools:context=".ui.snapshots.SnapshotActivity">
|
||||||
|
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/textView"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="126dp"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:layout_marginEnd="126dp"
|
||||||
|
android:gravity="center"
|
||||||
|
android:text="Choose snapshot to load"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Display1"
|
||||||
|
android:textSize="14sp"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:typeface="monospace"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/edittext_snapshot_filter" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/edittext_snapshot_filter"
|
||||||
|
style="@style/Widget.AppCompat.EditText"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:ems="10"
|
||||||
|
android:hint="Search.."
|
||||||
|
android:inputType="textFilter|textPersonName"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<GridView
|
||||||
|
android:id="@+id/gridview_snapshots"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:layout_marginEnd="8dp"
|
||||||
|
android:gravity="center"
|
||||||
|
android:numColumns="auto_fit"
|
||||||
|
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/textView"
|
||||||
|
tools:context=".ui.snapshots.SnapshotActivity"
|
||||||
|
tools:showIn="@layout/activity_snapshot">
|
||||||
|
|
||||||
|
</GridView>
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -28,7 +28,7 @@
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintHorizontal_bias="0.517"
|
app:layout_constraintHorizontal_bias="0.517"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/bSave" />
|
app:layout_constraintTop_toBottomOf="@+id/bSnapshotSave" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/buttonB"
|
android:id="@+id/buttonB"
|
||||||
|
@ -129,26 +129,32 @@
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/bSave"
|
android:id="@+id/bSnapshotSave"
|
||||||
|
style="@style/Widget.AppCompat.Button.Small"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="16dp"
|
android:layout_marginTop="16dp"
|
||||||
android:layout_marginEnd="32dp"
|
android:layout_marginEnd="4dp"
|
||||||
android:text="Save"
|
android:onClick="onSaveSnapshot"
|
||||||
|
android:text="@string/action_save_snapshot"
|
||||||
app:layout_constraintEnd_toStartOf="@+id/bRestore"
|
app:layout_constraintEnd_toStartOf="@+id/bRestore"
|
||||||
|
app:layout_constraintStart_toEndOf="@+id/bLoadRom"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/bRestore"
|
android:id="@+id/bRestore"
|
||||||
|
style="@style/Widget.AppCompat.Button.Small"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="16dp"
|
android:layout_marginTop="16dp"
|
||||||
android:layout_marginEnd="16dp"
|
android:layout_marginEnd="16dp"
|
||||||
android:layout_marginBottom="12dp"
|
android:layout_marginBottom="12dp"
|
||||||
android:text="Button"
|
android:onClick="onViewSnapshots"
|
||||||
|
android:text="@string/action_view_snapshot"
|
||||||
app:layout_constraintBottom_toTopOf="@+id/gbaMockImageView"
|
app:layout_constraintBottom_toTopOf="@+id/gbaMockImageView"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintVertical_bias="0.0" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/tvFPS"
|
android:id="@+id/tvFPS"
|
||||||
|
|
17
AndroidApp/app/src/main/res/layout/content_rom_list.xml
Normal file
17
AndroidApp/app/src/main/res/layout/content_rom_list.xml
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.core.widget.NestedScrollView 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:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||||
|
tools:context=".ui.RomListActivity"
|
||||||
|
tools:showIn="@layout/activity_rom_list">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="@dimen/text_margin"
|
||||||
|
android:text="@string/large_text" />
|
||||||
|
|
||||||
|
</androidx.core.widget.NestedScrollView>
|
38
AndroidApp/app/src/main/res/layout/snapshot_item.xml
Normal file
38
AndroidApp/app/src/main/res/layout/snapshot_item.xml
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:gravity="center"
|
||||||
|
>
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/imageview_snapshot_preview"
|
||||||
|
android:layout_width="180dp"
|
||||||
|
android:layout_height="160dp"
|
||||||
|
android:scaleType="centerCrop"
|
||||||
|
app:srcCompat="@drawable/icon" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/textview_snapshot_title"
|
||||||
|
android:layout_width="180dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Cool Game - III"
|
||||||
|
android:gravity="center_horizontal"
|
||||||
|
android:paddingTop="4dp"
|
||||||
|
android:paddingLeft="8dp"
|
||||||
|
android:paddingRight="8dp"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:textSize="12sp"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/textview_snapshot_timestmap"
|
||||||
|
android:layout_width="180dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="1.1.2020"
|
||||||
|
android:gravity="center_horizontal"
|
||||||
|
android:textSize="12sp"
|
||||||
|
/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
20
AndroidApp/app/src/main/res/menu/menu_emulator.xml
Normal file
20
AndroidApp/app/src/main/res/menu/menu_emulator.xml
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
<menu 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"
|
||||||
|
tools:context="com.mrmichel.rustdroid_emu.ui.RomListActivity">
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_settings"
|
||||||
|
android:orderInCategory="100"
|
||||||
|
android:title="@string/action_settings"
|
||||||
|
app:showAsAction="never" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_save_snapshot"
|
||||||
|
android:icon="@android:drawable/ic_input_add"
|
||||||
|
android:orderInCategory="101"
|
||||||
|
android:title="@string/action_save_snapshot"
|
||||||
|
app:showAsAction="withText" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_view_snapshots"
|
||||||
|
android:orderInCategory="102"
|
||||||
|
android:title="@string/action_view_snapshot" />
|
||||||
|
</menu>
|
10
AndroidApp/app/src/main/res/menu/menu_rom_list.xml
Normal file
10
AndroidApp/app/src/main/res/menu/menu_rom_list.xml
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<menu 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"
|
||||||
|
tools:context="com.mrmichel.rustdroid_emu.ui.RomListActivity">
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_settings"
|
||||||
|
android:orderInCategory="100"
|
||||||
|
android:title="@string/action_settings"
|
||||||
|
app:showAsAction="never" />
|
||||||
|
</menu>
|
10
AndroidApp/app/src/main/res/menu/menu_snapshot.xml
Normal file
10
AndroidApp/app/src/main/res/menu/menu_snapshot.xml
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<menu 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"
|
||||||
|
tools:context="com.mrmichel.rustdroid_emu.ui.snapshots.SnapshotActivity">
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_settings"
|
||||||
|
android:orderInCategory="100"
|
||||||
|
android:title="@string/action_settings"
|
||||||
|
app:showAsAction="never" />
|
||||||
|
</menu>
|
|
@ -1,3 +1,5 @@
|
||||||
<resources>
|
<resources>
|
||||||
<dimen name="fab_margin">16dp</dimen>
|
<dimen name="fab_margin">16dp</dimen>
|
||||||
|
<dimen name="app_bar_height">180dp</dimen>
|
||||||
|
<dimen name="text_margin">16dp</dimen>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -1,4 +1,99 @@
|
||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">RustdroidAdvance</string>
|
<string name="app_name">RustdroidAdvance</string>
|
||||||
<string name="title_activity_emulator">RustdroidAdvance</string>
|
<string name="title_activity_emulator">RustdroidAdvance</string>
|
||||||
|
<string name="title_activity_rom_list">Roms</string>
|
||||||
|
<string name="large_text">
|
||||||
|
"Material is the metaphor.\n\n"
|
||||||
|
|
||||||
|
"A material metaphor is the unifying theory of a rationalized space and a system of motion."
|
||||||
|
"The material is grounded in tactile reality, inspired by the study of paper and ink, yet "
|
||||||
|
"technologically advanced and open to imagination and magic.\n"
|
||||||
|
"Surfaces and edges of the material provide visual cues that are grounded in reality. The "
|
||||||
|
"use of familiar tactile attributes helps users quickly understand affordances. Yet the "
|
||||||
|
"flexibility of the material creates new affordances that supercede those in the physical "
|
||||||
|
"world, without breaking the rules of physics.\n"
|
||||||
|
"The fundamentals of light, surface, and movement are key to conveying how objects move, "
|
||||||
|
"interact, and exist in space and in relation to each other. Realistic lighting shows "
|
||||||
|
"seams, divides space, and indicates moving parts.\n\n"
|
||||||
|
|
||||||
|
"Bold, graphic, intentional.\n\n"
|
||||||
|
|
||||||
|
"The foundational elements of print based design typography, grids, space, scale, color, "
|
||||||
|
"and use of imagery guide visual treatments. These elements do far more than please the "
|
||||||
|
"eye. They create hierarchy, meaning, and focus. Deliberate color choices, edge to edge "
|
||||||
|
"imagery, large scale typography, and intentional white space create a bold and graphic "
|
||||||
|
"interface that immerse the user in the experience.\n"
|
||||||
|
"An emphasis on user actions makes core functionality immediately apparent and provides "
|
||||||
|
"waypoints for the user.\n\n"
|
||||||
|
|
||||||
|
"Motion provides meaning.\n\n"
|
||||||
|
|
||||||
|
"Motion respects and reinforces the user as the prime mover. Primary user actions are "
|
||||||
|
"inflection points that initiate motion, transforming the whole design.\n"
|
||||||
|
"All action takes place in a single environment. Objects are presented to the user without "
|
||||||
|
"breaking the continuity of experience even as they transform and reorganize.\n"
|
||||||
|
"Motion is meaningful and appropriate, serving to focus attention and maintain continuity. "
|
||||||
|
"Feedback is subtle yet clear. Transitions are efficient yet coherent.\n\n"
|
||||||
|
|
||||||
|
"3D world.\n\n"
|
||||||
|
|
||||||
|
"The material environment is a 3D space, which means all objects have x, y, and z "
|
||||||
|
"dimensions. The z-axis is perpendicularly aligned to the plane of the display, with the "
|
||||||
|
"positive z-axis extending towards the viewer. Every sheet of material occupies a single "
|
||||||
|
"position along the z-axis and has a standard 1dp thickness.\n"
|
||||||
|
"On the web, the z-axis is used for layering and not for perspective. The 3D world is "
|
||||||
|
"emulated by manipulating the y-axis.\n\n"
|
||||||
|
|
||||||
|
"Light and shadow.\n\n"
|
||||||
|
|
||||||
|
"Within the material environment, virtual lights illuminate the scene. Key lights create "
|
||||||
|
"directional shadows, while ambient light creates soft shadows from all angles.\n"
|
||||||
|
"Shadows in the material environment are cast by these two light sources. In Android "
|
||||||
|
"development, shadows occur when light sources are blocked by sheets of material at "
|
||||||
|
"various positions along the z-axis. On the web, shadows are depicted by manipulating the "
|
||||||
|
"y-axis only. The following example shows the card with a height of 6dp.\n\n"
|
||||||
|
|
||||||
|
"Resting elevation.\n\n"
|
||||||
|
|
||||||
|
"All material objects, regardless of size, have a resting elevation, or default elevation "
|
||||||
|
"that does not change. If an object changes elevation, it should return to its resting "
|
||||||
|
"elevation as soon as possible.\n\n"
|
||||||
|
|
||||||
|
"Component elevations.\n\n"
|
||||||
|
|
||||||
|
"The resting elevation for a component type is consistent across apps (e.g., FAB elevation "
|
||||||
|
"does not vary from 6dp in one app to 16dp in another app).\n"
|
||||||
|
"Components may have different resting elevations across platforms, depending on the depth "
|
||||||
|
"of the environment (e.g., TV has a greater depth than mobile or desktop).\n\n"
|
||||||
|
|
||||||
|
"Responsive elevation and dynamic elevation offsets.\n\n"
|
||||||
|
|
||||||
|
"Some component types have responsive elevation, meaning they change elevation in response "
|
||||||
|
"to user input (e.g., normal, focused, and pressed) or system events. These elevation "
|
||||||
|
"changes are consistently implemented using dynamic elevation offsets.\n"
|
||||||
|
"Dynamic elevation offsets are the goal elevation that a component moves towards, relative "
|
||||||
|
"to the component’s resting state. They ensure that elevation changes are consistent "
|
||||||
|
"across actions and component types. For example, all components that lift on press have "
|
||||||
|
"the same elevation change relative to their resting elevation.\n"
|
||||||
|
"Once the input event is completed or cancelled, the component will return to its resting "
|
||||||
|
"elevation.\n\n"
|
||||||
|
|
||||||
|
"Avoiding elevation interference.\n\n"
|
||||||
|
|
||||||
|
"Components with responsive elevations may encounter other components as they move between "
|
||||||
|
"their resting elevations and dynamic elevation offsets. Because material cannot pass "
|
||||||
|
"through other material, components avoid interfering with one another any number of ways, "
|
||||||
|
"whether on a per component basis or using the entire app layout.\n"
|
||||||
|
"On a component level, components can move or be removed before they cause interference. "
|
||||||
|
"For example, a floating action button (FAB) can disappear or move off screen before a "
|
||||||
|
"user picks up a card, or it can move if a snackbar appears.\n"
|
||||||
|
"On the layout level, design your app layout to minimize opportunities for interference. "
|
||||||
|
"For example, position the FAB to one side of stream of a cards so the FAB won’t interfere "
|
||||||
|
"when a user tries to pick up one of cards.\n\n"
|
||||||
|
</string>
|
||||||
|
<string name="action_settings">Settings</string>
|
||||||
|
<string name="action_save_snapshot">Save Snapshot</string>
|
||||||
|
<string name="action_view_snapshot">View Snapshots</string>
|
||||||
|
|
||||||
|
<string name="title_activity_snapshot">Snapshot Manager</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Reference in a new issue