am 276b1a2e: Add debug settings for keypress popup animations

* commit '276b1a2ebc6d5ea3fa36fa9271cdc6310db34021':
  Add debug settings for keypress popup animations
This commit is contained in:
Tadashi G. Takaoka 2014-02-07 01:37:07 -08:00 committed by Android Git Automerger
commit 0072f3a774
13 changed files with 305 additions and 106 deletions

View file

@ -111,10 +111,6 @@
<attr name="keyPreviewOffset" format="dimension" />
<!-- Height of the key press feedback popup. -->
<attr name="keyPreviewHeight" format="dimension" />
<!-- Duration of key preview popup zoom in animation in millisecond -->
<attr name="keyPreviewZoomInDuration" format="integer" />
<!-- Duration of key preview popup zoom out animation in millisecond -->
<attr name="keyPreviewZoomOutDuration" format="integer" />
<!-- Delay after key releasing and key press feedback dismissing in millisecond -->
<attr name="keyPreviewLingerTimeout" format="integer" />
<!-- Layout resource for more keys keyboard -->

View file

@ -35,8 +35,10 @@
<integer name="config_ignore_alt_code_key_timeout">350</integer>
<integer name="config_key_preview_zoom_in_duration">35</integer>
<integer name="config_key_preview_zoom_out_duration">40</integer>
<integer name="config_key_preview_show_up_duration">35</integer>
<integer name="config_key_preview_dismiss_duration">40</integer>
<fraction name="config_key_preview_show_up_start_scale">70%</fraction>
<fraction name="config_key_preview_dismiss_end_scale">70%</fraction>
<integer name="config_key_preview_linger_timeout">70</integer>
<!-- Suppress showing key preview duration after batch input in millisecond -->
<integer name="config_suppress_key_preview_after_batch_input_duration">1000</integer>

View file

@ -486,6 +486,14 @@ mobile devices. [CHAR LIMIT=25] -->
<string name="prefs_keypress_vibration_duration_settings">Keypress vibration duration</string>
<!-- Title of the settings for keypress sound volume [CHAR LIMIT=35] -->
<string name="prefs_keypress_sound_volume_settings">Keypress sound volume</string>
<!-- Title of the settings for key popup show up animation duration (in milliseconds) [CHAR LIMIT=35] -->
<string name="prefs_key_popup_show_up_duration_settings" translatable="false">Key popup show up duration</string>
<!-- Title of the settings for key popup dismiss animation duration (in milliseconds) [CHAR LIMIT=35] -->
<string name="prefs_key_popup_dismiss_duration_settings" translatable="false">Key popup dismiss duration</string>
<!-- Title of the settings for key popup show up animation start scale (in percentile) [CHAR LIMIT=35] -->
<string name="prefs_key_popup_show_up_start_scale_settings" translatable="false">Key popup show up start scale</string>
<!-- Title of the settings for key popup dismiss animation end scale (in percentile) [CHAR LIMIT=35] -->
<string name="prefs_key_popup_dismiss_end_scale_settings" translatable="false">Key popup dismiss end scale</string>
<!-- Title of the settings for reading an external dictionary file -->
<string name="prefs_read_external_dictionary">Read external dictionary file</string>
<!-- Title of the settings for using only personalization dictionary -->

View file

@ -77,8 +77,6 @@
<item name="ignoreAltCodeKeyTimeout">@integer/config_ignore_alt_code_key_timeout</item>
<item name="keyPreviewLayout">@layout/key_preview</item>
<item name="keyPreviewHeight">@dimen/config_key_preview_height</item>
<item name="keyPreviewZoomInDuration">@integer/config_key_preview_zoom_in_duration</item>
<item name="keyPreviewZoomOutDuration">@integer/config_key_preview_zoom_out_duration</item>
<item name="keyPreviewLingerTimeout">@integer/config_key_preview_linger_timeout</item>
<item name="moreKeysKeyboardLayout">@layout/more_keys_keyboard</item>
<item name="showMoreKeysKeyboardAtTouchedPoint">@bool/config_show_more_keys_keyboard_at_touched_point</item>

View file

@ -14,68 +14,75 @@
limitations under the License.
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/prefs_debug_mode"
android:key="english_ime_debug_settings">
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
android:title="@string/prefs_debug_mode"
android:key="english_ime_debug_settings"
>
<CheckBoxPreference
android:key="enable_logging"
android:title="@string/prefs_enable_log"
android:summary="@string/prefs_description_log"
android:persistent="true"
android:defaultValue="false" />
android:key="enable_logging"
android:title="@string/prefs_enable_log"
android:summary="@string/prefs_description_log"
android:persistent="true"
android:defaultValue="false" />
<ListPreference
android:key="pref_keyboard_layout_20110916"
android:title="@string/keyboard_layout"
android:summary="%s"
android:persistent="true"
android:entryValues="@array/keyboard_layout_modes_values"
android:entries="@array/keyboard_layout_modes"
android:defaultValue="@string/config_default_keyboard_theme_index" />
android:key="pref_keyboard_layout_20110916"
android:title="@string/keyboard_layout"
android:summary="%s"
android:persistent="true"
android:entryValues="@array/keyboard_layout_modes_values"
android:entries="@array/keyboard_layout_modes"
android:defaultValue="@string/config_default_keyboard_theme_index" />
<CheckBoxPreference
android:key="debug_mode"
android:title="@string/prefs_debug_mode"
android:persistent="true"
android:defaultValue="false" />
android:key="debug_mode"
android:title="@string/prefs_debug_mode"
android:persistent="true"
android:defaultValue="false" />
<CheckBoxPreference
android:key="force_non_distinct_multitouch"
android:title="@string/prefs_force_non_distinct_multitouch"
android:persistent="true"
android:defaultValue="false" />
android:key="force_non_distinct_multitouch"
android:title="@string/prefs_force_non_distinct_multitouch"
android:persistent="true"
android:defaultValue="false" />
<CheckBoxPreference
android:key="usability_study_mode"
android:title="@string/prefs_usability_study_mode"
android:persistent="true"
android:defaultValue="false" />
android:key="usability_study_mode"
android:title="@string/prefs_usability_study_mode"
android:persistent="true"
android:defaultValue="false" />
<com.android.inputmethod.latin.settings.SeekBarDialogPreference
android:key="pref_key_preview_show_up_start_scale"
android:title="@string/prefs_key_popup_show_up_start_scale_settings"
latin:maxValue="100" /> <!-- percent -->
<com.android.inputmethod.latin.settings.SeekBarDialogPreference
android:key="pref_key_preview_dismiss_end_scale"
android:title="@string/prefs_key_popup_dismiss_end_scale_settings"
latin:maxValue="100" /> <!-- percent -->
<com.android.inputmethod.latin.settings.SeekBarDialogPreference
android:key="pref_key_preview_show_up_duration"
android:title="@string/prefs_key_popup_show_up_duration_settings"
latin:maxValue="100" /> <!-- milliseconds -->
<com.android.inputmethod.latin.settings.SeekBarDialogPreference
android:key="pref_key_preview_dismiss_duration"
android:title="@string/prefs_key_popup_dismiss_duration_settings"
latin:maxValue="100" /> <!-- milliseconds -->
<CheckBoxPreference
android:defaultValue="false"
android:key="use_only_personalization_dictionary_for_debug"
android:persistent="true"
android:title="@string/prefs_use_only_personalization_dictionary" />
<PreferenceScreen
android:key="read_external_dictionary"
android:title="@string/prefs_read_external_dictionary" />
<PreferenceScreen
android:key="dump_contacts_dict"
android:title="@string/prefs_dump_contacts_dict" />
<PreferenceScreen
android:key="dump_user_dict"
android:title="@string/prefs_dump_user_dict" />
<PreferenceScreen
android:key="dump_user_history_dict"
android:title="@string/prefs_dump_user_history_dict" />
<PreferenceScreen
android:key="dump_personalization_dict"
android:title="@string/prefs_dump_personalization_dict" />
</PreferenceScreen>

View file

@ -37,6 +37,7 @@ import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.RichInputMethodManager;
import com.android.inputmethod.latin.SubtypeSwitcher;
import com.android.inputmethod.latin.WordComposer;
import com.android.inputmethod.latin.settings.DebugSettings;
import com.android.inputmethod.latin.settings.Settings;
import com.android.inputmethod.latin.settings.SettingsValues;
import com.android.inputmethod.latin.utils.ResourceUtils;
@ -80,6 +81,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
private KeyboardState mState;
private KeyboardLayoutSet mKeyboardLayoutSet;
private SettingsValues mCurrentSettingsValues;
/** mIsAutoCorrectionActive indicates that auto corrected word will be input instead of
* what user actually typed. */
@ -158,6 +160,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
settingsValues.mShowsVoiceInputKey,
settingsValues.isLanguageSwitchKeyEnabled());
mKeyboardLayoutSet = builder.build();
mCurrentSettingsValues = settingsValues;
try {
mState.onLoadKeyboard();
} catch (KeyboardLayoutSetException e) {
@ -189,8 +192,13 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
keyboardView.setKeyboard(keyboard);
mCurrentInputView.setKeyboardTopPadding(keyboard.mTopPadding);
keyboardView.setKeyPreviewPopupEnabled(
Settings.readKeyPreviewPopupEnabled(mPrefs, mResources),
Settings.readKeyPreviewPopupDismissDelay(mPrefs, mResources));
mCurrentSettingsValues.mKeyPreviewPopupOn,
mCurrentSettingsValues.mKeyPreviewPopupDismissDelay);
keyboardView.setKeyPreviewAnimationParams(
mCurrentSettingsValues.mKeyPreviewShowUpStartScale,
mCurrentSettingsValues.mKeyPreviewShowUpDuration,
mCurrentSettingsValues.mKeyPreviewDismissEndScale,
mCurrentSettingsValues.mKeyPreviewDismissDuration);
keyboardView.updateAutoCorrectionState(mIsAutoCorrectionActive);
keyboardView.updateShortcutKey(mSubtypeSwitcher.isShortcutImeReady());
final boolean subtypeChanged = (oldKeyboard == null)

View file

@ -421,6 +421,12 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
mKeyPreviewDrawParams.setPopupEnabled(previewEnabled, delay);
}
public void setKeyPreviewAnimationParams(final float showUpStartScale, final int showUpDuration,
final float dismissEndScale, final int dismissDuration) {
mKeyPreviewDrawParams.setAnimationParams(
showUpStartScale, showUpDuration, dismissEndScale, dismissDuration);
}
private void locatePreviewPlacerView() {
if (mDrawingPreviewPlacerView.getParent() != null) {
return;

View file

@ -100,7 +100,7 @@ public final class KeyPreviewChoreographer {
if (withAnimation) {
if (tag instanceof KeyPreviewAnimations) {
final KeyPreviewAnimations animation = (KeyPreviewAnimations)tag;
animation.startZoomOut();
animation.startDismiss();
}
return;
}
@ -198,87 +198,87 @@ public final class KeyPreviewChoreographer {
}
// Show preview with animation.
final Animator zoomIn = createZoomInAniation(key, previewTextView);
final Animator zoomOut = createZoomOutAnimation(key, previewTextView);
final KeyPreviewAnimations animation = new KeyPreviewAnimations(zoomIn, zoomOut);
final Animator showUpAnimation = createShowUpAniation(key, previewTextView);
final Animator dismissAnimation = createDismissAnimation(key, previewTextView);
final KeyPreviewAnimations animation = new KeyPreviewAnimations(
showUpAnimation, dismissAnimation);
previewTextView.setTag(animation);
animation.startZoomIn();
animation.startShowUp();
}
// TODO: Move these parameters to resources or preferences.
private static final float KEY_PREVIEW_START_ZOOM_IN_SCALE = 0.7f;
private static final float KEY_PREVIEW_END_ZOOM_IN_SCALE = 1.0f;
private static final float KEY_PREVIEW_END_ZOOM_OUT_SCALE = 0.7f;
private static final float KEY_PREVIEW_SHOW_UP_END_SCALE = 1.0f;
private static final AccelerateInterpolator ACCELERATE_INTERPOLATOR =
new AccelerateInterpolator();
private static final DecelerateInterpolator DECELERATE_INTERPOLATOR =
new DecelerateInterpolator();
private Animator createZoomInAniation(final Key key, final TextView previewTextView) {
private Animator createShowUpAniation(final Key key, final TextView previewTextView) {
// TODO: Optimization for no scale animation and no duration.
final ObjectAnimator scaleXAnimation = ObjectAnimator.ofFloat(
previewTextView, View.SCALE_X, KEY_PREVIEW_START_ZOOM_IN_SCALE,
KEY_PREVIEW_END_ZOOM_IN_SCALE);
previewTextView, View.SCALE_X, mParams.getShowUpStartScale(),
KEY_PREVIEW_SHOW_UP_END_SCALE);
final ObjectAnimator scaleYAnimation = ObjectAnimator.ofFloat(
previewTextView, View.SCALE_Y, KEY_PREVIEW_START_ZOOM_IN_SCALE,
KEY_PREVIEW_END_ZOOM_IN_SCALE);
final AnimatorSet zoomInAnimation = new AnimatorSet();
zoomInAnimation.play(scaleXAnimation).with(scaleYAnimation);
// TODO: Implement preference option to control key preview animation duration.
zoomInAnimation.setDuration(mParams.mZoomInDuration);
zoomInAnimation.setInterpolator(DECELERATE_INTERPOLATOR);
zoomInAnimation.addListener(new AnimatorListenerAdapter() {
previewTextView, View.SCALE_Y, mParams.getShowUpStartScale(),
KEY_PREVIEW_SHOW_UP_END_SCALE);
final AnimatorSet showUpAnimation = new AnimatorSet();
showUpAnimation.play(scaleXAnimation).with(scaleYAnimation);
showUpAnimation.setDuration(mParams.getShowUpDuration());
showUpAnimation.setInterpolator(DECELERATE_INTERPOLATOR);
showUpAnimation.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(final Animator animation) {
showKeyPreview(key, previewTextView, false /* withAnimation */);
}
});
return zoomInAnimation;
return showUpAnimation;
}
private Animator createZoomOutAnimation(final Key key, final TextView previewTextView) {
private Animator createDismissAnimation(final Key key, final TextView previewTextView) {
// TODO: Optimization for no scale animation and no duration.
final ObjectAnimator scaleXAnimation = ObjectAnimator.ofFloat(
previewTextView, View.SCALE_X, KEY_PREVIEW_END_ZOOM_OUT_SCALE);
previewTextView, View.SCALE_X, mParams.getDismissEndScale());
final ObjectAnimator scaleYAnimation = ObjectAnimator.ofFloat(
previewTextView, View.SCALE_Y, KEY_PREVIEW_END_ZOOM_OUT_SCALE);
final AnimatorSet zoomOutAnimation = new AnimatorSet();
zoomOutAnimation.play(scaleXAnimation).with(scaleYAnimation);
// TODO: Implement preference option to control key preview animation duration.
final int zoomOutDuration = Math.min(mParams.mZoomOutDuration, mParams.getLingerTimeout());
zoomOutAnimation.setDuration(zoomOutDuration);
zoomOutAnimation.setInterpolator(ACCELERATE_INTERPOLATOR);
zoomOutAnimation.addListener(new AnimatorListenerAdapter() {
previewTextView, View.SCALE_Y, mParams.getDismissEndScale());
final AnimatorSet dismissAnimation = new AnimatorSet();
dismissAnimation.play(scaleXAnimation).with(scaleYAnimation);
final int dismissDuration = Math.min(
mParams.getDismissDuration(), mParams.getLingerTimeout());
dismissAnimation.setDuration(dismissDuration);
dismissAnimation.setInterpolator(ACCELERATE_INTERPOLATOR);
dismissAnimation.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(final Animator animation) {
dismissKeyPreview(key, false /* withAnimation */);
}
});
return zoomOutAnimation;
return dismissAnimation;
}
private static class KeyPreviewAnimations extends AnimatorListenerAdapter {
private final Animator mZoomIn;
private final Animator mZoomOut;
private final Animator mShowUpAnimation;
private final Animator mDismissAnimation;
public KeyPreviewAnimations(final Animator zoomIn, final Animator zoomOut) {
mZoomIn = zoomIn;
mZoomOut = zoomOut;
public KeyPreviewAnimations(final Animator showUpAnimation,
final Animator dismissAnimation) {
mShowUpAnimation = showUpAnimation;
mDismissAnimation = dismissAnimation;
}
public void startZoomIn() {
mZoomIn.start();
public void startShowUp() {
mShowUpAnimation.start();
}
public void startZoomOut() {
if (mZoomIn.isRunning()) {
mZoomIn.addListener(this);
public void startDismiss() {
if (mShowUpAnimation.isRunning()) {
mShowUpAnimation.addListener(this);
return;
}
mZoomOut.start();
mDismissAnimation.start();
}
@Override
public void onAnimationEnd(final Animator animation) {
mZoomOut.start();
mDismissAnimation.start();
}
}
}

View file

@ -26,9 +26,10 @@ public final class KeyPreviewDrawParams {
public final int mLayoutId;
public final int mPreviewOffset;
public final int mPreviewHeight;
// TODO: Move those parameters to preferences.
public final int mZoomInDuration;
public final int mZoomOutDuration;
private int mShowUpDuration;
private int mDismissDuration;
private float mShowUpStartScale;
private float mDismissEndScale;
private int mLingerTimeout;
private boolean mShowPopup = true;
@ -69,10 +70,6 @@ public final class KeyPreviewDrawParams {
if (mLayoutId == 0) {
mShowPopup = false;
}
mZoomInDuration = mainKeyboardViewAttr.getInt(
R.styleable.MainKeyboardView_keyPreviewZoomInDuration, 0);
mZoomOutDuration = mainKeyboardViewAttr.getInt(
R.styleable.MainKeyboardView_keyPreviewZoomOutDuration, 0);
}
public void setVisibleOffset(final int previewVisibleOffset) {
@ -117,4 +114,28 @@ public final class KeyPreviewDrawParams {
public int getLingerTimeout() {
return mLingerTimeout;
}
public void setAnimationParams(final float showUpStartScale, final int showUpDuration,
final float dismissEndScale, final int dismissDuration) {
mShowUpStartScale = showUpStartScale;
mShowUpDuration = showUpDuration;
mDismissEndScale = dismissEndScale;
mDismissDuration = dismissDuration;
}
public float getShowUpStartScale() {
return mShowUpStartScale;
}
public int getShowUpDuration() {
return mShowUpDuration;
}
public float getDismissEndScale() {
return mDismissEndScale;
}
public int getDismissDuration() {
return mDismissDuration;
}
}

View file

@ -18,6 +18,7 @@ package com.android.inputmethod.latin.settings;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.Process;
import android.preference.CheckBoxPreference;
@ -32,6 +33,7 @@ import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.debug.ExternalDictionaryGetterForDebug;
import com.android.inputmethod.latin.utils.ApplicationUtils;
import com.android.inputmethod.latin.utils.ResourceUtils;
public final class DebugSettings extends PreferenceFragment
implements SharedPreferences.OnSharedPreferenceChangeListener {
@ -42,6 +44,14 @@ public final class DebugSettings extends PreferenceFragment
public static final String PREF_STATISTICS_LOGGING = "enable_logging";
public static final String PREF_USE_ONLY_PERSONALIZATION_DICTIONARY_FOR_DEBUG =
"use_only_personalization_dictionary_for_debug";
public static final String PREF_KEY_PREVIEW_SHOW_UP_START_SCALE =
"pref_key_preview_show_up_start_scale";
public static final String PREF_KEY_PREVIEW_DISMISS_END_SCALE =
"pref_key_preview_dismiss_end_scale";
public static final String PREF_KEY_PREVIEW_SHOW_UP_DURATION =
"pref_key_preview_show_up_duration";
public static final String PREF_KEY_PREVIEW_DISMISS_DURATION =
"pref_key_preview_dismiss_duration";
private static final String PREF_READ_EXTERNAL_DICTIONARY = "read_external_dictionary";
private static final String PREF_DUMP_CONTACTS_DICT = "dump_contacts_dict";
private static final String PREF_DUMP_USER_DICT = "dump_user_dict";
@ -101,6 +111,17 @@ public final class DebugSettings extends PreferenceFragment
dictDumpPrefClickListener);
findPreference(PREF_DUMP_PERSONALIZATION_DICT).setOnPreferenceClickListener(
dictDumpPrefClickListener);
final Resources res = getResources();
setupKeyPreviewAnimationDuration(prefs, res, PREF_KEY_PREVIEW_SHOW_UP_DURATION,
res.getInteger(R.integer.config_key_preview_show_up_duration));
setupKeyPreviewAnimationDuration(prefs, res, PREF_KEY_PREVIEW_DISMISS_DURATION,
res.getInteger(R.integer.config_key_preview_dismiss_duration));
setupKeyPreviewAnimationScale(prefs, res, PREF_KEY_PREVIEW_SHOW_UP_START_SCALE,
ResourceUtils.getFloatFromFraction(
res, R.fraction.config_key_preview_show_up_start_scale));
setupKeyPreviewAnimationScale(prefs, res, PREF_KEY_PREVIEW_DISMISS_END_SCALE,
ResourceUtils.getFloatFromFraction(
res, R.fraction.config_key_preview_dismiss_end_scale));
mServiceNeedsRestart = false;
mDebugMode = (CheckBoxPreference) findPreference(PREF_DEBUG_MODE);
@ -180,4 +201,92 @@ public final class DebugSettings extends PreferenceFragment
mDebugMode.setSummary(version);
}
}
private void setupKeyPreviewAnimationScale(final SharedPreferences sp, final Resources res,
final String prefKey, final float defaultValue) {
final SeekBarDialogPreference pref = (SeekBarDialogPreference)findPreference(prefKey);
if (pref == null) {
return;
}
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) {
sp.edit().putFloat(key, getValueFromPercentage(value)).apply();
}
@Override
public void writeDefaultValue(final String key) {
sp.edit().remove(key).apply();
}
@Override
public int readValue(final String key) {
return getPercentageFromValue(
Settings.readKeyPreviewAnimationScale(sp, key, defaultValue));
}
@Override
public int readDefaultValue(final String key) {
return getPercentageFromValue(defaultValue);
}
@Override
public String getValueText(final int value) {
if (value < 0) {
return res.getString(R.string.settings_system_default);
}
return String.format("%d%%", value);
}
@Override
public void feedbackValue(final int value) {}
});
}
private void setupKeyPreviewAnimationDuration(final SharedPreferences sp, final Resources res,
final String prefKey, final int defaultValue) {
final SeekBarDialogPreference pref = (SeekBarDialogPreference)findPreference(prefKey);
if (pref == null) {
return;
}
pref.setInterface(new SeekBarDialogPreference.ValueProxy() {
@Override
public void writeValue(final int value, final String key) {
sp.edit().putInt(key, value).apply();
}
@Override
public void writeDefaultValue(final String key) {
sp.edit().remove(key).apply();
}
@Override
public int readValue(final String key) {
return Settings.readKeyPreviewAnimationDuration(sp, key, defaultValue);
}
@Override
public int readDefaultValue(final String key) {
return defaultValue;
}
@Override
public String getValueText(final int value) {
return res.getString(R.string.abbreviation_unit_milliseconds, value);
}
@Override
public void feedbackValue(final int value) {}
});
}
}

View file

@ -107,6 +107,9 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
public static final String PREF_EMOJI_CATEGORY_LAST_TYPED_ID = "emoji_category_last_typed_id";
public static final String PREF_LAST_SHOWN_EMOJI_CATEGORY_ID = "last_shown_emoji_category_id";
private static final float UNDEFINED_PREFERENCE_VALUE_FLOAT = -1.0f;
private static final int UNDEFINED_PREFERENCE_VALUE_INT = -1;
private Context mContext;
private Resources mRes;
private SharedPreferences mPrefs;
@ -301,8 +304,10 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
public static float readKeypressSoundVolume(final SharedPreferences prefs,
final Resources res) {
final float volume = prefs.getFloat(PREF_KEYPRESS_SOUND_VOLUME, -1.0f);
return (volume >= 0) ? volume : readDefaultKeypressSoundVolume(res);
final float volume = prefs.getFloat(
PREF_KEYPRESS_SOUND_VOLUME, UNDEFINED_PREFERENCE_VALUE_FLOAT);
return (volume != UNDEFINED_PREFERENCE_VALUE_FLOAT) ? volume
: readDefaultKeypressSoundVolume(res);
}
public static float readDefaultKeypressSoundVolume(final Resources res) {
@ -312,8 +317,10 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
public static int readKeyLongpressTimeout(final SharedPreferences prefs,
final Resources res) {
final int ms = prefs.getInt(PREF_KEY_LONGPRESS_TIMEOUT, -1);
return (ms >= 0) ? ms : readDefaultKeyLongpressTimeout(res);
final int milliseconds = prefs.getInt(
PREF_KEY_LONGPRESS_TIMEOUT, UNDEFINED_PREFERENCE_VALUE_INT);
return (milliseconds != UNDEFINED_PREFERENCE_VALUE_INT) ? milliseconds
: readDefaultKeyLongpressTimeout(res);
}
public static int readDefaultKeyLongpressTimeout(final Resources res) {
@ -322,8 +329,10 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
public static int readKeypressVibrationDuration(final SharedPreferences prefs,
final Resources res) {
final int ms = prefs.getInt(PREF_VIBRATION_DURATION_SETTINGS, -1);
return (ms >= 0) ? ms : readDefaultKeypressVibrationDuration(res);
final int milliseconds = prefs.getInt(
PREF_VIBRATION_DURATION_SETTINGS, UNDEFINED_PREFERENCE_VALUE_INT);
return (milliseconds != UNDEFINED_PREFERENCE_VALUE_INT) ? milliseconds
: readDefaultKeypressVibrationDuration(res);
}
public static int readDefaultKeypressVibrationDuration(final Resources res) {
@ -335,6 +344,18 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
return prefs.getBoolean(DebugSettings.PREF_USABILITY_STUDY_MODE, true);
}
public static float readKeyPreviewAnimationScale(final SharedPreferences prefs,
final String prefKey, final float defaultValue) {
final float fraction = prefs.getFloat(prefKey, UNDEFINED_PREFERENCE_VALUE_FLOAT);
return (fraction != UNDEFINED_PREFERENCE_VALUE_FLOAT) ? fraction : defaultValue;
}
public static int readKeyPreviewAnimationDuration(final SharedPreferences prefs,
final String prefKey, final int defaultValue) {
final int milliseconds = prefs.getInt(prefKey, UNDEFINED_PREFERENCE_VALUE_INT);
return (milliseconds != UNDEFINED_PREFERENCE_VALUE_INT) ? milliseconds : defaultValue;
}
public static boolean readUseFullscreenMode(final Resources res) {
return res.getBoolean(R.bool.config_use_fullscreen_mode);
}

View file

@ -29,6 +29,7 @@ import com.android.inputmethod.latin.InputAttributes;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.RichInputMethodManager;
import com.android.inputmethod.latin.utils.AsyncResultHolder;
import com.android.inputmethod.latin.utils.ResourceUtils;
import com.android.inputmethod.latin.utils.TargetPackageInfoGetterTask;
import java.util.Arrays;
@ -93,6 +94,10 @@ public final class SettingsValues {
// Debug settings
public final boolean mIsInternal;
public final int mKeyPreviewShowUpDuration;
public final int mKeyPreviewDismissDuration;
public final float mKeyPreviewShowUpStartScale;
public final float mKeyPreviewDismissEndScale;
public SettingsValues(final Context context, final SharedPreferences prefs, final Resources res,
final InputAttributes inputAttributes) {
@ -149,6 +154,20 @@ public final class SettingsValues {
AdditionalFeaturesSettingUtils.readAdditionalFeaturesPreferencesIntoArray(
prefs, mAdditionalFeaturesSettingValues);
mIsInternal = Settings.isInternal(prefs);
mKeyPreviewShowUpDuration = Settings.readKeyPreviewAnimationDuration(
prefs, DebugSettings.PREF_KEY_PREVIEW_SHOW_UP_DURATION,
res.getInteger(R.integer.config_key_preview_show_up_duration));
mKeyPreviewDismissDuration = Settings.readKeyPreviewAnimationDuration(
prefs, DebugSettings.PREF_KEY_PREVIEW_DISMISS_DURATION,
res.getInteger(R.integer.config_key_preview_dismiss_duration));
mKeyPreviewShowUpStartScale = Settings.readKeyPreviewAnimationScale(
prefs, DebugSettings.PREF_KEY_PREVIEW_SHOW_UP_START_SCALE,
ResourceUtils.getFloatFromFraction(
res, R.fraction.config_key_preview_show_up_start_scale));
mKeyPreviewDismissEndScale = Settings.readKeyPreviewAnimationScale(
prefs, DebugSettings.PREF_KEY_PREVIEW_DISMISS_END_SCALE,
ResourceUtils.getFloatFromFraction(
res, R.fraction.config_key_preview_dismiss_end_scale));
mUseOnlyPersonalizationDictionaryForDebug = prefs.getBoolean(
DebugSettings.PREF_USE_ONLY_PERSONALIZATION_DICTIONARY_FOR_DEBUG, false);
mDisplayOrientation = res.getConfiguration().orientation;

View file

@ -260,6 +260,10 @@ public final class ResourceUtils {
return dimension >= 0;
}
public static float getFloatFromFraction(final Resources res, final int fractionResId) {
return res.getFraction(fractionResId, 1, 1);
}
public static float getFraction(final TypedArray a, final int index, final float defValue) {
final TypedValue value = a.peekValue(index);
if (value == null || !isFractionValue(value)) {