Skip to content
Merged
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
12 changes: 12 additions & 0 deletions android/app/src/main/java/com/openipc/decoder/MenuManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ void showMenu(View anchor, boolean quadEnabled, int mActive, String version,
int margin = dp(12);
mMenuPopup.showAtLocation(anchor, Gravity.TOP | Gravity.START, margin, margin);
mMenuPopup.setOnDismissListener(() -> mMenuPopup = null);
focusForKeys(mMenuLayout);
return;
}

Expand All @@ -126,13 +127,15 @@ public boolean dispatchKeyEvent(KeyEvent event) {
}
};
layout.setOrientation(LinearLayout.VERTICAL);
layout.setFocusableInTouchMode(true);

PopupWindow popup = new PopupWindow(layout, LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT, true);
int margin = dp(12);
popup.showAtLocation(anchor, Gravity.TOP | Gravity.START, margin, margin);
mMenuPopup = popup;
popup.setOnDismissListener(() -> mMenuPopup = null);
focusForKeys(layout);

LinearLayout camRow = new LinearLayout(activity);
camRow.setOrientation(LinearLayout.HORIZONTAL);
Expand Down Expand Up @@ -247,6 +250,15 @@ private void updateCachedMenu(boolean quadEnabled, int mActive, String[] mHosts)
}
}

/**
* A menu opened by touch has no focused view, so keys never reach the layout and Escape
* did not close it. In touch mode the layout itself takes focus; with a remote, focus
* stays on the menu items as before.
*/
private static void focusForKeys(View layout) {
if (layout.isInTouchMode()) layout.requestFocus();
}

private TextView createItem(String title) {
TextView text = new TextView(activity);
text.setText(title);
Expand Down
Loading