Skip to content

Instantly share code, notes, and snippets.

@TheMatten
Created November 19, 2017 14:22
Show Gist options
  • Save TheMatten/de18c6f643c48a551496c7c8dab17e2b to your computer and use it in GitHub Desktop.
Save TheMatten/de18c6f643c48a551496c7c8dab17e2b to your computer and use it in GitHub Desktop.
ScoreKeeper - minimal soccer score counting app
<?xml version="1.0" encoding="utf-8"?>
<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="@color/colorPrimary"
tools:context=".MainActivity">
<TextView
android:id="@+id/app_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:fontFamily="sans-serif-medium"
android:padding="16dp"
android:text="ScoreKeeper"
android:textColor="@android:color/white"
android:textSize="20sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/app_title"
android:baselineAligned="false"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-medium"
android:gravity="center_horizontal"
android:paddingBottom="16dp"
android:text="Team A"
android:textColor="@android:color/white"
android:textSize="24sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-condensed"
android:gravity="center_horizontal"
android:text="Goals"
android:textAllCaps="true"
android:textColor="@android:color/white"
android:textStyle="bold" />
<TextView
android:id="@+id/goal_count_a"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:gravity="center_horizontal"
android:includeFontPadding="false"
android:text="0"
android:textColor="@android:color/white"
android:textSize="80sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-condensed"
android:gravity="center_horizontal"
android:text="Fouls"
android:textAllCaps="true"
android:textColor="@android:color/white"
android:textStyle="bold" />
<TextView
android:id="@+id/foul_count_a"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:gravity="center_horizontal"
android:text="0"
android:textColor="@android:color/white"
android:textSize="56sp" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="@color/colorPrimaryDark"
android:onClick="onGoalA"
android:text="+ Goal" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="@color/colorPrimaryDark"
android:onClick="onFoulA"
android:text="+ Foul" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-medium"
android:gravity="center_horizontal"
android:paddingBottom="16dp"
android:text="Team B"
android:textColor="@android:color/white"
android:textSize="24sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-condensed"
android:gravity="center_horizontal"
android:text="Goals"
android:textAllCaps="true"
android:textColor="@android:color/white"
android:textStyle="bold" />
<TextView
android:id="@+id/goal_count_b"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:gravity="center_horizontal"
android:includeFontPadding="false"
android:text="0"
android:textColor="@android:color/white"
android:textSize="80sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-condensed"
android:gravity="center_horizontal"
android:text="Fouls"
android:textAllCaps="true"
android:textColor="@android:color/white"
android:textStyle="bold" />
<TextView
android:id="@+id/foul_count_b"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:gravity="center_horizontal"
android:text="0"
android:textColor="@android:color/white"
android:textSize="56sp" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="@color/colorPrimaryDark"
android:onClick="onGoalB"
android:text="+ Goal" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="@color/colorPrimaryDark"
android:onClick="onFoulB"
android:text="+ Foul" />
</LinearLayout>
</LinearLayout>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="16dp"
android:backgroundTint="@color/colorPrimaryDark"
android:onClick="onReset"
android:text="Reset" />
</RelativeLayout>
package com.example.android.scorekeeper;
import android.support.constraint.solver.Goal;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
int goalCountA, foulCountA, goalCountB, foulCountB = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onGoalA(View view) {
goalCountA++;
displayGoalCountA(goalCountA);
}
public void onFoulA(View view) {
foulCountA++;
displayFoulCountA(foulCountA);
}
public void onGoalB(View view) {
goalCountB++;
displayGoalCountB(goalCountB);
}
public void onFoulB(View view) {
foulCountB++;
displayFoulCountB(foulCountB);
}
public void onReset(View view) {
goalCountA = 0;
foulCountA = 0;
goalCountB = 0;
foulCountB = 0;
displayGoalCountA(goalCountA);
displayFoulCountA(foulCountA);
displayGoalCountB(goalCountB);
displayFoulCountB(foulCountB);
}
public void displayGoalCountA(int count) {
TextView countView = (TextView) findViewById(R.id.goal_count_a);
countView.setText(String.valueOf(count));
}
public void displayFoulCountA(int count) {
TextView countView = (TextView) findViewById(R.id.foul_count_a);
countView.setText(String.valueOf(count));
}
public void displayGoalCountB(int count) {
TextView countView = (TextView) findViewById(R.id.goal_count_b);
countView.setText(String.valueOf(count));
}
public void displayFoulCountB(int count) {
TextView countView = (TextView) findViewById(R.id.foul_count_b);
countView.setText(String.valueOf(count));
}
}
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@android:color/holo_green_dark</item>
<item name="android:navigationBarColor">@color/colorPrimaryDark</item>
</style>
</resources>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment