Commit 5c013e66 authored by Shaun Burch's avatar Shaun Burch 💻

#7 Highlight Player Mark by Color

parent a4db1a9a
Pipeline #23090373 passed with stages
in 9 minutes and 4 seconds
...@@ -121,8 +121,21 @@ public class MainActivity extends AppCompatActivity implements AddPlayerDialog.A ...@@ -121,8 +121,21 @@ public class MainActivity extends AppCompatActivity implements AddPlayerDialog.A
} }
private void showPlayers() { private void showPlayers() {
mPlayerOne.setText(mPlayers.get(0).getName()); // Get players
mPlayerTwo.setText(mPlayers.get(1).getName()); Player player1 = mPlayers.get(0);
Player player2 = mPlayers.get(1);
// Set Names
mPlayerOne.setText(player1.getName());
mPlayerTwo.setText(player2.getName());
// Resolve Colors (Using deprecated method as min SDK is API 21)
int x = getResources().getColor(R.color.colorX);
int o = getResources().getColor(R.color.colorO);
// Set player name to color
mPlayerOne.setTextColor(player1.getMark() == Mark.X ? x : o);
mPlayerTwo.setTextColor(player2.getMark() == Mark.X ? x : o);
} }
@OnClick({R.id.cell_A1, R.id.cell_A2, R.id.cell_A3, @OnClick({R.id.cell_A1, R.id.cell_A2, R.id.cell_A3,
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
...@@ -16,6 +15,7 @@ ...@@ -16,6 +15,7 @@
<TextView <TextView
android:id="@+id/name_player_1" android:id="@+id/name_player_1"
style="@style/PlayerName"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="8dp" android:layout_marginBottom="8dp"
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
<TextView <TextView
android:id="@+id/name_player_2" android:id="@+id/name_player_2"
style="@style/PlayerName"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="8dp" android:layout_marginBottom="8dp"
......
...@@ -4,4 +4,7 @@ ...@@ -4,4 +4,7 @@
<color name="colorPrimaryDark">#ba000d</color> <color name="colorPrimaryDark">#ba000d</color>
<color name="colorAccent">#2196f3</color> <color name="colorAccent">#2196f3</color>
<color name="colorCell">#eceff1</color> <color name="colorCell">#eceff1</color>
<color name="colorX">@color/colorPrimary</color>
<color name="colorO">@color/colorAccent</color>
</resources> </resources>
...@@ -36,4 +36,8 @@ ...@@ -36,4 +36,8 @@
<item name="android:textAllCaps">true</item> <item name="android:textAllCaps">true</item>
</style> </style>
<style name="PlayerName">
<item name="android:textSize">18sp</item>
</style>
</resources> </resources>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment