mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-19 08:20:15 +00:00
Added sub-categories and moved some settings to more appropriate categories
This commit is contained in:
parent
38789cc87f
commit
35f53b0649
7 changed files with 339 additions and 288 deletions
|
@ -57,15 +57,6 @@ public final class AdvancedSettingsFragment extends SubScreenFragment {
|
|||
if (!Settings.isInternal(prefs)) {
|
||||
removePreference(Settings.SCREEN_DEBUG);
|
||||
}
|
||||
|
||||
if (!AudioAndHapticFeedbackManager.getInstance().hasVibrator()) {
|
||||
removePreference(Settings.PREF_VIBRATION_DURATION_SETTINGS);
|
||||
}
|
||||
|
||||
setupKeypressVibrationDurationSettings();
|
||||
setupKeypressSoundVolumeSettings();
|
||||
setupKeyLongpressTimeoutSettings();
|
||||
refreshEnablingsOfKeypressSoundAndVibrationSettings();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -73,154 +64,5 @@ public final class AdvancedSettingsFragment extends SubScreenFragment {
|
|||
if (key.equals(Settings.PREF_SHOW_SETUP_WIZARD_ICON)) {
|
||||
SystemBroadcastReceiver.toggleAppIcon(getActivity());
|
||||
}
|
||||
refreshEnablingsOfKeypressSoundAndVibrationSettings();
|
||||
}
|
||||
|
||||
private void refreshEnablingsOfKeypressSoundAndVibrationSettings() {
|
||||
final SharedPreferences prefs = getSharedPreferences();
|
||||
final Resources res = getResources();
|
||||
setPreferenceEnabled(Settings.PREF_VIBRATION_DURATION_SETTINGS,
|
||||
Settings.readVibrationEnabled(prefs, res));
|
||||
setPreferenceEnabled(Settings.PREF_KEYPRESS_SOUND_VOLUME,
|
||||
Settings.readKeypressSoundEnabled(prefs, res));
|
||||
}
|
||||
|
||||
private void setupKeypressVibrationDurationSettings() {
|
||||
final SeekBarDialogPreference pref = (SeekBarDialogPreference)findPreference(
|
||||
Settings.PREF_VIBRATION_DURATION_SETTINGS);
|
||||
if (pref == null) {
|
||||
return;
|
||||
}
|
||||
final SharedPreferences prefs = getSharedPreferences();
|
||||
final Resources res = getResources();
|
||||
pref.setInterface(new SeekBarDialogPreference.ValueProxy() {
|
||||
@Override
|
||||
public void writeValue(final int value, final String key) {
|
||||
prefs.edit().putInt(key, value).apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeDefaultValue(final String key) {
|
||||
prefs.edit().remove(key).apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readValue(final String key) {
|
||||
return Settings.readKeypressVibrationDuration(prefs, res);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readDefaultValue(final String key) {
|
||||
return Settings.readDefaultKeypressVibrationDuration(res);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void feedbackValue(final int value) {
|
||||
AudioAndHapticFeedbackManager.getInstance().vibrate(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValueText(final int value) {
|
||||
if (value < 0) {
|
||||
return res.getString(R.string.settings_system_default);
|
||||
}
|
||||
return res.getString(R.string.abbreviation_unit_milliseconds, value);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setupKeypressSoundVolumeSettings() {
|
||||
final SeekBarDialogPreference pref = (SeekBarDialogPreference)findPreference(
|
||||
Settings.PREF_KEYPRESS_SOUND_VOLUME);
|
||||
if (pref == null) {
|
||||
return;
|
||||
}
|
||||
final SharedPreferences prefs = getSharedPreferences();
|
||||
final Resources res = getResources();
|
||||
final AudioManager am = (AudioManager)getActivity().getSystemService(Context.AUDIO_SERVICE);
|
||||
pref.setInterface(new SeekBarDialogPreference.ValueProxy() {
|
||||
private static final float PERCENTAGE_FLOAT = 100.0f;
|
||||
|
||||
private float getValueFromPercentage(final int percentage) {
|
||||
return percentage / PERCENTAGE_FLOAT;
|
||||
}
|
||||
|
||||
private int getPercentageFromValue(final float floatValue) {
|
||||
return (int)(floatValue * PERCENTAGE_FLOAT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeValue(final int value, final String key) {
|
||||
prefs.edit().putFloat(key, getValueFromPercentage(value)).apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeDefaultValue(final String key) {
|
||||
prefs.edit().remove(key).apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readValue(final String key) {
|
||||
return getPercentageFromValue(Settings.readKeypressSoundVolume(prefs, res));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readDefaultValue(final String key) {
|
||||
return getPercentageFromValue(Settings.readDefaultKeypressSoundVolume(res));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValueText(final int value) {
|
||||
if (value < 0) {
|
||||
return res.getString(R.string.settings_system_default);
|
||||
}
|
||||
return Integer.toString(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void feedbackValue(final int value) {
|
||||
am.playSoundEffect(
|
||||
AudioManager.FX_KEYPRESS_STANDARD, getValueFromPercentage(value));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setupKeyLongpressTimeoutSettings() {
|
||||
final SharedPreferences prefs = getSharedPreferences();
|
||||
final Resources res = getResources();
|
||||
final SeekBarDialogPreference pref = (SeekBarDialogPreference)findPreference(
|
||||
Settings.PREF_KEY_LONGPRESS_TIMEOUT);
|
||||
if (pref == null) {
|
||||
return;
|
||||
}
|
||||
pref.setInterface(new SeekBarDialogPreference.ValueProxy() {
|
||||
@Override
|
||||
public void writeValue(final int value, final String key) {
|
||||
prefs.edit().putInt(key, value).apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeDefaultValue(final String key) {
|
||||
prefs.edit().remove(key).apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readValue(final String key) {
|
||||
return Settings.readKeyLongpressTimeout(prefs, res);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readDefaultValue(final String key) {
|
||||
return Settings.readDefaultKeyLongpressTimeout(res);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValueText(final int value) {
|
||||
return res.getString(R.string.abbreviation_unit_milliseconds, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void feedbackValue(final int value) {}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.dslul.openboard.inputmethod.latin.settings;
|
|||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.media.AudioManager;
|
||||
import android.os.Bundle;
|
||||
import android.preference.Preference;
|
||||
|
||||
|
@ -26,17 +27,6 @@ import org.dslul.openboard.inputmethod.latin.AudioAndHapticFeedbackManager;
|
|||
import org.dslul.openboard.inputmethod.latin.R;
|
||||
import org.dslul.openboard.inputmethod.latin.RichInputMethodManager;
|
||||
|
||||
/**
|
||||
* "Preferences" settings sub screen.
|
||||
*
|
||||
* This settings sub screen handles the following input preferences.
|
||||
* - Auto-capitalization
|
||||
* - Double-space period
|
||||
* - Vibrate on keypress
|
||||
* - Sound on keypress
|
||||
* - Popup on keypress
|
||||
* - Voice input key
|
||||
*/
|
||||
public final class PreferencesSettingsFragment extends SubScreenFragment {
|
||||
|
||||
private static final boolean VOICE_IME_ENABLED =
|
||||
|
@ -62,11 +52,16 @@ public final class PreferencesSettingsFragment extends SubScreenFragment {
|
|||
}
|
||||
if (!AudioAndHapticFeedbackManager.getInstance().hasVibrator()) {
|
||||
removePreference(Settings.PREF_VIBRATE_ON);
|
||||
removePreference(Settings.PREF_VIBRATION_DURATION_SETTINGS);
|
||||
}
|
||||
if (!Settings.readFromBuildConfigIfToShowKeyPreviewPopupOption(res)) {
|
||||
removePreference(Settings.PREF_POPUP_ON);
|
||||
}
|
||||
|
||||
setupKeypressVibrationDurationSettings();
|
||||
setupKeypressSoundVolumeSettings();
|
||||
setupKeyLongpressTimeoutSettings();
|
||||
refreshEnablingsOfKeypressSoundAndVibrationSettings();
|
||||
refreshEnablingsOfKeypressSoundAndVibrationSettings();
|
||||
}
|
||||
|
||||
|
@ -95,4 +90,143 @@ public final class PreferencesSettingsFragment extends SubScreenFragment {
|
|||
setPreferenceEnabled(Settings.PREF_KEYPRESS_SOUND_VOLUME,
|
||||
Settings.readKeypressSoundEnabled(prefs, res));
|
||||
}
|
||||
|
||||
private void setupKeypressVibrationDurationSettings() {
|
||||
final SeekBarDialogPreference pref = (SeekBarDialogPreference)findPreference(
|
||||
Settings.PREF_VIBRATION_DURATION_SETTINGS);
|
||||
if (pref == null) {
|
||||
return;
|
||||
}
|
||||
final SharedPreferences prefs = getSharedPreferences();
|
||||
final Resources res = getResources();
|
||||
pref.setInterface(new SeekBarDialogPreference.ValueProxy() {
|
||||
@Override
|
||||
public void writeValue(final int value, final String key) {
|
||||
prefs.edit().putInt(key, value).apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeDefaultValue(final String key) {
|
||||
prefs.edit().remove(key).apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readValue(final String key) {
|
||||
return Settings.readKeypressVibrationDuration(prefs, res);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readDefaultValue(final String key) {
|
||||
return Settings.readDefaultKeypressVibrationDuration(res);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void feedbackValue(final int value) {
|
||||
AudioAndHapticFeedbackManager.getInstance().vibrate(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValueText(final int value) {
|
||||
if (value < 0) {
|
||||
return res.getString(R.string.settings_system_default);
|
||||
}
|
||||
return res.getString(R.string.abbreviation_unit_milliseconds, value);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setupKeypressSoundVolumeSettings() {
|
||||
final SeekBarDialogPreference pref = (SeekBarDialogPreference)findPreference(
|
||||
Settings.PREF_KEYPRESS_SOUND_VOLUME);
|
||||
if (pref == null) {
|
||||
return;
|
||||
}
|
||||
final SharedPreferences prefs = getSharedPreferences();
|
||||
final Resources res = getResources();
|
||||
final AudioManager am = (AudioManager)getActivity().getSystemService(Context.AUDIO_SERVICE);
|
||||
pref.setInterface(new SeekBarDialogPreference.ValueProxy() {
|
||||
private static final float PERCENTAGE_FLOAT = 100.0f;
|
||||
|
||||
private float getValueFromPercentage(final int percentage) {
|
||||
return percentage / PERCENTAGE_FLOAT;
|
||||
}
|
||||
|
||||
private int getPercentageFromValue(final float floatValue) {
|
||||
return (int)(floatValue * PERCENTAGE_FLOAT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeValue(final int value, final String key) {
|
||||
prefs.edit().putFloat(key, getValueFromPercentage(value)).apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeDefaultValue(final String key) {
|
||||
prefs.edit().remove(key).apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readValue(final String key) {
|
||||
return getPercentageFromValue(Settings.readKeypressSoundVolume(prefs, res));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readDefaultValue(final String key) {
|
||||
return getPercentageFromValue(Settings.readDefaultKeypressSoundVolume(res));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValueText(final int value) {
|
||||
if (value < 0) {
|
||||
return res.getString(R.string.settings_system_default);
|
||||
}
|
||||
return Integer.toString(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void feedbackValue(final int value) {
|
||||
am.playSoundEffect(
|
||||
AudioManager.FX_KEYPRESS_STANDARD, getValueFromPercentage(value));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setupKeyLongpressTimeoutSettings() {
|
||||
final SharedPreferences prefs = getSharedPreferences();
|
||||
final Resources res = getResources();
|
||||
final SeekBarDialogPreference pref = (SeekBarDialogPreference)findPreference(
|
||||
Settings.PREF_KEY_LONGPRESS_TIMEOUT);
|
||||
if (pref == null) {
|
||||
return;
|
||||
}
|
||||
pref.setInterface(new SeekBarDialogPreference.ValueProxy() {
|
||||
@Override
|
||||
public void writeValue(final int value, final String key) {
|
||||
prefs.edit().putInt(key, value).apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeDefaultValue(final String key) {
|
||||
prefs.edit().remove(key).apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readValue(final String key) {
|
||||
return Settings.readKeyLongpressTimeout(prefs, res);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readDefaultValue(final String key) {
|
||||
return Settings.readDefaultKeyLongpressTimeout(res);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValueText(final int value) {
|
||||
return res.getString(R.string.abbreviation_unit_milliseconds, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void feedbackValue(final int value) {}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import android.os.Build;
|
|||
import android.os.Bundle;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceCategory;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.preference.PreferenceScreen;
|
||||
import android.util.Log;
|
||||
|
@ -47,8 +48,14 @@ public abstract class SubScreenFragment extends PreferenceFragment
|
|||
|
||||
static void removePreference(final String prefKey, final PreferenceScreen screen) {
|
||||
final Preference preference = screen.findPreference(prefKey);
|
||||
if (preference != null) {
|
||||
screen.removePreference(preference);
|
||||
if (preference != null && !screen.removePreference(preference)) {
|
||||
final int count = screen.getPreferenceCount();
|
||||
for (int i = 0; i < count; i++) {
|
||||
final Preference pref = screen.getPreference(i);
|
||||
if (pref instanceof PreferenceCategory
|
||||
&& ((PreferenceCategory) pref).removePreference(preference))
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue