Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package it.fontanagianpaolo.www.rubrica;
- import android.app.DialogFragment;
- import android.content.Intent;
- import android.net.Uri;
- import android.os.Bundle;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.Button;
- import android.widget.TextView;
- //Dialog che permette di scegliere se chiamare o mandare sms al contatto selezionato
- public class PhoneDialog extends DialogFragment implements View.OnClickListener {
- private TextView tvContatto;
- private Contatto contatto;
- private Button btCall;
- private Button btSms;
- public static PhoneDialog createInstance(Contatto contatto) {
- PhoneDialog frag = new PhoneDialog();
- Bundle init = new Bundle();
- init.putParcelable("contatto", contatto);
- frag.setArguments(init);
- return frag;
- }
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- View root = inflater.inflate(R.layout.dialog_phone, container,
- false);
- findViews(root);
- setupViews();
- return root;
- }
- private void findViews(View root) {
- btCall = (Button) root.findViewById(R.id.btCall);
- btSms = (Button) root.findViewById(R.id.btSms);
- tvContatto = (TextView) root.findViewById(R.id.tvContatto);
- }
- private void setupViews() {
- if (getArguments() != null) {
- contatto = (Contatto) getArguments().getParcelable("contatto");
- tvContatto.setText(contatto.getName() + " " + " \n" + contatto.getLastname());
- btCall.setOnClickListener(this);
- btSms.setOnClickListener(this);
- }
- }
- @Override
- public void onClick(View v) {
- int id = v.getId();
- if (id == R.id.btCall) {
- callContatto();
- }
- else if (id == R.id.btSms){
- sendMessage();
- }
- }
- private void callContatto() {
- Intent callIntent = new Intent(Intent.ACTION_CALL);
- callIntent.setData(Uri.parse("tel:" + Uri.encode(contatto.getPhone())));
- callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- startActivity(callIntent);
- }
- private void sendMessage () {
- /* Intent sendMessage = new Intent (Intent.ACTION_SENDTO);
- sendMessage.setData(Uri.parse("tel:" + Uri.encode(contatto.getPhone())));
- sendMessage.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- startActivity(sendMessage);*/
- Intent sendIntent = new Intent(Intent.ACTION_VIEW);
- // sendIntent.setData(Uri.parse("tel:" + Uri.encode(contatto.getPhone())));
- //sendIntent.putExtra("sms_body", "default content");
- sendIntent.setType("vnd.android-dir/mms-sms");
- sendIntent.putExtra("address", contatto.getPhone());
- startActivity(sendIntent);
- // SmsManager sms = SmsManager.getDefault();
- // sms.sendTextMessage(contatto.getPhone(), null, String.valueOf(sms), null, null);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement