diff --git a/java/res/layout/input_view.xml b/java/res/layout/input_view.xml index b9451f8aebfa962595ad82384bbeac3f37ecb94e..0a8d71f300c1dca79d9812f9c057e3fbdf128e9b 100644 --- a/java/res/layout/input_view.xml +++ b/java/res/layout/input_view.xml @@ -20,15 +20,15 @@ <com.android.inputmethod.latin.InputView xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content" > + <!-- The height of key_preview_backing view will automatically be determined by code. --> <View android:id="@+id/key_preview_backing" android:layout_width="match_parent" - android:layout_height="@dimen/key_preview_backing_height" /> + android:layout_height="0dip" /> <!-- On tablets, the suggestions strip is centered with horizontal paddings on both sides because width of the landscape mode is too long for the suggestions strip. This diff --git a/java/res/values-land/dimens.xml b/java/res/values-land/dimens.xml index 0b123b408a24d00834f558504d21fb2030d7f1bd..73192d944325b027a33ac72318a05aebb8aaa04a 100644 --- a/java/res/values-land/dimens.xml +++ b/java/res/values-land/dimens.xml @@ -64,8 +64,6 @@ <dimen name="more_suggestions_row_height">36dip</dimen> <integer name="max_more_suggestions_row">2</integer> <fraction name="min_more_suggestions_width">60%</fraction> - <!-- key_preview_backing_height = more_suggestions_row_height * max_more_suggestions_row --> - <dimen name="key_preview_backing_height">72dip</dimen> <!-- Amount of allowance for selecting keys in a mini popup keyboard by sliding finger. --> <!-- popup_key_height x 1.2 --> <dimen name="more_keys_keyboard_slide_allowance">0.336in</dimen> diff --git a/java/res/values-sw600dp-land/dimens.xml b/java/res/values-sw600dp-land/dimens.xml index 1c725a48454bb2767410dc9b87000868cddea08f..68083b534eeab6709fa127398cc22a525706aa9b 100644 --- a/java/res/values-sw600dp-land/dimens.xml +++ b/java/res/values-sw600dp-land/dimens.xml @@ -53,6 +53,4 @@ <dimen name="suggestions_strip_padding">40.0mm</dimen> <integer name="max_more_suggestions_row">5</integer> <fraction name="min_more_suggestions_width">50%</fraction> - <!-- key_preview_backing_height = more_suggestions_row_height * max_more_suggestions_row --> - <dimen name="key_preview_backing_height">220dip</dimen> </resources> diff --git a/java/res/values-sw600dp/dimens.xml b/java/res/values-sw600dp/dimens.xml index fb71f17414d215395aa006052122dbebee616cf9..a861024212ff983d4129de50e68e8f4dfa151f2e 100644 --- a/java/res/values-sw600dp/dimens.xml +++ b/java/res/values-sw600dp/dimens.xml @@ -72,8 +72,6 @@ <dimen name="more_suggestions_row_height">44dip</dimen> <integer name="max_more_suggestions_row">6</integer> <fraction name="min_more_suggestions_width">90%</fraction> - <!-- key_preview_backing_height = more_suggestions_row_height * max_more_suggestions_row --> - <dimen name="key_preview_backing_height">264dip</dimen> <dimen name="suggestions_strip_padding">15.0mm</dimen> <dimen name="suggestion_min_width">0.3in</dimen> <dimen name="suggestion_padding">12dip</dimen> diff --git a/java/res/values-sw768dp/dimens.xml b/java/res/values-sw768dp/dimens.xml index 32b6f6a2feb5532573b6bfda77043980c58c01f9..a9ad030fe10fa30289a0a7ce3d512f7e9ecc6a53 100644 --- a/java/res/values-sw768dp/dimens.xml +++ b/java/res/values-sw768dp/dimens.xml @@ -75,8 +75,6 @@ <dimen name="more_suggestions_row_height">44dip</dimen> <integer name="max_more_suggestions_row">6</integer> <fraction name="min_more_suggestions_width">90%</fraction> - <!-- key_preview_backing_height = more_suggestions_row_height * max_more_suggestions_row --> - <dimen name="key_preview_backing_height">264dip</dimen> <dimen name="suggestions_strip_padding">15.0mm</dimen> <dimen name="suggestion_min_width">46dip</dimen> <dimen name="suggestion_padding">8dip</dimen> diff --git a/java/res/values/dimens.xml b/java/res/values/dimens.xml index 580c4959bc5f04e2d43f6adb2fef0ffc74d3fe4b..37720ce727a2bcc8728ad20b8f1eff32e54f20c2 100644 --- a/java/res/values/dimens.xml +++ b/java/res/values/dimens.xml @@ -89,8 +89,6 @@ <integer name="max_more_suggestions_row">6</integer> <fraction name="min_more_suggestions_width">90%</fraction> <fraction name="more_suggestions_info_ratio">18%</fraction> - <!-- key_preview_backing_height = more_suggestions_row_height * max_more_suggestions_row --> - <dimen name="key_preview_backing_height">240dip</dimen> <dimen name="suggestions_strip_padding">0dip</dimen> <dimen name="suggestion_min_width">44dip</dimen> <dimen name="suggestion_padding">6dip</dimen> diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 20423643ed9254e6d5a2fc60de49efb32d11e828..1858db949645a03b9daf2ee8dcc2b084d8cb89fe 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -25,6 +25,7 @@ import android.content.IntentFilter; import android.content.SharedPreferences; 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; @@ -44,6 +45,7 @@ import android.view.KeyEvent; import android.view.View; import android.view.ViewGroup; import android.view.ViewParent; +import android.view.ViewGroup.LayoutParams; import android.view.inputmethod.CompletionInfo; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.ExtractedText; @@ -1021,12 +1023,34 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar setSuggestionStripShownInternal(shown, /* needsInputViewShown */true); } + private void adjustInputViewHeight() { + if (mKeyPreviewBackingView.getHeight() > 0) { + return; + } + + final KeyboardView keyboardView = mKeyboardSwitcher.getKeyboardView(); + if (keyboardView == null) return; + final int keyboardHeight = keyboardView.getHeight(); + final int suggestionsHeight = mSuggestionsContainer.getHeight(); + final int displayHeight = mResources.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 = mSuggestionsView.setMoreSuggestionsHeight(remainingHeight); + mKeyPreviewBackingView.setLayoutParams(params); + } + @Override public void onComputeInsets(InputMethodService.Insets outInsets) { super.onComputeInsets(outInsets); final KeyboardView inputView = mKeyboardSwitcher.getKeyboardView(); if (inputView == null || mSuggestionsContainer == null) return; + adjustInputViewHeight(); // In fullscreen mode, the height of the extract area managed by InputMethodService should // be considered. // See {@link android.inputmethodservice.InputMethodService#onComputeInsets}. diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java index d3362940f8d0e2859c29f0b5410ba7af8638f5c3..075fb68ee28701a3eb9a563473d7640d3e8cec2c 100644 --- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java +++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java @@ -137,7 +137,8 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, public final int mDividerWidth; public final int mSuggestionsStripHeight; public final int mSuggestionsCountInStrip; - public final int mMaxMoreSuggestionsRow; + public final int mMoreSuggestionsRowHeight; + private int mMaxMoreSuggestionsRow; public final float mMinMoreSuggestionsWidth; public final int mMoreSuggestionsBottomGap; @@ -225,12 +226,34 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, mCenterSuggestionIndex = mSuggestionsCountInStrip / 2; mMoreSuggestionsBottomGap = res.getDimensionPixelOffset( R.dimen.more_suggestions_bottom_gap); + mMoreSuggestionsRowHeight = res.getDimensionPixelSize( + R.dimen.more_suggestions_row_height); final LayoutInflater inflater = LayoutInflater.from(context); mWordToSaveView = (TextView)inflater.inflate(R.layout.suggestion_word, null); mHintToSaveView = (TextView)inflater.inflate(R.layout.suggestion_word, null); } + public int getMaxMoreSuggestionsRow() { + return mMaxMoreSuggestionsRow; + } + + private int getMoreSuggestionsHeight() { + return mMaxMoreSuggestionsRow * mMoreSuggestionsRowHeight + mMoreSuggestionsBottomGap; + } + + public int setMoreSuggestionsHeight(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(Resources res, float textSize, int color) { final Paint paint = new Paint(); paint.setAntiAlias(true); @@ -645,6 +668,9 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, mParams.layout(mSuggestedWords, mSuggestionsStrip, this, getWidth()); } + public int setMoreSuggestionsHeight(int remainingHeight) { + return mParams.setMoreSuggestionsHeight(remainingHeight); + } public boolean isShowingAddToDictionaryHint() { return mSuggestionsStrip.getChildCount() > 0 @@ -735,7 +761,7 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, final MoreSuggestions.Builder builder = mMoreSuggestionsBuilder; builder.layout(mSuggestedWords, params.mSuggestionsCountInStrip, maxWidth, (int)(maxWidth * params.mMinMoreSuggestionsWidth), - params.mMaxMoreSuggestionsRow); + params.getMaxMoreSuggestionsRow()); mMoreSuggestionsView.setKeyboard(builder.build()); container.measure( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);