Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.ladev.triptosemarang;
- import android.content.Intent;
- import android.net.Uri;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.CheckBox;
- import android.widget.EditText;
- import android.widget.TextView;
- import static android.R.attr.name;
- public class MainActivity extends AppCompatActivity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- }
- public void submitTrip(View view){
- EditText nameField = (EditText)findViewById(R.id.name_field);
- String name = nameField.getText().toString();
- CheckBox tuguMuda = (CheckBox)findViewById(R.id.tuguMuda);
- boolean hasTuguMuda = tuguMuda.isChecked();
- CheckBox lawangSewu = (CheckBox)findViewById(R.id.lawangSewu);
- boolean hasLawangSewu = lawangSewu.isChecked();
- CheckBox blendukChruch = (CheckBox)findViewById(R.id.blendukChruch);
- boolean hasBlendukChruch = blendukChruch.isChecked();
- CheckBox greatMosque = (CheckBox)findViewById(R.id.greatMosque);
- boolean hasGreatMosque = greatMosque.isChecked();
- CheckBox samPooKong = (CheckBox)findViewById(R.id.samPooKong);
- boolean hasSamPooKong = samPooKong.isChecked();
- CheckBox viharaPagoda = (CheckBox)findViewById(R.id.viharaPagoda);
- boolean hasViharaPagoda = viharaPagoda.isChecked();
- int budgetTrip = countBudget(hasTuguMuda, hasLawangSewu, hasBlendukChruch, hasGreatMosque, hasSamPooKong, hasViharaPagoda);
- tripSummary(name, budgetTrip, hasTuguMuda, hasLawangSewu, hasBlendukChruch, hasGreatMosque, hasSamPooKong, hasViharaPagoda);
- }
- private int countBudget(boolean hasTuguMuda, boolean hasLawangSewu, boolean hasBlendukChruch, boolean hasGreatMosque, boolean hasSamPooKong, boolean hasViharaPagoda){
- int budget = 0;
- if(hasTuguMuda){
- budget = budget+10000;
- }
- if(hasLawangSewu){
- budget = budget+20000;
- }
- if(hasBlendukChruch){
- budget = budget+25000;
- }
- if(hasGreatMosque){
- budget = budget+30000;
- }
- if(hasSamPooKong){
- budget = budget+25000;
- }
- if(hasViharaPagoda){
- budget = budget+30000;
- }
- return budget;
- }
- public void tripSummary(String name, int budgetTrip, boolean hasTuguMuda, boolean hasLawangSewu, boolean hasBlendukChruch, boolean hasGreatMosque, boolean hasSamPooKong, boolean hasViharaPagoda){
- TextView result = (TextView)findViewById(R.id.result_text);
- String resultMessage= "Result: \nName: "+name+
- "\nTugu Muda? "+hasTuguMuda+
- "\nLawang Sewu? "+hasLawangSewu+
- "\nBlenduk Chruch? "+hasBlendukChruch+
- "\nGreat Mosque of Central Java? "+hasGreatMosque+
- "\nSam Poo Kong Temple? "+hasSamPooKong+
- "\nVihara Buddhagaya Pagoda? "+hasViharaPagoda+
- "\nTotal Budget Trip: "+budgetTrip;
- result.setText(resultMessage);
- Intent intent = new Intent(Intent.ACTION_SENDTO);
- intent.setData(Uri.parse("mailto:"));
- intent.putExtra(Intent.EXTRA_SUBJECT,"Order Trip To Semarang "+name);
- intent.putExtra(Intent.EXTRA_TEXT,resultMessage);
- if(intent.resolveActivity(getPackageManager())!=null){
- startActivity(intent);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement