aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin')
-rw-r--r--java/src/com/android/inputmethod/latin/AudioAndHapticFeedbackManager.java2
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java31
-rw-r--r--java/src/com/android/inputmethod/latin/PositionalInfoForUserDictPendingAddition.java10
-rw-r--r--java/src/com/android/inputmethod/latin/SeekBarDialog.java201
-rw-r--r--java/src/com/android/inputmethod/latin/SeekBarDialogPreference.java123
-rw-r--r--java/src/com/android/inputmethod/latin/SettingsFragment.java176
-rw-r--r--java/src/com/android/inputmethod/latin/StringUtils.java31
-rw-r--r--java/src/com/android/inputmethod/latin/UserBinaryDictionary.java6
-rw-r--r--java/src/com/android/inputmethod/latin/WordComposer.java2
9 files changed, 241 insertions, 341 deletions
diff --git a/java/src/com/android/inputmethod/latin/AudioAndHapticFeedbackManager.java b/java/src/com/android/inputmethod/latin/AudioAndHapticFeedbackManager.java
index 8a1613120..f859d0ba3 100644
--- a/java/src/com/android/inputmethod/latin/AudioAndHapticFeedbackManager.java
+++ b/java/src/com/android/inputmethod/latin/AudioAndHapticFeedbackManager.java
@@ -29,8 +29,6 @@ import android.view.View;
* complexity of settings and the like.
*/
public final class AudioAndHapticFeedbackManager {
- public static final int MAX_KEYPRESS_VIBRATION_DURATION = 250; // millisecond
-
private AudioManager mAudioManager;
private Vibrator mVibrator;
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index d02c4df7e..f4b7a1708 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -773,7 +773,8 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
// to the user dictionary.
if (null != mPositionalInfoForUserDictPendingAddition
&& mPositionalInfoForUserDictPendingAddition.tryReplaceWithActualWord(
- mConnection, editorInfo, mLastSelectionEnd)) {
+ mConnection, editorInfo, mLastSelectionEnd,
+ mSubtypeSwitcher.getCurrentSubtypeLocale())) {
mPositionalInfoForUserDictPendingAddition = null;
}
// If tryReplaceWithActualWord returns false, we don't know what word was
@@ -1223,11 +1224,17 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
mPositionalInfoForUserDictPendingAddition = null;
return;
}
+ final String wordToEdit;
+ if (StringUtils.isAutoCapsMode(mLastComposedWord.mCapitalizedMode)) {
+ wordToEdit = word.toLowerCase(mSubtypeSwitcher.getCurrentSubtypeLocale());
+ } else {
+ wordToEdit = word;
+ }
mPositionalInfoForUserDictPendingAddition =
new PositionalInfoForUserDictPendingAddition(
- word, mLastSelectionEnd, getCurrentInputEditorInfo(),
+ wordToEdit, mLastSelectionEnd, getCurrentInputEditorInfo(),
mLastComposedWord.mCapitalizedMode);
- mUserDictionary.addWordToUserDictionary(word, 128);
+ mUserDictionary.addWordToUserDictionary(wordToEdit);
}
public void onWordAddedToUserDictionary(final String newSpelling) {
@@ -1240,7 +1247,8 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
}
mPositionalInfoForUserDictPendingAddition.setActualWordBeingAdded(newSpelling);
if (mPositionalInfoForUserDictPendingAddition.tryReplaceWithActualWord(
- mConnection, getCurrentInputEditorInfo(), mLastSelectionEnd)) {
+ mConnection, getCurrentInputEditorInfo(), mLastSelectionEnd,
+ mSubtypeSwitcher.getCurrentSubtypeLocale())) {
mPositionalInfoForUserDictPendingAddition = null;
}
}
@@ -1476,7 +1484,10 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
Stats.onAutoCorrection("", mWordComposer.getTypedWord(), " ", mWordComposer);
}
}
- if (mWordComposer.size() <= 1) {
+ final int wordComposerSize = mWordComposer.size();
+ // Since isComposingWord() is true, the size is at least 1.
+ final int lastChar = mWordComposer.getCodeAt(wordComposerSize - 1);
+ if (wordComposerSize <= 1) {
// We auto-correct the previous (typed, not gestured) string iff it's one character
// long. The reason for this is, even in the middle of gesture typing, you'll still
// tap one-letter words and you want them auto-corrected (typically, "i" in English
@@ -1490,8 +1501,14 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
}
mExpectingUpdateSelection = true;
// The following is necessary for the case where the user typed something but didn't
- // manual pick it and didn't input any separator.
- mSpaceState = SPACE_STATE_PHANTOM;
+ // manual pick it and didn't input any separator: we want to put a space between what
+ // has been entered and the coming gesture input result, so we go into phantom space
+ // state, which will be promoted to a space when the gesture result is committed. But if
+ // the current input ends in a word connector on the other hand, then we want to have
+ // the next input stick to the current input so we don't switch to phantom space state.
+ if (!mSettings.getCurrent().isWordConnector(lastChar)) {
+ mSpaceState = SPACE_STATE_PHANTOM;
+ }
} else {
final int codePointBeforeCursor = mConnection.getCodePointBeforeCursor();
if (mSettings.getCurrent().isUsuallyFollowedBySpace(codePointBeforeCursor)) {
diff --git a/java/src/com/android/inputmethod/latin/PositionalInfoForUserDictPendingAddition.java b/java/src/com/android/inputmethod/latin/PositionalInfoForUserDictPendingAddition.java
index a33cefcd6..8493ef669 100644
--- a/java/src/com/android/inputmethod/latin/PositionalInfoForUserDictPendingAddition.java
+++ b/java/src/com/android/inputmethod/latin/PositionalInfoForUserDictPendingAddition.java
@@ -18,6 +18,8 @@ package com.android.inputmethod.latin;
import android.view.inputmethod.EditorInfo;
+import java.util.Locale;
+
/**
* Holder class for data about a word already committed but that may still be edited.
*
@@ -70,10 +72,11 @@ public final class PositionalInfoForUserDictPendingAddition {
* @param connection The RichInputConnection through which to contact the editor.
* @param editorInfo Information pertaining to the editor we are currently in.
* @param currentCursorPosition The current cursor position, for checking purposes.
+ * @param locale The locale for changing case, if necessary
* @return true if the edit has been successfully made, false if we need to try again later
*/
public boolean tryReplaceWithActualWord(final RichInputConnection connection,
- final EditorInfo editorInfo, final int currentCursorPosition) {
+ final EditorInfo editorInfo, final int currentCursorPosition, final Locale locale) {
// If we still don't know the actual word being added, we need to try again later.
if (null == mActualWordBeingAdded) return false;
// The entered text and the registered text were the same anyway : we can
@@ -92,9 +95,12 @@ public final class PositionalInfoForUserDictPendingAddition {
// so that it won't be tried again
if (currentCursorPosition != mCursorPos) return true;
// We have made all the checks : do the replacement and report success
+ // If this was auto-capitalized, we need to restore the case before committing
+ final String wordWithCaseFixed = StringUtils.applyAutoCapsMode(mActualWordBeingAdded,
+ mCapitalizedMode, locale);
connection.setComposingRegion(currentCursorPosition - mOriginalWord.length(),
currentCursorPosition);
- connection.commitText(mActualWordBeingAdded, mActualWordBeingAdded.length());
+ connection.commitText(wordWithCaseFixed, wordWithCaseFixed.length());
return true;
}
}
diff --git a/java/src/com/android/inputmethod/latin/SeekBarDialog.java b/java/src/com/android/inputmethod/latin/SeekBarDialog.java
deleted file mode 100644
index c736d1b1a..000000000
--- a/java/src/com/android/inputmethod/latin/SeekBarDialog.java
+++ /dev/null
@@ -1,201 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package com.android.inputmethod.latin;
-
-import android.app.AlertDialog;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.widget.SeekBar;
-import android.widget.SeekBar.OnSeekBarChangeListener;
-import android.widget.TextView;
-
-public final class SeekBarDialog implements DialogInterface.OnClickListener,
- OnSeekBarChangeListener {
- public interface Listener {
- public void onPositiveButtonClick(final SeekBarDialog dialog);
- public void onNegativeButtonClick(final SeekBarDialog dialog);
- public void onNeutralButtonClick(final SeekBarDialog dialog);
- public void onDismiss(final SeekBarDialog dialog);
- public void onProgressChanged(final SeekBarDialog dialog);
- public void onStartTrackingTouch(final SeekBarDialog dialog);
- public void onStopTrackingTouch(final SeekBarDialog dialog);
- }
-
- public static class Adapter implements Listener {
- @Override
- public void onPositiveButtonClick(final SeekBarDialog dialog) {}
- @Override
- public void onNegativeButtonClick(final SeekBarDialog dialog) {}
- @Override
- public void onNeutralButtonClick(final SeekBarDialog dialog) {}
- @Override
- public void onDismiss(final SeekBarDialog dialog) {}
- @Override
- public void onProgressChanged(final SeekBarDialog dialog) {}
- @Override
- public void onStartTrackingTouch(final SeekBarDialog dialog) {}
- @Override
- public void onStopTrackingTouch(final SeekBarDialog dialog) {}
- }
-
- private static final Listener EMPTY_ADAPTER = new Adapter();
-
- private final AlertDialog mDialog;
- private final Listener mListener;
- private final TextView mValueView;
- private final SeekBar mSeekBar;
- private final String mValueFormat;
-
- private int mValue;
-
- private SeekBarDialog(final Builder builder) {
- final AlertDialog.Builder dialogBuilder = builder.mDialogBuilder;
- dialogBuilder.setView(builder.mView);
- dialogBuilder.setPositiveButton(android.R.string.ok, this);
- dialogBuilder.setNegativeButton(android.R.string.cancel, this);
- if (builder.mNeutralButtonTextResId != 0) {
- dialogBuilder.setNeutralButton(builder.mNeutralButtonTextResId, this);
- }
- mDialog = dialogBuilder.create();
- mListener = (builder.mListener == null) ? EMPTY_ADAPTER : builder.mListener;
- mValueView = (TextView)builder.mView.findViewById(R.id.seek_bar_dialog_value);
- mSeekBar = (SeekBar)builder.mView.findViewById(R.id.seek_bar_dialog_bar);
- mSeekBar.setMax(builder.mMaxValue);
- mSeekBar.setOnSeekBarChangeListener(this);
- if (builder.mValueFormatResId == 0) {
- mValueFormat = "%s";
- } else {
- mValueFormat = mDialog.getContext().getString(builder.mValueFormatResId);
- }
- }
-
- public void setValue(final int value, final boolean fromUser) {
- mValue = value;
- mValueView.setText(String.format(mValueFormat, value));
- if (!fromUser) {
- mSeekBar.setProgress(value);
- }
- }
-
- public int getValue() {
- return mValue;
- }
-
- public CharSequence getValueText() {
- return mValueView.getText();
- }
-
- public void show() {
- mDialog.show();
- }
-
- public void dismiss() {
- mDialog.dismiss();
- }
-
- @Override
- public void onClick(final DialogInterface dialog, final int which) {
- switch (which) {
- case DialogInterface.BUTTON_POSITIVE:
- mListener.onPositiveButtonClick(this);
- break;
- case DialogInterface.BUTTON_NEGATIVE:
- mListener.onNegativeButtonClick(this);
- break;
- case DialogInterface.BUTTON_NEUTRAL:
- mListener.onNeutralButtonClick(this);
- break;
- default:
- return;
- }
- mListener.onDismiss(this);
- }
-
- @Override
- public void onProgressChanged(final SeekBar seekBar, final int progress,
- final boolean fromUser) {
- setValue(progress, fromUser);
- if (fromUser) {
- mListener.onProgressChanged(this);
- }
- }
-
- @Override
- public void onStartTrackingTouch(final SeekBar seekBar) {
- mListener.onStartTrackingTouch(this);
- }
-
- @Override
- public void onStopTrackingTouch(final SeekBar seekBar) {
- mListener.onStopTrackingTouch(this);
- }
-
- public static final class Builder {
- final AlertDialog.Builder mDialogBuilder;
- final View mView;
-
- int mNeutralButtonTextResId;
- int mMaxValue;
- int mValueFormatResId;
- int mValue;
- Listener mListener;
-
- public Builder(final Context context) {
- mDialogBuilder = new AlertDialog.Builder(context);
- mView = LayoutInflater.from(context).inflate(R.layout.seek_bar_dialog, null);
- }
-
- public Builder setTitle(final int resId) {
- mDialogBuilder.setTitle(resId);
- return this;
- }
-
- public Builder setNeutralButtonText(final int resId) {
- mNeutralButtonTextResId = resId;
- return this;
- }
-
- public Builder setMaxValue(final int max) {
- mMaxValue = max;
- mValue = Math.min(mValue, max);
- return this;
- }
-
- public Builder setValueFromat(final int resId) {
- mValueFormatResId = resId;
- return this;
- }
-
- public Builder setValue(final int value) {
- mValue = Math.min(value, mMaxValue);
- return this;
- }
-
- public Builder setListener(final Listener listener) {
- mListener = listener;
- return this;
- }
-
- public SeekBarDialog create() {
- final SeekBarDialog dialog = new SeekBarDialog(this);
- dialog.setValue(mValue, false /* fromUser */);
- return dialog;
- }
- }
-}
diff --git a/java/src/com/android/inputmethod/latin/SeekBarDialogPreference.java b/java/src/com/android/inputmethod/latin/SeekBarDialogPreference.java
new file mode 100644
index 000000000..56a6a9b01
--- /dev/null
+++ b/java/src/com/android/inputmethod/latin/SeekBarDialogPreference.java
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.android.inputmethod.latin;
+
+import android.app.AlertDialog;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.res.TypedArray;
+import android.preference.DialogPreference;
+import android.util.AttributeSet;
+import android.view.View;
+import android.widget.SeekBar;
+import android.widget.TextView;
+
+public final class SeekBarDialogPreference extends DialogPreference
+ implements SeekBar.OnSeekBarChangeListener {
+ public interface ValueProxy {
+ public int readValue(final String key);
+ public int readDefaultValue(final String key);
+ public void writeValue(final int value, final String key);
+ public void feedbackValue(final int value);
+ }
+
+ private final int mValueFormatResId;
+ private final int mMaxValue;
+
+ private TextView mValueView;
+ private SeekBar mSeekBar;
+
+ private ValueProxy mValueProxy;
+
+ public SeekBarDialogPreference(final Context context, final AttributeSet attrs) {
+ super(context, attrs);
+ final TypedArray a = context.obtainStyledAttributes(
+ attrs, R.styleable.SeekBarDialogPreference, 0, 0);
+ mValueFormatResId = a.getResourceId(R.styleable.SeekBarDialogPreference_valueFormatText, 0);
+ mMaxValue = a.getInt(R.styleable.SeekBarDialogPreference_maxValue, 0);
+ a.recycle();
+ setDialogLayoutResource(R.layout.seek_bar_dialog);
+ }
+
+ public void setInterface(final ValueProxy proxy) {
+ mValueProxy = proxy;
+ setSummary(getValueText(proxy.readValue(getKey())));
+ }
+
+ private String getValueText(final int value) {
+ if (mValueFormatResId == 0) {
+ return Integer.toString(value);
+ } else {
+ return getContext().getString(mValueFormatResId, value);
+ }
+ }
+
+ @Override
+ protected View onCreateDialogView() {
+ final View view = super.onCreateDialogView();
+ mSeekBar = (SeekBar)view.findViewById(R.id.seek_bar_dialog_bar);
+ mSeekBar.setMax(mMaxValue);
+ mSeekBar.setOnSeekBarChangeListener(this);
+ mValueView = (TextView)view.findViewById(R.id.seek_bar_dialog_value);
+ return view;
+ }
+
+ private void setValue(final int value, final boolean fromUser) {
+ mValueView.setText(getValueText(value));
+ if (!fromUser) {
+ mSeekBar.setProgress(value);
+ }
+ }
+
+ @Override
+ protected void onBindDialogView(final View view) {
+ setValue(mValueProxy.readValue(getKey()), false /* fromUser */);
+ }
+
+ @Override
+ protected void onPrepareDialogBuilder(final AlertDialog.Builder builder) {
+ builder.setPositiveButton(android.R.string.ok, this)
+ .setNegativeButton(android.R.string.cancel, this)
+ .setNeutralButton(R.string.button_default, this);
+ }
+
+ @Override
+ public void onClick(final DialogInterface dialog, final int which) {
+ super.onClick(dialog, which);
+ if (which == DialogInterface.BUTTON_NEUTRAL) {
+ setValue(mValueProxy.readDefaultValue(getKey()), false /* fromUser */);
+ }
+ if (which != DialogInterface.BUTTON_NEGATIVE) {
+ setSummary(mValueView.getText());
+ mValueProxy.writeValue(mSeekBar.getProgress(), getKey());
+ }
+ }
+
+ @Override
+ public void onProgressChanged(final SeekBar seekBar, final int progress,
+ final boolean fromUser) {
+ setValue(progress, fromUser);
+ }
+
+ @Override
+ public void onStartTrackingTouch(final SeekBar seekBar) {}
+
+ @Override
+ public void onStopTrackingTouch(final SeekBar seekBar) {
+ mValueProxy.feedbackValue(seekBar.getProgress());
+ }
+}
diff --git a/java/src/com/android/inputmethod/latin/SettingsFragment.java b/java/src/com/android/inputmethod/latin/SettingsFragment.java
index 6a4371835..3558d817d 100644
--- a/java/src/com/android/inputmethod/latin/SettingsFragment.java
+++ b/java/src/com/android/inputmethod/latin/SettingsFragment.java
@@ -26,7 +26,6 @@ import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
-import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceGroup;
import android.preference.PreferenceScreen;
import android.view.inputmethod.InputMethodSubtype;
@@ -36,8 +35,6 @@ import com.android.inputmethodcommon.InputMethodSettingsFragment;
public final class SettingsFragment extends InputMethodSettingsFragment
implements SharedPreferences.OnSharedPreferenceChangeListener {
- private PreferenceScreen mKeypressVibrationDurationSettingsPref;
- private PreferenceScreen mKeypressSoundVolumeSettingsPref;
private ListPreference mVoicePreference;
private ListPreference mShowCorrectionSuggestionsPreference;
private ListPreference mAutoCorrectionThresholdPreference;
@@ -167,36 +164,8 @@ public final class SettingsFragment extends InputMethodSettingsFragment
getPreferenceScreen().removePreference(gestureTypingSettings);
}
- mKeypressVibrationDurationSettingsPref =
- (PreferenceScreen) findPreference(Settings.PREF_VIBRATION_DURATION_SETTINGS);
- if (mKeypressVibrationDurationSettingsPref != null) {
- mKeypressVibrationDurationSettingsPref.setOnPreferenceClickListener(
- new OnPreferenceClickListener() {
- @Override
- public boolean onPreferenceClick(Preference arg0) {
- showKeypressVibrationDurationSettingsDialog();
- return true;
- }
- });
- mKeypressVibrationDurationSettingsPref.setSummary(
- res.getString(R.string.settings_keypress_vibration_duration,
- Settings.readKeypressVibrationDuration(prefs, res)));
- }
-
- mKeypressSoundVolumeSettingsPref =
- (PreferenceScreen) findPreference(Settings.PREF_KEYPRESS_SOUND_VOLUME);
- if (mKeypressSoundVolumeSettingsPref != null) {
- mKeypressSoundVolumeSettingsPref.setOnPreferenceClickListener(
- new OnPreferenceClickListener() {
- @Override
- public boolean onPreferenceClick(Preference arg0) {
- showKeypressSoundVolumeSettingDialog();
- return true;
- }
- });
- mKeypressSoundVolumeSettingsPref.setSummary(String.valueOf(
- getCurrentKeyPressSoundVolumePercent(prefs, res)));
- }
+ setupKeypressVibrationDurationSettings(prefs, res);
+ setupKeypressSoundVolumeSettings(prefs, res);
refreshEnablingsOfKeypressSoundAndVibrationSettings(prefs, res);
}
@@ -287,127 +256,86 @@ public final class SettingsFragment extends InputMethodSettingsFragment
private void refreshEnablingsOfKeypressSoundAndVibrationSettings(
final SharedPreferences sp, final Resources res) {
- if (mKeypressVibrationDurationSettingsPref != null) {
- final boolean hasVibratorHardware =
- AudioAndHapticFeedbackManager.getInstance().hasVibrator();
- final boolean vibrateOnByUser = sp.getBoolean(Settings.PREF_VIBRATE_ON,
- res.getBoolean(R.bool.config_default_vibration_enabled));
- mKeypressVibrationDurationSettingsPref.setEnabled(
- hasVibratorHardware && vibrateOnByUser);
- }
-
- if (mKeypressSoundVolumeSettingsPref != null) {
- final boolean soundOn = sp.getBoolean(Settings.PREF_SOUND_ON,
- res.getBoolean(R.bool.config_default_sound_enabled));
- mKeypressSoundVolumeSettingsPref.setEnabled(soundOn);
- }
+ final boolean hasVibratorHardware =
+ AudioAndHapticFeedbackManager.getInstance().hasVibrator();
+ final boolean vibrateOnByUser = sp.getBoolean(Settings.PREF_VIBRATE_ON,
+ res.getBoolean(R.bool.config_default_vibration_enabled));
+ setPreferenceEnabled(Settings.PREF_VIBRATION_DURATION_SETTINGS,
+ hasVibratorHardware && vibrateOnByUser);
+
+ final boolean soundOn = sp.getBoolean(Settings.PREF_SOUND_ON,
+ res.getBoolean(R.bool.config_default_sound_enabled));
+ setPreferenceEnabled(Settings.PREF_KEYPRESS_SOUND_VOLUME, soundOn);
}
- private void showKeypressVibrationDurationSettingsDialog() {
- final SharedPreferences sp = getPreferenceManager().getSharedPreferences();
- final Context context = getActivity();
- final PreferenceScreen settingsPref = mKeypressVibrationDurationSettingsPref;
- final SeekBarDialog.Listener listener = new SeekBarDialog.Adapter() {
- private void writePreference(final SharedPreferences sp, final int value) {
- sp.edit().putInt(Settings.PREF_VIBRATION_DURATION_SETTINGS, value).apply();
- }
-
- private void feedbackSettingsValue(final int value) {
- AudioAndHapticFeedbackManager.getInstance().vibrate(value);
- }
-
+ private void setupKeypressVibrationDurationSettings(final SharedPreferences sp,
+ final Resources res) {
+ final SeekBarDialogPreference pref = (SeekBarDialogPreference)findPreference(
+ Settings.PREF_VIBRATION_DURATION_SETTINGS);
+ if (pref == null) {
+ return;
+ }
+ pref.setInterface(new SeekBarDialogPreference.ValueProxy() {
@Override
- public void onPositiveButtonClick(final SeekBarDialog dialog) {
- writePreference(sp, dialog.getValue());
+ public void writeValue(final int value, final String key) {
+ sp.edit().putInt(key, value).apply();
}
@Override
- public void onNeutralButtonClick(final SeekBarDialog dialog) {
- final int defaultValue =
- Settings.readDefaultKeypressVibrationDuration(context.getResources());
- dialog.setValue(defaultValue, false /* fromUser */);
- writePreference(sp, defaultValue);
+ public int readValue(final String key) {
+ return Settings.readKeypressVibrationDuration(sp, res);
}
@Override
- public void onDismiss(final SeekBarDialog dialog) {
- if (settingsPref != null) {
- settingsPref.setSummary(dialog.getValueText());
- }
+ public int readDefaultValue(final String key) {
+ return Settings.readDefaultKeypressVibrationDuration(res);
}
@Override
- public void onStopTrackingTouch(final SeekBarDialog dialog) {
- feedbackSettingsValue(dialog.getValue());
+ public void feedbackValue(final int value) {
+ AudioAndHapticFeedbackManager.getInstance().vibrate(value);
}
- };
- final int currentMs = Settings.readKeypressVibrationDuration(sp, getResources());
- final SeekBarDialog.Builder builder = new SeekBarDialog.Builder(context);
- builder.setTitle(R.string.prefs_keypress_vibration_duration_settings)
- .setNeutralButtonText(R.string.button_default)
- .setListener(listener)
- .setMaxValue(AudioAndHapticFeedbackManager.MAX_KEYPRESS_VIBRATION_DURATION)
- .setValueFromat(R.string.settings_keypress_vibration_duration)
- .setValue(currentMs)
- .create()
- .show();
+ });
}
- private static final int PERCENT_INT = 100;
- private static final float PERCENT_FLOAT = 100.0f;
-
- private static int getCurrentKeyPressSoundVolumePercent(final SharedPreferences sp,
- final Resources res) {
- return (int)(Settings.readKeypressSoundVolume(sp, res) * PERCENT_FLOAT);
- }
+ private void setupKeypressSoundVolumeSettings(final SharedPreferences sp, final Resources res) {
+ final SeekBarDialogPreference pref = (SeekBarDialogPreference)findPreference(
+ Settings.PREF_KEYPRESS_SOUND_VOLUME);
+ if (pref == null) {
+ return;
+ }
+ final AudioManager am = (AudioManager)getActivity().getSystemService(Context.AUDIO_SERVICE);
+ pref.setInterface(new SeekBarDialogPreference.ValueProxy() {
+ private static final float PERCENTAGE_FLOAT = 100.0f;
- private void showKeypressSoundVolumeSettingDialog() {
- final SharedPreferences sp = getPreferenceManager().getSharedPreferences();
- final Context context = getActivity();
- final AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
- final PreferenceScreen settingsPref = mKeypressSoundVolumeSettingsPref;
- final SeekBarDialog.Listener listener = new SeekBarDialog.Adapter() {
- private void writePreference(final SharedPreferences sp, final float value) {
- sp.edit().putFloat(Settings.PREF_KEYPRESS_SOUND_VOLUME, value).apply();
+ private float getValueFromPercentage(final int percentage) {
+ return percentage / PERCENTAGE_FLOAT;
}
- private void feedbackSettingsValue(final float value) {
- am.playSoundEffect(AudioManager.FX_KEYPRESS_STANDARD, value);
+ private int getPercentageFromValue(final float floatValue) {
+ return (int)(floatValue * PERCENTAGE_FLOAT);
}
@Override
- public void onPositiveButtonClick(final SeekBarDialog dialog) {
- writePreference(sp, dialog.getValue() / PERCENT_FLOAT);
+ public void writeValue(final int value, final String key) {
+ sp.edit().putFloat(key, getValueFromPercentage(value)).apply();
}
@Override
- public void onNeutralButtonClick(final SeekBarDialog dialog) {
- final float defaultValue =
- Settings.readDefaultKeypressSoundVolume(context.getResources());
- dialog.setValue((int)(defaultValue * PERCENT_INT), false /* fromUser */);
- writePreference(sp, defaultValue);
+ public int readValue(final String key) {
+ return getPercentageFromValue(Settings.readKeypressSoundVolume(sp, res));
}
@Override
- public void onDismiss(final SeekBarDialog dialog) {
- if (settingsPref != null) {
- settingsPref.setSummary(dialog.getValueText());
- }
+ public int readDefaultValue(final String key) {
+ return getPercentageFromValue(Settings.readDefaultKeypressSoundVolume(res));
}
@Override
- public void onStopTrackingTouch(final SeekBarDialog dialog) {
- feedbackSettingsValue(dialog.getValue() / PERCENT_FLOAT);
+ public void feedbackValue(final int value) {
+ am.playSoundEffect(
+ AudioManager.FX_KEYPRESS_STANDARD, getValueFromPercentage(value));
}
- };
- final SeekBarDialog.Builder builder = new SeekBarDialog.Builder(context);
- final int currentVolumeInt = getCurrentKeyPressSoundVolumePercent(sp, getResources());
- builder.setTitle(R.string.prefs_keypress_sound_volume_settings)
- .setNeutralButtonText(R.string.button_default)
- .setListener(listener)
- .setMaxValue(PERCENT_INT)
- .setValue(currentVolumeInt)
- .create()
- .show();
+ });
}
}
diff --git a/java/src/com/android/inputmethod/latin/StringUtils.java b/java/src/com/android/inputmethod/latin/StringUtils.java
index ddaa5ff5b..d00edbe92 100644
--- a/java/src/com/android/inputmethod/latin/StringUtils.java
+++ b/java/src/com/android/inputmethod/latin/StringUtils.java
@@ -103,6 +103,37 @@ public final class StringUtils {
}
}
+ /**
+ * Apply an auto-caps mode to a string.
+ *
+ * This intentionally does NOT apply manual caps mode. It only changes the capitalization if
+ * the mode is one of the auto-caps modes.
+ * @param s The string to capitalize.
+ * @param capitalizeMode The mode in which to capitalize.
+ * @param locale The locale for capitalizing.
+ * @return The capitalized string.
+ */
+ public static String applyAutoCapsMode(final String s, final int capitalizeMode,
+ final Locale locale) {
+ if (WordComposer.CAPS_MODE_AUTO_SHIFT_LOCKED == capitalizeMode) {
+ return s.toUpperCase(locale);
+ } else if (WordComposer.CAPS_MODE_AUTO_SHIFTED == capitalizeMode) {
+ return toTitleCase(s, locale);
+ } else {
+ return s;
+ }
+ }
+
+ /**
+ * Return whether a constant represents an auto-caps mode (either auto-shift or auto-shift-lock)
+ * @param mode The mode to test for
+ * @return true if this represents an auto-caps mode, false otherwise
+ */
+ public static boolean isAutoCapsMode(final int mode) {
+ return WordComposer.CAPS_MODE_AUTO_SHIFTED == mode
+ || WordComposer.CAPS_MODE_AUTO_SHIFT_LOCKED == mode;
+ }
+
public static String toTitleCase(final String s, final Locale locale) {
if (s.length() <= 1) {
// TODO: is this really correct? Shouldn't this be s.toUpperCase()?
diff --git a/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java b/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java
index a16784985..0d5bde623 100644
--- a/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java
@@ -216,17 +216,13 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary {
*
* @param word the word to add. If the word is capitalized, then the dictionary will
* recognize it as a capitalized word when searched.
- * @param frequency the frequency of occurrence of the word. A frequency of 255 is considered
- * the highest.
- * @TODO use a higher or float range for frequency
*/
- public synchronized void addWordToUserDictionary(final String word, final int frequency) {
+ public synchronized void addWordToUserDictionary(final String word) {
// TODO: do something for the UI. With the following, any sufficiently long word will
// look like it will go to the user dictionary but it won't.
// Safeguard against adding long words. Can cause stack overflow.
if (word.length() >= MAX_WORD_LENGTH) return;
- // TODO: Add an argument to the intent to specify the frequency.
Intent intent = new Intent(ACTION_USER_DICTIONARY_INSERT);
intent.putExtra(Words.WORD, word);
intent.putExtra(Words.LOCALE, mLocale);
diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java
index b9ec4979d..01629fefa 100644
--- a/java/src/com/android/inputmethod/latin/WordComposer.java
+++ b/java/src/com/android/inputmethod/latin/WordComposer.java
@@ -360,8 +360,10 @@ public final class WordComposer {
mDigitsCount = 0;
mIsBatchMode = false;
mTypedWord.setLength(0);
+ mCodePointSize = 0;
mTrailingSingleQuotesCount = 0;
mIsFirstCharCapitalized = false;
+ mCapitalizedMode = CAPS_MODE_OFF;
refreshSize();
mAutoCorrection = null;
mIsResumed = false;