mirror of
https://github.com/libretro/Play-.git
synced 2025-02-12 20:29:11 +00:00
Use PreferenceActivity on Android for preference edition.
This commit is contained in:
parent
da79ed744c
commit
4141a5b2de
@ -1,6 +1,5 @@
|
|||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <android/log.h>
|
|
||||||
#include <android/native_window.h>
|
#include <android/native_window.h>
|
||||||
#include <android/native_window_jni.h>
|
#include <android/native_window_jni.h>
|
||||||
#include "PathUtils.h"
|
#include "PathUtils.h"
|
||||||
@ -8,30 +7,13 @@
|
|||||||
#include "../PS2VM.h"
|
#include "../PS2VM.h"
|
||||||
#include "../PS2VM_Preferences.h"
|
#include "../PS2VM_Preferences.h"
|
||||||
#include "../gs/GSH_Null.h"
|
#include "../gs/GSH_Null.h"
|
||||||
|
#include "NativeShared.h"
|
||||||
#include "GSH_OpenGLAndroid.h"
|
#include "GSH_OpenGLAndroid.h"
|
||||||
#include "PH_Android.h"
|
#include "PH_Android.h"
|
||||||
#include "StatsManager.h"
|
#include "StatsManager.h"
|
||||||
|
|
||||||
#define LOG_NAME "Play!"
|
|
||||||
|
|
||||||
CPS2VM* g_virtualMachine = nullptr;
|
CPS2VM* g_virtualMachine = nullptr;
|
||||||
|
|
||||||
void Log_Print(const char* fmt, ...)
|
|
||||||
{
|
|
||||||
va_list ap;
|
|
||||||
va_start(ap, fmt);
|
|
||||||
__android_log_vprint(ANDROID_LOG_INFO, LOG_NAME, fmt, ap);
|
|
||||||
va_end(ap);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string GetStringFromJstring(JNIEnv* env, jstring javaString)
|
|
||||||
{
|
|
||||||
auto nativeString = env->GetStringUTFChars(javaString, JNI_FALSE);
|
|
||||||
std::string result(nativeString);
|
|
||||||
env->ReleaseStringUTFChars(javaString, nativeString);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" JNIEXPORT void JNICALL Java_com_virtualapplications_play_NativeInterop_setFilesDirPath(JNIEnv* env, jobject obj, jstring dirPathString)
|
extern "C" JNIEXPORT void JNICALL Java_com_virtualapplications_play_NativeInterop_setFilesDirPath(JNIEnv* env, jobject obj, jstring dirPathString)
|
||||||
{
|
{
|
||||||
auto dirPath = env->GetStringUTFChars(dirPathString, 0);
|
auto dirPath = env->GetStringUTFChars(dirPathString, 0);
|
||||||
|
21
Source/ui_android/NativeShared.cpp
Normal file
21
Source/ui_android/NativeShared.cpp
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#include <jni.h>
|
||||||
|
#include <android/log.h>
|
||||||
|
#include "NativeShared.h"
|
||||||
|
|
||||||
|
#define LOG_NAME "Play!"
|
||||||
|
|
||||||
|
void Log_Print(const char* fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
__android_log_vprint(ANDROID_LOG_INFO, LOG_NAME, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string GetStringFromJstring(JNIEnv* env, jstring javaString)
|
||||||
|
{
|
||||||
|
auto nativeString = env->GetStringUTFChars(javaString, JNI_FALSE);
|
||||||
|
std::string result(nativeString);
|
||||||
|
env->ReleaseStringUTFChars(javaString, nativeString);
|
||||||
|
return result;
|
||||||
|
}
|
6
Source/ui_android/NativeShared.h
Normal file
6
Source/ui_android/NativeShared.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
void Log_Print(const char* fmt, ...);
|
||||||
|
std::string GetStringFromJstring(JNIEnv*, jstring);
|
44
Source/ui_android/SettingsManager.cpp
Normal file
44
Source/ui_android/SettingsManager.cpp
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#include <jni.h>
|
||||||
|
#include "SettingsManager.h"
|
||||||
|
#include "NativeShared.h"
|
||||||
|
#include "../AppConfig.h"
|
||||||
|
|
||||||
|
void CSettingsManager::Save()
|
||||||
|
{
|
||||||
|
CAppConfig::GetInstance().Save();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSettingsManager::RegisterPreferenceBoolean(const std::string& name, bool value)
|
||||||
|
{
|
||||||
|
CAppConfig::GetInstance().RegisterPreferenceBoolean(name.c_str(), value);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CSettingsManager::GetPreferenceBoolean(const std::string& name)
|
||||||
|
{
|
||||||
|
return CAppConfig::GetInstance().GetPreferenceBoolean(name.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSettingsManager::SetPreferenceBoolean(const std::string& name, bool value)
|
||||||
|
{
|
||||||
|
CAppConfig::GetInstance().SetPreferenceBoolean(name.c_str(), value);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" JNIEXPORT void JNICALL Java_com_virtualapplications_play_SettingsManager_save(JNIEnv* env, jobject obj)
|
||||||
|
{
|
||||||
|
CSettingsManager::GetInstance().Save();
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" JNIEXPORT void JNICALL Java_com_virtualapplications_play_SettingsManager_registerPreferenceBoolean(JNIEnv* env, jobject obj, jstring name, jboolean value)
|
||||||
|
{
|
||||||
|
CSettingsManager::GetInstance().RegisterPreferenceBoolean(GetStringFromJstring(env, name), value == JNI_TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" JNIEXPORT jboolean JNICALL Java_com_virtualapplications_play_SettingsManager_getPreferenceBoolean(JNIEnv* env, jobject obj, jstring name)
|
||||||
|
{
|
||||||
|
return CSettingsManager::GetInstance().GetPreferenceBoolean(GetStringFromJstring(env, name));
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" JNIEXPORT void JNICALL Java_com_virtualapplications_play_SettingsManager_setPreferenceBoolean(JNIEnv* env, jobject obj, jstring name, jboolean value)
|
||||||
|
{
|
||||||
|
CSettingsManager::GetInstance().SetPreferenceBoolean(GetStringFromJstring(env, name), value == JNI_TRUE);
|
||||||
|
}
|
16
Source/ui_android/SettingsManager.h
Normal file
16
Source/ui_android/SettingsManager.h
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Singleton.h"
|
||||||
|
|
||||||
|
class CSettingsManager : public CSingleton<CSettingsManager>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void Save();
|
||||||
|
|
||||||
|
void RegisterPreferenceBoolean(const std::string&, bool);
|
||||||
|
bool GetPreferenceBoolean(const std::string&);
|
||||||
|
void SetPreferenceBoolean(const std::string&, bool);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
};
|
@ -10,11 +10,18 @@ import java.util.*;
|
|||||||
|
|
||||||
public class EmulatorActivity extends Activity
|
public class EmulatorActivity extends Activity
|
||||||
{
|
{
|
||||||
|
private static final String PREFERENCE_UI_SHOWFPS = "ui.showfps";
|
||||||
|
|
||||||
private SurfaceView _renderView;
|
private SurfaceView _renderView;
|
||||||
private TextView _statsTextView;
|
private TextView _statsTextView;
|
||||||
private Timer _statsTimer = new Timer();
|
private Timer _statsTimer = new Timer();
|
||||||
private Handler _statsTimerHandler;
|
private Handler _statsTimerHandler;
|
||||||
|
|
||||||
|
public static void RegisterPreferences()
|
||||||
|
{
|
||||||
|
SettingsManager.registerPreferenceBoolean(PREFERENCE_UI_SHOWFPS, false);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState)
|
protected void onCreate(Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
@ -35,8 +42,7 @@ public class EmulatorActivity extends Activity
|
|||||||
SurfaceHolder holder = _renderView.getHolder();
|
SurfaceHolder holder = _renderView.getHolder();
|
||||||
holder.addCallback(new SurfaceCallback());
|
holder.addCallback(new SurfaceCallback());
|
||||||
|
|
||||||
final SharedPreferences _preferences = getSharedPreferences("prefs", MODE_PRIVATE);
|
if(SettingsManager.getPreferenceBoolean(PREFERENCE_UI_SHOWFPS))
|
||||||
if (_preferences.getBoolean("fpsValue", false))
|
|
||||||
{
|
{
|
||||||
_statsTextView = (TextView)findViewById(R.id.emulator_stats);
|
_statsTextView = (TextView)findViewById(R.id.emulator_stats);
|
||||||
setupStatsTimer();
|
setupStatsTimer();
|
||||||
|
@ -30,10 +30,11 @@ public class MainActivity extends Activity
|
|||||||
|
|
||||||
setContentView(R.layout.main);
|
setContentView(R.layout.main);
|
||||||
|
|
||||||
_preferences = getSharedPreferences("prefs", MODE_PRIVATE);
|
|
||||||
|
|
||||||
File filesDir = getFilesDir();
|
File filesDir = getFilesDir();
|
||||||
NativeInterop.setFilesDirPath(Environment.getExternalStorageDirectory().getAbsolutePath());
|
NativeInterop.setFilesDirPath(Environment.getExternalStorageDirectory().getAbsolutePath());
|
||||||
|
|
||||||
|
_preferences = getSharedPreferences("prefs", MODE_PRIVATE);
|
||||||
|
EmulatorActivity.RegisterPreferences();
|
||||||
|
|
||||||
if(!NativeInterop.isVirtualMachineCreated())
|
if(!NativeInterop.isVirtualMachineCreated())
|
||||||
{
|
{
|
||||||
@ -93,6 +94,12 @@ public class MainActivity extends Activity
|
|||||||
dialog.show();
|
dialog.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void displaySettingsActivity()
|
||||||
|
{
|
||||||
|
Intent intent = new Intent(getApplicationContext(), SettingsActivity.class);
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
private void displayAboutDialog()
|
private void displayAboutDialog()
|
||||||
{
|
{
|
||||||
long buildDate = getBuildDate(this);
|
long buildDate = getBuildDate(this);
|
||||||
@ -101,23 +108,6 @@ public class MainActivity extends Activity
|
|||||||
displaySimpleMessage("About Play!", aboutMessage);
|
displaySimpleMessage("About Play!", aboutMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setFps(MenuItem item)
|
|
||||||
{
|
|
||||||
SharedPreferences.Editor preferencesEditor = _preferences.edit();
|
|
||||||
|
|
||||||
if (item.isChecked())
|
|
||||||
{
|
|
||||||
preferencesEditor.putBoolean("fpsValue", false);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
preferencesEditor.putBoolean("fpsValue", true);
|
|
||||||
}
|
|
||||||
preferencesEditor.commit();
|
|
||||||
|
|
||||||
item.setChecked(_preferences.getBoolean("fpsValue", false));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu)
|
public boolean onCreateOptionsMenu(Menu menu)
|
||||||
{
|
{
|
||||||
@ -126,24 +116,17 @@ public class MainActivity extends Activity
|
|||||||
return super.onCreateOptionsMenu(menu);
|
return super.onCreateOptionsMenu(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onPrepareOptionsMenu(Menu menu)
|
|
||||||
{
|
|
||||||
menu.getItem(1).setChecked(_preferences.getBoolean("fpsValue", false));
|
|
||||||
return super.onPrepareOptionsMenu(menu);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item)
|
public boolean onOptionsItemSelected(MenuItem item)
|
||||||
{
|
{
|
||||||
switch(item.getItemId())
|
switch(item.getItemId())
|
||||||
{
|
{
|
||||||
|
case R.id.main_menu_settings:
|
||||||
|
displaySettingsActivity();
|
||||||
|
return true;
|
||||||
case R.id.main_menu_about:
|
case R.id.main_menu_about:
|
||||||
displayAboutDialog();
|
displayAboutDialog();
|
||||||
return true;
|
return true;
|
||||||
case R.id.main_menu_fps:
|
|
||||||
setFps(item);
|
|
||||||
return true;
|
|
||||||
default:
|
default:
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,67 @@
|
|||||||
|
package com.virtualapplications.play;
|
||||||
|
|
||||||
|
import android.os.*;
|
||||||
|
import android.preference.*;
|
||||||
|
import android.widget.*;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class SettingsActivity extends PreferenceActivity
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onDestroy()
|
||||||
|
{
|
||||||
|
super.onDestroy();
|
||||||
|
SettingsManager.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBuildHeaders(List<Header> target)
|
||||||
|
{
|
||||||
|
loadHeadersFromResource(R.xml.settings_headers, target);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isValidFragment(String fragmentName)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class GeneralSettingsFragment extends PreferenceFragment
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState)
|
||||||
|
{
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
addPreferencesFromResource(R.xml.settings_general_fragment);
|
||||||
|
|
||||||
|
PreferenceGroup prefGroup = getPreferenceScreen();
|
||||||
|
for(int i = 0; i < prefGroup.getPreferenceCount(); i++)
|
||||||
|
{
|
||||||
|
Preference pref = prefGroup.getPreference(i);
|
||||||
|
if(pref instanceof CheckBoxPreference)
|
||||||
|
{
|
||||||
|
CheckBoxPreference checkBoxPref = (CheckBoxPreference)pref;
|
||||||
|
checkBoxPref.setChecked(SettingsManager.getPreferenceBoolean(checkBoxPref.getKey()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy()
|
||||||
|
{
|
||||||
|
PreferenceGroup prefGroup = getPreferenceScreen();
|
||||||
|
for(int i = 0; i < prefGroup.getPreferenceCount(); i++)
|
||||||
|
{
|
||||||
|
Preference pref = prefGroup.getPreference(i);
|
||||||
|
if(pref instanceof CheckBoxPreference)
|
||||||
|
{
|
||||||
|
CheckBoxPreference checkBoxPref = (CheckBoxPreference)pref;
|
||||||
|
SettingsManager.setPreferenceBoolean(checkBoxPref.getKey(), checkBoxPref.isChecked());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
super.onDestroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package com.virtualapplications.play;
|
||||||
|
|
||||||
|
public class SettingsManager
|
||||||
|
{
|
||||||
|
static
|
||||||
|
{
|
||||||
|
System.loadLibrary("Play");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static native void save();
|
||||||
|
|
||||||
|
public static native void registerPreferenceBoolean(String name, boolean defaultValue);
|
||||||
|
public static native boolean getPreferenceBoolean(String name);
|
||||||
|
public static native void setPreferenceBoolean(String name, boolean value);
|
||||||
|
}
|
@ -23,5 +23,9 @@
|
|||||||
android:configChanges="orientation|locale|keyboard|keyboardHidden|navigation"
|
android:configChanges="orientation|locale|keyboard|keyboardHidden|navigation"
|
||||||
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
|
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
|
||||||
</activity>
|
</activity>
|
||||||
|
<activity
|
||||||
|
android:name=".SettingsActivity"
|
||||||
|
android:configChanges="orientation|locale|keyboard|keyboardHidden|navigation">
|
||||||
|
</activity>
|
||||||
</application>
|
</application>
|
||||||
</manifest>
|
</manifest>
|
||||||
|
@ -164,7 +164,9 @@ LOCAL_SRC_FILES := ../../Source/AppConfig.cpp \
|
|||||||
../../Source/ui_android/GSH_OpenGLAndroid.cpp \
|
../../Source/ui_android/GSH_OpenGLAndroid.cpp \
|
||||||
../../Source/ui_android/InputManager.cpp \
|
../../Source/ui_android/InputManager.cpp \
|
||||||
../../Source/ui_android/NativeInterop.cpp \
|
../../Source/ui_android/NativeInterop.cpp \
|
||||||
|
../../Source/ui_android/NativeShared.cpp \
|
||||||
../../Source/ui_android/PH_Android.cpp \
|
../../Source/ui_android/PH_Android.cpp \
|
||||||
|
../../Source/ui_android/SettingsManager.cpp \
|
||||||
../../Source/ui_android/StatsManager.cpp \
|
../../Source/ui_android/StatsManager.cpp \
|
||||||
../../Source/Utils.cpp
|
../../Source/Utils.cpp
|
||||||
LOCAL_CFLAGS := -mcpu=cortex-a7 -Wno-extern-c-compat -D_IOP_EMULATE_MODULES -DDISABLE_LOGGING -DGLES_COMPATIBILITY
|
LOCAL_CFLAGS := -mcpu=cortex-a7 -Wno-extern-c-compat -D_IOP_EMULATE_MODULES -DDISABLE_LOGGING -DGLES_COMPATIBILITY
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||||
|
<item
|
||||||
|
android:id="@+id/main_menu_settings"
|
||||||
|
android:title="@string/main_menu_settings"
|
||||||
|
android:showAsAction="never"
|
||||||
|
/>
|
||||||
<item
|
<item
|
||||||
android:id="@+id/main_menu_about"
|
android:id="@+id/main_menu_about"
|
||||||
android:title="@string/main_menu_about"
|
android:title="@string/main_menu_about"
|
||||||
android:showAsAction="never"
|
android:showAsAction="never"
|
||||||
/>
|
/>
|
||||||
<item
|
|
||||||
android:id="@+id/main_menu_fps"
|
|
||||||
android:title="@string/main_menu_fps"
|
|
||||||
android:showAsAction="never"
|
|
||||||
android:checkable="true"
|
|
||||||
/>
|
|
||||||
</menu>
|
</menu>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">Play!</string>
|
<string name="app_name">Play!</string>
|
||||||
|
<string name="main_menu_settings">Settings</string>
|
||||||
<string name="main_menu_about">About</string>
|
<string name="main_menu_about">About</string>
|
||||||
<string name="main_menu_fps">Enable FPS</string>
|
|
||||||
</resources>
|
</resources>
|
||||||
|
8
build_android/res/xml/settings_general_fragment.xml
Normal file
8
build_android/res/xml/settings_general_fragment.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:key="ui.showfps"
|
||||||
|
android:title="Display F/S & DC/F"
|
||||||
|
android:summary="Show "Frames Per Second" and "Draw Calls Per Frame" on screen."
|
||||||
|
android:persistent="false"
|
||||||
|
/>
|
||||||
|
</PreferenceScreen>
|
6
build_android/res/xml/settings_headers.xml
Normal file
6
build_android/res/xml/settings_headers.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<preference-headers xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<header
|
||||||
|
android:fragment="com.virtualapplications.play.SettingsActivity$GeneralSettingsFragment"
|
||||||
|
android:title="General Settings"
|
||||||
|
/>
|
||||||
|
</preference-headers>
|
Loading…
x
Reference in New Issue
Block a user