use of android.content.DialogInterface.OnClickListener in project android-aosp-mms by slvn.
the class MessageUtils method showErrorDialog.
public static void showErrorDialog(Activity activity, String title, String message) {
if (activity.isFinishing()) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setIcon(R.drawable.ic_sms_mms_not_delivered);
builder.setTitle(title);
builder.setMessage(message);
builder.setPositiveButton(android.R.string.ok, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == DialogInterface.BUTTON_POSITIVE) {
dialog.dismiss();
}
}
});
builder.show();
}
use of android.content.DialogInterface.OnClickListener in project iNaturalistAndroid by inaturalist.
the class INaturalistApp method detectUserCountryAndUpdateNetwork.
public void detectUserCountryAndUpdateNetwork(Context context) {
// Don't ask the user again to switch to another network (if he's been asked before)
if (getInaturalistNetworkMember() != null)
return;
ActivityHelper helper;
helper = new ActivityHelper(context);
Resources res = getBaseContext().getResources();
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
View titleBarView = inflater.inflate(R.layout.change_network_title_bar, null);
ImageView titleBarLogo = (ImageView) titleBarView.findViewById(R.id.title_bar_logo);
String country = getUserCountry(context);
Log.d(TAG, "Detected country: " + country);
final String[] inatNetworks = getINatNetworks();
if (country == null) {
// Couldn't detect country - set default iNat network
setInaturalistNetworkMember(inatNetworks[0]);
return;
}
// Select default iNaturalist network
String detectedNetwork = inatNetworks[0];
for (int i = 0; i < inatNetworks.length; i++) {
if (country.equalsIgnoreCase(getStringResourceByName("inat_country_" + inatNetworks[i]))) {
detectedNetwork = inatNetworks[i];
break;
}
}
// Don't ask the user again to switch if it's the default iNat network
if (!detectedNetwork.equals(inatNetworks[0])) {
// Set the logo in the title bar according to network type
String logoName = getStringResourceByName("inat_logo_" + detectedNetwork);
String packageName = getPackageName();
int resId = getResources().getIdentifier(logoName, "drawable", packageName);
titleBarLogo.setImageResource(resId);
final String selectedNetwork = detectedNetwork;
helper.confirm(titleBarView, getStringResourceByName("alert_message_use_" + detectedNetwork), new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
setInaturalistNetworkMember(selectedNetwork);
restart();
}
}, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Set default iNaturalist network
setInaturalistNetworkMember(inatNetworks[0]);
}
});
} else {
// Set default iNaturalist network
setInaturalistNetworkMember(inatNetworks[0]);
}
}
use of android.content.DialogInterface.OnClickListener 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.OnClickListener in project Osmand by osmandapp.
the class AudioVideoNotesPlugin method chooseDefaultAction.
private void chooseDefaultAction(final double lat, final double lon, final MapActivity mapActivity) {
AlertDialog.Builder ab = new AlertDialog.Builder(mapActivity);
ab.setItems(new String[] { mapActivity.getString(R.string.recording_context_menu_arecord), mapActivity.getString(R.string.recording_context_menu_vrecord), mapActivity.getString(R.string.recording_context_menu_precord) }, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
int action = which == 0 ? AV_DEFAULT_ACTION_AUDIO : (which == 1 ? AV_DEFAULT_ACTION_VIDEO : AV_DEFAULT_ACTION_TAKEPICTURE);
takeAction(mapActivity, lon, lat, action);
}
});
ab.show();
}
use of android.content.DialogInterface.OnClickListener in project Osmand by osmandapp.
the class FavoriteDialogs method showFavoritesDialog.
public static final AlertDialog showFavoritesDialog(final Context uiContext, final FavouritesAdapter favouritesAdapter, final OnItemClickListener click, final OnDismissListener dismissListener, final Dialog[] dialogHolder, final boolean sortByDist) {
ListView listView = new ListView(uiContext);
AlertDialog.Builder bld = new AlertDialog.Builder(uiContext);
final Collator inst = Collator.getInstance();
favouritesAdapter.sort(new Comparator<FavouritePoint>() {
@Override
public int compare(FavouritePoint lhs, FavouritePoint rhs) {
if (sortByDist) {
if (favouritesAdapter.getLocation() == null) {
return 0;
}
double ld = MapUtils.getDistance(favouritesAdapter.getLocation(), lhs.getLatitude(), lhs.getLongitude());
double rd = MapUtils.getDistance(favouritesAdapter.getLocation(), rhs.getLatitude(), rhs.getLongitude());
return Double.compare(ld, rd);
}
return inst.compare(lhs.getName(), rhs.getName());
}
});
listView.setAdapter(favouritesAdapter);
listView.setOnItemClickListener(click);
bld.setPositiveButton(sortByDist ? R.string.sort_by_name : R.string.sort_by_distance, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
showFavoritesDialog(uiContext, favouritesAdapter, click, dismissListener, dialogHolder, !sortByDist);
}
});
bld.setNegativeButton(R.string.shared_string_cancel, null);
bld.setView(listView);
AlertDialog dlg = bld.show();
if (dialogHolder != null) {
dialogHolder[0] = dlg;
}
dlg.setOnDismissListener(dismissListener);
return dlg;
}
Aggregations