Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package justjava.alessiosferro.com.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 android.widget.Toast;
- import java.text.NumberFormat;
- public class MainActivity extends AppCompatActivity {
- // Attributi Privati
- private EditText editText;
- private CheckBox checkBox;
- private TextView quantity;
- private TextView price;
- private TextView finalPrice;
- private TextView summary;
- private TextView orders;
- private TextView whippedCream;
- private TextView name;
- private int var;
- private boolean order;
- // Metodo protetto (ereditato da AppCompatActivity)
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- editText = (EditText) findViewById(R.id.editText);
- checkBox = (CheckBox) findViewById(R.id.prova_check_box);
- quantity = (TextView) findViewById(R.id.quantity_text_view);
- price = (TextView) findViewById(R.id.price_text_view);
- finalPrice = (TextView) findViewById(R.id.finalPrice);
- summary = (TextView) findViewById(R.id.summary);
- orders = (TextView) findViewById(R.id.orders);
- whippedCream = (TextView) findViewById(R.id.panna);
- name = (TextView) findViewById(R.id.nome);
- order = false;
- }
- // Metodi pubblici
- /**
- * Questo metodo resetta le textView a default alla pressione del bottone CANCELLA
- * @param view prende la view come parametro
- */
- public void canc(View view){
- editText.setText("");
- checkBox.setChecked(false);
- quantity.setText("0");
- price.setText("0,00 €");
- finalPrice.setText("");
- summary.setText("");
- orders.setText("");
- whippedCream.setText("");
- name.setText("");
- var = 0;
- order = false;
- }
- /**
- * Questo metodo imposta un ordine alla pressione del bottone ORDINA
- * @param view prende la view corrente come parametro
- */
- public void submitOrder(View view) {
- if(editText.length() == 0){
- Toast.makeText(MainActivity.this, "Inserisci il nome!", Toast.LENGTH_LONG).show();
- return;
- }else if(var == 0){
- Toast.makeText(MainActivity.this, "Nessun ordine inserito!", Toast.LENGTH_LONG).show();
- return;
- }
- order = true;
- summary.setText("Riepilogo ordine");
- orders.setText("Numero ordini: " + quantity.getText());
- finalPrice.setText("Prezzo: " + price.getText());
- if(checkBox.isChecked()){
- whippedCream.setText("Panna: SI");
- }else{
- whippedCream.setText("Panna: NO");
- }
- name.setText("Nome: " + editText.getText());
- }
- /**
- * Questo metodo invoca il metodo composeEmail alla pressione del bottone EMAIL
- * @param view prende la view corrente come parametro
- */
- public void email(View view){
- if(!order){
- Toast.makeText(MainActivity.this, "Ordina qualcosa!", Toast.LENGTH_LONG).show();
- return;
- }
- composeEmail("" + summary.getText() + "\n" + name.getText() + "\n" + orders.getText() + "\n"
- + whippedCream.getText() + "\n" + finalPrice.getText(), "Ordine");
- }
- public void pannaMont(View view){
- if(checkBox.isChecked())
- price.setText(NumberFormat.getCurrencyInstance().format(var*.80));
- else
- price.setText(NumberFormat.getCurrencyInstance().format(var*.50));
- }
- public void increment(View view){
- var++;
- quantity.setText("" + var);
- displayPrice();
- }
- public void decrement(View view){
- if(var > 0) {
- var--;
- quantity.setText("" + var);
- displayPrice();
- }else{
- Toast.makeText(MainActivity.this, "Impossibile decrementare", Toast.LENGTH_SHORT).show();
- }
- }
- /**
- * Questo metodo crea un intent per le app di posta elettronica
- * @param body corpo dell'email
- * @param subject oggetto dell'email
- */
- public void composeEmail(String body, String subject) {
- Intent intent = new Intent(Intent.ACTION_SENDTO);
- intent.setData(Uri.parse("mailto:")); // only email apps should handle this
- intent.putExtra(Intent.EXTRA_TEXT, body);
- intent.putExtra(Intent.EXTRA_SUBJECT, subject);
- if (intent.resolveActivity(getPackageManager()) != null) {
- startActivity(intent);
- }
- }
- }
Add Comment
Please, Sign In to add comment