mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-25 07:09:48 -06:00
Android: Allow reading global settings without a Settings object
This makes things more convenient for code that just wants to read the current value of a setting.
This commit is contained in:
@ -49,4 +49,10 @@ public class AdHocBooleanSetting implements AbstractBooleanSetting
|
|||||||
{
|
{
|
||||||
NativeConfig.setBoolean(settings.getWriteLayer(), mFile, mSection, mKey, newValue);
|
NativeConfig.setBoolean(settings.getWriteLayer(), mFile, mSection, mKey, newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean getBooleanGlobal(String file, String section, String key,
|
||||||
|
boolean defaultValue)
|
||||||
|
{
|
||||||
|
return NativeConfig.getBoolean(NativeConfig.LAYER_ACTIVE, file, section, key, defaultValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,57 @@
|
|||||||
|
package org.dolphinemu.dolphinemu.features.settings.model;
|
||||||
|
|
||||||
|
public class AdHocStringSetting implements AbstractStringSetting
|
||||||
|
{
|
||||||
|
private final String mFile;
|
||||||
|
private final String mSection;
|
||||||
|
private final String mKey;
|
||||||
|
private final String mDefaultValue;
|
||||||
|
|
||||||
|
public AdHocStringSetting(String file, String section, String key, String defaultValue)
|
||||||
|
{
|
||||||
|
mFile = file;
|
||||||
|
mSection = section;
|
||||||
|
mKey = key;
|
||||||
|
mDefaultValue = defaultValue;
|
||||||
|
|
||||||
|
if (!NativeConfig.isSettingSaveable(file, section, key))
|
||||||
|
{
|
||||||
|
throw new IllegalArgumentException("File/section/key is unknown or legacy");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isOverridden(Settings settings)
|
||||||
|
{
|
||||||
|
return NativeConfig.isOverridden(mFile, mSection, mKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isRuntimeEditable()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean delete(Settings settings)
|
||||||
|
{
|
||||||
|
return NativeConfig.deleteKey(settings.getWriteLayer(), mFile, mSection, mKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getString(Settings settings)
|
||||||
|
{
|
||||||
|
return NativeConfig.getString(NativeConfig.LAYER_ACTIVE, mFile, mSection, mKey, mDefaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setString(Settings settings, String newValue)
|
||||||
|
{
|
||||||
|
NativeConfig.setString(settings.getWriteLayer(), mFile, mSection, mKey, newValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getStringGlobal(String file, String section, String key, String defaultValue)
|
||||||
|
{
|
||||||
|
return NativeConfig.getString(NativeConfig.LAYER_ACTIVE, file, section, key, defaultValue);
|
||||||
|
}
|
||||||
|
}
|
@ -191,4 +191,9 @@ public enum BooleanSetting implements AbstractBooleanSetting
|
|||||||
settings.getSection(mFile, mSection).setBoolean(mKey, newValue);
|
settings.getSection(mFile, mSection).setBoolean(mKey, newValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getBooleanGlobal()
|
||||||
|
{
|
||||||
|
return NativeConfig.getBoolean(NativeConfig.LAYER_ACTIVE, mFile, mSection, mKey, mDefaultValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,4 +73,9 @@ public enum FloatSetting implements AbstractFloatSetting
|
|||||||
settings.getSection(mFile, mSection).setFloat(mKey, newValue);
|
settings.getSection(mFile, mSection).setFloat(mKey, newValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float getFloatGlobal()
|
||||||
|
{
|
||||||
|
return NativeConfig.getFloat(NativeConfig.LAYER_ACTIVE, mFile, mSection, mKey, mDefaultValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,4 +130,9 @@ public enum IntSetting implements AbstractIntSetting
|
|||||||
settings.getSection(mFile, mSection).setInt(mKey, newValue);
|
settings.getSection(mFile, mSection).setInt(mKey, newValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getIntGlobal()
|
||||||
|
{
|
||||||
|
return NativeConfig.getInt(NativeConfig.LAYER_ACTIVE, mFile, mSection, mKey, mDefaultValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,4 +104,9 @@ public enum StringSetting implements AbstractStringSetting
|
|||||||
settings.getSection(mFile, mSection).setString(mKey, newValue);
|
settings.getSection(mFile, mSection).setString(mKey, newValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getStringGlobal()
|
||||||
|
{
|
||||||
|
return NativeConfig.getString(NativeConfig.LAYER_ACTIVE, mFile, mSection, mKey, mDefaultValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -152,8 +152,7 @@ public final class MenuFragment extends Fragment implements View.OnClickListener
|
|||||||
|
|
||||||
LinearLayout options = requireView().findViewById(R.id.layout_options);
|
LinearLayout options = requireView().findViewById(R.id.layout_options);
|
||||||
|
|
||||||
Settings settings = ((EmulationActivity) requireActivity()).getSettings();
|
boolean savestatesEnabled = BooleanSetting.MAIN_ENABLE_SAVESTATES.getBooleanGlobal();
|
||||||
boolean savestatesEnabled = BooleanSetting.MAIN_ENABLE_SAVESTATES.getBoolean(settings);
|
|
||||||
int savestateVisibility = savestatesEnabled ? View.VISIBLE : View.GONE;
|
int savestateVisibility = savestatesEnabled ? View.VISIBLE : View.GONE;
|
||||||
options.findViewById(R.id.menu_quicksave).setVisibility(savestateVisibility);
|
options.findViewById(R.id.menu_quicksave).setVisibility(savestateVisibility);
|
||||||
options.findViewById(R.id.menu_quickload).setVisibility(savestateVisibility);
|
options.findViewById(R.id.menu_quickload).setVisibility(savestateVisibility);
|
||||||
|
@ -81,12 +81,7 @@ public class GameFileCache
|
|||||||
*/
|
*/
|
||||||
public boolean scanLibrary(Context context)
|
public boolean scanLibrary(Context context)
|
||||||
{
|
{
|
||||||
boolean recursiveScan;
|
boolean recursiveScan = BooleanSetting.MAIN_RECURSIVE_ISO_PATHS.getBooleanGlobal();
|
||||||
try (Settings settings = new Settings())
|
|
||||||
{
|
|
||||||
settings.loadSettings(null);
|
|
||||||
recursiveScan = BooleanSetting.MAIN_RECURSIVE_ISO_PATHS.getBoolean(settings);
|
|
||||||
}
|
|
||||||
|
|
||||||
removeNonExistentGameFolders(context);
|
removeNonExistentGameFolders(context);
|
||||||
|
|
||||||
|
@ -291,11 +291,7 @@ public final class MainActivity extends AppCompatActivity implements MainView
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
try (Settings settings = new Settings())
|
mViewPager.setCurrentItem(IntSetting.MAIN_LAST_PLATFORM_TAB.getIntGlobal());
|
||||||
{
|
|
||||||
settings.loadSettings(null);
|
|
||||||
mViewPager.setCurrentItem(IntSetting.MAIN_LAST_PLATFORM_TAB.getInt(settings));
|
|
||||||
}
|
|
||||||
|
|
||||||
showGames();
|
showGames();
|
||||||
GameFileCacheService.startLoad(this);
|
GameFileCacheService.startLoad(this);
|
||||||
|
@ -24,44 +24,41 @@ public class Analytics
|
|||||||
{
|
{
|
||||||
new AfterDirectoryInitializationRunner().run(context, false, () ->
|
new AfterDirectoryInitializationRunner().run(context, false, () ->
|
||||||
{
|
{
|
||||||
Settings settings = new Settings();
|
if (!BooleanSetting.MAIN_ANALYTICS_PERMISSION_ASKED.getBooleanGlobal())
|
||||||
settings.loadSettings(null);
|
|
||||||
if (!BooleanSetting.MAIN_ANALYTICS_PERMISSION_ASKED.getBoolean(settings))
|
|
||||||
{
|
{
|
||||||
showMessage(context, settings);
|
showMessage(context);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
settings.close();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void showMessage(Context context, Settings settings)
|
private static void showMessage(Context context)
|
||||||
{
|
{
|
||||||
new AlertDialog.Builder(context, R.style.DolphinDialogBase)
|
new AlertDialog.Builder(context, R.style.DolphinDialogBase)
|
||||||
.setTitle(context.getString(R.string.analytics))
|
.setTitle(context.getString(R.string.analytics))
|
||||||
.setMessage(context.getString(R.string.analytics_desc))
|
.setMessage(context.getString(R.string.analytics_desc))
|
||||||
.setPositiveButton(R.string.yes, (dialogInterface, i) ->
|
.setPositiveButton(R.string.yes, (dialogInterface, i) ->
|
||||||
{
|
{
|
||||||
firstAnalyticsAdd(settings, true);
|
firstAnalyticsAdd(true);
|
||||||
})
|
})
|
||||||
.setNegativeButton(R.string.no, (dialogInterface, i) ->
|
.setNegativeButton(R.string.no, (dialogInterface, i) ->
|
||||||
{
|
{
|
||||||
firstAnalyticsAdd(settings, false);
|
firstAnalyticsAdd(false);
|
||||||
})
|
})
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void firstAnalyticsAdd(Settings settings, boolean enabled)
|
private static void firstAnalyticsAdd(boolean enabled)
|
||||||
{
|
{
|
||||||
BooleanSetting.MAIN_ANALYTICS_ENABLED.setBoolean(settings, enabled);
|
try (Settings settings = new Settings())
|
||||||
BooleanSetting.MAIN_ANALYTICS_PERMISSION_ASKED.setBoolean(settings, true);
|
{
|
||||||
|
settings.loadSettings(null);
|
||||||
|
|
||||||
// Context is set to null to avoid toasts
|
BooleanSetting.MAIN_ANALYTICS_ENABLED.setBoolean(settings, enabled);
|
||||||
settings.saveSettings(null, null);
|
BooleanSetting.MAIN_ANALYTICS_PERMISSION_ASKED.setBoolean(settings, true);
|
||||||
|
|
||||||
settings.close();
|
// Context is set to null to avoid toasts
|
||||||
|
settings.saveSettings(null, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendReport(String endpoint, byte[] data)
|
public static void sendReport(String endpoint, byte[] data)
|
||||||
|
@ -9,6 +9,7 @@ import android.util.SparseArray;
|
|||||||
import android.view.InputDevice;
|
import android.view.InputDevice;
|
||||||
|
|
||||||
import org.dolphinemu.dolphinemu.activities.EmulationActivity;
|
import org.dolphinemu.dolphinemu.activities.EmulationActivity;
|
||||||
|
import org.dolphinemu.dolphinemu.features.settings.model.AdHocStringSetting;
|
||||||
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
|
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
|
||||||
import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile;
|
import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile;
|
||||||
|
|
||||||
@ -28,9 +29,8 @@ public class Rumble
|
|||||||
|
|
||||||
for (int i = 0; i < 8; i++)
|
for (int i = 0; i < 8; i++)
|
||||||
{
|
{
|
||||||
String deviceName = activity.getSettings()
|
String deviceName = AdHocStringSetting.getStringGlobal(Settings.FILE_DOLPHIN,
|
||||||
.getSection(Settings.FILE_DOLPHIN, Settings.SECTION_BINDINGS)
|
Settings.SECTION_BINDINGS, SettingsFile.KEY_EMU_RUMBLE + i, "");
|
||||||
.getString(SettingsFile.KEY_EMU_RUMBLE + i, "");
|
|
||||||
|
|
||||||
if (!deviceName.isEmpty())
|
if (!deviceName.isEmpty())
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user