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();
}
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);
}
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;
}
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;
}
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();
}
}
Aggregations