Last active
January 8, 2018 10:55
-
-
Save evanca/059831b19ce2cc426c51016d80dd214e to your computer and use it in GitHub Desktop.
Google Developer Challenge Scholarship - Android Basics / Court Counter
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"?> | |
<LinearLayout 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="#F5F5F6" | |
android:gravity="center" | |
android:orientation="vertical"> | |
<LinearLayout | |
android:id="@+id/main_linear" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:orientation="horizontal" | |
tools:context=".MainActivity"> | |
<LinearLayout | |
android:layout_width="0dp" | |
android:layout_height="wrap_content" | |
android:layout_weight="1" | |
android:orientation="vertical" | |
android:paddingEnd="@dimen/large_padding" | |
android:paddingStart="@dimen/large_padding"> | |
<TextView | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginTop="@dimen/normal_margin" | |
android:fontFamily="sans-serif" | |
android:gravity="center_horizontal" | |
android:text="@string/water" | |
android:textAllCaps="true" | |
android:textColor="#616161" | |
android:textSize="@dimen/title_text" /> | |
<ImageView | |
android:layout_width="wrap_content" | |
android:layout_height="@dimen/icon_height" | |
android:layout_marginTop="@dimen/normal_margin" | |
android:src="@drawable/water"></ImageView> | |
<TextView | |
android:id="@+id/water_score" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:fontFamily="sans-serif-light" | |
android:gravity="center_horizontal" | |
android:text="@string/zero_ml" | |
android:textColor="#000000" | |
android:textSize="@dimen/maxi_text" /> | |
<Button | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginBottom="@dimen/mini_margin" | |
android:layout_marginEnd="@dimen/small_margin" | |
android:layout_marginStart="@dimen/small_margin" | |
android:layout_marginTop="@dimen/top_button_margin" | |
android:fontFamily="sans-serif" | |
android:onClick="plus250mlWater" | |
android:text="@string/s250ml" | |
android:textColor="#ffffff" | |
android:textSize="@dimen/normal_text" /> | |
<Button | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginBottom="@dimen/mini_margin" | |
android:layout_marginEnd="@dimen/small_margin" | |
android:layout_marginStart="@dimen/small_margin" | |
android:fontFamily="sans-serif" | |
android:onClick="plus350mlWater" | |
android:text="@string/s350ml" | |
android:textColor="#ffffff" | |
android:textSize="@dimen/normal_text" /> | |
<Button | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginBottom="@dimen/mini_margin" | |
android:layout_marginEnd="@dimen/small_margin" | |
android:layout_marginStart="@dimen/small_margin" | |
android:fontFamily="sans-serif" | |
android:onClick="plus500mlWater" | |
android:text="@string/s500ml" | |
android:textColor="#ffffff" | |
android:textSize="@dimen/normal_text" /> | |
</LinearLayout> | |
<View | |
android:layout_width="1dp" | |
android:layout_height="match_parent" | |
android:layout_marginTop="@dimen/normal_margin" | |
android:background="@android:color/darker_gray" /> | |
<LinearLayout | |
android:layout_width="0dp" | |
android:layout_height="wrap_content" | |
android:layout_weight="1" | |
android:orientation="vertical" | |
android:paddingEnd="@dimen/large_padding" | |
android:paddingStart="@dimen/large_padding"> | |
<TextView | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginTop="@dimen/normal_margin" | |
android:fontFamily="sans-serif" | |
android:gravity="center_horizontal" | |
android:text="@string/beverages" | |
android:textAllCaps="true" | |
android:textColor="#616161" | |
android:textSize="@dimen/title_text" /> | |
<ImageView | |
android:layout_width="wrap_content" | |
android:layout_height="@dimen/icon_height" | |
android:layout_marginTop="@dimen/normal_margin" | |
android:src="@drawable/juice"></ImageView> | |
<TextView | |
android:id="@+id/juice_score" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:fontFamily="sans-serif-light" | |
android:gravity="center_horizontal" | |
android:text="@string/zero_ml" | |
android:textColor="#000000" | |
android:textSize="@dimen/maxi_text" /> | |
<Button | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginBottom="@dimen/mini_margin" | |
android:layout_marginEnd="@dimen/small_margin" | |
android:layout_marginStart="@dimen/small_margin" | |
android:layout_marginTop="@dimen/top_button_margin" | |
android:fontFamily="sans-serif" | |
android:onClick="plus250mlJuice" | |
android:text="@string/s250ml" | |
android:textColor="#ffffff" | |
android:textSize="@dimen/normal_text" /> | |
<Button | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginBottom="@dimen/mini_margin" | |
android:layout_marginEnd="@dimen/small_margin" | |
android:layout_marginStart="@dimen/small_margin" | |
android:fontFamily="sans-serif" | |
android:onClick="plus350mlJuice" | |
android:text="@string/s350ml" | |
android:textColor="#ffffff" | |
android:textSize="@dimen/normal_text" /> | |
<Button | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginBottom="@dimen/mini_margin" | |
android:layout_marginEnd="@dimen/small_margin" | |
android:layout_marginStart="@dimen/small_margin" | |
android:fontFamily="sans-serif" | |
android:onClick="plus500mlJuice" | |
android:text="@string/s500ml" | |
android:textColor="#ffffff" | |
android:textSize="@dimen/normal_text" /> | |
</LinearLayout> | |
</LinearLayout> | |
<TextView | |
android:id="@+id/goal" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center_horizontal" | |
android:layout_marginBottom="@dimen/large_margin" | |
android:layout_marginEnd="@dimen/maxi_margin" | |
android:layout_marginStart="@dimen/maxi_margin" | |
android:layout_marginTop="@dimen/large_margin" | |
android:onClick="resetBoth" | |
android:text="@string/infobox" | |
android:textSize="@dimen/infobox_text" /> | |
<Button | |
android:id="@+id/reset_button" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center_horizontal" | |
android:layout_marginBottom="@dimen/small_margin" | |
android:background="#FF7C80" | |
android:fontFamily="sans-serif" | |
android:onClick="resetBoth" | |
android:text="@string/reset" | |
android:textColor="#ffffff" | |
android:textSize="@dimen/normal_text" /> | |
</LinearLayout> |
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.android.courtcounter; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.TextView; | |
public class MainActivity extends AppCompatActivity { | |
/** | |
* HERE Create The GLOBAL Variable | |
*/ | |
int scoreWater = 0; | |
int scoreJuice = 0; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
displayForWater(0); | |
} | |
/** | |
* Displays the given score for Team A. | |
*/ | |
public void displayForWater(int score) { | |
TextView scoreView = (TextView) findViewById(R.id.water_score); | |
scoreView.setText(String.valueOf(score) + " ml"); | |
} | |
public void plus250mlWater(View v) { | |
scoreWater = scoreWater + 250; | |
displayForWater(scoreWater); | |
} | |
public void plus350mlWater(View v) { | |
scoreWater = scoreWater + 350; | |
displayForWater(scoreWater); | |
} | |
public void plus500mlWater(View v) { | |
scoreWater = scoreWater + 500; | |
displayForWater(scoreWater); | |
} | |
/** | |
* Displays the given score for Team B. | |
*/ | |
public void displayForJuice(int score) { | |
TextView scoreView = (TextView) findViewById(R.id.juice_score); | |
scoreView.setText(String.valueOf(score) + " ml"); | |
} | |
public void plus250mlJuice(View v) { | |
scoreJuice = scoreJuice + 250; | |
displayForJuice(scoreJuice); | |
} | |
public void plus350mlJuice(View v) { | |
scoreJuice = scoreJuice + 350; | |
displayForJuice(scoreJuice); | |
} | |
public void plus500mlJuice(View v) { | |
scoreJuice = scoreJuice + 500; | |
displayForJuice(scoreJuice); | |
} | |
// RESET button: | |
public void resetBoth(View v) { | |
scoreJuice = 0; | |
scoreWater = 0; | |
displayForJuice(scoreJuice); | |
displayForWater(scoreWater); | |
} | |
} |
Author
evanca
commented
Jan 8, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment