Created
January 25, 2018 13:52
-
-
Save thmsdnnr/8f21e17270939ba5f2da345b0d3180d7 to your computer and use it in GitHub Desktop.
Barista (Just Java) App from Udacity Android Class
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"?> | |
<LinearLayout 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" | |
android:background="@drawable/mybg" | |
android:paddingTop="16dp" | |
android:paddingLeft="16dp" | |
tools:context="com.example.android.justjava.MainActivity"> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginBottom="16dp" | |
android:padding="4dp" | |
android:textAllCaps="true" | |
android:id="@+id/quantity_label" | |
android:text="Quantity" /> | |
<LinearLayout | |
android:layout_width="120dp" | |
android:layout_height="wrap_content" | |
android:layout_marginBottom="16dp"> | |
<Button | |
android:id="@+id/decrease_qty" | |
android:layout_width="0dp" | |
android:layout_height="wrap_content" | |
android:layout_weight="1" | |
android:onClick="decrease" | |
android:text="-" | |
android:textColor="@color/colorAccent" | |
android:textSize="18sp" | |
android:textStyle="bold" | |
android:typeface="monospace" /> | |
<TextView | |
android:layout_width="0dp" | |
android:layout_weight="1" | |
android:layout_height="wrap_content" | |
android:textSize="16sp" | |
android:textColor="@color/colorTextHeader" | |
android:id="@+id/quantity_text_view" | |
android:textAlignment="center" | |
android:text="0" /> | |
<Button | |
android:id="@+id/increase_qty" | |
android:layout_width="0dp" | |
android:layout_height="wrap_content" | |
android:layout_weight="1" | |
android:fontFamily="monospace" | |
android:onClick="increase" | |
android:text="+" | |
android:textColor="@color/colorAccent" | |
android:textSize="18sp" | |
android:textStyle="bold" | |
android:typeface="monospace" /> | |
</LinearLayout> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginTop="16dp" | |
android:textAllCaps="true" | |
android:text="Price" /> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:textColor="@android:color/black" | |
android:layout_marginTop="16dp" | |
android:textSize="16sp" | |
android:id="@+id/price_text_view" | |
android:textAlignment="center" | |
android:text="$0" /> | |
<Button | |
android:layout_width="150dp" | |
android:layout_height="wrap_content" | |
android:id="@+id/order_button" | |
android:layout_marginTop="20dp" | |
android:textColor="@color/colorAccent" | |
android:text="Order" | |
android:onClick="submitOrder" /> | |
</LinearLayout> |
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="colorTextHeader">#000000</color> | |
<color name="colorPrimaryLight">#EFEBE9</color> | |
<color name="colorPrimary">#795548</color> | |
<color name="colorPrimaryDark">#3E2723</color> | |
<color name="colorAccent">#004D40</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.justjava; | |
import android.os.Bundle; | |
import android.support.v7.app.AppCompatActivity; | |
import android.view.View; | |
import android.widget.TextView; | |
import java.text.NumberFormat; | |
/** | |
* This app displays an order form to order coffee. | |
*/ | |
public class MainActivity extends AppCompatActivity { | |
int quantity=1; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
display(quantity); | |
} | |
public void increase(View view) { | |
quantity++; | |
display(quantity); | |
} | |
public void decrease(View view) { | |
quantity--; | |
quantity = quantity>=0 ? quantity : 0; | |
display(quantity); | |
} | |
public void submitOrder(View view) { | |
displayPrice(quantity * 5); | |
} | |
/** | |
* This method displays the given price value on the screen, formatted as a price. | |
*/ | |
private void displayPrice(int number) { | |
TextView priceTextView = (TextView) findViewById(R.id.price_text_view); | |
priceTextView.setText(NumberFormat.getCurrencyInstance().format(number)); | |
} | |
/** | |
* This method displays the given quantity value on the screen, formatted as a number. | |
*/ | |
private void display(int number) { | |
TextView quantityTextView = (TextView) findViewById(R.id.quantity_text_view); | |
quantityTextView.setText("" + number); | |
} | |
} |
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"?> | |
<bitmap | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
android:src="@drawable/cafe" | |
android:gravity="center" | |
android:alpha="0.3" | |
android:scaleType="centerCrop" | |
/> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment