forked from extern/Unexpected-Keyboard
f1ce6abe5a
Store preferences in device protected storage, which is available before the device is unlocked. The keyboard was crashing when trying to access the encrypted preferences. The emoji pane uses a separate preferences file, the old data is lost. The SettingsActivity can't easily use the new preferences storage. Instead, it continues to use the "default" preferences store, which is copied back to the protected storage when needed.
45 lines
1.3 KiB
Java
45 lines
1.3 KiB
Java
package juloo.keyboard2;
|
|
|
|
import android.content.SharedPreferences;
|
|
import android.content.res.Configuration;
|
|
import android.os.Build;
|
|
import android.os.Bundle;
|
|
import android.preference.PreferenceActivity;
|
|
import android.preference.PreferenceManager;
|
|
|
|
public class SettingsActivity extends PreferenceActivity
|
|
{
|
|
@Override
|
|
public void onCreate(Bundle savedInstanceState)
|
|
{
|
|
detectSystemTheme();
|
|
super.onCreate(savedInstanceState);
|
|
addPreferencesFromResource(R.xml.settings);
|
|
PreferenceManager.getDefaultSharedPreferences(this)
|
|
.registerOnSharedPreferenceChangeListener(this.new OnPreferencesChange());
|
|
}
|
|
|
|
/** 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);
|
|
}
|
|
}
|
|
|
|
/** See DirectBootAwarePreferences. */
|
|
class OnPreferencesChange implements SharedPreferences.OnSharedPreferenceChangeListener
|
|
{
|
|
@Override
|
|
public void onSharedPreferenceChanged(SharedPreferences prefs, String _key)
|
|
{
|
|
DirectBootAwarePreferences
|
|
.copy_preferences_to_protected_storage(SettingsActivity.this, prefs);
|
|
}
|
|
}
|
|
}
|