Guest User

Untitled

a guest
Jan 4th, 2018
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.18 KB | None | 0 0
  1. package com.example.android.justjava;
  2.  
  3. import android.content.Intent;
  4. import android.net.Uri;
  5. import android.os.Bundle;
  6. import android.support.v7.app.AppCompatActivity;
  7. import android.view.View;
  8. import android.widget.CheckBox;
  9. import android.widget.EditText;
  10. import android.widget.TextView;
  11. import java.text.NumberFormat;
  12.  
  13. import static android.R.attr.value;
  14. import static android.R.id.checkbox;
  15. import static android.R.id.message;
  16.  
  17. /**
  18. * This app displays an order form to order coffee.
  19. */
  20. public class MainActivity extends AppCompatActivity {
  21.  
  22. @Override
  23. protected void onCreate(Bundle savedInstanceState) {
  24. super.onCreate(savedInstanceState);
  25. setContentView(R.layout.activity_main);
  26. }
  27.  
  28. int topping_price = 0;
  29. /**
  30. * This method is called when the order button is clicked.
  31. */
  32. public void submitOrder(View view) {
  33. String variable1,variable2,variable3;
  34. CheckBox cream = (CheckBox) findViewById(R.id.checkbox);
  35. CheckBox choco = (CheckBox) findViewById(R.id.checkbox_choco);
  36. boolean value1 = cream.isChecked();
  37. boolean value2 = choco.isChecked();
  38.  
  39. if(value1 == true) {
  40. variable1 = "Yes";
  41. topping_price += 1;
  42. }
  43. else
  44. variable1 = "No" ;
  45.  
  46. if(value2 == true) {
  47. variable2 = "Yes";
  48. topping_price += 2;
  49. }
  50.  
  51. else
  52. variable2 = "No" ;
  53.  
  54. EditText input_name = (EditText) findViewById(R.id.name);
  55. variable3 = input_name.getText().toString();
  56.  
  57. if((quantity + count) == 0){
  58. topping_price = 0;
  59. variable1 = "No";
  60. variable2 = "No";
  61. }
  62.  
  63. String price_message = "Whipped cream topping: " + variable1 + "nChocolate topping: " + variable2 +"nName: " + variable3 +"nQuantity: " + (quantity + count) +"nTotal $" + (( quantity + count ) * 10 + topping_price ) + "nThank You";
  64. displayMessage(price_message);
  65. topping_price = 0 ;
  66.  
  67. Intent sendIntent = new Intent(Intent.ACTION_SENDTO);
  68. sendIntent.setType("*/*");
  69. sendIntent.setData(Uri.parse("masquerade0097@gmail.com"));
  70. sendIntent.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail");
  71. sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { "masquerade0097@gmail.com" });
  72. sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Just Java order for " + variable3);
  73. sendIntent.putExtra(Intent.EXTRA_TEXT,"Whipped cream topping: " + variable1 + "nChocolate topping: " + variable2 +"nName: " + variable3 +"nQuantity: " + (quantity + count) +"nTotal $" + (( quantity + count ) * 10 + topping_price ) + "nThank You");
  74. // startActivity(sendIntent);
  75. if (sendIntent.resolveActivity(getPackageManager()) != null) {
  76. startActivity(sendIntent);
  77. }
  78. }
  79.  
  80. /**
  81. * This method displays the given text on the screen.
  82. */
  83. private void displayMessage(String message) {
  84. TextView priceTextView = (TextView) findViewById(R.id.price_text_view);
  85. priceTextView.setText(message);
  86. }
  87.  
  88. int quantity = 1;
  89. int count = 0;
  90.  
  91. public void increment(View view){
  92. if((quantity + count) < 101)
  93. count = count + 1;
  94. display(quantity + count );
  95. displayPrice( (quantity + count) * 10);
  96. }
  97.  
  98. public void decrement(View view){
  99.  
  100. if((quantity + count) != 0)
  101. count = count - 1;
  102.  
  103. display(quantity + count);
  104. displayPrice((quantity + count) * 10);
  105.  
  106. }
  107. /**
  108. * This method displays the given quantity value on the screen.
  109. */
  110. private void display(int number) {
  111. TextView quantityTextView = (TextView) findViewById(R.id.quantity_text_view);
  112. quantityTextView.setText("" + number);
  113. }
  114.  
  115. private void displayPrice(int number){
  116. TextView priceTextView = (TextView) findViewById(R.id.price_text_view);
  117. priceTextView.setText(NumberFormat.getCurrencyInstance().format(number));
  118. }
  119. }
  120.  
  121. Intent intent = new Intent(Intent.ACTION_SEND);
  122. intent.setType("message/rfc822");
  123. intent.putExtra(Intent.EXTRA_TEXT, "Text you want to share");
  124. startActivity(Intent.createChooser(intent, "Send mail..."));
  125.  
  126. Intent sendIntent = new Intent(Intent.ACTION_VIEW);
  127. sendIntent.setData(Uri.parse("test@gmail.com"));
  128. sendIntent.setClassName("com.google.android.gm","com.google.android.gm.ComposeActivityGmail");
  129. sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { "test@gmail.com" });
  130. sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Test");
  131. sendIntent.putExtra(Intent.EXTRA_TEXT, "Test");
  132. startActivity(sendIntent);
  133.  
  134. Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
  135. "mailto", emailId, null));
  136. emailIntent.putExtra(Intent.EXTRA_SUBJECT, "");
  137. emailIntent.putExtra(Intent.EXTRA_TEXT, "");
  138. startActivity(Intent.createChooser(emailIntent, "Send email..."));
  139.  
  140. Intent mailClient = new Intent(Intent.ACTION_VIEW);
  141. mailClient.setClassName("com.google.android.gm", "com.google.android.gm.ConversationListActivity");
  142. startActivity(mailClient);
  143.  
  144. mailClient.putExtra(Intent.EXTRA_EMAIL, new String[] { "hello@gmail.com" });
  145. mailClient.putExtra(Intent.EXTRA_SUBJECT, "hello subject");
  146. mailClient.putExtra(Intent.EXTRA_TEXT, "hello message");
Add Comment
Please, Sign In to add comment