From efe5e308f6c6fd570b535bb5b1801870c10cd361 Mon Sep 17 00:00:00 2001 From: Brian Nenninger Date: Mon, 10 Oct 2022 13:49:33 -0400 Subject: [PATCH] Adjust high score layout (#132) --- .../bouncy/BouncyActivity.java | 42 +++++++++++------- app/src/main/res/layout/highscoreitemview.xml | 11 ----- app/src/main/res/layout/main.xml | 43 ++++++++++++------- 3 files changed, 55 insertions(+), 41 deletions(-) delete mode 100644 app/src/main/res/layout/highscoreitemview.xml diff --git a/app/src/main/java/com/dozingcatsoftware/bouncy/BouncyActivity.java b/app/src/main/java/com/dozingcatsoftware/bouncy/BouncyActivity.java index 44bc0ec..878489c 100644 --- a/app/src/main/java/com/dozingcatsoftware/bouncy/BouncyActivity.java +++ b/app/src/main/java/com/dozingcatsoftware/bouncy/BouncyActivity.java @@ -27,15 +27,17 @@ import android.os.Looper; import android.preference.PreferenceManager; import android.util.Log; +import android.view.Gravity; import android.view.HapticFeedbackConstants; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.View; +import android.view.ViewGroup; import android.view.Window; -import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.CheckBox; -import android.widget.ListView; +import android.widget.LinearLayout; +import android.widget.TextView; public class BouncyActivity extends Activity { @@ -64,10 +66,10 @@ public class BouncyActivity extends Activity { Button showHighScoreButton; Button hideHighScoreButton; CheckBox unlimitedBallsToggle; + ViewGroup highScoreListLayout; + View noHighScoresTextView; final static int ACTIVITY_PREFERENCES = 1; - ArrayAdapter highScoreStringsAdapter; - Handler handler = new Handler(Looper.myLooper()); IStringResolver stringLookupFn = (key, params) -> { @@ -161,6 +163,8 @@ public class BouncyActivity extends Activity { unlimitedBallsToggle = findViewById(R.id.unlimitedBallsToggle); showHighScoreButton = findViewById(R.id.highScoreButton); hideHighScoreButton = findViewById(R.id.hideHighScoreButton); + highScoreListLayout = findViewById(R.id.highScoreListLayout); + noHighScoresTextView = findViewById(R.id.noHighScoresTextView); // Ugly workaround that seems to be required when supporting keyboard navigation. // In main.xml, all buttons have `android:focusableInTouchMode` set to true. @@ -197,10 +201,6 @@ public class BouncyActivity extends Activity { }); } - this.highScoreStringsAdapter = new ArrayAdapter(this, R.layout.highscoreitemview, R.id.highscoreitemtextview); - ListView highScoreListView = findViewById(R.id.highScoreListView); - highScoreListView.setAdapter(this.highScoreStringsAdapter); - // TODO: allow field configuration to specify whether tilting is allowed /* orientationListener = new OrientationListener(this, SensorManager.SENSOR_DELAY_GAME, @@ -615,19 +615,31 @@ public void showHighScore(View view) { public void hideHighScore(View view) { this.buttonPanel.setVisibility(View.VISIBLE); this.highScorePanel.setVisibility(View.GONE); - this.highScoreStringsAdapter.clear(); + this.highScoreListLayout.removeAllViews(); } private void fillHighScoreAdapter() { - this.highScoreStringsAdapter.clear(); + LinearLayout.LayoutParams params = null; + this.highScoreListLayout.removeAllViews(); for (int index = 0; index < this.highScores.size(); index++) { long score = this.highScores.get(index); if (score > 0) { - this.highScoreStringsAdapter.add(ScoreView.SCORE_FORMAT.format(score)); + if (params == null) { + params = new LinearLayout.LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, + LinearLayout.LayoutParams.WRAP_CONTENT); + params.bottomMargin = (int)(16 * getResources().getDisplayMetrics().scaledDensity); + } + TextView scoreItem = new TextView(this); + scoreItem.setLayoutParams(params); + scoreItem.setText(ScoreView.SCORE_FORMAT.format(score)); + scoreItem.setTextSize(22); + scoreItem.setTextColor(Color.argb(255, 240, 240, 240)); + scoreItem.setGravity(Gravity.END); + this.highScoreListLayout.addView(scoreItem); } } - if (this.highScoreStringsAdapter.isEmpty()) { - this.highScoreStringsAdapter.add(getString(R.string.no_high_scores_message)); - } + this.noHighScoresTextView.setVisibility( + this.highScoreListLayout.getChildCount() == 0 ? View.VISIBLE : View.GONE); } -} \ No newline at end of file +} diff --git a/app/src/main/res/layout/highscoreitemview.xml b/app/src/main/res/layout/highscoreitemview.xml deleted file mode 100644 index 8ff4f59..0000000 --- a/app/src/main/res/layout/highscoreitemview.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - \ No newline at end of file diff --git a/app/src/main/res/layout/main.xml b/app/src/main/res/layout/main.xml index 1283ef2..b18f928 100644 --- a/app/src/main/res/layout/main.xml +++ b/app/src/main/res/layout/main.xml @@ -125,29 +125,42 @@ - + -