aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/keyboard/emoji/EmojiCategory.java3
-rw-r--r--java/src/com/android/inputmethod/latin/EmojiAltPhysicalKeyDetector.java93
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java10
-rw-r--r--java/src/com/android/inputmethod/latin/settings/AppearanceSettingsFragment.java8
-rw-r--r--java/src/com/android/inputmethod/latin/settings/DebugSettings.java2
-rw-r--r--java/src/com/android/inputmethod/latin/settings/DebugSettingsFragment.java3
-rw-r--r--java/src/com/android/inputmethod/latin/settings/LocalSettingsConstants.java1
-rw-r--r--java/src/com/android/inputmethod/latin/settings/Settings.java6
-rw-r--r--java/src/com/android/inputmethod/latin/settings/SettingsValues.java11
-rw-r--r--java/src/com/android/inputmethod/latin/utils/CollectionUtils.java12
-rw-r--r--java/src/com/android/inputmethod/latin/utils/CoordinateUtils.java35
11 files changed, 141 insertions, 43 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/emoji/EmojiCategory.java b/java/src/com/android/inputmethod/keyboard/emoji/EmojiCategory.java
index 0e8ce7f23..a9711aed2 100644
--- a/java/src/com/android/inputmethod/keyboard/emoji/EmojiCategory.java
+++ b/java/src/com/android/inputmethod/keyboard/emoji/EmojiCategory.java
@@ -30,7 +30,6 @@ import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.KeyboardId;
import com.android.inputmethod.keyboard.KeyboardLayoutSet;
import com.android.inputmethod.latin.R;
-import com.android.inputmethod.latin.common.Constants;
import com.android.inputmethod.latin.settings.Settings;
import java.util.ArrayList;
@@ -271,7 +270,7 @@ final class EmojiCategory {
}
private static final Long getCategoryKeyboardMapKey(final int categoryId, final int id) {
- return (((long) categoryId) << Constants.MAX_INT_BIT_COUNT) | id;
+ return (((long) categoryId) << Integer.SIZE) | id;
}
public DynamicGridKeyboard getKeyboard(final int categoryId, final int id) {
diff --git a/java/src/com/android/inputmethod/latin/EmojiAltPhysicalKeyDetector.java b/java/src/com/android/inputmethod/latin/EmojiAltPhysicalKeyDetector.java
new file mode 100644
index 000000000..8116a4983
--- /dev/null
+++ b/java/src/com/android/inputmethod/latin/EmojiAltPhysicalKeyDetector.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2014, 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.view.KeyEvent;
+
+import com.android.inputmethod.keyboard.KeyboardSwitcher;
+import com.android.inputmethod.latin.settings.Settings;
+
+/**
+ * A class for detecting Emoji-Alt physical key.
+ */
+final class EmojiAltPhysicalKeyDetector {
+ // True if the Alt key has been used as a modifier. In this case the Alt key up isn't
+ // recognized as an emoji key.
+ private boolean mAltHasBeenUsedAsAModifier;
+
+ /**
+ * Record a down key event.
+ * @param keyEvent a down key event.
+ */
+ public void onKeyDown(final KeyEvent keyEvent) {
+ if (isAltKey(keyEvent)) {
+ mAltHasBeenUsedAsAModifier = false;
+ }
+ if (containsAltModifier(keyEvent)) {
+ mAltHasBeenUsedAsAModifier = true;
+ }
+ }
+
+ /**
+ * Determine whether an up key event is a special key up or not.
+ * @param keyEvent an up key event.
+ */
+ public void onKeyUp(final KeyEvent keyEvent) {
+ if (keyEvent.isCanceled()) {
+ // This key up event was a part of key combinations and should be ignored.
+ return;
+ }
+ if (!isAltKey(keyEvent)) {
+ mAltHasBeenUsedAsAModifier |= containsAltModifier(keyEvent);
+ return;
+ }
+ if (containsAltModifier(keyEvent)) {
+ mAltHasBeenUsedAsAModifier = true;
+ return;
+ }
+ if (!Settings.getInstance().getCurrent().mEnableEmojiAltPhysicalKey) {
+ return;
+ }
+ if (!mAltHasBeenUsedAsAModifier) {
+ onEmojiAltKeyDetected();
+ }
+ }
+
+ private static void onEmojiAltKeyDetected() {
+ KeyboardSwitcher.getInstance().onToggleEmojiKeyboard();
+ }
+
+ private static boolean isAltKey(final KeyEvent keyEvent) {
+ final int keyCode = keyEvent.getKeyCode();
+ return keyCode == KeyEvent.KEYCODE_ALT_LEFT || keyCode == KeyEvent.KEYCODE_ALT_RIGHT;
+ }
+
+ private static boolean containsAltModifier(final KeyEvent keyEvent) {
+ final int metaState = keyEvent.getMetaState();
+ // TODO: Support multiple keyboards. Take device id into account.
+ switch (keyEvent.getKeyCode()) {
+ case KeyEvent.KEYCODE_ALT_LEFT:
+ // Return true if Left-Alt is pressed with Right-Alt pressed.
+ return (metaState & KeyEvent.META_ALT_RIGHT_ON) != 0;
+ case KeyEvent.KEYCODE_ALT_RIGHT:
+ // Return true if Right-Alt is pressed with Left-Alt pressed.
+ return (metaState & KeyEvent.META_ALT_LEFT_ON) != 0;
+ default:
+ return (metaState & (KeyEvent.META_ALT_LEFT_ON | KeyEvent.META_ALT_RIGHT_ON)) != 0;
+ }
+ }
+}
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 11cbec378..ff82087ae 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -167,7 +167,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
@UsedForTesting final KeyboardSwitcher mKeyboardSwitcher;
final SubtypeSwitcher mSubtypeSwitcher;
private final SubtypeState mSubtypeState = new SubtypeState();
- private final SpecialKeyDetector mSpecialKeyDetector;
+ private final EmojiAltPhysicalKeyDetector mEmojiAltPhysicalKeyDetector =
+ new EmojiAltPhysicalKeyDetector();
private StatsUtilsManager mStatsUtilsManager;
// Working variable for {@link #startShowingInputView()} and
// {@link #onEvaluateInputViewShown()}.
@@ -545,7 +546,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mSettings = Settings.getInstance();
mSubtypeSwitcher = SubtypeSwitcher.getInstance();
mKeyboardSwitcher = KeyboardSwitcher.getInstance();
- mSpecialKeyDetector = new SpecialKeyDetector(this);
mStatsUtilsManager = StatsUtilsManager.getInstance();
mIsHardwareAcceleratedDrawingEnabled =
InputMethodServiceCompatUtils.enableHardwareAcceleration(this);
@@ -1765,7 +1765,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// Hooks for hardware keyboard
@Override
public boolean onKeyDown(final int keyCode, final KeyEvent keyEvent) {
- mSpecialKeyDetector.onKeyDown(keyEvent);
+ // TODO: This should be processed in {@link InputLogic}.
+ mEmojiAltPhysicalKeyDetector.onKeyDown(keyEvent);
if (!ProductionFlags.IS_HARDWARE_KEYBOARD_SUPPORTED) {
return super.onKeyDown(keyCode, keyEvent);
}
@@ -1786,7 +1787,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
@Override
public boolean onKeyUp(final int keyCode, final KeyEvent keyEvent) {
- mSpecialKeyDetector.onKeyUp(keyEvent);
+ // TODO: This should be processed in {@link InputLogic}.
+ mEmojiAltPhysicalKeyDetector.onKeyUp(keyEvent);
if (!ProductionFlags.IS_HARDWARE_KEYBOARD_SUPPORTED) {
return super.onKeyUp(keyCode, keyEvent);
}
diff --git a/java/src/com/android/inputmethod/latin/settings/AppearanceSettingsFragment.java b/java/src/com/android/inputmethod/latin/settings/AppearanceSettingsFragment.java
index a9884ba13..554edc85c 100644
--- a/java/src/com/android/inputmethod/latin/settings/AppearanceSettingsFragment.java
+++ b/java/src/com/android/inputmethod/latin/settings/AppearanceSettingsFragment.java
@@ -19,9 +19,9 @@ package com.android.inputmethod.latin.settings;
import android.os.Bundle;
import com.android.inputmethod.latin.R;
+import com.android.inputmethod.latin.common.Constants;
import com.android.inputmethod.latin.define.ProductionFlags;
-
/**
* "Appearance" settings sub screen.
*/
@@ -30,8 +30,8 @@ public final class AppearanceSettingsFragment extends SubScreenFragment {
public void onCreate(final Bundle icicle) {
super.onCreate(icicle);
addPreferencesFromResource(R.xml.prefs_screen_appearance);
- if (!ProductionFlags.IS_SPLIT_KEYBOARD_SUPPORTED
- || !Settings.getInstance().getCurrent().isTablet()) {
+ if (!ProductionFlags.IS_SPLIT_KEYBOARD_SUPPORTED ||
+ Constants.isPhone(Settings.readScreenMetrics(getResources()))) {
removePreference(Settings.PREF_ENABLE_SPLIT_KEYBOARD);
}
}
@@ -43,4 +43,4 @@ public final class AppearanceSettingsFragment extends SubScreenFragment {
findPreference(Settings.PREF_CUSTOM_INPUT_STYLES));
ThemeSettingsFragment.updateKeyboardThemeSummary(findPreference(Settings.SCREEN_THEME));
}
-} \ No newline at end of file
+}
diff --git a/java/src/com/android/inputmethod/latin/settings/DebugSettings.java b/java/src/com/android/inputmethod/latin/settings/DebugSettings.java
index 768cba9b2..4985c2f08 100644
--- a/java/src/com/android/inputmethod/latin/settings/DebugSettings.java
+++ b/java/src/com/android/inputmethod/latin/settings/DebugSettings.java
@@ -27,8 +27,6 @@ package com.android.inputmethod.latin.settings;
public final class DebugSettings {
public static final String PREF_DEBUG_MODE = "debug_mode";
public static final String PREF_FORCE_NON_DISTINCT_MULTITOUCH = "force_non_distinct_multitouch";
- public static final String PREF_FORCE_PHYSICAL_KEYBOARD_SPECIAL_KEY =
- "force_physical_keyboard_special_key";
public static final String PREF_HAS_CUSTOM_KEY_PREVIEW_ANIMATION_PARAMS =
"pref_has_custom_key_preview_animation_params";
public static final String PREF_KEY_PREVIEW_DISMISS_DURATION =
diff --git a/java/src/com/android/inputmethod/latin/settings/DebugSettingsFragment.java b/java/src/com/android/inputmethod/latin/settings/DebugSettingsFragment.java
index 475f1def7..2e5c3c479 100644
--- a/java/src/com/android/inputmethod/latin/settings/DebugSettingsFragment.java
+++ b/java/src/com/android/inputmethod/latin/settings/DebugSettingsFragment.java
@@ -142,8 +142,7 @@ public final class DebugSettingsFragment extends SubScreenFragment
mServiceNeedsRestart = true;
return;
}
- if (key.equals(DebugSettings.PREF_FORCE_NON_DISTINCT_MULTITOUCH)
- || key.equals(DebugSettings.PREF_FORCE_PHYSICAL_KEYBOARD_SPECIAL_KEY)) {
+ if (key.equals(DebugSettings.PREF_FORCE_NON_DISTINCT_MULTITOUCH)) {
mServiceNeedsRestart = true;
return;
}
diff --git a/java/src/com/android/inputmethod/latin/settings/LocalSettingsConstants.java b/java/src/com/android/inputmethod/latin/settings/LocalSettingsConstants.java
index c9e9dc8d9..0fd94b0f8 100644
--- a/java/src/com/android/inputmethod/latin/settings/LocalSettingsConstants.java
+++ b/java/src/com/android/inputmethod/latin/settings/LocalSettingsConstants.java
@@ -46,7 +46,6 @@ public class LocalSettingsConstants {
// correctly set for it to work on a new device.
DebugSettings.PREF_DEBUG_MODE,
DebugSettings.PREF_FORCE_NON_DISTINCT_MULTITOUCH,
- DebugSettings.PREF_FORCE_PHYSICAL_KEYBOARD_SPECIAL_KEY,
DebugSettings.PREF_HAS_CUSTOM_KEY_PREVIEW_ANIMATION_PARAMS,
DebugSettings.PREF_KEY_PREVIEW_DISMISS_DURATION,
DebugSettings.PREF_KEY_PREVIEW_DISMISS_END_X_SCALE,
diff --git a/java/src/com/android/inputmethod/latin/settings/Settings.java b/java/src/com/android/inputmethod/latin/settings/Settings.java
index 5e23693d2..6d23fcb66 100644
--- a/java/src/com/android/inputmethod/latin/settings/Settings.java
+++ b/java/src/com/android/inputmethod/latin/settings/Settings.java
@@ -97,6 +97,8 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
"pref_vibration_duration_settings";
public static final String PREF_KEYPRESS_SOUND_VOLUME = "pref_keypress_sound_volume";
public static final String PREF_KEY_LONGPRESS_TIMEOUT = "pref_key_longpress_timeout";
+ public static final String PREF_ENABLE_EMOJI_ALT_PHYSICAL_KEY =
+ "pref_enable_emoji_alt_physical_key";
public static final String PREF_GESTURE_PREVIEW_TRAIL = "pref_gesture_preview_trail";
public static final String PREF_GESTURE_FLOATING_PREVIEW_TEXT =
"pref_gesture_floating_preview_text";
@@ -211,6 +213,10 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
return mSettingsValues.mBlockPotentiallyOffensive;
}
+ public static int readScreenMetrics(final Resources res) {
+ return res.getInteger(R.integer.config_screen_metrics);
+ }
+
// Accessed from the settings interface, hence public
public static boolean readKeypressSoundEnabled(final SharedPreferences prefs,
final Resources res) {
diff --git a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
index 660be06d6..bdb4e64e0 100644
--- a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
+++ b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
@@ -29,7 +29,6 @@ import com.android.inputmethod.latin.InputAttributes;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.RichInputMethodManager;
import com.android.inputmethod.latin.SubtypeSwitcher;
-import com.android.inputmethod.latin.common.Constants;
import com.android.inputmethod.latin.utils.AsyncResultHolder;
import com.android.inputmethod.latin.utils.ResourceUtils;
import com.android.inputmethod.latin.utils.TargetPackageInfoGetterTask;
@@ -80,6 +79,7 @@ public class SettingsValues {
public final boolean mSlidingKeyInputPreviewEnabled;
public final boolean mPhraseGestureEnabled;
public final int mKeyLongpressTimeout;
+ public final boolean mEnableEmojiAltPhysicalKey;
public final boolean mEnableMetricsLogging;
public final boolean mShouldShowLxxSuggestionUi;
// Use split layout for keyboard.
@@ -157,7 +157,7 @@ public class SettingsValues {
mHasHardwareKeyboard = Settings.readHasHardwareKeyboard(res.getConfiguration());
mEnableMetricsLogging = prefs.getBoolean(Settings.PREF_ENABLE_METRICS_LOGGING, true);
mIsSplitKeyboardEnabled = prefs.getBoolean(Settings.PREF_ENABLE_SPLIT_KEYBOARD, false);
- mScreenMetrics = res.getInteger(R.integer.config_screen_metrics);
+ mScreenMetrics = Settings.readScreenMetrics(res);
mShouldShowLxxSuggestionUi = Settings.SHOULD_SHOW_LXX_SUGGESTION_UI
&& prefs.getBoolean(DebugSettings.PREF_SHOULD_SHOW_LXX_SUGGESTION_UI, true);
@@ -166,6 +166,8 @@ public class SettingsValues {
mKeypressVibrationDuration = Settings.readKeypressVibrationDuration(prefs, res);
mKeypressSoundVolume = Settings.readKeypressSoundVolume(prefs, res);
mKeyPreviewPopupDismissDelay = Settings.readKeyPreviewPopupDismissDelay(prefs, res);
+ mEnableEmojiAltPhysicalKey = prefs.getBoolean(
+ Settings.PREF_ENABLE_EMOJI_ALT_PHYSICAL_KEY, true);
mAutoCorrectionThreshold = readAutoCorrectionThreshold(res,
autoCorrectionThresholdRawValue);
mGestureInputEnabled = Settings.readGestureInputEnabled(prefs, res);
@@ -221,11 +223,6 @@ public class SettingsValues {
return mEnableMetricsLogging;
}
- public boolean isTablet() {
- return mScreenMetrics == Constants.SCREEN_METRICS_SMALL_TABLET
- || mScreenMetrics == Constants.SCREEN_METRICS_LARGE_TABLET;
- }
-
public boolean isApplicationSpecifiedCompletionsOn() {
return mInputAttributes.mApplicationSpecifiedCompletionOn;
}
diff --git a/java/src/com/android/inputmethod/latin/utils/CollectionUtils.java b/java/src/com/android/inputmethod/latin/utils/CollectionUtils.java
index d0df72479..f9839eb91 100644
--- a/java/src/com/android/inputmethod/latin/utils/CollectionUtils.java
+++ b/java/src/com/android/inputmethod/latin/utils/CollectionUtils.java
@@ -19,15 +19,17 @@ package com.android.inputmethod.latin.utils;
import java.util.ArrayList;
import java.util.Collection;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
public final class CollectionUtils {
private CollectionUtils() {
// This utility class is not publicly instantiable.
}
- public static <E> ArrayList<E> arrayAsList(final E[] array, final int start, final int end) {
- if (array == null) {
- throw new NullPointerException();
- }
+ @Nonnull
+ public static <E> ArrayList<E> arrayAsList(@Nonnull final E[] array, final int start,
+ final int end) {
if (start < 0 || start > end || end > array.length) {
throw new IllegalArgumentException();
}
@@ -44,7 +46,7 @@ public final class CollectionUtils {
* @param c Collection to test.
* @return Whether c contains no elements.
*/
- public static boolean isNullOrEmpty(final Collection<?> c) {
+ public static boolean isNullOrEmpty(@Nullable final Collection<?> c) {
return c == null || c.isEmpty();
}
}
diff --git a/java/src/com/android/inputmethod/latin/utils/CoordinateUtils.java b/java/src/com/android/inputmethod/latin/utils/CoordinateUtils.java
index 87df013a6..3a9705904 100644
--- a/java/src/com/android/inputmethod/latin/utils/CoordinateUtils.java
+++ b/java/src/com/android/inputmethod/latin/utils/CoordinateUtils.java
@@ -16,7 +16,7 @@
package com.android.inputmethod.latin.utils;
-import java.util.Arrays;
+import javax.annotation.Nonnull;
public final class CoordinateUtils {
private static final int INDEX_X = 0;
@@ -27,32 +27,35 @@ public final class CoordinateUtils {
// This utility class is not publicly instantiable.
}
+ @Nonnull
public static int[] newInstance() {
return new int[ELEMENT_SIZE];
}
- public static int x(final int[] coords) {
+ public static int x(@Nonnull final int[] coords) {
return coords[INDEX_X];
}
- public static int y(final int[] coords) {
+ public static int y(@Nonnull final int[] coords) {
return coords[INDEX_Y];
}
- public static void set(final int[] coords, final int x, final int y) {
+ public static void set(@Nonnull final int[] coords, final int x, final int y) {
coords[INDEX_X] = x;
coords[INDEX_Y] = y;
}
- public static void copy(final int[] destination, final int[] source) {
+ public static void copy(@Nonnull final int[] destination, @Nonnull final int[] source) {
destination[INDEX_X] = source[INDEX_X];
destination[INDEX_Y] = source[INDEX_Y];
}
+ @Nonnull
public static int[] newCoordinateArray(final int arraySize) {
return new int[ELEMENT_SIZE * arraySize];
}
+ @Nonnull
public static int[] newCoordinateArray(final int arraySize,
final int defaultX, final int defaultY) {
final int[] result = new int[ELEMENT_SIZE * arraySize];
@@ -62,30 +65,30 @@ public final class CoordinateUtils {
return result;
}
- public static int xFromArray(final int[] coordsArray, final int index) {
+ public static int xFromArray(@Nonnull final int[] coordsArray, final int index) {
return coordsArray[ELEMENT_SIZE * index + INDEX_X];
}
- public static int yFromArray(final int[] coordsArray, final int index) {
+ public static int yFromArray(@Nonnull final int[] coordsArray, final int index) {
return coordsArray[ELEMENT_SIZE * index + INDEX_Y];
}
- public static int[] coordinateFromArray(final int[] coordsArray, final int index) {
- final int baseIndex = ELEMENT_SIZE * index;
- return Arrays.copyOfRange(coordsArray, baseIndex, baseIndex + ELEMENT_SIZE);
+ @Nonnull
+ public static int[] coordinateFromArray(@Nonnull final int[] coordsArray, final int index) {
+ final int[] coords = newInstance();
+ set(coords, xFromArray(coordsArray, index), yFromArray(coordsArray, index));
+ return coords;
}
- public static void setXYInArray(final int[] coordsArray, final int index,
+ public static void setXYInArray(@Nonnull final int[] coordsArray, final int index,
final int x, final int y) {
final int baseIndex = ELEMENT_SIZE * index;
coordsArray[baseIndex + INDEX_X] = x;
coordsArray[baseIndex + INDEX_Y] = y;
}
- public static void setCoordinateInArray(final int[] coordsArray, final int index,
- final int[] coords) {
- final int baseIndex = ELEMENT_SIZE * index;
- coordsArray[baseIndex + INDEX_X] = coords[INDEX_X];
- coordsArray[baseIndex + INDEX_Y] = coords[INDEX_Y];
+ public static void setCoordinateInArray(@Nonnull final int[] coordsArray, final int index,
+ @Nonnull final int[] coords) {
+ setXYInArray(coordsArray, index, x(coords), y(coords));
}
}