Created
April 12, 2018 06:52
-
-
Save susanas/7d05a27653bc8ff02ab0fb7bee29d296 to your computer and use it in GitHub Desktop.
Project 2: Tennis ScoreKeeper App
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<android.support.constraint.ConstraintLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:orientation="vertical" | |
tools:context="com.example.android.scorekeeper.MainActivity"> | |
<!--/** 1st outer nested horizontal layout - top row **/--> | |
<android.support.v7.widget.LinearLayoutCompat | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_weight="1" | |
android:orientation="horizontal"> | |
<android.support.v7.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:orientation="vertical"> | |
<TextView | |
android:id="@+id/matchLabel" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginTop="8dp" | |
android:layout_weight="1" | |
android:fontFamily="sans-serif" | |
android:text="\[ Match - Game \]" | |
android:textAlignment="center" | |
android:textColor="#616161" | |
android:textSize="16sp" | |
android:textStyle="bold" /> | |
<TextView | |
android:id="@+id/gameNumber" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginTop="2dp" | |
android:layout_weight="1" | |
android:fontFamily="sans-serif" | |
android:text="\[ 0 - 0\ ]" | |
android:textAlignment="center" | |
android:textColor="#616161" | |
android:textSize="24sp" /> | |
</android.support.v7.widget.LinearLayoutCompat> | |
</android.support.v7.widget.LinearLayoutCompat> | |
<!--/** 2nd outer nested horizontal layout - mid column **/--> | |
<android.support.v7.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_weight="1" | |
android:orientation="horizontal"> | |
<!--/** Team A **/--> | |
<android.support.v7.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginTop="52dp" | |
android:layout_weight="1" | |
android:orientation="vertical"> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center" | |
android:fontFamily="sans-serif-medium" | |
android:padding="12dp" | |
android:text="Player A Score" | |
android:textColor="#616161" | |
android:textSize="14sp" | |
android:textStyle="bold" /> | |
<TextView | |
android:id="@+id/team_a_score" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center" | |
android:layout_marginBottom="24dp" | |
android:fontFamily="sans-serif-light" | |
android:padding="8dp" | |
android:text="0" | |
android:textColor="#000000" | |
android:textSize="56sp" /> | |
<Button | |
android:id="@+id/three_point_text_view" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center" | |
android:onClick="addFiftForTeamA" | |
android:paddingHorizontal="28dp" | |
android:text="15" /> | |
<Button | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center" | |
android:layout_marginVertical="8dp" | |
android:onClick="addThirtForTeamA" | |
android:paddingHorizontal="28dp" | |
android:text="30" /> | |
<Button | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center" | |
android:onClick="addFourForTeamA" | |
android:paddingHorizontal="28dp" | |
android:text="40" /> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center" | |
android:layout_marginBottom="1dp" | |
android:fontFamily="sans-serif-light" | |
android:padding="1dp" | |
android:text="@string/games_won" | |
android:textColor="#000000" | |
android:textSize="20sp" /> | |
<TextView | |
android:id="@+id/team_a_gameswon" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center" | |
android:layout_marginBottom="1dp" | |
android:fontFamily="sans-serif-light" | |
app:padding="1dp" | |
android:text="0" | |
android:textColor="#000000" | |
android:textSize="24sp" /> | |
</android.support.v7.widget.LinearLayoutCompat> | |
<!--/** Vertical Gray Line **/--> | |
<android.support.v7.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="wrap_content" | |
android:layout_height="match_parent" | |
android:layout_gravity="center" | |
android:layout_marginTop="42dp" | |
android:background="@android:color/darker_gray" | |
android:padding="1dp"> | |
</android.support.v7.widget.LinearLayoutCompat> | |
<!--/** Team B **/--> | |
<android.support.v7.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginTop="52dp" | |
android:layout_weight="1" | |
android:orientation="vertical"> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center" | |
android:fontFamily="sans-serif-medium" | |
android:padding="12dp" | |
android:text="Player B Score" | |
android:textColor="#616161" | |
android:textSize="14sp" | |
android:textStyle="bold" /> | |
<TextView | |
android:id="@+id/team_b_score" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center" | |
android:layout_marginBottom="24dp" | |
android:fontFamily="sans-serif-light" | |
android:padding="8dp" | |
android:text="0" | |
android:textColor="#000000" | |
android:textSize="56sp" /> | |
<Button | |
android:id="@+id/three_point_text_viewB" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center" | |
android:onClick="addFiftForTeamB" | |
android:paddingHorizontal="28dp" | |
android:text="15" /> | |
<Button | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center" | |
android:layout_marginVertical="8dp" | |
android:onClick="addThirtForTeamB" | |
android:paddingHorizontal="28dp" | |
android:text="30" /> | |
<Button | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center" | |
android:onClick="addFourForTeamB" | |
android:paddingHorizontal="28dp" | |
android:text="40" /> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center" | |
android:layout_marginBottom="1dp" | |
android:fontFamily="sans-serif-light" | |
android:padding="1dp" | |
android:text="@string/games_won" | |
android:textColor="#000000" | |
android:textSize="20sp" /> | |
<TextView | |
android:id="@+id/team_b_gameswon" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center" | |
android:layout_marginBottom="1dp" | |
android:fontFamily="sans-serif-light" | |
android:padding="1dp" | |
android:text="0" | |
android:textColor="#000000" | |
android:textSize="24sp" /> | |
</android.support.v7.widget.LinearLayoutCompat> | |
</android.support.v7.widget.LinearLayoutCompat> | |
<!--/** 3rd outer nested horizontal layout - bottom row **/--> | |
<Button | |
android:id="@+id/tTop" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginBottom="24dp" | |
android:onClick="resetBothScores" | |
android:text="Reset Game" | |
app:layout_constraintBottom_toBottomOf="parent" | |
app:layout_constraintLeft_toLeftOf="parent" | |
app:layout_constraintRight_toRightOf="parent" /> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center" | |
android:layout_marginBottom="5dp" | |
android:fontFamily="sans-serif-light" | |
android:padding="1dp" | |
android:text="* 1 match = 6 games" | |
android:textColor="#000000" | |
android:textSize="14sp" | |
android:textStyle="italic" | |
app:layout_constraintLeft_toLeftOf="parent" | |
app:layout_constraintRight_toRightOf="parent" | |
app:layout_constraintTop_toBottomOf="@+id/tTop" | |
tools:ignore="UnusedAttribute" /> | |
</android.support.constraint.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<resources> | |
<color name="colorPrimary">#3F51B5</color> | |
<color name="colorPrimaryDark">#303F9F</color> | |
<color name="colorAccent">#FF4081</color> | |
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.android.scorekeeper; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.TextView; | |
import static java.lang.String.*; | |
public class MainActivity extends AppCompatActivity { | |
int scoreA = 0; | |
int scoreB = 0; | |
int numGameWonA = 0; | |
int numGameWonB = 0; | |
int numOfGame = 0; | |
int numOfMatch = 0; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
} | |
// /** | |
// * Displays the score for tennis player A. | |
// **/ | |
public void displayForTeamA(int scoreA) { | |
TextView scoreView = (TextView) findViewById(R.id.team_a_score); | |
scoreView.setText(valueOf(scoreA)); | |
} | |
// /** | |
// * Displays the score for tennis player B. | |
// **/ | |
public void displayForTeamB(int scoreB) { | |
TextView scoreView = (TextView) findViewById(R.id.team_b_score); | |
scoreView.setText(valueOf(scoreB)); | |
} | |
// /** | |
// * Displays number of games won by tennis player A. | |
// **/ | |
public void displayGamesWonForTeamA(int numGameWonA) { | |
TextView scoreView = (TextView) findViewById(R.id.team_a_gameswon); | |
scoreView.setText(valueOf(numGameWonA)); | |
} | |
// /** | |
// * Displays number of games won tennis player B. | |
// **/ | |
public void displayGamesWonForTeamB(int numGameWonB) { | |
TextView scoreView = (TextView) findViewById(R.id.team_b_gameswon); | |
scoreView.setText(valueOf(numGameWonB)); | |
} | |
// /** | |
// * Displays total number of tennis games played. | |
// **/ | |
public void displayForNumGame(int numOfGame) { | |
TextView scoreView = (TextView) findViewById(R.id.gameNumber); | |
scoreView.setText(valueOf(valueOf(numOfGame))); | |
} | |
// /** | |
// * Displays total number of tennis matches played. 1 tennis match has 6 games. | |
// */ | |
public void displayMatchGame(int numOfMatch, int numOfGame) { | |
TextView scoreView = (TextView) findViewById(R.id.gameNumber); | |
scoreView.setText("[ " + valueOf(numOfMatch) + " - " + valueOf(numOfGame) + " ]"); | |
} | |
// /** | |
// * Displays score for player A. At 40 points, calculates number of games and matches. | |
// **/ | |
public void addFiftForTeamA(View view) { | |
scoreA = 15; | |
displayForTeamA(scoreA); | |
} | |
public void addThirtForTeamA(View view) { | |
scoreA = 30; | |
displayForTeamA(scoreA); | |
} | |
public void addFourForTeamA(View view) { | |
scoreA = 40; | |
numOfGame = numOfGame + 1; | |
numGameWonA = numGameWonA + 1; | |
displayForTeamA(scoreA); | |
displayGamesWonForTeamA(numGameWonA); | |
if (numOfGame <= 6) { | |
displayMatchGame(numOfMatch, numOfGame); | |
} else { | |
numOfGame = 0; | |
numOfMatch = numOfMatch + 1; | |
displayMatchGame(numOfMatch, numOfGame); | |
} | |
} | |
// /** | |
// * Displays score for player B. At 40 points, calculates number of games and matches. | |
// **/ | |
public void addFiftForTeamB(View view) { | |
scoreB = 15; | |
displayForTeamB(scoreB); | |
} | |
public void addThirtForTeamB(View view) { | |
scoreB = 30; | |
displayForTeamB(scoreB); | |
} | |
public void addFourForTeamB(View view) { | |
scoreB = 40; | |
numOfGame = numOfGame + 1; | |
numGameWonB = numGameWonB + 1; | |
displayForTeamB(scoreB); | |
displayGamesWonForTeamB(numGameWonB); | |
if (numOfGame <= 6) { | |
displayMatchGame(numOfMatch, numOfGame); | |
} else { | |
numOfGame = 0; | |
numOfMatch = numOfMatch + 1; | |
displayMatchGame(numOfMatch, numOfGame); | |
} | |
} | |
// /** | |
// * Resets game score for each player. | |
// **/ | |
public void resetBothScores(View view) { | |
scoreA = 0; | |
scoreB = 0; | |
displayForTeamA(scoreA); | |
displayForTeamB(scoreB); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<resources> | |
<string name="app_name">Score Keeper - Tennis</string> | |
<string name="games_won">Games won:</string> | |
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<resources> | |
<style name="AppTheme" parent="Theme.AppCompat.Light"> | |
<!-- Primary theme color of the app (sets background color of app bar) --> | |
<item name="colorPrimary">#FF969E</item> | |
<!-- Background color of buttons in the app --> | |
<item name="colorButtonNormal">#FF969E</item> | |
</style> | |
</resources> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment