From 276b1a2ebc6d5ea3fa36fa9271cdc6310db34021 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Fri, 7 Feb 2014 15:25:50 +0900 Subject: [PATCH] Add debug settings for keypress popup animations Bug: 12928125 Change-Id: I49faab754c7d1dcf4a791dfc535d3a78b62ce67a --- java/res/values/attrs.xml | 4 - java/res/values/config-common.xml | 6 +- java/res/values/strings.xml | 8 ++ java/res/values/themes-common.xml | 2 - java/res/xml/prefs_for_debug.xml | 85 +++++++------- .../keyboard/KeyboardSwitcher.java | 12 +- .../keyboard/MainKeyboardView.java | 6 + .../internal/KeyPreviewChoreographer.java | 88 +++++++------- .../internal/KeyPreviewDrawParams.java | 35 ++++-- .../latin/settings/DebugSettings.java | 109 ++++++++++++++++++ .../inputmethod/latin/settings/Settings.java | 33 +++++- .../latin/settings/SettingsValues.java | 19 +++ .../latin/utils/ResourceUtils.java | 4 + 13 files changed, 305 insertions(+), 106 deletions(-) diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml index 5bedd4ac2..b513d964a 100644 --- a/java/res/values/attrs.xml +++ b/java/res/values/attrs.xml @@ -111,10 +111,6 @@ - - - - diff --git a/java/res/values/config-common.xml b/java/res/values/config-common.xml index c92015288..1b44bad50 100644 --- a/java/res/values/config-common.xml +++ b/java/res/values/config-common.xml @@ -35,8 +35,10 @@ 350 - 35 - 40 + 35 + 40 + 70% + 70% 70 1000 diff --git a/java/res/values/strings.xml b/java/res/values/strings.xml index 70f4c1829..b762af3ad 100644 --- a/java/res/values/strings.xml +++ b/java/res/values/strings.xml @@ -486,6 +486,14 @@ mobile devices. [CHAR LIMIT=25] --> Keypress vibration duration Keypress sound volume + + Key popup show up duration + + Key popup dismiss duration + + Key popup show up start scale + + Key popup dismiss end scale Read external dictionary file diff --git a/java/res/values/themes-common.xml b/java/res/values/themes-common.xml index 3bfd73a55..fc96d19a1 100644 --- a/java/res/values/themes-common.xml +++ b/java/res/values/themes-common.xml @@ -77,8 +77,6 @@ @integer/config_ignore_alt_code_key_timeout @layout/key_preview @dimen/config_key_preview_height - @integer/config_key_preview_zoom_in_duration - @integer/config_key_preview_zoom_out_duration @integer/config_key_preview_linger_timeout @layout/more_keys_keyboard @bool/config_show_more_keys_keyboard_at_touched_point diff --git a/java/res/xml/prefs_for_debug.xml b/java/res/xml/prefs_for_debug.xml index 899e2b88e..81a5d98b9 100644 --- a/java/res/xml/prefs_for_debug.xml +++ b/java/res/xml/prefs_for_debug.xml @@ -14,68 +14,75 @@ limitations under the License. --> - - + - + android:key="enable_logging" + android:title="@string/prefs_enable_log" + android:summary="@string/prefs_description_log" + android:persistent="true" + android:defaultValue="false" /> - + 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="debug_mode" + android:title="@string/prefs_debug_mode" + 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" /> - + android:key="usability_study_mode" + android:title="@string/prefs_usability_study_mode" + android:persistent="true" + android:defaultValue="false" /> + + + + - - - - - - diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index 53b448515..9f98d298e 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -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) diff --git a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java index f3cfae203..ce41a31fc 100644 --- a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java @@ -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; diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyPreviewChoreographer.java b/java/src/com/android/inputmethod/keyboard/internal/KeyPreviewChoreographer.java index df869b2bc..ff197ba27 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyPreviewChoreographer.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyPreviewChoreographer.java @@ -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(); } } } diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyPreviewDrawParams.java b/java/src/com/android/inputmethod/keyboard/internal/KeyPreviewDrawParams.java index ff493b198..37e5c889d 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyPreviewDrawParams.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyPreviewDrawParams.java @@ -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; + } } diff --git a/java/src/com/android/inputmethod/latin/settings/DebugSettings.java b/java/src/com/android/inputmethod/latin/settings/DebugSettings.java index fa5ae92e7..c87dd1589 100644 --- a/java/src/com/android/inputmethod/latin/settings/DebugSettings.java +++ b/java/src/com/android/inputmethod/latin/settings/DebugSettings.java @@ -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) {} + }); + } } diff --git a/java/src/com/android/inputmethod/latin/settings/Settings.java b/java/src/com/android/inputmethod/latin/settings/Settings.java index 9bf269b6e..f0f7de7d4 100644 --- a/java/src/com/android/inputmethod/latin/settings/Settings.java +++ b/java/src/com/android/inputmethod/latin/settings/Settings.java @@ -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); } diff --git a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java index 2979544ae..90d3519a4 100644 --- a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java @@ -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; diff --git a/java/src/com/android/inputmethod/latin/utils/ResourceUtils.java b/java/src/com/android/inputmethod/latin/utils/ResourceUtils.java index deb28a08d..3a1c24c74 100644 --- a/java/src/com/android/inputmethod/latin/utils/ResourceUtils.java +++ b/java/src/com/android/inputmethod/latin/utils/ResourceUtils.java @@ -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)) {