aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java16
-rw-r--r--java/src/com/android/inputmethod/latin/LatinKeyboard.java86
-rw-r--r--java/src/com/android/inputmethod/voice/VoiceInput.java16
-rw-r--r--java/src/com/android/inputmethod/voice/VoiceInputLogger.java15
4 files changed, 71 insertions, 62 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index fb9c47db2..692183dbf 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -96,7 +96,7 @@ public class LatinIME extends InputMethodService
private static final String PREF_QUICK_FIXES = "quick_fixes";
private static final String PREF_SHOW_SUGGESTIONS = "show_suggestions";
private static final String PREF_AUTO_COMPLETE = "auto_complete";
- //private static final String PREF_BIGRAM_SUGGESTIONS = "bigram_suggestion";
+ private static final String PREF_BIGRAM_SUGGESTIONS = "bigram_suggestion";
private static final String PREF_VOICE_MODE = "voice_mode";
// Whether or not the user has used voice input before (and thus, whether to show the
@@ -192,8 +192,7 @@ public class LatinIME extends InputMethodService
private boolean mJustAddedAutoSpace;
private boolean mAutoCorrectEnabled;
private boolean mReCorrectionEnabled;
- // Bigram Suggestion is disabled in this version.
- private final boolean mBigramSuggestionEnabled = false;
+ private boolean mBigramSuggestionEnabled;
private boolean mAutoCorrectOn;
// TODO move this state variable outside LatinIME
private boolean mCapsLock;
@@ -1849,13 +1848,13 @@ public class LatinIME extends InputMethodService
}
public void pickSuggestionManually(int index, CharSequence suggestion) {
- if (mAfterVoiceInput && mShowingVoiceSuggestions) mVoiceInput.logNBestChoose(index);
List<CharSequence> suggestions = mCandidateView.getSuggestions();
-
- if (mAfterVoiceInput && !mShowingVoiceSuggestions) {
+ if (mAfterVoiceInput && mShowingVoiceSuggestions) {
mVoiceInput.flushAllTextModificationCounters();
// send this intent AFTER logging any prior aggregated edits.
- mVoiceInput.logTextModifiedByChooseSuggestion(suggestion.length());
+ mVoiceInput.logTextModifiedByChooseSuggestion(suggestion.toString(), index,
+ mWordSeparators,
+ getCurrentInputConnection());
}
final boolean correcting = TextEntryState.isCorrecting();
@@ -2487,8 +2486,7 @@ public class LatinIME extends InputMethodService
}
mAutoCorrectEnabled = sp.getBoolean(PREF_AUTO_COMPLETE,
mResources.getBoolean(R.bool.enable_autocorrect)) & mShowSuggestions;
- //mBigramSuggestionEnabled = sp.getBoolean(
- // PREF_BIGRAM_SUGGESTIONS, true) & mShowSuggestions;
+ mBigramSuggestionEnabled = sp.getBoolean(PREF_BIGRAM_SUGGESTIONS, true) & mShowSuggestions;
updateCorrectionMode();
updateAutoTextEnabled(mResources.getConfiguration().locale);
mLanguageSwitcher.loadLocales(sp);
diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboard.java b/java/src/com/android/inputmethod/latin/LatinKeyboard.java
index 14a503bc3..76b90f8f3 100644
--- a/java/src/com/android/inputmethod/latin/LatinKeyboard.java
+++ b/java/src/com/android/inputmethod/latin/LatinKeyboard.java
@@ -36,6 +36,8 @@ import android.util.Log;
import android.view.ViewConfiguration;
import android.view.inputmethod.EditorInfo;
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Locale;
@@ -48,7 +50,7 @@ public class LatinKeyboard extends Keyboard {
private Drawable mShiftLockIcon;
private Drawable mShiftLockPreviewIcon;
- private Drawable mOldShiftIcon;
+ private final HashMap<Key, Drawable> mOldShiftIcons = new HashMap<Key, Drawable>();
private Drawable mSpaceIcon;
private Drawable mSpaceAutoCompletionIndicator;
private Drawable mSpacePreviewIcon;
@@ -58,7 +60,7 @@ public class LatinKeyboard extends Keyboard {
private Drawable m123MicPreviewIcon;
private final Drawable mButtonArrowLeftIcon;
private final Drawable mButtonArrowRightIcon;
- private Key mShiftKey;
+ private ArrayList<Key> mShiftKeys;
private Key mEnterKey;
private Key mF1Key;
private Key mSpaceKey;
@@ -156,9 +158,22 @@ public class LatinKeyboard extends Keyboard {
mNumberHintIcons[9] = res.getDrawable(R.drawable.keyboard_hint_9);
}
+ // TODO: delete this method and do initialization in constructor.
+ private void initializeMemberVariablesAsNeeded() {
+ if (mNumberHintKeys == null)
+ mNumberHintKeys = new Key[NUMBER_HINT_COUNT];
+ if (mShiftKeys == null)
+ mShiftKeys = new ArrayList<Key>();
+ }
+
@Override
protected Key createKeyFromXml(Resources res, Row parent, int x, int y,
XmlResourceParser parser) {
+ // TODO: This initialization is needed because this protected method is being called from
+ // the base class constructor before this class constructor gets called. We need to fix
+ // this.
+ initializeMemberVariablesAsNeeded();
+
Key key = new LatinKey(res, parent, x, y, parser);
switch (key.codes[0]) {
case LatinIME.KEYCODE_ENTER:
@@ -170,6 +185,9 @@ public class LatinKeyboard extends Keyboard {
case LatinIME.KEYCODE_SPACE:
mSpaceKey = key;
break;
+ case KEYCODE_SHIFT:
+ mShiftKeys.add(key);
+ break;
case KEYCODE_MODE_CHANGE:
m123Key = key;
m123Label = key.label;
@@ -177,11 +195,6 @@ public class LatinKeyboard extends Keyboard {
}
// For number hints on the upper-right corner of key
- if (mNumberHintKeys == null) {
- // NOTE: This protected method is being called from the base class constructor before
- // mNumberHintKeys gets initialized.
- mNumberHintKeys = new Key[NUMBER_HINT_COUNT];
- }
int hintNumber = -1;
if (LatinKeyboardBaseView.isNumberAtLeftmostPopupChar(key)) {
hintNumber = key.popupCharacters.charAt(0) - '0';
@@ -195,7 +208,7 @@ public class LatinKeyboard extends Keyboard {
return key;
}
- void setImeOptions(Resources res, int mode, int options) {
+ public void setImeOptions(Resources res, int mode, int options) {
if (mEnterKey != null) {
// Reset some of the rarely used attributes.
mEnterKey.popupCharacters = null;
@@ -253,61 +266,56 @@ public class LatinKeyboard extends Keyboard {
}
}
}
-
- void enableShiftLock() {
- int index = getShiftKeyIndex();
- if (index >= 0) {
- mShiftKey = getKeys().get(index);
- if (mShiftKey instanceof LatinKey) {
- ((LatinKey)mShiftKey).enableShiftLock();
+
+ public void enableShiftLock() {
+ for (final Key key : mShiftKeys) {
+ if (key instanceof LatinKey) {
+ ((LatinKey)key).enableShiftLock();
}
- mOldShiftIcon = mShiftKey.icon;
+ mOldShiftIcons.put(key, key.icon);
}
}
- void setShiftLocked(boolean shiftLocked) {
- if (mShiftKey != null) {
- if (shiftLocked) {
- mShiftKey.on = true;
- mShiftKey.icon = mShiftLockIcon;
- mShiftState = SHIFT_LOCKED;
- } else {
- mShiftKey.on = false;
- mShiftKey.icon = mShiftLockIcon;
- mShiftState = SHIFT_ON;
- }
+ public void setShiftLocked(boolean shiftLocked) {
+ for (final Key key : mShiftKeys) {
+ key.on = shiftLocked;
+ key.icon = mShiftLockIcon;
}
+ mShiftState = shiftLocked ? SHIFT_LOCKED : SHIFT_ON;
}
- boolean isShiftLocked() {
+ public boolean isShiftLocked() {
return mShiftState == SHIFT_LOCKED;
}
@Override
public boolean setShifted(boolean shiftState) {
boolean shiftChanged = false;
- if (mShiftKey != null) {
+ if (mShiftKeys.size() > 0) {
+ for (final Key key : mShiftKeys) {
+ if (shiftState == false) {
+ key.on = false;
+ key.icon = mOldShiftIcons.get(key);
+ } else if (mShiftState == SHIFT_OFF) {
+ key.icon = mShiftLockIcon;
+ }
+ }
if (shiftState == false) {
shiftChanged = mShiftState != SHIFT_OFF;
mShiftState = SHIFT_OFF;
- mShiftKey.on = false;
- mShiftKey.icon = mOldShiftIcon;
- } else {
- if (mShiftState == SHIFT_OFF) {
- shiftChanged = mShiftState == SHIFT_OFF;
- mShiftState = SHIFT_ON;
- mShiftKey.icon = mShiftLockIcon;
- }
+ } else if (mShiftState == SHIFT_OFF) {
+ shiftChanged = mShiftState == SHIFT_OFF;
+ mShiftState = SHIFT_ON;
}
+ return shiftChanged;
} else {
return super.setShifted(shiftState);
}
- return shiftChanged;
}
@Override
public boolean isShifted() {
- if (mShiftKey != null) {
+ if (mShiftKeys.size() > 0) {
return mShiftState != SHIFT_OFF;
} else {
return super.isShifted();
diff --git a/java/src/com/android/inputmethod/voice/VoiceInput.java b/java/src/com/android/inputmethod/voice/VoiceInput.java
index f24c180d0..4c54dd3c5 100644
--- a/java/src/com/android/inputmethod/voice/VoiceInput.java
+++ b/java/src/com/android/inputmethod/voice/VoiceInput.java
@@ -16,6 +16,7 @@
package com.android.inputmethod.voice;
+import com.android.inputmethod.latin.EditingUtil;
import com.android.inputmethod.latin.R;
import android.content.ContentResolver;
@@ -30,6 +31,7 @@ import android.speech.RecognitionListener;
import android.speech.SpeechRecognizer;
import android.speech.RecognizerIntent;
import android.util.Log;
+import android.view.inputmethod.InputConnection;
import android.view.View;
import android.view.View.OnClickListener;
@@ -423,8 +425,14 @@ public class VoiceInput implements OnClickListener {
mLogger.textModifiedByTypingDeletion(length);
}
- public void logTextModifiedByChooseSuggestion(int length) {
- mLogger.textModifiedByChooseSuggestion(length);
+ public void logTextModifiedByChooseSuggestion(String suggestion, int index,
+ String wordSeparators, InputConnection ic) {
+ EditingUtil.Range range = new EditingUtil.Range();
+ String wordToBeReplaced = EditingUtil.getWordAtCursor(ic, wordSeparators, range);
+ // If we enable phrase-based alternatives, only send up the first word
+ // in suggestion and wordToBeReplaced.
+ mLogger.textModifiedByChooseSuggestion(suggestion.length(), wordToBeReplaced.length(),
+ index, wordToBeReplaced, suggestion);
}
public void logKeyboardWarningDialogShown() {
@@ -455,10 +463,6 @@ public class VoiceInput implements OnClickListener {
mLogger.voiceInputDelivered(length);
}
- public void logNBestChoose(int index) {
- mLogger.nBestChoose(index);
- }
-
public void logInputEnded() {
mLogger.inputEnded();
}
diff --git a/java/src/com/android/inputmethod/voice/VoiceInputLogger.java b/java/src/com/android/inputmethod/voice/VoiceInputLogger.java
index 9d3a92037..4d50f5ee8 100644
--- a/java/src/com/android/inputmethod/voice/VoiceInputLogger.java
+++ b/java/src/com/android/inputmethod/voice/VoiceInputLogger.java
@@ -178,20 +178,19 @@ public class VoiceInputLogger {
mContext.sendBroadcast(i);
}
- public void textModifiedByChooseSuggestion(int length) {
+ public void textModifiedByChooseSuggestion(int suggestionLength, int replacedPhraseLength,
+ int index, String before, String after) {
Intent i = newLoggingBroadcast(LoggingEvents.VoiceIme.TEXT_MODIFIED);
- i.putExtra(LoggingEvents.VoiceIme.EXTRA_TEXT_MODIFIED_LENGTH, length);
+ i.putExtra(LoggingEvents.VoiceIme.EXTRA_TEXT_MODIFIED_LENGTH, suggestionLength);
+ i.putExtra(LoggingEvents.VoiceIme.EXTRA_TEXT_REPLACED_LENGTH, replacedPhraseLength);
i.putExtra(LoggingEvents.VoiceIme.EXTRA_TEXT_MODIFIED_TYPE,
LoggingEvents.VoiceIme.TEXT_MODIFIED_TYPE_CHOOSE_SUGGESTION);
- mContext.sendBroadcast(i);
- }
-
- public void nBestChoose(int index) {
- Intent i = newLoggingBroadcast(LoggingEvents.VoiceIme.N_BEST_CHOOSE);
i.putExtra(LoggingEvents.VoiceIme.EXTRA_N_BEST_CHOOSE_INDEX, index);
+ i.putExtra(LoggingEvents.VoiceIme.EXTRA_BEFORE_N_BEST_CHOOSE, before);
+ i.putExtra(LoggingEvents.VoiceIme.EXTRA_AFTER_N_BEST_CHOOSE, after);
mContext.sendBroadcast(i);
}
-
+
public void inputEnded() {
mContext.sendBroadcast(newLoggingBroadcast(LoggingEvents.VoiceIme.INPUT_ENDED));
}