aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/LatinIME.java
diff options
context:
space:
mode:
authorTadashi G. Takaoka <takaoka@google.com>2011-04-13 14:12:24 +0900
committerTadashi G. Takaoka <takaoka@google.com>2011-04-13 18:59:33 +0900
commit7a3d3ae17f7a8ca0b44e9c92328a7de7cbc80f92 (patch)
tree0975cb3d2df4eced4c836078291306761f136991 /java/src/com/android/inputmethod/latin/LatinIME.java
parent47d2ef69d3f94e68bf675967ce3140cbb6179279 (diff)
downloadlatinime-7a3d3ae17f7a8ca0b44e9c92328a7de7cbc80f92.tar.gz
latinime-7a3d3ae17f7a8ca0b44e9c92328a7de7cbc80f92.tar.xz
latinime-7a3d3ae17f7a8ca0b44e9c92328a7de7cbc80f92.zip
Fast key preview
Previously the key preview was implemented by PopupWindow. The key preview popup window would be dismissed and shown each time the key was released and pressed. It turned out that it was taking several milliseconds. This change implements the key preview by a simple TextView which will be layout-ed at absolute coordinates within the screen FrameLayout. And dismissing and showing the key preview is implemented by the TextView's visibility. This implementation needs careful coordination of candidates.xml layout and LatinIME.onComputeInsets to control suggestion strip visibility. Bug: 4179964 Change-Id: Id6347cb35b91eb14ab20dd2f312e58b54b6625a7
Diffstat (limited to 'java/src/com/android/inputmethod/latin/LatinIME.java')
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java69
1 files changed, 31 insertions, 38 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 6a858fe99..7664a48fb 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -56,7 +56,6 @@ import android.util.DisplayMetrics;
import android.util.Log;
import android.util.PrintWriterPrinter;
import android.util.Printer;
-import android.view.Gravity;
import android.view.HapticFeedbackConstants;
import android.view.KeyEvent;
import android.view.LayoutInflater;
@@ -70,8 +69,6 @@ import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.ExtractedText;
import android.view.inputmethod.ExtractedTextRequest;
import android.view.inputmethod.InputConnection;
-import android.widget.FrameLayout;
-import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;
import java.io.FileDescriptor;
@@ -143,6 +140,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
};
private View mCandidateViewContainer;
+ private int mCandidateStripHeight;
private CandidateView mCandidateView;
private Suggest mSuggest;
private CompletionInfo[] mApplicationSpecifiedCompletions;
@@ -528,12 +526,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
LayoutInflater inflater = getLayoutInflater();
LinearLayout container = (LinearLayout)inflater.inflate(R.layout.candidates, null);
mCandidateViewContainer = container;
- if (container.getPaddingRight() != 0) {
- HorizontalScrollView scrollView =
- (HorizontalScrollView) container.findViewById(R.id.candidates_scroll_view);
- setOverScrollModeNever(scrollView);
- container.setGravity(Gravity.CENTER_HORIZONTAL);
- }
+ mCandidateStripHeight = (int)mResources.getDimension(R.dimen.candidate_strip_height);
mCandidateView = (CandidateView) container.findViewById(R.id.candidates);
mCandidateView.setService(this);
setCandidatesViewShown(true);
@@ -581,8 +574,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
switcher.updateShiftState();
}
- setCandidatesViewShownInternal(isCandidateStripVisible(),
- false /* needsInputViewShown */ );
+ setCandidatesViewShownInternal(isCandidateStripVisible(), false /* needsInputViewShown */ );
// Delay updating suggestions because keyboard input view may not be shown at this point.
mHandler.postUpdateSuggestions();
@@ -872,10 +864,21 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
}
private void setCandidatesViewShownInternal(boolean shown, boolean needsInputViewShown) {
- // TODO: Remove this if we support candidates with hard keyboard
+ // TODO: Modify this if we support candidates with hard keyboard
if (onEvaluateInputViewShown()) {
- super.setCandidatesViewShown(shown
- && (needsInputViewShown ? mKeyboardSwitcher.isInputViewShown() : true));
+ final boolean shouldShowCandidates = shown
+ && (needsInputViewShown ? mKeyboardSwitcher.isInputViewShown() : true);
+ if (isExtractViewShown()) {
+ // No need to have extra space to show the key preview.
+ mCandidateViewContainer.setMinimumHeight(0);
+ super.setCandidatesViewShown(shown);
+ } else {
+ // We must control the visibility of the suggestion strip in order to avoid clipped
+ // key previews, even when we don't show the suggestion strip.
+ mCandidateViewContainer.setVisibility(
+ shouldShowCandidates ? View.VISIBLE : View.INVISIBLE);
+ super.setCandidatesViewShown(true);
+ }
}
}
@@ -887,35 +890,25 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
@Override
public void onComputeInsets(InputMethodService.Insets outInsets) {
super.onComputeInsets(outInsets);
- if (!isFullscreenMode()) {
- outInsets.contentTopInsets = outInsets.visibleTopInsets;
- }
- KeyboardView inputView = mKeyboardSwitcher.getInputView();
+ final KeyboardView inputView = mKeyboardSwitcher.getInputView();
// Need to set touchable region only if input view is being shown
if (inputView != null && mKeyboardSwitcher.isInputViewShown()) {
- final int x = 0;
- int y = 0;
- final int width = inputView.getWidth();
- int height = inputView.getHeight() + EXTENDED_TOUCHABLE_REGION_HEIGHT;
- if (mCandidateViewContainer != null) {
- ViewParent candidateParent = mCandidateViewContainer.getParent();
- if (candidateParent instanceof FrameLayout) {
- FrameLayout fl = (FrameLayout) candidateParent;
- if (fl != null) {
- // Check frame layout's visibility
- if (fl.getVisibility() == View.INVISIBLE) {
- y = fl.getHeight();
- height += y;
- } else if (fl.getVisibility() == View.VISIBLE) {
- height += fl.getHeight();
- }
- }
- }
+ final int containerHeight = mCandidateViewContainer.getHeight();
+ int touchY = containerHeight;
+ if (mCandidateViewContainer.getVisibility() == View.VISIBLE) {
+ touchY -= mCandidateStripHeight;
}
+ outInsets.contentTopInsets = touchY;
+ outInsets.visibleTopInsets = touchY;
+ final int touchWidth = inputView.getWidth();
+ final int touchHeight = inputView.getHeight() + containerHeight
+ // Extend touchable region below the keyboard.
+ + EXTENDED_TOUCHABLE_REGION_HEIGHT;
if (DEBUG) {
- Log.d(TAG, "Touchable region " + x + ", " + y + ", " + width + ", " + height);
+ Log.d(TAG, "Touchable region: y=" + touchY + " width=" + touchWidth
+ + " height=" + touchHeight);
}
- setTouchableRegionCompat(outInsets, x, y, width, height);
+ setTouchableRegionCompat(outInsets, 0, touchY, touchWidth, touchHeight);
}
}