Skip to content

Commit

Permalink
Adjust high score layout (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
dozingcat authored Oct 10, 2022
1 parent 7b1b90e commit efe5e30
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 41 deletions.
42 changes: 27 additions & 15 deletions app/src/main/java/com/dozingcatsoftware/bouncy/BouncyActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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<String> highScoreStringsAdapter;

Handler handler = new Handler(Looper.myLooper());

IStringResolver stringLookupFn = (key, params) -> {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -197,10 +201,6 @@ public class BouncyActivity extends Activity {
});
}

this.highScoreStringsAdapter = new ArrayAdapter<String>(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,
Expand Down Expand Up @@ -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);
}
}
}
11 changes: 0 additions & 11 deletions app/src/main/res/layout/highscoreitemview.xml

This file was deleted.

43 changes: 28 additions & 15 deletions app/src/main/res/layout/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,29 +125,42 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="24sp"
android:textStyle="bold"
android:textColor="#F0F0F0"
android:paddingBottom="20dp"
android:text="@string/high_score_table_title" />

<ListView
android:id="@+id/highScoreListView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
<LinearLayout
android:id="@+id/highScoreListLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="4dp"
android:orientation="vertical" />

<Button
android:id="@+id/hideHighScoreButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10sp"
android:onClick="hideHighScore"
android:focusableInTouchMode="true"
android:text="@string/hide_high_score_button_label" />
<TextView
android:id="@+id/noHighScoresTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textColor="#F0F0F0"
android:textSize="18sp"
android:paddingBottom="24dp"
android:text="@string/no_high_scores_message" />

</TableLayout>
<Button
android:id="@+id/hideHighScoreButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10sp"
android:onClick="hideHighScore"
android:focusableInTouchMode="true"
android:text="@string/hide_high_score_button_label" />

</TableLayout>

</FrameLayout>
</FrameLayout>

</LinearLayout>

0 comments on commit efe5e30

Please sign in to comment.