aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/keyboard/LatinKeyboard.java9
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java22
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java30
-rw-r--r--java/src/com/android/inputmethod/latin/Settings.java139
-rw-r--r--java/src/com/android/inputmethod/latin/Utils.java18
5 files changed, 170 insertions, 48 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java
index c51f1849b..762039625 100644
--- a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java
+++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java
@@ -38,7 +38,6 @@ import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.SubtypeSwitcher;
import com.android.inputmethod.latin.Utils;
-import java.lang.ref.SoftReference;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Locale;
@@ -329,10 +328,12 @@ public class LatinKeyboard extends Keyboard {
Math.max(0, Math.min(y, mOccupiedHeight - 1)));
}
+ private static final int[] ATTR_TEXT_SIZE = { android.R.attr.textSize };
+
public static int getTextSizeFromTheme(Theme theme, int style, int defValue) {
- TypedArray array = theme.obtainStyledAttributes(
- style, new int[] { android.R.attr.textSize });
- int textSize = array.getDimensionPixelSize(array.getResourceId(0, 0), defValue);
+ final TypedArray a = theme.obtainStyledAttributes(style, ATTR_TEXT_SIZE);
+ final int textSize = a.getDimensionPixelSize(a.getResourceId(0, 0), defValue);
+ a.recycle();
return textSize;
}
}
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
index dd31d17c8..c2e96f877 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
@@ -19,6 +19,7 @@ package com.android.inputmethod.keyboard.internal;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
+import android.content.res.XmlResourceParser;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
@@ -268,14 +269,17 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
public KeyboardBuilder<KP> load(KeyboardId id) {
mParams.mId = id;
+ final XmlResourceParser parser = mResources.getXml(id.getXmlId());
try {
- parseKeyboard(id.getXmlId());
+ parseKeyboard(parser);
} catch (XmlPullParserException e) {
Log.w(TAG, "keyboard XML parse error: " + e);
throw new IllegalArgumentException(e);
} catch (IOException e) {
Log.w(TAG, "keyboard XML parse error: " + e);
throw new RuntimeException(e);
+ } finally {
+ parser.close();
}
return this;
}
@@ -288,9 +292,9 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
return new Keyboard(mParams);
}
- private void parseKeyboard(int resId) throws XmlPullParserException, IOException {
+ private void parseKeyboard(XmlResourceParser parser)
+ throws XmlPullParserException, IOException {
if (DEBUG) Log.d(TAG, String.format("<%s> %s", TAG_KEYBOARD, mParams.mId));
- final XmlPullParser parser = mResources.getXml(resId);
int event;
while ((event = parser.next()) != XmlPullParser.END_DOCUMENT) {
if (event == XmlPullParser.START_TAG) {
@@ -319,7 +323,10 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
if (TAG_KEYBOARD.equals(tag)) {
final TypedArray keyboardAttr = res.obtainAttributes(Xml.asAttributeSet(parser),
R.styleable.Keyboard);
- return keyboardAttr.getString(R.styleable.Keyboard_keyboardLocale);
+ final String locale = keyboardAttr.getString(
+ R.styleable.Keyboard_keyboardLocale);
+ keyboardAttr.recycle();
+ return locale;
} else {
throw new IllegalStartTag(parser, TAG_KEYBOARD);
}
@@ -535,7 +542,12 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
throw new ParseException("No keyboardLayout attribute in <include/>", parser);
if (DEBUG) Log.d(TAG, String.format("<%s keyboardLayout=%s />",
TAG_INCLUDE, mResources.getResourceEntryName(keyboardLayout)));
- parseMerge(mResources.getLayout(keyboardLayout), row, skip);
+ final XmlResourceParser parserForInclude = mResources.getXml(keyboardLayout);
+ try {
+ parseMerge(parserForInclude, row, skip);
+ } finally {
+ parserForInclude.close();
+ }
}
}
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 05aa305f5..cedf3c4b6 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -28,7 +28,6 @@ import android.content.res.Resources;
import android.inputmethodservice.InputMethodService;
import android.media.AudioManager;
import android.net.ConnectivityManager;
-import android.os.Build;
import android.os.Debug;
import android.os.Message;
import android.os.SystemClock;
@@ -182,7 +181,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
// TODO: Create an inner class to group options and pseudo-options to improve readability.
// These variables are initialized according to the {@link EditorInfo#inputType}.
- private boolean mShouldInsertMagicSpace;
+ private boolean mInsertSpaceOnPickSuggestionManually;
private boolean mInputTypeNoAutoCorrect;
private boolean mIsSettingsSuggestionStripOn;
private boolean mApplicationSpecifiedCompletionOn;
@@ -776,7 +775,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
inputType, attribute.imeOptions));
}
- mShouldInsertMagicSpace = false;
+ mInsertSpaceOnPickSuggestionManually = false;
mInputTypeNoAutoCorrect = false;
mIsSettingsSuggestionStripOn = false;
mApplicationSpecifiedCompletionOn = false;
@@ -791,9 +790,11 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
}
if (InputTypeCompatUtils.isEmailVariation(variation)
|| variation == InputType.TYPE_TEXT_VARIATION_PERSON_NAME) {
- mShouldInsertMagicSpace = false;
+ // The point in turning this off is that we don't want to insert a space after
+ // a name when filling a form: we can't delete trailing spaces when changing fields
+ mInsertSpaceOnPickSuggestionManually = false;
} else {
- mShouldInsertMagicSpace = true;
+ mInsertSpaceOnPickSuggestionManually = true;
}
if (InputTypeCompatUtils.isEmailVariation(variation)) {
mIsSettingsSuggestionStripOn = false;
@@ -1815,8 +1816,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
final int rawPrimaryCode = suggestion.charAt(0);
// Maybe apply the "bidi mirrored" conversions for parentheses
final LatinKeyboard keyboard = mKeyboardSwitcher.getLatinKeyboard();
- final int primaryCode = Key.getRtlParenthesisCode(
- rawPrimaryCode, keyboard.mIsRtlKeyboard);
+ final boolean isRtl = keyboard != null && keyboard.mIsRtlKeyboard;
+ final int primaryCode = Key.getRtlParenthesisCode(rawPrimaryCode, isRtl);
final CharSequence beforeText = ic != null ? ic.getTextBeforeCursor(1, 0) : "";
final int toLeft = (ic == null || TextUtils.isEmpty(beforeText))
@@ -1850,7 +1851,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
suggestion.toString(), index, suggestions.mWords);
TextEntryState.acceptedSuggestion(mComposingStringBuilder.toString(), suggestion);
// Follow it with a space
- if (mShouldInsertMagicSpace && !recorrecting) {
+ if (mInsertSpaceOnPickSuggestionManually && !recorrecting) {
sendMagicSpace();
}
@@ -2144,16 +2145,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
}
};
- // update sound effect volume
+ // update keypress sound volume
private void updateSoundEffectVolume() {
- final String[] volumePerHardwareList = mResources.getStringArray(R.array.keypress_volumes);
- final String hardwarePrefix = Build.HARDWARE + ",";
- for (final String element : volumePerHardwareList) {
- if (element.startsWith(hardwarePrefix)) {
- mFxVolume = Float.parseFloat(element.substring(element.lastIndexOf(',') + 1));
- break;
- }
- }
+ mFxVolume = Utils.getCurrentKeypressSoundVolume(mPrefs, mResources);
}
// update flags for silent mode
@@ -2334,7 +2328,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
p.println(" mCorrectionMode=" + mCorrectionMode);
p.println(" mHasUncommittedTypedChars=" + mHasUncommittedTypedChars);
p.println(" mAutoCorrectEnabled=" + mSettingsValues.mAutoCorrectEnabled);
- p.println(" mShouldInsertMagicSpace=" + mShouldInsertMagicSpace);
+ p.println(" mInsertSpaceOnPickSuggestionManually=" + mInsertSpaceOnPickSuggestionManually);
p.println(" mApplicationSpecifiedCompletionOn=" + mApplicationSpecifiedCompletionOn);
p.println(" TextEntryState.state=" + TextEntryState.getState());
p.println(" mSoundOn=" + mSettingsValues.mSoundOn);
diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java
index d9508f4c1..eeb0299b1 100644
--- a/java/src/com/android/inputmethod/latin/Settings.java
+++ b/java/src/com/android/inputmethod/latin/Settings.java
@@ -26,6 +26,7 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
+import android.media.AudioManager;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
@@ -91,9 +92,11 @@ public class Settings extends InputMethodSettingsActivity
public static final String PREF_USABILITY_STUDY_MODE = "usability_study_mode";
- public static final String PREF_VIBRATION_DURATION_SETTINGS =
+ public static final String PREF_KEYPRESS_VIBRATION_DURATION_SETTINGS =
"pref_vibration_duration_settings";
+ public static final String PREF_KEYPRESS_SOUND_VOLUME =
+ "pref_keypress_sound_volume";
// Dialog ids
private static final int VOICE_INPUT_CONFIRM_DIALOG = 0;
@@ -327,7 +330,8 @@ public class Settings extends InputMethodSettingsActivity
}
private PreferenceScreen mInputLanguageSelection;
- private PreferenceScreen mVibrationDurationSettingsPref;
+ private PreferenceScreen mKeypressVibrationDurationSettingsPref;
+ private PreferenceScreen mKeypressSoundVolumeSettingsPref;
private ListPreference mVoicePreference;
private CheckBoxPreference mShowSettingsKeyPreference;
private ListPreference mShowCorrectionSuggestionsPreference;
@@ -341,7 +345,8 @@ public class Settings extends InputMethodSettingsActivity
private boolean mVoiceOn;
private AlertDialog mDialog;
- private TextView mVibrationSettingsTextView;
+ private TextView mKeypressVibrationDurationSettingsTextView;
+ private TextView mKeypressSoundVolumeSettingsTextView;
private boolean mOkClicked = false;
private String mVoiceModeOff;
@@ -477,19 +482,34 @@ public class Settings extends InputMethodSettingsActivity
}
}
- mVibrationDurationSettingsPref =
- (PreferenceScreen) findPreference(PREF_VIBRATION_DURATION_SETTINGS);
- if (mVibrationDurationSettingsPref != null) {
- mVibrationDurationSettingsPref.setOnPreferenceClickListener(
+ mKeypressVibrationDurationSettingsPref =
+ (PreferenceScreen) findPreference(PREF_KEYPRESS_VIBRATION_DURATION_SETTINGS);
+ if (mKeypressVibrationDurationSettingsPref != null) {
+ mKeypressVibrationDurationSettingsPref.setOnPreferenceClickListener(
new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference arg0) {
- showVibrationSettingsDialog();
+ showKeypressVibrationDurationSettingsDialog();
return true;
}
});
- updateVibrationDurationSettingsSummary(prefs, res);
+ updateKeypressVibrationDurationSettingsSummary(prefs, res);
}
+
+ mKeypressSoundVolumeSettingsPref =
+ (PreferenceScreen) findPreference(PREF_KEYPRESS_SOUND_VOLUME);
+ if (mKeypressSoundVolumeSettingsPref != null) {
+ mKeypressSoundVolumeSettingsPref.setOnPreferenceClickListener(
+ new OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference arg0) {
+ showKeypressSoundVolumeSettingDialog();
+ return true;
+ }
+ });
+ updateKeypressSoundVolumeSummary(prefs, res);
+ }
+ refreshEnablingsOfKeypressSoundAndVibrationSettings(prefs, res);
}
@SuppressWarnings("unused")
@@ -537,6 +557,7 @@ public class Settings extends InputMethodSettingsActivity
updateVoiceModeSummary();
updateShowCorrectionSuggestionsSummary();
updateKeyPreviewPopupDelaySummary();
+ refreshEnablingsOfKeypressSoundAndVibrationSettings(prefs, getResources());
}
@Override
@@ -637,26 +658,44 @@ public class Settings extends InputMethodSettingsActivity
}
}
- private void updateVibrationDurationSettingsSummary(SharedPreferences sp, Resources res) {
- if (mVibrationDurationSettingsPref != null) {
- mVibrationDurationSettingsPref.setSummary(
+ private void refreshEnablingsOfKeypressSoundAndVibrationSettings(
+ SharedPreferences sp, Resources res) {
+ if (mKeypressVibrationDurationSettingsPref != null) {
+ final boolean hasVibrator = VibratorCompatWrapper.getInstance(this).hasVibrator();
+ final boolean vibrateOn = hasVibrator && sp.getBoolean(Settings.PREF_VIBRATE_ON,
+ res.getBoolean(R.bool.config_default_vibration_enabled));
+ mKeypressVibrationDurationSettingsPref.setEnabled(vibrateOn);
+ }
+
+ if (mKeypressSoundVolumeSettingsPref != null) {
+ final boolean soundOn = sp.getBoolean(Settings.PREF_SOUND_ON,
+ res.getBoolean(R.bool.config_default_sound_enabled));
+ mKeypressSoundVolumeSettingsPref.setEnabled(soundOn);
+ }
+ }
+
+ private void updateKeypressVibrationDurationSettingsSummary(
+ SharedPreferences sp, Resources res) {
+ if (mKeypressVibrationDurationSettingsPref != null) {
+ mKeypressVibrationDurationSettingsPref.setSummary(
Utils.getCurrentVibrationDuration(sp, res)
+ res.getString(R.string.settings_ms));
}
}
- private void showVibrationSettingsDialog() {
+ private void showKeypressVibrationDurationSettingsDialog() {
final SharedPreferences sp = getPreferenceManager().getSharedPreferences();
final Activity context = getActivityInternal();
final Resources res = context.getResources();
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
- builder.setTitle(R.string.prefs_vibration_duration_settings);
+ builder.setTitle(R.string.prefs_keypress_vibration_duration_settings);
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {
- final int ms = Integer.valueOf(mVibrationSettingsTextView.getText().toString());
- sp.edit().putInt(Settings.PREF_VIBRATION_DURATION_SETTINGS, ms).apply();
- updateVibrationDurationSettingsSummary(sp, res);
+ final int ms = Integer.valueOf(
+ mKeypressVibrationDurationSettingsTextView.getText().toString());
+ sp.edit().putInt(Settings.PREF_KEYPRESS_VIBRATION_DURATION_SETTINGS, ms).apply();
+ updateKeypressVibrationDurationSettingsSummary(sp, res);
}
});
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@@ -669,13 +708,13 @@ public class Settings extends InputMethodSettingsActivity
R.layout.vibration_settings_dialog, null);
final int currentMs = Utils.getCurrentVibrationDuration(
getPreferenceManager().getSharedPreferences(), getResources());
- mVibrationSettingsTextView = (TextView)v.findViewById(R.id.vibration_value);
+ mKeypressVibrationDurationSettingsTextView = (TextView)v.findViewById(R.id.vibration_value);
final SeekBar sb = (SeekBar)v.findViewById(R.id.vibration_settings);
sb.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
final int tempMs = arg1;
- mVibrationSettingsTextView.setText(String.valueOf(tempMs));
+ mKeypressVibrationDurationSettingsTextView.setText(String.valueOf(tempMs));
}
@Override
@@ -689,7 +728,67 @@ public class Settings extends InputMethodSettingsActivity
}
});
sb.setProgress(currentMs);
- mVibrationSettingsTextView.setText(String.valueOf(currentMs));
+ mKeypressVibrationDurationSettingsTextView.setText(String.valueOf(currentMs));
+ builder.setView(v);
+ builder.create().show();
+ }
+
+ private void updateKeypressSoundVolumeSummary(SharedPreferences sp, Resources res) {
+ if (mKeypressSoundVolumeSettingsPref != null) {
+ mKeypressSoundVolumeSettingsPref.setSummary(
+ String.valueOf((int)(Utils.getCurrentKeypressSoundVolume(sp, res) * 100)));
+ }
+ }
+
+ private void showKeypressSoundVolumeSettingDialog() {
+ final AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
+ final SharedPreferences sp = getPreferenceManager().getSharedPreferences();
+ final Activity context = getActivityInternal();
+ final Resources res = context.getResources();
+ final AlertDialog.Builder builder = new AlertDialog.Builder(context);
+ builder.setTitle(R.string.prefs_keypress_sound_volume_settings);
+ builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int whichButton) {
+ final float volume =
+ ((float)Integer.valueOf(
+ mKeypressSoundVolumeSettingsTextView.getText().toString())) / 100;
+ sp.edit().putFloat(Settings.PREF_KEYPRESS_SOUND_VOLUME, volume).apply();
+ updateKeypressSoundVolumeSummary(sp, res);
+ }
+ });
+ builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int whichButton) {
+ dialog.dismiss();
+ }
+ });
+ final View v = context.getLayoutInflater().inflate(
+ R.layout.sound_effect_volume_dialog, null);
+ final int currentVolumeInt = (int)(Utils.getCurrentKeypressSoundVolume(
+ getPreferenceManager().getSharedPreferences(), getResources()) * 100);
+ mKeypressSoundVolumeSettingsTextView =
+ (TextView)v.findViewById(R.id.sound_effect_volume_value);
+ final SeekBar sb = (SeekBar)v.findViewById(R.id.sound_effect_volume_bar);
+ sb.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
+ @Override
+ public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
+ final int tempVolume = arg1;
+ mKeypressSoundVolumeSettingsTextView.setText(String.valueOf(tempVolume));
+ }
+
+ @Override
+ public void onStartTrackingTouch(SeekBar arg0) {
+ }
+
+ @Override
+ public void onStopTrackingTouch(SeekBar arg0) {
+ final float tempVolume = ((float)arg0.getProgress()) / 100;
+ am.playSoundEffect(AudioManager.FX_KEYPRESS_STANDARD, tempVolume);
+ }
+ });
+ sb.setProgress(currentVolumeInt);
+ mKeypressSoundVolumeSettingsTextView.setText(String.valueOf(currentVolumeInt));
builder.setView(v);
builder.create().show();
}
diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java
index f6343f1d7..b29ff1975 100644
--- a/java/src/com/android/inputmethod/latin/Utils.java
+++ b/java/src/com/android/inputmethod/latin/Utils.java
@@ -779,7 +779,7 @@ public class Utils {
}
public static int getCurrentVibrationDuration(SharedPreferences sp, Resources res) {
- final int ms = sp.getInt(Settings.PREF_VIBRATION_DURATION_SETTINGS, -1);
+ final int ms = sp.getInt(Settings.PREF_KEYPRESS_VIBRATION_DURATION_SETTINGS, -1);
if (ms >= 0) {
return ms;
}
@@ -794,6 +794,22 @@ public class Utils {
return -1;
}
+ public static float getCurrentKeypressSoundVolume(SharedPreferences sp, Resources res) {
+ final float volume = sp.getFloat(Settings.PREF_KEYPRESS_SOUND_VOLUME, -1.0f);
+ if (volume >= 0) {
+ return volume;
+ }
+
+ final String[] volumePerHardwareList = res.getStringArray(R.array.keypress_volumes);
+ final String hardwarePrefix = Build.HARDWARE + ",";
+ for (final String element : volumePerHardwareList) {
+ if (element.startsWith(hardwarePrefix)) {
+ return Float.parseFloat(element.substring(element.lastIndexOf(',') + 1));
+ }
+ }
+ return -1.0f;
+ }
+
public static boolean willAutoCorrect(SuggestedWords suggestions) {
return !suggestions.mTypedWordValid && suggestions.mHasAutoCorrectionCandidate
&& !suggestions.shouldBlockAutoCorrection();