Browse Source

Android: minor fixes for settings

1. Added the missing load/save operations for 'stereo' item
2. Adjusted the 'default' button to use true defaults
3. Added a new 'reset' button to discard current changes
4. Use 'GridLayout' for containing bottom buttons
LouYihua 7 years ago
parent
commit
71b4c58ee0

+ 1 - 0
android/app/build.gradle

@@ -48,5 +48,6 @@ dependencies {
         exclude group: 'com.android.support', module: 'support-annotations'
     })
     compile 'com.android.support:appcompat-v7:25.3.1'
+    compile 'com.android.support:gridlayout-v7:25.3.1'
     compile 'com.android.support:design:25.3.1'
 }

+ 9 - 9
android/app/src/main/cpp/android_jni.cpp

@@ -109,40 +109,40 @@ JNIEXPORT jboolean JNICALL Java_io_github_sdlpal_SettingsActivity_saveConfigFile
 /*
  * Class:     io_github_sdlpal_SettingsActivity
  * Method:    getConfigBoolean
- * Signature: (Ljava/lang/String;)Z
+ * Signature: (Ljava/lang/String;Z)Z
  */
 EXTERN_C_LINKAGE
-JNIEXPORT jboolean JNICALL Java_io_github_sdlpal_SettingsActivity_getConfigBoolean(JNIEnv *env, jclass cls, jstring j_str)
+JNIEXPORT jboolean JNICALL Java_io_github_sdlpal_SettingsActivity_getConfigBoolean(JNIEnv *env, jclass cls, jstring j_str, jboolean defval)
 {
     ConfigValue value;
     std::string name = jstring_to_utf8(env, j_str);
-    return PAL_GetConfigItem(name.c_str(), &value) ? value.bValue : JNI_FALSE;
+    return PAL_GetConfigItem(name.c_str(), &value, defval) ? value.bValue : JNI_FALSE;
 }
 
 /*
  * Class:     io_github_sdlpal_SettingsActivity
  * Method:    getConfigInt
- * Signature: (Ljava/lang/String;)I
+ * Signature: (Ljava/lang/String;Z)I
  */
 EXTERN_C_LINKAGE
-JNIEXPORT int JNICALL Java_io_github_sdlpal_SettingsActivity_getConfigInt(JNIEnv *env, jclass cls, jstring j_str)
+JNIEXPORT int JNICALL Java_io_github_sdlpal_SettingsActivity_getConfigInt(JNIEnv *env, jclass cls, jstring j_str, jboolean defval)
 {
     ConfigValue value;
     std::string name = jstring_to_utf8(env, j_str);
-    return PAL_GetConfigItem(name.c_str(), &value) ? value.iValue : JNI_FALSE;
+    return PAL_GetConfigItem(name.c_str(), &value, defval) ? value.iValue : JNI_FALSE;
 }
 
 /*
  * Class:     io_github_sdlpal_SettingsActivity
  * Method:    getConfigString
- * Signature: (Ljava/lang/String;)ILjava/lang/String;
+ * Signature: (Ljava/lang/String;Z)ILjava/lang/String;
  */
 EXTERN_C_LINKAGE
-JNIEXPORT jstring JNICALL Java_io_github_sdlpal_SettingsActivity_getConfigString(JNIEnv *env, jclass cls, jstring j_str)
+JNIEXPORT jstring JNICALL Java_io_github_sdlpal_SettingsActivity_getConfigString(JNIEnv *env, jclass cls, jstring j_str, jboolean defval)
 {
     ConfigValue value;
     std::string name = jstring_to_utf8(env, j_str);
-    return PAL_GetConfigItem(name.c_str(), &value) ? env->NewStringUTF(value.sValue) : nullptr;
+    return PAL_GetConfigItem(name.c_str(), &value, defval) ? env->NewStringUTF(value.sValue) : nullptr;
 }
 
 /*

+ 2 - 2
android/app/src/main/java/io/github/sdlpal/PalActivity.java

@@ -40,9 +40,9 @@ public class PalActivity extends SDLActivity {
         String cachePath = getApplicationContext().getCacheDir().getPath();
         String sdcardState = Environment.getExternalStorageState();
         if (sdcardState.equals(Environment.MEDIA_MOUNTED)){
-            setAppPath(Environment.getExternalStorageDirectory().getPath() + "/sdlpal", dataPath, cachePath);
+            setAppPath(Environment.getExternalStorageDirectory().getPath() + "/sdlpal/", dataPath, cachePath);
         } else {
-            setAppPath("/sdcard/sdlpal", dataPath, cachePath);
+            setAppPath("/sdcard/sdlpal/", dataPath, cachePath);
         }
 
         DisplayMetrics metrics = new DisplayMetrics();

+ 65 - 22
android/app/src/main/java/io/github/sdlpal/SettingsActivity.java

@@ -2,6 +2,7 @@ package io.github.sdlpal;
 
 import android.content.DialogInterface;
 import android.os.Bundle;
+import android.os.Environment;
 import android.support.v7.app.AppCompatActivity;
 import android.support.v7.widget.AppCompatSpinner;
 import android.support.v7.widget.SwitchCompat;
@@ -18,9 +19,9 @@ public class SettingsActivity extends AppCompatActivity {
 
     public static native boolean loadConfigFile();
     public static native boolean saveConfigFile();
-    public static native boolean getConfigBoolean(String item);
-    public static native int getConfigInt(String item);
-    public static native String getConfigString(String item);
+    public static native boolean getConfigBoolean(String item, boolean defval);
+    public static native int getConfigInt(String item, boolean defval);
+    public static native String getConfigString(String item, boolean defval);
     public static native boolean setConfigBoolean(String item, boolean value);
     public static native boolean setConfigInt(String item, int value);
     public static native boolean setConfigString(String item, String value);
@@ -89,6 +90,13 @@ public class SettingsActivity extends AppCompatActivity {
             }
         });
 
+        findViewById(R.id.btnReset).setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View view) {
+                resetConfigs();
+            }
+        });
+
         findViewById(R.id.btnFinish).setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
@@ -109,7 +117,7 @@ public class SettingsActivity extends AppCompatActivity {
             }
         });
 
-        setDefaults();
+        resetConfigs();
 
         if (PalActivity.crashed) {
             AlertDialog.Builder builder = new AlertDialog.Builder(this);
@@ -142,33 +150,67 @@ public class SettingsActivity extends AppCompatActivity {
     }
 
     protected void setDefaults() {
+        String sdcardState = Environment.getExternalStorageState();
+
+        findViewById(R.id.edLangFile).setVisibility(View.GONE);
+        findViewById(R.id.layoutOPL).setVisibility(View.VISIBLE);
+
+        ((SeekBar)findViewById(R.id.sbMusVol)).setProgress(getConfigInt(MusicVolume, true));
+        ((SeekBar)findViewById(R.id.sbSFXVol)).setProgress(getConfigInt(SoundVolume, true));
+        ((SeekBar)findViewById(R.id.sbQuality)).setProgress(getConfigInt(ResampleQuality, true));
+
+        if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
+            ((EditText)findViewById(R.id.edFolder)).setText(Environment.getExternalStorageDirectory().getPath() + "/sdlpal/");
+        } else {
+            ((EditText)findViewById(R.id.edFolder)).setText("/sdcard/sdlpal/");
+        }
+        ((EditText)findViewById(R.id.edLangFile)).setText("");
+
+        ((SwitchCompat)findViewById(R.id.swEmbedFont)).setChecked(getConfigBoolean(UseEmbeddedFonts, true));
+        ((SwitchCompat)findViewById(R.id.swCustomLang)).setChecked(false);
+        ((SwitchCompat)findViewById(R.id.swGameLang)).setChecked(getConfigInt(CodePage, true) != 0);
+        ((SwitchCompat)findViewById(R.id.swTouch)).setChecked(getConfigBoolean(UseTouchOverlay, true));
+        ((SwitchCompat)findViewById(R.id.swAspect)).setChecked(getConfigBoolean(KeepAspectRatio, true));
+        ((SwitchCompat)findViewById(R.id.swSurround)).setChecked(getConfigBoolean(UseSurroundOPL, true));
+        ((SwitchCompat)findViewById(R.id.swStereo)).setChecked(getConfigBoolean(Stereo, true));
+
+        ((AppCompatSpinner)findViewById(R.id.spSample)).setSelection(findMatchedIntIndex(getConfigInt(SampleRate, true), AudioSampleRates, 2));    // 44100Hz
+        ((AppCompatSpinner)findViewById(R.id.spBuffer)).setSelection(findMatchedIntIndex(getConfigInt(AudioBufferSize, true), AudioBufferSizes, 1));    // 1024
+        ((AppCompatSpinner)findViewById(R.id.spCDFmt)).setSelection(findMatchedStringIndex(getConfigString(CDFormat, true), CDFormats, 1));     // OGG
+        ((AppCompatSpinner)findViewById(R.id.spMusFmt)).setSelection(findMatchedStringIndex(getConfigString(MusicFormat, true), MusicFormats, 1));    // RIX
+        ((AppCompatSpinner)findViewById(R.id.spOPL)).setSelection(findMatchedStringIndex(getConfigString(OPLFormat, true), OPLFormats, 1));       // MAME
+        ((AppCompatSpinner)findViewById(R.id.spOPLRate)).setSelection(findMatchedIntIndex(getConfigInt(OPLSampleRate, true), OPLSampleRates, 2));  // 49716Hz
+    }
+
+
+    protected void resetConfigs() {
         findViewById(R.id.edLangFile).setVisibility(View.GONE);
         findViewById(R.id.layoutOPL).setVisibility(View.VISIBLE);
 
-        ((SeekBar)findViewById(R.id.sbMusVol)).setProgress(getConfigInt(MusicVolume));
-        ((SeekBar)findViewById(R.id.sbSFXVol)).setProgress(getConfigInt(SoundVolume));
-        ((SeekBar)findViewById(R.id.sbQuality)).setProgress(getConfigInt(ResampleQuality)); // Best quality
+        ((SeekBar)findViewById(R.id.sbMusVol)).setProgress(getConfigInt(MusicVolume, false));
+        ((SeekBar)findViewById(R.id.sbSFXVol)).setProgress(getConfigInt(SoundVolume, false));
+        ((SeekBar)findViewById(R.id.sbQuality)).setProgress(getConfigInt(ResampleQuality, false)); // Best quality
 
-        String langFile = getConfigString(MessageFileName);
-        ((EditText)findViewById(R.id.edFolder)).setText(getConfigString(GamePath));
+        String langFile = getConfigString(MessageFileName, false);
+        ((EditText)findViewById(R.id.edFolder)).setText(getConfigString(GamePath, false));
         ((EditText)findViewById(R.id.edLangFile)).setText(langFile);
 
-        ((SwitchCompat)findViewById(R.id.swEmbedFont)).setChecked(getConfigBoolean(UseEmbeddedFonts));
+        ((SwitchCompat)findViewById(R.id.swEmbedFont)).setChecked(getConfigBoolean(UseEmbeddedFonts, false));
         ((SwitchCompat)findViewById(R.id.swCustomLang)).setChecked(langFile != null && !langFile.isEmpty());
-        ((SwitchCompat)findViewById(R.id.swGameLang)).setChecked(getConfigInt(CodePage) != 0);
-        ((SwitchCompat)findViewById(R.id.swTouch)).setChecked(getConfigBoolean(UseTouchOverlay));
-        ((SwitchCompat)findViewById(R.id.swAspect)).setChecked(getConfigBoolean(KeepAspectRatio));
-        ((SwitchCompat)findViewById(R.id.swSurround)).setChecked(getConfigBoolean(UseSurroundOPL));
-
-        ((AppCompatSpinner)findViewById(R.id.spSample)).setSelection(findMatchedIntIndex(getConfigInt(SampleRate), AudioSampleRates, 2));    // 44100Hz
-        ((AppCompatSpinner)findViewById(R.id.spBuffer)).setSelection(findMatchedIntIndex(getConfigInt(AudioBufferSize), AudioBufferSizes, 1));    // 1024
-        ((AppCompatSpinner)findViewById(R.id.spCDFmt)).setSelection(findMatchedStringIndex(getConfigString(CDFormat), CDFormats, 1));     // OGG
-        ((AppCompatSpinner)findViewById(R.id.spMusFmt)).setSelection(findMatchedStringIndex(getConfigString(MusicFormat), MusicFormats, 1));    // RIX
-        ((AppCompatSpinner)findViewById(R.id.spOPL)).setSelection(findMatchedStringIndex(getConfigString(OPLFormat), OPLFormats, 1));       // MAME
-        ((AppCompatSpinner)findViewById(R.id.spOPLRate)).setSelection(findMatchedIntIndex(getConfigInt(OPLSampleRate), OPLSampleRates, 2));  // 49716Hz
+        ((SwitchCompat)findViewById(R.id.swGameLang)).setChecked(getConfigInt(CodePage, false) != 0);
+        ((SwitchCompat)findViewById(R.id.swTouch)).setChecked(getConfigBoolean(UseTouchOverlay, false));
+        ((SwitchCompat)findViewById(R.id.swAspect)).setChecked(getConfigBoolean(KeepAspectRatio, false));
+        ((SwitchCompat)findViewById(R.id.swSurround)).setChecked(getConfigBoolean(UseSurroundOPL, false));
+        ((SwitchCompat)findViewById(R.id.swStereo)).setChecked(getConfigBoolean(Stereo, false));
+
+        ((AppCompatSpinner)findViewById(R.id.spSample)).setSelection(findMatchedIntIndex(getConfigInt(SampleRate, false), AudioSampleRates, 2));    // 44100Hz
+        ((AppCompatSpinner)findViewById(R.id.spBuffer)).setSelection(findMatchedIntIndex(getConfigInt(AudioBufferSize, false), AudioBufferSizes, 1));    // 1024
+        ((AppCompatSpinner)findViewById(R.id.spCDFmt)).setSelection(findMatchedStringIndex(getConfigString(CDFormat, false), CDFormats, 1));     // OGG
+        ((AppCompatSpinner)findViewById(R.id.spMusFmt)).setSelection(findMatchedStringIndex(getConfigString(MusicFormat, false), MusicFormats, 1));    // RIX
+        ((AppCompatSpinner)findViewById(R.id.spOPL)).setSelection(findMatchedStringIndex(getConfigString(OPLFormat, false), OPLFormats, 1));       // MAME
+        ((AppCompatSpinner)findViewById(R.id.spOPLRate)).setSelection(findMatchedIntIndex(getConfigInt(OPLSampleRate, false), OPLSampleRates, 2));  // 49716Hz
     }
 
-
     protected boolean setConfigs() {
         if (((EditText)findViewById(R.id.edFolder)).getText().toString().isEmpty()) {
             AlertDialog.Builder builder = new AlertDialog.Builder(this);
@@ -196,6 +238,7 @@ public class SettingsActivity extends AppCompatActivity {
         setConfigBoolean(UseTouchOverlay, ((SwitchCompat)findViewById(R.id.swTouch)).isChecked());
         setConfigBoolean(KeepAspectRatio, ((SwitchCompat)findViewById(R.id.swAspect)).isChecked());
         setConfigBoolean(UseSurroundOPL, ((SwitchCompat)findViewById(R.id.swSurround)).isChecked());
+        setConfigBoolean(Stereo, ((SwitchCompat)findViewById(R.id.swStereo)).isChecked());
 
         setConfigInt(SampleRate, Integer.parseInt((String)((AppCompatSpinner)findViewById(R.id.spSample)).getSelectedItem()));
         setConfigInt(AudioBufferSize, Integer.parseInt((String)((AppCompatSpinner)findViewById(R.id.spBuffer)).getSelectedItem()));

+ 30 - 23
android/app/src/main/res/layout/content_settings.xml

@@ -27,22 +27,15 @@
                 tools:layout_editor_absoluteX="8dp"
                 tools:layout_editor_absoluteY="-1dp" />
 
-            <LinearLayout
+            <EditText
+                android:id="@+id/edFolder"
                 android:layout_width="match_parent"
-                android:layout_height="match_parent"
-                android:orientation="horizontal">
-
-                <EditText
-                    android:id="@+id/edFolder"
-                    android:layout_width="368dp"
-                    android:layout_height="wrap_content"
-                    android:layout_weight="1"
-                    android:ems="10"
-                    android:inputType="textUri"
-                    tools:layout_editor_absoluteX="8dp"
-                    tools:layout_editor_absoluteY="16dp" />
-
-            </LinearLayout>
+                android:layout_height="wrap_content"
+                android:layout_weight="1"
+                android:ems="10"
+                android:inputType="textUri"
+                tools:layout_editor_absoluteX="8dp"
+                tools:layout_editor_absoluteY="16dp" />
 
             <android.support.v7.widget.SwitchCompat
                 android:id="@+id/swEmbedFont"
@@ -222,9 +215,12 @@
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
                     android:text="@string/action_suropl" />
+
             </LinearLayout>
 
-            <RelativeLayout
+            <android.support.v7.widget.GridLayout
+                app:columnCount="3"
+                app:rowCount="1"
                 android:layout_width="match_parent"
                 android:layout_height="match_parent">
 
@@ -235,9 +231,20 @@
                     android:layout_alignParentLeft="true"
                     android:layout_alignParentStart="true"
                     android:layout_centerVertical="true"
-                    android:layout_marginLeft="20dp"
-                    android:layout_marginStart="20dp"
-                    android:text="@string/action_default" />
+                    android:text="@string/action_default"
+                    app:layout_column="0"
+                    app:layout_columnWeight="1" />
+
+                <Button
+                    android:id="@+id/btnReset"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_alignParentEnd="true"
+                    android:layout_alignParentRight="true"
+                    android:layout_centerVertical="true"
+                    android:text="@string/action_restore"
+                    app:layout_column="1"
+                    app:layout_columnWeight="1" />
 
                 <Button
                     android:id="@+id/btnFinish"
@@ -246,10 +253,10 @@
                     android:layout_alignParentEnd="true"
                     android:layout_alignParentRight="true"
                     android:layout_centerVertical="true"
-                    android:layout_marginEnd="20dp"
-                    android:layout_marginRight="20dp"
-                    android:text="@string/action_finish" />
-            </RelativeLayout>
+                    android:text="@string/action_finish"
+                    app:layout_column="2"
+                    app:layout_columnWeight="1" />
+            </android.support.v7.widget.GridLayout>
 
         </LinearLayout>
     </ScrollView>

+ 1 - 0
android/app/src/main/res/values-zh-rTW/strings.xml

@@ -26,4 +26,5 @@
     <string name="msg_empty">必須指定遊戲資源檔案夾!</string>
     <string name="msg_exit">您的設定已保存,下次啟動時將直接開始遊戲。在遊戲中,您可以通過遊戲系統功能表的返回設定選項回到本設定頁面。</string>
     <string name="switch_simplified">簡</string>
+    <string name="action_restore">撤銷修改</string>
 </resources>

+ 1 - 0
android/app/src/main/res/values-zh/strings.xml

@@ -26,4 +26,5 @@
     <string name="msg_empty">必须指定游戏资源文件夹!</string>
     <string name="msg_exit">您的设置已保存,下次启动时将直接开始游戏。在游戏中,您可以通过游戏系统菜单中的返回设置选项回到本设置页面。</string>
     <string name="switch_simplified">简</string>
+    <string name="action_restore">撤销修改</string>
 </resources>

+ 3 - 2
android/app/src/main/res/values/strings.xml

@@ -21,8 +21,9 @@
     <string name="label_oplrate">OPL emulator\'s samplerate</string>
     <string name="label_opl">OPL emulator</string>
     <string name="action_suropl">Surround OPL</string>
-    <string name="action_default">Default values</string>
-    <string name="action_finish">Finish Setting</string>
+    <string name="action_default">Default</string>
+    <string name="action_finish">Finish</string>
+    <string name="action_restore">Reset</string>
     <string name="msg_exit">Settings have been saved and the game will be started on next launch. You can use the main menu option inside the game to return to this page.</string>
     <string name="msg_crash">The program is abnormally terminated last time. The setting page has been launched for you. Please check if there are any incorrect settings.</string>
     <string name="msg_empty">The game resource folder must be specified!</string>

+ 8 - 1
palcfg.c

@@ -506,13 +506,19 @@ PAL_SaveConfig(
 BOOL
 PAL_GetConfigItem(
 	const char  *szName,
-	ConfigValue *value
+	ConfigValue *value,
+	BOOL isDefault
 )
 {
 	for (int index = PALCFG_ALL_MIN; index < PALCFG_ALL_MAX; index++)
 	{
 		if (SDL_strcasecmp(gConfigItems[index].Name, szName) == 0)
 		{
+			if (isDefault)
+			{
+				*value = gConfigItems[index].DefaultValue;
+				return TRUE;
+			}
 			switch (index)
 			{
 			case PALCFG_FULLSCREEN:        value->bValue = gConfig.fFullScreen; return TRUE;
@@ -540,6 +546,7 @@ PAL_GetConfigItem(
 			case PALCFG_MUSIC:             value->sValue = music_types[gConfig.eMusicType]; return TRUE;
 			case PALCFG_OPL:               value->sValue = opl_types[gConfig.eOPLType]; return TRUE;
 			}
+			break;
 		}
 	}
 	return FALSE;

+ 5 - 4
palcfg.h

@@ -245,14 +245,15 @@ PAL_LimitConfig(
 
 BOOL
 PAL_GetConfigItem(
-	const char  *szName,
-	ConfigValue *value
+	const char * szName,
+	ConfigValue * pValue,
+	BOOL isDefault
 );
 
 BOOL
 PAL_SetConfigItem(
-	const char  *szName,
-	const ConfigValue *value
+	const char * szName,
+	const ConfigValue * pValue
 );
 
 PAL_C_LINKAGE_END