Merge "Revert "Remove key preview backing view""
commit
2f95baaaf0
|
@ -23,8 +23,13 @@
|
||||||
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"
|
||||||
android:gravity="bottom|center_horizontal"
|
|
||||||
>
|
>
|
||||||
|
<!-- 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="0dp" />
|
||||||
|
|
||||||
<!-- To ensure that key preview popup is correctly placed when the current system locale is
|
<!-- To ensure that key preview popup is correctly placed when the current system locale is
|
||||||
one of RTL locales, layoutDirection="ltr" is needed in the SDK version 17+. -->
|
one of RTL locales, layoutDirection="ltr" is needed in the SDK version 17+. -->
|
||||||
<com.android.inputmethod.latin.suggestions.SuggestionStripView
|
<com.android.inputmethod.latin.suggestions.SuggestionStripView
|
||||||
|
@ -32,14 +37,17 @@
|
||||||
android:layoutDirection="ltr"
|
android:layoutDirection="ltr"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="@dimen/suggestions_strip_height"
|
android:layout_height="@dimen/suggestions_strip_height"
|
||||||
|
android:gravity="center_vertical"
|
||||||
android:paddingRight="@dimen/suggestions_strip_padding"
|
android:paddingRight="@dimen/suggestions_strip_padding"
|
||||||
android:paddingLeft="@dimen/suggestions_strip_padding"
|
android:paddingLeft="@dimen/suggestions_strip_padding"
|
||||||
style="?attr/suggestionStripViewStyle" />
|
style="?attr/suggestionStripViewStyle" />
|
||||||
|
|
||||||
<!-- To ensure that key preview popup is correctly placed when the current system locale is
|
<!-- To ensure that key preview popup is correctly placed when the current system locale is
|
||||||
one of RTL locales, layoutDirection="ltr" is needed in the SDK version 17+. -->
|
one of RTL locales, layoutDirection="ltr" is needed in the SDK version 17+. -->
|
||||||
<com.android.inputmethod.keyboard.MainKeyboardView
|
<com.android.inputmethod.keyboard.MainKeyboardView
|
||||||
android:id="@+id/keyboard_view"
|
android:id="@+id/keyboard_view"
|
||||||
android:layoutDirection="ltr"
|
android:layoutDirection="ltr"
|
||||||
android:layout_width="wrap_content"
|
android:layout_alignParentBottom="true"
|
||||||
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
</com.android.inputmethod.latin.InputView>
|
</com.android.inputmethod.latin.InputView>
|
||||||
|
|
|
@ -31,6 +31,7 @@ import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageInfo;
|
import android.content.pm.PackageInfo;
|
||||||
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;
|
||||||
|
@ -50,6 +51,7 @@ import android.util.Printer;
|
||||||
import android.view.KeyCharacterMap;
|
import android.view.KeyCharacterMap;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup.LayoutParams;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.view.inputmethod.CompletionInfo;
|
import android.view.inputmethod.CompletionInfo;
|
||||||
|
@ -153,8 +155,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
|
|
||||||
private final Settings mSettings;
|
private final Settings mSettings;
|
||||||
|
|
||||||
private View mInputView;
|
private View mExtractArea;
|
||||||
private int mInputViewMinHeight;
|
private View mKeyPreviewBackingView;
|
||||||
private SuggestionStripView mSuggestionStripView;
|
private SuggestionStripView mSuggestionStripView;
|
||||||
// Never null
|
// Never null
|
||||||
private SuggestedWords mSuggestedWords = SuggestedWords.EMPTY;
|
private SuggestedWords mSuggestedWords = SuggestedWords.EMPTY;
|
||||||
|
@ -673,25 +675,17 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
return mKeyboardSwitcher.onCreateInputView(mIsHardwareAcceleratedDrawingEnabled);
|
return mKeyboardSwitcher.onCreateInputView(mIsHardwareAcceleratedDrawingEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setInputViewMinHeight(final int minHeight) {
|
|
||||||
if (mInputView != null && mInputViewMinHeight != minHeight) {
|
|
||||||
mInputView.setMinimumHeight(minHeight);
|
|
||||||
mInputViewMinHeight = minHeight;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setInputView(final View inputView) {
|
public void setInputView(final View view) {
|
||||||
super.setInputView(inputView);
|
super.setInputView(view);
|
||||||
mInputView = inputView;
|
mExtractArea = getWindow().getWindow().getDecorView()
|
||||||
setInputViewMinHeight(0);
|
.findViewById(android.R.id.extractArea);
|
||||||
mSuggestionStripView = (SuggestionStripView)inputView.findViewById(
|
mKeyPreviewBackingView = view.findViewById(R.id.key_preview_backing);
|
||||||
R.id.suggestion_strip_view);
|
mSuggestionStripView = (SuggestionStripView)view.findViewById(R.id.suggestion_strip_view);
|
||||||
if (mSuggestionStripView != null) {
|
if (mSuggestionStripView != null)
|
||||||
mSuggestionStripView.setListener(this, inputView);
|
mSuggestionStripView.setListener(this, view);
|
||||||
}
|
|
||||||
if (LatinImeLogger.sVISUALDEBUG) {
|
if (LatinImeLogger.sVISUALDEBUG) {
|
||||||
inputView.setBackgroundColor(0x10FF0000);
|
mKeyPreviewBackingView.setBackgroundColor(0x10FF0000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1169,11 +1163,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
mSuggestionStripView.setVisibility(
|
mSuggestionStripView.setVisibility(
|
||||||
shouldShowSuggestions ? View.VISIBLE : View.INVISIBLE);
|
shouldShowSuggestions ? View.VISIBLE : View.INVISIBLE);
|
||||||
}
|
}
|
||||||
if (shouldShowSuggestions && mainKeyboardView != null) {
|
|
||||||
final int remainingHeight = getWindow().getWindow().getDecorView().getHeight()
|
|
||||||
- mainKeyboardView.getHeight() - mSuggestionStripView.getHeight();
|
|
||||||
mSuggestionStripView.setMoreSuggestionsHeight(remainingHeight);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1181,6 +1170,31 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
setSuggestionStripShownInternal(shown, /* needsInputViewShown */true);
|
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
|
@Override
|
||||||
public void onComputeInsets(final InputMethodService.Insets outInsets) {
|
public void onComputeInsets(final InputMethodService.Insets outInsets) {
|
||||||
super.onComputeInsets(outInsets);
|
super.onComputeInsets(outInsets);
|
||||||
|
@ -1188,30 +1202,32 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
if (mainKeyboardView == null || mSuggestionStripView == null) {
|
if (mainKeyboardView == null || mSuggestionStripView == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// This method is never called when in fullscreen mode.
|
final int adjustedBackingHeight = getAdjustedBackingViewHeight();
|
||||||
// The contentTop is the top coordinate of the keyboard. The application behind will be
|
final boolean backingGone = (mKeyPreviewBackingView.getVisibility() == View.GONE);
|
||||||
// resized/panned above this coordibnate to be able to show an input field.
|
final int backingHeight = backingGone ? 0 : adjustedBackingHeight;
|
||||||
final int contentTop = mInputView.getHeight() - mainKeyboardView.getHeight();
|
// In fullscreen mode, the height of the extract area managed by InputMethodService should
|
||||||
final int suggestionsHeight = (mSuggestionStripView.getVisibility() == View.VISIBLE)
|
// be considered.
|
||||||
? mSuggestionStripView.getHeight() : 0;
|
// See {@link android.inputmethodservice.InputMethodService#onComputeInsets}.
|
||||||
// The visibleTop is the top coordinates of the visible part of this IME. The application
|
final int extractHeight = isFullscreenMode() ? mExtractArea.getHeight() : 0;
|
||||||
// behind will never be resized, but may be panned or scrolled.
|
final int suggestionsHeight = (mSuggestionStripView.getVisibility() == View.GONE) ? 0
|
||||||
final int visibleTop = mainKeyboardView.isShowingMoreKeysPanel() ? 0
|
: mSuggestionStripView.getHeight();
|
||||||
: contentTop - suggestionsHeight;
|
final int extraHeight = extractHeight + backingHeight + suggestionsHeight;
|
||||||
outInsets.contentTopInsets = contentTop;
|
int visibleTopY = extraHeight;
|
||||||
outInsets.visibleTopInsets = visibleTop;
|
|
||||||
// Need to set touchable region only if input view is being shown
|
// Need to set touchable region only if input view is being shown
|
||||||
if (mainKeyboardView.isShown()) {
|
if (mainKeyboardView.isShown()) {
|
||||||
final int touchLeft = 0;
|
if (mSuggestionStripView.getVisibility() == View.VISIBLE) {
|
||||||
final int touchTop = visibleTop;
|
visibleTopY -= suggestionsHeight;
|
||||||
final int touchRight = touchLeft + mainKeyboardView.getWidth();
|
}
|
||||||
final int touchBottom = contentTop + mainKeyboardView.getHeight()
|
final int touchY = mainKeyboardView.isShowingMoreKeysPanel() ? 0 : visibleTopY;
|
||||||
|
final int touchWidth = mainKeyboardView.getWidth();
|
||||||
|
final int touchHeight = mainKeyboardView.getHeight() + extraHeight
|
||||||
// Extend touchable region below the keyboard.
|
// Extend touchable region below the keyboard.
|
||||||
+ EXTENDED_TOUCHABLE_REGION_HEIGHT;
|
+ 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.touchableInsets = InputMethodService.Insets.TOUCHABLE_INSETS_REGION;
|
||||||
|
outInsets.touchableRegion.set(0, touchY, touchWidth, touchHeight);
|
||||||
}
|
}
|
||||||
|
outInsets.contentTopInsets = visibleTopY;
|
||||||
|
outInsets.visibleTopInsets = visibleTopY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1234,11 +1250,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
@Override
|
@Override
|
||||||
public void updateFullscreenMode() {
|
public void updateFullscreenMode() {
|
||||||
super.updateFullscreenMode();
|
super.updateFullscreenMode();
|
||||||
if (!isFullscreenMode()) {
|
|
||||||
// Expand the input view to cover entire display to be able to show key previews and
|
if (mKeyPreviewBackingView == null) return;
|
||||||
// more suggestions view that may be displayed above the keyboard.
|
// In fullscreen mode, no need to have extra space to show the key preview.
|
||||||
setInputViewMinHeight(getResources().getDisplayMetrics().heightPixels);
|
// 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
|
// This will reset the whole input state to the starting state. It will clear
|
||||||
|
|
|
@ -165,9 +165,20 @@ final class SuggestionStripLayoutHelper {
|
||||||
return mMaxMoreSuggestionsRow;
|
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)
|
mMaxMoreSuggestionsRow = (remainingHeight - mMoreSuggestionsBottomGap)
|
||||||
/ mMoreSuggestionsRowHeight;
|
/ mMoreSuggestionsRowHeight;
|
||||||
|
final int newHeight = getMoreSuggestionsHeight();
|
||||||
|
return newHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Drawable getMoreSuggestionsHint(final Resources res, final float textSize,
|
private static Drawable getMoreSuggestionsHint(final Resources res, final float textSize,
|
||||||
|
|
|
@ -135,8 +135,8 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMoreSuggestionsHeight(final int remainingHeight) {
|
public int setMoreSuggestionsHeight(final int remainingHeight) {
|
||||||
mLayoutHelper.setMoreSuggestionsHeight(remainingHeight);
|
return mLayoutHelper.setMoreSuggestionsHeight(remainingHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isShowingAddToDictionaryHint() {
|
public boolean isShowingAddToDictionaryHint() {
|
||||||
|
|
Loading…
Reference in New Issue