aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod')
-rw-r--r--java/src/com/android/inputmethod/dictionarypack/CommonPreferences.java2
-rw-r--r--java/src/com/android/inputmethod/dictionarypack/DictionaryDownloadProgressBar.java1
-rw-r--r--java/src/com/android/inputmethod/keyboard/EmojiPalettesView.java58
-rw-r--r--java/src/com/android/inputmethod/keyboard/MainKeyboardView.java4
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/EmojiPageKeyboardView.java22
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/TimerHandler.java2
-rw-r--r--java/src/com/android/inputmethod/latin/BinaryDictionary.java3
-rw-r--r--java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java2
8 files changed, 60 insertions, 34 deletions
diff --git a/java/src/com/android/inputmethod/dictionarypack/CommonPreferences.java b/java/src/com/android/inputmethod/dictionarypack/CommonPreferences.java
index 7c27e6d51..3d0e29ed0 100644
--- a/java/src/com/android/inputmethod/dictionarypack/CommonPreferences.java
+++ b/java/src/com/android/inputmethod/dictionarypack/CommonPreferences.java
@@ -23,7 +23,7 @@ public final class CommonPreferences {
private static final String COMMON_PREFERENCES_NAME = "LatinImeDictPrefs";
public static SharedPreferences getCommonPreferences(final Context context) {
- return context.getSharedPreferences(COMMON_PREFERENCES_NAME, Context.MODE_WORLD_READABLE);
+ return context.getSharedPreferences(COMMON_PREFERENCES_NAME, 0);
}
public static void enable(final SharedPreferences pref, final String id) {
diff --git a/java/src/com/android/inputmethod/dictionarypack/DictionaryDownloadProgressBar.java b/java/src/com/android/inputmethod/dictionarypack/DictionaryDownloadProgressBar.java
index 88b5032e3..384ee3e07 100644
--- a/java/src/com/android/inputmethod/dictionarypack/DictionaryDownloadProgressBar.java
+++ b/java/src/com/android/inputmethod/dictionarypack/DictionaryDownloadProgressBar.java
@@ -100,6 +100,7 @@ public class DictionaryDownloadProgressBar extends ProgressBar {
@Override
protected void onDetachedFromWindow() {
+ super.onDetachedFromWindow();
mIsCurrentlyAttachedToWindow = false;
updateReporterThreadRunningStatusAccordingToVisibility();
}
diff --git a/java/src/com/android/inputmethod/keyboard/EmojiPalettesView.java b/java/src/com/android/inputmethod/keyboard/EmojiPalettesView.java
index ff0d53865..8dea908e8 100644
--- a/java/src/com/android/inputmethod/keyboard/EmojiPalettesView.java
+++ b/java/src/com/android/inputmethod/keyboard/EmojiPalettesView.java
@@ -71,8 +71,8 @@ import java.util.concurrent.ConcurrentHashMap;
* Because of the above reasons, this class doesn't extend {@link KeyboardView}.
*/
public final class EmojiPalettesView extends LinearLayout implements OnTabChangeListener,
- ViewPager.OnPageChangeListener, View.OnClickListener,
- EmojiPageKeyboardView.OnKeyClickListener {
+ ViewPager.OnPageChangeListener, View.OnTouchListener,
+ EmojiPageKeyboardView.OnKeyEventListener {
static final String TAG = EmojiPalettesView.class.getSimpleName();
private static final boolean DEBUG_PAGER = false;
private final int mKeyBackgroundId;
@@ -486,16 +486,16 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange
final ImageView alphabetKey = (ImageView)findViewById(R.id.emoji_keyboard_alphabet);
alphabetKey.setBackgroundResource(mEmojiFunctionalKeyBackgroundId);
alphabetKey.setTag(Constants.CODE_SWITCH_ALPHA_SYMBOL);
- alphabetKey.setOnClickListener(this);
+ alphabetKey.setOnTouchListener(this);
final ImageView spaceKey = (ImageView)findViewById(R.id.emoji_keyboard_space);
spaceKey.setBackgroundResource(mKeyBackgroundId);
spaceKey.setTag(Constants.CODE_SPACE);
- spaceKey.setOnClickListener(this);
+ spaceKey.setOnTouchListener(this);
mEmojiLayoutParams.setKeyProperties(spaceKey);
final ImageView alphabetKey2 = (ImageView)findViewById(R.id.emoji_keyboard_alphabet2);
alphabetKey2.setBackgroundResource(mEmojiFunctionalKeyBackgroundId);
alphabetKey2.setTag(Constants.CODE_SWITCH_ALPHA_SYMBOL);
- alphabetKey2.setOnClickListener(this);
+ alphabetKey2.setOnTouchListener(this);
}
@Override
@@ -543,31 +543,51 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange
}
}
+ // Called from {@link EmojiPageKeyboardView} through {@link View.OnTouchListener} interface to
+ // handle touch events from View-based elements such as the space bar.
@Override
- public void onClick(final View v) {
- if (v.getTag() instanceof Integer) {
- final int code = (Integer)v.getTag();
- registerCode(code);
- return;
+ public boolean onTouch(final View v, final MotionEvent event) {
+ final Object tag = v.getTag();
+ if (!(tag instanceof Integer)) {
+ return false;
+ }
+ final int code = (Integer) tag;
+ switch (event.getAction()) {
+ case MotionEvent.ACTION_DOWN:
+ mKeyboardActionListener.onPressKey(
+ code, 0 /* repeatCount */, true /* isSinglePointer */);
+ break;
+ case MotionEvent.ACTION_UP:
+ mKeyboardActionListener.onCodeInput(code, NOT_A_COORDINATE, NOT_A_COORDINATE);
+ mKeyboardActionListener.onReleaseKey(code, false /* withSliding */);
+ break;
}
+ return false;
}
- private void registerCode(final int code) {
+ // Called from {@link EmojiPageKeyboardView} through
+ // {@link EmojiPageKeyboardView.OnKeyEventListener} interface to handle touch events from
+ // non-View-based elements like typical Emoji characters.
+ @Override
+ public void onPressKey(final Key key) {
+ final int code = key.getCode();
mKeyboardActionListener.onPressKey(code, 0 /* repeatCount */, true /* isSinglePointer */);
- mKeyboardActionListener.onCodeInput(code, NOT_A_COORDINATE, NOT_A_COORDINATE);
- mKeyboardActionListener.onReleaseKey(code, false /* withSliding */);
}
+ // Called from {@link EmojiPageKeyboardView} through
+ // {@link EmojiPageKeyboardView.OnKeyEventListener} interface to handle touch events from
+ // non-View-based elements like typical Emoji characters.
@Override
- public void onKeyClick(final Key key) {
+ public void onReleaseKey(final Key key) {
mEmojiPalettesAdapter.addRecentKey(key);
mEmojiCategory.saveLastTypedCategoryPage();
final int code = key.getCode();
if (code == Constants.CODE_OUTPUT_TEXT) {
mKeyboardActionListener.onTextInput(key.getOutputText());
- return;
+ } else {
+ mKeyboardActionListener.onCodeInput(code, NOT_A_COORDINATE, NOT_A_COORDINATE);
}
- registerCode(code);
+ mKeyboardActionListener.onReleaseKey(code, false /* withSliding */);
}
public void setHardwareAcceleratedDrawingEnabled(final boolean enabled) {
@@ -630,7 +650,7 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange
}
private static class EmojiPalettesAdapter extends PagerAdapter {
- private final EmojiPageKeyboardView.OnKeyClickListener mListener;
+ private final EmojiPageKeyboardView.OnKeyEventListener mListener;
private final DynamicGridKeyboard mRecentsKeyboard;
private final SparseArray<EmojiPageKeyboardView> mActiveKeyboardViews =
CollectionUtils.newSparseArray();
@@ -638,7 +658,7 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange
private int mActivePosition = 0;
public EmojiPalettesAdapter(final EmojiCategory emojiCategory,
- final EmojiPageKeyboardView.OnKeyClickListener listener) {
+ final EmojiPageKeyboardView.OnKeyEventListener listener) {
mEmojiCategory = emojiCategory;
mListener = listener;
mRecentsKeyboard = mEmojiCategory.getKeyboard(CATEGORY_ID_RECENTS, 0);
@@ -702,7 +722,7 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange
final EmojiPageKeyboardView keyboardView = (EmojiPageKeyboardView)inflater.inflate(
R.layout.emoji_keyboard_page, container, false /* attachToRoot */);
keyboardView.setKeyboard(keyboard);
- keyboardView.setOnKeyClickListener(mListener);
+ keyboardView.setOnKeyEventListener(mListener);
container.addView(keyboardView);
mActiveKeyboardViews.put(position, keyboardView);
return keyboardView;
diff --git a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
index e1c841de7..810bd9150 100644
--- a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
@@ -424,8 +424,8 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
*/
@Override
public void setKeyboard(final Keyboard keyboard) {
- // Remove any pending messages.
- mKeyTimerHandler.cancelAllKeyTimers();
+ // Remove any pending messages, except dismissing preview and key repeat.
+ mKeyTimerHandler.cancelLongPressTimers();
super.setKeyboard(keyboard);
mKeyDetector.setKeyboard(
keyboard, -getPaddingLeft(), -getPaddingTop() + getVerticalCorrection());
diff --git a/java/src/com/android/inputmethod/keyboard/internal/EmojiPageKeyboardView.java b/java/src/com/android/inputmethod/keyboard/internal/EmojiPageKeyboardView.java
index 2e80f7962..5c7c6e39d 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/EmojiPageKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/EmojiPageKeyboardView.java
@@ -35,16 +35,19 @@ import com.android.inputmethod.latin.R;
// TODO: Implement key popup preview.
public final class EmojiPageKeyboardView extends KeyboardView implements
GestureDetector.OnGestureListener {
- public interface OnKeyClickListener {
- public void onKeyClick(Key key);
+ public interface OnKeyEventListener {
+ public void onPressKey(Key key);
+ public void onReleaseKey(Key key);
}
- private static final OnKeyClickListener EMPTY_LISTENER = new OnKeyClickListener() {
- @Override
- public void onKeyClick(final Key key) {}
+ private static final OnKeyEventListener EMPTY_LISTENER = new OnKeyEventListener() {
+ @Override
+ public void onPressKey(final Key key) {}
+ @Override
+ public void onReleaseKey(final Key key) {}
};
- private OnKeyClickListener mListener = EMPTY_LISTENER;
+ private OnKeyEventListener mListener = EMPTY_LISTENER;
private final KeyDetector mKeyDetector = new KeyDetector(0.0f /*keyHysteresisDistance */);
private final GestureDetector mGestureDetector;
@@ -59,7 +62,7 @@ public final class EmojiPageKeyboardView extends KeyboardView implements
mGestureDetector.setIsLongpressEnabled(false /* isLongpressEnabled */);
}
- public void setOnKeyClickListener(final OnKeyClickListener listener) {
+ public void setOnKeyEventListener(final OnKeyEventListener listener) {
mListener = listener;
}
@@ -115,9 +118,9 @@ public final class EmojiPageKeyboardView extends KeyboardView implements
if (key == null) {
return false;
}
- // TODO: May call {@link KeyboardActionListener#onPressKey(int,int,boolean)}.
key.onPressed();
invalidateKey(key);
+ mListener.onPressKey(key);
return false;
}
@@ -133,10 +136,9 @@ public final class EmojiPageKeyboardView extends KeyboardView implements
if (key == null) {
return false;
}
- // TODO: May call {@link KeyboardActionListener#onReleaseKey(int,boolean)}.
key.onReleased();
invalidateKey(key);
- mListener.onKeyClick(key);
+ mListener.onReleaseKey(key);
return true;
}
diff --git a/java/src/com/android/inputmethod/keyboard/internal/TimerHandler.java b/java/src/com/android/inputmethod/keyboard/internal/TimerHandler.java
index 3298a3f24..ec7b9b024 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/TimerHandler.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/TimerHandler.java
@@ -126,7 +126,7 @@ public final class TimerHandler extends LeakGuardHandlerWrapper<Callbacks> imple
removeMessages(MSG_LONGPRESS_SHIFT_KEY);
}
- private void cancelLongPressTimers() {
+ public void cancelLongPressTimers() {
removeMessages(MSG_LONGPRESS_KEY);
removeMessages(MSG_LONGPRESS_SHIFT_KEY);
}
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
index 95ac3e203..708f75a06 100644
--- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
@@ -365,6 +365,7 @@ public final class BinaryDictionary extends Dictionary {
}
public static class LanguageModelParam {
+ public final String mTargetWord;
public final int[] mWord0;
public final int[] mWord1;
// TODO: this needs to be a list of shortcuts
@@ -379,6 +380,7 @@ public final class BinaryDictionary extends Dictionary {
// Constructor for unigram. TODO: support shortcuts
public LanguageModelParam(final String word, final int unigramProbability,
final int timestamp) {
+ mTargetWord = word;
mWord0 = null;
mWord1 = StringUtils.toCodePointArray(word);
mShortcutTarget = null;
@@ -394,6 +396,7 @@ public final class BinaryDictionary extends Dictionary {
public LanguageModelParam(final String word0, final String word1,
final int unigramProbability, final int bigramProbability,
final int timestamp) {
+ mTargetWord = word1;
mWord0 = StringUtils.toCodePointArray(word0);
mWord1 = StringUtils.toCodePointArray(word1);
mShortcutTarget = null;
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
index 181ad17ea..7e97802e1 100644
--- a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
+++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
@@ -112,7 +112,7 @@ final public class BinaryDictionaryGetter {
public DictPackSettings(final Context context) {
mDictPreferences = null == context ? null
: context.getSharedPreferences(COMMON_PREFERENCES_NAME,
- Context.MODE_WORLD_READABLE | Context.MODE_MULTI_PROCESS);
+ Context.MODE_MULTI_PROCESS);
}
public boolean isWordListActive(final String dictId) {
if (null == mDictPreferences) {