/** Children can extend this to add more things to base builder. */
  @Override
  protected Builder build(Builder builder) {
    final String title = getTitle();
    if (!TextUtils.isEmpty(title)) {
      builder.setTitle(title);
    }

    final String message = getMessage();
    if (!TextUtils.isEmpty(message)) {
      builder.setMessage(message);
    }

    final String positiveButtonText = getPositiveButtonText();
    if (!TextUtils.isEmpty(positiveButtonText)) {
      builder.setPositiveButton(
          positiveButtonText,
          new View.OnClickListener() {
            @Override
            public void onClick(View view) {
              ISimpleDialogListener listener = getDialogListener();
              if (listener != null) {
                listener.onPositiveButtonClicked(mRequestCode);
              }
              dismiss();
            }
          });
    }

    final String negativeButtonText = getNegativeButtonText();
    if (!TextUtils.isEmpty(negativeButtonText)) {
      builder.setNegativeButton(
          negativeButtonText,
          new View.OnClickListener() {
            @Override
            public void onClick(View view) {
              ISimpleDialogListener listener = getDialogListener();
              if (listener != null) {
                listener.onNegativeButtonClicked(mRequestCode);
              }
              dismiss();
            }
          });
    }
    return builder;
  }
Example #2
0
    @Override
    protected Builder build(Builder builder) {
      /* set dialog title */
      String title = String.format("About %s", getString(R.string.app_name));
      builder.setTitle(title);

      /* set dialog main message */
      final TextView message = new TextView(getActivity());
      SpannableString aboutText = new SpannableString(getString(R.string.about_text));
      String versionString = String.format("Version: %s", getAppVersion());
      message.setText(versionString + "\n\n" + aboutText);
      message.setTextSize(16);
      Linkify.addLinks(message, Linkify.ALL);
      int padding = (int) getActivity().getResources().getDimension(R.dimen.dialog_message_padding);
      builder.setView(message, padding, padding, padding, padding);

      /* set buttons (only add the "go pro" button to free version) */
      if (mPackageInfo != null && !mPackageInfo.packageName.contains("glimmrpro")) {
        builder.setNegativeButton(
            getString(R.string.pro_donate),
            new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                Uri uri = Uri.parse(Constants.PRO_MARKET_LINK);
                Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                startActivity(intent);
                dismiss();
              }
            });
      }
      builder.setPositiveButton(
          getString(android.R.string.ok),
          new View.OnClickListener() {
            @Override
            public void onClick(View view) {
              dismiss();
            }
          });

      return builder;
    }
  private void build() {
    final WorkoutsActivity activity = (WorkoutsActivity) context;

    Builder builder = new Builder(context);
    builder.setTitle(R.string.delete_workout);
    builder.setMessage(
        Html.fromHtml(
            getContext().getString(R.string.really_delete_workout) + ": <b>" + name + "</b>"));
    builder
        .setPositiveButton(
            R.string.delete,
            new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int id) {
                activity.removeWorkout(position);
              }
            })
        .setNegativeButton(
            R.string.cancel,
            new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int id) {}
            });
    builder.create().show();
  }