Skip to content
Snippets Groups Projects
Commit c648b887 authored by Tadashi G. Takaoka's avatar Tadashi G. Takaoka Committed by Android (Google) Code Review
Browse files

Merge "Dynamically determine key preview backing view height"

parents 898d8419 c8b0e579
No related branches found
No related tags found
No related merge requests found
...@@ -20,15 +20,15 @@ ...@@ -20,15 +20,15 @@
<com.android.inputmethod.latin.InputView <com.android.inputmethod.latin.InputView
xmlns:android="http://schemas.android.com/apk/res/android" 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:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
> >
<!-- The height of key_preview_backing view will automatically be determined by code. -->
<View <View
android:id="@+id/key_preview_backing" android:id="@+id/key_preview_backing"
android:layout_width="match_parent" 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 <!-- 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 because width of the landscape mode is too long for the suggestions strip. This
......
...@@ -64,8 +64,6 @@ ...@@ -64,8 +64,6 @@
<dimen name="more_suggestions_row_height">36dip</dimen> <dimen name="more_suggestions_row_height">36dip</dimen>
<integer name="max_more_suggestions_row">2</integer> <integer name="max_more_suggestions_row">2</integer>
<fraction name="min_more_suggestions_width">60%</fraction> <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. --> <!-- Amount of allowance for selecting keys in a mini popup keyboard by sliding finger. -->
<!-- popup_key_height x 1.2 --> <!-- popup_key_height x 1.2 -->
<dimen name="more_keys_keyboard_slide_allowance">0.336in</dimen> <dimen name="more_keys_keyboard_slide_allowance">0.336in</dimen>
......
...@@ -53,6 +53,4 @@ ...@@ -53,6 +53,4 @@
<dimen name="suggestions_strip_padding">40.0mm</dimen> <dimen name="suggestions_strip_padding">40.0mm</dimen>
<integer name="max_more_suggestions_row">5</integer> <integer name="max_more_suggestions_row">5</integer>
<fraction name="min_more_suggestions_width">50%</fraction> <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> </resources>
...@@ -72,8 +72,6 @@ ...@@ -72,8 +72,6 @@
<dimen name="more_suggestions_row_height">44dip</dimen> <dimen name="more_suggestions_row_height">44dip</dimen>
<integer name="max_more_suggestions_row">6</integer> <integer name="max_more_suggestions_row">6</integer>
<fraction name="min_more_suggestions_width">90%</fraction> <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="suggestions_strip_padding">15.0mm</dimen>
<dimen name="suggestion_min_width">0.3in</dimen> <dimen name="suggestion_min_width">0.3in</dimen>
<dimen name="suggestion_padding">12dip</dimen> <dimen name="suggestion_padding">12dip</dimen>
......
...@@ -75,8 +75,6 @@ ...@@ -75,8 +75,6 @@
<dimen name="more_suggestions_row_height">44dip</dimen> <dimen name="more_suggestions_row_height">44dip</dimen>
<integer name="max_more_suggestions_row">6</integer> <integer name="max_more_suggestions_row">6</integer>
<fraction name="min_more_suggestions_width">90%</fraction> <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="suggestions_strip_padding">15.0mm</dimen>
<dimen name="suggestion_min_width">46dip</dimen> <dimen name="suggestion_min_width">46dip</dimen>
<dimen name="suggestion_padding">8dip</dimen> <dimen name="suggestion_padding">8dip</dimen>
......
...@@ -89,8 +89,6 @@ ...@@ -89,8 +89,6 @@
<integer name="max_more_suggestions_row">6</integer> <integer name="max_more_suggestions_row">6</integer>
<fraction name="min_more_suggestions_width">90%</fraction> <fraction name="min_more_suggestions_width">90%</fraction>
<fraction name="more_suggestions_info_ratio">18%</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="suggestions_strip_padding">0dip</dimen>
<dimen name="suggestion_min_width">44dip</dimen> <dimen name="suggestion_min_width">44dip</dimen>
<dimen name="suggestion_padding">6dip</dimen> <dimen name="suggestion_padding">6dip</dimen>
......
...@@ -25,6 +25,7 @@ import android.content.IntentFilter; ...@@ -25,6 +25,7 @@ import android.content.IntentFilter;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Rect;
import android.inputmethodservice.InputMethodService; import android.inputmethodservice.InputMethodService;
import android.media.AudioManager; import android.media.AudioManager;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
...@@ -44,6 +45,7 @@ import android.view.KeyEvent; ...@@ -44,6 +45,7 @@ import android.view.KeyEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewParent; import android.view.ViewParent;
import android.view.ViewGroup.LayoutParams;
import android.view.inputmethod.CompletionInfo; import android.view.inputmethod.CompletionInfo;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.ExtractedText; import android.view.inputmethod.ExtractedText;
...@@ -1021,12 +1023,34 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar ...@@ -1021,12 +1023,34 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
setSuggestionStripShownInternal(shown, /* needsInputViewShown */true); 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 @Override
public void onComputeInsets(InputMethodService.Insets outInsets) { public void onComputeInsets(InputMethodService.Insets outInsets) {
super.onComputeInsets(outInsets); super.onComputeInsets(outInsets);
final KeyboardView inputView = mKeyboardSwitcher.getKeyboardView(); final KeyboardView inputView = mKeyboardSwitcher.getKeyboardView();
if (inputView == null || mSuggestionsContainer == null) if (inputView == null || mSuggestionsContainer == null)
return; return;
adjustInputViewHeight();
// In fullscreen mode, the height of the extract area managed by InputMethodService should // In fullscreen mode, the height of the extract area managed by InputMethodService should
// be considered. // be considered.
// See {@link android.inputmethodservice.InputMethodService#onComputeInsets}. // See {@link android.inputmethodservice.InputMethodService#onComputeInsets}.
......
...@@ -137,7 +137,8 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, ...@@ -137,7 +137,8 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
public final int mDividerWidth; public final int mDividerWidth;
public final int mSuggestionsStripHeight; public final int mSuggestionsStripHeight;
public final int mSuggestionsCountInStrip; public final int mSuggestionsCountInStrip;
public final int mMaxMoreSuggestionsRow; public final int mMoreSuggestionsRowHeight;
private int mMaxMoreSuggestionsRow;
public final float mMinMoreSuggestionsWidth; public final float mMinMoreSuggestionsWidth;
public final int mMoreSuggestionsBottomGap; public final int mMoreSuggestionsBottomGap;
...@@ -225,12 +226,34 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, ...@@ -225,12 +226,34 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
mCenterSuggestionIndex = mSuggestionsCountInStrip / 2; mCenterSuggestionIndex = mSuggestionsCountInStrip / 2;
mMoreSuggestionsBottomGap = res.getDimensionPixelOffset( mMoreSuggestionsBottomGap = res.getDimensionPixelOffset(
R.dimen.more_suggestions_bottom_gap); R.dimen.more_suggestions_bottom_gap);
mMoreSuggestionsRowHeight = res.getDimensionPixelSize(
R.dimen.more_suggestions_row_height);
final LayoutInflater inflater = LayoutInflater.from(context); final LayoutInflater inflater = LayoutInflater.from(context);
mWordToSaveView = (TextView)inflater.inflate(R.layout.suggestion_word, null); mWordToSaveView = (TextView)inflater.inflate(R.layout.suggestion_word, null);
mHintToSaveView = (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) { private static Drawable getMoreSuggestionsHint(Resources res, float textSize, int color) {
final Paint paint = new Paint(); final Paint paint = new Paint();
paint.setAntiAlias(true); paint.setAntiAlias(true);
...@@ -645,6 +668,9 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, ...@@ -645,6 +668,9 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
mParams.layout(mSuggestedWords, mSuggestionsStrip, this, getWidth()); mParams.layout(mSuggestedWords, mSuggestionsStrip, this, getWidth());
} }
public int setMoreSuggestionsHeight(int remainingHeight) {
return mParams.setMoreSuggestionsHeight(remainingHeight);
}
public boolean isShowingAddToDictionaryHint() { public boolean isShowingAddToDictionaryHint() {
return mSuggestionsStrip.getChildCount() > 0 return mSuggestionsStrip.getChildCount() > 0
...@@ -735,7 +761,7 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, ...@@ -735,7 +761,7 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
final MoreSuggestions.Builder builder = mMoreSuggestionsBuilder; final MoreSuggestions.Builder builder = mMoreSuggestionsBuilder;
builder.layout(mSuggestedWords, params.mSuggestionsCountInStrip, maxWidth, builder.layout(mSuggestedWords, params.mSuggestionsCountInStrip, maxWidth,
(int)(maxWidth * params.mMinMoreSuggestionsWidth), (int)(maxWidth * params.mMinMoreSuggestionsWidth),
params.mMaxMoreSuggestionsRow); params.getMaxMoreSuggestionsRow());
mMoreSuggestionsView.setKeyboard(builder.build()); mMoreSuggestionsView.setKeyboard(builder.build());
container.measure( container.measure(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment