aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/keyboard/MainKeyboardView.java')
-rw-r--r--java/src/com/android/inputmethod/keyboard/MainKeyboardView.java44
1 files changed, 25 insertions, 19 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
index 9a859bfdb..e7cfc453f 100644
--- a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
@@ -35,7 +35,6 @@ import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodSubtype;
-import android.widget.TextView;
import com.android.inputmethod.accessibility.AccessibilityUtils;
import com.android.inputmethod.accessibility.MainKeyboardAccessibilityDelegate;
@@ -48,6 +47,7 @@ import com.android.inputmethod.keyboard.internal.KeyDrawParams;
import com.android.inputmethod.keyboard.internal.KeyPreviewChoreographer;
import com.android.inputmethod.keyboard.internal.KeyPreviewDrawParams;
import com.android.inputmethod.keyboard.internal.LanguageOnSpacebarHelper;
+import com.android.inputmethod.keyboard.internal.MoreKeySpec;
import com.android.inputmethod.keyboard.internal.NonDistinctMultitouchHelper;
import com.android.inputmethod.keyboard.internal.SlidingKeyInputDrawingPreview;
import com.android.inputmethod.keyboard.internal.TimerHandler;
@@ -428,15 +428,6 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
windowContentView.addView(mDrawingPreviewPlacerView);
}
- /**
- * Returns the enabled state of the key feedback preview
- * @return whether or not the key feedback preview is enabled
- * @see #setKeyPreviewPopupEnabled(boolean, int)
- */
- public boolean isKeyPreviewPopupEnabled() {
- return mKeyPreviewDrawParams.isPopupEnabled();
- }
-
// Implements {@link DrawingHandler.Callbacks} method.
@Override
public void dismissAllKeyPreviews() {
@@ -461,12 +452,9 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
}
locatePreviewPlacerView();
- final TextView previewTextView = mKeyPreviewChoreographer.getKeyPreviewTextView(
- key, mDrawingPreviewPlacerView);
getLocationInWindow(mOriginCoords);
- mKeyPreviewChoreographer.placeKeyPreview(key, previewTextView, keyboard.mIconsSet,
- mKeyDrawParams, getWidth(), mOriginCoords);
- mKeyPreviewChoreographer.showKeyPreview(key, previewTextView, isHardwareAccelerated());
+ mKeyPreviewChoreographer.placeKeyPreviewAndShow(key, keyboard.mIconsSet, mKeyDrawParams,
+ getWidth(), mOriginCoords, mDrawingPreviewPlacerView, isHardwareAccelerated());
}
// Implements {@link TimerHandler.Callbacks} method.
@@ -557,13 +545,25 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
}
private MoreKeysPanel onCreateMoreKeysPanel(final Key key, final Context context) {
- if (key.getMoreKeys() == null) {
+ final MoreKeySpec[] moreKeys = key.getMoreKeys();
+ if (moreKeys == null) {
return null;
}
Keyboard moreKeysKeyboard = mMoreKeysKeyboardCache.get(key);
if (moreKeysKeyboard == null) {
- moreKeysKeyboard = new MoreKeysKeyboard.Builder(
- context, key, this, mKeyPreviewDrawParams).build();
+ // {@link KeyPreviewDrawParams#mPreviewVisibleWidth} should have been set at
+ // {@link KeyPreviewChoreographer#placeKeyPreview(Key,TextView,KeyboardIconsSet,KeyDrawParams,int,int[]},
+ // though there may be some chances that the value is zero. <code>width == 0</code>
+ // will cause zero-division error at
+ // {@link MoreKeysKeyboardParams#setParameters(int,int,int,int,int,int,boolean,int)}.
+ final boolean singleMoreKeyWithPreview = mKeyPreviewDrawParams.isPopupEnabled()
+ && !key.noKeyPreview() && moreKeys.length == 1
+ && mKeyPreviewDrawParams.getVisibleWidth() > 0;
+ final MoreKeysKeyboard.Builder builder = new MoreKeysKeyboard.Builder(
+ context, key, getKeyboard(), singleMoreKeyWithPreview,
+ mKeyPreviewDrawParams.getVisibleWidth(),
+ mKeyPreviewDrawParams.getVisibleHeight(), newLabelPaint(key));
+ moreKeysKeyboard = builder.build();
mMoreKeysKeyboardCache.put(key, moreKeysKeyboard);
}
@@ -619,7 +619,8 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
final int[] lastCoords = CoordinateUtils.newInstance();
tracker.getLastCoordinates(lastCoords);
- final boolean keyPreviewEnabled = isKeyPreviewPopupEnabled() && !key.noKeyPreview();
+ final boolean keyPreviewEnabled = mKeyPreviewDrawParams.isPopupEnabled()
+ && !key.noKeyPreview();
// The more keys keyboard is usually horizontally aligned with the center of the parent key.
// If showMoreKeysKeyboardAtTouchedPoint is true and the key preview is disabled, the more
// keys keyboard is placed at the touch point of the parent key.
@@ -665,6 +666,10 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
@Override
public void onDismissMoreKeysPanel() {
dimEntireKeyboard(false /* dimmed */);
+ dismissMoreKeysPanel();
+ }
+
+ private void dismissMoreKeysPanel() {
if (isShowingMoreKeysPanel()) {
mMoreKeysPanel.removeFromParent();
mMoreKeysPanel = null;
@@ -730,6 +735,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
}
public void onHideWindow() {
+ dismissMoreKeysPanel();
final MainKeyboardAccessibilityDelegate accessibilityDelegate = mAccessibilityDelegate;
if (accessibilityDelegate != null) {
accessibilityDelegate.onHideWindow();