android.app.AlertDialog.Builder Java Examples

The following examples show how to use android.app.AlertDialog.Builder. 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: MMAlert.java    From wechatsdk-xamarin with Apache License 2.0 6 votes vote down vote up
public static AlertDialog showAlert(final Context context, final int msgId, final int titleId, 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.setIcon(R.drawable.ic_dialog_alert);
	builder.setTitle(titleId);
	builder.setMessage(msgId);
	builder.setPositiveButton(R.string.app_ok, lOk);
	builder.setNegativeButton(R.string.app_cancel, lCancel);
	// builder.setCancelable(false);
	final AlertDialog alert = builder.create();
	alert.show();
	return alert;
}
 
Example #3
Source File: VNTFontListPreference.java    From VNTFontListPreference with Apache License 2.0 6 votes vote down vote up
@Override
protected void onPrepareDialogBuilder(final Builder builder) {
    final CustomListPreferenceAdapter customListPreferenceAdapter = new CustomListPreferenceAdapter(fonts, fontPreviewString, selectedFontFace);

    builder.setAdapter(customListPreferenceAdapter, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(final DialogInterface dialog, final int which) {
            if (shouldPersist()) {
                final Font selectedFont = fonts.get(which);

                if (callChangeListener(selectedFont.fontPath)) {
                    selectedFontFace = selectedFont;
                    updateSummary();
                    persistString(selectedFontFace.fontPath);
                }
            }
            dialog.cancel();
        }
    });

    builder.setPositiveButton(null, null);
}
 
Example #4
Source File: CustomedDialog.java    From evercam-android with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * The dialog that prompt to connect Internet, with listener.
 */
public static AlertDialog getNoInternetDialog(final Activity activity,
                                              DialogInterface.OnClickListener negativeistener) {
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity)
            .setTitle(R.string.msg_network_not_connected)
            .setMessage(R.string.msg_try_network_again)
            .setCancelable(false).setPositiveButton(R.string.settings_capital, new
                    DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                            activity.startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
                        }
                    }).setNegativeButton(R.string.notNow, negativeistener);
    return dialogBuilder.create();
}
 
Example #5
Source File: MultiSelectListPreference.java    From YalpStore with GNU General Public License v2.0 6 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.");
    }

    if (mNewValues == null) {
        mNewValues = new HashSet<>();
        mNewValues.addAll(mValues);
        mPreferenceChanged = false;
    }

    final boolean[] checkedItems = getSelectedItems(mNewValues);
    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());
                }
            }
        });
}
 
Example #6
Source File: UpdaterDialogManager.java    From TurkcellUpdater_android_sdk with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a dialog for given message.
 *
 * @param activity        Parent activity.
 * @param message         Message contents
 * @param dismissListener Listener that will be called when dialog is closed or
 *                        cancelled.
 * @return Created dialog.
 */
public static Dialog createMessageDialog(Activity activity, Message message, OnDismissListener dismissListener) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    final String title = message.description == null ? null : message.description.get(MessageDescription.KEY_TITLE);
    if (!Utilities.isNullOrEmpty(title)) {
        builder.setTitle(title);
    }
    final View dialogContentsView = createMessageDialogContentsView(activity, message.description);
    builder.setView(dialogContentsView);
    initializeMessageDialogButtons(activity, builder, message);
    builder.setCancelable(true);
    final AlertDialog dialog = builder.create();
    if (Utilities.isNullOrEmpty(title)) {
        dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    }
    dialog.setOnDismissListener(dismissListener);
    return dialog;
}
 
Example #7
Source File: AccessibilityActivity.java    From AndroidAutoClick with MIT License 6 votes vote down vote up
/** 显示未开启辅助服务的对话框*/
private void showOpenAccessibilityServiceDialog() {
    if(mTipsDialog != null && mTipsDialog.isShowing()) {
        return;
    }
    View view = getLayoutInflater().inflate(R.layout.dialog_tips_layout, null);
    view.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            openAccessibilityServiceSettings();
        }
    });
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("需要开启辅助服务正常使用");
    builder.setView(view);
    builder.setPositiveButton("打开辅助服务", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            openAccessibilityServiceSettings();
        }
    });
    mTipsDialog = builder.show();
}
 
Example #8
Source File: NetWorkUtil.java    From Viewer with Apache License 2.0 6 votes vote down vote up
public static void openDialog(final Activity context)
{
	final Builder builder = new AlertDialog.Builder(context);
	builder.setTitle("网络不可用");
	builder.setMessage("请连接网络");
	builder.setPositiveButton("确定", new DialogInterface.OnClickListener()
	{
		@Override
		public void onClick(DialogInterface dialog, int which)
		{
			builder.create().dismiss();
			context.finish();
		}
	});
	builder.show();
}
 
Example #9
Source File: ARCanvasSurfaceView.java    From geoar-app with Apache License 2.0 6 votes vote down vote up
private void onItemClicked(ARObject item) {
	PluginActivityContext pluginActivityContext = new PluginActivityContext(
			item.getDataSourceInstance().getParent().getPluginHolder()
					.getPluginContext(), getContext());
	View featureView = item.getVisualization().getFeatureView(
			item.getEntity(), null, null, pluginActivityContext);
	if (featureView != null) {
		String title = item.getVisualization().getTitle(item.getEntity());
		if (title == null || title.isEmpty()) {
			title = "";
		}
		String message = item.getVisualization().getDescription(
				item.getEntity());
		if (message == null || message.isEmpty()) {
			message = "";
		}
		Builder builder = new AlertDialog.Builder(getContext());
		builder.setTitle(title).setMessage(message)
				.setNeutralButton(R.string.cancel, null)
				.setView(featureView);
		builder.create().show();
	}
}
 
Example #10
Source File: AccountActivity.java    From iBeebo with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == ADD_ACCOUNT_REQUEST_CODE && resultCode == RESULT_OK) {
        refresh();
        if (data == null) {
            return;
        }
        String expires_time = data.getExtras().getString("expires_in");
        long expiresDays = TimeUnit.SECONDS.toDays(Long.valueOf(expires_time));

        String content = String.format(getString(R.string.token_expires_in_time), String.valueOf(expiresDays));
        DevLog.printLog("AccountActivity: ", content);
        if (false) {
            Builder builder = new Builder(this).setMessage(content).setPositiveButton(R.string.ok,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {

                        }
                    });

            builder.show();
        }

    }
}
 
Example #11
Source File: CustomedDialog.java    From evercam-android with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * The single message dialog that contains title, a message, two buttons(Yes
 * & No) and two listeners.
 * <p/>
 * If int negativeButton == 0, it will be a dialog without negative button
 */
private static AlertDialog getStandardStyledDialog(final Activity activity, int title,
                                                   int message,
                                                   DialogInterface.OnClickListener
                                                           positiveListener,
                                                   DialogInterface.OnClickListener
                                                           negativeListener,
                                                   int positiveButton, int negativeButton) {
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity)
            .setTitle(title)
            .setMessage(message)
            .setCancelable(false).setPositiveButton(positiveButton, positiveListener);
    if (negativeButton != 0) {
        dialogBuilder.setNegativeButton(negativeButton, negativeListener);
    }
    return dialogBuilder.create();
}
 
Example #12
Source File: MsgBox.java    From cordova-plugin-app-update with MIT License 6 votes vote down vote up
/**
 * 错误提示窗口
 *
 * @param errorDialogOnClick
 */
public Dialog showErrorDialog(OnClickListener errorDialogOnClick) {
    if (this.errorDialog == null) {
        LOG.d(TAG, "initErrorDialog");
        // 构造对话框
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        builder.setTitle(msgHelper.getString(MsgHelper.UPDATE_ERROR_TITLE));
        builder.setMessage(msgHelper.getString(MsgHelper.UPDATE_ERROR_MESSAGE));
        // 更新
        builder.setPositiveButton(msgHelper.getString(MsgHelper.UPDATE_ERROR_YES_BTN), errorDialogOnClick);
        errorDialog = builder.create();
    }

    if (!errorDialog.isShowing()) errorDialog.show();

    return errorDialog;
}
 
Example #13
Source File: MsgBox.java    From cordova-plugin-app-update-demo with MIT License 6 votes vote down vote up
/**
 * 显示软件更新对话框
 *
 * @param onClickListener
 */
public Dialog showNoticeDialog(OnClickListener onClickListener) {
    if (noticeDialog == null) {
        LOG.d(TAG, "showNoticeDialog");
        // 构造对话框
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        builder.setTitle(msgHelper.getString(MsgHelper.UPDATE_TITLE));
        builder.setMessage(msgHelper.getString(MsgHelper.UPDATE_MESSAGE));
        // 更新
        builder.setPositiveButton(msgHelper.getString(MsgHelper.UPDATE_UPDATE_BTN), onClickListener);
        noticeDialog = builder.create();
    }

    if (!noticeDialog.isShowing()) noticeDialog.show();

    noticeDialog.setCanceledOnTouchOutside(false);// 设置点击屏幕Dialog不消失
    return noticeDialog;
}
 
Example #14
Source File: AccountActivity.java    From iBeebo with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == ADD_ACCOUNT_REQUEST_CODE && resultCode == RESULT_OK) {
        refresh();
        if (data == null) {
            return;
        }
        String expires_time = data.getExtras().getString("expires_in");
        long expiresDays = TimeUnit.SECONDS.toDays(Long.valueOf(expires_time));

        String content = String.format(getString(R.string.token_expires_in_time), String.valueOf(expiresDays));
        DevLog.printLog("AccountActivity: ", content);
        if (false) {
            Builder builder = new Builder(this).setMessage(content).setPositiveButton(R.string.ok,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {

                        }
                    });

            builder.show();
        }

    }
}
 
Example #15
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 msg, final String title) {
	if (context instanceof Activity && ((Activity) context).isFinishing()) {
		return null;
	}

	final Builder builder = new AlertDialog.Builder(context);
	builder.setIcon(R.drawable.ic_dialog_alert);
	builder.setTitle(title);
	builder.setMessage(msg);
	builder.setPositiveButton(R.string.app_ok, new DialogInterface.OnClickListener() {

		@Override
		public void onClick(final DialogInterface dialog, final int which) {
			dialog.cancel();
		}
	});
	final AlertDialog alert = builder.create();
	alert.show();
	return alert;
}
 
Example #16
Source File: MultiSelectListPreference.java    From android_9.0.0_r45 with Apache License 2.0 6 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.");
    }
    
    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 #17
Source File: MultipleChoicePreference.java    From matlog with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onPrepareDialogBuilder(Builder builder) {

    // convert comma-separated list to boolean array

    String value = getValue();
    Set<String> commaSeparated = new HashSet<>(Arrays.asList(StringUtil.split(value, DELIMITER)));

    CharSequence[] entryValues = getEntryValues();
    final boolean[] checked = new boolean[entryValues.length];
    for (int i = 0; i < entryValues.length; i++) {
        checked[i] = commaSeparated.contains(entryValues[i]);
    }

    builder.setMultiChoiceItems(getEntries(), checked, (dialog, which, isChecked) -> checked[which] = isChecked);
    builder.setPositiveButton(android.R.string.ok, (dialog, which) -> {

        checkedDialogEntryIndexes = checked;

        /*
         * Clicking on an item simulates the positive button
         * click, and dismisses the dialog.
         */
        MultipleChoicePreference.this.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
        dialog.dismiss();

    });
}
 
Example #18
Source File: CustomedDialog.java    From evercam-android with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Dialog without title, but with a message and an 'OK' button
 *
 * @param message Message to show in the dialog
 */
public static void showMessageDialog(Activity activity, int message) {
    new MaterialDialog.Builder(activity)
            .content(message)
            .negativeText(R.string.ok)
            .show();
}
 
Example #19
Source File: SanaUtil.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Creates a message dialog.
 *
 * @param context the current Context
 * @param title   the dialog title
 * @param message the dialog message
 * @return a new dialogf for alerting the user.
 */
public static AlertDialog createDialog(Context context, String title,
                                       String message) {
    Builder dialogBuilder = new Builder(context);
    dialogBuilder.setPositiveButton(context.getResources().getString(
            R.string.general_ok), null);
    dialogBuilder.setTitle(title);
    dialogBuilder.setMessage(message);
    return dialogBuilder.create();
}
 
Example #20
Source File: ThemeListPreference.java    From droidddle with Apache License 2.0 5 votes vote down vote up
@Override
protected void onPrepareDialogBuilder(Builder builder) {

    entries = getEntries();
    entryValues = getEntryValues();

    if (entries == null || entryValues == null || entries.length != entryValues.length) {
        throw new IllegalStateException("ListPreference requires an entries array and an entryValues array which are both the same length");
    }

    mEntryIndex = findIndexOfValues(getValue(), entryValues);

    OnClickListener listener = new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            mEntryIndex = which;
            // setSummary(getColorSummary(mEntryIndex));
            editor.putString(getKey(), entryValues[which].toString()).commit();
            /*
             * Clicking on an item simulates the positive button click, and
             * dismisses the dialog.
             */
            if (mThemeListener != null) {
                mThemeListener.onPreferenceChange(ThemeListPreference.this, which);
            }
            ThemeListPreference.this.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
            dialog.dismiss();
        }
    };
    ThemeListPreferenceAdapter adapter = new ThemeListPreferenceAdapter(mContext);
    builder.setSingleChoiceItems(adapter, mEntryIndex, listener);

    /*
     * The typical interaction for list-based dialogs is to have
     * click-on-an-item dismiss the dialog instead of the user having to
     * press 'Ok'.
     */
    builder.setPositiveButton(null, null);
}
 
Example #21
Source File: FriendActivity.java    From Conquer with Apache License 2.0 5 votes vote down vote up
public void showDeleteDialog(final User user) {
	Builder builder = new Builder(context);
	builder.setTitle("是否删除好友").setPositiveButton("确定", new DialogInterface.OnClickListener() {
		@Override
		public void onClick(DialogInterface dialog, int which) {
			deleteContact(user);
		}
	}).setNegativeButton("取消", null).show();

}
 
Example #22
Source File: RootDialog.java    From Android-PreferencesManager with Apache License 2.0 5 votes vote down vote up
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    if (getActivity() == null) {
        return null;
    }
    return new Builder(getActivity()).setIcon(R.drawable.ic_action_emo_evil).setTitle(R.string.no_root_title)
            .setMessage(R.string.no_root_message).setPositiveButton(R.string.no_root_button, new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dismiss();
                }
            }).create();
}
 
Example #23
Source File: DialogUtil.java    From letv with Apache License 2.0 5 votes vote down vote up
public static void call(Activity activity, int messageId, int yes, int no, OnClickListener yesListener, OnClickListener noListener) {
    if (activity != null) {
        Dialog dialog = new Builder(activity).setTitle(R.string.dialog_default_title).setIcon(R.drawable.dialog_icon).setMessage(messageId).setPositiveButton(yes, yesListener).setNegativeButton(no, noListener).create();
        if (!activity.isFinishing() && !activity.isRestricted()) {
            dialog.show();
        }
    }
}
 
Example #24
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 #25
Source File: Notification.java    From showCaseCordova with Apache License 2.0 5 votes vote down vote up
@SuppressLint("NewApi")
private AlertDialog.Builder createDialog(CordovaInterface cordova) {
    int currentapiVersion = android.os.Build.VERSION.SDK_INT;
    if (currentapiVersion >= android.os.Build.VERSION_CODES.HONEYCOMB) {
        return new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);
    } else {
        return new AlertDialog.Builder(cordova.getActivity());
    }
}
 
Example #26
Source File: Notification.java    From reader with MIT License 5 votes vote down vote up
@SuppressLint("NewApi")
private AlertDialog.Builder createDialog(CordovaInterface cordova) {
    int currentapiVersion = android.os.Build.VERSION.SDK_INT;
    if (currentapiVersion >= android.os.Build.VERSION_CODES.HONEYCOMB) {
        return new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);
    } else {
        return new AlertDialog.Builder(cordova.getActivity());
    }
}
 
Example #27
Source File: DialogUtil.java    From letv with Apache License 2.0 5 votes vote down vote up
public static void call(Activity activity, String messageId, int yesId, int noId, OnClickListener yes, OnClickListener no) {
    if (activity != null) {
        Dialog dialog = new Builder(activity).setIcon(R.drawable.dialog_icon).setMessage(messageId).setPositiveButton(yesId, yes).setNegativeButton(noId, no).create();
        if (!activity.isFinishing() && !activity.isRestricted()) {
            dialog.show();
        }
    }
}
 
Example #28
Source File: CustomedDialog.java    From evercam-android with GNU Affero General Public License v3.0 5 votes vote down vote up
public static AlertDialog showCannotChangeRightsDialog(Activity activity,
                                                          final CameraShareInterface shareInterface) throws JSONException {
//        int positiveButtonTextId = R.string.ok;
        int messageTextId = R.string.msg_cannot_change_rights;

        if (((CameraShare) shareInterface).getUserId().equals(AppData.defaultUser.getUsername())) {
            messageTextId = R.string.msg_cannot_change_rights;
        }
        return new AlertDialog.Builder(activity).setMessage(messageTextId).setCancelable(true).create();
    }
 
Example #29
Source File: Notification.java    From showCaseCordova with Apache License 2.0 5 votes vote down vote up
@SuppressLint("NewApi")
private void changeTextDirection(Builder dlg){
    int currentapiVersion = android.os.Build.VERSION.SDK_INT;
    dlg.create();
    AlertDialog dialog =  dlg.show();
    if (currentapiVersion >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
        TextView messageview = (TextView)dialog.findViewById(android.R.id.message);
        messageview.setTextDirection(android.view.View.TEXT_DIRECTION_LOCALE);
    }
}
 
Example #30
Source File: DialogUtil.java    From letv with Apache License 2.0 5 votes vote down vote up
public static void call(Activity activity, String message, OnClickListener yes, boolean cancelable) {
    if (activity != null) {
        Dialog dialog = new Builder(activity).setTitle(R.string.dialog_default_title).setIcon(R.drawable.dialog_icon).setMessage(message).setPositiveButton(R.string.dialog_default_ok, yes).create();
        dialog.setCancelable(cancelable);
        if (!activity.isFinishing() && !activity.isRestricted()) {
            dialog.show();
        }
    }
}