aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/LatinIME.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin/LatinIME.java')
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java133
1 files changed, 61 insertions, 72 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 385e884ab..a7798e335 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -31,7 +31,6 @@ import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.res.Configuration;
import android.content.res.Resources;
-import android.graphics.Rect;
import android.inputmethodservice.InputMethodService;
import android.media.AudioManager;
import android.net.ConnectivityManager;
@@ -51,7 +50,6 @@ import android.util.Printer;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.view.View;
-import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.CompletionInfo;
@@ -76,6 +74,7 @@ import com.android.inputmethod.keyboard.MainKeyboardView;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.define.ProductionFlag;
import com.android.inputmethod.latin.personalization.PersonalizationDictionaryHelper;
+import com.android.inputmethod.latin.personalization.PersonalizationDictionarySessionRegister;
import com.android.inputmethod.latin.personalization.PersonalizationPredictionDictionary;
import com.android.inputmethod.latin.personalization.UserHistoryPredictionDictionary;
import com.android.inputmethod.latin.settings.Settings;
@@ -150,9 +149,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private final Settings mSettings;
- private View mExtractArea;
- private View mKeyPreviewBackingView;
- private View mSuggestionsContainer;
+ private View mInputView;
+ private int mInputViewMinHeight;
private SuggestionStripView mSuggestionStripView;
// Never null
private SuggestedWords mSuggestedWords = SuggestedWords.EMPTY;
@@ -473,6 +471,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
KeyboardSwitcher.init(this);
AudioAndHapticFeedbackManager.init(this);
AccessibilityUtils.init(this);
+ PersonalizationDictionarySessionRegister.init(this);
super.onCreate();
@@ -653,6 +652,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mOptionsDialog.dismiss();
}
}
+ PersonalizationDictionarySessionRegister.onConfigurationChanged(this, conf);
super.onConfigurationChanged(conf);
}
@@ -661,18 +661,25 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
return mKeyboardSwitcher.onCreateInputView(mIsHardwareAcceleratedDrawingEnabled);
}
+ private void setInputViewMinHeight(final int minHeight) {
+ if (mInputView != null && mInputViewMinHeight != minHeight) {
+ mInputView.setMinimumHeight(minHeight);
+ mInputViewMinHeight = minHeight;
+ }
+ }
+
@Override
- public void setInputView(final View view) {
- super.setInputView(view);
- mExtractArea = getWindow().getWindow().getDecorView()
- .findViewById(android.R.id.extractArea);
- mKeyPreviewBackingView = view.findViewById(R.id.key_preview_backing);
- mSuggestionsContainer = view.findViewById(R.id.suggestions_container);
- mSuggestionStripView = (SuggestionStripView)view.findViewById(R.id.suggestion_strip_view);
- if (mSuggestionStripView != null)
- mSuggestionStripView.setListener(this, view);
+ public void setInputView(final View inputView) {
+ super.setInputView(inputView);
+ mInputView = inputView;
+ setInputViewMinHeight(0);
+ mSuggestionStripView = (SuggestionStripView)inputView.findViewById(
+ R.id.suggestion_strip_view);
+ if (mSuggestionStripView != null) {
+ mSuggestionStripView.setListener(this, inputView);
+ }
if (LatinImeLogger.sVISUALDEBUG) {
- mKeyPreviewBackingView.setBackgroundColor(0x10FF0000);
+ inputView.setBackgroundColor(0x10FF0000);
}
}
@@ -848,8 +855,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mainKeyboardView.setSlidingKeyInputPreviewEnabled(
currentSettingsValues.mSlidingKeyInputPreviewEnabled);
mainKeyboardView.setGestureHandlingEnabledByUser(
- currentSettingsValues.mGestureInputEnabled);
- mainKeyboardView.setGesturePreviewMode(currentSettingsValues.mGesturePreviewTrailEnabled,
+ currentSettingsValues.mGestureInputEnabled,
+ currentSettingsValues.mGestureTrailEnabled,
currentSettingsValues.mGestureFloatingPreviewTextEnabled);
// If we have a user dictionary addition in progress, we should check now if we should
@@ -1111,19 +1118,24 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private void setSuggestionStripShownInternal(final boolean shown,
final boolean needsInputViewShown) {
// TODO: Modify this if we support suggestions with hard keyboard
- if (onEvaluateInputViewShown() && mSuggestionsContainer != null) {
+ if (onEvaluateInputViewShown() && mSuggestionStripView != null) {
final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView();
final boolean inputViewShown = (mainKeyboardView != null)
? mainKeyboardView.isShown() : false;
final boolean shouldShowSuggestions = shown
&& (needsInputViewShown ? inputViewShown : true);
if (isFullscreenMode()) {
- mSuggestionsContainer.setVisibility(
+ mSuggestionStripView.setVisibility(
shouldShowSuggestions ? View.VISIBLE : View.GONE);
} else {
- mSuggestionsContainer.setVisibility(
+ mSuggestionStripView.setVisibility(
shouldShowSuggestions ? View.VISIBLE : View.INVISIBLE);
}
+ if (shouldShowSuggestions && mainKeyboardView != null) {
+ final int remainingHeight = getWindow().getWindow().getDecorView().getHeight()
+ - mainKeyboardView.getHeight() - mSuggestionStripView.getHeight();
+ mSuggestionStripView.setMoreSuggestionsHeight(remainingHeight);
+ }
}
}
@@ -1131,64 +1143,37 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
setSuggestionStripShownInternal(shown, /* needsInputViewShown */true);
}
- private int getAdjustedBackingViewHeight() {
- final int currentHeight = mKeyPreviewBackingView.getHeight();
- if (currentHeight > 0) {
- return currentHeight;
- }
-
- final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView();
- if (mainKeyboardView == null) {
- return 0;
- }
- final int keyboardHeight = mainKeyboardView.getHeight();
- final int suggestionsHeight = mSuggestionsContainer.getHeight();
- final int displayHeight = getResources().getDisplayMetrics().heightPixels;
- final Rect rect = new Rect();
- mKeyPreviewBackingView.getWindowVisibleDisplayFrame(rect);
- final int notificationBarHeight = rect.top;
- final int remainingHeight = displayHeight - notificationBarHeight - suggestionsHeight
- - keyboardHeight;
-
- final LayoutParams params = mKeyPreviewBackingView.getLayoutParams();
- params.height = mSuggestionStripView.setMoreSuggestionsHeight(remainingHeight);
- mKeyPreviewBackingView.setLayoutParams(params);
- return params.height;
- }
-
@Override
public void onComputeInsets(final InputMethodService.Insets outInsets) {
super.onComputeInsets(outInsets);
final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView();
- if (mainKeyboardView == null || mSuggestionsContainer == null) {
+ if (mainKeyboardView == null || mSuggestionStripView == null) {
return;
}
- final int adjustedBackingHeight = getAdjustedBackingViewHeight();
- final boolean backingGone = (mKeyPreviewBackingView.getVisibility() == View.GONE);
- final int backingHeight = backingGone ? 0 : adjustedBackingHeight;
- // In fullscreen mode, the height of the extract area managed by InputMethodService should
- // be considered.
- // See {@link android.inputmethodservice.InputMethodService#onComputeInsets}.
- final int extractHeight = isFullscreenMode() ? mExtractArea.getHeight() : 0;
- final int suggestionsHeight = (mSuggestionsContainer.getVisibility() == View.GONE) ? 0
- : mSuggestionsContainer.getHeight();
- final int extraHeight = extractHeight + backingHeight + suggestionsHeight;
- int visibleTopY = extraHeight;
+ // This method is never called when in fullscreen mode.
+ // The contentTop is the top coordinate of the keyboard. The application behind will be
+ // resized/panned above this coordibnate to be able to show an input field.
+ final int contentTop = mInputView.getHeight() - mainKeyboardView.getHeight();
+ final int suggestionsHeight = (mSuggestionStripView.getVisibility() == View.VISIBLE)
+ ? mSuggestionStripView.getHeight() : 0;
+ // The visibleTop is the top coordinates of the visible part of this IME. The application
+ // behind will never be resized, but may be panned or scrolled.
+ final int visibleTop = mainKeyboardView.isShowingMoreKeysPanel() ? 0
+ : contentTop - suggestionsHeight;
+ outInsets.contentTopInsets = contentTop;
+ outInsets.visibleTopInsets = visibleTop;
// Need to set touchable region only if input view is being shown
if (mainKeyboardView.isShown()) {
- if (mSuggestionsContainer.getVisibility() == View.VISIBLE) {
- visibleTopY -= suggestionsHeight;
- }
- final int touchY = mainKeyboardView.isShowingMoreKeysPanel() ? 0 : visibleTopY;
- final int touchWidth = mainKeyboardView.getWidth();
- final int touchHeight = mainKeyboardView.getHeight() + extraHeight
+ final int touchLeft = 0;
+ final int touchTop = visibleTop;
+ final int touchRight = touchLeft + mainKeyboardView.getWidth();
+ final int touchBottom = contentTop + mainKeyboardView.getHeight()
// Extend touchable region below the keyboard.
+ EXTENDED_TOUCHABLE_REGION_HEIGHT;
+ // The touch event on touchableRegion will be delivered to this IME.
+ outInsets.touchableRegion.set(touchLeft, touchTop, touchRight, touchBottom);
outInsets.touchableInsets = InputMethodService.Insets.TOUCHABLE_INSETS_REGION;
- outInsets.touchableRegion.set(0, touchY, touchWidth, touchHeight);
}
- outInsets.contentTopInsets = visibleTopY;
- outInsets.visibleTopInsets = visibleTopY;
}
@Override
@@ -1211,11 +1196,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
@Override
public void updateFullscreenMode() {
super.updateFullscreenMode();
-
- if (mKeyPreviewBackingView == null) return;
- // In fullscreen mode, no need to have extra space to show the key preview.
- // If not, we should have extra space above the keyboard to show the key preview.
- mKeyPreviewBackingView.setVisibility(isFullscreenMode() ? View.GONE : View.VISIBLE);
+ if (!isFullscreenMode()) {
+ // Expand the input view to cover entire display to be able to show key previews and
+ // more suggestions view that may be displayed above the keyboard.
+ setInputViewMinHeight(getResources().getDisplayMetrics().heightPixels);
+ }
}
// This will reset the whole input state to the starting state. It will clear
@@ -1512,6 +1497,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
case Constants.CODE_LANGUAGE_SWITCH:
handleLanguageSwitchKey();
break;
+ case Constants.CODE_EMOJI:
+ // TODO: Implement emoji keyboard switch.
+ break;
case Constants.CODE_ENTER:
final EditorInfo editorInfo = getCurrentInputEditorInfo();
final int imeOptionsActionId =
@@ -2529,7 +2517,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
final int maxFreq = AutoCorrectionUtils.getMaxFrequency(
suggest.getUnigramDictionaries(), suggestion);
if (maxFreq == 0) return null;
- userHistoryPredictionDictionary.addToUserHistory(prevWord, secondWord, maxFreq > 0);
+ userHistoryPredictionDictionary
+ .addToPersonalizationPredictionDictionary(prevWord, secondWord, maxFreq > 0);
return prevWord;
}