cyclic scroll: vertical

This commit is contained in:
Yuriy Liskov
2020-07-01 01:34:19 +03:00
parent 61c721520b
commit 3b2b7a2d47
3 changed files with 49 additions and 7 deletions

View File

@@ -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
}
}

View File

@@ -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;
}
}

View File

@@ -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);
}
}