Example usage for android.app AlertDialog.Builder show

List of usage examples for android.app AlertDialog.Builder show

Introduction

In this page you can find the example usage for android.app AlertDialog.Builder show.

Prototype

public void show() 

Source Link

Document

Start the dialog and display it on screen.

Usage

From source file:com.guardtrax.ui.screens.HomeScreen.java

private void camera_click() {
    AlertDialog.Builder dialog = new AlertDialog.Builder(HomeScreen.this);
    dialog.setTitle("Camera");
    dialog.setMessage("Snap a Picture?");

    dialog.setPositiveButton("Snap", new DialogInterface.OnClickListener() {
        @Override//from ww  w.ja  va 2s  .co m
        public void onClick(DialogInterface dialog, int which) {
            try {
                //Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
                cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                String path = GTConstants.sendfileFolder + Utility.createFileName() + ".jpg";
                file_name = path;

                File file = new File(path);
                Uri outputFileUri = Uri.fromFile(file);
                cameraIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, outputFileUri);
                startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
            } catch (Exception e) {

            }
        }
    });

    dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
        }
    });

    dialog.setNeutralButton("View", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            galleryIntent = new Intent(Intent.ACTION_PICK,
                    android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            startActivityForResult(galleryIntent, ACTIVITY_SELECT_IMAGE);
        }
    });
    dialog.show();
}

From source file:edu.mit.viral.shen.DroidFish.java

private final Dialog moveListMenuDialog() {
    final int EDIT_HEADERS = 0;
    final int EDIT_COMMENTS = 1;
    final int REMOVE_SUBTREE = 2;
    final int MOVE_VAR_UP = 3;
    final int MOVE_VAR_DOWN = 4;
    final int ADD_NULL_MOVE = 5;

    List<CharSequence> lst = new ArrayList<CharSequence>();
    List<Integer> actions = new ArrayList<Integer>();
    // lst.add(getString(R.string.edit_headers));      actions.add(EDIT_HEADERS);
    // if (ctrl.humansTurn()) {
    lst.add(getString(R.string.edit_comments));
    actions.add(EDIT_COMMENTS);// w w w  .ja  v  a 2  s .c  o m
    // }
    // lst.add(getString(R.string.truncate_gametree)); actions.add(REMOVE_SUBTREE);
    // if (ctrl.numVariations() > 1) {
    //     lst.add(getString(R.string.move_var_up));   actions.add(MOVE_VAR_UP);
    //     lst.add(getString(R.string.move_var_down)); actions.add(MOVE_VAR_DOWN);
    // }

    boolean allowNullMove = gameMode.analysisMode()
            || (gameMode.playerWhite() && gameMode.playerBlack() && !gameMode.clocksActive());
    if (allowNullMove) {
        lst.add(getString(R.string.add_null_move));
        actions.add(ADD_NULL_MOVE);
    }
    final List<Integer> finalActions = actions;
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.edit_game);
    builder.setItems(lst.toArray(new CharSequence[lst.size()]), new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int item) {
            switch (finalActions.get(item)) {
            case EDIT_HEADERS: {
                final TreeMap<String, String> headers = new TreeMap<String, String>();
                ctrl.getHeaders(headers);

                AlertDialog.Builder builder = new AlertDialog.Builder(DroidFish.this);
                builder.setTitle(R.string.edit_headers);
                View content = View.inflate(DroidFish.this, R.layout.edit_headers, null);
                builder.setView(content);

                final TextView event, site, date, round, white, black;

                event = (TextView) content.findViewById(R.id.ed_header_event);
                site = (TextView) content.findViewById(R.id.ed_header_site);
                date = (TextView) content.findViewById(R.id.ed_header_date);
                round = (TextView) content.findViewById(R.id.ed_header_round);
                white = (TextView) content.findViewById(R.id.ed_header_white);
                black = (TextView) content.findViewById(R.id.ed_header_black);

                event.setText(headers.get("Event"));
                site.setText(headers.get("Site"));
                date.setText(headers.get("Date"));
                round.setText(headers.get("Round"));
                white.setText(headers.get("White"));
                black.setText(headers.get("Black"));

                builder.setNegativeButton(R.string.cancel, null);
                builder.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        headers.put("Event", event.getText().toString().trim());
                        headers.put("Site", site.getText().toString().trim());
                        headers.put("Date", date.getText().toString().trim());
                        headers.put("Round", round.getText().toString().trim());
                        headers.put("White", white.getText().toString().trim());
                        headers.put("Black", black.getText().toString().trim());
                        ctrl.setHeaders(headers);
                        setBoardFlip(true);
                    }
                });

                builder.show();
                break;
            }
            case EDIT_COMMENTS: {
                AlertDialog.Builder builder = new AlertDialog.Builder(DroidFish.this);
                builder.setTitle(R.string.edit_comments);
                View content = View.inflate(DroidFish.this, R.layout.edit_comments, null);
                builder.setView(content);

                DroidChessController.CommentInfo commInfo = ctrl.getComments();

                final TextView preComment, moveView, nag, postComment;
                preComment = (TextView) content.findViewById(R.id.ed_comments_pre);
                moveView = (TextView) content.findViewById(R.id.ed_comments_move);
                nag = (TextView) content.findViewById(R.id.ed_comments_nag);
                postComment = (TextView) content.findViewById(R.id.ed_comments_post);

                preComment.setText(commInfo.preComment);
                postComment.setText(commInfo.postComment);
                moveView.setText(commInfo.move);
                String nagStr = Node.nagStr(commInfo.nag).trim();
                if ((nagStr.length() == 0) && (commInfo.nag > 0))
                    nagStr = String.format(Locale.US, "%d", commInfo.nag);
                nag.setText(nagStr);

                builder.setNegativeButton(R.string.cancel, null);
                builder.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        String pre = preComment.getText().toString().trim();
                        String post = postComment.getText().toString().trim();
                        int nagVal = Node.strToNag(nag.getText().toString());

                        DroidChessController.CommentInfo commInfo = new DroidChessController.CommentInfo();
                        commInfo.preComment = pre;
                        commInfo.postComment = post;
                        commInfo.nag = nagVal;
                        ctrl.setComments(commInfo);
                    }
                });

                builder.show();
                break;
            }
            case REMOVE_SUBTREE:
                ctrl.removeSubTree();
                break;
            case MOVE_VAR_UP:
                ctrl.moveVariation(-1);
                break;
            case MOVE_VAR_DOWN:
                ctrl.moveVariation(1);
                break;
            case ADD_NULL_MOVE:
                ctrl.makeHumanNullMove();
                break;
            }
            moveListMenuDlg = null;
        }
    });
    AlertDialog alert = builder.create();
    moveListMenuDlg = alert;
    return alert;
}

From source file:com.guardtrax.ui.screens.HomeScreen.java

private void send_media_via_email(final String type) {
    //only send email if "allowed"
    if (Utility.allowSend(HomeScreen.this)) {
        AlertDialog.Builder dialog = new AlertDialog.Builder(HomeScreen.this);
        dialog.setTitle("email the media?");
        dialog.setMessage("Enter Email address");
        final EditText input = new EditText(this);
        dialog.setView(input);//from  w  w w.j  a va 2 s  .  c  o  m

        dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                String emailAddress = input.getText().toString().trim();
                File current_file = new File(file_name);
                //String attachment = GTConstants.receivefileFolder + current_file.getName();
                ArrayList<String> mediaList = new ArrayList<String>();
                mediaList.add(GTConstants.receivefileFolder + current_file.getName());

                if (type.equalsIgnoreCase("audio"))
                    Utility.send_email(HomeScreen.this, emailAddress, mediaList, "audio",
                            "email from GT android App",
                            "This email is being sent directly from the GuardTrax - Android App");
                if (type.equalsIgnoreCase("photo"))
                    Utility.send_email(HomeScreen.this, emailAddress, mediaList, "photo",
                            "email from GT android App",
                            "This email is being sent directly from the GuardTrax - Android App");
                if (type.equalsIgnoreCase("video"))
                    Utility.send_email(HomeScreen.this, emailAddress, mediaList, "video",
                            "email from GT android App",
                            "This email is being sent directly from the GuardTrax - Android App");
            }
        });

        //if no email to be sent then exit
        dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {

            }
        });
        dialog.show();
    }
}

From source file:me.ububble.speakall.fragment.ConversationGroupFragment.java

private void choosePicture() {
    if (cameraDialog == null) {
        LayoutInflater dialogInflater = (LayoutInflater) activity
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        final View dialogView = dialogInflater.inflate(R.layout.dialog_camera_gallery, null);
        TextView camera = (TextView) dialogView.findViewById(R.id.dialog_camera);
        TextView gallery = (TextView) dialogView.findViewById(R.id.dialog_gallery);
        TFCache.apply(activity, camera, TFCache.TF_SPEAKALL);
        TFCache.apply(activity, gallery, TFCache.TF_SPEAKALL);
        final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity).setView(dialogView)
                .setCancelable(true);//from   w  w  w .  ja  v a  2  s.com
        cameraDialog = dialogBuilder.show();
        camera.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                cameraDialog.dismiss();
                dontClose = true;
                ((MainActivity) activity).dontClose = true;
                hideKeyBoard();
                File imagesFolder = new File(
                        Environment.getExternalStorageDirectory().getAbsolutePath() + "/SpeakOn/Image/Sent");
                imagesFolder.mkdirs();
                menuAdjunt = false;
                adjuntLayout.setVisibility(View.GONE);
                dateToCamera = Calendar.getInstance().getTimeInMillis();
                File image = new File(imagesFolder, dateToCamera + ".png");
                Uri uriSavedImage = Uri.fromFile(image);
                pictureActionIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                pictureActionIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
                startActivityForResult(pictureActionIntent, 23);
            }
        });
        gallery.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                cameraDialog.dismiss();
                dontClose = true;
                ((MainActivity) activity).dontClose = true;
                hideKeyBoard();
                menuAdjunt = false;
                adjuntLayout.setVisibility(View.GONE);
                pictureActionIntent = new Intent(Intent.ACTION_PICK,
                        android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                startActivityForResult(pictureActionIntent, 1);
            }
        });
        cameraDialog.setCanceledOnTouchOutside(true);
    } else {
        cameraDialog.show();
    }
}

From source file:com.guardtrax.ui.screens.HomeScreen.java

private void showAlert(final String title, final String message, boolean OKOnly) {
    AlertDialog.Builder dialog = new AlertDialog.Builder(HomeScreen.this);
    dialog.setCancelable(false);/* w ww  .  jav  a  2s .  c  o m*/
    dialog.setTitle(title);
    dialog.setMessage(message);
    dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int place) {
            //if device not registered go straight to scan screen
            if (!Utility.deviceRegistered())
                scan_click(false);

            //if OK entered from updateSync then reboot
            if (restartsyncTimer) {
                Intent restartIntent = getPackageManager().getLaunchIntentForPackage(getPackageName());
                PendingIntent intent = PendingIntent.getActivity(HomeScreen.this, 0, restartIntent,
                        Intent.FLAG_ACTIVITY_CLEAR_TOP);
                AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
                manager.set(AlarmManager.RTC, System.currentTimeMillis() + 500, intent);
                System.exit(2);
            }

            if (taa == 5) {
                taa = 3; //when returning to onResume from signature screen this will execute specific code inside onResume
                signaturefileName = Utility.createSignatureFileName();
                Intent intent = new Intent();
                intent.setClass(HomeScreen.this, SignatureScreen.class);
                intent.putExtra("file_name", Utility.getsharedPreference(HomeScreen.this, "signaturefileName"));
                startActivity(intent);
            }
        }
    });

    if (!OKOnly) {
        dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int place) {
                if (taa == 5) {
                    taa = 3; //tells onResume to execute end shift code
                    onResume();
                }
            }
        });
    }
    dialog.show();
}

From source file:me.ububble.speakall.fragment.ConversationGroupFragment.java

public void checkCountryLocation(final boolean gpsProvider, final boolean netProvider) {
    getActivity().runOnUiThread(new Runnable() {
        @Override/*from   www  .j  ava2  s. com*/
        public void run() {
            boolean gpsEnabled = false;
            boolean networkEnabled = false;
            if (gpsProvider) {
                gpsEnabled = milocManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
            }
            if (netProvider) {
                networkEnabled = milocManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
            }
            if (gpsProvider && netProvider) {
                if (!gpsEnabled && !networkEnabled) {
                    LayoutInflater dialogInflater = (LayoutInflater) activity
                            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                    dialogView = dialogInflater.inflate(R.layout.null_contact_dialog, null);
                    TextView mensaje = (TextView) dialogView.findViewById(R.id.dialog_add_contact);
                    mensaje.setText(getString(R.string.location_services));
                    final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity)
                            .setView(dialogView).setCancelable(true)
                            .setPositiveButton(R.string.add_contact_yes, null)
                            .setNegativeButton(R.string.add_contact_no, null);
                    finderDialog = dialogBuilder.show();
                    finderDialog.setCanceledOnTouchOutside(true);
                    finderDialog.getButton(DialogInterface.BUTTON_POSITIVE)
                            .setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    finderDialog.dismiss();
                                    System.gc();
                                    dontClose = true;
                                    ((MainActivity) activity).dontClose = true;
                                    Intent intent = new Intent(
                                            android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                                    startActivityForResult(intent, 45);
                                }
                            });
                    finderDialog.getButton(DialogInterface.BUTTON_NEGATIVE)
                            .setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    finderDialog.dismiss();
                                }
                            });
                } else {
                    milocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
                            ConversationGroupFragment.this);
                    milocManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0,
                            ConversationGroupFragment.this);
                }
            }
        }
    });
}

From source file:me.ububble.speakall.fragment.ConversationGroupFragment.java

public void showDialogAddContact(final String contacto) {
    final boolean[] agregar = { false };
    try {/*from  w w w  . java2 s.c o m*/
        final ContentResolver contentResolver = activity.getContentResolver();
        final JSONObject contact = new JSONObject(contacto);
        String name = null;
        String phone = null;

        String selectionArgs = ContactsContract.Contacts.DISPLAY_NAME + " = ? AND "
                + ContactsContract.CommonDataKinds.Phone.TYPE + "= "
                + ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE;

        Cursor c = contentResolver.query(ContactsContract.Data.CONTENT_URI,
                new String[] { ContactsContract.CommonDataKinds.Phone.NUMBER }, selectionArgs,
                new String[] { contact.getString("nombre") }, null);

        if (c.getCount() > 0) {
            if (c.moveToFirst()) {
                phone = c.getString(0);
            }
            if (phone.equals(contact.getString("telefono"))) {
                Toast.makeText(activity, "Ya tienes este contacto", Toast.LENGTH_SHORT).show();
            } else {
                LayoutInflater dialogInflater = (LayoutInflater) activity
                        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                dialogView = dialogInflater.inflate(R.layout.add_contact_message, null);
                final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity).setView(dialogView)
                        .setCancelable(true).setPositiveButton(R.string.add_contact_yes, null)
                        .setNegativeButton(R.string.add_contact_no, null);
                finderDialog = dialogBuilder.show();
                finderDialog.setCanceledOnTouchOutside(true);
                finderDialog.getButton(DialogInterface.BUTTON_POSITIVE)
                        .setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                try {
                                    finderDialog.dismiss();
                                    agregar[0] = true;
                                    if (agregar[0]) {
                                        ContentValues values = new ContentValues();
                                        values.put(ContactsContract.Data.DISPLAY_NAME,
                                                contact.getString("nombre"));
                                        Uri rawContactUri = contentResolver
                                                .insert(ContactsContract.RawContacts.CONTENT_URI, values);

                                        long rawContactId = ContentUris.parseId(rawContactUri);
                                        long contactId = ContentUris.parseId(rawContactUri);

                                        values.clear();
                                        values.put(ContactsContract.CommonDataKinds.Phone.NUMBER,
                                                contact.getString("telefono"));
                                        values.put(ContactsContract.CommonDataKinds.Phone.TYPE,
                                                ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE);
                                        values.put(ContactsContract.Contacts.Data.RAW_CONTACT_ID, rawContactId);
                                        contentResolver.insert(ContactsContract.Data.CONTENT_URI, values);

                                    }
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                            }
                        });
                finderDialog.getButton(DialogInterface.BUTTON_NEGATIVE)
                        .setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                finderDialog.dismiss();
                                agregar[0] = false;
                            }
                        });
            }
        } else {
            LayoutInflater dialogInflater = (LayoutInflater) activity
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            dialogView = dialogInflater.inflate(R.layout.add_contact_message, null);
            final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity).setView(dialogView)
                    .setCancelable(true).setPositiveButton(R.string.add_contact_yes, null)
                    .setNegativeButton(R.string.add_contact_no, null);
            finderDialog = dialogBuilder.show();
            finderDialog.setCanceledOnTouchOutside(true);
            finderDialog.getButton(DialogInterface.BUTTON_POSITIVE)
                    .setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            try {
                                finderDialog.dismiss();
                                agregar[0] = true;
                                if (agregar[0]) {
                                    ContentValues values = new ContentValues();
                                    values.put(ContactsContract.Data.DISPLAY_NAME, contact.getString("nombre"));
                                    Uri rawContactUri = contentResolver
                                            .insert(ContactsContract.RawContacts.CONTENT_URI, values);

                                    long rawContactId = ContentUris.parseId(rawContactUri);

                                    values.clear();
                                    values.put(android.provider.ContactsContract.Data.MIMETYPE,
                                            ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
                                    values.put(ContactsContract.CommonDataKinds.Phone.NUMBER,
                                            contact.getString("telefono"));
                                    values.put(ContactsContract.CommonDataKinds.Phone.TYPE,
                                            ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE);
                                    values.put(ContactsContract.Contacts.Data.RAW_CONTACT_ID, rawContactId);
                                    contentResolver.insert(ContactsContract.Data.CONTENT_URI, values);

                                    values.clear();
                                    values.put(ContactsContract.Contacts.Data.MIMETYPE,
                                            ContactsContract.Data.CONTENT_TYPE);
                                    values.put(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME,
                                            contact.getString("nombre"));
                                    values.put(ContactsContract.Contacts.Data.RAW_CONTACT_ID, rawContactId);
                                    contentResolver.insert(ContactsContract.Data.CONTENT_URI, values);

                                    values.clear();
                                    values.put(ContactsContract.Contacts.Data.MIMETYPE,
                                            ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE);
                                    values.put(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME,
                                            contact.getString("nombre"));
                                    values.put(ContactsContract.Contacts.Data.RAW_CONTACT_ID, rawContactId);
                                    contentResolver.insert(ContactsContract.Data.CONTENT_URI, values);

                                }
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                        }
                    });
            finderDialog.getButton(DialogInterface.BUTTON_NEGATIVE)
                    .setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            finderDialog.dismiss();
                            agregar[0] = false;
                        }
                    });
        }
        c.close();
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:me.ububble.speakall.fragment.ConversationChatFragment.java

public void checkCountryLocation(final boolean gpsProvider, final boolean netProvider) {
    getActivity().runOnUiThread(new Runnable() {
        @Override//from w w w  . j  a v a2s  .  co  m
        public void run() {
            boolean gpsEnabled = false;
            boolean networkEnabled = false;
            if (gpsProvider) {
                gpsEnabled = milocManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
            }
            if (netProvider) {
                networkEnabled = milocManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
            }
            if (gpsProvider && netProvider) {
                if (!gpsEnabled && !networkEnabled) {
                    LayoutInflater dialogInflater = (LayoutInflater) activity
                            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                    dialogView = dialogInflater.inflate(R.layout.null_contact_dialog, null);
                    TextView mensaje = (TextView) dialogView.findViewById(R.id.dialog_add_contact);
                    mensaje.setText(getString(R.string.location_services));
                    final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity)
                            .setView(dialogView).setCancelable(true)
                            .setPositiveButton(R.string.add_contact_yes, null)
                            .setNegativeButton(R.string.add_contact_no, null);
                    finderDialog = dialogBuilder.show();
                    finderDialog.setCanceledOnTouchOutside(true);
                    finderDialog.getButton(DialogInterface.BUTTON_POSITIVE)
                            .setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    finderDialog.dismiss();
                                    System.gc();
                                    dontClose = true;
                                    ((MainActivity) activity).dontClose = true;
                                    hideKeyBoard();
                                    Intent intent = new Intent(
                                            android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                                    startActivityForResult(intent, 45);
                                }
                            });
                    finderDialog.getButton(DialogInterface.BUTTON_NEGATIVE)
                            .setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    finderDialog.dismiss();
                                }
                            });
                } else {
                    milocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
                            ConversationChatFragment.this);
                    milocManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0,
                            ConversationChatFragment.this);
                }
            }
        }
    });
}

From source file:me.ububble.speakall.fragment.ConversationChatFragment.java

public void showDialogAddContact(final String contacto) {
    final boolean[] agregar = { false };
    try {//from w  w  w .j  a v a2  s  . c  om
        final ContentResolver contentResolver = activity.getContentResolver();
        final JSONObject contact = new JSONObject(contacto);
        String name = null;
        String phone = null;

        String selectionArgs = ContactsContract.Contacts.DISPLAY_NAME + " = ? AND "
                + ContactsContract.CommonDataKinds.Phone.TYPE + "= "
                + ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE;

        Cursor c = contentResolver.query(ContactsContract.Data.CONTENT_URI,
                new String[] { ContactsContract.CommonDataKinds.Phone.NUMBER }, selectionArgs,
                new String[] { contact.getString("nombre") }, null);

        if (c.getCount() > 0) {
            if (c.moveToFirst()) {
                phone = c.getString(0);
            }
            if (phone.equals(contact.getString("telefono"))) {
                Toast.makeText(activity, "Ya tienes este contacto", Toast.LENGTH_SHORT).show();
            } else {
                LayoutInflater dialogInflater = (LayoutInflater) activity
                        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                dialogView = dialogInflater.inflate(R.layout.add_contact_message, null);
                final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity).setView(dialogView)
                        .setCancelable(true).setPositiveButton(R.string.add_contact_yes, null)
                        .setNegativeButton(R.string.add_contact_no, null);
                finderDialog = dialogBuilder.show();
                finderDialog.setCanceledOnTouchOutside(true);
                finderDialog.getButton(DialogInterface.BUTTON_POSITIVE)
                        .setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                try {
                                    finderDialog.dismiss();
                                    agregar[0] = true;
                                    if (agregar[0]) {
                                        ContentValues values = new ContentValues();
                                        values.put(ContactsContract.Data.DISPLAY_NAME,
                                                contact.getString("nombre"));
                                        Uri rawContactUri = contentResolver
                                                .insert(ContactsContract.RawContacts.CONTENT_URI, values);

                                        long rawContactId = ContentUris.parseId(rawContactUri);
                                        long contactId = ContentUris.parseId(rawContactUri);

                                        values.clear();
                                        values.put(ContactsContract.CommonDataKinds.Phone.NUMBER,
                                                contact.getString("telefono"));
                                        values.put(ContactsContract.CommonDataKinds.Phone.TYPE,
                                                ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE);
                                        values.put(Data.RAW_CONTACT_ID, rawContactId);
                                        contentResolver.insert(ContactsContract.Data.CONTENT_URI, values);

                                    }
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                            }
                        });
                finderDialog.getButton(DialogInterface.BUTTON_NEGATIVE)
                        .setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                finderDialog.dismiss();
                                agregar[0] = false;
                            }
                        });
            }
        } else {
            LayoutInflater dialogInflater = (LayoutInflater) activity
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            dialogView = dialogInflater.inflate(R.layout.add_contact_message, null);
            final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity).setView(dialogView)
                    .setCancelable(true).setPositiveButton(R.string.add_contact_yes, null)
                    .setNegativeButton(R.string.add_contact_no, null);
            finderDialog = dialogBuilder.show();
            finderDialog.setCanceledOnTouchOutside(true);
            finderDialog.getButton(DialogInterface.BUTTON_POSITIVE)
                    .setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            try {
                                finderDialog.dismiss();
                                agregar[0] = true;
                                if (agregar[0]) {
                                    ContentValues values = new ContentValues();
                                    values.put(ContactsContract.Data.DISPLAY_NAME, contact.getString("nombre"));
                                    Uri rawContactUri = contentResolver
                                            .insert(ContactsContract.RawContacts.CONTENT_URI, values);

                                    long rawContactId = ContentUris.parseId(rawContactUri);

                                    values.clear();
                                    values.put(android.provider.ContactsContract.Data.MIMETYPE,
                                            ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
                                    values.put(ContactsContract.CommonDataKinds.Phone.NUMBER,
                                            contact.getString("telefono"));
                                    values.put(ContactsContract.CommonDataKinds.Phone.TYPE,
                                            ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE);
                                    values.put(Data.RAW_CONTACT_ID, rawContactId);
                                    contentResolver.insert(ContactsContract.Data.CONTENT_URI, values);

                                    values.clear();
                                    values.put(Data.MIMETYPE, ContactsContract.Data.CONTENT_TYPE);
                                    values.put(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME,
                                            contact.getString("nombre"));
                                    values.put(Data.RAW_CONTACT_ID, rawContactId);
                                    contentResolver.insert(ContactsContract.Data.CONTENT_URI, values);

                                    values.clear();
                                    values.put(Data.MIMETYPE,
                                            ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE);
                                    values.put(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME,
                                            contact.getString("nombre"));
                                    values.put(Data.RAW_CONTACT_ID, rawContactId);
                                    contentResolver.insert(ContactsContract.Data.CONTENT_URI, values);

                                }
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                        }
                    });
            finderDialog.getButton(DialogInterface.BUTTON_NEGATIVE)
                    .setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            finderDialog.dismiss();
                            agregar[0] = false;
                        }
                    });
        }
        c.close();
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:com.guardtrax.ui.screens.HomeScreen.java

private void video_click() {
    AlertDialog.Builder dialog = new AlertDialog.Builder(HomeScreen.this);
    dialog.setTitle("Video");
    dialog.setMessage("Record a video?");

    dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override//from w ww . jav  a 2s . c o  m
        public void onClick(DialogInterface dialog, int which) {

            if (GTConstants.videoFeed.equalsIgnoreCase("dvtel")) {
                //Launch the DVTel program - TruWitness
                Intent intent = getPackageManager().getLaunchIntentForPackage("com.dvtel.mobilecam");
                if (intent != null) {
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                }
            } else if (GTConstants.videoFeed.equalsIgnoreCase("milestone")) {
                //Launch the DVTel program - TruWitness
                Intent intent = getPackageManager().getLaunchIntentForPackage("com.milestonesys.mobile");
                if (intent != null) {
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                }
            } else {
                // Launch an intent to capture video from MediaStore
                Intent takeVideoIntent = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);

                String path = GTConstants.sendfileFolder + Utility.createFileName() + ".mpeg";
                file_name = path;

                File file = new File(path);
                Uri outputFileUri = Uri.fromFile(file);
                takeVideoIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, outputFileUri);
                startActivityForResult(takeVideoIntent, ACTION_TAKE_VIDEO);
            }
        }
    });

    dialog.setNeutralButton("View", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            galleryIntent = new Intent(Intent.ACTION_PICK,
                    android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
            startActivityForResult(galleryIntent, ACTIVITY_SELECT_VIDEO);
        }
    });

    dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {

        }
    });
    dialog.show();
}