Search in sources :

Example 91 with OnClickListener

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();
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) OnClickListener(android.content.DialogInterface.OnClickListener)

Example 92 with OnClickListener

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]);
    }
}
Also used : DialogInterface(android.content.DialogInterface) LayoutInflater(android.view.LayoutInflater) Activity(android.app.Activity) OnClickListener(android.content.DialogInterface.OnClickListener) Resources(android.content.res.Resources) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) View(android.view.View)

Example 93 with OnClickListener

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;
}
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 94 with OnClickListener

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();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) OnClickListener(android.content.DialogInterface.OnClickListener) GeoParsedPoint(net.osmand.util.GeoPointParserUtil.GeoParsedPoint)

Example 95 with OnClickListener

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;
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) ListView(android.widget.ListView) FavouritePoint(net.osmand.data.FavouritePoint) DialogInterface(android.content.DialogInterface) OnClickListener(android.content.DialogInterface.OnClickListener) FavouritePoint(net.osmand.data.FavouritePoint) Collator(java.text.Collator)

Aggregations

OnClickListener (android.content.DialogInterface.OnClickListener)264 DialogInterface (android.content.DialogInterface)259 AlertDialog (android.app.AlertDialog)161 View (android.view.View)75 TextView (android.widget.TextView)52 Intent (android.content.Intent)44 SuppressLint (android.annotation.SuppressLint)41 Context (android.content.Context)35 AlertDialog (android.support.v7.app.AlertDialog)32 LayoutInflater (android.view.LayoutInflater)30 EditText (android.widget.EditText)30 Activity (android.app.Activity)27 Bundle (android.os.Bundle)25 OnCancelListener (android.content.DialogInterface.OnCancelListener)21 ImageView (android.widget.ImageView)17 Builder (android.app.AlertDialog.Builder)16 Dialog (android.app.Dialog)16 ProgressDialog (android.app.ProgressDialog)15 Paint (android.graphics.Paint)15 AdapterView (android.widget.AdapterView)15