Search in sources :

Example 16 with OnCancelListener

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

the class InCallActivity method showErrorDialog.

/**
 * Utility function to bring up a generic "error" dialog.
 */
private void showErrorDialog(CharSequence msg) {
    Log.i(this, "Show Dialog: " + msg);
    dismissPendingDialogs();
    mDialog = new AlertDialog.Builder(this).setMessage(msg).setPositiveButton(android.R.string.ok, new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            onDialogDismissed();
        }
    }).setOnCancelListener(new OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialog) {
            onDialogDismissed();
        }
    }).create();
    mDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    mDialog.show();
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) OnClickListener(android.content.DialogInterface.OnClickListener) OnCancelListener(android.content.DialogInterface.OnCancelListener)

Example 17 with OnCancelListener

use of android.content.DialogInterface.OnCancelListener in project android-aosp-mms by slvn.

the class MessageUtils method handleReadReport.

public static void handleReadReport(final Context context, final Collection<Long> threadIds, final int status, final Runnable callback) {
    StringBuilder selectionBuilder = new StringBuilder(Mms.MESSAGE_TYPE + " = " + PduHeaders.MESSAGE_TYPE_RETRIEVE_CONF + " AND " + Mms.READ + " = 0" + " AND " + Mms.READ_REPORT + " = " + PduHeaders.VALUE_YES);
    String[] selectionArgs = null;
    if (threadIds != null) {
        String threadIdSelection = null;
        StringBuilder buf = new StringBuilder();
        selectionArgs = new String[threadIds.size()];
        int i = 0;
        for (long threadId : threadIds) {
            if (i > 0) {
                buf.append(" OR ");
            }
            buf.append(Mms.THREAD_ID).append("=?");
            selectionArgs[i++] = Long.toString(threadId);
        }
        threadIdSelection = buf.toString();
        selectionBuilder.append(" AND (" + threadIdSelection + ")");
    }
    final Cursor c = SqliteWrapper.query(context, context.getContentResolver(), Mms.Inbox.CONTENT_URI, new String[] { Mms._ID, Mms.MESSAGE_ID }, selectionBuilder.toString(), selectionArgs, null);
    if (c == null) {
        return;
    }
    final Map<String, String> map = new HashMap<String, String>();
    try {
        if (c.getCount() == 0) {
            if (callback != null) {
                callback.run();
            }
            return;
        }
        while (c.moveToNext()) {
            Uri uri = ContentUris.withAppendedId(Mms.CONTENT_URI, c.getLong(0));
            map.put(c.getString(1), AddressUtils.getFrom(context, uri));
        }
    } finally {
        c.close();
    }
    OnClickListener positiveListener = new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            for (final Map.Entry<String, String> entry : map.entrySet()) {
                MmsMessageSender.sendReadRec(context, entry.getValue(), entry.getKey(), status);
            }
            if (callback != null) {
                callback.run();
            }
            dialog.dismiss();
        }
    };
    OnClickListener negativeListener = new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (callback != null) {
                callback.run();
            }
            dialog.dismiss();
        }
    };
    OnCancelListener cancelListener = new OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialog) {
            if (callback != null) {
                callback.run();
            }
            dialog.dismiss();
        }
    };
    confirmReadReportDialog(context, positiveListener, negativeListener, cancelListener);
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) DialogInterface(android.content.DialogInterface) Cursor(android.database.Cursor) Uri(android.net.Uri) OnClickListener(android.content.DialogInterface.OnClickListener) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) OnCancelListener(android.content.DialogInterface.OnCancelListener)

Example 18 with OnCancelListener

use of android.content.DialogInterface.OnCancelListener in project network-monitor by caarmen.

the class ConfirmDialogFragment method onCreateDialog.

/**
 * @return a Dialog with a title, message, ok, and cancel buttons.
 */
@Override
@NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Log.v(TAG, "onCreateDialog: savedInstanceState = " + savedInstanceState);
    Activity activity = getActivity();
    Bundle arguments = getArguments();
    if (activity == null || arguments == null)
        return super.onCreateDialog(savedInstanceState);
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setTitle(arguments.getCharSequence(DialogFragmentFactory.EXTRA_TITLE));
    builder.setMessage(arguments.getCharSequence(DialogFragmentFactory.EXTRA_MESSAGE));
    final int actionId = arguments.getInt(DialogFragmentFactory.EXTRA_ACTION_ID);
    final Bundle extras = arguments.getBundle(DialogFragmentFactory.EXTRA_EXTRAS);
    OnClickListener positiveListener = null;
    OnClickListener negativeListener = null;
    if (activity instanceof DialogButtonListener) {
        positiveListener = (dialog, which) -> {
            Log.v(TAG, "onClick (positive button");
            if (activity.isFinishing())
                Log.w(TAG, "User clicked on dialog after it was detached from activity. Monkey?");
            else
                ((DialogButtonListener) activity).onOkClicked(actionId, extras);
        };
        negativeListener = (dialog, which) -> {
            Log.v(TAG, "onClick (negative button");
            if (activity.isFinishing())
                Log.w(TAG, "User clicked on dialog after it was detached from activity. Monkey?");
            else
                ((DialogButtonListener) activity).onCancelClicked(actionId, extras);
        };
    }
    builder.setNegativeButton(android.R.string.cancel, negativeListener);
    builder.setPositiveButton(android.R.string.ok, positiveListener);
    if (activity instanceof OnCancelListener)
        builder.setOnCancelListener((OnCancelListener) activity);
    final Dialog dialog = builder.create();
    if (activity instanceof OnDismissListener)
        dialog.setOnDismissListener((OnDismissListener) activity);
    return dialog;
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) Bundle(android.os.Bundle) AlertDialog(android.support.v7.app.AlertDialog) Dialog(android.app.Dialog) OnDismissListener(android.content.DialogInterface.OnDismissListener) Activity(android.app.Activity) OnClickListener(android.content.DialogInterface.OnClickListener) OnCancelListener(android.content.DialogInterface.OnCancelListener) NonNull(android.support.annotation.NonNull)

Example 19 with OnCancelListener

use of android.content.DialogInterface.OnCancelListener in project network-monitor by caarmen.

the class InfoDialogFragment method onCreateDialog.

/**
 * @return a Dialog with a title, message, and single button to dismiss the dialog.
 */
@Override
@NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Log.v(TAG, "onCreateDialog: savedInstanceState = " + savedInstanceState);
    Context context = getActivity();
    Bundle arguments = getArguments();
    if (context == null || arguments == null)
        return super.onCreateDialog(savedInstanceState);
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    final int iconId = arguments.getInt(DialogFragmentFactory.EXTRA_ICON_ID);
    if (iconId > 0)
        builder.setIcon(iconId);
    CharSequence message = arguments.getString(DialogFragmentFactory.EXTRA_MESSAGE);
    SpannableString s = new SpannableString(message);
    Linkify.addLinks(s, Linkify.WEB_URLS);
    builder.setTitle(arguments.getString(DialogFragmentFactory.EXTRA_TITLE)).setMessage(s);
    builder.setPositiveButton(android.R.string.ok, null);
    if (getActivity() instanceof OnCancelListener)
        builder.setOnCancelListener((OnCancelListener) getActivity());
    final Dialog dialog = builder.create();
    if (getActivity() instanceof OnDismissListener)
        dialog.setOnDismissListener((OnDismissListener) getActivity());
    dialog.setOnShowListener(dialogInterface -> {
        TextView messageTextView = ((Dialog) dialogInterface).findViewById(android.R.id.message);
        if (messageTextView != null)
            messageTextView.setMovementMethod(LinkMovementMethod.getInstance());
    });
    return dialog;
}
Also used : Context(android.content.Context) AlertDialog(android.support.v7.app.AlertDialog) SpannableString(android.text.SpannableString) Bundle(android.os.Bundle) Dialog(android.app.Dialog) AlertDialog(android.support.v7.app.AlertDialog) OnDismissListener(android.content.DialogInterface.OnDismissListener) TextView(android.widget.TextView) OnCancelListener(android.content.DialogInterface.OnCancelListener) NonNull(android.support.annotation.NonNull)

Example 20 with OnCancelListener

use of android.content.DialogInterface.OnCancelListener in project Osmand by osmandapp.

the class FailSafeFuntions method restoreRoutingMode.

public static void restoreRoutingMode(final MapActivity ma) {
    final OsmandApplication app = ma.getMyApplication();
    final OsmandSettings settings = app.getSettings();
    final Handler uiHandler = new Handler();
    final String gpxPath = settings.FOLLOW_THE_GPX_ROUTE.get();
    final TargetPointsHelper targetPoints = app.getTargetPointsHelper();
    final TargetPoint pointToNavigate = targetPoints.getPointToNavigate();
    if (pointToNavigate == null && gpxPath == null) {
        notRestoreRoutingMode(ma, app);
    } else {
        quitRouteRestoreDialog = false;
        Runnable encapsulate = new Runnable() {

            int delay = 7;

            Runnable delayDisplay = null;

            @Override
            public void run() {
                AlertDialog.Builder builder = new AlertDialog.Builder(ma);
                final TextView tv = new TextView(ma);
                tv.setText(ma.getString(R.string.continue_follow_previous_route_auto, delay + ""));
                tv.setPadding(7, 5, 7, 5);
                builder.setView(tv);
                builder.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        quitRouteRestoreDialog = true;
                        restoreRoutingModeInner();
                    }
                });
                builder.setNegativeButton(R.string.shared_string_no, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        quitRouteRestoreDialog = true;
                        notRestoreRoutingMode(ma, app);
                    }
                });
                final AlertDialog dlg = builder.show();
                dlg.setOnDismissListener(new OnDismissListener() {

                    @Override
                    public void onDismiss(DialogInterface dialog) {
                        quitRouteRestoreDialog = true;
                    }
                });
                dlg.setOnCancelListener(new OnCancelListener() {

                    @Override
                    public void onCancel(DialogInterface dialog) {
                        quitRouteRestoreDialog = true;
                    }
                });
                delayDisplay = new Runnable() {

                    @Override
                    public void run() {
                        if (!quitRouteRestoreDialog) {
                            delay--;
                            tv.setText(ma.getString(R.string.continue_follow_previous_route_auto, delay + ""));
                            if (delay <= 0) {
                                try {
                                    if (dlg.isShowing() && !quitRouteRestoreDialog) {
                                        dlg.dismiss();
                                    }
                                    quitRouteRestoreDialog = true;
                                    restoreRoutingModeInner();
                                } catch (Exception e) {
                                    // swalow view not attached exception
                                    log.error(e.getMessage() + "", e);
                                }
                            } else {
                                uiHandler.postDelayed(delayDisplay, 1000);
                            }
                        }
                    }
                };
                delayDisplay.run();
            }

            private void restoreRoutingModeInner() {
                AsyncTask<String, Void, GPXFile> task = new AsyncTask<String, Void, GPXFile>() {

                    @Override
                    protected GPXFile doInBackground(String... params) {
                        if (gpxPath != null) {
                            // Reverse also should be stored ?
                            GPXFile f = GPXUtilities.loadGPXFile(app, new File(gpxPath));
                            if (f.warning != null) {
                                return null;
                            }
                            return f;
                        } else {
                            return null;
                        }
                    }

                    @Override
                    protected void onPostExecute(GPXFile result) {
                        final GPXRouteParamsBuilder gpxRoute;
                        if (result != null) {
                            gpxRoute = new GPXRouteParamsBuilder(result, settings);
                            if (settings.GPX_ROUTE_CALC_OSMAND_PARTS.get()) {
                                gpxRoute.setCalculateOsmAndRouteParts(true);
                            }
                            if (settings.GPX_CALCULATE_RTEPT.get()) {
                                gpxRoute.setUseIntermediatePointsRTE(true);
                            }
                            if (settings.GPX_ROUTE_CALC.get()) {
                                gpxRoute.setCalculateOsmAndRoute(true);
                            }
                        } else {
                            gpxRoute = null;
                        }
                        TargetPoint endPoint = pointToNavigate;
                        if (endPoint == null) {
                            notRestoreRoutingMode(ma, app);
                        } else {
                            enterRoutingMode(ma, gpxRoute);
                        }
                    }
                };
                task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, gpxPath);
            }
        };
        encapsulate.run();
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) OsmandApplication(net.osmand.plus.OsmandApplication) DialogInterface(android.content.DialogInterface) GPXRouteParamsBuilder(net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder) GPXRouteParamsBuilder(net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder) OnDismissListener(android.content.DialogInterface.OnDismissListener) AsyncTask(android.os.AsyncTask) Handler(android.os.Handler) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) OsmandSettings(net.osmand.plus.OsmandSettings) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) TextView(android.widget.TextView) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) TargetPointsHelper(net.osmand.plus.TargetPointsHelper) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) File(java.io.File) OnCancelListener(android.content.DialogInterface.OnCancelListener)

Aggregations

OnCancelListener (android.content.DialogInterface.OnCancelListener)58 DialogInterface (android.content.DialogInterface)54 AlertDialog (android.app.AlertDialog)23 OnClickListener (android.content.DialogInterface.OnClickListener)18 View (android.view.View)13 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 LayoutInflater (android.view.LayoutInflater)5 InputMethodInfo (android.view.inputmethod.InputMethodInfo)5 InputMethodSubtype (android.view.inputmethod.InputMethodSubtype)5 CompoundButton (android.widget.CompoundButton)5