Java Code Examples for android.app.AlertDialog.Builder#setCancelable()

The following examples show how to use android.app.AlertDialog.Builder#setCancelable() . 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: LogsFragment.java    From callmeter with GNU General Public License v3.0 8 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean onItemLongClick(final AdapterView<?> parent, final View view,
        final int position, final long id) {
    final Builder b = new Builder(getActivity());
    b.setCancelable(true);
    b.setItems(R.array.dialog_delete, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(final DialogInterface dialog, final int which) {
            LogsFragment.this
                    .getActivity()
                    .getContentResolver()
                    .delete(ContentUris.withAppendedId(DataProvider.Logs.CONTENT_URI, id),
                            null, null);
            LogsFragment.this.setAdapter(true);
            LogRunnerService.update(LogsFragment.this.getActivity(), null);
        }
    });
    b.setNegativeButton(android.R.string.cancel, null);
    b.show();
    return true;
}
 
Example 2
Source File: Utils.java    From BatteryFu with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Prompt user whether to proceed or not, if so, execute runnable
 * 
 * @param context
 * @param titleResId
 * @param msgResId
 * @param onConfirm
 */
public static void confirm(Context context, String logTag, int titleResId, int msgResId,
         int OkResId, int cancelResId, final Runnable onConfirm) {
   AlertDialog dialog = null;
   try {
      Builder b = new Builder(context);
      b.setCancelable(true);
      if (titleResId >= 0) b.setTitle(titleResId);
      if (msgResId >= 0) b.setMessage(msgResId);
      if (cancelResId >= 0) b.setNegativeButton(cancelResId, null);
      if (onConfirm != null && OkResId >= 0) b.setPositiveButton(OkResId, new OnClickListener() {
         @Override
         public void onClick(DialogInterface arg0, int arg1) {
            onConfirm.run();
         }
      });

      b.create().show();
   } catch (Exception e) {
      if (logTag != null) Utils.handleException(logTag, context, e);
   }
}
 
Example 3
Source File: BaseActivity.java    From Viewer with Apache License 2.0 5 votes vote down vote up
public void openDialogMessage(int title,String message){
	final Builder builder = new AlertDialog.Builder(this);
	builder.setTitle(title);
	builder.setMessage(message);
	builder.setCancelable(true);
	builder.setPositiveButton(R.string.ok_btn, new DialogInterface.OnClickListener() {
		public void onClick(DialogInterface dialog, int which) {
			builder.create().dismiss();
		}
	});
	builder.show();
}
 
Example 4
Source File: BaseActivity.java    From Viewer with Apache License 2.0 5 votes vote down vote up
public void openDialogMessage(int title,int message,boolean isCancelable){
	final Builder builder = new AlertDialog.Builder(this);
	builder.setTitle(title);
	builder.setMessage(message);
	builder.setCancelable(isCancelable);
	builder.setPositiveButton(R.string.ok_btn, new DialogInterface.OnClickListener() {
		public void onClick(DialogInterface dialog, int which) {
			builder.create().dismiss();
			finish();
		}
	});
	builder.show();
}
 
Example 5
Source File: BaseActivity.java    From Viewer with Apache License 2.0 5 votes vote down vote up
public void openDialogMessage(int title,int message,boolean isCancelable,boolean killAllActivity){
		final Builder builder = new AlertDialog.Builder(this);
		builder.setTitle(title);
		builder.setMessage(message);
		builder.setCancelable(isCancelable);
		builder.setPositiveButton(R.string.confirm_btn, new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int which) {
				builder.create().dismiss();
				if(isExit){
//					application.exit();
				}
			}
		});
		builder.show();
	}
 
Example 6
Source File: Display.java    From Women-Safety-App with GNU General Public License v2.0 5 votes vote down vote up
public void showMessage(String title,String message)
{
    Builder builder=new Builder(this);
    builder.setCancelable(true);
    builder.setTitle(title);
    builder.setMessage(message);
    builder.show();
}
 
Example 7
Source File: BaseActivity.java    From Viewer with Apache License 2.0 5 votes vote down vote up
public void openDialogMessage(int title,int message){
	final Builder builder = new AlertDialog.Builder(this);
	builder.setTitle(title);
	builder.setMessage(message);
	builder.setCancelable(true);
	builder.setPositiveButton(R.string.ok_btn, new DialogInterface.OnClickListener() {
		public void onClick(DialogInterface dialog, int which) {
			builder.create().dismiss();
		}
	});
	builder.show();
}
 
Example 8
Source File: BillModeListPreference.java    From callmeter with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onDialogClosed(final boolean positiveResult) {
    final String ov = getValue();
    super.onDialogClosed(positiveResult);
    if (positiveResult) {
        String v = getValue();
        if (v == null || !v.contains("/")) { // custom bill mode
            Builder b = new Builder(getContext());
            final EditText et = new EditText(getContext());
            et.setText(ov);
            b.setView(et);
            b.setCancelable(false);
            b.setTitle(getTitle());
            b.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface paramDialogInterface,
                        final int paramInt) {
                    BillModeListPreference.this.setValue(ov);
                }
            });
            b.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    String nv = et.getText().toString().trim();
                    final String[] t = nv.toString().split("/");
                    if (t.length != 2 || !TextUtils.isDigitsOnly(t[0])
                            || !TextUtils.isDigitsOnly(t[1])) {
                        Toast.makeText(BillModeListPreference.this.ctx, R.string.missing_slash,
                                Toast.LENGTH_LONG).show();
                        BillModeListPreference.this.setValue(ov);
                    } else {
                        BillModeListPreference.this.setValue(nv);
                    }
                }
            });
            b.show();
        }
    }
}
 
Example 9
Source File: SingleChoiceDialogFragment.java    From barterli_android with Apache License 2.0 5 votes vote down vote up
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {

    if (savedInstanceState != null) {
        mTitleId = savedInstanceState.getInt(DialogKeys.TITLE_ID);
        isCancellable = savedInstanceState
                        .getBoolean(DialogKeys.CANCELLABLE);
        mIconId = savedInstanceState.getInt(DialogKeys.ICON_ID);
        mTheme = savedInstanceState.getInt(DialogKeys.THEME);
        mItemsId = savedInstanceState.getInt(DialogKeys.ITEMS_ID);
    }

    final Builder builder = new Builder(getActivity(), mTheme);

    if (mItemsId == 0) {
        throw new IllegalArgumentException("No items available to add");
    }

    builder.setItems(mItemsId, mClickListener);

    if (mIconId != 0) {
        builder.setIcon(mIconId);
    }
    if (mTitleId != 0) {
        builder.setTitle(mTitleId);
    }

    builder.setCancelable(isCancellable);
    setCancelable(isCancellable);
    return builder.create();
}
 
Example 10
Source File: MyOverlays.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
protected boolean onTap(int index) {
	OverlayItem overlayItem = overlays[index];
	Builder builder = new AlertDialog.Builder(context);
	builder.setMessage("This will end the activity");
	builder.setCancelable(true);
	builder.setPositiveButton("I agree", new OkOnClickListener());
	builder.setNegativeButton("No, no", new CancelOnClickListener());
	AlertDialog dialog = builder.create();
	dialog.show();
	return true;
}
 
Example 11
Source File: AlertExampleActivity.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected Dialog onCreateDialog(int id) {
	switch (id) {
	case DIALOG_ALERT:
		// Create out AlterDialog
		Builder builder = new AlertDialog.Builder(this);
		builder.setMessage("This will end the activity");
		builder.setCancelable(true);
		builder.setPositiveButton("I agree", new OkOnClickListener());
		builder.setNegativeButton("No, no", new CancelOnClickListener());
		AlertDialog dialog = builder.create();
		dialog.show();
	}
	return super.onCreateDialog(id);
}
 
Example 12
Source File: HourGroupEdit.java    From callmeter with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Show dialog to edit the group name.
 */
private void showNameDialog() {
    final Uri u = ContentUris.withAppendedId(DataProvider.HoursGroup.CONTENT_URI, gid);
    Cursor c = getContentResolver().query(u, DataProvider.HoursGroup.PROJECTION, null,
            null, null);
    String name = null;
    if (c.moveToFirst()) {
        name = c.getString(DataProvider.NumbersGroup.INDEX_NAME);
    }
    c.close();
    final Builder builder = new Builder(this);
    final EditText et = new EditText(this);
    et.setText(name);
    builder.setView(et);
    builder.setTitle(R.string.name_);
    builder.setCancelable(true);
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        public void onClick(final DialogInterface dialog, final int id) {
            ContentValues values = new ContentValues();
            values.put(DataProvider.NumbersGroup.NAME, et.getText().toString());
            HourGroupEdit.this.getContentResolver().update(u, values, null, null);
            CallMeter.setActivitySubtitle(HourGroupEdit.this, et.getText().toString());
        }
    });
    builder.setNegativeButton(android.R.string.cancel, null);
    builder.show();
}
 
Example 13
Source File: NumberGroupEdit.java    From callmeter with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Show dialog to edit the group name.
 */
private void showNameDialog() {
    final Uri u = ContentUris.withAppendedId(DataProvider.NumbersGroup.CONTENT_URI, gid);
    Cursor c = getContentResolver().query(u, DataProvider.NumbersGroup.PROJECTION, null,
            null, null);
    String name = null;
    if (c.moveToFirst()) {
        name = c.getString(DataProvider.NumbersGroup.INDEX_NAME);
    }
    c.close();
    final Builder builder = new Builder(this);
    final EditText et = new EditText(this);
    et.setText(name);
    builder.setView(et);
    builder.setTitle(R.string.name_);
    builder.setCancelable(true);
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        public void onClick(final DialogInterface dialog, final int id) {
            ContentValues values = new ContentValues();
            values.put(DataProvider.NumbersGroup.NAME, et.getText().toString());
            NumberGroupEdit.this.getContentResolver().update(u, values, null, null);
            CallMeter.setActivitySubtitle(NumberGroupEdit.this, et.getText().toString());
        }
    });
    builder.setNegativeButton(android.R.string.cancel, null);
    builder.show();
}
 
Example 14
Source File: MainActivity.java    From BlackJack with MIT License 4 votes vote down vote up
public void alertBox() {

    final Builder alert = new Builder(this);
    alert.setCancelable(false);
    String message = "Play Again";
    String positive = "Next Hand";
    if (splitting) {
      message = "You previously split, continue?";
      positive = "I am ready";
    }
    final String finalMessage = message;
    final String finalPositive = positive;
    Thread t = new Thread() {
      public void run() {

        try {
          sleep(1500);
        } catch (InterruptedException e) {
          e.printStackTrace();
        }

        runOnUiThread(new Runnable() {
          public void run() {
            alert.setMessage(finalMessage);
            alert.setPositiveButton(finalPositive,
                                    new DialogInterface.OnClickListener() {

                                      public void onClick(DialogInterface dialog,
                                                          int which) {
                                        if (splitting) {
                                          _bet = _splitBet;
                                          _money = _money - _bet;
                                          tvMoney.setText(" $ " + _money);
                                          tvBet.setText("Bet - $ " + _bet);

                                          splitting = false;
                                          ivSplitCard1.setVisibility(View.GONE);
                                          ivSplitCard2.setVisibility(View.GONE);
                                          ivSplitCard3.setVisibility(View.GONE);
                                          ivSplitCard4.setVisibility(View.GONE);
                                          ivSplitCard5.setVisibility(View.GONE);

                                          ivDealerCard1.setImageResource(R.drawable.default_red);
                                          ivDealerCard2.setImageResource(R.drawable.default_red);
                                          ivDealerCard3.setImageResource(R.drawable.default_red);
                                          ivDealerCard4.setImageResource(R.drawable.default_red);
                                          ivDealerCard5.setImageResource(R.drawable.default_red);

                                          ivYourCard1.setImageResource(R.drawable.default_blue);
                                          ivYourCard2.setImageResource(R.drawable.default_blue);
                                          ivYourCard3.setImageResource(R.drawable.default_blue);
                                          ivYourCard4.setImageResource(R.drawable.default_blue);
                                          ivYourCard5.setImageResource(R.drawable.default_blue);

                                          for (int i = 0; i < 5; i++) {
                                            _dealerCardArray[i] = '0';
                                            _dealerScoreCount[i] = 0;
                                            _playerCardArray[i] = '0';
                                            _playerScoreCount[i] = 0;
                                          }

                                          _dealerCardArray[0] = cardsCalling(_splitDealerCard, ivDealerCard1);
                                          _dealerScoreCount[0] = getIntValueFromCard(_dealerCardArray[0]);
                                          _playerCardArray[0] = cardsCalling(_splitCard, ivYourCard1);
                                          _playerScoreCount[0] = getIntValueFromCard(_playerCardArray[0]);
                                          _playerCardNumber = 1;
                                          _dealerCardNumber = 1;

                                          calculateDealerScore();
                                          calculatePlayerScore();
                                        }else  {
                                          resetEveryThing();
                                          hidePlayButtons();
                                          // Making some sound here
                                          SharedPreferences prefs = PreferenceManager
                                              .getDefaultSharedPreferences(getApplicationContext());
                                          boolean gameSound = prefs.getBoolean(
                                              "pref_cb_sound",
                                              true);

                                          if (gameSound) {
                                            mp.release();
                                          }
                                        }
                                      }
                                    });
            alert.show();
          }
        });
      }
    };
    t.start();
    // Thread ends here
  }
 
Example 15
Source File: CVBillModePreference.java    From callmeter with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onDialogClosed(final boolean positiveResult) {
    final String ov = getValue();
    super.onDialogClosed(positiveResult);
    if (positiveResult) {
        String v = getValue();
        if (v == null || !v.contains("/")) { // custom bill mode
            Builder b = new Builder(getContext());
            final EditText et = new EditText(getContext());
            et.setText(ov);
            b.setView(et);
            b.setCancelable(false);
            b.setTitle(getTitle());
            b.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface paramDialogInterface,
                        final int paramInt) {
                    CVBillModePreference.this.setValue(ov);
                }
            });
            b.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    String nv = et.getText().toString().trim();
                    final String[] t = nv.toString().split("/");
                    if (t.length != 2 || !TextUtils.isDigitsOnly(t[0])
                            || !TextUtils.isDigitsOnly(t[1])) {
                        Toast.makeText(CVBillModePreference.this.ctx, R.string.missing_slash,
                                Toast.LENGTH_LONG).show();
                        CVBillModePreference.this.setValue(ov);
                    } else {
                        CVBillModePreference.this.setValue(nv);
                        CVBillModePreference.this.cv
                                .put(CVBillModePreference.this.getKey(), nv);
                        if (CVBillModePreference.this.ul != null) {
                            CVBillModePreference.this.ul
                                    .onUpdateValue(CVBillModePreference.this);
                        }
                    }
                }
            });
            b.show();
        } else {
            cv.put(getKey(), v);
            if (ul != null) {
                ul.onUpdateValue(this);
            }
        }
    }
}
 
Example 16
Source File: EnableLocationDialogFragment.java    From barterli_android with Apache License 2.0 4 votes vote down vote up
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {

    if (savedInstanceState != null) {
        mTitleId = savedInstanceState.getInt(DialogKeys.TITLE_ID);
        
        mMessageId = savedInstanceState.getInt(DialogKeys.MESSAGE_ID);
        mNegativeLabelId = savedInstanceState
                        .getInt(DialogKeys.NEGATIVE_LABEL_ID);
        mNeutralLabelId = savedInstanceState
                        .getInt(DialogKeys.NEUTRAL_LABEL_ID);
        mPositiveLabelId = savedInstanceState
                        .getInt(DialogKeys.POSITIVE_LABEL_ID);
        isCancellable = savedInstanceState
                        .getBoolean(DialogKeys.CANCELLABLE);
        mIconId = savedInstanceState.getInt(DialogKeys.ICON_ID);
        mTheme = savedInstanceState.getInt(DialogKeys.THEME);
        mMessageParams = savedInstanceState
                .getStringArray(DialogKeys.MESSAGE_PARAMS);
    }

    final Builder builder = new Builder(getActivity(), mTheme);

    if ((mTitleId == 0) && (mMessageId == 0)) {
        throw new IllegalArgumentException("No Title and no message");
    }
    
    if (mMessageId != 0) {

        if ((mMessageParams != null) && (mMessageParams.length > 0)) {
            builder.setMessage(getActivity()
                            .getString(mMessageId, (Object[]) mMessageParams));
        } else {
            builder.setMessage(mMessageId);
        }
    }

  

    if (mIconId != 0) {
        builder.setIcon(mIconId);
    }
    if (mTitleId != 0) {
        builder.setTitle(mTitleId);
    }

    if (mPositiveLabelId != 0) {
        builder.setPositiveButton(mPositiveLabelId, mClickListener);
    }

    if (mNegativeLabelId != 0) {
        builder.setNegativeButton(mNegativeLabelId, mClickListener);
    }

    if (mNeutralLabelId != 0) {
        builder.setNeutralButton(mNeutralLabelId, mClickListener);
    }

    builder.setCancelable(isCancellable);
    setCancelable(isCancellable);
    return builder.create();
}
 
Example 17
Source File: AddSingleEditTextDialogFragment.java    From barterli_android with Apache License 2.0 4 votes vote down vote up
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {

    if (savedInstanceState != null) {
        mTitleId = savedInstanceState.getInt(DialogKeys.TITLE_ID);
        mNegativeLabelId = savedInstanceState
                        .getInt(DialogKeys.NEGATIVE_LABEL_ID);
        mNeutralLabelId = savedInstanceState
                        .getInt(DialogKeys.NEUTRAL_LABEL_ID);
        mPositiveLabelId = savedInstanceState
                        .getInt(DialogKeys.POSITIVE_LABEL_ID);
        isCancellable = savedInstanceState
                        .getBoolean(DialogKeys.CANCELLABLE);
        mIconId = savedInstanceState.getInt(DialogKeys.ICON_ID);
        mTheme = savedInstanceState.getInt(DialogKeys.THEME);
    }

    final Builder builder = new Builder(getActivity(), mTheme);

    final View contentView = LayoutInflater.from(getActivity())
                    .inflate(R.layout.layout_dialog_place, null);
    mNameEditText = (EditText) contentView
                    .findViewById(R.id.edittext_location_name);
    
    if(mHintLabelId!=0)
    {
    	mNameEditText.setHint(mHintLabelId);
    }
    builder.setView(contentView);

    if (mIconId != 0) {
        builder.setIcon(mIconId);
    }
    if (mTitleId != 0) {
        builder.setTitle(mTitleId);
    }

    if (mPositiveLabelId != 0) {
        builder.setPositiveButton(mPositiveLabelId, mClickListener);
    }

    if (mNegativeLabelId != 0) {
        builder.setNegativeButton(mNegativeLabelId, mClickListener);
    }

    if (mNeutralLabelId != 0) {
        builder.setNeutralButton(mNeutralLabelId, mClickListener);
    }

    builder.setCancelable(isCancellable);
    setCancelable(isCancellable);
    return builder.create();
}
 
Example 18
Source File: AlertDialogFragment.java    From barterli_android with Apache License 2.0 4 votes vote down vote up
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {

    if (savedInstanceState != null) {
        mTitleId = savedInstanceState.getInt(DialogKeys.TITLE_ID);
        mMessageId = savedInstanceState.getInt(DialogKeys.MESSAGE_ID);
        mNegativeLabelId = savedInstanceState
                        .getInt(DialogKeys.NEGATIVE_LABEL_ID);
        mNeutralLabelId = savedInstanceState
                        .getInt(DialogKeys.NEUTRAL_LABEL_ID);
        mPositiveLabelId = savedInstanceState
                        .getInt(DialogKeys.POSITIVE_LABEL_ID);
        isCancellable = savedInstanceState
                        .getBoolean(DialogKeys.CANCELLABLE);
        mIconId = savedInstanceState.getInt(DialogKeys.ICON_ID);
        mTheme = savedInstanceState.getInt(DialogKeys.THEME);
        mMessageParams = savedInstanceState
                        .getStringArray(DialogKeys.MESSAGE_PARAMS);
    }

    final Builder builder = new Builder(getActivity(), mTheme);

    if ((mTitleId == 0) && (mMessageId == 0)) {
        throw new IllegalArgumentException("No Title and no message");
    }
    if (mIconId != 0) {
        builder.setIcon(mIconId);
    }
    if (mTitleId != 0) {
        builder.setTitle(mTitleId);
    }

    if (mMessageId != 0) {

        if ((mMessageParams != null) && (mMessageParams.length > 0)) {
            builder.setMessage(getActivity()
                            .getString(mMessageId, (Object[]) mMessageParams));
        } else {
            builder.setMessage(mMessageId);
        }
    }

    if (mPositiveLabelId != 0) {
        builder.setPositiveButton(mPositiveLabelId, mClickListener);
    }

    if (mNegativeLabelId != 0) {
        builder.setNegativeButton(mNegativeLabelId, mClickListener);
    }

    if (mNeutralLabelId != 0) {
        builder.setNeutralButton(mNeutralLabelId, mClickListener);
    }

    builder.setCancelable(isCancellable);
    setCancelable(isCancellable);
    return builder.create();
}
 
Example 19
Source File: AddUserInfoDialogFragment.java    From barterli_android with Apache License 2.0 4 votes vote down vote up
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {

    if (savedInstanceState != null) {
        mTitleId = savedInstanceState.getInt(DialogKeys.TITLE_ID);
        mNegativeLabelId = savedInstanceState
                        .getInt(DialogKeys.NEGATIVE_LABEL_ID);
        mNeutralLabelId = savedInstanceState
                        .getInt(DialogKeys.NEUTRAL_LABEL_ID);
        mPositiveLabelId = savedInstanceState
                        .getInt(DialogKeys.POSITIVE_LABEL_ID);
        isCancellable = savedInstanceState
                        .getBoolean(DialogKeys.CANCELLABLE);
        mIconId = savedInstanceState.getInt(DialogKeys.ICON_ID);
        mTheme = savedInstanceState.getInt(DialogKeys.THEME);
    }

    final Builder builder = new Builder(getActivity(), mTheme);

    final View contentView = LayoutInflater.from(getActivity())
                    .inflate(R.layout.layout_dialog_names, null);
    mFirstNameEditText = (EditText) contentView
                    .findViewById(R.id.edittext_first_name);
    mLastNameEditText = (EditText) contentView
                    .findViewById(R.id.edittext_last_name);

    builder.setView(contentView);

    if (mIconId != 0) {
        builder.setIcon(mIconId);
    }
    if (mTitleId != 0) {
        builder.setTitle(mTitleId);
    }

    if (mPositiveLabelId != 0) {
        builder.setPositiveButton(mPositiveLabelId, mClickListener);
    }

    if (mNegativeLabelId != 0) {
        builder.setNegativeButton(mNegativeLabelId, mClickListener);
    }

    if (mNeutralLabelId != 0) {
        builder.setNeutralButton(mNeutralLabelId, mClickListener);
    }

    builder.setCancelable(isCancellable);
    setCancelable(isCancellable);
    return builder.create();
}