Skip to content

Debloat any Android or Google TV over Wi-Fi and get an Apple TV-style home.

launcher: keep D-pad focus inside a row at its ends

Yaswanth Gosulacad6c02b63c5
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/AppAdapter.java b/launcher/app/src/main/java/com/gathin/tvhome/AppAdapter.java
index 6b4c1434b..db53271c8 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/AppAdapter.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/AppAdapter.java
@@ -43,7 +43,7 @@ public class AppAdapter extends RecyclerView.Adapter<AppAdapter.Holder> {
interface TileListener {
void onTileFocused(int position, View card);
- /** Called for D-pad Up/Down on a tile. Return true when handled. */
+ /** Called for a D-pad direction key on a tile. Return true when handled (focus stays put). */
boolean onTileVerticalKey(int position, int keyCode);
}
@@ -273,7 +273,8 @@ public class AppAdapter extends RecyclerView.Adapter<AppAdapter.Holder> {
card.setOnKeyListener((view, keyCode, event) -> {
if (event.getAction() != KeyEvent.ACTION_DOWN) return false;
- if (keyCode != KeyEvent.KEYCODE_DPAD_UP && keyCode != KeyEvent.KEYCODE_DPAD_DOWN) return false;
+ if (keyCode != KeyEvent.KEYCODE_DPAD_UP && keyCode != KeyEvent.KEYCODE_DPAD_DOWN
+ && keyCode != KeyEvent.KEYCODE_DPAD_LEFT && keyCode != KeyEvent.KEYCODE_DPAD_RIGHT) return false;
int pos = getBindingAdapterPosition();
return listener != null && pos != RecyclerView.NO_POSITION && listener.onTileVerticalKey(pos, keyCode);
});
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java b/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java
index 1983ab73e..5648d276d 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java
@@ -338,6 +338,14 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
public boolean onTileVerticalKey(int position, int keyCode) {
int count = adapter.getItemCount();
int target;
+ // Horizontal: swallow the key at a row's ends so focus never wraps to the next row or
+ // escapes up into the top bar. Mid-row moves fall through to the default focus search.
+ if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
+ return position % COLUMNS == 0;
+ }
+ if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
+ return position % COLUMNS == COLUMNS - 1 || position == count - 1;
+ }
if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
if (position < COLUMNS) return false; // dock row: let focus move to the top bar
target = position - COLUMNS;