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

The following examples show how to use android.app.AlertDialog.Builder#setView() . 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: MMAlert.java    From wechatsdk-xamarin with Apache License 2.0 6 votes vote down vote up
public static AlertDialog showAlert(final Context context, final String title, final View view, final String ok, final String cancel, final DialogInterface.OnClickListener lOk,
		final DialogInterface.OnClickListener lCancel) {
	if (context instanceof Activity && ((Activity) context).isFinishing()) {
		return null;
	}

	final Builder builder = new AlertDialog.Builder(context);
	builder.setTitle(title);
	builder.setView(view);
	builder.setPositiveButton(ok, lOk);
	builder.setNegativeButton(cancel, lCancel);
	// builder.setCancelable(false);
	final AlertDialog alert = builder.create();
	alert.show();
	return alert;
}
 
Example 2
Source File: MMAlert.java    From wechatsdk-xamarin with Apache License 2.0 6 votes vote down vote up
public static AlertDialog showAlert(final Context context, final String title, final String msg, final View view, final DialogInterface.OnClickListener lOk,
		final DialogInterface.OnClickListener lCancel) {
	if (context instanceof Activity && ((Activity) context).isFinishing()) {
		return null;
	}

	final Builder builder = new AlertDialog.Builder(context);
	builder.setTitle(title);
	builder.setMessage(msg);
	builder.setView(view);
	builder.setPositiveButton(R.string.app_ok, lOk);
	builder.setNegativeButton(R.string.app_cancel, lCancel);
	// builder.setCancelable(true);
	builder.setOnCancelListener(new DialogInterface.OnCancelListener() {

		@Override
		public void onCancel(DialogInterface dialog) {
			if (lCancel != null) {
				lCancel.onClick(dialog, 0);
			}
		}
	});
	final AlertDialog alert = builder.create();
	alert.show();
	return alert;
}
 
Example 3
Source File: VNTNumberPickerPreference.java    From VNTNumberPickerPreference with Apache License 2.0 6 votes vote down vote up
@Override
protected void onPrepareDialogBuilder(final Builder builder) {
    super.onPrepareDialogBuilder(builder);

    numberPicker = new NumberPicker(this.getContext());
    numberPicker.setMinValue(minValue);
    numberPicker.setMaxValue(maxValue);
    numberPicker.setValue(selectedValue);
    numberPicker.setWrapSelectorWheel(wrapSelectorWheel);
    numberPicker.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    final LinearLayout linearLayout = new LinearLayout(this.getContext());
    linearLayout.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    linearLayout.setGravity(Gravity.CENTER);
    linearLayout.addView(numberPicker);

    builder.setView(linearLayout);
}
 
Example 4
Source File: CustomedDialog.java    From evercam-android with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Return a pop up dialog that ask the user whether or not to save the snapshot
 */
public static AlertDialog getConfirmSnapshotDialog(Activity activity, Bitmap bitmap,
                                                   DialogInterface.OnClickListener listener) {
    Builder snapshotDialogBuilder = new AlertDialog.Builder(activity);
    LayoutInflater mInflater = LayoutInflater.from(activity);
    final View snapshotView = mInflater.inflate(R.layout.dialog_confirm_snapshot, null);
    ImageView snapshotImageView = (ImageView) snapshotView.findViewById(R.id
            .confirm_snapshot_image);
    snapshotImageView.setImageBitmap(bitmap);
    snapshotDialogBuilder.setView(snapshotView);
    snapshotDialogBuilder.setPositiveButton(activity.getString(R.string.save), listener);
    snapshotDialogBuilder.setNegativeButton(activity.getString(R.string.cancel),
            new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
    AlertDialog snapshotDialog = snapshotDialogBuilder.create();
    snapshotDialog.setCanceledOnTouchOutside(false);

    return snapshotDialog;
}
 
Example 5
Source File: CustomedDialog.java    From evercam-android with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * The prompt dialog that ask for a preset name
 */
public static AlertDialog getCreatePresetDialog(final VideoActivity videoActivity, final String cameraId) {
    Builder dialogBuilder = new AlertDialog.Builder(videoActivity);
    LayoutInflater inflater = LayoutInflater.from(videoActivity);
    final View view = inflater.inflate(R.layout.dialog_create_preset, null);
    final EditText editText = (EditText) view.findViewById(R.id.create_preset_edit_text);
    dialogBuilder.setView(view);
    dialogBuilder.setPositiveButton(R.string.add, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            String presetName = editText.getText().toString();
            if (!presetName.isEmpty()) {
                new CreatePresetTask(videoActivity, cameraId, presetName)
                        .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            }
        }
    });
    dialogBuilder.setNegativeButton(R.string.cancel, null);
    return dialogBuilder.create();
}
 
Example 6
Source File: MMAlert.java    From wechatsdk-xamarin with Apache License 2.0 5 votes vote down vote up
public static AlertDialog showAlert(final Context context, final String title, final View view, final DialogInterface.OnClickListener lOk) {
	if (context instanceof Activity && ((Activity) context).isFinishing()) {
		return null;
	}

	final Builder builder = new AlertDialog.Builder(context);
	builder.setTitle(title);
	builder.setView(view);
	builder.setPositiveButton(R.string.app_ok, lOk);
	// builder.setCancelable(true);
	final AlertDialog alert = builder.create();
	alert.show();
	return alert;
}
 
Example 7
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 8
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 9
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 10
Source File: ColorDialogPreference.java    From Augendiagnose with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected final void onPrepareDialogBuilder(@NonNull final Builder builder) {
	super.onPrepareDialogBuilder(builder);
	int storedColor = getSharedPreferences().getInt(getContext().getString(R.string.key_overlay_color), Color.RED);

	ColorPickerPalette palette = new ColorPickerPalette(getContext());
	palette.init(ColorPickerConstants.COLOR_PICKER_SIZE, ColorPickerConstants.COLOR_PICKER_COLUMNS, this);
	palette.drawPalette(ColorPickerConstants.COLOR_PICKER_COLORS, storedColor);
	palette.setGravity(Gravity.CENTER);

	builder.setView(palette);
	builder.setPositiveButton(null, null);
}
 
Example 11
Source File: MMAlert.java    From wechatsdk-xamarin with Apache License 2.0 5 votes vote down vote up
public static AlertDialog showAlert(final Context context, final String title, final View view, final DialogInterface.OnCancelListener lCancel) {
	if (context instanceof Activity && ((Activity) context).isFinishing()) {
		return null;
	}

	final Builder builder = new AlertDialog.Builder(context);
	builder.setTitle(title);
	builder.setView(view);
	// builder.setCancelable(true);
	builder.setOnCancelListener(lCancel);
	final AlertDialog alert = builder.create();
	alert.show();
	return alert;
}
 
Example 12
Source File: MMAlert.java    From wechatsdk-xamarin with Apache License 2.0 5 votes vote down vote up
public static AlertDialog showAlert(final Context context, final String title, final String ok, final View view, final DialogInterface.OnClickListener lOk) {
	if (context instanceof Activity && ((Activity) context).isFinishing()) {
		return null;
	}

	final Builder builder = new AlertDialog.Builder(context);
	builder.setTitle(title);
	builder.setView(view);
	builder.setPositiveButton(ok, lOk);
	// builder.setCancelable(true);
	final AlertDialog alert = builder.create();
	alert.show();
	return alert;
}
 
Example 13
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 14
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();
}
 
Example 15
Source File: MultiSelectDragListPreference.javaMultiSelectDragListPreference.java    From Klyph with MIT License 4 votes vote down vote up
@Override
protected void onPrepareDialogBuilder(Builder builder)
{
	super.onPrepareDialogBuilder(builder);

	if (mEntries == null || mEntryValues == null)
	{
		throw new IllegalStateException("MultiSelectListPreference requires an entries array and "
										+ "an entryValues array.");
	}

	String[] entries = new String[mEntries.length];
	for (int i = 0; i < mEntries.length; i++)
	{
		entries[i] = mEntries[i].toString();
	}

	boolean [] selectedItems = getSelectedItems();

	ArrayList<String> orderedList = new ArrayList<String>();
	int n = selectedItems.length;
	
	for (String value : mValues)
	{
		int index = ArrayUtils.indexOf(mEntryValues, value);
		orderedList.add(mEntries[index].toString());
	}

	for (int i = 0; i < mEntries.length; i++)
	{
		if (!mValues.contains(mEntryValues[i]))
			orderedList.add(mEntries[i].toString());
	}

	adapter = new ArrayAdapter<String>(getContext(), R.layout.item_list_preference_multi_drag, R.id.text,
			orderedList);
	listView = new DragSortListView(getContext(), null);
	listView.setAdapter(adapter);

	listView.setDropListener(onDrop);
	listView.setDragEnabled(true);
	listView.setFloatAlpha(0.8f);

	DragSortController controller = new DragSortController(listView);
	controller.setDragHandleId(R.id.drag_handle);
	controller.setRemoveEnabled(false);
	controller.setSortEnabled(true);
	controller.setBackgroundColor(0xFFFFFF);
	controller.setDragInitMode(DragSortController.ON_DOWN);

	listView.setFloatViewManager(controller);
	listView.setOnTouchListener(controller);

	
	builder.setView(listView);
	listView.setOnItemClickListener(new OnItemClickListener() {

		@Override
		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3)
		{
			mPreferenceChanged = true;
			refreshNewValues();
		}});
	
	listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
	for (int i = 0; i < n; i++)
	{
		listView.setItemChecked(i, i < mValues.size());
	}

	/*
	 * boolean [] checkedItems = getSelectedItems();
	 * builder.setMultiChoiceItems(mEntries, checkedItems,
	 * new DialogInterface.OnMultiChoiceClickListener() {
	 * public void onClick(DialogInterface dialog, int which, boolean 
	 * isChecked) {
	 * if (isChecked) {
	 * mPreferenceChanged |= mNewValues.add(mEntryValues[which].toString());
	 * } else {
	 * mPreferenceChanged |=
	 * mNewValues.remove(mEntryValues[which].toString());
	 * }
	 * }
	 * });
	 */
	mNewValues.clear();
	mNewValues.addAll(mValues);
}
 
Example 16
Source File: ConfirmAPIActivity.java    From android with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();
    try {
        mPackage = getCallingPackage();
        if (mPackage == null) {
            finish();
            return;
        }


        PackageManager pm = getPackageManager();
        ApplicationInfo app = pm.getApplicationInfo(mPackage, 0);

        View view = View.inflate(this, R.layout.api_confirm, null);
        ((ImageView) view.findViewById(R.id.icon)).setImageDrawable(app.loadIcon(pm));
        ((TextView) view.findViewById(R.id.prompt)).setText(
                getString(R.string.prompt, app.loadLabel(pm), getString(R.string.app)));
        ((CompoundButton) view.findViewById(R.id.check)).setOnCheckedChangeListener(this);


        Builder builder = new AlertDialog.Builder(this);

        builder.setView(view);

        builder.setIconAttribute(android.R.attr.alertDialogIcon);
        builder.setTitle(android.R.string.dialog_alert_title);
        builder.setPositiveButton(android.R.string.ok, this);
        builder.setNegativeButton(android.R.string.cancel, this);

        mAlert = builder.create();
        mAlert.setCanceledOnTouchOutside(false);

        mAlert.setOnShowListener(new OnShowListener() {

            @Override
            public void onShow(DialogInterface dialog) {
                mButton = mAlert.getButton(DialogInterface.BUTTON_POSITIVE);
                mButton.setEnabled(false);

            }
        });

        //setCloseOnTouchOutside(false);

        mAlert.show();

    } catch (Exception e) {
        Log.e(TAG, "onResume", e);
        finish();
    }
}
 
Example 17
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);
            }
        }
    }
}