package com.fernandomantoan.ramaispti.android.fragment; import com.fernandomantoan.ramaispti.android.R; import com.fernandomantoan.ramaispti.android.util.Telephony; import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.support.v4.app.DialogFragment; /** * Dialog to choose telephone number when has more than one * * @author inovatic * */ public class NumberChoiceDialogFragment extends DialogFragment { static final String TELEPHONES = "telefones"; static NumberChoiceDialogFragment newInstance(String[] arrayTel) { NumberChoiceDialogFragment f = new NumberChoiceDialogFragment(); Bundle args = new Bundle(); args.putStringArray(TELEPHONES, arrayTel); f.setArguments(args); return f; } @Override public Dialog onCreateDialog(Bundle savedInstanceState) { // Use the Builder class for convenient dialog construction AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(getResources().getString(R.string.escolher_telefone)) .setItems(getArguments().getStringArray(TELEPHONES), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // If the device has dialer and SIM card available if (Telephony.isTelephonyAvailable(getActivity())) { Uri number = Uri.parse("tel:" + getArguments().getStringArray( TELEPHONES)[which]); Intent callIntent = new Intent( Intent.ACTION_DIAL, number); startActivity(callIntent); } } }); // Create the AlertDialog object and return it return builder.create(); } }