Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ed432962 authored by Jean Chalard's avatar Jean Chalard
Browse files

Move settings method from Utils to SettingsValues

Change-Id: I633378a41f63cd492b8c9345d550e07254df5e5a
parent a76c62e9
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -2323,7 +2323,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar

    // update keypress sound volume
    private void updateSoundEffectVolume() {
        mFxVolume = Utils.getCurrentKeypressSoundVolume(mPrefs, mResources);
        mFxVolume = SettingsValues.getCurrentKeypressSoundVolume(mPrefs, mResources);
    }

    // update flags for silent mode
@@ -2336,7 +2336,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
    }

    private void updateKeypressVibrationDuration() {
        mKeypressVibrationDuration = Utils.getCurrentVibrationDuration(mPrefs, mResources);
        mKeypressVibrationDuration = SettingsValues.getCurrentVibrationDuration(mPrefs, mResources);
    }

    private void playKeyClick(int primaryCode) {
+5 −5
Original line number Diff line number Diff line
@@ -447,7 +447,7 @@ public class Settings extends InputMethodSettingsActivity
            SharedPreferences sp, Resources res) {
        if (mKeypressVibrationDurationSettingsPref != null) {
            mKeypressVibrationDurationSettingsPref.setSummary(
                    Utils.getCurrentVibrationDuration(sp, res)
                    SettingsValues.getCurrentVibrationDuration(sp, res)
                            + res.getString(R.string.settings_ms));
        }
    }
@@ -475,7 +475,7 @@ public class Settings extends InputMethodSettingsActivity
        });
        final View v = context.getLayoutInflater().inflate(
                R.layout.vibration_settings_dialog, null);
        final int currentMs = Utils.getCurrentVibrationDuration(
        final int currentMs = SettingsValues.getCurrentVibrationDuration(
                getPreferenceManager().getSharedPreferences(), getResources());
        mKeypressVibrationDurationSettingsTextView = (TextView)v.findViewById(R.id.vibration_value);
        final SeekBar sb = (SeekBar)v.findViewById(R.id.vibration_settings);
@@ -504,8 +504,8 @@ public class Settings extends InputMethodSettingsActivity

    private void updateKeypressSoundVolumeSummary(SharedPreferences sp, Resources res) {
        if (mKeypressSoundVolumeSettingsPref != null) {
            mKeypressSoundVolumeSettingsPref.setSummary(
                    String.valueOf((int)(Utils.getCurrentKeypressSoundVolume(sp, res) * 100)));
            mKeypressSoundVolumeSettingsPref.setSummary(String.valueOf(
                    (int)(SettingsValues.getCurrentKeypressSoundVolume(sp, res) * 100)));
        }
    }

@@ -534,7 +534,7 @@ public class Settings extends InputMethodSettingsActivity
        });
        final View v = context.getLayoutInflater().inflate(
                R.layout.sound_effect_volume_dialog, null);
        final int currentVolumeInt = (int)(Utils.getCurrentKeypressSoundVolume(
        final int currentVolumeInt = (int)(SettingsValues.getCurrentKeypressSoundVolume(
                getPreferenceManager().getSharedPreferences(), getResources()) * 100);
        mKeypressSoundVolumeSettingsTextView =
                (TextView)v.findViewById(R.id.sound_effect_volume_value);
+35 −1
Original line number Diff line number Diff line
@@ -19,11 +19,13 @@ package com.android.inputmethod.latin;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.Build;
import android.util.Log;
import android.view.inputmethod.EditorInfo;

import com.android.inputmethod.compat.InputTypeCompatUtils;
import com.android.inputmethod.compat.VibratorCompatWrapper;
import com.android.inputmethod.latin.R.array;

import java.util.Arrays;
import java.util.Locale;
@@ -241,4 +243,36 @@ public class SettingsValues {
    public boolean isVoiceKeyOnMain() {
        return mVoiceKeyOnMain;
    }

    public static float getCurrentKeypressSoundVolume(SharedPreferences sp, Resources res) {
        final float volume = sp.getFloat(Settings.PREF_KEYPRESS_SOUND_VOLUME, -1.0f);
        if (volume >= 0) {
            return volume;
        }

        final String[] volumePerHardwareList = res.getStringArray(R.array.keypress_volumes);
        final String hardwarePrefix = Build.HARDWARE + ",";
        for (final String element : volumePerHardwareList) {
            if (element.startsWith(hardwarePrefix)) {
                return Float.parseFloat(element.substring(element.lastIndexOf(',') + 1));
            }
        }
        return -1.0f;
    }

    public static int getCurrentVibrationDuration(SharedPreferences sp, Resources res) {
        final int ms = sp.getInt(Settings.PREF_KEYPRESS_VIBRATION_DURATION_SETTINGS, -1);
        if (ms >= 0) {
            return ms;
        }
        final String[] durationPerHardwareList = res.getStringArray(
                R.array.keypress_vibration_durations);
        final String hardwarePrefix = Build.HARDWARE + ",";
        for (final String element : durationPerHardwareList) {
            if (element.startsWith(hardwarePrefix)) {
                return (int)Long.parseLong(element.substring(element.lastIndexOf(',') + 1));
            }
        }
        return -1;
    }
}
+0 −34
Original line number Diff line number Diff line
@@ -17,11 +17,9 @@
package com.android.inputmethod.latin;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.inputmethodservice.InputMethodService;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Process;
@@ -778,38 +776,6 @@ public class Utils {
        return s.toUpperCase(locale).charAt(0) + s.substring(1);
    }

    public static int getCurrentVibrationDuration(SharedPreferences sp, Resources res) {
        final int ms = sp.getInt(Settings.PREF_KEYPRESS_VIBRATION_DURATION_SETTINGS, -1);
        if (ms >= 0) {
            return ms;
        }
        final String[] durationPerHardwareList = res.getStringArray(
                R.array.keypress_vibration_durations);
        final String hardwarePrefix = Build.HARDWARE + ",";
        for (final String element : durationPerHardwareList) {
            if (element.startsWith(hardwarePrefix)) {
                return (int)Long.parseLong(element.substring(element.lastIndexOf(',') + 1));
            }
        }
        return -1;
    }

    public static float getCurrentKeypressSoundVolume(SharedPreferences sp, Resources res) {
        final float volume = sp.getFloat(Settings.PREF_KEYPRESS_SOUND_VOLUME, -1.0f);
        if (volume >= 0) {
            return volume;
        }

        final String[] volumePerHardwareList = res.getStringArray(R.array.keypress_volumes);
        final String hardwarePrefix = Build.HARDWARE + ",";
        for (final String element : volumePerHardwareList) {
            if (element.startsWith(hardwarePrefix)) {
                return Float.parseFloat(element.substring(element.lastIndexOf(',') + 1));
            }
        }
        return -1.0f;
    }

    public static boolean willAutoCorrect(SuggestedWords suggestions) {
        return !suggestions.mTypedWordValid && suggestions.mHasAutoCorrectionCandidate
                && !suggestions.shouldBlockAutoCorrection();