Created
December 5, 2017 06:54
-
-
Save asafstr2/77e322aeba1edb84a8c42587fa8537be to your computer and use it in GitHub Desktop.
upgraded Just Java app
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
<ScrollView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools"> | |
<RelativeLayout | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:layout_gravity="left"> | |
<ImageView | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:src="@drawable/cofee" | |
android:scaleType="fitXY"/> | |
<!-- | |
we can change the android:gravity="right" to left in order to support Hebrew it is done automaticly | |
--> | |
<LinearLayout | |
android:id="@+id/layout" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:gravity="right" | |
android:orientation="vertical"> | |
<EditText | |
android:id="@+id/name" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:hint="@string/your_name" | |
android:paddingBottom="6dp" | |
android:paddingLeft="6dp" | |
android:paddingRight="6dp" | |
android:paddingTop="6dp" | |
android:textSize="20sp" | |
android:inputType="textCapWords"/> | |
<TextView | |
android:id="@+id/topping" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:fontFamily="sans-serif-light" | |
android:paddingBottom="6dp" | |
android:paddingLeft="6dp" | |
android:paddingRight="6dp" | |
android:paddingTop="6dp" | |
android:text="@string/topping" | |
android:textAllCaps="true" | |
android:textSize="12sp" | |
android:textStyle="bold"/> | |
<CheckBox | |
android:id="@+id/checkBox" | |
style="@android:style/Widget.DeviceDefault.Light.CompoundButton.CheckBox" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:button="@null" | |
android:drawableLeft="?android:attr/listChoiceIndicatorMultiple" | |
android:drawablePadding="24dp" | |
android:text="@string/whiped_cream" | |
android:textSize="16sp" | |
android:typeface="serif" | |
android:onClick="whipped"/> | |
<CheckBox | |
android:id="@+id/chocoled" | |
style="@android:style/Widget.DeviceDefault.Light.CompoundButton.CheckBox" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:button="@null" | |
android:drawableLeft="?android:attr/listChoiceIndicatorMultiple" | |
android:drawablePadding="24dp" | |
android:text="@string/chocoled" | |
android:textSize="16sp" | |
android:typeface="serif" | |
android:onClick="chocolad"/> | |
<TextView | |
android:id="@+id/quantity" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:fontFamily="sans-serif-light" | |
android:paddingBottom="6dp" | |
android:paddingLeft="6dp" | |
android:paddingRight="6dp" | |
android:paddingTop="6dp" | |
android:text="@string/quantity" | |
android:textAllCaps="true" | |
android:textSize="12sp" | |
android:textStyle="bold"/> | |
<LinearLayout | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:orientation="horizontal"> | |
<Button | |
android:id="@+id/plus" | |
android:layout_width="45dp" | |
android:layout_height="40dp" | |
android:layout_margin="6dp" | |
android:layout_marginBottom="16dp" | |
android:onClick="plus" | |
android:paddingLeft="6dp" | |
android:paddingRight="6dp" | |
android:text="+" | |
android:textSize="16sp" /> | |
<TextView | |
android:id="@+id/quantity_text_view" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_margin="6dp" | |
android:fontFamily="sans-serif-light" | |
android:text="0" | |
android:textColor="#000000" | |
android:textSize="20sp" /> | |
<Button | |
android:id="@+id/minus" | |
android:layout_width="45sp" | |
android:layout_height="40dp" | |
android:layout_margin="6dp" | |
android:onClick="minus" | |
android:text="-" | |
android:textSize="16sp" /> | |
</LinearLayout> | |
<TextView | |
android:id="@+id/price" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginTop="16dp" | |
android:fontFamily="sans-serif-light" | |
android:paddingLeft="6dp" | |
android:paddingRight="6dp" | |
android:text="@string/price" | |
android:textAllCaps="true" | |
android:textSize="12sp" | |
android:textStyle="bold"/> | |
<TextView | |
android:id="@+id/price_text_view" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginTop="16dp" | |
android:fontFamily="sans-serif-light" | |
android:paddingLeft="6dp" | |
android:paddingRight="6dp" | |
android:text="@string/_0" | |
android:textAllCaps="true" | |
android:textColor="#000000" | |
android:textSize="20sp" /> | |
<TextView | |
android:id="@+id/thank_you" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginTop="16dp" | |
android:fontFamily="sans-serif-light" | |
android:paddingLeft="6dp" | |
android:paddingRight="6dp" | |
android:text="@string/thank_you" | |
android:textAllCaps="true" | |
android:textColor="#000000" | |
android:textSize="20sp" /> | |
<Button | |
android:id="@+id/button" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginRight="8dp" | |
android:layout_marginTop="16dp" | |
android:onClick="order2" | |
android:paddingLeft="6dp" | |
android:text="@string/order" | |
android:textSize="16sp" | |
android:layout_marginLeft="8dp" /> | |
</LinearLayout> | |
</RelativeLayout> | |
</ScrollView> | |
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
<RelativeLayout | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:layout_gravity="left" | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:background="#BCAAA4" | |
> | |
<ScrollView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_centerHorizontal="true" | |
android:fillViewport="false" | |
android:scrollbarStyle="insideOverlay"> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_gravity="left" | |
android:orientation="vertical"> | |
<EditText | |
android:id="@+id/popup" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_alignParentTop="true" | |
android:layout_centerHorizontal="true" | |
android:layout_marginTop="13dp" | |
android:background="#BCAAA4" | |
android:enabled="false" | |
android:scrollbars="vertical" | |
android:text="@string/thank_you_for_123" | |
android:textSize="20sp" | |
android:paddingRight="16dp" | |
android:paddingLeft="16dp" | |
/> | |
<Button | |
android:id="@+id/submit" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginRight="8dp" | |
android:layout_marginTop="16dp" | |
android:onClick="mail" | |
android:paddingLeft="6dp" | |
android:text="submit" | |
android:textSize="16sp" | |
android:layout_marginLeft="8dp" /> | |
</LinearLayout> | |
</ScrollView> | |
</RelativeLayout> |
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"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
package="com.example.android.cofeeorder"> | |
<application | |
android:allowBackup="true" | |
android:icon="@mipmap/ic_launcher" | |
android:label="@string/app_name" | |
android:roundIcon="@mipmap/ic_launcher_round" | |
android:supportsRtl="true" | |
android:theme="@style/AppTheme"> | |
<activity android:name=".MainActivity"> | |
<intent-filter> | |
<action android:name="android.intent.action.MAIN" /> | |
<category android:name="android.intent.category.LAUNCHER" /> | |
</intent-filter> | |
</activity> | |
</application> | |
</manifest> |
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"?> | |
<resources> | |
<color name="colorPrimary">#3F51B5</color> | |
<color name="colorPrimaryDark">#303F9F</color> | |
<color name="colorAccent">#FF4081</color> | |
</resources> |
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.cofeeorder; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import android.support.v7.app.AlertDialog; | |
import android.support.v7.app.AppCompatActivity; | |
import android.text.Editable; | |
import android.view.Gravity; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.CheckBox; | |
import android.widget.EditText; | |
import android.widget.LinearLayout; | |
import android.widget.TextView; | |
import android.widget.Toast; | |
import java.text.NumberFormat; | |
import java.util.Locale; | |
/** | |
* This app displays an order form to order coffee. | |
*/ | |
public class MainActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
LinearLayout llyaout = findViewById(R.id.layout); | |
if (Locale.getDefault().getLanguage().equals("en")) { | |
llyaout.setGravity(Gravity.LEFT); | |
} | |
else if (Locale.getDefault().getLanguage().equals("he")) { | |
llyaout.setGravity(Gravity.RIGHT); | |
} | |
} | |
/** | |
* This method is called when the order button is clicked. | |
*/ | |
int quantity=0; | |
int sum=0; | |
int cream=3; | |
int chocolate=1; | |
int cofeeprice=6; | |
String toMail; | |
String[] address = {"[email protected]"}; | |
String stringName=""; | |
public void plus(View view) { | |
quantity+=1; | |
displayQuantity(quantity); | |
displayPrice(calculatePrice(quantity));} | |
public void minus(View view) { | |
if (quantity>0) | |
quantity-=1; | |
else{ | |
quantity=0; | |
Toast.makeText(this, "you cannot have less then 1 coffe",Toast.LENGTH_SHORT).show();} | |
displayQuantity(quantity); | |
displayPrice(calculatePrice(quantity)); | |
} | |
/** | |
* This method displays the given quantity value on the screen. | |
*/ | |
public void whipped (View view) { | |
calculatePrice(quantity); | |
displayQuantity(quantity); | |
displayPrice(sum); | |
} | |
public void chocolad (View view){ | |
calculatePrice(quantity); | |
displayQuantity(quantity); | |
displayPrice(sum); | |
} | |
public int calculatePrice(int quantity) { | |
CheckBox chocolad = findViewById(R.id.chocoled); | |
CheckBox whipped = findViewById(R.id.checkBox); | |
int priceMiddle=0; | |
int price=cofeeprice; | |
if (whipped.isChecked()) {price+=cream;} | |
if (chocolad.isChecked()){price+=chocolate;} | |
priceMiddle+=quantity * price; | |
sum=priceMiddle; | |
return sum; | |
} | |
private void displayQuantity(int number) { | |
TextView quantityTextView = findViewById(R.id.quantity_text_view); | |
quantityTextView.setText(getString(R.string.blank) + number); | |
} | |
/** | |
* This method displays the given price on the screen. | |
*/ | |
private void displayPrice(int number) { | |
TextView priceTextView = findViewById(R.id.price_text_view); | |
priceTextView.setText(NumberFormat.getCurrencyInstance().format(number)); | |
} | |
/** | |
* This method displays the given text on the screen. | |
*/ | |
public void order2 (View view){ | |
CheckBox chocolad = findViewById(R.id.chocoled); | |
CheckBox whipped = findViewById(R.id.checkBox); | |
String topping=""; | |
String thnks=getString(R.string.Thank_you_for_buying); | |
String yourPrice=getString(R.string.your_price_is); | |
if (whipped.isChecked()&&chocolad.isChecked()) {topping=getString(R.string.you_add_whipped_cream_you_add_chocolate);} | |
if (whipped.isChecked()&&!chocolad.isChecked()) {topping=getString(R.string.you_add_whipped_cream);} | |
if (chocolad.isChecked()&&!whipped.isChecked()) {topping=getString(R.string.you_add_chocklade);} | |
AlertDialog.Builder mBuilder = new AlertDialog.Builder(MainActivity.this); | |
View mView = getLayoutInflater().inflate(R.layout.activity_popup2,null,true); | |
final EditText popup = mView.findViewById(R.id.popup); | |
EditText name = findViewById(R.id.name); | |
Editable mid = name.getText(); | |
stringName = "\n"+name.getText().toString(); | |
popup.setText(mid+thnks+topping+yourPrice+(NumberFormat.getCurrencyInstance().format(sum))); | |
toMail=mid+thnks+topping+yourPrice+(NumberFormat.getCurrencyInstance().format(sum)); | |
mBuilder.setView(mView); | |
final AlertDialog dialog = mBuilder.create(); | |
dialog.show(); | |
} | |
public void mail (View view){composeEmail(address,"cofee order for "+stringName, toMail );} | |
public void composeEmail(String[] addresses, String subject, String content) { | |
Intent intent = new Intent(Intent.ACTION_SEND); | |
intent.setType("*/*"); | |
intent.putExtra(Intent.EXTRA_EMAIL, addresses); | |
intent.putExtra(Intent.EXTRA_SUBJECT, subject); | |
intent.putExtra(Intent.EXTRA_TEXT, content); | |
if (intent.resolveActivity(getPackageManager()) != null) { | |
startActivity(intent); | |
} | |
} | |
} | |
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"?> | |
<resources> | |
<string name="app_name">טופס הזמנת קפה</string> | |
<string name="order">הזמנה</string> | |
<string name="thank_you">תודה רבה!</string> | |
<string name="quantity">כמות</string> | |
<string name="_0">0$</string> | |
<string name="chocoled">שוקולד</string> | |
<string name="whiped_cream">שמנת</string> | |
<string name="topping">תוספות</string> | |
<string name="your_name">שמך:</string> | |
<string name="thank_you_for_123">תודה רבה!</string> | |
<string name="you_add_chocklade">"תוספת שוקולד "</string> | |
<string name="you_add_whipped_cream">תוספת שמנת</string> | |
<string name="you_add_whipped_cream_you_add_chocolate">\nתוספת שמנת ותוספת שוקולד\n</string> | |
<string name="price">מחיר:</string> | |
<string name="Thank_you_for_buying">\nתודה שקנית!\n</string> | |
<string name="your_price_is">\nהמחיר הוא:\n</string> | |
</resources> |
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
<resources> | |
<!-- Base application theme. --> | |
<style name="AppTheme" parent="Theme.AppCompat.Light"> | |
<!-- Primary theme color of the app (sets background color of app bar) --> | |
<item name="colorPrimary">#BCAAA4</item> | |
<!-- Background color of buttons in the app --> | |
<item name="colorButtonNormal">#BCAAA4 | |
</item> | |
</style> | |
<style name="AppTheme.NoActionBar"> | |
<item name="windowActionBar">false</item> | |
<item name="windowNoTitle">true</item> | |
</style> | |
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" /> | |
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" /> | |
</resources> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment