mirror of
https://github.com/yuliskov/LeanKeyboard.git
synced 2026-04-20 15:06:53 -04:00
cyclic scroll: vertical
This commit is contained in:
@@ -679,13 +679,13 @@ public class LeanbackKeyboardContainer {
|
||||
}
|
||||
|
||||
public void updateCyclicFocus(int dir, KeyFocus oldFocus, KeyFocus newFocus) {
|
||||
if (oldFocus.equals(newFocus) || newFocus.index == 0) { // submit button has index 0
|
||||
if (oldFocus.equals(newFocus) || LeanbackUtils.isSubmitButton(newFocus)) { // submit button has index 0
|
||||
if (LeanKeyPreferences.instance(mContext).getCyclicNavigationEnabled()) {
|
||||
if (dir == DIRECTION_LEFT) {
|
||||
offsetRect(mRect, mMainKeyboardView);
|
||||
boolean onSameRow = oldFocus.rect.top < mRect.bottom/2f && mRect.bottom/2f < oldFocus.rect.bottom;
|
||||
boolean isCentered = oldFocus.rect.top < mRect.bottom/2f && mRect.bottom/2f < oldFocus.rect.bottom;
|
||||
|
||||
if (onSameRow) {
|
||||
if (isCentered) {
|
||||
offsetRect(mRect, mActionButtonView);
|
||||
configureFocus(newFocus, mRect, 0, KeyFocus.TYPE_ACTION);
|
||||
} else {
|
||||
@@ -695,15 +695,27 @@ public class LeanbackKeyboardContainer {
|
||||
configureFocus(newFocus, mRect, keyIdx, key, 0);
|
||||
}
|
||||
} else if (dir == DIRECTION_RIGHT) {
|
||||
boolean onSameRow = Math.abs(oldFocus.rect.bottom - newFocus.rect.bottom) < 20;
|
||||
offsetRect(mRect, mMainKeyboardView);
|
||||
boolean isCentered = oldFocus.rect.top < mRect.bottom/2f && mRect.bottom/2f < oldFocus.rect.bottom;
|
||||
|
||||
if (oldFocus.index == 0 || !onSameRow) {
|
||||
offsetRect(mRect, mMainKeyboardView);
|
||||
if (LeanbackUtils.isSubmitButton(oldFocus) || !isCentered) {
|
||||
// leftmost key (usually a button)
|
||||
int keyIdx = mMainKeyboardView.getNearestIndex(0, mY - mRect.top);
|
||||
Key key = mMainKeyboardView.getKey(keyIdx);
|
||||
configureFocus(newFocus, mRect, keyIdx, key, 0);
|
||||
}
|
||||
} else if (dir == DIRECTION_DOWN) {
|
||||
offsetRect(mRect, mMainKeyboardView);
|
||||
// topmost key
|
||||
int keyIdx = mMainKeyboardView.getNearestIndex(mX - mRect.left, 0);
|
||||
Key key = mMainKeyboardView.getKey(keyIdx);
|
||||
configureFocus(newFocus, mRect, keyIdx, key, 0);
|
||||
} else if (dir == DIRECTION_UP) {
|
||||
offsetRect(mRect, mMainKeyboardView);
|
||||
// downmost key
|
||||
int keyIdx = mMainKeyboardView.getNearestIndex(mX - mRect.left, mRect.bottom);
|
||||
Key key = mMainKeyboardView.getKey(keyIdx);
|
||||
configureFocus(newFocus, mRect, keyIdx, key, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1574,4 +1586,23 @@ public class LeanbackKeyboardContainer {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void focusNearestSuggestion(KeyFocus newFocus) {
|
||||
int count = mSuggestions.getChildCount();
|
||||
for (int idx = 0; idx < count; ++idx) {
|
||||
View view = mSuggestions.getChildAt(idx);
|
||||
offsetRect(mRect, view);
|
||||
if (mX < (float) mRect.right || idx + 1 == count) {
|
||||
view.requestFocus();
|
||||
LeanbackUtils.sendAccessibilityEvent(view.findViewById(R.id.text), true);
|
||||
configureFocus(newFocus, mRect, idx, KeyFocus.TYPE_SUGGESTION);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void focusOppositeSuggestion(KeyFocus currentFocus, KeyFocus newFocus) {
|
||||
int count = mSuggestions.getChildCount();
|
||||
// TODO: find opposite suggestion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,10 @@ import android.view.accessibility.AccessibilityEvent;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.view.inputmethod.InputConnection;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.LinearLayout;
|
||||
import androidx.core.text.BidiFormatter;
|
||||
import com.liskovsoft.leankeyboard.ime.LeanbackKeyboardContainer.KeyFocus;
|
||||
import com.liskovsoft.leankeykeyboard.R;
|
||||
|
||||
public class LeanbackUtils {
|
||||
private static final int ACCESSIBILITY_DELAY_MS = 250;
|
||||
@@ -184,4 +187,12 @@ public class LeanbackUtils {
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
public static boolean isSubmitButton(KeyFocus focus) {
|
||||
return focus.index == 0 && focus.type == KeyFocus.TYPE_ACTION;
|
||||
}
|
||||
|
||||
public static boolean isSuggestionsButton(KeyFocus focus) {
|
||||
return focus.type == KeyFocus.TYPE_SUGGESTION;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,6 +109,6 @@ public final class LeanKeyPreferences {
|
||||
}
|
||||
|
||||
public boolean getCyclicNavigationEnabled() {
|
||||
return mPrefs.getBoolean(CYCLIC_NAVIGATION_ENABLED, true);
|
||||
return mPrefs.getBoolean(CYCLIC_NAVIGATION_ENABLED, false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user