Created
January 26, 2018 09:42
-
-
Save JamieBe/073c3f898a0bf929fe20c1eb0f13e17b to your computer and use it in GitHub Desktop.
CourtCounter
This file contains hidden or 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" | |
tools:context="com.example.behnj.courtcounter.MainActivity"> | |
<RelativeLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:background="#1497d4"> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content"> | |
<LinearLayout | |
android:layout_width="0dp" | |
android:layout_height="wrap_content" | |
android:layout_weight="1" | |
android:orientation="vertical"> | |
<TextView | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginBottom="16dp" | |
android:layout_marginTop="16dp" | |
android:fontFamily="sans-serif-medium" | |
android:gravity="center" | |
android:text="Team A" | |
android:textColor="#ffffff" | |
android:textSize="18sp" /> | |
<TextView | |
android:id="@+id/team_a_score" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center" | |
android:layout_marginBottom="12dp" | |
android:background="#000000" | |
android:fontFamily="sans-serif" | |
android:gravity="center" | |
android:padding="4dp" | |
android:text="0" | |
android:textColor="#ff0000" | |
android:textSize="30sp" /> | |
<TextView | |
android:id="@+id/team_a_foul" | |
android:layout_width="wrap_content" | |
android:layout_height="match_parent" | |
android:layout_gravity="center" | |
android:layout_marginBottom="12dp" | |
android:background="#000000" | |
android:fontFamily="sans-serif" | |
android:gravity="center" | |
android:padding="4dp" | |
android:text="0" | |
android:textColor="#ff0000" | |
android:textSize="20sp" /> | |
<Button | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginBottom="8dp" | |
android:layout_marginLeft="24dp" | |
android:layout_marginRight="24dp" | |
android:onClick="addThreeForTeamA" | |
android:text="+3 Punkte" /> | |
<Button | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginBottom="8dp" | |
android:layout_marginLeft="24dp" | |
android:layout_marginRight="24dp" | |
android:onClick="addTwoForTeamA" | |
android:text="+2 Punkte" /> | |
<Button | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginBottom="8dp" | |
android:layout_marginLeft="24dp" | |
android:layout_marginRight="24dp" | |
android:onClick="addOneForTeamA" | |
android:text="Freiwurf" /> | |
<Button | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginBottom="10dp" | |
android:layout_marginLeft="50dp" | |
android:layout_marginRight="50dp" | |
android:background="#FF9800" | |
android:onClick="FoulForA" | |
android:text="Foul" /> | |
</LinearLayout> | |
<LinearLayout | |
android:layout_width="0dp" | |
android:layout_height="wrap_content" | |
android:layout_weight="1" | |
android:orientation="vertical"> | |
<TextView | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginBottom="16dp" | |
android:layout_marginTop="16dp" | |
android:fontFamily="sans-serif-medium" | |
android:gravity="center" | |
android:text="Team B" | |
android:textColor="#ffffff" | |
android:textSize="18sp" /> | |
<TextView | |
android:id="@+id/team_b_score" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center" | |
android:layout_marginBottom="12dp" | |
android:background="#000000" | |
android:fontFamily="sans-serif" | |
android:padding="4dp" | |
android:text="0" | |
android:textColor="#ff0000" | |
android:textSize="30sp"/> | |
<TextView | |
android:id="@+id/team_b_foul" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center" | |
android:layout_marginBottom="12dp" | |
android:background="#000000" | |
android:fontFamily="sans-serif" | |
android:padding="4dp" | |
android:text="0" | |
android:textColor="#ff0000" | |
android:textSize="20sp" /> | |
<Button | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginBottom="8dp" | |
android:layout_marginLeft="24dp" | |
android:layout_marginRight="24dp" | |
android:onClick="addThreeForTeamB" | |
android:text="+3 Punkte" /> | |
<Button | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginBottom="8dp" | |
android:layout_marginLeft="24dp" | |
android:layout_marginRight="24dp" | |
android:onClick="addTwoForTeamB" | |
android:text="+2 Punkte" /> | |
<Button | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginBottom="8dp" | |
android:layout_marginLeft="24dp" | |
android:layout_marginRight="24dp" | |
android:onClick="addOneForTeamB" | |
android:text="Freiwurf" /> | |
<Button | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginBottom="10dp" | |
android:layout_marginLeft="50dp" | |
android:layout_marginRight="50dp" | |
android:background="#FF9800" | |
android:onClick="FoulForB" | |
android:text="Foul" /> | |
</LinearLayout> | |
</LinearLayout> | |
<Button | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_alignParentBottom="true" | |
android:layout_centerHorizontal="true" | |
android:onClick="ScoreReset" | |
android:text="Reset" | |
tools:layout_editor_absoluteX="148dp" | |
tools:layout_editor_absoluteY="0dp" /> | |
</RelativeLayout> | |
</android.support.constraint.ConstraintLayout> |
This file contains hidden or 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.behnj.courtcounter; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.TextView; | |
public class MainActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
} | |
int scoreTeamA = 0; | |
int scoreTeamB = 0; | |
int foulA = 0; | |
int foulB = 0; | |
/** | |
* Increase the score for Team A by 1 point. | |
*/ | |
public void addOneForTeamA(View v) { | |
scoreTeamA = scoreTeamA + 1; | |
displayForTeamA(scoreTeamA) | |
; | |
} | |
/** | |
* Increase the score for Team A by 2 points. | |
*/ | |
public void addTwoForTeamA(View v) { | |
scoreTeamA = scoreTeamA + 2; | |
displayForTeamA(scoreTeamA); | |
} | |
/** | |
* Increase the score for Team A by 3 points. | |
*/ | |
public void addThreeForTeamA(View v) { | |
scoreTeamA = scoreTeamA + 3; | |
displayForTeamA(scoreTeamA); | |
} | |
/** | |
* Displays the given score for Team A. | |
*/ | |
public void displayForTeamA(int score) { | |
TextView scoreView = (TextView) findViewById(R.id.team_a_score); | |
scoreView.setText(String.valueOf(score)); | |
} | |
/** | |
* Increase the score for Team B by 1 point. | |
*/ | |
public void addOneForTeamB(View v) { | |
scoreTeamB = scoreTeamB + 1; | |
displayForTeamB(scoreTeamB) | |
; | |
} | |
/** | |
* Increase the score for Team B by 2 points. | |
*/ | |
public void addTwoForTeamB(View v) { | |
scoreTeamB = scoreTeamB + 2; | |
displayForTeamB(scoreTeamB); | |
} | |
/** | |
* Increase the score for Team B by 3 points. | |
*/ | |
public void addThreeForTeamB(View v) { | |
scoreTeamB = scoreTeamB + 3; | |
displayForTeamB(scoreTeamB); | |
} | |
/** | |
* Displays the given score for Team B. | |
*/ | |
public void displayForTeamB(int score) { | |
TextView scoreView = (TextView) findViewById(R.id.team_b_score); | |
scoreView.setText(String.valueOf(score)); | |
} | |
/** | |
* Resets the points for both teams | |
*/ | |
public void ScoreReset(View v) { | |
scoreTeamB = 0; | |
scoreTeamA = 0; | |
foulB = 0; | |
foulA = 0; | |
displayForTeamAFouls(foulA); | |
displayForTeamBFouls(foulB); | |
displayForTeamB(scoreTeamB); | |
displayForTeamA(scoreTeamA); | |
} | |
/** | |
* Add one faul to the team A | |
*/ | |
public void FoulForA(View v) { | |
foulA = foulA + 1; | |
displayForTeamAFouls(foulA); | |
} | |
/** | |
* Displays the given fauls for team A | |
*/ | |
public void displayForTeamAFouls(int score) { | |
TextView scoreView = (TextView) findViewById(R.id.team_a_foul); | |
scoreView.setText(String.valueOf(score)); | |
} | |
/** | |
* Add one faul to the team B | |
*/ | |
public void FoulForB(View v) { | |
foulB = foulB + 1; | |
displayForTeamBFouls(foulB); | |
} | |
/** | |
* Displays the given fauls for team B | |
*/ | |
public void displayForTeamBFouls(int score) { | |
TextView scoreView = (TextView) findViewById(R.id.team_b_foul); | |
scoreView.setText(String.valueOf(score)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment