Merge "Make PopupPanel decoupled with LatinKeyboardView and Keyboard"
This commit is contained in:
commit
ed23cc7f0b
4 changed files with 59 additions and 43 deletions
|
@ -81,6 +81,7 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
|
||||||
private int mOldPointerCount = 1;
|
private int mOldPointerCount = 1;
|
||||||
private int mOldKeyIndex;
|
private int mOldKeyIndex;
|
||||||
|
|
||||||
|
private final boolean mConfigShowMiniKeyboardAtTouchedPoint;
|
||||||
protected KeyDetector mKeyDetector;
|
protected KeyDetector mKeyDetector;
|
||||||
|
|
||||||
// To detect double tap.
|
// To detect double tap.
|
||||||
|
@ -225,6 +226,8 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
|
||||||
a.recycle();
|
a.recycle();
|
||||||
|
|
||||||
final Resources res = getResources();
|
final Resources res = getResources();
|
||||||
|
mConfigShowMiniKeyboardAtTouchedPoint = res.getBoolean(
|
||||||
|
R.bool.config_show_mini_keyboard_at_touched_point);
|
||||||
final float keyHysteresisDistance = res.getDimension(R.dimen.key_hysteresis_distance);
|
final float keyHysteresisDistance = res.getDimension(R.dimen.key_hysteresis_distance);
|
||||||
mKeyDetector = new KeyDetector(keyHysteresisDistance);
|
mKeyDetector = new KeyDetector(keyHysteresisDistance);
|
||||||
|
|
||||||
|
@ -459,7 +462,13 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
|
||||||
mPopupPanel = popupPanel;
|
mPopupPanel = popupPanel;
|
||||||
mPopupPanelPointerTrackerId = tracker.mPointerId;
|
mPopupPanelPointerTrackerId = tracker.mPointerId;
|
||||||
|
|
||||||
popupPanel.showPopupPanel(this, parentKey, tracker, mPopupWindow);
|
final Keyboard keyboard = getKeyboard();
|
||||||
|
mPopupPanel.setShifted(keyboard.isShiftedOrShiftLocked());
|
||||||
|
final int pointX = (mConfigShowMiniKeyboardAtTouchedPoint) ? tracker.getLastX()
|
||||||
|
: parentKey.mX + parentKey.mWidth / 2;
|
||||||
|
final int pointY = parentKey.mY - keyboard.mVerticalGap;
|
||||||
|
popupPanel.showPopupPanel(
|
||||||
|
this, this, pointX, pointY, mPopupWindow, getKeyboardActionListener());
|
||||||
final int translatedX = popupPanel.translateX(tracker.getLastX());
|
final int translatedX = popupPanel.translateX(tracker.getLastX());
|
||||||
final int translatedY = popupPanel.translateY(tracker.getLastY());
|
final int translatedY = popupPanel.translateY(tracker.getLastY());
|
||||||
tracker.onShowPopupPanel(translatedX, translatedY, SystemClock.uptimeMillis(), popupPanel);
|
tracker.onShowPopupPanel(translatedX, translatedY, SystemClock.uptimeMillis(), popupPanel);
|
||||||
|
|
|
@ -63,13 +63,12 @@ public class PointerTracker {
|
||||||
public TimerProxy getTimerProxy();
|
public TimerProxy getTimerProxy();
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface DrawingProxy {
|
public interface DrawingProxy extends PopupPanel.Controller {
|
||||||
public void invalidateKey(Key key);
|
public void invalidateKey(Key key);
|
||||||
public TextView inflateKeyPreviewText();
|
public TextView inflateKeyPreviewText();
|
||||||
public void showKeyPreview(int keyIndex, PointerTracker tracker);
|
public void showKeyPreview(int keyIndex, PointerTracker tracker);
|
||||||
public void cancelShowKeyPreview(PointerTracker tracker);
|
public void cancelShowKeyPreview(PointerTracker tracker);
|
||||||
public void dismissKeyPreview(PointerTracker tracker);
|
public void dismissKeyPreview(PointerTracker tracker);
|
||||||
public boolean dismissPopupPanel();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface TimerProxy {
|
public interface TimerProxy {
|
||||||
|
|
|
@ -36,12 +36,12 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
public class PopupMiniKeyboardView extends KeyboardView implements PopupPanel {
|
public class PopupMiniKeyboardView extends KeyboardView implements PopupPanel {
|
||||||
private final int[] mCoordinates = new int[2];
|
private final int[] mCoordinates = new int[2];
|
||||||
private final boolean mConfigShowMiniKeyboardAtTouchedPoint;
|
|
||||||
|
|
||||||
private final KeyDetector mKeyDetector;
|
private final KeyDetector mKeyDetector;
|
||||||
private final int mVerticalCorrection;
|
private final int mVerticalCorrection;
|
||||||
|
|
||||||
private LatinKeyboardView mParentKeyboardView;
|
private Controller mController;
|
||||||
|
private KeyboardActionListener mListener;
|
||||||
private int mOriginX;
|
private int mOriginX;
|
||||||
private int mOriginY;
|
private int mOriginY;
|
||||||
|
|
||||||
|
@ -101,30 +101,29 @@ public class PopupMiniKeyboardView extends KeyboardView implements PopupPanel {
|
||||||
public void cancelKeyTimers() {}
|
public void cancelKeyTimers() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
private final KeyboardActionListener mListner = new KeyboardActionListener() {
|
private final KeyboardActionListener mMiniKeyboardListener = new KeyboardActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onCodeInput(int primaryCode, int[] keyCodes, int x, int y) {
|
public void onCodeInput(int primaryCode, int[] keyCodes, int x, int y) {
|
||||||
mParentKeyboardView.getKeyboardActionListener()
|
mListener.onCodeInput(primaryCode, keyCodes, x, y);
|
||||||
.onCodeInput(primaryCode, keyCodes, x, y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTextInput(CharSequence text) {
|
public void onTextInput(CharSequence text) {
|
||||||
mParentKeyboardView.getKeyboardActionListener().onTextInput(text);
|
mListener.onTextInput(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCancelInput() {
|
public void onCancelInput() {
|
||||||
mParentKeyboardView.getKeyboardActionListener().onCancelInput();
|
mListener.onCancelInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPress(int primaryCode, boolean withSliding) {
|
public void onPress(int primaryCode, boolean withSliding) {
|
||||||
mParentKeyboardView.getKeyboardActionListener().onPress(primaryCode, withSliding);
|
mListener.onPress(primaryCode, withSliding);
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void onRelease(int primaryCode, boolean withSliding) {
|
public void onRelease(int primaryCode, boolean withSliding) {
|
||||||
mParentKeyboardView.getKeyboardActionListener().onRelease(primaryCode, withSliding);
|
mListener.onRelease(primaryCode, withSliding);
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public boolean onCustomRequest(int requestCode) { return false; }
|
public boolean onCustomRequest(int requestCode) { return false; }
|
||||||
|
@ -144,8 +143,6 @@ public class PopupMiniKeyboardView extends KeyboardView implements PopupPanel {
|
||||||
a.recycle();
|
a.recycle();
|
||||||
|
|
||||||
final Resources res = context.getResources();
|
final Resources res = context.getResources();
|
||||||
mConfigShowMiniKeyboardAtTouchedPoint = res.getBoolean(
|
|
||||||
R.bool.config_show_mini_keyboard_at_touched_point);
|
|
||||||
// Override default ProximityKeyDetector.
|
// Override default ProximityKeyDetector.
|
||||||
mKeyDetector = new MiniKeyboardKeyDetector(res.getDimension(
|
mKeyDetector = new MiniKeyboardKeyDetector(res.getDimension(
|
||||||
R.dimen.mini_keyboard_slide_allowance));
|
R.dimen.mini_keyboard_slide_allowance));
|
||||||
|
@ -179,7 +176,7 @@ public class PopupMiniKeyboardView extends KeyboardView implements PopupPanel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KeyboardActionListener getKeyboardActionListener() {
|
public KeyboardActionListener getKeyboardActionListener() {
|
||||||
return mListner;
|
return mMiniKeyboardListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -200,34 +197,36 @@ public class PopupMiniKeyboardView extends KeyboardView implements PopupPanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void showPopupPanel(LatinKeyboardView parentKeyboardView, Key parentKey,
|
public void setShifted(boolean shifted) {
|
||||||
PointerTracker tracker, PopupWindow window) {
|
|
||||||
mParentKeyboardView = parentKeyboardView;
|
|
||||||
final View container = (View)getParent();
|
|
||||||
final MiniKeyboard miniKeyboard = (MiniKeyboard)getKeyboard();
|
final MiniKeyboard miniKeyboard = (MiniKeyboard)getKeyboard();
|
||||||
final Keyboard parentKeyboard = parentKeyboardView.getKeyboard();
|
if (miniKeyboard.setShifted(shifted)) {
|
||||||
|
|
||||||
parentKeyboardView.getLocationInWindow(mCoordinates);
|
|
||||||
final int pointX = (mConfigShowMiniKeyboardAtTouchedPoint) ? tracker.getLastX()
|
|
||||||
: parentKey.mX + parentKey.mWidth / 2;
|
|
||||||
final int pointY = parentKey.mY;
|
|
||||||
final int miniKeyboardLeft = pointX - miniKeyboard.getDefaultCoordX()
|
|
||||||
+ parentKeyboardView.getPaddingLeft();
|
|
||||||
final int x = wrapUp(Math.max(0, Math.min(miniKeyboardLeft,
|
|
||||||
parentKeyboardView.getWidth() - miniKeyboard.mOccupiedWidth))
|
|
||||||
- container.getPaddingLeft() + mCoordinates[0],
|
|
||||||
container.getMeasuredWidth(), 0, parentKeyboardView.getWidth());
|
|
||||||
final int y = pointY - parentKeyboard.mVerticalGap
|
|
||||||
- (container.getMeasuredHeight() - container.getPaddingBottom())
|
|
||||||
+ parentKeyboardView.getPaddingTop() + mCoordinates[1];
|
|
||||||
|
|
||||||
if (miniKeyboard.setShifted(parentKeyboard.isShiftedOrShiftLocked())) {
|
|
||||||
invalidateAllKeys();
|
invalidateAllKeys();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void showPopupPanel(View parentView, Controller controller, int pointX, int pointY,
|
||||||
|
PopupWindow window, KeyboardActionListener listener) {
|
||||||
|
mController = controller;
|
||||||
|
mListener = listener;
|
||||||
|
final View container = (View)getParent();
|
||||||
|
final MiniKeyboard miniKeyboard = (MiniKeyboard)getKeyboard();
|
||||||
|
|
||||||
|
parentView.getLocationInWindow(mCoordinates);
|
||||||
|
final int miniKeyboardLeft = pointX - miniKeyboard.getDefaultCoordX()
|
||||||
|
+ parentView.getPaddingLeft();
|
||||||
|
final int x = wrapUp(Math.max(0, Math.min(miniKeyboardLeft,
|
||||||
|
parentView.getWidth() - miniKeyboard.mOccupiedWidth))
|
||||||
|
- container.getPaddingLeft() + mCoordinates[0],
|
||||||
|
container.getMeasuredWidth(), 0, parentView.getWidth());
|
||||||
|
final int y = pointY
|
||||||
|
- (container.getMeasuredHeight() - container.getPaddingBottom())
|
||||||
|
+ parentView.getPaddingTop() + mCoordinates[1];
|
||||||
|
|
||||||
window.setContentView(container);
|
window.setContentView(container);
|
||||||
window.setWidth(container.getMeasuredWidth());
|
window.setWidth(container.getMeasuredWidth());
|
||||||
window.setHeight(container.getMeasuredHeight());
|
window.setHeight(container.getMeasuredHeight());
|
||||||
window.showAtLocation(parentKeyboardView, Gravity.NO_GRAVITY, x, y);
|
window.showAtLocation(parentView, Gravity.NO_GRAVITY, x, y);
|
||||||
|
|
||||||
mOriginX = x + container.getPaddingLeft() - mCoordinates[0];
|
mOriginX = x + container.getPaddingLeft() - mCoordinates[0];
|
||||||
mOriginY = y + container.getPaddingTop() - mCoordinates[1];
|
mOriginY = y + container.getPaddingTop() - mCoordinates[1];
|
||||||
|
@ -243,7 +242,7 @@ public class PopupMiniKeyboardView extends KeyboardView implements PopupPanel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean dismissPopupPanel() {
|
public boolean dismissPopupPanel() {
|
||||||
return mParentKeyboardView.dismissPopupPanel();
|
return mController.dismissPopupPanel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -16,18 +16,27 @@
|
||||||
|
|
||||||
package com.android.inputmethod.keyboard;
|
package com.android.inputmethod.keyboard;
|
||||||
|
|
||||||
|
import android.view.View;
|
||||||
import android.widget.PopupWindow;
|
import android.widget.PopupWindow;
|
||||||
|
|
||||||
public interface PopupPanel extends PointerTracker.KeyEventHandler {
|
public interface PopupPanel extends PointerTracker.KeyEventHandler {
|
||||||
|
public interface Controller {
|
||||||
|
public boolean dismissPopupPanel();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShifted(boolean shifted);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show popup panel.
|
* Show popup panel.
|
||||||
* @param parentKeyboardView the parent KeyboardView that has the parent key.
|
* @param parentView the parent view of this popup panel
|
||||||
* @param parentKey the parent key that is the source of this popup panel
|
* @param controller the controller that can dismiss this popup panel
|
||||||
* @param tracker the pointer tracker that pressesd the parent key
|
* @param pointX x coordinate of this popup panel
|
||||||
|
* @param pointY y coordinate of this popup panel
|
||||||
* @param window PopupWindow to be used to show this popup panel
|
* @param window PopupWindow to be used to show this popup panel
|
||||||
|
* @param listener the listener that will receive keyboard action from this popup panel.
|
||||||
*/
|
*/
|
||||||
public void showPopupPanel(LatinKeyboardView parentKeyboardView, Key parentKey,
|
public void showPopupPanel(View parentView, Controller controller, int pointX, int pointY,
|
||||||
PointerTracker tracker, PopupWindow window);
|
PopupWindow window, KeyboardActionListener listener);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Translate X-coordinate of touch event to the local X-coordinate of this PopupPanel.
|
* Translate X-coordinate of touch event to the local X-coordinate of this PopupPanel.
|
||||||
|
|
Loading…
Reference in a new issue