Java Code Examples for android.support.v7.app.AlertDialog#setButton()

The following examples show how to use android.support.v7.app.AlertDialog#setButton() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AddTodoItem.java    From Minitask with Apache License 2.0 6 votes vote down vote up
@Override
public void onDateSet(DatePickerDialog view, int year, int monthOfYear, int dayOfMonth) {
    // if the date is in the past tell user to choose again
    if (dateTimeUtils.checkInvalidDate(year, monthOfYear, dayOfMonth)){
        AlertDialog alertDialog = new AlertDialog.Builder(AddTodoItem.this).create();
        alertDialog.setTitle("Date not valid!");
        alertDialog.setIcon(R.drawable.ic_warning_black_24dp);
        alertDialog.setMessage("You are selecting a time a point of time in the past!");
        alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        alertDialog.show();
        return;
    }

    // set date value to the value user selected and change the text
    date = dateTimeUtils.dateToString(year, monthOfYear, dayOfMonth);
    reminderText.setText(getString(R.string.reminder_set_at) + " " + date + " " + time);
}
 
Example 2
Source File: AddTodoItem.java    From Minitask with Apache License 2.0 6 votes vote down vote up
@Override
public void onTimeSet(TimePickerDialog view, int hourOfDay, int minute, int second) {
    // if date is not chosen first but time is chosen -> make today the default date.
    // also check for valid time, must be today but not the past hour or minutes.
    if (date.equals(dateTimeUtils.fillDateIfEmpty("")) && dateTimeUtils.checkInvalidTime(hourOfDay, minute)) {
        AlertDialog alertDialog = new AlertDialog.Builder(AddTodoItem.this).create();
        alertDialog.setTitle("Time not valid!");
        alertDialog.setMessage("You are selecting a point of time in the past!");
        alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        alertDialog.show();
        return;
    }

    // set time value and update text
    time = dateTimeUtils.timeToString(hourOfDay, minute);
    reminderText.setText(getString(R.string.reminder_set_at) + " " + date + " " + time);
}
 
Example 3
Source File: MainActivity.java    From LecteurOPUS with GNU General Public License v3.0 6 votes vote down vote up
private void enableReaderMode() {
    Log.i(TAG, "Enabling reader mode");
    Activity activity = this;
    NfcAdapter nfc = NfcAdapter.getDefaultAdapter(activity);
    if (!nfc.isEnabled()) {
        AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
        alertDialog.setTitle(getString(R.string.disable_title));
        alertDialog.setMessage(getString(R.string.nfc_disable));
        alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        startActivity(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS));

                    }
                });
        alertDialog.show();
    }
    else if (nfc != null) {
        nfc.enableReaderMode(activity, mCardReader, FLAG_MIFARE | FLAG_OPUS, null);
    }
}
 
Example 4
Source File: ArticlesFragment.java    From WanAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public void showAutoLoginFail() {
    final AlertDialog alertDialog = new AlertDialog.Builder(getContext()).create();
    alertDialog.setTitle(R.string.warning_title);
    alertDialog.setMessage(getString(R.string.tip));
    alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.sure), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            MainActivity main = (MainActivity) getActivity();
            main.navigateToLogin();
            alertDialog.dismiss();
        }
    });
    alertDialog.show();
}
 
Example 5
Source File: WaypointNavigationActivity.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
private void showDropoffDialog() {
  AlertDialog alertDialog = new AlertDialog.Builder(this).create();
  alertDialog.setMessage(getString(R.string.dropoff_dialog_text));
  alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.dropoff_dialog_positive_text),
    (dialogInterface, in) -> fetchRoute(getLastKnownLocation(), points.remove(0)));
  alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.dropoff_dialog_negative_text),
    (dialogInterface, in) -> {
      // Do nothing
    });

  alertDialog.show();
}
 
Example 6
Source File: CompassActivity.java    From Travel-Mate with MIT License 5 votes vote down vote up
/**
 * Check AccelerometerSensor in device
 **/
private void getAccelerometerSensor() {
    PackageManager mManager = getPackageManager();
    boolean hasAccelerometer = mManager.hasSystemFeature(PackageManager.FEATURE_SENSOR_ACCELEROMETER);
    boolean hasMagneticSensor = mManager.hasSystemFeature(PackageManager.FEATURE_SENSOR_COMPASS);
    if (!hasAccelerometer || !hasMagneticSensor) {
        AlertDialog alertDialog = new AlertDialog.Builder(CompassActivity.this).create();
        alertDialog.setTitle(getResources().getString(R.string.compass_dialog_header));
        alertDialog.setMessage(getResources().getString(R.string.compass_dialog_description));
        alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, getResources().getString(R.string.compass_dialog_confirm),
                (dialog, which) -> dialog.dismiss());
        alertDialog.show();
    }
}
 
Example 7
Source File: AboutFragment.java    From go-bees with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Shows a dialog with given data.
 *
 * @param title dialog title.
 * @param body  dialog text.
 */
private void showDialog(String title, String body) {
    AlertDialog alertDialog = new AlertDialog.Builder(getContext()).create();
    alertDialog.setTitle(title);
    alertDialog.setMessage(AndroidUtils.fromHtml(body));
    alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, getString(R.string.close_btn),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
    alertDialog.show();
}
 
Example 8
Source File: GameFragment.java    From block-this with GNU General Public License v3.0 5 votes vote down vote up
public void displayDialog(){
    AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).create();
    alertDialog.setTitle("Thank you!");
    alertDialog.setMessage("By installing any of these games, you support this app's existence and further development." +
            " Without your help, all of this would not be possible. Thank you!");
    alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "Okay, I understand",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    sharedPreferences.edit().putBoolean("seen_games_dialog", true).apply();
                    dialog.dismiss();
                }
            });
    alertDialog.show();
}
 
Example 9
Source File: UpdateAgent.java    From update with Apache License 2.0 4 votes vote down vote up
@Override
public void prompt(IUpdateAgent agent) {
    if (mContext instanceof Activity && ((Activity) mContext).isFinishing()) {
        return;
    }
    final UpdateInfo info = agent.getInfo();
    String size = Formatter.formatShortFileSize(mContext, info.size);
    String content = String.format("最新版本:%1$s\n新版本大小:%2$s\n\n更新内容\n%3$s", info.versionName, size, info.updateContent);

    final AlertDialog dialog = new AlertDialog.Builder(mContext).create();

    dialog.setTitle("应用更新");
    dialog.setCancelable(false);
    dialog.setCanceledOnTouchOutside(false);


    float density = mContext.getResources().getDisplayMetrics().density;
    TextView tv = new TextView(mContext);
    tv.setMovementMethod(new ScrollingMovementMethod());
    tv.setVerticalScrollBarEnabled(true);
    tv.setTextSize(14);
    tv.setMaxHeight((int) (250 * density));

    dialog.setView(tv, (int) (25 * density), (int) (15 * density), (int) (25 * density), 0);


    DialogInterface.OnClickListener listener = new DefaultPromptClickListener(agent, true);

    if (info.isForce) {
        tv.setText("您需要更新应用才能继续使用\n\n" + content);
        dialog.setButton(DialogInterface.BUTTON_POSITIVE, "确定", listener);
    } else {
        tv.setText(content);
        dialog.setButton(DialogInterface.BUTTON_POSITIVE, "立即更新", listener);
        dialog.setButton(DialogInterface.BUTTON_NEGATIVE, "以后再说", listener);
        if (info.isIgnorable) {
            dialog.setButton(DialogInterface.BUTTON_NEUTRAL, "忽略该版", listener);
        }
    }
    dialog.show();
}