Example usage for android.app AlertDialog.Builder setIconAttribute

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

Introduction

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

Prototype

public void setIconAttribute(@AttrRes int attrId) 

Source Link

Document

Set an icon as supplied by a theme attribute.

Usage

From source file:org.smssecure.smssecure.ConversationListFragment.java

private void handleSendDrafts() {
    AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
    alert.setIconAttribute(R.attr.dialog_alert_icon);
    alert.setTitle(getString(R.string.ConversationListFragment_send_drafts));
    alert.setMessage(/*from ww  w . j a  va  2  s. c o  m*/
            getString(R.string.ConversationListFragment_this_will_send_drafts_of_selected_conversations));
    alert.setCancelable(true);

    alert.setPositiveButton(R.string.ConversationListFragment_send, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            final Set<Long> selectedConversations = new HashSet<>(getListAdapter().getBatchSelections());
            final Context context = getActivity();

            if (!selectedConversations.isEmpty() && masterSecret != null) {
                final MasterCipher masterCipher = new MasterCipher(masterSecret);

                new AsyncTask<Void, Void, Void>() {
                    private ProgressDialog dialog;
                    private boolean isSingleConversation;
                    private boolean isSecureDestination;
                    private DraftDatabase draftDatabase;
                    private Recipients recipients;

                    @Override
                    protected void onPreExecute() {
                        dialog = ProgressDialog.show(context,
                                context.getString(R.string.ConversationListFragment_sending),
                                context.getString(R.string.ConversationListFragment_sending_selected_drafts),
                                true, false);
                    }

                    @Override
                    protected Void doInBackground(Void... params) {
                        draftDatabase = DatabaseFactory.getDraftDatabase(context);

                        for (long threadId : selectedConversations) {
                            List<DraftDatabase.Draft> drafts = draftDatabase.getDrafts(masterCipher, threadId);
                            recipients = getListAdapter().getRecipientsFromThreadId(threadId);

                            if (recipients != null) {
                                isSingleConversation = recipients.isSingleRecipient()
                                        && !recipients.isGroupRecipient();
                                isSecureDestination = isSingleConversation && SessionUtil.hasSession(context,
                                        masterSecret, recipients.getPrimaryRecipient());

                                Log.w(TAG, "Number of drafts: " + drafts.size());
                                if (drafts.size() > 1
                                        && !drafts.get(1).getType().equals(DraftDatabase.Draft.TEXT)) {
                                    sendMediaDraft(drafts.get(1), threadId, drafts.get(0).getValue());
                                } else {
                                    for (DraftDatabase.Draft draft : drafts) {
                                        Log.w(TAG, "getType(): " + draft.getType());
                                        if (draft.getType().equals(DraftDatabase.Draft.TEXT)) {
                                            sendTextDraft(draft, threadId);
                                        } else {
                                            sendMediaDraft(draft, threadId, null);
                                        }
                                    }
                                }
                            } else {
                                Log.w(TAG, "null recipients when sending drafts ?!");
                            }
                            draftDatabase.clearDrafts(threadId);
                        }
                        return null;
                    }

                    @Override
                    protected void onPostExecute(Void result) {
                        dialog.dismiss();
                        if (actionMode != null) {
                            actionMode.finish();
                            actionMode = null;
                        }
                    }

                    private void sendTextDraft(DraftDatabase.Draft draft, long threadId) {
                        OutgoingTextMessage message;
                        if (isSecureDestination) {
                            message = new OutgoingEncryptedMessage(recipients, draft.getValue(), -1);
                        } else {
                            message = new OutgoingTextMessage(recipients, draft.getValue(), -1);
                        }
                        MessageSender.send(context, masterSecret, message, threadId, false);
                    }

                    private void sendMediaDraft(DraftDatabase.Draft draft, long threadId,
                            @Nullable String forcedValue) {
                        List<Attachment> attachment = new LinkedList<Attachment>();
                        attachment.add(new UriAttachment(Uri.parse(draft.getValue()), draft.getType() + "/*",
                                AttachmentDatabase.TRANSFER_PROGRESS_DONE));

                        OutgoingMediaMessage message = new OutgoingMediaMessage(recipients,
                                forcedValue != null ? forcedValue : "", attachment, System.currentTimeMillis(),
                                -1, ThreadDatabase.DistributionTypes.BROADCAST);

                        if (isSecureDestination) {
                            message = new OutgoingSecureMediaMessage(message);
                        }
                        MessageSender.send(context, masterSecret, message, threadId, false);
                    }
                }.execute();
            }
        }
    });

    alert.setNegativeButton(android.R.string.cancel, null);
    alert.show();
}

From source file:org.thoughtcrime.securesms.conversation.ConversationFragment.java

private void handleDeleteMessages(final Set<MessageRecord> messageRecords) {
    int messagesCount = messageRecords.size();
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    builder.setIconAttribute(R.attr.dialog_alert_icon);
    builder.setTitle(getActivity().getResources().getQuantityString(
            R.plurals.ConversationFragment_delete_selected_messages, messagesCount, messagesCount));
    builder.setMessage(getActivity().getResources().getQuantityString(
            R.plurals.ConversationFragment_this_will_permanently_delete_all_n_selected_messages, messagesCount,
            messagesCount));//w ww.j a  v  a 2  s.c  o m
    builder.setCancelable(true);

    builder.setPositiveButton(R.string.delete, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            new ProgressDialogAsyncTask<MessageRecord, Void, Void>(getActivity(),
                    R.string.ConversationFragment_deleting, R.string.ConversationFragment_deleting_messages) {
                @Override
                protected Void doInBackground(MessageRecord... messageRecords) {
                    for (MessageRecord messageRecord : messageRecords) {
                        boolean threadDeleted;

                        if (messageRecord.isMms()) {
                            threadDeleted = DatabaseFactory.getMmsDatabase(getActivity())
                                    .delete(messageRecord.getId());
                        } else {
                            threadDeleted = DatabaseFactory.getSmsDatabase(getActivity())
                                    .deleteMessage(messageRecord.getId());
                        }

                        if (threadDeleted) {
                            threadId = -1;
                            listener.setThreadId(threadId);
                        }
                    }

                    return null;
                }
            }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,
                    messageRecords.toArray(new MessageRecord[messageRecords.size()]));
        }
    });

    builder.setNegativeButton(android.R.string.cancel, null);
    builder.show();
}

From source file:org.xingjitong.LinphoneActivity.java

@SuppressLint("NewApi")
private void initPopupWindow() {
    Log.v("yyppdebug", "yyppoption init 000");
    view = getLayoutInflater().inflate(R.layout.option_menu, null);
    pop = new PopupWindow(view, ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    pop.setOutsideTouchable(true);//from   www .ja  v a 2 s  .com

    // ??
    mlayout_setting = (LinearLayout) view.findViewById(R.id.option_menu_aaa);
    mlayout_about = (LinearLayout) view.findViewById(R.id.option_menu_bbb);
    mlayout_exit = (LinearLayout) view.findViewById(R.id.option_menu_ccc);

    mlayout_setting.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            if (pop.isShowing()) {
                pop.dismiss();

                isPopShowing = false;
            }
            //do somethiing
            LinphoneActivity.instance().changeCurrentFragment(FragmentsAvailable.TITTLE_SETTINGS, null);
            //-----------------

        }
    });

    mlayout_about.setOnClickListener(new View.OnClickListener() {

        @SuppressLint("NewApi")
        public void onClick(View v) {
            if (pop.isShowing()) {
                pop.dismiss();
                isPopShowing = false;

            }
            //do something...

            AlertDialog.Builder buildernew = new AlertDialog.Builder(LinphoneActivity.instance(),
                    AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);
            String tmpmsg = "?????????www.wecare200.com";
            buildernew.setIconAttribute(android.R.attr.alertDialogIcon);
            buildernew.setTitle("?");
            buildernew.setMessage(tmpmsg);

            buildernew.setNegativeButton("?", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub

                }
            });

            buildernew.create().show();

            //---------------------------------------------------------

        }
    });

    mlayout_exit.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if (pop.isShowing()) {
                pop.dismiss();
                isPopShowing = false;
            }
            //do something...

            //LinphoneActivity.instance().exit();
            //----------------------------------
            startActivity(new Intent().setAction(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME));

        }
    });
}

From source file:com.android.mms.ui.MessageUtils.java

public static void confirmDeleteMessage(final Activity activity, final Uri msgUri) {
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setTitle(R.string.confirm_dialog_title);
    builder.setIconAttribute(android.R.attr.alertDialogIcon);
    builder.setCancelable(true);//from  ww w .  j a  v a 2s . c  o  m
    builder.setMessage(R.string.confirm_delete_message);
    builder.setPositiveButton(R.string.delete, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            /// M: fix bug ALPS00351620; for requery searchactivity.
            SearchActivity.setNeedRequery();
            SqliteWrapper.delete(activity.getApplicationContext(), activity.getContentResolver(), msgUri, null,
                    null);
            dialog.dismiss();
            activity.finish();
        }
    });
    builder.setNegativeButton(R.string.no, null);
    builder.show();
}