Example usage for android.app AlertDialog.Builder setCancelable

List of usage examples for android.app AlertDialog.Builder setCancelable

Introduction

In this page you can find the example usage for android.app AlertDialog.Builder setCancelable.

Prototype

public void setCancelable(boolean flag) 

Source Link

Document

Sets whether this dialog is cancelable with the KeyEvent#KEYCODE_BACK BACK key.

Usage

From source file:com.entertailion.android.dial.ServerFinder.java

private AlertDialog buildNoWifiDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);

    builder.setMessage(R.string.finder_wifi_not_available);
    builder.setCancelable(false);
    builder.setPositiveButton(R.string.finder_configure, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialogInterface, int id) {
            Intent intent = new Intent(Settings.ACTION_WIRELESS_SETTINGS);
            startActivityForResult(intent, CODE_WIFI_SETTINGS);
        }//from  www .j  a  va  2  s. c  o  m
    });
    builder.setNegativeButton(R.string.finder_cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialogInterface, int id) {
            setResult(RESULT_CANCELED, null);
            finish();
        }
    });
    return builder.create();
}

From source file:de.ub0r.android.callmeter.ui.prefs.Preferences.java

/**
 * Reset internal Logs./*w  w  w  .  ja  v  a  2s.  c o m*/
 */
private void resetDataDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.reset_data_);
    builder.setMessage(R.string.reset_data_hint);
    builder.setCancelable(false);
    builder.setPositiveButton(android.R.string.yes, new OnClickListener() {
        @Override
        public void onClick(final DialogInterface dialog, final int which) {
            Preferences.this.resetData(DataProvider.TYPE_CALL);
            Preferences.this.resetData(DataProvider.TYPE_SMS);
            Preferences.this.resetData(DataProvider.TYPE_MMS);
        }
    });
    builder.setNeutralButton(R.string.reset_data_data_, new OnClickListener() {
        @Override
        public void onClick(final DialogInterface dialog, final int which) {
            Preferences.this.resetData(-1);
        }
    });
    builder.setNegativeButton(android.R.string.no, null);
    builder.show();
}

From source file:com.daskiworks.ghwatch.MainActivity.java

private void showMarkAllNotificationsAsReadDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.message_confirm_notifications_all_mark_read_title);
    if (filterByRepository == null) {
        builder.setMessage(R.string.message_confirm_notifications_all_mark_read);
    } else {/* w  w w.  j a  v a2s .c  o m*/
        builder.setMessage(R.string.message_confirm_notifications_all_mark_read_repo);
    }
    builder.setCancelable(true);
    builder.setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            ActivityTracker.sendEvent(MainActivity.this, ActivityTracker.CAT_UI, "notifications_mark_read_all",
                    "", 0L);
            new MarkAllNotificationsAsReadTask().execute();
        }
    });
    builder.setNegativeButton(R.string.button_cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
        }
    });
    builder.create().show();
}

From source file:com.aniruddhc.acemusic.player.LauncherActivity.LauncherActivity.java

public void showTrialDialog(final boolean expired, int numDaysRemaining) {

    AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
    builder.setTitle(R.string.app_name);
    builder.setCancelable(false);

    View view = this.getLayoutInflater().inflate(R.layout.trial_expiry_dialog, null);
    TextView trialExpiredText = (TextView) view.findViewById(R.id.trial_message);
    TextView trialDaysRemaining = (TextView) view.findViewById(R.id.trial_days_remaining);
    TextView trialDaysCaps = (TextView) view.findViewById(R.id.days_caps);

    trialExpiredText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
    trialExpiredText/*w  w w . j ava 2s . c o  m*/
            .setPaintFlags(trialExpiredText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

    trialDaysRemaining.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));

    trialDaysCaps.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
    trialDaysCaps
            .setPaintFlags(trialDaysCaps.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

    if (expired) {
        trialDaysRemaining.setText(R.string.expired);
        trialExpiredText.setText(R.string.trial_expired);
        trialDaysRemaining.setTextColor(0xFFFF8800);
        trialDaysCaps.setVisibility(View.GONE);
        trialDaysRemaining.setTextSize(36);
        trialDaysRemaining.setPaintFlags(
                trialDaysRemaining.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
    } else {
        trialExpiredText.setText(R.string.trial_running);
        trialDaysRemaining.setText("" + numDaysRemaining);
        trialDaysCaps.setVisibility(View.VISIBLE);
        trialDaysRemaining.setTextColor(0xFF0099CC);
        trialDaysRemaining.setPaintFlags(trialDaysRemaining.getPaintFlags() | Paint.ANTI_ALIAS_FLAG
                | Paint.SUBPIXEL_TEXT_FLAG | Paint.FAKE_BOLD_TEXT_FLAG);
    }

    builder.setView(view);
    builder.setPositiveButton(R.string.upgrade, new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            showUpgradeFragmentWithPromo();

        }

    });

    builder.setNegativeButton(R.string.later, new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (expired) {
                finish();
            } else {
                launchMainActivity();
            }

        }

    });

    builder.create().show();
}

From source file:com.jaspersoft.android.jaspermobile.dialog.NumberPickerDialogFragment.java

@NonNull
@Override//from   w  w  w . j a  v a2  s. c o  m
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    ViewGroup customView = (ViewGroup) LayoutInflater.from(getActivity()).inflate(R.layout.number_dialog_layout,
            (ViewGroup) getView(), false);

    numberPicker = (NumberPicker) customView.findViewById(R.id.numberPicker);
    numberPicker.setMinValue(mMinValue);
    numberPicker.setMaxValue(mMaxValue);

    int inputId = getActivity().getResources().getIdentifier("numberpicker_input", "id", "android");
    etNumber = (EditText) numberPicker.findViewById(inputId);
    etNumber.addTextChangedListener(new PickerTextWatcher());

    builder.setTitle(R.string.dialog_current_page);
    builder.setView(customView);
    builder.setCancelable(true);
    builder.setPositiveButton(R.string.ok, this);
    builder.setNegativeButton(R.string.cancel, this);

    AlertDialog dialog = builder.create();
    if (savedInstanceState == null) {
        dialog.setOnShowListener(this);
    }

    return dialog;
}

From source file:com.ezio.multiwii.Main.MainMultiWiiActivity.java

public void VarioSoundOnOffOnClick(View v) {
    if (Sec.VerifyDeveloperID(Sec.GetDeviceID(getApplicationContext()), Sec.TestersIDs)
            || Sec.Verify(getApplicationContext(), "D..3")) {
        app.VarioSound = !app.VarioSound;
    } else {/*from   w ww .j av a 2  s  .  co  m*/
        AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this);

        dlgAlert.setTitle(getString(R.string.Locked));
        dlgAlert.setMessage(getString(R.string.DoYouWantToUnlock));
        // dlgAlert.setPositiveButton(getString(R.string.Yes), null);
        dlgAlert.setCancelable(false);
        dlgAlert.setPositiveButton(getString(R.string.Yes), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                try {
                    Intent LaunchIntent = getPackageManager()
                            .getLaunchIntentForPackage("com.ezio.ez_gui_unlocker");
                    startActivity(LaunchIntent);
                } catch (Exception e) {
                    Intent goToMarket = null;
                    goToMarket = new Intent(Intent.ACTION_VIEW,
                            Uri.parse("market://details?id=com.ezio.ez_gui_unlocker"));
                    startActivity(goToMarket);
                }
                // finish();
            }
        });
        dlgAlert.setNegativeButton(getString(R.string.No), new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                // finish();
            }
        });

        dlgAlert.create().show();
    }

}

From source file:com.orangelabs.rcs.ri.messaging.chat.group.GroupChatView.java

/**
 * Add participants to be invited in the session
 *//*from w w  w .j  a va  2  s . com*/
private void addParticipants() {
    /* Build list of available contacts not already in the conference */
    Set<ContactId> availableParticipants = new HashSet<>();
    try {
        Set<RcsContact> contacts = getContactApi().getRcsContacts();
        for (RcsContact rcsContact : contacts) {
            ContactId contact = rcsContact.getContactId();
            if (mGroupChat.isAllowedToInviteParticipant(contact)) {
                availableParticipants.add(contact);
            }
        }
    } catch (RcsServiceException e) {
        showException(e);
        return;
    }
    /* Check if some participants are available */
    if (availableParticipants.size() == 0) {
        showMessage(R.string.label_no_participant_found);
        return;
    }
    /* Display contacts */
    final List<String> selectedParticipants = new ArrayList<>();
    final CharSequence[] items = new CharSequence[availableParticipants.size()];
    int i = 0;
    for (ContactId contact : availableParticipants) {
        items[i++] = contact.toString();
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.label_select_contacts);
    builder.setCancelable(true);
    builder.setMultiChoiceItems(items, null, new DialogInterface.OnMultiChoiceClickListener() {
        public void onClick(DialogInterface dialog, int which, boolean isChecked) {
            String c = (String) items[which];
            if (isChecked) {
                selectedParticipants.add(c);
            } else {
                selectedParticipants.remove(c);
            }
        }
    });
    builder.setNegativeButton(R.string.label_cancel, null);
    builder.setPositiveButton(R.string.label_ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int position) {
            /* Add new participants in the session in background */
            try {
                int max = mGroupChat.getMaxParticipants() - 1;
                int connected = mGroupChat.getParticipants().size();
                int limit = max - connected;
                if (selectedParticipants.size() > limit) {
                    showMessage(R.string.label_max_participants);
                    return;
                }
                Set<ContactId> contacts = new HashSet<>();
                ContactUtil contactUtils = ContactUtil.getInstance(GroupChatView.this);
                for (String participant : selectedParticipants) {
                    contacts.add(contactUtils.formatContact(participant));
                }
                /* Add participants */
                mGroupChat.inviteParticipants(contacts);

            } catch (RcsServiceException e) {
                showException(e);
            }
        }
    });
    registerDialog(builder.show());
}

From source file:com.almunt.jgcaap.systemupdater.MainActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
        refreshLayout.setRefreshing(true);
        final GetLinks g = new GetLinks();
        RefreshLinks2(g);//from w w w.  j a va2 s .  c o  m
        refreshLayout.setRefreshing(false);
    } else {
        AlertDialog.Builder builder1 = new AlertDialog.Builder(MainActivity.this);
        builder1.setTitle("This app needs the storage permission to download and view jgcaap rom updates");
        builder1.setMessage(
                "Tap \"Request Permission\" to try requesting the permission again or close the app");
        builder1.setCancelable(false);
        builder1.setPositiveButton("Request Permission", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                ActivityCompat.requestPermissions(MainActivity.this,
                        new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 1);
            }
        });
        builder1.setNegativeButton("Close App", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                finish();
            }
        });
        AlertDialog alert11 = builder1.create();
        alert11.show();
    }
}

From source file:it.scoppelletti.mobilepower.app.HelpDialogFragment.java

/**
 * Crea il dialogo./*from   ww  w  . j a va  2 s  . co m*/
 * 
 * @param  savedInstanceState Stato dell&rsquo;istanza.
 * @return                    Dialogo.
 */
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    int mode, resId;
    View contentView;
    AlertDialog dlg;
    AlertDialog.Builder builder;
    LayoutInflater inflater;
    TextView textControl;
    Bundle args = getArguments();

    builder = newAlertDialogBuilder();

    resId = args.getInt(HelpDialogFragment.ARG_TITLEID, 0);
    if (resId > 0) {
        builder.setTitle(resId);
    }

    inflater = getActivity().getLayoutInflater();
    contentView = inflater.inflate(R.layout.helpdialog, null);
    builder.setView(contentView);

    builder.setIcon(android.R.drawable.ic_dialog_info);

    mode = getArguments().getInt(HelpDialogFragment.ARG_MODE, HelpDialogFragment.MODE_HELP);
    switch (mode) {
    case HelpDialogFragment.MODE_CONFIRM:
        setCancelable(false);
        builder.setCancelable(false);
        builder.setPositiveButton(R.string.cmd_proceed, this);
        builder.setNegativeButton(android.R.string.cancel, this);
        break;

    default: // HelpDialogFragment.MODE_HELP
        builder.setNeutralButton(R.string.cmd_close, null);
        break;
    }

    dlg = builder.create();

    textControl = (TextView) contentView.findViewById(R.id.txt_help);
    textControl.setKeyListener(null);

    resId = args.getInt(HelpDialogFragment.ARG_TEXTID, 0);
    if (resId > 0) {
        textControl.setText(Html.fromHtml(getResources().getString(resId)));
    }

    return dlg;
}

From source file:org.kde.necessitas.ministro.MinistroActivity.java

private void checkNetworkAndDownload(final boolean update) {
    if (isOnline(this))
        new CheckLibraries().execute(update);
    else {//from  w w  w .  ja  v a2 s  .com
        AlertDialog.Builder builder = new AlertDialog.Builder(MinistroActivity.this);
        builder.setMessage(getResources().getString(R.string.ministro_network_access_msg));
        builder.setCancelable(true);
        builder.setNeutralButton(getResources().getString(R.string.settings_msg),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        final ProgressDialog m_dialog = ProgressDialog.show(MinistroActivity.this, null,
                                getResources().getString(R.string.wait_for_network_connection_msg), true, true,
                                new DialogInterface.OnCancelListener() {
                                    public void onCancel(DialogInterface dialog) {
                                        finishMe();
                                    }
                                });
                        getApplication().registerReceiver(new BroadcastReceiver() {
                            @Override
                            public void onReceive(Context context, Intent intent) {
                                if (isOnline(MinistroActivity.this)) {
                                    try {
                                        getApplication().unregisterReceiver(this);
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                    runOnUiThread(new Runnable() {
                                        public void run() {
                                            m_dialog.dismiss();
                                            new CheckLibraries().execute(update);
                                        }
                                    });
                                }
                            }
                        }, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
                        try {
                            startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
                        } catch (Exception e) {
                            e.printStackTrace();
                            try {
                                startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
                            } catch (Exception e1) {

                                e1.printStackTrace();
                            }
                        }
                        dialog.dismiss();
                    }
                });
        builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
            }
        });
        builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
            public void onCancel(DialogInterface dialog) {
                finishMe();
            }
        });
        AlertDialog alert = builder.create();
        alert.show();
    }
}