Skip to content

Instantly share code, notes, and snippets.

@tokagecreative
Created January 20, 2018 19:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tokagecreative/707086057dc16239b855257f88f14684 to your computer and use it in GitHub Desktop.
Save tokagecreative/707086057dc16239b855257f88f14684 to your computer and use it in GitHub Desktop.
Football score app
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:background="@drawable/bg"
android:textColor="#FFFFFF"
tools:context="com.damirpolutranko.footballscore.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:paddingLeft="24dp"
android:paddingRight="24dp"
tools:context="com.example.android.courtcounter.MainActivity">
<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_horizontal"
android:padding="4dp"
android:text="HOME"
android:textColor="#FFFFFF"
android:textSize="14sp" />
<TextView
android:id="@+id/home_score"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="14dp"
android:fontFamily="sans-serif-light"
android:gravity="center_horizontal"
android:padding="4dp"
android:text="0"
android:textColor="#FFFFFF"
android:textSize="56sp" />
<Button
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_margin="4dp"
android:layout_marginBottom="4dp"
android:onClick="addTouchdownForHome"
android:text="touchdown"
android:textColor="#FFFFFF" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:layout_marginBottom="4dp"
android:layout_marginTop="4dp"
android:onClick="addExtraPointForHome"
android:text="Extra Point"
android:textColor="#FFFFFF" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:layout_marginTop="4dp"
android:onClick="addTwoPointForHome"
android:text="Two Point Conversion"
android:textColor="#FFFFFF" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:layout_marginTop="4dp"
android:onClick="addFieldGolForHome"
android:text="Field Gol"
android:textColor="#FFFFFF" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:layout_marginTop="4dp"
android:onClick="addSafetyForHome"
android:text="Safety"
android:textColor="#FFFFFF" />
</LinearLayout>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@android:color/darker_gray" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:paddingLeft="24dp"
android:paddingRight="24dp"
tools:context="com.example.android.courtcounter.MainActivity">
<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_horizontal"
android:padding="4dp"
android:text="AWAY"
android:textColor="#FFFFFF"
android:textSize="14sp" />
<TextView
android:id="@+id/away_score"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="14dp"
android:fontFamily="sans-serif-light"
android:gravity="center_horizontal"
android:padding="4dp"
android:text="0"
android:textColor="#FFFFFF"
android:textSize="56sp" />
<Button
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_margin="4dp"
android:layout_marginBottom="4dp"
android:onClick="addTouchdownForAway"
android:text="touchdown"
android:textColor="#FFFFFF" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:layout_marginBottom="4dp"
android:layout_marginTop="4dp"
android:onClick="addExtraPointForAway"
android:text="Extra Point"
android:textColor="#FFFFFF" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:layout_marginTop="4dp"
android:onClick="addTwoPointForAway"
android:text="Two Point Conversion"
android:textColor="#FFFFFF" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:layout_marginTop="4dp"
android:onClick="addFieldGolForAway"
android:text="Field Gol"
android:textColor="#FFFFFF" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:layout_marginTop="4dp"
android:onClick="addSafetyForAway"
android:text="Safety"
android:textColor="#FFFFFF" />
</LinearLayout>
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="80dp"
android:onClick="resetScore"
android:text="Reset"
android:textColor="#FFFFFF" />
</RelativeLayout>
package com.damirpolutranko.footballscore;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
int home_score = 0;
int away_score = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* Increase the score for Home by 6 points.
*/
public void addTouchdownForHome(View v) {
home_score = home_score + 6;
displayForHome(home_score);
}
/**
* Increase the score for Home by 1 point.
*/
public void addExtraPointForHome(View v) {
home_score = home_score + 1;
displayForHome(home_score);
}
/**
* Increase the score for Home by 2 points.
*/
public void addTwoPointForHome(View v) {
home_score = home_score + 2;
displayForHome(home_score);
}
/**
* Increase the score for Home by 3 points.
*/
public void addFieldGolForHome(View v) {
home_score = home_score + 3;
displayForHome(home_score);
}
/**
* Increase the score for Home by 2 points.
*/
public void addSafetyForHome(View v) {
home_score = home_score + 2;
displayForHome(home_score);
}
/**
* Increase the score for Away by 6 points.
*/
public void addTouchdownForAway(View v) {
away_score = away_score + 6;
displayForAway(away_score);
}
/**
* Increase the score for Away by 1 point.
*/
public void addExtraPointForAway(View v) {
away_score = away_score + 1;
displayForAway(away_score);
}
/**
* Increase the score for Away by 2 points.
*/
public void addTwoPointForAway(View v) {
away_score = away_score + 2;
displayForAway(away_score);
}
/**
* Increase the score for Away by 3 points.
*/
public void addFieldGolForAway(View v) {
away_score = away_score + 3;
displayForAway(away_score);
}
/**
* Increase the score for Away by 2 points.
*/
public void addSafetyForAway(View v) {
away_score = away_score + 2;
displayForAway(away_score);
}
/**
* Reset score to 0.
*/
public void resetScore(View v) {
home_score = 0;
away_score = 0;
displayForHome(home_score);
displayForAway(away_score);
}
/**
* Displays the given score for Home.
*/
public void displayForHome(int score) {
TextView scoreView = (TextView) findViewById(R.id.home_score);
scoreView.setText(String.valueOf(score));
}
/**
* Displays the given score for Away.
*/
public void displayForAway(int score) {
TextView scoreView = (TextView) findViewById(R.id.away_score);
scoreView.setText(String.valueOf(score));
}
}
<menu 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"
tools:context=".MainActivity">
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
app:showAsAction="never" />
</menu>
<resources>
<string name="app_name">Football Score</string>
<string name="action_settings">Settings</string>
</resources>
<resources>
<!-- Base application theme. -->
<!--<style name="AppTheme" parent="Theme.AppCompat.Light"> -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Primary theme color of the app (sets background color of app bar) -->
<item name="colorPrimary">#eeeeee</item>
<!-- Background color of buttons in the app -->
<item name="colorButtonNormal">#333333</item>
</style>
</resources>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment