From 458d0def440ba6c1f47cb2c7c2d14dc1ebab3730 Mon Sep 17 00:00:00 2001 From: Brian Nenninger Date: Mon, 10 Oct 2022 17:30:15 -0400 Subject: [PATCH] Fixes for ancient device compatibility and button focus --- .../com/dozingcatsoftware/bouncy/BouncyActivity.java | 8 ++++++-- .../dozingcatsoftware/bouncy/FieldLayoutReader.java | 11 ++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/dozingcatsoftware/bouncy/BouncyActivity.java b/app/src/main/java/com/dozingcatsoftware/bouncy/BouncyActivity.java index 878489c..54ab8b8 100644 --- a/app/src/main/java/com/dozingcatsoftware/bouncy/BouncyActivity.java +++ b/app/src/main/java/com/dozingcatsoftware/bouncy/BouncyActivity.java @@ -309,8 +309,9 @@ public void unpauseGame() { void updateButtons() { GameState state = field.getGameState(); if (state.isPaused()) { - if (highScorePanel.getVisibility() == View.VISIBLE){ + if (highScorePanel.getVisibility() == View.VISIBLE) { buttonPanel.setVisibility(View.GONE); + hideHighScoreButton.requestFocus(); } else { buttonPanel.setVisibility(View.VISIBLE); @@ -327,8 +328,9 @@ void updateButtons() { buttonPanel.setVisibility(View.GONE); highScorePanel.setVisibility(View.GONE); } - else if (highScorePanel.getVisibility() == View.VISIBLE){ + else if (highScorePanel.getVisibility() == View.VISIBLE) { buttonPanel.setVisibility(View.GONE); + hideHighScoreButton.requestFocus(); } else { buttonPanel.setVisibility(View.VISIBLE); @@ -610,12 +612,14 @@ public void showHighScore(View view) { this.fillHighScoreAdapter(); this.buttonPanel.setVisibility(View.GONE); this.highScorePanel.setVisibility(View.VISIBLE); + updateButtons(); } public void hideHighScore(View view) { this.buttonPanel.setVisibility(View.VISIBLE); this.highScorePanel.setVisibility(View.GONE); this.highScoreListLayout.removeAllViews(); + updateButtons(); } private void fillHighScoreAdapter() { diff --git a/app/src/main/java/com/dozingcatsoftware/bouncy/FieldLayoutReader.java b/app/src/main/java/com/dozingcatsoftware/bouncy/FieldLayoutReader.java index 590a403..c201c80 100644 --- a/app/src/main/java/com/dozingcatsoftware/bouncy/FieldLayoutReader.java +++ b/app/src/main/java/com/dozingcatsoftware/bouncy/FieldLayoutReader.java @@ -17,9 +17,14 @@ public class FieldLayoutReader { public static int getNumberOfLevels(Context context) { try { - return (int) Arrays.stream(context.getAssets().list("tables")) - .filter(name -> name.matches("^table\\d+\\.json")) - .count(); + // This would be cleaner with Arrays.stream/filter/count, but that's not supported + // by Android's desugaring library so it breaks on older devices. + List tableFiles = Arrays.asList(context.getAssets().list("tables")); + int count = 0; + while (tableFiles.contains("table" + (count + 1) + ".json")) { + count++; + } + return count; } catch (IOException ex) { throw new RuntimeException(ex);