From c160a3932f74fea72c5347798c001d4ae961864c Mon Sep 17 00:00:00 2001 From: Ken Wakasa Date: Fri, 30 Aug 2013 07:50:37 +0000 Subject: [PATCH] Revert "Remove key preview backing view" This reverts commit 2dfcfc5013eee2fbd19a5830ff70943bd6c1bee2. Change-Id: I96c691b2e9c92be456420196cd7361d03ea4f3e9 bug: 10541453 --- java/res/layout/input_view.xml | 12 +- .../android/inputmethod/latin/LatinIME.java | 110 ++++++++++-------- .../SuggestionStripLayoutHelper.java | 13 ++- .../suggestions/SuggestionStripView.java | 4 +- 4 files changed, 87 insertions(+), 52 deletions(-) diff --git a/java/res/layout/input_view.xml b/java/res/layout/input_view.xml index 78217b01a..1ffb8a32a 100644 --- a/java/res/layout/input_view.xml +++ b/java/res/layout/input_view.xml @@ -23,8 +23,13 @@ android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content" - android:gravity="bottom|center_horizontal" > + + + + diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 68805f785..6339e9c50 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -31,6 +31,7 @@ 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; @@ -50,6 +51,7 @@ 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; @@ -148,8 +150,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen private final Settings mSettings; - private View mInputView; - private int mInputViewMinHeight; + private View mExtractArea; + private View mKeyPreviewBackingView; private SuggestionStripView mSuggestionStripView; // Never null private SuggestedWords mSuggestedWords = SuggestedWords.EMPTY; @@ -658,25 +660,17 @@ 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 inputView) { - super.setInputView(inputView); - mInputView = inputView; - setInputViewMinHeight(0); - mSuggestionStripView = (SuggestionStripView)inputView.findViewById( - R.id.suggestion_strip_view); - if (mSuggestionStripView != null) { - mSuggestionStripView.setListener(this, inputView); - } + 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); + mSuggestionStripView = (SuggestionStripView)view.findViewById(R.id.suggestion_strip_view); + if (mSuggestionStripView != null) + mSuggestionStripView.setListener(this, view); if (LatinImeLogger.sVISUALDEBUG) { - inputView.setBackgroundColor(0x10FF0000); + mKeyPreviewBackingView.setBackgroundColor(0x10FF0000); } } @@ -1128,11 +1122,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen 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); - } } } @@ -1140,6 +1129,31 @@ 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 = mSuggestionStripView.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); @@ -1147,30 +1161,32 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen if (mainKeyboardView == null || mSuggestionStripView == null) { return; } - // 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; + 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 = (mSuggestionStripView.getVisibility() == View.GONE) ? 0 + : mSuggestionStripView.getHeight(); + final int extraHeight = extractHeight + backingHeight + suggestionsHeight; + int visibleTopY = extraHeight; // Need to set touchable region only if input view is being shown if (mainKeyboardView.isShown()) { - final int touchLeft = 0; - final int touchTop = visibleTop; - final int touchRight = touchLeft + mainKeyboardView.getWidth(); - final int touchBottom = contentTop + mainKeyboardView.getHeight() + if (mSuggestionStripView.getVisibility() == View.VISIBLE) { + visibleTopY -= suggestionsHeight; + } + final int touchY = mainKeyboardView.isShowingMoreKeysPanel() ? 0 : visibleTopY; + final int touchWidth = mainKeyboardView.getWidth(); + final int touchHeight = mainKeyboardView.getHeight() + extraHeight // 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 @@ -1193,11 +1209,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen @Override public void updateFullscreenMode() { super.updateFullscreenMode(); - 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); - } + + 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); } // This will reset the whole input state to the starting state. It will clear diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java index bcf64a8e8..1dd04fc4d 100644 --- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java +++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java @@ -177,9 +177,20 @@ final class SuggestionStripLayoutHelper { return mMaxMoreSuggestionsRow; } - public void setMoreSuggestionsHeight(final int remainingHeight) { + private int getMoreSuggestionsHeight() { + return mMaxMoreSuggestionsRow * mMoreSuggestionsRowHeight + mMoreSuggestionsBottomGap; + } + + public int setMoreSuggestionsHeight(final int remainingHeight) { + final int currentHeight = getMoreSuggestionsHeight(); + if (currentHeight <= remainingHeight) { + return currentHeight; + } + mMaxMoreSuggestionsRow = (remainingHeight - mMoreSuggestionsBottomGap) / mMoreSuggestionsRowHeight; + final int newHeight = getMoreSuggestionsHeight(); + return newHeight; } private static Drawable getMoreSuggestionsHint(final Resources res, final float textSize, diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java index 2644f3c9c..a8a14a825 100644 --- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java +++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java @@ -135,8 +135,8 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick } } - public void setMoreSuggestionsHeight(final int remainingHeight) { - mLayoutHelper.setMoreSuggestionsHeight(remainingHeight); + public int setMoreSuggestionsHeight(final int remainingHeight) { + return mLayoutHelper.setMoreSuggestionsHeight(remainingHeight); } public boolean isShowingAddToDictionaryHint() {