2015-08-08 16:47:22 +02:00
|
|
|
package juloo.keyboard2;
|
|
|
|
|
2022-11-11 14:27:02 +01:00
|
|
|
import android.content.SharedPreferences;
|
2022-11-05 10:13:35 +01:00
|
|
|
import android.content.res.Configuration;
|
|
|
|
import android.os.Build;
|
2015-08-08 16:47:22 +02:00
|
|
|
import android.os.Bundle;
|
|
|
|
import android.preference.PreferenceActivity;
|
2022-11-11 14:27:02 +01:00
|
|
|
import android.preference.PreferenceManager;
|
2015-08-08 16:47:22 +02:00
|
|
|
|
|
|
|
public class SettingsActivity extends PreferenceActivity
|
|
|
|
{
|
2021-12-19 19:44:27 +01:00
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState)
|
|
|
|
{
|
2022-11-05 10:13:35 +01:00
|
|
|
detectSystemTheme();
|
2021-12-19 19:44:27 +01:00
|
|
|
super.onCreate(savedInstanceState);
|
2022-11-11 15:39:28 +01:00
|
|
|
// The preferences can't be read when in direct-boot mode. Avoid crashing
|
|
|
|
// and don't allow changing the settings.
|
2023-08-15 20:23:33 +02:00
|
|
|
// Run the config migration on this prefs as it might be different from the
|
|
|
|
// one used by the keyboard, which have been migrated.
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Config.migrate(getPreferenceManager().getSharedPreferences());
|
|
|
|
}
|
2022-11-11 15:39:28 +01:00
|
|
|
catch (Exception _e) { fallbackEncrypted(); return; }
|
2021-12-19 19:44:27 +01:00
|
|
|
addPreferencesFromResource(R.xml.settings);
|
|
|
|
}
|
2022-11-05 10:13:35 +01:00
|
|
|
|
|
|
|
/** The default theme is [Theme.DeviceDefault], which is dark. Detect if the
|
|
|
|
system is using light theme. */
|
|
|
|
void detectSystemTheme()
|
|
|
|
{
|
|
|
|
if (Build.VERSION.SDK_INT >= 14)
|
|
|
|
{
|
|
|
|
int ui_mode = getResources().getConfiguration().uiMode;
|
|
|
|
if ((ui_mode & Configuration.UI_MODE_NIGHT_NO) != 0)
|
|
|
|
setTheme(android.R.style.Theme_DeviceDefault_Light);
|
|
|
|
}
|
|
|
|
}
|
2022-11-11 14:27:02 +01:00
|
|
|
|
2022-11-11 15:39:28 +01:00
|
|
|
void fallbackEncrypted()
|
|
|
|
{
|
|
|
|
// Can't communicate with the user here.
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
|
2022-12-11 21:57:40 +01:00
|
|
|
protected void onStop()
|
2022-11-11 14:27:02 +01:00
|
|
|
{
|
2022-12-11 21:57:40 +01:00
|
|
|
DirectBootAwarePreferences
|
|
|
|
.copy_preferences_to_protected_storage(this,
|
|
|
|
getPreferenceManager().getSharedPreferences());
|
|
|
|
super.onStop();
|
2022-11-11 14:27:02 +01:00
|
|
|
}
|
2015-08-08 16:47:22 +02:00
|
|
|
}
|