aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java56
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java59
-rw-r--r--java/src/com/android/inputmethod/latin/SuggestionsView.java28
-rw-r--r--java/src/com/android/inputmethod/latin/UserDictionary.java60
4 files changed, 74 insertions, 129 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
index c02b37b82..d38f25496 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
@@ -81,8 +81,6 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
private final HashMap<KeyboardId, SoftReference<LatinKeyboard>> mKeyboardCache =
new HashMap<KeyboardId, SoftReference<LatinKeyboard>>();
- private KeyboardLayoutState mSavedKeyboardState = new KeyboardLayoutState();
-
/** mIsAutoCorrectionActive indicates that auto corrected word will be input instead of
* what user actually typed. */
private boolean mIsAutoCorrectionActive;
@@ -92,56 +90,6 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
private static final KeyboardSwitcher sInstance = new KeyboardSwitcher();
- // TODO: Move this to KeyboardState.
- private class KeyboardLayoutState {
- private boolean mIsValid;
- private boolean mIsAlphabetMode;
- private boolean mIsShiftLocked;
- private boolean mIsShifted;
-
- public void save() {
- mIsAlphabetMode = isAlphabetMode();
- if (mIsAlphabetMode) {
- mIsShiftLocked = mState.isShiftLocked();
- mIsShifted = !mIsShiftLocked && mState.isShiftedOrShiftLocked();
- } else {
- mIsShiftLocked = false;
- mIsShifted = isSymbolShifted();
- }
- mIsValid = true;
- if (DEBUG_STATE) {
- Log.d(TAG, "save: alphabet=" + mIsAlphabetMode + " shiftLocked=" + mIsShiftLocked
- + " shift=" + mIsShifted);
- }
- }
-
- public void restore() {
- if (DEBUG_STATE) {
- Log.d(TAG, "restore: valid=" + mIsValid + " alphabet=" + mIsAlphabetMode
- + " shiftLocked=" + mIsShiftLocked + " shift=" + mIsShifted);
- }
- if (!mIsValid || mIsAlphabetMode) {
- setAlphabetKeyboard();
- } else {
- if (mIsShifted) {
- setSymbolsShiftedKeyboard();
- } else {
- setSymbolsKeyboard();
- }
- }
-
- if (!mIsValid) return;
- mIsValid = false;
-
- if (mIsAlphabetMode) {
- setShiftLocked(mIsShiftLocked);
- if (!mIsShiftLocked) {
- setShifted(mIsShifted ? MANUAL_SHIFT : UNSHIFT);
- }
- }
- }
- }
-
public static KeyboardSwitcher getInstance() {
return sInstance;
}
@@ -194,7 +142,7 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
mSymbolsShiftedKeyboardId = getKeyboardId(editorInfo, true, true, settingsValues);
mState.onLoadKeyboard(mResources.getString(R.string.layout_switch_back_symbols));
mPrevMainKeyboardWasShiftLocked = false;
- mSavedKeyboardState.restore();
+ mState.onRestoreKeyboardState();
} catch (RuntimeException e) {
Log.w(TAG, "loading keyboard failed: " + mMainKeyboardId, e);
LatinImeLogger.logOnException(mMainKeyboardId.toString(), e);
@@ -203,7 +151,7 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
public void saveKeyboardState() {
if (mCurrentId != null) {
- mSavedKeyboardState.save();
+ mState.onSaveKeyboardState(isAlphabetMode(), isSymbolShifted());
}
}
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java
index a632a27b1..ee5ef9164 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java
@@ -17,11 +17,15 @@
package com.android.inputmethod.keyboard.internal;
import android.text.TextUtils;
+import android.util.Log;
import com.android.inputmethod.keyboard.Keyboard;
// TODO: Add unit tests
public class KeyboardState {
+ private static final String TAG = KeyboardState.class.getSimpleName();
+ private static final boolean DEBUG_STATE = false;
+
public interface SwitchActions {
public void setAlphabetKeyboard();
public static final int UNSHIFT = 0;
@@ -52,6 +56,15 @@ public class KeyboardState {
private final SwitchActions mSwitchActions;
+ private final SavedKeyboardState mSavedKeyboardState = new SavedKeyboardState();
+
+ private static class SavedKeyboardState {
+ public boolean mIsValid;
+ public boolean mIsAlphabetMode;
+ public boolean mIsShiftLocked;
+ public boolean mIsShifted;
+ }
+
public KeyboardState(SwitchActions switchActions) {
mSwitchActions = switchActions;
}
@@ -64,6 +77,52 @@ public class KeyboardState {
mSymbolKeyState.onRelease();
}
+ // TODO: Get rid of isAlphabetMode and isSymbolShifted arguments.
+ public void onSaveKeyboardState(boolean isAlphabetMode, boolean isSymbolShifted) {
+ final SavedKeyboardState state = mSavedKeyboardState;
+ state.mIsAlphabetMode = isAlphabetMode;
+ if (isAlphabetMode) {
+ state.mIsShiftLocked = isShiftLocked();
+ state.mIsShifted = !state.mIsShiftLocked && isShiftedOrShiftLocked();
+ } else {
+ state.mIsShiftLocked = false;
+ state.mIsShifted = isSymbolShifted;
+ }
+ state.mIsValid = true;
+ if (DEBUG_STATE) {
+ Log.d(TAG, "save: alphabet=" + state.mIsAlphabetMode
+ + " shiftLocked=" + state.mIsShiftLocked + " shift=" + state.mIsShifted);
+ }
+ }
+
+ public void onRestoreKeyboardState() {
+ final SavedKeyboardState state = mSavedKeyboardState;
+ if (DEBUG_STATE) {
+ Log.d(TAG, "restore: valid=" + state.mIsValid + " alphabet=" + state.mIsAlphabetMode
+ + " shiftLocked=" + state.mIsShiftLocked + " shift=" + state.mIsShifted);
+ }
+ if (!state.mIsValid || state.mIsAlphabetMode) {
+ mSwitchActions.setAlphabetKeyboard();
+ } else {
+ if (state.mIsShifted) {
+ mSwitchActions.setSymbolsShiftedKeyboard();
+ } else {
+ mSwitchActions.setSymbolsKeyboard();
+ }
+ }
+
+ if (!state.mIsValid) return;
+ state.mIsValid = false;
+
+ if (state.mIsAlphabetMode) {
+ mSwitchActions.setShiftLocked(state.mIsShiftLocked);
+ if (!state.mIsShiftLocked) {
+ mSwitchActions.setShifted(
+ state.mIsShifted ? SwitchActions.MANUAL_SHIFT : SwitchActions.UNSHIFT);
+ }
+ }
+ }
+
// TODO: Get rid of this method
public void onSetKeyboard(boolean isAlphabetMode) {
mSwitchState = isAlphabetMode ? SWITCH_STATE_ALPHA : SWITCH_STATE_SYMBOL_BEGIN;
diff --git a/java/src/com/android/inputmethod/latin/SuggestionsView.java b/java/src/com/android/inputmethod/latin/SuggestionsView.java
index 8c49ba0cf..10f5ec9db 100644
--- a/java/src/com/android/inputmethod/latin/SuggestionsView.java
+++ b/java/src/com/android/inputmethod/latin/SuggestionsView.java
@@ -672,34 +672,8 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
mPreviewPopup.dismiss();
}
- private void showPreview(View view, CharSequence word) {
- if (TextUtils.isEmpty(word))
- return;
-
- final TextView previewText = mPreviewText;
- previewText.setTextColor(mParams.mColorTypedWord);
- previewText.setText(word);
- previewText.measure(
- ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
- final int[] offsetInWindow = new int[2];
- view.getLocationInWindow(offsetInWindow);
- final int posX = offsetInWindow[0];
- final int posY = offsetInWindow[1] - previewText.getMeasuredHeight();
- final PopupWindow previewPopup = mPreviewPopup;
- if (previewPopup.isShowing()) {
- previewPopup.update(posX, posY, previewPopup.getWidth(), previewPopup.getHeight());
- } else {
- previewPopup.showAtLocation(this, Gravity.NO_GRAVITY, posX, posY);
- }
- previewText.setVisibility(VISIBLE);
- mHandler.postHidePreview();
- }
-
private void addToDictionary(CharSequence word) {
- if (mListener.addWordToDictionary(word.toString())) {
- final CharSequence message = getContext().getString(R.string.added_word, word);
- showPreview(mParams.mWordToSaveView, message);
- }
+ mListener.addWordToDictionary(word.toString());
}
private final KeyboardActionListener mMoreSuggestionsListener =
diff --git a/java/src/com/android/inputmethod/latin/UserDictionary.java b/java/src/com/android/inputmethod/latin/UserDictionary.java
index 3e53bb0a3..8c28324d8 100644
--- a/java/src/com/android/inputmethod/latin/UserDictionary.java
+++ b/java/src/com/android/inputmethod/latin/UserDictionary.java
@@ -20,6 +20,7 @@ import android.content.ContentProviderClient;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
+import android.content.Intent;
import android.database.ContentObserver;
import android.database.Cursor;
import android.net.Uri;
@@ -38,11 +39,9 @@ public class UserDictionary extends ExpandableDictionary {
Words.FREQUENCY,
};
- private static final String[] PROJECTION_ADD = {
- Words._ID,
- Words.FREQUENCY,
- Words.LOCALE,
- };
+ // This is not exported by the framework so we pretty much have to write it here verbatim
+ private static final String ACTION_USER_DICTIONARY_INSERT =
+ "com.android.settings.USER_DICTIONARY_INSERT";
private ContentObserver mObserver;
final private String mLocale;
@@ -164,54 +163,19 @@ public class UserDictionary extends ExpandableDictionary {
public synchronized void addWord(final String word, final int frequency) {
// Force load the dictionary here synchronously
if (getRequiresReload()) loadDictionaryAsync();
+ // 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() >= getMaxWordLength()) return;
super.addWord(word, frequency);
- // Update the user dictionary provider
- final ContentValues values = new ContentValues(5);
- values.put(Words.WORD, word);
- values.put(Words.FREQUENCY, frequency);
- values.put(Words.LOCALE, mLocale);
- values.put(Words.APP_ID, 0);
-
- final ContentResolver contentResolver = getContext().getContentResolver();
- final ContentProviderClient client =
- contentResolver.acquireContentProviderClient(Words.CONTENT_URI);
- if (null == client) return;
- new Thread("addWord") {
- @Override
- public void run() {
- Cursor cursor = null;
- try {
- cursor = client.query(Words.CONTENT_URI, PROJECTION_ADD,
- "word=? and ((locale IS NULL) or (locale=?))",
- new String[] { word, mLocale }, null);
- if (cursor != null && cursor.moveToFirst()) {
- final String locale = cursor.getString(cursor.getColumnIndex(Words.LOCALE));
- // If locale is null, we will not override the entry.
- if (locale != null && locale.equals(mLocale.toString())) {
- final long id = cursor.getLong(cursor.getColumnIndex(Words._ID));
- final Uri uri =
- Uri.withAppendedPath(Words.CONTENT_URI, Long.toString(id));
- // Update the entry with new frequency value.
- client.update(uri, values, null, null);
- }
- } else {
- // Insert new entry.
- client.insert(Words.CONTENT_URI, values);
- }
- } catch (RemoteException e) {
- // If we come here, the activity is already about to be killed, and we
- // have no means of contacting the content provider any more.
- // See ContentResolver#insert, inside the catch(){}
- } finally {
- if (null != cursor) cursor.close();
- client.release();
- }
- }
- }.start();
+ // 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);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ getContext().startActivity(intent);
// In case the above does a synchronous callback of the change observer
setRequiresReload(false);