am 276b1a2e: Add debug settings for keypress popup animations

* commit '276b1a2ebc6d5ea3fa36fa9271cdc6310db34021':
  Add debug settings for keypress popup animations
main
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" /> <attr name="keyPreviewOffset" format="dimension" />
<!-- Height of the key press feedback popup. --> <!-- Height of the key press feedback popup. -->
<attr name="keyPreviewHeight" format="dimension" /> <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 --> <!-- Delay after key releasing and key press feedback dismissing in millisecond -->
<attr name="keyPreviewLingerTimeout" format="integer" /> <attr name="keyPreviewLingerTimeout" format="integer" />
<!-- Layout resource for more keys keyboard --> <!-- 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_ignore_alt_code_key_timeout">350</integer>
<integer name="config_key_preview_zoom_in_duration">35</integer> <integer name="config_key_preview_show_up_duration">35</integer>
<integer name="config_key_preview_zoom_out_duration">40</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> <integer name="config_key_preview_linger_timeout">70</integer>
<!-- Suppress showing key preview duration after batch input in millisecond --> <!-- Suppress showing key preview duration after batch input in millisecond -->
<integer name="config_suppress_key_preview_after_batch_input_duration">1000</integer> <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> <string name="prefs_keypress_vibration_duration_settings">Keypress vibration duration</string>
<!-- Title of the settings for keypress sound volume [CHAR LIMIT=35] --> <!-- Title of the settings for keypress sound volume [CHAR LIMIT=35] -->
<string name="prefs_keypress_sound_volume_settings">Keypress sound volume</string> <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 --> <!-- Title of the settings for reading an external dictionary file -->
<string name="prefs_read_external_dictionary">Read external dictionary file</string> <string name="prefs_read_external_dictionary">Read external dictionary file</string>
<!-- Title of the settings for using only personalization dictionary --> <!-- 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="ignoreAltCodeKeyTimeout">@integer/config_ignore_alt_code_key_timeout</item>
<item name="keyPreviewLayout">@layout/key_preview</item> <item name="keyPreviewLayout">@layout/key_preview</item>
<item name="keyPreviewHeight">@dimen/config_key_preview_height</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="keyPreviewLingerTimeout">@integer/config_key_preview_linger_timeout</item>
<item name="moreKeysKeyboardLayout">@layout/more_keys_keyboard</item> <item name="moreKeysKeyboardLayout">@layout/more_keys_keyboard</item>
<item name="showMoreKeysKeyboardAtTouchedPoint">@bool/config_show_more_keys_keyboard_at_touched_point</item> <item name="showMoreKeysKeyboardAtTouchedPoint">@bool/config_show_more_keys_keyboard_at_touched_point</item>

View File

@ -14,68 +14,75 @@
limitations under the License. limitations under the License.
--> -->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" <PreferenceScreen
android:title="@string/prefs_debug_mode" xmlns:android="http://schemas.android.com/apk/res/android"
android:key="english_ime_debug_settings"> 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 <CheckBoxPreference
android:key="enable_logging" android:key="enable_logging"
android:title="@string/prefs_enable_log" android:title="@string/prefs_enable_log"
android:summary="@string/prefs_description_log" android:summary="@string/prefs_description_log"
android:persistent="true" android:persistent="true"
android:defaultValue="false" /> android:defaultValue="false" />
<ListPreference <ListPreference
android:key="pref_keyboard_layout_20110916" android:key="pref_keyboard_layout_20110916"
android:title="@string/keyboard_layout" android:title="@string/keyboard_layout"
android:summary="%s" android:summary="%s"
android:persistent="true" android:persistent="true"
android:entryValues="@array/keyboard_layout_modes_values" android:entryValues="@array/keyboard_layout_modes_values"
android:entries="@array/keyboard_layout_modes" android:entries="@array/keyboard_layout_modes"
android:defaultValue="@string/config_default_keyboard_theme_index" /> android:defaultValue="@string/config_default_keyboard_theme_index" />
<CheckBoxPreference <CheckBoxPreference
android:key="debug_mode" android:key="debug_mode"
android:title="@string/prefs_debug_mode" android:title="@string/prefs_debug_mode"
android:persistent="true" android:persistent="true"
android:defaultValue="false" /> android:defaultValue="false" />
<CheckBoxPreference <CheckBoxPreference
android:key="force_non_distinct_multitouch" android:key="force_non_distinct_multitouch"
android:title="@string/prefs_force_non_distinct_multitouch" android:title="@string/prefs_force_non_distinct_multitouch"
android:persistent="true" android:persistent="true"
android:defaultValue="false" /> android:defaultValue="false" />
<CheckBoxPreference <CheckBoxPreference
android:key="usability_study_mode" android:key="usability_study_mode"
android:title="@string/prefs_usability_study_mode" android:title="@string/prefs_usability_study_mode"
android:persistent="true" android:persistent="true"
android:defaultValue="false" /> 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 <CheckBoxPreference
android:defaultValue="false" android:defaultValue="false"
android:key="use_only_personalization_dictionary_for_debug" android:key="use_only_personalization_dictionary_for_debug"
android:persistent="true" android:persistent="true"
android:title="@string/prefs_use_only_personalization_dictionary" /> android:title="@string/prefs_use_only_personalization_dictionary" />
<PreferenceScreen <PreferenceScreen
android:key="read_external_dictionary" android:key="read_external_dictionary"
android:title="@string/prefs_read_external_dictionary" /> android:title="@string/prefs_read_external_dictionary" />
<PreferenceScreen <PreferenceScreen
android:key="dump_contacts_dict" android:key="dump_contacts_dict"
android:title="@string/prefs_dump_contacts_dict" /> android:title="@string/prefs_dump_contacts_dict" />
<PreferenceScreen <PreferenceScreen
android:key="dump_user_dict" android:key="dump_user_dict"
android:title="@string/prefs_dump_user_dict" /> android:title="@string/prefs_dump_user_dict" />
<PreferenceScreen <PreferenceScreen
android:key="dump_user_history_dict" android:key="dump_user_history_dict"
android:title="@string/prefs_dump_user_history_dict" /> android:title="@string/prefs_dump_user_history_dict" />
<PreferenceScreen <PreferenceScreen
android:key="dump_personalization_dict" android:key="dump_personalization_dict"
android:title="@string/prefs_dump_personalization_dict" /> android:title="@string/prefs_dump_personalization_dict" />
</PreferenceScreen> </PreferenceScreen>

View File

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

View File

@ -421,6 +421,12 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
mKeyPreviewDrawParams.setPopupEnabled(previewEnabled, delay); 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() { private void locatePreviewPlacerView() {
if (mDrawingPreviewPlacerView.getParent() != null) { if (mDrawingPreviewPlacerView.getParent() != null) {
return; return;

View File

@ -100,7 +100,7 @@ public final class KeyPreviewChoreographer {
if (withAnimation) { if (withAnimation) {
if (tag instanceof KeyPreviewAnimations) { if (tag instanceof KeyPreviewAnimations) {
final KeyPreviewAnimations animation = (KeyPreviewAnimations)tag; final KeyPreviewAnimations animation = (KeyPreviewAnimations)tag;
animation.startZoomOut(); animation.startDismiss();
} }
return; return;
} }
@ -198,87 +198,87 @@ public final class KeyPreviewChoreographer {
} }
// Show preview with animation. // Show preview with animation.
final Animator zoomIn = createZoomInAniation(key, previewTextView); final Animator showUpAnimation = createShowUpAniation(key, previewTextView);
final Animator zoomOut = createZoomOutAnimation(key, previewTextView); final Animator dismissAnimation = createDismissAnimation(key, previewTextView);
final KeyPreviewAnimations animation = new KeyPreviewAnimations(zoomIn, zoomOut); final KeyPreviewAnimations animation = new KeyPreviewAnimations(
showUpAnimation, dismissAnimation);
previewTextView.setTag(animation); previewTextView.setTag(animation);
animation.startZoomIn(); animation.startShowUp();
} }
// TODO: Move these parameters to resources or preferences. private static final float KEY_PREVIEW_SHOW_UP_END_SCALE = 1.0f;
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 AccelerateInterpolator ACCELERATE_INTERPOLATOR = private static final AccelerateInterpolator ACCELERATE_INTERPOLATOR =
new AccelerateInterpolator(); new AccelerateInterpolator();
private static final DecelerateInterpolator DECELERATE_INTERPOLATOR = private static final DecelerateInterpolator DECELERATE_INTERPOLATOR =
new DecelerateInterpolator(); 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( final ObjectAnimator scaleXAnimation = ObjectAnimator.ofFloat(
previewTextView, View.SCALE_X, KEY_PREVIEW_START_ZOOM_IN_SCALE, previewTextView, View.SCALE_X, mParams.getShowUpStartScale(),
KEY_PREVIEW_END_ZOOM_IN_SCALE); KEY_PREVIEW_SHOW_UP_END_SCALE);
final ObjectAnimator scaleYAnimation = ObjectAnimator.ofFloat( final ObjectAnimator scaleYAnimation = ObjectAnimator.ofFloat(
previewTextView, View.SCALE_Y, KEY_PREVIEW_START_ZOOM_IN_SCALE, previewTextView, View.SCALE_Y, mParams.getShowUpStartScale(),
KEY_PREVIEW_END_ZOOM_IN_SCALE); KEY_PREVIEW_SHOW_UP_END_SCALE);
final AnimatorSet zoomInAnimation = new AnimatorSet(); final AnimatorSet showUpAnimation = new AnimatorSet();
zoomInAnimation.play(scaleXAnimation).with(scaleYAnimation); showUpAnimation.play(scaleXAnimation).with(scaleYAnimation);
// TODO: Implement preference option to control key preview animation duration. showUpAnimation.setDuration(mParams.getShowUpDuration());
zoomInAnimation.setDuration(mParams.mZoomInDuration); showUpAnimation.setInterpolator(DECELERATE_INTERPOLATOR);
zoomInAnimation.setInterpolator(DECELERATE_INTERPOLATOR); showUpAnimation.addListener(new AnimatorListenerAdapter() {
zoomInAnimation.addListener(new AnimatorListenerAdapter() {
@Override @Override
public void onAnimationStart(final Animator animation) { public void onAnimationStart(final Animator animation) {
showKeyPreview(key, previewTextView, false /* withAnimation */); 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( 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( final ObjectAnimator scaleYAnimation = ObjectAnimator.ofFloat(
previewTextView, View.SCALE_Y, KEY_PREVIEW_END_ZOOM_OUT_SCALE); previewTextView, View.SCALE_Y, mParams.getDismissEndScale());
final AnimatorSet zoomOutAnimation = new AnimatorSet(); final AnimatorSet dismissAnimation = new AnimatorSet();
zoomOutAnimation.play(scaleXAnimation).with(scaleYAnimation); dismissAnimation.play(scaleXAnimation).with(scaleYAnimation);
// TODO: Implement preference option to control key preview animation duration. final int dismissDuration = Math.min(
final int zoomOutDuration = Math.min(mParams.mZoomOutDuration, mParams.getLingerTimeout()); mParams.getDismissDuration(), mParams.getLingerTimeout());
zoomOutAnimation.setDuration(zoomOutDuration); dismissAnimation.setDuration(dismissDuration);
zoomOutAnimation.setInterpolator(ACCELERATE_INTERPOLATOR); dismissAnimation.setInterpolator(ACCELERATE_INTERPOLATOR);
zoomOutAnimation.addListener(new AnimatorListenerAdapter() { dismissAnimation.addListener(new AnimatorListenerAdapter() {
@Override @Override
public void onAnimationEnd(final Animator animation) { public void onAnimationEnd(final Animator animation) {
dismissKeyPreview(key, false /* withAnimation */); dismissKeyPreview(key, false /* withAnimation */);
} }
}); });
return zoomOutAnimation; return dismissAnimation;
} }
private static class KeyPreviewAnimations extends AnimatorListenerAdapter { private static class KeyPreviewAnimations extends AnimatorListenerAdapter {
private final Animator mZoomIn; private final Animator mShowUpAnimation;
private final Animator mZoomOut; private final Animator mDismissAnimation;
public KeyPreviewAnimations(final Animator zoomIn, final Animator zoomOut) { public KeyPreviewAnimations(final Animator showUpAnimation,
mZoomIn = zoomIn; final Animator dismissAnimation) {
mZoomOut = zoomOut; mShowUpAnimation = showUpAnimation;
mDismissAnimation = dismissAnimation;
} }
public void startZoomIn() { public void startShowUp() {
mZoomIn.start(); mShowUpAnimation.start();
} }
public void startZoomOut() { public void startDismiss() {
if (mZoomIn.isRunning()) { if (mShowUpAnimation.isRunning()) {
mZoomIn.addListener(this); mShowUpAnimation.addListener(this);
return; return;
} }
mZoomOut.start(); mDismissAnimation.start();
} }
@Override @Override
public void onAnimationEnd(final Animator animation) { 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 mLayoutId;
public final int mPreviewOffset; public final int mPreviewOffset;
public final int mPreviewHeight; public final int mPreviewHeight;
// TODO: Move those parameters to preferences. private int mShowUpDuration;
public final int mZoomInDuration; private int mDismissDuration;
public final int mZoomOutDuration; private float mShowUpStartScale;
private float mDismissEndScale;
private int mLingerTimeout; private int mLingerTimeout;
private boolean mShowPopup = true; private boolean mShowPopup = true;
@ -69,10 +70,6 @@ public final class KeyPreviewDrawParams {
if (mLayoutId == 0) { if (mLayoutId == 0) {
mShowPopup = false; mShowPopup = false;
} }
mZoomInDuration = mainKeyboardViewAttr.getInt(
R.styleable.MainKeyboardView_keyPreviewZoomInDuration, 0);
mZoomOutDuration = mainKeyboardViewAttr.getInt(
R.styleable.MainKeyboardView_keyPreviewZoomOutDuration, 0);
} }
public void setVisibleOffset(final int previewVisibleOffset) { public void setVisibleOffset(final int previewVisibleOffset) {
@ -117,4 +114,28 @@ public final class KeyPreviewDrawParams {
public int getLingerTimeout() { public int getLingerTimeout() {
return mLingerTimeout; 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.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.Bundle; import android.os.Bundle;
import android.os.Process; import android.os.Process;
import android.preference.CheckBoxPreference; 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.R;
import com.android.inputmethod.latin.debug.ExternalDictionaryGetterForDebug; import com.android.inputmethod.latin.debug.ExternalDictionaryGetterForDebug;
import com.android.inputmethod.latin.utils.ApplicationUtils; import com.android.inputmethod.latin.utils.ApplicationUtils;
import com.android.inputmethod.latin.utils.ResourceUtils;
public final class DebugSettings extends PreferenceFragment public final class DebugSettings extends PreferenceFragment
implements SharedPreferences.OnSharedPreferenceChangeListener { 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_STATISTICS_LOGGING = "enable_logging";
public static final String PREF_USE_ONLY_PERSONALIZATION_DICTIONARY_FOR_DEBUG = public static final String PREF_USE_ONLY_PERSONALIZATION_DICTIONARY_FOR_DEBUG =
"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_READ_EXTERNAL_DICTIONARY = "read_external_dictionary";
private static final String PREF_DUMP_CONTACTS_DICT = "dump_contacts_dict"; private static final String PREF_DUMP_CONTACTS_DICT = "dump_contacts_dict";
private static final String PREF_DUMP_USER_DICT = "dump_user_dict"; private static final String PREF_DUMP_USER_DICT = "dump_user_dict";
@ -101,6 +111,17 @@ public final class DebugSettings extends PreferenceFragment
dictDumpPrefClickListener); dictDumpPrefClickListener);
findPreference(PREF_DUMP_PERSONALIZATION_DICT).setOnPreferenceClickListener( findPreference(PREF_DUMP_PERSONALIZATION_DICT).setOnPreferenceClickListener(
dictDumpPrefClickListener); 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; mServiceNeedsRestart = false;
mDebugMode = (CheckBoxPreference) findPreference(PREF_DEBUG_MODE); mDebugMode = (CheckBoxPreference) findPreference(PREF_DEBUG_MODE);
@ -180,4 +201,92 @@ public final class DebugSettings extends PreferenceFragment
mDebugMode.setSummary(version); 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_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"; 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 Context mContext;
private Resources mRes; private Resources mRes;
private SharedPreferences mPrefs; private SharedPreferences mPrefs;
@ -301,8 +304,10 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
public static float readKeypressSoundVolume(final SharedPreferences prefs, public static float readKeypressSoundVolume(final SharedPreferences prefs,
final Resources res) { final Resources res) {
final float volume = prefs.getFloat(PREF_KEYPRESS_SOUND_VOLUME, -1.0f); final float volume = prefs.getFloat(
return (volume >= 0) ? volume : readDefaultKeypressSoundVolume(res); PREF_KEYPRESS_SOUND_VOLUME, UNDEFINED_PREFERENCE_VALUE_FLOAT);
return (volume != UNDEFINED_PREFERENCE_VALUE_FLOAT) ? volume
: readDefaultKeypressSoundVolume(res);
} }
public static float readDefaultKeypressSoundVolume(final Resources 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, public static int readKeyLongpressTimeout(final SharedPreferences prefs,
final Resources res) { final Resources res) {
final int ms = prefs.getInt(PREF_KEY_LONGPRESS_TIMEOUT, -1); final int milliseconds = prefs.getInt(
return (ms >= 0) ? ms : readDefaultKeyLongpressTimeout(res); PREF_KEY_LONGPRESS_TIMEOUT, UNDEFINED_PREFERENCE_VALUE_INT);
return (milliseconds != UNDEFINED_PREFERENCE_VALUE_INT) ? milliseconds
: readDefaultKeyLongpressTimeout(res);
} }
public static int readDefaultKeyLongpressTimeout(final Resources 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, public static int readKeypressVibrationDuration(final SharedPreferences prefs,
final Resources res) { final Resources res) {
final int ms = prefs.getInt(PREF_VIBRATION_DURATION_SETTINGS, -1); final int milliseconds = prefs.getInt(
return (ms >= 0) ? ms : readDefaultKeypressVibrationDuration(res); PREF_VIBRATION_DURATION_SETTINGS, UNDEFINED_PREFERENCE_VALUE_INT);
return (milliseconds != UNDEFINED_PREFERENCE_VALUE_INT) ? milliseconds
: readDefaultKeypressVibrationDuration(res);
} }
public static int readDefaultKeypressVibrationDuration(final Resources 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); 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) { public static boolean readUseFullscreenMode(final Resources res) {
return res.getBoolean(R.bool.config_use_fullscreen_mode); 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.R;
import com.android.inputmethod.latin.RichInputMethodManager; import com.android.inputmethod.latin.RichInputMethodManager;
import com.android.inputmethod.latin.utils.AsyncResultHolder; import com.android.inputmethod.latin.utils.AsyncResultHolder;
import com.android.inputmethod.latin.utils.ResourceUtils;
import com.android.inputmethod.latin.utils.TargetPackageInfoGetterTask; import com.android.inputmethod.latin.utils.TargetPackageInfoGetterTask;
import java.util.Arrays; import java.util.Arrays;
@ -93,6 +94,10 @@ public final class SettingsValues {
// Debug settings // Debug settings
public final boolean mIsInternal; 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, public SettingsValues(final Context context, final SharedPreferences prefs, final Resources res,
final InputAttributes inputAttributes) { final InputAttributes inputAttributes) {
@ -149,6 +154,20 @@ public final class SettingsValues {
AdditionalFeaturesSettingUtils.readAdditionalFeaturesPreferencesIntoArray( AdditionalFeaturesSettingUtils.readAdditionalFeaturesPreferencesIntoArray(
prefs, mAdditionalFeaturesSettingValues); prefs, mAdditionalFeaturesSettingValues);
mIsInternal = Settings.isInternal(prefs); 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( mUseOnlyPersonalizationDictionaryForDebug = prefs.getBoolean(
DebugSettings.PREF_USE_ONLY_PERSONALIZATION_DICTIONARY_FOR_DEBUG, false); DebugSettings.PREF_USE_ONLY_PERSONALIZATION_DICTIONARY_FOR_DEBUG, false);
mDisplayOrientation = res.getConfiguration().orientation; mDisplayOrientation = res.getConfiguration().orientation;

View File

@ -260,6 +260,10 @@ public final class ResourceUtils {
return dimension >= 0; 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) { public static float getFraction(final TypedArray a, final int index, final float defValue) {
final TypedValue value = a.peekValue(index); final TypedValue value = a.peekValue(index);
if (value == null || !isFractionValue(value)) { if (value == null || !isFractionValue(value)) {