Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. package com.ladev.triptosemarang;
  2.  
  3. import android.content.Intent;
  4. import android.net.Uri;
  5. import android.support.v7.app.AppCompatActivity;
  6. import android.os.Bundle;
  7. import android.view.View;
  8. import android.widget.CheckBox;
  9. import android.widget.EditText;
  10. import android.widget.TextView;
  11.  
  12. import static android.R.attr.name;
  13.  
  14. public class MainActivity extends AppCompatActivity {
  15.  
  16. @Override
  17. protected void onCreate(Bundle savedInstanceState) {
  18. super.onCreate(savedInstanceState);
  19. setContentView(R.layout.activity_main);
  20. }
  21.  
  22. public void submitTrip(View view){
  23. EditText nameField = (EditText)findViewById(R.id.name_field);
  24. String name = nameField.getText().toString();
  25.  
  26. CheckBox tuguMuda = (CheckBox)findViewById(R.id.tuguMuda);
  27. boolean hasTuguMuda = tuguMuda.isChecked();
  28. CheckBox lawangSewu = (CheckBox)findViewById(R.id.lawangSewu);
  29. boolean hasLawangSewu = lawangSewu.isChecked();
  30. CheckBox blendukChruch = (CheckBox)findViewById(R.id.blendukChruch);
  31. boolean hasBlendukChruch = blendukChruch.isChecked();
  32. CheckBox greatMosque = (CheckBox)findViewById(R.id.greatMosque);
  33. boolean hasGreatMosque = greatMosque.isChecked();
  34. CheckBox samPooKong = (CheckBox)findViewById(R.id.samPooKong);
  35. boolean hasSamPooKong = samPooKong.isChecked();
  36. CheckBox viharaPagoda = (CheckBox)findViewById(R.id.viharaPagoda);
  37. boolean hasViharaPagoda = viharaPagoda.isChecked();
  38.  
  39. int budgetTrip = countBudget(hasTuguMuda, hasLawangSewu, hasBlendukChruch, hasGreatMosque, hasSamPooKong, hasViharaPagoda);
  40. tripSummary(name, budgetTrip, hasTuguMuda, hasLawangSewu, hasBlendukChruch, hasGreatMosque, hasSamPooKong, hasViharaPagoda);
  41. }
  42.  
  43. private int countBudget(boolean hasTuguMuda, boolean hasLawangSewu, boolean hasBlendukChruch, boolean hasGreatMosque, boolean hasSamPooKong, boolean hasViharaPagoda){
  44. int budget = 0;
  45. if(hasTuguMuda){
  46. budget = budget+10000;
  47. }
  48. if(hasLawangSewu){
  49. budget = budget+20000;
  50. }
  51. if(hasBlendukChruch){
  52. budget = budget+25000;
  53. }
  54. if(hasGreatMosque){
  55. budget = budget+30000;
  56. }
  57. if(hasSamPooKong){
  58. budget = budget+25000;
  59. }
  60. if(hasViharaPagoda){
  61. budget = budget+30000;
  62. }
  63. return budget;
  64. }
  65. public void tripSummary(String name, int budgetTrip, boolean hasTuguMuda, boolean hasLawangSewu, boolean hasBlendukChruch, boolean hasGreatMosque, boolean hasSamPooKong, boolean hasViharaPagoda){
  66. TextView result = (TextView)findViewById(R.id.result_text);
  67. String resultMessage= "Result: \nName: "+name+
  68. "\nTugu Muda? "+hasTuguMuda+
  69. "\nLawang Sewu? "+hasLawangSewu+
  70. "\nBlenduk Chruch? "+hasBlendukChruch+
  71. "\nGreat Mosque of Central Java? "+hasGreatMosque+
  72. "\nSam Poo Kong Temple? "+hasSamPooKong+
  73. "\nVihara Buddhagaya Pagoda? "+hasViharaPagoda+
  74. "\nTotal Budget Trip: "+budgetTrip;
  75. result.setText(resultMessage);
  76.  
  77. Intent intent = new Intent(Intent.ACTION_SENDTO);
  78. intent.setData(Uri.parse("mailto:"));
  79. intent.putExtra(Intent.EXTRA_SUBJECT,"Order Trip To Semarang "+name);
  80. intent.putExtra(Intent.EXTRA_TEXT,resultMessage);
  81.  
  82. if(intent.resolveActivity(getPackageManager())!=null){
  83. startActivity(intent);
  84. }
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement