Created
October 19, 2015 03:59
-
-
Save devinceble/70c5a73b47f7e619f1ef to your computer and use it in GitHub Desktop.
MainActivity
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:orientation="vertical" | |
tools:context=".MainActivity"> | |
<ScrollView | |
android:id="@+id/svMain" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
//Content | |
<RelativeLayout | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<ImageView | |
android:src="@drawable/bgcoffee" | |
android:scaleType="centerCrop" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" /> | |
//Main Content | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:orientation="vertical" | |
android:paddingLeft="@dimen/activity_horizontal_margin" | |
android:paddingRight="@dimen/activity_horizontal_margin" | |
android:paddingTop="@dimen/activity_vertical_margin" | |
android:paddingBottom="@dimen/activity_vertical_margin"> | |
//Customer Name | |
<EditText | |
android:id="@+id/txtCustomerName" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:hint="Customer Name" | |
android:inputType="textMultiLine" | |
android:textSize="24sp"/> | |
//Type of Order | |
<RadioGroup | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:orientation="horizontal" | |
android:layout_margin="16dp" | |
> | |
<RadioButton | |
android:id="@+id/rbCoffeeBlack" | |
android:layout_width="0dp" | |
android:layout_weight="1" | |
android:layout_height="wrap_content" | |
android:text="Black - P10" | |
android:textSize="24sp" | |
android:textAppearance="?android:textAppearanceMedium" | |
android:onClick="OrderCoffee"/> | |
<RadioButton | |
android:id="@+id/rbCoffeeCreamy" | |
android:layout_width="0dp" | |
android:layout_weight="1" | |
android:layout_height="wrap_content" | |
android:text="Creamy-P15" | |
android:textSize="24sp" | |
android:textAppearance="?android:textAppearanceMedium" | |
android:onClick="OrderCoffee"/> | |
</RadioGroup> | |
//Label Addons | |
<TextView | |
android:text="Add-on's P5:" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:textSize="24sp" | |
android:layout_marginBottom="16dp"/> | |
//Addons | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:orientation="horizontal" | |
android:layout_marginBottom="16dp"> | |
<CheckBox | |
android:id="@+id/cbAddonChoco" | |
android:layout_width="0dp" | |
android:layout_weight="1" | |
android:layout_height="wrap_content" | |
android:text="Chocolate" | |
android:textSize="24sp" | |
android:onClick="PlusAddon" | |
/> | |
<CheckBox | |
android:id="@+id/cbAddonCream" | |
android:layout_width="0dp" | |
android:layout_weight="1" | |
android:layout_height="wrap_content" | |
android:text="Cream" | |
android:textSize="24sp" | |
android:onClick="PlusAddon" | |
/> | |
</LinearLayout> | |
//Number of Orders | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:orientation="horizontal" | |
android:layout_marginBottom="16dp"> | |
<Button | |
android:id="@+id/btnDecOrder" | |
android:layout_width="0dp" | |
android:layout_weight="1" | |
android:layout_height="wrap_content" | |
android:text="-" | |
android:textSize="26sp" | |
android:onClick="DecOrder" | |
android:background="@color/colorPrimary"/> | |
<TextView | |
android:id="@+id/txtNumberOfOrders" | |
android:text="1" | |
android:layout_width="0dp" | |
android:layout_weight="1" | |
android:layout_height="wrap_content" | |
android:textSize="27sp" | |
android:layout_marginBottom="16dp" | |
android:textAlignment="center" | |
android:textStyle="bold" | |
/> | |
<Button | |
android:id="@+id/btnIncOrder" | |
android:layout_width="0dp" | |
android:layout_weight="1" | |
android:layout_height="wrap_content" | |
android:text="+" | |
android:textSize="26sp" | |
android:onClick="IncOrder" | |
android:background="@color/colorPrimary"/> | |
</LinearLayout> | |
//Total Price | |
<TextView | |
android:id="@+id/txtVPrice" | |
android:text="Total Price:" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:textSize="26sp" | |
android:layout_marginBottom="16dp" | |
android:textStyle="bold" | |
/> | |
//Order Slip | |
<LinearLayout | |
android:id="@+id/llOrderSlip" | |
android:layout_width="match_parent" | |
android:layout_height="0dp" | |
android:orientation="vertical" | |
> | |
<View | |
android:layout_width="match_parent" | |
android:layout_height="1dp" | |
android:background="#000"/> | |
<TextView | |
android:id="@+id/txtVCustomerName" | |
android:text="Name:" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:textSize="24sp" | |
android:layout_marginBottom="16dp" | |
android:textStyle="bold" | |
/> | |
<TextView | |
android:id="@+id/txtVCustomerOrder" | |
android:text="Order:" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:textSize="24sp" | |
android:layout_marginBottom="16dp" | |
android:textStyle="bold" | |
/> | |
<TextView | |
android:id="@+id/txtVCustomerAddons" | |
android:text="Addon's:" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:textSize="24sp" | |
android:layout_marginBottom="16dp" | |
android:textStyle="bold" | |
/> | |
<TextView | |
android:id="@+id/txtGrandPrice" | |
android:text="Total Price: " | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:textSize="24sp" | |
android:layout_marginBottom="16dp" | |
android:textStyle="bold" | |
/> | |
<View | |
android:layout_width="match_parent" | |
android:layout_height="1dp" | |
android:background="#000"/> | |
</LinearLayout> | |
<Button | |
android:id="@+id/btnOrderNow" | |
android:text="Order" | |
android:layout_width="match_parent" | |
android:layout_height="80dp" | |
android:onClick="OrderNow" | |
android:textSize="26sp" | |
android:background="@color/colorPrimaryDark"/> | |
</LinearLayout> | |
</RelativeLayout> | |
</ScrollView> | |
</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 io.github.devinceble.ordertaker; | |
import android.app.ActionBar; | |
import android.content.Intent; | |
import android.net.Uri; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.Button; | |
import android.widget.CheckBox; | |
import android.widget.EditText; | |
import android.widget.LinearLayout; | |
import android.widget.RadioButton; | |
import android.widget.ScrollView; | |
import android.widget.TextView; | |
public class MainActivity extends AppCompatActivity { | |
boolean orderStat = true; | |
int PriceBlack = 10; | |
int PriceCreamy = 15; | |
int PriceAddons = 5; | |
int NumberOfAddons = 0; | |
int NumberOfOrders = 1; | |
int TotalOrderPrice = 0; | |
int GrandTotal = 0; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
} | |
public void PlusAddon(View view){ | |
int LocalTotalPrice = 0; | |
TextView txtVPrice = (TextView) findViewById(R.id.txtVPrice); | |
CheckBox thisCheck = (CheckBox) view; | |
CheckBox cbChocolate = (CheckBox) findViewById(R.id.cbAddonChoco); | |
CheckBox cbCream = (CheckBox) findViewById(R.id.cbAddonCream); | |
if(thisCheck.getId() == R.id.cbAddonChoco) { | |
if (cbChocolate.isChecked()) { | |
NumberOfAddons += 1; | |
} else { | |
NumberOfAddons -= 1; | |
} | |
}else { | |
if (cbCream.isChecked()) { | |
NumberOfAddons += 1; | |
} else { | |
NumberOfAddons -= 1; | |
} | |
} | |
LocalTotalPrice = (TotalOrderPrice + (NumberOfAddons) * PriceAddons) * NumberOfOrders; | |
GrandTotal = LocalTotalPrice; | |
txtVPrice.setText("Total Price: P " + LocalTotalPrice); | |
} | |
public void OrderCoffee(View view){ | |
int LocalTotalPrice; | |
RadioButton thisRadio = (RadioButton) view; | |
TextView txtVPrice = (TextView) findViewById(R.id.txtVPrice); | |
TextView txtOrder = (TextView) findViewById(R.id.txtVCustomerOrder); | |
if(thisRadio.getId() == R.id.rbCoffeeBlack){ | |
TotalOrderPrice = PriceBlack; | |
txtOrder.setText("Order: Black"); | |
}else{ | |
TotalOrderPrice = PriceCreamy; | |
txtOrder.setText("Order: Creamy"); | |
} | |
LocalTotalPrice = (TotalOrderPrice + (NumberOfAddons) * PriceAddons) * NumberOfOrders; | |
GrandTotal = LocalTotalPrice; | |
txtVPrice.setText("Total Price: P " + LocalTotalPrice); | |
} | |
public void DecOrder(View view){ | |
ChangeNumberOrders(false); | |
} | |
public void IncOrder(View view){ | |
ChangeNumberOrders(true); | |
} | |
private void ChangeNumberOrders(boolean stat) { | |
int LocalTotalPrice, LocalPriceAddon; | |
TextView txtNumberOfOrders = (TextView) findViewById(R.id.txtNumberOfOrders); | |
TextView txtVPrice = (TextView) findViewById(R.id.txtVPrice); | |
if(stat){ | |
NumberOfOrders += 1; | |
}else{ | |
if(NumberOfOrders > 1) { | |
NumberOfOrders -= 1; | |
} | |
} | |
LocalPriceAddon = (NumberOfAddons * PriceAddons) * NumberOfOrders; | |
LocalTotalPrice = TotalOrderPrice * NumberOfOrders + LocalPriceAddon; | |
GrandTotal = LocalTotalPrice; | |
txtNumberOfOrders.setText("" + NumberOfOrders); | |
txtVPrice.setText("Total Price: P " + LocalTotalPrice); | |
} | |
public void OrderNow(View view){ | |
String AddonList; | |
String ExtraMessage; | |
Button thisButton = (Button) view; | |
TextView txtVAddon = (TextView) findViewById(R.id.txtVCustomerAddons); | |
TextView txtVOrder = (TextView) findViewById(R.id.txtVCustomerOrder); | |
TextView txtVCustomerName = (TextView) findViewById(R.id.txtVCustomerName); | |
TextView txtGrandPrice = (TextView) findViewById(R.id.txtGrandPrice); | |
EditText txtCustomerName = (EditText) findViewById(R.id.txtCustomerName); | |
CheckBox cbChocolate = (CheckBox) findViewById(R.id.cbAddonChoco); | |
CheckBox cbCream= (CheckBox) findViewById(R.id.cbAddonCream); | |
TextView txtVPrice = (TextView) findViewById(R.id.txtVPrice); | |
TextView txtNumberOfOrders = (TextView) findViewById(R.id.txtNumberOfOrders); | |
RadioButton rbBlack = (RadioButton) findViewById(R.id.rbCoffeeBlack); | |
RadioButton rbCreamy = (RadioButton) findViewById(R.id.rbCoffeeCreamy); | |
ScrollView svMain = (ScrollView) findViewById(R.id.svMain); | |
if(thisButton.getText() == "Reset"){ | |
int LocalTotalPrice; | |
NumberOfAddons = 0; | |
NumberOfOrders = 1; | |
TotalOrderPrice = 0; | |
GrandTotal = 0; | |
txtCustomerName.setText(""); | |
cbChocolate.setChecked(false); | |
cbCream.setChecked(false); | |
rbBlack.setChecked(false); | |
rbCreamy.setChecked(false); | |
LocalTotalPrice = (TotalOrderPrice + (NumberOfAddons) * PriceAddons) * NumberOfOrders; | |
GrandTotal = LocalTotalPrice; | |
txtVPrice.setText("Total Price: P " + LocalTotalPrice); | |
txtNumberOfOrders.setText("" + NumberOfOrders); | |
svMain.fullScroll(ScrollView.FOCUS_UP); | |
}else{ | |
AddonList = "Addons: \n"; | |
if(cbChocolate.isChecked()){ | |
AddonList += "Chocolate \n"; | |
} | |
if(cbCream.isChecked()){ | |
AddonList += "Creamy \n"; | |
} | |
txtVAddon.setText(AddonList); | |
txtGrandPrice.setText("Total Price: P" + GrandTotal); | |
txtVCustomerName.setText(txtCustomerName.getText()); | |
ExtraMessage = "Order Taker\n"; | |
ExtraMessage += txtVCustomerName.getText() + "\n"; | |
ExtraMessage += txtVOrder.getText() + "\n"; | |
ExtraMessage += txtVAddon.getText() + "\n"; | |
ExtraMessage += txtGrandPrice.getText() + "\n"; | |
//Send Email | |
Intent intent = new Intent(Intent.ACTION_SENDTO); | |
intent.setData(Uri.parse("mailto:")); // only email apps should handle this | |
intent.putExtra(Intent.EXTRA_SUBJECT, "My Coffee Order"); | |
intent.putExtra(Intent.EXTRA_TEXT, ExtraMessage); | |
if (intent.resolveActivity(getPackageManager()) != null) { | |
startActivity(intent); | |
} | |
} | |
LinearLayout OrderSlipContent = (LinearLayout) findViewById(R.id.llOrderSlip); | |
if (orderStat){ | |
thisButton.setText("Reset"); | |
OrderSlipContent.setLayoutParams( | |
new LinearLayout.LayoutParams( | |
LinearLayout.LayoutParams.MATCH_PARENT, //Width | |
LinearLayout.LayoutParams.WRAP_CONTENT //Height | |
) | |
); | |
orderStat = false; | |
}else{ | |
thisButton.setText("Order"); | |
OrderSlipContent.setLayoutParams( | |
new LinearLayout.LayoutParams( | |
LinearLayout.LayoutParams.MATCH_PARENT,//Width | |
0 //Height | |
) | |
); | |
orderStat = true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment