package com.karan.android.activity;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;

import com.karan.android.R;

public class DetailActivity extends Activity {
    String email = "", phone = "", name = "";
    private TextView nameTV, emailTV, phoneTV;
    private ImageButton callButton, smsButton, emailButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detail);
        nameTV = (TextView) findViewById(R.id.nameTV);
        phoneTV = (TextView) findViewById(R.id.mobileTV);
        emailTV = (TextView) findViewById(R.id.emailTV);
        callButton = (ImageButton) findViewById(R.id.callButton);
        smsButton = (ImageButton) findViewById(R.id.smsButton);
        emailButton = (ImageButton) findViewById(R.id.mailButton);
        parseIntent();
        setTextViewData();
        setOnClickListeners();
    }


    private void parseIntent() {
        try {
            Bundle b = getIntent().getExtras();
            name = b.getString("name");
            phone = b.getString("phone");
            email = b.getString("email");
        } catch (Exception e) {
            e.printStackTrace();
        }


    }

    private void setTextViewData() {

        nameTV.setText(name);
        emailTV.setText(email);
        phoneTV.setText(phone);
    }

    private void setOnClickListeners() {
        callButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Uri callNumUri = Uri.parse("tel:" + phone);
                Intent callIntent = new Intent(Intent.ACTION_DIAL, callNumUri);
                startActivity(callIntent);

            }
        });
        smsButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Uri smsNumUri = Uri.parse("smsto:" + phone);
                Intent smsIntent = new Intent(Intent.ACTION_SENDTO, smsNumUri);
                startActivity(smsIntent);
            }
        });
        emailButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);


                String aEmailList[] = { email };

                emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);


                emailIntent.setType("plain/text");

                startActivity(emailIntent);

            }
        });


    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_detail, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

@@ -1135,25 +1135,28 @@
 rs();%0A    %7D%0A
-%0A
+    
 %0A    private
@@ -1438,18 +1438,16 @@
       %7D%0A
-%0A%0A
     %7D%0A%0A 
@@ -1478,25 +1478,24 @@
 iewData() %7B%0A
-%0A
         name
@@ -1933,33 +1933,32 @@
 ty(callIntent);%0A
-%0A
             %7D%0A  
@@ -2444,17 +2444,16 @@
 view) %7B%0A
-%0A
         
@@ -2529,18 +2529,16 @@
 _SEND);%0A
-%0A%0A
         
@@ -2578,17 +2578,16 @@
 mail %7D;%0A
-%0A
         
@@ -2664,18 +2664,16 @@
 lList);%0A
-%0A%0A
         
@@ -2715,17 +2715,16 @@
 text%22);%0A
-%0A
         
@@ -2759,17 +2759,16 @@
 ntent);%0A
-%0A
         
@@ -2765,32 +2765,32 @@
 ;%0A            %7D%0A
+
         %7D);%0A%0A%0A  
@@ -2785,18 +2785,16 @@
     %7D);%0A
-%0A%0A
     %7D%0A%0A 

Update DetailActivity