From 65fe03ebd14eddb375579e905a8c83c14fafeb5d Mon Sep 17 00:00:00 2001 From: Yuriy Liskov Date: Tue, 30 Jun 2020 21:18:44 +0300 Subject: [PATCH] cyclic scroll: fin --- .../ime/LeanbackKeyboardContainer.java | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/leankeykeyboard/src/main/java/com/liskovsoft/leankeyboard/ime/LeanbackKeyboardContainer.java b/leankeykeyboard/src/main/java/com/liskovsoft/leankeyboard/ime/LeanbackKeyboardContainer.java index fc211be..6f0a1c7 100644 --- a/leankeykeyboard/src/main/java/com/liskovsoft/leankeyboard/ime/LeanbackKeyboardContainer.java +++ b/leankeykeyboard/src/main/java/com/liskovsoft/leankeyboard/ime/LeanbackKeyboardContainer.java @@ -679,20 +679,31 @@ public class LeanbackKeyboardContainer { } public void updateCyclicFocus(int dir, KeyFocus oldFocus, KeyFocus newFocus) { - if (oldFocus.equals(newFocus)) { + if (oldFocus.equals(newFocus) || newFocus.index == 0) { // submit button has index 0 if (LeanKeyPreferences.instance(mContext).getCyclicNavigationEnabled()) { if (dir == DIRECTION_LEFT) { offsetRect(mRect, mMainKeyboardView); - // rightmost key (usually ok button) - int keyIdx = mMainKeyboardView.getNearestIndex(mRect.right, mY - mRect.top); - Key key = mMainKeyboardView.getKey(keyIdx); - configureFocus(newFocus, mRect, keyIdx, key, 0); + boolean onSameRow = oldFocus.rect.top < mRect.bottom/2f && mRect.bottom/2f < oldFocus.rect.bottom; + + if (onSameRow) { + offsetRect(mRect, mActionButtonView); + configureFocus(newFocus, mRect, 0, KeyFocus.TYPE_ACTION); + } else { + // rightmost key (usually ok button) + int keyIdx = mMainKeyboardView.getNearestIndex(mRect.right, mY - mRect.top); + Key key = mMainKeyboardView.getKey(keyIdx); + configureFocus(newFocus, mRect, keyIdx, key, 0); + } } else if (dir == DIRECTION_RIGHT) { - offsetRect(mRect, mMainKeyboardView); - // leftmost key (usually a button) - int keyIdx = mMainKeyboardView.getNearestIndex(0, mY - mRect.top); - Key key = mMainKeyboardView.getKey(keyIdx); - configureFocus(newFocus, mRect, keyIdx, key, 0); + boolean onSameRow = Math.abs(oldFocus.rect.bottom - newFocus.rect.bottom) < 20; + + if (oldFocus.index == 0 || !onSameRow) { + offsetRect(mRect, mMainKeyboardView); + // leftmost key (usually a button) + int keyIdx = mMainKeyboardView.getNearestIndex(0, mY - mRect.top); + Key key = mMainKeyboardView.getKey(keyIdx); + configureFocus(newFocus, mRect, keyIdx, key, 0); + } } }