Advertisement
jumpy83

Untitled

Feb 3rd, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. package it.fontanagianpaolo.www.rubrica;
  2.  
  3. import android.app.DialogFragment;
  4. import android.content.Intent;
  5. import android.net.Uri;
  6. import android.os.Bundle;
  7. import android.view.LayoutInflater;
  8. import android.view.View;
  9. import android.view.ViewGroup;
  10. import android.widget.Button;
  11. import android.widget.TextView;
  12.  
  13. //Dialog che permette di scegliere se chiamare o mandare sms al contatto selezionato
  14.  
  15. public class PhoneDialog extends DialogFragment implements View.OnClickListener {
  16.  
  17.  
  18. private TextView tvContatto;
  19. private Contatto contatto;
  20. private Button btCall;
  21. private Button btSms;
  22.  
  23. public static PhoneDialog createInstance(Contatto contatto) {
  24.  
  25. PhoneDialog frag = new PhoneDialog();
  26. Bundle init = new Bundle();
  27. init.putParcelable("contatto", contatto);
  28. frag.setArguments(init);
  29. return frag;
  30. }
  31.  
  32.  
  33. @Override
  34. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  35. Bundle savedInstanceState) {
  36. View root = inflater.inflate(R.layout.dialog_phone, container,
  37. false);
  38. findViews(root);
  39. setupViews();
  40. return root;
  41. }
  42.  
  43. private void findViews(View root) {
  44.  
  45.  
  46. btCall = (Button) root.findViewById(R.id.btCall);
  47. btSms = (Button) root.findViewById(R.id.btSms);
  48. tvContatto = (TextView) root.findViewById(R.id.tvContatto);
  49.  
  50. }
  51.  
  52.  
  53. private void setupViews() {
  54.  
  55. if (getArguments() != null) {
  56. contatto = (Contatto) getArguments().getParcelable("contatto");
  57.  
  58. tvContatto.setText(contatto.getName() + " " + " \n" + contatto.getLastname());
  59. btCall.setOnClickListener(this);
  60. btSms.setOnClickListener(this);
  61. }
  62. }
  63.  
  64. @Override
  65. public void onClick(View v) {
  66. int id = v.getId();
  67. if (id == R.id.btCall) {
  68. callContatto();
  69. }
  70.  
  71. else if (id == R.id.btSms){
  72. sendMessage();
  73. }
  74.  
  75. }
  76.  
  77. private void callContatto() {
  78. Intent callIntent = new Intent(Intent.ACTION_CALL);
  79. callIntent.setData(Uri.parse("tel:" + Uri.encode(contatto.getPhone())));
  80. callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  81. startActivity(callIntent);
  82. }
  83.  
  84. private void sendMessage () {
  85. /* Intent sendMessage = new Intent (Intent.ACTION_SENDTO);
  86. sendMessage.setData(Uri.parse("tel:" + Uri.encode(contatto.getPhone())));
  87. sendMessage.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  88. startActivity(sendMessage);*/
  89.  
  90. Intent sendIntent = new Intent(Intent.ACTION_VIEW);
  91. // sendIntent.setData(Uri.parse("tel:" + Uri.encode(contatto.getPhone())));
  92. //sendIntent.putExtra("sms_body", "default content");
  93. sendIntent.setType("vnd.android-dir/mms-sms");
  94. sendIntent.putExtra("address", contatto.getPhone());
  95. startActivity(sendIntent);
  96.  
  97.  
  98. // SmsManager sms = SmsManager.getDefault();
  99. // sms.sendTextMessage(contatto.getPhone(), null, String.valueOf(sms), null, null);
  100. }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement