Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions java/src/org/futo/inputmethod/keyboard/MoreKeysKeyboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,22 @@

public final class MoreKeysKeyboard extends Keyboard {
private final int mDefaultKeyCoordX;
private final Key mDefaultKey;

MoreKeysKeyboard(final MoreKeysKeyboardParams params) {
super(params);
mDefaultKeyCoordX = params.getDefaultKeyCoordX() + params.mDefaultKeyWidth / 2;
mDefaultKey = params.mDefaultKey;
}

public int getDefaultCoordX() {
return mDefaultKeyCoordX;
}

public Key getDefaultKey() {
return mDefaultKey;
}

@UsedForTesting
static class MoreKeysKeyboardParams extends KeyboardParams {
public boolean mIsMoreKeysFixedOrder;
Expand All @@ -56,6 +62,7 @@ static class MoreKeysKeyboardParams extends KeyboardParams {
public int mRightKeys; // includes default key.
public int mDividerWidth;
public int mColumnWidth;
public Key mDefaultKey;

public MoreKeysKeyboardParams() {
super();
Expand Down Expand Up @@ -354,6 +361,9 @@ public MoreKeysKeyboard build() {
final int x = params.getX(n, row);
final int y = params.getY(row);
final Key key = moreKeySpec.buildKey(x, y, moreKeyFlags, params);
if (n == 0) {
params.mDefaultKey = key;
}
params.markAsEdgeKey(key, row);
params.onAddKey(key);
}
Expand Down
31 changes: 28 additions & 3 deletions java/src/org/futo/inputmethod/keyboard/MoreKeysKeyboardView.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class MoreKeysKeyboardView extends KeyboardView implements MoreKeysPanel
private Key mCurrentKey;

private int mActivePointerId;
private boolean mDefaultKeySelectionFallback;

private final float sideAllowance;

Expand Down Expand Up @@ -189,14 +190,33 @@ protected int getDefaultCoordX() {
@Override
public void onDownEvent(final int x, final int y, final int pointerId, final long eventTime) {
mActivePointerId = pointerId;
mDefaultKeySelectionFallback = false;
mCurrentKey = detectKey(x, y);
}

@Override
public void selectDefaultKeyIfNone() {
if (mCurrentKey != null) {
return;
}
final Key defaultKey = ((MoreKeysKeyboard)getKeyboard()).getDefaultKey();
if (defaultKey == null) {
return;
}
mDefaultKeySelectionFallback = true;
mCurrentKey = defaultKey;
updatePressKeyGraphics(defaultKey);
}

@Override
public void onMoveEvent(final int x, final int y, final int pointerId, final long eventTime) {
if (mActivePointerId != pointerId) {
return;
}
if (mDefaultKeySelectionFallback && mKeyDetector.detectHitKey(x, y) == null) {
return;
}
mDefaultKeySelectionFallback = false;
final boolean hasOldKey = (mCurrentKey != null);
mCurrentKey = detectKey(x, y);
if (hasOldKey && mCurrentKey == null) {
Expand All @@ -210,14 +230,18 @@ public void onUpEvent(final int x, final int y, final int pointerId, final long
if (mActivePointerId != pointerId) {
return;
}
// Calling {@link #detectKey(int,int,int)} here is harmless because the last move event and
// the following up event share the same coordinates.
mCurrentKey = detectKey(x, y);
if (!mDefaultKeySelectionFallback || mKeyDetector.detectHitKey(x, y) != null) {
// Calling {@link #detectKey(int,int,int)} here is harmless because the last move event and
// the following up event share the same coordinates.
mDefaultKeySelectionFallback = false;
mCurrentKey = detectKey(x, y);
}
if (mCurrentKey != null) {
updateReleaseKeyGraphics(mCurrentKey);
onKeyInput(mCurrentKey, x, y);
mCurrentKey = null;
}
mDefaultKeySelectionFallback = false;
}

/**
Expand Down Expand Up @@ -281,6 +305,7 @@ public void dismissMoreKeysPanel() {
&& AccessibilityUtils.getInstance().isAccessibilityEnabled()) {
accessibilityDelegate.onDismissMoreKeysKeyboard();
}
mDefaultKeySelectionFallback = false;
mController.onDismissMoreKeysPanel();
}

Expand Down
5 changes: 5 additions & 0 deletions java/src/org/futo/inputmethod/keyboard/MoreKeysPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ public void showMoreKeysPanel(View parentView, Controller controller, int pointX
*/
public void onDownEvent(final int x, final int y, final int pointerId, final long eventTime);

/**
* Select the default key if no key is currently selected.
*/
public void selectDefaultKeyIfNone();

/**
* Process an up event on the more keys panel.
*
Expand Down
1 change: 1 addition & 0 deletions java/src/org/futo/inputmethod/keyboard/PointerTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -1258,6 +1258,7 @@ public void onLongPressed() {
final int translatedX = moreKeysPanel.translateX(mLastX);
final int translatedY = moreKeysPanel.translateY(mLastY);
moreKeysPanel.onDownEvent(translatedX, translatedY, mPointerId, SystemClock.uptimeMillis());
moreKeysPanel.selectDefaultKeyIfNone();
mMoreKeysPanel = moreKeysPanel;
}

Expand Down