Search in sources :

Example 6 with DialogInterface

use of android.content.DialogInterface in project Signal-Android by WhisperSystems.

the class ConversationFragment method handleDeleteMessages.

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));
    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;
                }
            }.execute(messageRecords.toArray(new MessageRecord[messageRecords.size()]));
        }
    });
    builder.setNegativeButton(android.R.string.cancel, null);
    builder.show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) MediaMmsMessageRecord(org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord) ProgressDialogAsyncTask(org.thoughtcrime.securesms.util.task.ProgressDialogAsyncTask)

Example 7 with DialogInterface

use of android.content.DialogInterface in project Signal-Android by WhisperSystems.

the class MediaOverviewActivity method saveToDisk.

private void saveToDisk() {
    final Context c = this;
    SaveAttachmentTask.showWarningDialog(this, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            new ProgressDialogAsyncTask<Void, Void, List<SaveAttachmentTask.Attachment>>(c, R.string.ConversationFragment_collecting_attahments, R.string.please_wait) {

                @Override
                protected List<SaveAttachmentTask.Attachment> doInBackground(Void... params) {
                    Cursor cursor = DatabaseFactory.getMediaDatabase(c).getMediaForThread(threadId);
                    List<SaveAttachmentTask.Attachment> attachments = new ArrayList<>(cursor.getCount());
                    while (cursor != null && cursor.moveToNext()) {
                        MediaRecord record = MediaRecord.from(cursor);
                        attachments.add(new SaveAttachmentTask.Attachment(record.getAttachment().getDataUri(), record.getContentType(), record.getDate()));
                    }
                    return attachments;
                }

                @Override
                protected void onPostExecute(List<SaveAttachmentTask.Attachment> attachments) {
                    super.onPostExecute(attachments);
                    SaveAttachmentTask saveTask = new SaveAttachmentTask(c, masterSecret, attachments.size());
                    saveTask.execute(attachments.toArray(new SaveAttachmentTask.Attachment[attachments.size()]));
                }
            }.execute();
        }
    }, gridView.getAdapter().getItemCount());
}
Also used : Context(android.content.Context) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) SaveAttachmentTask(org.thoughtcrime.securesms.util.SaveAttachmentTask) MediaRecord(org.thoughtcrime.securesms.database.MediaDatabase.MediaRecord) ProgressDialogAsyncTask(org.thoughtcrime.securesms.util.task.ProgressDialogAsyncTask) ArrayList(java.util.ArrayList) List(java.util.List)

Example 8 with DialogInterface

use of android.content.DialogInterface in project Signal-Android by WhisperSystems.

the class ImportExportFragment method handleImportSms.

private void handleImportSms() {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setIconAttribute(R.attr.dialog_info_icon);
    builder.setTitle(getActivity().getString(R.string.ImportFragment_import_system_sms_database));
    builder.setMessage(getActivity().getString(R.string.ImportFragment_this_will_import_messages_from_the_system));
    builder.setPositiveButton(getActivity().getString(R.string.ImportFragment_import), new AlertDialog.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            Intent intent = new Intent(getActivity(), ApplicationMigrationService.class);
            intent.setAction(ApplicationMigrationService.MIGRATE_DATABASE);
            intent.putExtra("master_secret", masterSecret);
            getActivity().startService(intent);
            Intent nextIntent = new Intent(getActivity(), ConversationListActivity.class);
            Intent activityIntent = new Intent(getActivity(), DatabaseMigrationActivity.class);
            activityIntent.putExtra("next_intent", nextIntent);
            getActivity().startActivity(activityIntent);
        }
    });
    builder.setNegativeButton(getActivity().getString(R.string.ImportFragment_cancel), null);
    builder.show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) Intent(android.content.Intent) ApplicationMigrationService(org.thoughtcrime.securesms.service.ApplicationMigrationService)

Example 9 with DialogInterface

use of android.content.DialogInterface in project material-dialogs by afollestad.

the class ColorChooserDialog method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    if (getArguments() == null || !getArguments().containsKey("builder")) {
        throw new IllegalStateException("ColorChooserDialog should be created using its Builder interface.");
    }
    generateColors();
    int preselectColor;
    boolean foundPreselectColor = false;
    if (savedInstanceState != null) {
        foundPreselectColor = !savedInstanceState.getBoolean("in_custom", false);
        preselectColor = getSelectedColor();
    } else {
        if (getBuilder().setPreselectionColor) {
            preselectColor = getBuilder().preselectColor;
            if (preselectColor != 0) {
                for (int topIndex = 0; topIndex < colorsTop.length; topIndex++) {
                    if (colorsTop[topIndex] == preselectColor) {
                        foundPreselectColor = true;
                        topIndex(topIndex);
                        if (getBuilder().accentMode) {
                            subIndex(2);
                        } else if (colorsSub != null) {
                            findSubIndexForColor(topIndex, preselectColor);
                        } else {
                            subIndex(5);
                        }
                        break;
                    }
                    if (colorsSub != null) {
                        for (int subIndex = 0; subIndex < colorsSub[topIndex].length; subIndex++) {
                            if (colorsSub[topIndex][subIndex] == preselectColor) {
                                foundPreselectColor = true;
                                topIndex(topIndex);
                                subIndex(subIndex);
                                break;
                            }
                        }
                        if (foundPreselectColor) {
                            break;
                        }
                    }
                }
            }
        } else {
            preselectColor = Color.BLACK;
            foundPreselectColor = true;
        }
    }
    circleSize = getResources().getDimensionPixelSize(R.dimen.md_colorchooser_circlesize);
    final Builder builder = getBuilder();
    MaterialDialog.Builder bd = new MaterialDialog.Builder(getActivity()).title(getTitle()).autoDismiss(false).customView(R.layout.md_dialog_colorchooser, false).negativeText(builder.cancelBtn).positiveText(builder.doneBtn).neutralText(builder.allowUserCustom ? builder.customBtn : 0).onPositive(new MaterialDialog.SingleButtonCallback() {

        @Override
        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
            callback.onColorSelection(ColorChooserDialog.this, getSelectedColor());
            dismiss();
        }
    }).onNegative(new MaterialDialog.SingleButtonCallback() {

        @Override
        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
            if (isInSub()) {
                dialog.setActionButton(DialogAction.NEGATIVE, getBuilder().cancelBtn);
                isInSub(false);
                // Do this to avoid ArrayIndexOutOfBoundsException
                subIndex(-1);
                invalidate();
            } else {
                dialog.cancel();
            }
        }
    }).onNeutral(new MaterialDialog.SingleButtonCallback() {

        @Override
        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
            toggleCustom(dialog);
        }
    }).showListener(new DialogInterface.OnShowListener() {

        @Override
        public void onShow(DialogInterface dialog) {
            invalidateDynamicButtonColors();
        }
    });
    if (builder.theme != null) {
        bd.theme(builder.theme);
    }
    final MaterialDialog dialog = bd.build();
    final View v = dialog.getCustomView();
    grid = (GridView) v.findViewById(R.id.md_grid);
    if (builder.allowUserCustom) {
        selectedCustomColor = preselectColor;
        colorChooserCustomFrame = v.findViewById(R.id.md_colorChooserCustomFrame);
        customColorHex = (EditText) v.findViewById(R.id.md_hexInput);
        customColorIndicator = v.findViewById(R.id.md_colorIndicator);
        customSeekA = (SeekBar) v.findViewById(R.id.md_colorA);
        customSeekAValue = (TextView) v.findViewById(R.id.md_colorAValue);
        customSeekR = (SeekBar) v.findViewById(R.id.md_colorR);
        customSeekRValue = (TextView) v.findViewById(R.id.md_colorRValue);
        customSeekG = (SeekBar) v.findViewById(R.id.md_colorG);
        customSeekGValue = (TextView) v.findViewById(R.id.md_colorGValue);
        customSeekB = (SeekBar) v.findViewById(R.id.md_colorB);
        customSeekBValue = (TextView) v.findViewById(R.id.md_colorBValue);
        if (!builder.allowUserCustomAlpha) {
            v.findViewById(R.id.md_colorALabel).setVisibility(View.GONE);
            customSeekA.setVisibility(View.GONE);
            customSeekAValue.setVisibility(View.GONE);
            customColorHex.setHint("2196F3");
            customColorHex.setFilters(new InputFilter[] { new InputFilter.LengthFilter(6) });
        } else {
            customColorHex.setHint("FF2196F3");
            customColorHex.setFilters(new InputFilter[] { new InputFilter.LengthFilter(8) });
        }
        if (!foundPreselectColor) {
            // If color wasn't found in the preset colors, it must be custom
            toggleCustom(dialog);
        }
    }
    invalidate();
    return dialog;
}
Also used : InputFilter(android.text.InputFilter) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) DialogInterface(android.content.DialogInterface) GridView(android.widget.GridView) View(android.view.View) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint) DialogAction(com.afollestad.materialdialogs.DialogAction) NonNull(android.support.annotation.NonNull) NonNull(android.support.annotation.NonNull)

Example 10 with DialogInterface

use of android.content.DialogInterface in project material-camera by afollestad.

the class BaseCaptureActivity method onCreate.

@Override
protected final void onCreate(Bundle savedInstanceState) {
    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
    super.onCreate(savedInstanceState);
    if (!CameraUtil.hasCamera(this)) {
        new MaterialDialog.Builder(this).title(R.string.mcam_error).content(R.string.mcam_video_capture_unsupported).positiveText(android.R.string.ok).dismissListener(new DialogInterface.OnDismissListener() {

            @Override
            public void onDismiss(DialogInterface dialog) {
                finish();
            }
        }).show();
        return;
    }
    setContentView(R.layout.mcam_activity_videocapture);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        final int primaryColor = getIntent().getIntExtra(CameraIntentKey.PRIMARY_COLOR, 0);
        final boolean isPrimaryDark = CameraUtil.isColorDark(primaryColor);
        final Window window = getWindow();
        window.setStatusBarColor(CameraUtil.darkenColor(primaryColor));
        window.setNavigationBarColor(isPrimaryDark ? primaryColor : Color.BLACK);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            final View view = window.getDecorView();
            int flags = view.getSystemUiVisibility();
            flags |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
            view.setSystemUiVisibility(flags);
        }
    }
    if (null == savedInstanceState) {
        checkPermissions();
        mLengthLimit = getIntent().getLongExtra(CameraIntentKey.LENGTH_LIMIT, -1);
    } else {
        mCameraPosition = savedInstanceState.getInt("camera_position", -1);
        mRequestingPermission = savedInstanceState.getBoolean("requesting_permission", false);
        mRecordingStart = savedInstanceState.getLong("recording_start", -1);
        mRecordingEnd = savedInstanceState.getLong("recording_end", -1);
        mLengthLimit = savedInstanceState.getLong(CameraIntentKey.LENGTH_LIMIT, -1);
        if (savedInstanceState.containsKey("front_camera_id_str")) {
            mFrontCameraId = savedInstanceState.getString("front_camera_id_str");
            mBackCameraId = savedInstanceState.getString("back_camera_id_str");
        } else {
            mFrontCameraId = savedInstanceState.getInt("front_camera_id_int");
            mBackCameraId = savedInstanceState.getInt("back_camera_id_int");
        }
        mFlashMode = savedInstanceState.getInt("flash_mode");
    }
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
Also used : Window(android.view.Window) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) DialogInterface(android.content.DialogInterface) View(android.view.View)

Aggregations

DialogInterface (android.content.DialogInterface)2733 AlertDialog (android.app.AlertDialog)1228 View (android.view.View)877 Intent (android.content.Intent)709 TextView (android.widget.TextView)653 AlertDialog (android.support.v7.app.AlertDialog)649 EditText (android.widget.EditText)426 ImageView (android.widget.ImageView)308 OnClickListener (android.content.DialogInterface.OnClickListener)285 LayoutInflater (android.view.LayoutInflater)242 SuppressLint (android.annotation.SuppressLint)225 AdapterView (android.widget.AdapterView)220 ListView (android.widget.ListView)220 ArrayList (java.util.ArrayList)213 Context (android.content.Context)181 Dialog (android.app.Dialog)180 File (java.io.File)160 OnClickListener (android.view.View.OnClickListener)157 Bundle (android.os.Bundle)146 Activity (android.app.Activity)143