am f76264dc: Merge "Remove key preview backing view"

* commit 'f76264dcf4942a0e2685a9f816f7581b3d9d76fb':
  Remove key preview backing view
main
Tadashi G. Takaoka 2013-08-09 04:53:48 -07:00 committed by Android Git Automerger
commit 3f75c04144
4 changed files with 52 additions and 87 deletions

View File

@ -23,13 +23,8 @@
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
@ -37,17 +32,14 @@
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_alignParentBottom="true" android:layout_width="wrap_content"
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>

View File

@ -31,7 +31,6 @@ 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;
@ -51,7 +50,6 @@ 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;
@ -150,8 +148,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private final Settings mSettings; private final Settings mSettings;
private View mExtractArea; private View mInputView;
private View mKeyPreviewBackingView; private int mInputViewMinHeight;
private SuggestionStripView mSuggestionStripView; private SuggestionStripView mSuggestionStripView;
// Never null // Never null
private SuggestedWords mSuggestedWords = SuggestedWords.EMPTY; private SuggestedWords mSuggestedWords = SuggestedWords.EMPTY;
@ -660,17 +658,25 @@ 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 view) { public void setInputView(final View inputView) {
super.setInputView(view); super.setInputView(inputView);
mExtractArea = getWindow().getWindow().getDecorView() mInputView = inputView;
.findViewById(android.R.id.extractArea); setInputViewMinHeight(0);
mKeyPreviewBackingView = view.findViewById(R.id.key_preview_backing); mSuggestionStripView = (SuggestionStripView)inputView.findViewById(
mSuggestionStripView = (SuggestionStripView)view.findViewById(R.id.suggestion_strip_view); R.id.suggestion_strip_view);
if (mSuggestionStripView != null) if (mSuggestionStripView != null) {
mSuggestionStripView.setListener(this, view); mSuggestionStripView.setListener(this, inputView);
}
if (LatinImeLogger.sVISUALDEBUG) { if (LatinImeLogger.sVISUALDEBUG) {
mKeyPreviewBackingView.setBackgroundColor(0x10FF0000); inputView.setBackgroundColor(0x10FF0000);
} }
} }
@ -1122,6 +1128,11 @@ 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);
}
} }
} }
@ -1129,31 +1140,6 @@ 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);
@ -1161,32 +1147,30 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
if (mainKeyboardView == null || mSuggestionStripView == null) { if (mainKeyboardView == null || mSuggestionStripView == null) {
return; return;
} }
final int adjustedBackingHeight = getAdjustedBackingViewHeight(); // This method is never called when in fullscreen mode.
final boolean backingGone = (mKeyPreviewBackingView.getVisibility() == View.GONE); // The contentTop is the top coordinate of the keyboard. The application behind will be
final int backingHeight = backingGone ? 0 : adjustedBackingHeight; // resized/panned above this coordibnate to be able to show an input field.
// In fullscreen mode, the height of the extract area managed by InputMethodService should final int contentTop = mInputView.getHeight() - mainKeyboardView.getHeight();
// be considered. final int suggestionsHeight = (mSuggestionStripView.getVisibility() == View.VISIBLE)
// See {@link android.inputmethodservice.InputMethodService#onComputeInsets}. ? mSuggestionStripView.getHeight() : 0;
final int extractHeight = isFullscreenMode() ? mExtractArea.getHeight() : 0; // The visibleTop is the top coordinates of the visible part of this IME. The application
final int suggestionsHeight = (mSuggestionStripView.getVisibility() == View.GONE) ? 0 // behind will never be resized, but may be panned or scrolled.
: mSuggestionStripView.getHeight(); final int visibleTop = mainKeyboardView.isShowingMoreKeysPanel() ? 0
final int extraHeight = extractHeight + backingHeight + suggestionsHeight; : contentTop - suggestionsHeight;
int visibleTopY = extraHeight; outInsets.contentTopInsets = contentTop;
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()) {
if (mSuggestionStripView.getVisibility() == View.VISIBLE) { final int touchLeft = 0;
visibleTopY -= suggestionsHeight; final int touchTop = visibleTop;
} final int touchRight = touchLeft + mainKeyboardView.getWidth();
final int touchY = mainKeyboardView.isShowingMoreKeysPanel() ? 0 : visibleTopY; final int touchBottom = contentTop + mainKeyboardView.getHeight()
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
@ -1209,11 +1193,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
@Override @Override
public void updateFullscreenMode() { public void updateFullscreenMode() {
super.updateFullscreenMode(); super.updateFullscreenMode();
if (!isFullscreenMode()) {
if (mKeyPreviewBackingView == null) return; // Expand the input view to cover entire display to be able to show key previews and
// In fullscreen mode, no need to have extra space to show the key preview. // more suggestions view that may be displayed above the keyboard.
// If not, we should have extra space above the keyboard to show the key preview. setInputViewMinHeight(getResources().getDisplayMetrics().heightPixels);
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

View File

@ -177,20 +177,9 @@ final class SuggestionStripLayoutHelper {
return mMaxMoreSuggestionsRow; return mMaxMoreSuggestionsRow;
} }
private int getMoreSuggestionsHeight() { public void setMoreSuggestionsHeight(final int remainingHeight) {
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,

View File

@ -135,8 +135,8 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
} }
} }
public int setMoreSuggestionsHeight(final int remainingHeight) { public void setMoreSuggestionsHeight(final int remainingHeight) {
return mLayoutHelper.setMoreSuggestionsHeight(remainingHeight); mLayoutHelper.setMoreSuggestionsHeight(remainingHeight);
} }
public boolean isShowingAddToDictionaryHint() { public boolean isShowingAddToDictionaryHint() {