Merge "Add advanced options to turn on/off the gesture trail and text preview" into jb-mr1-dev

main
Tadashi G. Takaoka 2012-07-30 00:22:40 -07:00 committed by Android (Google) Code Review
commit 293f062c26
8 changed files with 98 additions and 42 deletions

View File

@ -111,10 +111,16 @@
<!-- Description for "next word suggestion" option. This displays suggestions even when there is no input, based on the previous word. --> <!-- Description for "next word suggestion" option. This displays suggestions even when there is no input, based on the previous word. -->
<string name="bigram_prediction_summary">Based on previous word</string> <string name="bigram_prediction_summary">Based on previous word</string>
<!-- Option to enable gesture input. The user can input a word by tracing the letters of a word without releasing the finger from the screen. [CHAR LIMIT=20]--> <!-- Option to enable gesture input. The user can input a word by tracing the letters of a word without releasing the finger from the screen. [CHAR LIMIT=30]-->
<string name="gesture_input">Gesture input</string> <string name="gesture_input">Gesture input</string>
<!-- Description for "gesture_input" option. The user can input a word by tracing the letters of a word without releasing the finger from the screen. [CHAR LIMIT=65]--> <!-- Description for "gesture_input" option. The user can input a word by tracing the letters of a word without releasing the finger from the screen. [CHAR LIMIT=65]-->
<string name="gesture_input_summary">Input a word by tracing the letters of a word</string> <string name="gesture_input_summary">Input a word by tracing the letters of a word</string>
<!-- Option to enable gesture trail preview. The user can see a trail of the gesture during gesture input. [CHAR LIMIT=30]-->
<string name="gesture_preview_trail">Show gesture trail</string>
<!-- Option to enable gesture floating text preview. The user can see a suggested word floating under the moving finger during a gesture input. [CHAR LIMIT=30]-->
<string name="gesture_floating_preview_text">Show gesture word</string>
<!-- Description for "gesture_floating_preview_text" option. The user can see a suggested word floating under the moving finger during a gesture input. [CHAR LIMIT=65]-->
<string name="gesture_floating_preview_text_summary">Show floating preview word with gesture</string>
<!-- Indicates that a word has been added to the dictionary --> <!-- Indicates that a word has been added to the dictionary -->
<string name="added_word"><xliff:g id="word">%s</xliff:g> : Saved</string> <string name="added_word"><xliff:g id="word">%s</xliff:g> : Saved</string>

View File

@ -101,6 +101,12 @@
android:key="pref_advanced_settings" android:key="pref_advanced_settings"
android:title="@string/advanced_settings" android:title="@string/advanced_settings"
android:summary="@string/advanced_settings_summary"> android:summary="@string/advanced_settings_summary">
<CheckBoxPreference
android:key="pref_key_use_contacts_dict"
android:title="@string/use_contacts_dict"
android:summary="@string/use_contacts_dict_summary"
android:persistent="true"
android:defaultValue="true" />
<CheckBoxPreference <CheckBoxPreference
android:key="pref_suppress_language_switch_key" android:key="pref_suppress_language_switch_key"
android:title="@string/suppress_language_switch_key" android:title="@string/suppress_language_switch_key"
@ -120,18 +126,23 @@
<ListPreference <ListPreference
android:key="pref_key_preview_popup_dismiss_delay" android:key="pref_key_preview_popup_dismiss_delay"
android:title="@string/key_preview_popup_dismiss_delay" /> android:title="@string/key_preview_popup_dismiss_delay" />
<CheckBoxPreference
android:key="pref_key_use_contacts_dict"
android:title="@string/use_contacts_dict"
android:summary="@string/use_contacts_dict_summary"
android:persistent="true"
android:defaultValue="true" />
<PreferenceScreen <PreferenceScreen
android:key="pref_vibration_duration_settings" android:key="pref_vibration_duration_settings"
android:title="@string/prefs_keypress_vibration_duration_settings"/> android:title="@string/prefs_keypress_vibration_duration_settings"/>
<PreferenceScreen <PreferenceScreen
android:key="pref_keypress_sound_volume" android:key="pref_keypress_sound_volume"
android:title="@string/prefs_keypress_sound_volume_settings" /> android:title="@string/prefs_keypress_sound_volume_settings" />
<CheckBoxPreference
android:key="pref_gesture_preview_trail"
android:title="@string/gesture_preview_trail"
android:persistent="true"
android:defaultValue="true" />
<CheckBoxPreference
android:key="pref_gesture_floating_preview_text"
android:title="@string/gesture_floating_preview_text"
android:summary="@string/gesture_floating_preview_text_summary"
android:persistent="true"
android:defaultValue="true" />
</PreferenceScreen> </PreferenceScreen>
</PreferenceCategory> </PreferenceCategory>
</PreferenceScreen> </PreferenceScreen>

View File

@ -432,8 +432,11 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
return mShowKeyPreviewPopup; return mShowKeyPreviewPopup;
} }
public void setGestureHandlingMode(boolean shouldHandleGesture) { public void setGestureHandlingMode(boolean shouldHandleGesture,
boolean drawsGesturePreviewTrail, boolean drawsGestureFloatingPreviewText) {
mShouldHandleGesture = shouldHandleGesture; mShouldHandleGesture = shouldHandleGesture;
mPreviewPlacerView.setGesturePreviewMode(
drawsGesturePreviewTrail, drawsGestureFloatingPreviewText);
} }
@Override @Override
@ -896,15 +899,12 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
} }
public void showGesturePreviewText(String gesturePreviewText) { public void showGesturePreviewText(String gesturePreviewText) {
// TDOD: Add user settings option to control drawing gesture trail.
locatePreviewPlacerView(); locatePreviewPlacerView();
mPreviewPlacerView.setGesturePreviewText(gesturePreviewText); mPreviewPlacerView.setGesturePreviewText(gesturePreviewText);
mPreviewPlacerView.invalidate();
} }
@Override @Override
public void showGestureTrail(PointerTracker tracker) { public void showGestureTrail(PointerTracker tracker) {
// TDOD: Add user settings option to control drawing gesture trail.
locatePreviewPlacerView(); locatePreviewPlacerView();
mPreviewPlacerView.invalidatePointer(tracker); mPreviewPlacerView.invalidatePointer(tracker);
} }

View File

@ -481,8 +481,10 @@ public class MainKeyboardView extends KeyboardView implements PointerTracker.Key
} }
@Override @Override
public void setGestureHandlingMode(final boolean shouldHandleGesture) { public void setGestureHandlingMode(final boolean shouldHandleGesture,
super.setGestureHandlingMode(shouldHandleGesture); boolean drawsGesturePreviewTrail, boolean drawsGestureFloatingPreviewText) {
super.setGestureHandlingMode(shouldHandleGesture, drawsGesturePreviewTrail,
drawsGestureFloatingPreviewText);
PointerTracker.setKeyDetector(mKeyDetector, shouldHandleGesture); PointerTracker.setKeyDetector(mKeyDetector, shouldHandleGesture);
} }

View File

@ -51,6 +51,8 @@ public class PreviewPlacerView extends RelativeLayout {
private final SparseArray<PointerTracker> mPointers = new SparseArray<PointerTracker>(); private final SparseArray<PointerTracker> mPointers = new SparseArray<PointerTracker>();
private String mGesturePreviewText; private String mGesturePreviewText;
private boolean mDrawsGesturePreviewTrail;
private boolean mDrawsGestureFloatingPreviewText;
public PreviewPlacerView(Context context) { public PreviewPlacerView(Context context) {
super(context); super(context);
@ -89,6 +91,12 @@ public class PreviewPlacerView extends RelativeLayout {
mYOrigin = y; mYOrigin = y;
} }
public void setGesturePreviewMode(boolean drawsGesturePreviewTrail,
boolean drawsGestureFloatingPreviewText) {
mDrawsGesturePreviewTrail = drawsGesturePreviewTrail;
mDrawsGestureFloatingPreviewText = drawsGestureFloatingPreviewText;
}
public void invalidatePointer(PointerTracker tracker) { public void invalidatePointer(PointerTracker tracker) {
synchronized (mPointers) { synchronized (mPointers) {
mPointers.put(tracker.mPointerId, tracker); mPointers.put(tracker.mPointerId, tracker);
@ -100,18 +108,19 @@ public class PreviewPlacerView extends RelativeLayout {
@Override @Override
public void onDraw(Canvas canvas) { public void onDraw(Canvas canvas) {
super.onDraw(canvas); super.onDraw(canvas);
// TDOD: Add user settings option to control drawing gesture trail and gesture preview.
synchronized (mPointers) { synchronized (mPointers) {
canvas.translate(mXOrigin, mYOrigin); canvas.translate(mXOrigin, mYOrigin);
final int trackerCount = mPointers.size(); final int trackerCount = mPointers.size();
boolean floatingPreviewHasDrawn = false; boolean hasDrawnFloatingPreviewText = false;
for (int index = 0; index < trackerCount; index++) { for (int index = 0; index < trackerCount; index++) {
final PointerTracker tracker = mPointers.valueAt(index); final PointerTracker tracker = mPointers.valueAt(index);
if (mDrawsGesturePreviewTrail) {
tracker.drawGestureTrail(canvas, mGesturePaint); tracker.drawGestureTrail(canvas, mGesturePaint);
}
// TODO: Figure out more cleaner way to draw gesture preview text. // TODO: Figure out more cleaner way to draw gesture preview text.
if (!floatingPreviewHasDrawn) { if (mDrawsGestureFloatingPreviewText && !hasDrawnFloatingPreviewText) {
drawGesturePreviewText(canvas, tracker, mGesturePreviewText); drawGesturePreviewText(canvas, tracker, mGesturePreviewText);
floatingPreviewHasDrawn = true; hasDrawnFloatingPreviewText = true;
} }
} }
canvas.translate(-mXOrigin, -mYOrigin); canvas.translate(-mXOrigin, -mYOrigin);

View File

@ -2095,7 +2095,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
if (keyboardView != null) { if (keyboardView != null) {
final boolean shouldHandleGesture = mCurrentSettings.mGestureInputEnabled final boolean shouldHandleGesture = mCurrentSettings.mGestureInputEnabled
&& mIsMainDictionaryAvailable; && mIsMainDictionaryAvailable;
keyboardView.setGestureHandlingMode(shouldHandleGesture); keyboardView.setGestureHandlingMode(shouldHandleGesture,
mCurrentSettings.mGesturePreviewTrailEnabled,
mCurrentSettings.mGestureFloatingPreviewTextEnabled);
} }
} }

View File

@ -62,6 +62,7 @@ public class Settings extends InputMethodSettingsFragment
public static final String PREF_LAST_USER_DICTIONARY_WRITE_TIME = public static final String PREF_LAST_USER_DICTIONARY_WRITE_TIME =
"last_user_dictionary_write_time"; "last_user_dictionary_write_time";
public static final String PREF_ADVANCED_SETTINGS = "pref_advanced_settings"; public static final String PREF_ADVANCED_SETTINGS = "pref_advanced_settings";
public static final String PREF_KEY_USE_CONTACTS_DICT = "pref_key_use_contacts_dict";
public static final String PREF_SUPPRESS_LANGUAGE_SWITCH_KEY = public static final String PREF_SUPPRESS_LANGUAGE_SWITCH_KEY =
"pref_suppress_language_switch_key"; "pref_suppress_language_switch_key";
public static final String PREF_INCLUDE_OTHER_IMES_IN_LANGUAGE_SWITCH_LIST = public static final String PREF_INCLUDE_OTHER_IMES_IN_LANGUAGE_SWITCH_LIST =
@ -69,13 +70,15 @@ public class Settings extends InputMethodSettingsFragment
public static final String PREF_CUSTOM_INPUT_STYLES = "custom_input_styles"; public static final String PREF_CUSTOM_INPUT_STYLES = "custom_input_styles";
public static final String PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY = public static final String PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY =
"pref_key_preview_popup_dismiss_delay"; "pref_key_preview_popup_dismiss_delay";
public static final String PREF_KEY_USE_CONTACTS_DICT = "pref_key_use_contacts_dict";
public static final String PREF_BIGRAM_PREDICTIONS = "next_word_prediction"; public static final String PREF_BIGRAM_PREDICTIONS = "next_word_prediction";
public static final String PREF_GESTURE_INPUT = "gesture_input"; public static final String PREF_GESTURE_INPUT = "gesture_input";
public static final String PREF_VIBRATION_DURATION_SETTINGS = public static final String PREF_VIBRATION_DURATION_SETTINGS =
"pref_vibration_duration_settings"; "pref_vibration_duration_settings";
public static final String PREF_KEYPRESS_SOUND_VOLUME = public static final String PREF_KEYPRESS_SOUND_VOLUME =
"pref_keypress_sound_volume"; "pref_keypress_sound_volume";
public static final String PREF_GESTURE_PREVIEW_TRAIL = "pref_gesture_preview_trail";
public static final String PREF_GESTURE_FLOATING_PREVIEW_TEXT =
"pref_gesture_floating_preview_text";
public static final String PREF_INPUT_LANGUAGE = "input_language"; public static final String PREF_INPUT_LANGUAGE = "input_language";
public static final String PREF_SELECTED_LANGUAGES = "selected_languages"; public static final String PREF_SELECTED_LANGUAGES = "selected_languages";
@ -94,13 +97,17 @@ public class Settings extends InputMethodSettingsFragment
private TextView mKeypressVibrationDurationSettingsTextView; private TextView mKeypressVibrationDurationSettingsTextView;
private TextView mKeypressSoundVolumeSettingsTextView; private TextView mKeypressSoundVolumeSettingsTextView;
private static void setPreferenceEnabled(Preference preference, boolean enabled) {
if (preference != null) {
preference.setEnabled(enabled);
}
}
private void ensureConsistencyOfAutoCorrectionSettings() { private void ensureConsistencyOfAutoCorrectionSettings() {
final String autoCorrectionOff = getResources().getString( final String autoCorrectionOff = getResources().getString(
R.string.auto_correction_threshold_mode_index_off); R.string.auto_correction_threshold_mode_index_off);
final String currentSetting = mAutoCorrectionThresholdPreference.getValue(); final String currentSetting = mAutoCorrectionThresholdPreference.getValue();
if (null != mBigramPrediction) { setPreferenceEnabled(mBigramPrediction, !currentSetting.equals(autoCorrectionOff));
mBigramPrediction.setEnabled(!currentSetting.equals(autoCorrectionOff));
}
} }
@Override @Override
@ -180,13 +187,11 @@ public class Settings extends InputMethodSettingsFragment
if (null == mKeyPreviewPopupDismissDelay.getValue()) { if (null == mKeyPreviewPopupDismissDelay.getValue()) {
mKeyPreviewPopupDismissDelay.setValue(popupDismissDelayDefaultValue); mKeyPreviewPopupDismissDelay.setValue(popupDismissDelayDefaultValue);
} }
mKeyPreviewPopupDismissDelay.setEnabled( setPreferenceEnabled(mKeyPreviewPopupDismissDelay,
SettingsValues.isKeyPreviewPopupEnabled(prefs, res)); SettingsValues.isKeyPreviewPopupEnabled(prefs, res));
} }
final CheckBoxPreference includeOtherImesInLanguageSwitchList = setPreferenceEnabled(findPreference(PREF_INCLUDE_OTHER_IMES_IN_LANGUAGE_SWITCH_LIST),
(CheckBoxPreference)findPreference(PREF_INCLUDE_OTHER_IMES_IN_LANGUAGE_SWITCH_LIST);
includeOtherImesInLanguageSwitchList.setEnabled(
!SettingsValues.isLanguageSwitchKeySupressed(prefs)); !SettingsValues.isLanguageSwitchKeySupressed(prefs));
final PreferenceScreen dictionaryLink = final PreferenceScreen dictionaryLink =
@ -200,10 +205,19 @@ public class Settings extends InputMethodSettingsFragment
final boolean gestureInputEnabledByBuildConfig = res.getBoolean( final boolean gestureInputEnabledByBuildConfig = res.getBoolean(
R.bool.config_gesture_input_enabled_by_build_config); R.bool.config_gesture_input_enabled_by_build_config);
final Preference gesturePreviewTrail = findPreference(PREF_GESTURE_PREVIEW_TRAIL);
final Preference gestureFloatingPreviewText = findPreference(
PREF_GESTURE_FLOATING_PREVIEW_TEXT);
if (!gestureInputEnabledByBuildConfig) { if (!gestureInputEnabledByBuildConfig) {
final Preference gestureInputPref = findPreference(PREF_GESTURE_INPUT); miscSettings.removePreference(findPreference(PREF_GESTURE_INPUT));
miscSettings.removePreference(gestureInputPref); miscSettings.removePreference(gesturePreviewTrail);
miscSettings.removePreference(gestureFloatingPreviewText);
} else {
final boolean gestureInputEnabledByUser = prefs.getBoolean(PREF_GESTURE_INPUT, true);
setPreferenceEnabled(gesturePreviewTrail, gestureInputEnabledByUser);
setPreferenceEnabled(gestureFloatingPreviewText, gestureInputEnabledByUser);
} }
final boolean showUsabilityStudyModeOption = final boolean showUsabilityStudyModeOption =
res.getBoolean(R.bool.config_enable_usability_study_mode_option) res.getBoolean(R.bool.config_enable_usability_study_mode_option)
|| ProductionFlag.IS_EXPERIMENTAL || ENABLE_EXPERIMENTAL_SETTINGS; || ProductionFlag.IS_EXPERIMENTAL || ENABLE_EXPERIMENTAL_SETTINGS;
@ -277,17 +291,22 @@ public class Settings extends InputMethodSettingsFragment
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
(new BackupManager(getActivity())).dataChanged(); (new BackupManager(getActivity())).dataChanged();
if (key.equals(PREF_POPUP_ON)) { if (key.equals(PREF_POPUP_ON)) {
final ListPreference popupDismissDelay = setPreferenceEnabled(findPreference(PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY),
(ListPreference)findPreference(PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY); prefs.getBoolean(PREF_POPUP_ON, true));
if (null != popupDismissDelay) {
popupDismissDelay.setEnabled(prefs.getBoolean(PREF_POPUP_ON, true));
}
} else if (key.equals(PREF_SUPPRESS_LANGUAGE_SWITCH_KEY)) { } else if (key.equals(PREF_SUPPRESS_LANGUAGE_SWITCH_KEY)) {
final CheckBoxPreference includeOtherImesInLanguageSwicthList = setPreferenceEnabled(findPreference(PREF_INCLUDE_OTHER_IMES_IN_LANGUAGE_SWITCH_LIST),
(CheckBoxPreference)findPreference(
PREF_INCLUDE_OTHER_IMES_IN_LANGUAGE_SWITCH_LIST);
includeOtherImesInLanguageSwicthList.setEnabled(
!SettingsValues.isLanguageSwitchKeySupressed(prefs)); !SettingsValues.isLanguageSwitchKeySupressed(prefs));
} else if (key.equals(PREF_GESTURE_INPUT)) {
final boolean gestureInputEnabledByConfig = getResources().getBoolean(
R.bool.config_gesture_input_enabled_by_build_config);
if (gestureInputEnabledByConfig) {
final boolean gestureInputEnabledByUser = prefs.getBoolean(
PREF_GESTURE_INPUT, true);
setPreferenceEnabled(findPreference(PREF_GESTURE_PREVIEW_TRAIL),
gestureInputEnabledByUser);
setPreferenceEnabled(findPreference(PREF_GESTURE_FLOATING_PREVIEW_TEXT),
gestureInputEnabledByUser);
}
} }
ensureConsistencyOfAutoCorrectionSettings(); ensureConsistencyOfAutoCorrectionSettings();
updateVoiceModeSummary(); updateVoiceModeSummary();
@ -335,16 +354,18 @@ public class Settings extends InputMethodSettingsFragment
private void refreshEnablingsOfKeypressSoundAndVibrationSettings( private void refreshEnablingsOfKeypressSoundAndVibrationSettings(
SharedPreferences sp, Resources res) { SharedPreferences sp, Resources res) {
if (mKeypressVibrationDurationSettingsPref != null) { if (mKeypressVibrationDurationSettingsPref != null) {
final boolean hasVibrator = VibratorUtils.getInstance(getActivity()).hasVibrator(); final boolean hasVibratorHardware = VibratorUtils.getInstance(getActivity())
final boolean vibrateOn = hasVibrator && sp.getBoolean(Settings.PREF_VIBRATE_ON, .hasVibrator();
final boolean vibrateOnByUser = sp.getBoolean(Settings.PREF_VIBRATE_ON,
res.getBoolean(R.bool.config_default_vibration_enabled)); res.getBoolean(R.bool.config_default_vibration_enabled));
mKeypressVibrationDurationSettingsPref.setEnabled(vibrateOn); setPreferenceEnabled(mKeypressVibrationDurationSettingsPref,
hasVibratorHardware && vibrateOnByUser);
} }
if (mKeypressSoundVolumeSettingsPref != null) { if (mKeypressSoundVolumeSettingsPref != null) {
final boolean soundOn = sp.getBoolean(Settings.PREF_SOUND_ON, final boolean soundOn = sp.getBoolean(Settings.PREF_SOUND_ON,
res.getBoolean(R.bool.config_default_sound_enabled)); res.getBoolean(R.bool.config_default_sound_enabled));
mKeypressSoundVolumeSettingsPref.setEnabled(soundOn); setPreferenceEnabled(mKeypressSoundVolumeSettingsPref, soundOn);
} }
} }

View File

@ -84,6 +84,8 @@ public class SettingsValues {
private final float mKeypressSoundVolumeRawValue; private final float mKeypressSoundVolumeRawValue;
private final InputMethodSubtype[] mAdditionalSubtypes; private final InputMethodSubtype[] mAdditionalSubtypes;
public final boolean mGestureInputEnabled; public final boolean mGestureInputEnabled;
public final boolean mGesturePreviewTrailEnabled;
public final boolean mGestureFloatingPreviewTextEnabled;
// From the input box // From the input box
private final InputAttributes mInputAttributes; private final InputAttributes mInputAttributes;
@ -174,6 +176,9 @@ public class SettingsValues {
R.bool.config_gesture_input_enabled_by_build_config); R.bool.config_gesture_input_enabled_by_build_config);
mGestureInputEnabled = gestureInputEnabledByBuildConfig mGestureInputEnabled = gestureInputEnabledByBuildConfig
&& prefs.getBoolean(Settings.PREF_GESTURE_INPUT, true); && prefs.getBoolean(Settings.PREF_GESTURE_INPUT, true);
mGesturePreviewTrailEnabled = prefs.getBoolean(Settings.PREF_GESTURE_PREVIEW_TRAIL, true);
mGestureFloatingPreviewTextEnabled = prefs.getBoolean(
Settings.PREF_GESTURE_FLOATING_PREVIEW_TEXT, true);
mCorrectionEnabled = mAutoCorrectEnabled && !mInputAttributes.mInputTypeNoAutoCorrect; mCorrectionEnabled = mAutoCorrectEnabled && !mInputAttributes.mInputTypeNoAutoCorrect;
mSuggestionVisibility = createSuggestionVisibility(res); mSuggestionVisibility = createSuggestionVisibility(res);
} }