Search in sources :

Example 56 with OnCancelListener

use of android.content.DialogInterface.OnCancelListener in project Anki-Android by Ramblurr.

the class Reviewer method reloadCollection.

private void reloadCollection(Bundle savedInstanceState) {
    mSavedInstanceState = savedInstanceState;
    DeckTask.launchDeckTask(DeckTask.TASK_TYPE_OPEN_COLLECTION, new DeckTask.TaskListener() {

        @Override
        public void onPostExecute(DeckTask.TaskData result) {
            if (mOpenCollectionDialog.isShowing()) {
                try {
                    mOpenCollectionDialog.dismiss();
                } catch (Exception e) {
                    Log.e(AnkiDroidApp.TAG, "onPostExecute - Dialog dismiss Exception = " + e.getMessage());
                }
            }
            if (AnkiDroidApp.colIsOpen()) {
                onCreate(mSavedInstanceState);
            } else {
                finish();
            }
        }

        @Override
        public void onPreExecute() {
            mOpenCollectionDialog = StyledOpenCollectionDialog.show(Reviewer.this, getResources().getString(R.string.open_collection), new OnCancelListener() {

                @Override
                public void onCancel(DialogInterface arg0) {
                    finish();
                }
            });
        }

        @Override
        public void onProgressUpdate(DeckTask.TaskData... values) {
        }
    }, new DeckTask.TaskData(AnkiDroidApp.getCurrentAnkiDroidDirectory() + AnkiDroidApp.COLLECTION_PATH, 0, true));
}
Also used : DialogInterface(android.content.DialogInterface) DeckTask(com.ichi2.async.DeckTask) JSONException(org.json.JSONException) IOException(java.io.IOException) OnCancelListener(android.content.DialogInterface.OnCancelListener)

Example 57 with OnCancelListener

use of android.content.DialogInterface.OnCancelListener in project LiveSDK-for-Android by liveservices.

the class SkyDriveActivity method onActivityResult.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == FilePicker.PICK_FILE_REQUEST) {
        if (resultCode == RESULT_OK) {
            String filePath = data.getStringExtra(FilePicker.EXTRA_FILE_PATH);
            if (TextUtils.isEmpty(filePath)) {
                showToast("No file was choosen.");
                return;
            }
            File file = new File(filePath);
            final ProgressDialog uploadProgressDialog = new ProgressDialog(SkyDriveActivity.this);
            uploadProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            uploadProgressDialog.setMessage("Uploading...");
            uploadProgressDialog.setCancelable(true);
            uploadProgressDialog.show();
            final LiveOperation operation = mClient.uploadAsync(mCurrentFolderId, file.getName(), file, new LiveUploadOperationListener() {

                @Override
                public void onUploadProgress(int totalBytes, int bytesRemaining, LiveOperation operation) {
                    int percentCompleted = computePrecentCompleted(totalBytes, bytesRemaining);
                    uploadProgressDialog.setProgress(percentCompleted);
                }

                @Override
                public void onUploadFailed(LiveOperationException exception, LiveOperation operation) {
                    uploadProgressDialog.dismiss();
                    showToast(exception.getMessage());
                }

                @Override
                public void onUploadCompleted(LiveOperation operation) {
                    uploadProgressDialog.dismiss();
                    JSONObject result = operation.getResult();
                    if (result.has(JsonKeys.ERROR)) {
                        JSONObject error = result.optJSONObject(JsonKeys.ERROR);
                        String message = error.optString(JsonKeys.MESSAGE);
                        String code = error.optString(JsonKeys.CODE);
                        showToast(code + ": " + message);
                        return;
                    }
                    loadFolder(mCurrentFolderId);
                }
            });
            uploadProgressDialog.setOnCancelListener(new OnCancelListener() {

                @Override
                public void onCancel(DialogInterface dialog) {
                    operation.cancel();
                }
            });
        }
    }
}
Also used : JSONObject(org.json.JSONObject) DialogInterface(android.content.DialogInterface) LiveOperation(com.microsoft.live.LiveOperation) LiveUploadOperationListener(com.microsoft.live.LiveUploadOperationListener) ProgressDialog(android.app.ProgressDialog) LiveOperationException(com.microsoft.live.LiveOperationException) File(java.io.File) OnCancelListener(android.content.DialogInterface.OnCancelListener)

Example 58 with OnCancelListener

use of android.content.DialogInterface.OnCancelListener in project LiveSDK-for-Android by liveservices.

the class SkyDriveActivity method onCreateDialog.

@Override
protected Dialog onCreateDialog(final int id, final Bundle bundle) {
    Dialog dialog = null;
    switch(id) {
        case DIALOG_DOWNLOAD_ID:
            {
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setTitle("Download").setMessage("This file will be downloaded to the sdcard.").setPositiveButton("OK", new Dialog.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        final ProgressDialog progressDialog = new ProgressDialog(SkyDriveActivity.this);
                        progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
                        progressDialog.setMessage("Downloading...");
                        progressDialog.setCancelable(true);
                        progressDialog.show();
                        String fileId = bundle.getString(JsonKeys.ID);
                        String name = bundle.getString(JsonKeys.NAME);
                        File file = new File(Environment.getExternalStorageDirectory(), name);
                        final LiveDownloadOperation operation = mClient.downloadAsync(fileId + "/content", file, new LiveDownloadOperationListener() {

                            @Override
                            public void onDownloadProgress(int totalBytes, int bytesRemaining, LiveDownloadOperation operation) {
                                int percentCompleted = computePrecentCompleted(totalBytes, bytesRemaining);
                                progressDialog.setProgress(percentCompleted);
                            }

                            @Override
                            public void onDownloadFailed(LiveOperationException exception, LiveDownloadOperation operation) {
                                progressDialog.dismiss();
                                showToast(exception.getMessage());
                            }

                            @Override
                            public void onDownloadCompleted(LiveDownloadOperation operation) {
                                progressDialog.dismiss();
                                showToast("File downloaded.");
                            }
                        });
                        progressDialog.setOnCancelListener(new OnCancelListener() {

                            @Override
                            public void onCancel(DialogInterface dialog) {
                                operation.cancel();
                            }
                        });
                    }
                }).setNegativeButton("Cancel", new Dialog.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });
                dialog = builder.create();
                break;
            }
    }
    if (dialog != null) {
        dialog.setOnDismissListener(new OnDismissListener() {

            @Override
            public void onDismiss(DialogInterface dialog) {
                removeDialog(id);
            }
        });
    }
    return dialog;
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) OnDismissListener(android.content.DialogInterface.OnDismissListener) LiveDownloadOperationListener(com.microsoft.live.LiveDownloadOperationListener) ProgressDialog(android.app.ProgressDialog) LiveOperationException(com.microsoft.live.LiveOperationException) LiveDownloadOperation(com.microsoft.live.LiveDownloadOperation) AlertDialog(android.app.AlertDialog) Dialog(android.app.Dialog) ProgressDialog(android.app.ProgressDialog) OnClickListener(android.view.View.OnClickListener) File(java.io.File) OnCancelListener(android.content.DialogInterface.OnCancelListener)

Example 59 with OnCancelListener

use of android.content.DialogInterface.OnCancelListener in project android_packages_apps_Dialer by LineageOS.

the class CreateCustomSmsDialogFragment method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    super.onCreateDialog(savedInstanceState);
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    View view = View.inflate(builder.getContext(), R.layout.fragment_custom_sms_dialog, null);
    editText = (EditText) view.findViewById(R.id.custom_sms_input);
    if (savedInstanceState != null) {
        editText.setText(savedInstanceState.getCharSequence(ARG_ENTERED_TEXT));
    }
    inCallUiLock = FragmentUtils.getParentUnsafe(CreateCustomSmsDialogFragment.this, CreateCustomSmsHolder.class).acquireInCallUiLock("CreateCustomSmsDialogFragment");
    builder.setCancelable(true).setView(view).setPositiveButton(R.string.call_incoming_custom_message_send, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            FragmentUtils.getParentUnsafe(CreateCustomSmsDialogFragment.this, CreateCustomSmsHolder.class).customSmsCreated(editText.getText().toString().trim());
            dismiss();
        }
    }).setNegativeButton(R.string.call_incoming_custom_message_cancel, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            dismiss();
        }
    }).setOnCancelListener(new OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialogInterface) {
            dismiss();
        }
    }).setTitle(R.string.call_incoming_respond_via_sms_custom_message);
    final AlertDialog customMessagePopup = builder.create();
    customMessagePopup.setOnShowListener(new OnShowListener() {

        @Override
        public void onShow(DialogInterface dialogInterface) {
            ((AlertDialog) dialogInterface).getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
        }
    });
    editText.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            Button sendButton = customMessagePopup.getButton(DialogInterface.BUTTON_POSITIVE);
            sendButton.setEnabled(editable != null && editable.toString().trim().length() != 0);
        }
    });
    customMessagePopup.getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
    customMessagePopup.getWindow().addFlags(LayoutParams.FLAG_SHOW_WHEN_LOCKED);
    return customMessagePopup;
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) View(android.view.View) OnShowListener(android.content.DialogInterface.OnShowListener) Button(android.widget.Button) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) OnCancelListener(android.content.DialogInterface.OnCancelListener) NonNull(android.support.annotation.NonNull)

Example 60 with OnCancelListener

use of android.content.DialogInterface.OnCancelListener in project android_packages_apps_Dialer by LineageOS.

the class CallLogAdapter method showDeleteSelectedItemsDialog.

private void showDeleteSelectedItemsDialog() {
    SparseArray<String> voicemailsToDeleteOnConfirmation = selectedItems.clone();
    new AlertDialog.Builder(activity).setCancelable(true).setTitle(activity.getResources().getQuantityString(R.plurals.delete_voicemails_confirmation_dialog_title, selectedItems.size())).setPositiveButton(R.string.voicemailMultiSelectDeleteConfirm, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(final DialogInterface dialog, final int button) {
            LogUtil.i("CallLogAdapter.showDeleteSelectedItemsDialog", "onClick, these items to delete " + voicemailsToDeleteOnConfirmation);
            deleteSelectedItems(voicemailsToDeleteOnConfirmation);
            actionMode.finish();
            dialog.cancel();
            Logger.get(activity).logImpression(DialerImpression.Type.MULTISELECT_DELETE_ENTRY_VIA_CONFIRMATION_DIALOG);
        }
    }).setOnCancelListener(new OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialogInterface) {
            Logger.get(activity).logImpression(DialerImpression.Type.MULTISELECT_CANCEL_CONFIRMATION_DIALOG_VIA_CANCEL_TOUCH);
            dialogInterface.cancel();
        }
    }).setNegativeButton(R.string.voicemailMultiSelectDeleteCancel, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(final DialogInterface dialog, final int button) {
            Logger.get(activity).logImpression(DialerImpression.Type.MULTISELECT_CANCEL_CONFIRMATION_DIALOG_VIA_CANCEL_BUTTON);
            dialog.cancel();
        }
    }).show();
    Logger.get(activity).logImpression(DialerImpression.Type.MULTISELECT_DISPLAY_DELETE_CONFIRMATION_DIALOG);
}
Also used : DialogInterface(android.content.DialogInterface) OnCancelListener(android.content.DialogInterface.OnCancelListener)

Aggregations

OnCancelListener (android.content.DialogInterface.OnCancelListener)60 DialogInterface (android.content.DialogInterface)56 AlertDialog (android.app.AlertDialog)24 OnClickListener (android.content.DialogInterface.OnClickListener)18 View (android.view.View)14 Context (android.content.Context)12 ProgressDialog (android.app.ProgressDialog)11 TextView (android.widget.TextView)11 Intent (android.content.Intent)10 OnDismissListener (android.content.DialogInterface.OnDismissListener)7 Dialog (android.app.Dialog)6 SharedPreferences (android.content.SharedPreferences)6 TypedArray (android.content.res.TypedArray)6 ArrayList (java.util.ArrayList)6 Drawable (android.graphics.drawable.Drawable)5 LocaleList (android.os.LocaleList)5 NonNull (android.support.annotation.NonNull)5 LayoutInflater (android.view.LayoutInflater)5 InputMethodInfo (android.view.inputmethod.InputMethodInfo)5 InputMethodSubtype (android.view.inputmethod.InputMethodSubtype)5