Last active
February 24, 2017 09:09
-
-
Save anujajfox/81782a1e1ec5feddcd8f2aecd476b005 to your computer and use it in GitHub Desktop.
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
/** acticity_main - Just Java Udacity Course ( Link: https://classroom.udacity.com/courses/ud836/lessons/4584545214/concepts/45809704040923 **/ | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:orientation="vertical" | |
android:paddingBottom="@dimen/activity_vertical_margin" | |
android:paddingLeft="@dimen/activity_horizontal_margin" | |
android:paddingRight="@dimen/activity_horizontal_margin" | |
android:paddingTop="@dimen/activity_vertical_margin" | |
tools:context="com.example.android.justjava.MainActivity"> | |
<EditText | |
android:id="@+id/edit_text" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginBottom="16dp" | |
android:hint="Name" | |
android:inputType="textCapWords" /> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginBottom="16dp" | |
android:text="@string/toppings" | |
android:textAllCaps="true" /> | |
<CheckBox | |
android:id="@+id/whipped_cream_checkbox" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="@string/whipped_cream" | |
android:paddingLeft="16dp" | |
android:layout_marginBottom="16dp" | |
android:textAppearance="?android:textAppearanceMedium" /> | |
<CheckBox | |
android:id="@+id/chocolate_checkbox" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="@string/chocolate" | |
android:paddingLeft="16dp" | |
android:layout_marginBottom="16dp" | |
android:textAppearance="?android:textAppearanceMedium" /> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginBottom="16dp" | |
android:text="@string/quantity" | |
android:textAllCaps="true" /> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:orientation="horizontal" | |
android:padding="10sp"> | |
<Button | |
android:layout_width="48dp" | |
android:layout_height="48dp" | |
android:layout_toLeftOf="@+id/quantity_text_view" | |
android:onClick="decrement" | |
android:text="-" /> | |
<TextView | |
android:id="@+id/quantity_text_view" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:paddingLeft="8dp" | |
android:paddingRight="8dp" | |
android:text="@string/initial_quantity_value" | |
android:textColor="@android:color/black" | |
android:textSize="16sp" /> | |
<Button | |
android:layout_width="48dp" | |
android:layout_height="48dp" | |
android:layout_toRightOf="@+id/quantity_text_view" | |
android:onClick="increment" | |
android:text="+" /> | |
</LinearLayout> | |
<Button | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginTop="16dp" | |
android:onClick="submitOrder" | |
android:text="@string/order" /> | |
</LinearLayout> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
/** XML FILE - Hindi ( India ) **/
नाम
उपरी परत
फेटी हुई मलाई
चॉकलेट
मात्रा
1
आदेश करे
नाम: <xliff:g id="name" example="Amy">%s</xliff:g>
क्रीम जोड़ें? <xliff:g id="addWhippedCream" example="true">%b</xliff:g>
चॉकलेट जोड़ें ? <xliff:g id="addChocolate" example="true">%b</xliff:g>
मात्रा: <xliff:g id="quantity" example="2">%d</xliff:g>
कुल: <xliff:g id="price" example="$10">%s</xliff:g>
धन्यवाद!
केवल जावा आदेश करे <xliff:g id="name" example="Amy">%s</xliff:g>
/** XML FILE -English **/
Just Java
Topping
1
Thank You
Name
Whipped Cream
Chocolate
Quantityा
Order
Name <xliff:g id="name" example="Amy">%s</xliff:g>
Quantity <xliff:g id="addWhippedCream" example="true">%b</xliff:g>
Quantity <xliff:g id="addChocolate" example="true">%b</xliff:g>
Quantity: <xliff:g id="quantity" example="2">%d</xliff:g>
Total: <xliff:g id="price" example="$10">%s</xliff:g>
Just Java Order <xliff:g id="name" example="Amy">%s</xliff:g>
/** JAVA FILE - Only One ( Common for all language) **/
/**
Add your package below. Package name can be found in the project's AndroidManifest.xml file.
This is the package name our example uses:
package com.example.android.justjava;
*/
package com.example.android.justjava;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
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);
}
/**
This method is called when the plus button is clicked.
*/
public void increment(View view) {
if(quantity==100){
Toast.makeText(this, "You Can't Order More Than 100 Coffees", Toast.LENGTH_SHORT).show();
return;
}
quantity=quantity+1;
displayQuantity(quantity);
}
/**
This method is called when the plus button is clicked.
*/
public void decrement(View view) {
if (quantity==1){
Toast.makeText(this, "You Can't Order Less Than 1 Coffees", Toast.LENGTH_SHORT).show();
return;
}
quantity=quantity-1;
displayQuantity(quantity);
}
/**
This method is called when the order button is clicked.
*/
public void submitOrder(View view) {
CheckBox WhippedCreamCheckBox = (CheckBox) findViewById(R.id.whipped_cream_checkbox);
boolean hasWhippedCream = WhippedCreamCheckBox.isChecked();
CheckBox ChocolateCheckBox = (CheckBox) findViewById(R.id.chocolate_checkbox);
boolean hasChocolate = ChocolateCheckBox.isChecked();
EditText eText = (EditText) findViewById(R.id.edit_text);
String str = eText.getText().toString();
int price=calculatePrice(hasWhippedCream,hasChocolate);
String pricemsg= createOrderSummary(str,price,hasWhippedCream,hasChocolate,str);
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:")); // only email apps should handle this
intent.putExtra(Intent.EXTRA_SUBJECT,getString(R.string.order_summary_email_subject, str));
intent.putExtra(Intent.EXTRA_TEXT, pricemsg) ;
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
private int calculatePrice(boolean addCream, boolean addChocolate){
int baseprice=5;
if (addCream)
{
baseprice=baseprice+1;
}
if (addChocolate)
{
baseprice=baseprice+2;
}
return quantity*baseprice;
}
private String createOrderSummary(String name, int price, boolean addwhippedcream, boolean addchocolate, String addtext){
String priceMessage= getString(R.string.order_summary_name, name);
priceMessage += "\n" +getString(R.string.order_summary_whipped_cream, addwhippedcream);
priceMessage += "\n" +getString(R.string.order_summary_chocolate, addchocolate);
priceMessage += "\n" +getString(R.string.order_summary_quantity, quantity);
priceMessage += "\n" +getString(R.string.order_summary_price, NumberFormat.getCurrencyInstance().format(price));
priceMessage += "\n" +getString(R.string.thank_you);
return priceMessage;
}
/**
This method displays the given quantity value on the screen.
*/
private void displayQuantity(int number) {
TextView quantityTextView = (TextView) findViewById(R.id.quantity_text_view);
quantityTextView.setText("" + number);
}
}