-
-
Save udacityandroid/759b8b4c9ed9e6806e90 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="utf-8"?> | |
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> | |
<!-- Title for the application. [CHAR LIMIT=12] --> | |
<string name="app_name">Sólo Java</string> | |
<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] --> | |
<string name="name">Nombre</string> | |
<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] --> | |
<string name="toppings">Ingredientes</string> | |
<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] --> | |
<string name="whipped_cream">Crema batida</string> | |
<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] --> | |
<string name="chocolate">Chocolate</string> | |
<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] --> | |
<string name="quantity">Cantidad</string> | |
<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=5] --> | |
<string name="initial_quantity_value">2</string> | |
<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] --> | |
<string name="order">Ordenar</string> | |
<!-- | |
Name for the order summary. It will be shown in the format of "Name: Amy" where Amy is the | |
user's name. [CHAR LIMIT=NONE] | |
--> | |
<string name="order_summary_name">Nombre: <xliff:g id="name" example="Amy">%s</xliff:g></string> | |
<!-- | |
Whipped cream topping for the order summary. It will be shown in the format of | |
"Add whipped cream? true" or "Add whipped cream? false". [CHAR LIMIT=NONE] | |
--> | |
<string name="order_summary_whipped_cream">Agregue la crema batida? <xliff:g id="addWhippedCream" example="true">%b</xliff:g></string> | |
<!-- | |
Chocolate topping for the order summary. It will be shown in the format of | |
"Add chocolate? true" or "Add chocolate? false". [CHAR LIMIT=NONE] | |
--> | |
<string name="order_summary_chocolate">Agregue el chocolate? <xliff:g id="addChocolate" example="true">%b</xliff:g></string> | |
<!-- | |
Quantity of coffee cups for the order summary. It will be shown in the format of | |
"Quantity: 2", where 2 is the number of cups ordered. [CHAR LIMIT=NONE] | |
--> | |
<string name="order_summary_quantity">Cantidad: <xliff:g id="quantity" example="2">%d</xliff:g></string> | |
<!-- | |
Total price for the order summary. It will be shown in the format of | |
"Total: $10" where $10 is the price. [CHAR LIMIT=NONE] | |
--> | |
<string name="order_summary_price">Total: <xliff:g id="price" example="$10">%s</xliff:g></string> | |
<!-- Thank you message for the order summary. [CHAR LIMIT=NONE] --> | |
<string name="thank_you">¡Gracias!</string> | |
<!-- | |
Subject line for the order summary email. It will be in the format of | |
"Just Java order for Amy" where Amy is the user's name. [CHAR LIMIT=NONE] | |
--> | |
<string name="order_summary_email_subject">Sólo java para <xliff:g id="name" example="Amy">%s</xliff:g></string> | |
</resources> |
Gujarati Translations
Gujarati strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="app_name">માત્ર જાવા</string>
<string name="name">નામ</string>
<string name="toppings">ટોપિંગ્સ</string>
<string name="whipped_cream">ફીણેલી મલાઈ</string>
<string name="chocolate">ચોકલેટ</string>
<string name="quantity">જથ્થો</string>
<string name="initial_quantity_value">2</string>
<string name="order">ઓર્ડર</string>
<string name="order_summary_whipped_cream">ફીણેલી મલાઈ ઉમેરો છો? <xliff:g id="addWhippedCream" example="yes"> </xliff:g></string>
<string name="order_summary_chocolate">ચોકલેટ ઉમેરો છો? <xliff:g id="addChocolate" example="yes"> </xliff:g></string>
<string name="order_summary_quantity">જથ્થો: <xliff:g id="quantity" example="2">%d</xliff:g></string>
<string name="order_summary_price">કુલ: <xliff:g id="price" example="$10">%s</xliff:g></string>
<string name="thank_you">આભાર!</string>
<string name="order_summary_email_subject">માત્ર જાવા ઓર્ડર <xliff:g id="name" example="Amy">%s</xliff:g></string>
<string name="order_summary_name">નામ <xliff:g id="name" example="Amy">%s</xliff:g></string>
<string name="less_then_1_coffee">તમને 1 થી ઓછી કૉફી ન મળી શકે</string>
<string name="more_then_100_coffee">તમને 100 થી વધુ કૉફી ન મળી શકે</string>
<string name="toppings_yes">હા</string>
<string name="toppings_no">ના</string>
</resources>
MainActivity.java to get yes/no instead of true/false
private String createOrderSummary(String name, int price, boolean addWhippedCream, boolean addChocolate) {
String priceMessage = getString(R.string.order_summary_name, name);
priceMessage += "\n" + getString(R.string.order_summary_whipped_cream);
if (addWhippedCream) {
priceMessage += getString(R.string.toppings_yes);
} else priceMessage += getString(R.string.toppings_no);
priceMessage += "\n" + getString(R.string.order_summary_chocolate);
if (addChocolate) {
priceMessage += getString(R.string.toppings_yes);
} else priceMessage += getString(R.string.toppings_no);
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;
}
if you are getting %b before yes or no like %bYes or %b remove that %b from (look at the arrows in screenshot)
just java app screenshot gujarati
just java app screenshot english
Best of Luck Everybody!
العربية Arabic
جافا فقط<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] -->
<string name="name">اسم</string>
<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] -->
<string name="toppings">اضافات</string>
<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] -->
<string name="whipped_cream">كريمة مخفوقة</string>
<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] -->
<string name="chocolate">شوكولاتة</string>
<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] -->
<string name="quantity">الكمية</string>
<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=5] -->
<string name="initial_quantity_value">۲</string>
<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] -->
<string name="order">اطلب</string>
<!--
Name for the order summary. It will be shown in the format of "Name: Amy" where Amy is the
user's name. [CHAR LIMIT=NONE]
-->
<string name="order_summary_name">اسم: <xliff:g id="name" example="Amy">%s</xliff:g></string>
<!--
Whipped cream topping for the order summary. It will be shown in the format of
"Add whipped cream? true" or "Add whipped cream? false". [CHAR LIMIT=NONE]
-->
<string name="order_summary_whipped_cream"> اضافة كريمة مخفوقة ؟ <xliff:g id="addWhippedCream" example="true">%b</xliff:g></string>
<!--
Chocolate topping for the order summary. It will be shown in the format of
"Add chocolate? true" or "Add chocolate? false". [CHAR LIMIT=NONE]
-->
<string name="order_summary_chocolate">اضافة شوكولاتة ؟ <xliff:g id="addChocolate" example="true">%b</xliff:g></string>
<!--
Quantity of coffee cups for the order summary. It will be shown in the format of
"Quantity: 2", where 2 is the number of cups ordered. [CHAR LIMIT=NONE]
-->
<string name="order_summary_quantity">الكمية: <xliff:g id="quantity" example="2">%d</xliff:g></string>
<!--
Total price for the order summary. It will be shown in the format of
"Total: $10" where $10 is the price. [CHAR LIMIT=NONE]
-->
<string name="order_summary_price">المجموع: <xliff:g id="price" example="$10">%s</xliff:g></string>
<!-- Thank you message for the order summary. [CHAR LIMIT=NONE] -->
<string name="thank_you">شكرا لك</string>
<!--
Subject line for the order summary email. It will be in the format of
"Just Java order for Amy" where Amy is the user's name. [CHAR LIMIT=NONE]
-->
<string name="order_summary_email_subject">فقط جافا ل <xliff:g id="name" example="Amy">%s</xliff:g></string>
To speed up production it's best to rely on google translate
" I'm not able to display Name, Price, Quantity & Toppings Chosen in the email intent. Please help. "
package com.example.android.justjava;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import java.text.NumberFormat;
/**
-
This app displays an order form to order coffee.
*/
public class MainActivity extends AppCompatActivity {int quantity = 0;
@OverRide
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}public void increment(View view){
quantity = quantity+1;
displayQuantity(quantity);
}public void decrement(View view){
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 userName = (EditText) findViewById(R.id.name_field);
String isName = userName.getText().toString() ;int price = calculatePrice(hasWhippedCream , hasChocolate);
String priceMessage = createOrderSummary(price , hasWhippedCream , hasChocolate, isName);Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:")); // only email apps should handle this
intent.putExtra(Intent.EXTRA_SUBJECT, "Just Java order for " + isName);
intent.putExtra(Intent.EXTRA_TEXT, priceMessage);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
// displayMessage(priceMessage);
}
/**
-
Calculates the price of the order
-
@param hasWhippedCream if user has whipper cream toppings
-
@param hasChocolate if user has chocolate toppings
-
@return total price
*/
private int calculatePrice(boolean hasWhippedCream , boolean hasChocolate){
// base price for one coffee cup
int basePrice = 5;
// user choose whipped cream topping
if (hasWhippedCream)
basePrice = basePrice +1;
// user choose chocolate topping
if(hasChocolate)
basePrice = basePrice +2;return quantity * basePrice;
}
/**
- Create summary of the order
- @param name of the customer
- @param price of the order
- @param addWhippedCream is whether a user wants the whipped cream or not
- @param addChocolate is whether a user wants the chocolate or not
- @return text summary
/
private String createOrderSummary(int price , boolean addWhippedCream, boolean addChocolate , String name){
String priceMessage = "\n" + 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 numb) {
TextView quantityTextView = (TextView) findViewById(R.id.quantity_text_view);
quantityTextView.setText("" + numb);
}
-
Slovak
values\string.xml
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="app_name">Just java</string>
<string name="toppings">Toppings</string>
<string name="name">Name </string>
<string name="Whippedcream">Whipped cream </string>
<string name="Chocolate">Chocolate </string>
<string name="Quantity">Quantity </string>
<string name="plus">plus </string>
<string name="minus">minus </string>
<string name="Ordersummary">Order summary</string>
<string name="Order">Order </string>
<string name="order_summary_name">Name: <xliff:g id="name" example="Amy">%s</xliff:g></string>
<string name="order_summary_whipped_cream">Whipped cream? <xliff:g id="addWhippedCream" example="true">%b</xliff:g></string>
<string name="order_summary_chocolate">Chocolade? <xliff:g id="addChocolate" example="true">%b</xliff:g></string>
<string name="order_summary_quantity">Quantity <xliff:g id="quantity" example="2">%d</xliff:g></string>
<string name="order_summary_price">Total: <xliff:g id="price" example="$10">%s</xliff:g></string>
<string name="thank_you">Thanks you !</string>
</resources>
sk\string.xml
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="app_name">Just java</string>
<string name="thank_you">Ďakujem</string>
<string name="toppings">Polevy</string>
<string name="Chocolate">Čokoláda</string>
<string name="Quantity">Počet</string>
<string name="Whippedcream">Šľahačka</string>
<string name="minus">mínus</string>
<string name="name">"Meno "</string>
<string name="plus">plus</string>
<string name="order_summary_name">Meno <xliff:g id="name" example="Amy">%s</xliff:g></string>
<string name="Ordersummary">Sumár objednávky</string>
<string name="Order">Objednať</string>
<string name="order_summary_price">Spolu <xliff:g id="price" example="$10">%s</xliff:g></string>
<string name="order_summary_quantity">Množstvo <xliff:g id="quantity" example="2">%d</xliff:g></string>
<string name="order_summary_whipped_cream">"Šľahačku ? "<xliff:g id="addWhippedCream" example="true">%b</xliff:g></string>
<string name="order_summary_chocolate">Čokoládu ?<xliff:g id="addChocolate" example="true">%b</xliff:g></string>
</resources>
Mine doesn't and never works. There's always a lot of error messages and... Man I'm sad right now, I need to understand how this works :(
- Oʻzbek
-
<string name="app_name">Shunchaki Java</string>
-
<string name="chocolate">Shokoladli</string>
-
<string name="initial_quantity_value">2</string>
-
<string name="name">Ism</string>
-
<string name="order">Buyurtma</string>
-
<string name="order_summary_chocolate">Shokolad qoʻshilsinmi? <xliff:g id="addChocolate" example="true">%b</xliff:g></string>
-
<string name="order_summary_email_subject">Shunchaki javadan <xliff:g id="name" example="Amy">%s</xliff:g> buyurtma</string>
-
<string name="order_summary_name">Ism: <xliff:g id="name" example="Amy">%s</xliff:g></string>
-
<string name="order_summary_price">Jami: <xliff:g id="price" example="$10">%s</xliff:g></string>
-
<string name="order_summary_quantity">Miqdori: <xliff:g id="quantity" example="2">%d</xliff:g></string>
-
<string name="order_summary_whipped_cream"> Qaymoq qoʻshilsinmi? <xliff:g id="addWhippedCream" example="true">%b</xliff:g></string>
-
<string name="quantity">Miqdori</string>
-
<string name="thank_you">Rahmat!</string>
-
<string name="toppings">Qoʻshimchalar</string>
-
<string name="whipped_cream">Qaymoq</string>
-
-
Uzbek
Shunchaki Java<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] -->
<string name="name">ism</string>
<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] -->
<string name="toppings">qo\'shimchalar</string>
<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] -->
<string name="whipped_cream">ko\'pirtirilgan qaymoq</string>
<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] -->
<string name="chocolate">Shokolad</string>
<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] -->
<string name="quantity">Soni</string>
<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=5] -->
<string name="initial_quantity_value">1</string>
<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] -->
<string name="order">Buyurtma</string>
<!--
Name for the order summary. It will be shown in the format of "Name: Amy" where Amy is the
user's name. [CHAR LIMIT=NONE] -
Эътибор беринг қуйидаги сатр мисол тариқасида бошқа йўл билан белгиланди. Буни афзаллик томони агарда таржимонлар мазкур сатрни боқа тилга таржима қилиши натижасида исмдан кейин сатр номи
чиқиши керак бўлса яъни,"Amy:Name" чиқарилиши керак бўлса ":Name" сўзини исм қийматидан кейин ёзиши мумкин.
-->
<string name="order_summary_name">Ism: <xliff:g id="customer" example="Amy">%s</xliff:g></string>
<string name="order_summary_whipped_cream">ko\'pirtirilgan qaymoq qo\'shish? <xliff:g id="cream" example="true">%s</xliff:g></string>
<string name="order_summary_chocolate">Shokolad qo\'shish? <xliff:g id="choco" example="true">%s</xliff:g></string>
<string name="quantity_coffee">Soni: <xliff:g id="quantity" example="1">%d</xliff:g></string>
<string name="total_price">Jami: <xliff:g id="price" example="5">%d</xliff:g>$</string>
<string name="thank_you">Raxmat!</string>
<string name="can_not_have_more100">Siz 100 donadan ortiq qaxva sotib ololmaysiz</string>
<string name="can_not_have_less1">Siz 1 donadan kam qaxva sotib ololmaysiz</string>
<string name="yesCream">ha</string>
<string name="noCream">yo\'q</string>
<string name="yesChoco">ha</string>
<string name="noChoco">yo\'q</string>
<string name="order_for"><xliff:g id="name" example="order for">%s</xliff:g> uchun Shunchaki Javadan buyurtma</string>
public class MainActivity extends AppCompatActivity {
int quantity = 1;
@OverRide
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void submitOrder(View view) {
CheckBox whippedCreamCheckbox = (CheckBox) findViewById(R.id.cream_checkbox);
boolean hasWhippedCream = whippedCreamCheckbox.isChecked();
CheckBox ChocolateCheckbox = (CheckBox) findViewById(R.id.chokolate_checkbox);
boolean hasChocolate = ChocolateCheckbox.isChecked();
EditText customerName = (EditText) findViewById(R.id.name_field);
String name = customerName.getText().toString();
int price = calculatePrice(hasWhippedCream, hasChocolate);
String priceMessage = createOrderSummary(price, hasWhippedCream, hasChocolate, name);
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_for, name) );
intent.putExtra(Intent.EXTRA_TEXT, priceMessage);
startActivity(intent);
}
private int calculatePrice(boolean addWhipperCream, boolean addChocolate) {
int basePrice = 5;
if (addWhipperCream) {
basePrice += 1;
}
if (addChocolate) {
basePrice += 2;
}
return quantity * basePrice;
}
private String createOrderSummary(int price, boolean cream, boolean choco, String customer) {
String priceMessage = getString(R.string.order_summary_name,customer) ;
String creamTopping ;
String chocoTopping ;
if (cream) {
creamTopping = getString(R.string.yesCream);
} else creamTopping = getString(R.string.noCream);
if (choco) {
chocoTopping = getString(R.string.yesChoco);
} else chocoTopping = getString(R.string.noChoco);
priceMessage += "\n" + getString(R.string.order_summary_whipped_cream, creamTopping) ;
priceMessage += "\n" + getString(R.string.order_summary_chocolate, chocoTopping);
priceMessage += "\n" + getString(R.string.quantity_coffee,quantity);
priceMessage += "\n" + getString(R.string.total_price, price);
priceMessage += "\n" + getString(R.string.thank_you);
return priceMessage;
}
public void increment(View view) {
if (quantity == 100) {
Toast toast = Toast.makeText(this, getString(R.string.can_not_have_more100), Toast.LENGTH_LONG);
toast.show();
return;
}
quantity = quantity + 1;
displayQuantity(quantity);
}
public void decrement(View view) {
if (quantity == 1) {
Toast toast = Toast.makeText(this, getString(R.string.can_not_have_less1), Toast.LENGTH_LONG);
toast.show();
return;
}
quantity = quantity - 1;
displayQuantity(quantity);
}
private void displayQuantity(int number) {
TextView quantityTextView = (TextView) findViewById(R.id.quantity_text_view);
quantityTextView.setText("" + number);
}
private void displayPrice(String message) {
TextView priceTextView = (TextView) findViewById(R.id.price_text_view);
priceTextView.setText(message);
}
}
Can anyone help me....untill Intent everything was right but after localization neither subject is shown in gmail app nor order summsry shows correctly!!.......i have added screenshotnof emulator"s output too..
xml file*
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:id="@+id/name_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Name"
android:inputType="textCapWords"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
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:paddingLeft="24dp"
android:text="@string/whipped_cream"
android:textSize="16sp"/>
<CheckBox
android:id="@+id/chocolate_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="24dp"
android:text="@string/chocolate"
android:textSize="16sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/quantity"
android:textAllCaps="true" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="48dp"
android:layout_height="48dp"
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="2"
android:textSize="16sp" />
<Button
android:layout_width="48dp"
android:layout_height="48dp"
android:onClick="increment"
android:text="+" />
</LinearLayout>
<!--just comment out next two text views to exclude order summary from the app when it:s intented in email app
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Order Summary"
android:textAllCaps="true" />
<TextView
android:id="@+id/order_summary_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="$0"
android:textSize="16sp" />
-->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:onClick="submitOrder"
android:text="@string/order" />
</LinearLayout>
java fileeeeeeeee
package com.example.android.justjava;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
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;
import androidx.appcompat.app.AppCompatActivity;
/**
This app displays an order form to order coffee.
*/
public class MainActivity extends AppCompatActivity {
int quantity =2;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
/**
This method is called when the order button is clicked.
*/
public void increment(View view) {
if (quantity == 100) {
// show an error message as toast
Toast.makeText(this, " You cannot have more than 100 coffee", Toast.LENGTH_SHORT).show();
//exit this methold early because there is nothing left to do
return;
}
quantity = quantity + 1;
displayQuantity(quantity);
}
/**
This method is called when the order button is clicked.
*/
public void decrement(View view) {
if (quantity == 1) {
// show an error message as toast
Toast.makeText(this, " You cannot have less than 1 coffee", Toast.LENGTH_SHORT).show();
//exit this methold early because there is nothing left to do
return;
}
quantity = quantity - 1;
displayQuantity(quantity);
}
/**
This method is called when the order button is clicked.
*/
public void submitOrder(View view) {
EditText nameField = (EditText) findViewById(R.id.name_field);
//chain methold, namefield.getText gives Editable in output which then gives strings with toString methold on it
String name = nameField.getText().toString();
//figure out if user wants whipped cream topping
CheckBox whippedCreamCheckBox = (CheckBox) findViewById(R.id.whipped_cream_checkbox);
boolean hasWhippedCream = whippedCreamCheckBox.isChecked();
//figure out if user wants chocolate topping
CheckBox ChocolateCheckBox = (CheckBox) findViewById(R.id.chocolate_checkbox);
boolean hasChocolate = ChocolateCheckBox.isChecked();
int price = calculatePrice(hasWhippedCream,hasChocolate);
String priceMessage = createOrderSummary(name, price, hasWhippedCream, hasChocolate);
//use of intent for sending it to email app,where EXTRA_SUBJECT is for the subject in email app and EXTRA_TEXT is for the body of the email app
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, name));
//here EXTRA_TEXT is for BODY of the email app wheras EXTRA_SUBJECT is for subject part of email app
intent.putExtra(Intent.EXTRA_TEXT, priceMessage) ;
//preventing app from crashing in case there is no app supported for that function
if (intent.resolveActivity(getPackageManager())!= null) {
startActivity(intent);
}
// now we don't have to display message in the app since, we are using intent
// displayMessage(priceMessage);
}
/**
* Calculates the price of the order
* @param addwhippedcream is whether or not the user wants whipped cream topping
* @param addchocolate is whether or not user wants chocolate topping
* @return total price
*/
private int calculatePrice(boolean addwhippedcream, boolean addchocolate) {
// price of one cup of coffee
int basePrice = 5;
//add 1$ if user wants whipped cream toppings
if (addwhippedcream){
basePrice = basePrice +1;
}
//add 2$ if user wants chocolate toppings
if (addchocolate){
basePrice = basePrice + 2;
}
//calculate the total price by multipling it to the quantity
return quantity * basePrice;
}
/*creat summary of order
@param price of order
@return text summary
*/
private String createOrderSummary(String name,int price, boolean addWhippedCream, boolean addChocolate){
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 numberOfCoffees) {
TextView quantityTextView = (TextView) findViewById(
R.id.quantity_text_view);
quantityTextView.setText("" + numberOfCoffees);
}
/**
* This method displays the given text on the screen,but now we don't want to show order summary since we already are parsinf it to the email app through intent
*/
// private void displayMessage(String message) {
// TextView OrderSummaryTextView = (TextView) findViewById(R.id.order_summary_text_view);
// OrderSummaryTextView.setText(message);
// }
}
**string(english version)
just Java<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] -->
<string name="name">Name</string>
<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] -->
<string name="toppings">Toppings</string>
<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] -->
<string name="whipped_cream">Whipped cream</string>
<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] -->
<string name="chocolate">Chocolate</string>
<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] -->
<string name="quantity">Quantity</string>
<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=5] -->
<string name="initial_quantity_value">2</string>
<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] -->
<string name="order">Order</string>
<!--
Name for the order summary. It will be shown in the format of "Name: Amy" where Amy is the
user's name. [CHAR LIMIT=NONE]
-->
<string name="order_summary_name">Name: <xliff:g id="name" example="Amy">%s</xliff:g></string>
<!--
Whipped cream topping for the order summary. It will be shown in the format of
"Add whipped cream? true" or "Add whipped cream? false". [CHAR LIMIT=NONE]
-->
<string name="order_summary_whipped_cream">Add whipped cream? <xliff:g id="addWhippedCream" example="true">%b</xliff:g></string>
<!--
Chocolate topping for the order summary. It will be shown in the format of
"Add chocolate? true" or "Add chocolate? false". [CHAR LIMIT=NONE]
-->
<string name="order_summary_chocolate">Add chocolate? <xliff:g id="addChocolate" example="true">%b</xliff:g></string>
<!--
Quantity of coffee cups for the order summary. It will be shown in the format of
"Quantity: 2", where 2 is the number of cups ordered. [CHAR LIMIT=NONE]
-->
<string name="order_summary_quantity">Quantity: <xliff:g id="quantity" example="2">%d</xliff:g></string>
<!--
Total price for the order summary. It will be shown in the format of
"Total: $10" where $10 is the price. [CHAR LIMIT=NONE]
-->
<string name="order_summary_price">Total: <xliff:g id="price" example="$10">%s</xliff:g></string>
<!-- Thank you message for the order summary. [CHAR LIMIT=NONE] -->
<string name="thank_you">Thank you!</string>
<!--
Subject line for the order summary email. It will be in the format of
"Just Java order for Amy" where Amy is the user's name. [CHAR LIMIT=NONE]
-->
<string name="order_summary_email_subject">Just Java order for <xliff:g id="name" example="Amy">%s</xliff:g></string>
string(spanish version****
Sólo Java<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] -->
<string name="name">Nombre</string>
<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] -->
<string name="toppings">Ingredientes</string>
<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] -->
<string name="whipped_cream">Crema batida</string>
<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] -->
<string name="chocolate">Chocolate</string>
<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] -->
<string name="quantity">Cantidad</string>
<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=5] -->
<string name="initial_quantity_value">2</string>
<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] -->
<string name="order">Ordenar</string>
<!--
Name for the order summary. It will be shown in the format of "Name: Amy" where Amy is the
user's name. [CHAR LIMIT=NONE]
-->
<string name="order_summary_name">Nombre: <xliff:g id="name" example="Amy">%s</xliff:g></string>
<!--
Whipped cream topping for the order summary. It will be shown in the format of
"Add whipped cream? true" or "Add whipped cream? false". [CHAR LIMIT=NONE]
-->
<string name="order_summary_whipped_cream">Agregue la crema batida? <xliff:g id="addWhippedCream" example="true">%b</xliff:g></string>
<!--
Chocolate topping for the order summary. It will be shown in the format of
"Add chocolate? true" or "Add chocolate? false". [CHAR LIMIT=NONE]
-->
<string name="order_summary_chocolate">Agregue el chocolate? <xliff:g id="addChocolate" example="true">%b</xliff:g></string>
<!--
Quantity of coffee cups for the order summary. It will be shown in the format of
"Quantity: 2", where 2 is the number of cups ordered. [CHAR LIMIT=NONE]
-->
<string name="order_summary_quantity">Cantidad: <xliff:g id="quantity" example="2">%d</xliff:g></string>
<!--
Total price for the order summary. It will be shown in the format of
"Total: $10" where $10 is the price. [CHAR LIMIT=NONE]
-->
<string name="order_summary_price">Total: <xliff:g id="price" example="$10">%s</xliff:g></string>
<!-- Thank you message for the order summary. [CHAR LIMIT=NONE] -->
<string name="thank_you">¡Gracias!</string>
<!--
Subject line for the order summary email. It will be in the format of
"Just Java order for Amy" where Amy is the user's name. [CHAR LIMIT=NONE]
-->
<string name="order_summary_email_subject">Sólo java para <xliff:g id="name" example="Amy">%s</xliff:g></string>
@Naruto-uchiha24 Are you still facing the same issue? Have you tried to keep logs where the intent
was called from?
رغم اني املك تطبيق البريد الالكتروني في هاتفي لكن لم يستطع تطبيق جاست جافا استدعاءه لارسال ملخص الطلب
اعني انني عندما اضغط على زر الطلب لا يبعث الغرض للبريد الالكتروني
@RequiresApi(api = Build.VERSION_CODES.N)
public void submitOrder(View view) {
// Figure out if the user wants whipped cream topping
CheckBox WhippedCreamCheckBox = (CheckBox) findViewById(R.id.add_whipped_cream);
boolean hasWhippedCream = WhippedCreamCheckBox .isChecked();
// Figure out if the user wants chocolate topping
CheckBox chocolateCheckBox= findViewById(R.id.chocolate_checkbox);
boolean hasChocolate = chocolateCheckBox.isChecked();
EditText nameField = findViewById(R.id.name_of_user);
String name =nameField.getText().toString();
int price = calculatePrice(hasWhippedCream,hasChocolate);
String priceMessage = creatOrderSummary(price,hasWhippedCream, hasChocolate,name);
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:"));
intent.putExtra(Intent.EXTRA_SUBJECT,"Just java order for"+name);
intent.putExtra(Intent.EXTRA_TEXT,priceMessage);
displayMessage(priceMessage);
}
وهدا هو الكود الخاص بالغرض ارجو المساعدة كي استطيع متابعة الدروس
Arabic Version
النسخة العربيةالجافا فقط
<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] --> <string name="name">الأسم</string> <!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] --> <string name="toppings">إضافات</string> <!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] --> <string name="whipped_cream">كريمه</string> <!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] --> <string name="chocolate">شوكولاتة</string> <!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] --> <string name="quantity">الكميه</string> <!-- Hint text display in the empty field for the user's name [CHAR LIMIT=5] --> <string name="initial_quantity_value">٢</string> <!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] --> <string name="order">أطلب</string> <!-- Name for the order summary. It will be shown in the format of "Name: Amy" where Amy is the user's name. [CHAR LIMIT=NONE] --> <string name="order_summary_name">: الأسم<xliff:g id="name" example="Amy">%s</xliff:g></string> <!-- Whipped cream topping for the order summary. It will be shown in the format of "Add whipped cream? true" or "Add whipped cream? false". [CHAR LIMIT=NONE] --> <string name="order_summary_whipped_cream">إضافة كريمه ؟ <xliff:g id="addWhippedCream" example="true">%b</xliff:g></string> <!-- Chocolate topping for the order summary. It will be shown in the format of "Add chocolate? true" or "Add chocolate? false". [CHAR LIMIT=NONE] --> <string name="order_summary_chocolate">إضافة شوكولاتة؟<xliff:g id="addChocolate" example="true">%b</xliff:g></string> <!-- Quantity of coffee cups for the order summary. It will be shown in the format of "Quantity: 2", where 2 is the number of cups ordered. [CHAR LIMIT=NONE] --> <string name="order_summary_quantity">: الكميه<xliff:g id="quantity" example="2">%d</xliff:g></string> <!-- Total price for the order summary. It will be shown in the format of "Total: $10" where $10 is the price. [CHAR LIMIT=NONE] --> <string name="order_summary_price">:الأجمالى <xliff:g id="price" example="$10">%s</xliff:g></string> <!-- Thank you message for the order summary. [CHAR LIMIT=NONE] --> <string name="thank_you">شكراَ</string> <!-- Subject line for the order summary email. It will be in the format of "Just Java order for Amy" where Amy is the user's name. [CHAR LIMIT=NONE] --> <string name="order_summary_email_subject"> الجافا فقط إلى <xliff:g id="name" example="Amy">%s</xliff:g></string>
السلام عليكم
ممكن توضيح لx liff ؟ للغة العربية
Turkish Translation
Sadece Java Topingler Teşekkürler Krem şanti Çikolata Miktar Emir İsim: %s Miktar: %s Çırpılmış krema ekler misiniz? %s Çikolata ekle?? %s Toplam: ₺%f İsim iki Sadece Java SiparişiFor the strings that use booleans variables, I did two types of strings for the true and false. For order_summary_whipped_cream and order_summary_chocolate I got rid of the xliff:g and used this code:
English
<!--
Whipped cream topping for the order summary. It will be shown in the format of
"Add whipped cream? true" or "Add whipped cream? false". [CHAR LIMIT=NONE]
-->
<string name="order_summary_whipped_cream_true">Add whipped cream? true</string>
<string name="order_summary_whipped_cream_false">Add whipped cream? false</string>
<!--
Chocolate topping for the order summary. It will be shown in the format of
"Add chocolate? true" or "Add chocolate? false". [CHAR LIMIT=NONE]
-->
<string name="order_summary_chocolate_true">Add chocolate? true</string>
<string name="order_summary_chocolate_false">Add chocolate? false</string>
`Spanish
<!--
Whipped cream topping for the order summary. It will be shown in the format of
"Add whipped cream? true" or "Add whipped cream? false". [CHAR LIMIT=NONE]
-->
<string name="order_summary_whipped_cream_true">Agregue la crema batida? verdadero</string>
<string name="order_summary_whipped_cream_false">Agregue la crema batida? falso</string>
<!--
Chocolate topping for the order summary. It will be shown in the format of
"Add chocolate? true" or "Add chocolate? false". [CHAR LIMIT=NONE]
-->
<string name="order_summary_chocolate_true">Agregue el chocolate? verdadero</string>
<string name="order_summary_chocolate_false">Agregue el chocolate? falso</string>
Then in the java file, I used the conditional operator, ?:, to set the values.to the boolean variables.
Hindi Version
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="app_name">JavaActivity</string>
<string name="chocolate">चॉकलेट</string>
<string name="whipped_cream">मार पड़ी क्रीम</string>
<string name="order">आदेश</string>
<string name="toppings">सामग्री</string>
<string name="order_summary">आदेश सारांश</string>
<string name="quantity">"परिमाण: "</string>
<string name="thank_you">धन्यवाद!!</string>
<string name="Whipped_Cream">"व्हीप्ड क्रीम जोड़ें? "</string>
<string name="Chocolate">"चॉकलेट जोड़ें? "</string>
<string name="name_text">" नाम: <xliff:g example="Amy" id="name">%s</xliff:g>"</string>
<string name="total">"कुल: "</string>
<string name="name">नाम</string>
</resources>
<string name="order_summary_name"> الاسم<xliff:g id="quantity" example="Yazan">%s</xliff:g></string>
Java>>>>
package com.example.justjava;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
/**
-
This app displays an order form to order coffee.
*/
public class MainActivity extends AppCompatActivity {
int quantity;@OverRide
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
/**- This method is called when the plus button is clicked. Intent intent = new Intent(Intent.ACTION_SENDTO);
-
intent.setData(Uri.parse("mailto:")); // only email apps should handle this
-
intent.putExtra(Intent.EXTRA_SUBJECT, "just jvaa" + editable);
-
if (intent.resolveActivity(getPackageManager()) != null) {
-
startActivity(intent);
-
}
*/
public void increment(View view) {if (quantity==15){ Toast.makeText(this, " you cannot have more than 15 ", Toast.LENGTH_SHORT).show(); return; } quantity=++quantity; displayQuantity(quantity);
}
/**-
This method is called when the sub button is clicked.
/
public void decrement(View view) {
if (quantity<1){
Toast.makeText(this, "you cannot have less 1 cup", Toast.LENGTH_SHORT).show();
return;
}
quantity=--quantity;
displayQuantity(quantity);
}
/* -
This method is called when the order button is clicked.
*/
@SuppressLint("QueryPermissionsNeeded")
public void submitOrder(View view) {
EditText name = (EditText) findViewById(R.id.EditText_view);
String Name = name.getText().toString(); // Editable Name = editText.getText();CheckBox isCheck = (CheckBox) findViewById(R.id.checkbox);
boolean hasWhippedCream = isCheck.isChecked();CheckBox ischocolate = (CheckBox) findViewById(R.id.chocolate_checkbox);
boolean hasChocolate = ischocolate.isChecked();int price = calculatePrice(hasWhippedCream, hasChocolate);
String priceMassage = CsreateOrderSummary(price, hasWhippedCream, hasChocolate, Name);Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:")); // only email apps should handle this
intent.putExtra(Intent.EXTRA_SUBJECT, "Just Java order for "+ Name);
intent.putExtra(Intent.EXTRA_TEXT, priceMassage);
startActivity(intent);displayMessage(priceMassage);
}
private void displayQuantity(int number) {
TextView quantityTextView = findViewById(R.id.quantity_text_view); // num of cups
quantityTextView.setText("" + number);
}/**
- This method displays the given text on the screen.
*/
private void displayMessage(String message) {
TextView priceTextView = (TextView) findViewById(R.id.summary_order_text_view); // string
priceTextView.setText(message);
}
/**
- Calculate thr taxes of Saudi Arabia \if (hasWhippedCream || hasChocolate){
-
price = calculatePrice() + 5 ;
-
} if (hasWhippedCream && hasChocolate){
-
price = calculatePrice() + 10;
-
} else if(hasChocolate|| hasWhippedCream){
-
Toast.makeText(this, "have you add Toppings ", Toast.LENGTH_SHORT).show();
- @return the value of taxes
/
private int calculatePrice( boolean addWhippedCream ,boolean addChocolate ) {
int price = 5;
if (addWhippedCream){
price = price +1; }
if (addChocolate){
price = price+2; }
return quantityprice;
}
/**
* Create summary of the order. -
* @param name of the customer
-
@param price of the order
-
@param addWhippedCream is whether or not the user wants whipped cream topping
-
@param hasChoco is whether or not the user wants chocolate topping
* @return text summary
*/
private String CsreateOrderSummary (int price , boolean addWhippedCream,boolean hasChoco,String name ) {String priceMessage = getString(R.string.order_summary_name)+ name+":"; priceMessage += "\n" +getString(R.string.add_whipped) + "?"+addWhippedCream; priceMessage += "\n"+getString(R.string.add_chocolat) + "?"+ hasChoco; priceMessage += quantity+"\n"+getString(R.string.quantity) ; priceMessage += "\n"+getString(R.string.Total) + price; priceMessage += "\n"+ getString(R.string.thank_you); return priceMessage;
}
}
Marathi Translations:

path: res/values-mr-rIN/strings.xml