android.app.AlertDialog#setCanceledOnTouchOutside ( )源码实例Demo

下面列出了android.app.AlertDialog#setCanceledOnTouchOutside ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: android2048   文件: DialogUtils.java
public static void getOpenDialog(Context context, Gamer gamer) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(R.string.dialog_open_title);
    LayoutInflater inflate = LayoutInflater.from(context);
    View v = inflate.inflate(R.layout.dialog_open, null);
    //设置布局
    TextView tv_name = (TextView) v.findViewById(R.id.tv_name);
    TextView tv_score = (TextView) v.findViewById(R.id.tv_score);

    tv_name.setText("姓名:" + gamer.getName());
    tv_score.setText("分数:" + gamer.getScore());

    builder.setView(v);
    builder.setPositiveButton("确定", null);
    //dialog属性操作
    AlertDialog dialog = builder.create();
    dialog.setCanceledOnTouchOutside(false);
    dialog.show();
}
 
源代码2 项目: RelaxFinger   文件: SettingActivity.java
public void questionsAnswer() {

        AlertDialog dialog = new AlertDialog.Builder(this).create();
        dialog.setTitle("帮助说明");
        dialog.setCancelable(true);
        dialog.setCanceledOnTouchOutside(true);
        dialog.setMessage("1.不能卸载软件:在设置界面关闭“开启锁屏”选项后,即可正常卸载。\r\n" +
                "2.屏幕截图没反应:部分手机在第一次屏幕截图时需要稍等片刻,弹出授权框后,点击允许即可。\r\n" +
                "3.截图保存在哪里:截图保存在系统存储卡根目录RelaxFinger文件夹里面。\r\n" +
                "4.避让软键盘无效:安卓7.0以下系统避让软键盘功能最好安装两个及以上输入法(包含系统自带输入法)。\r\n" +
                "5.不能开机自启动:首先确保设置界面“开机启动”选项已开启,如果仍然不能启动,到系统设置->" +
                "安全->应用程序许可中找到RelaxFinger,点击进去后打开自动运行开关即可。\r\n" +
                "6.自定义主题不好看:在系统存储卡根目录找到RelaxFinger目录,将里面的DIY.png换成喜欢的图片" +
                ",确保新图片名称依然是DIY.png即可。\r\n" +
                "7.若频繁需要重新激活,系统设置->安全->应用程序许可->RelaxFinger->启用自动运行," +
                "部分国产手机->电池管理->受保护应用->启用悬浮助手,任务管理器中的一键清除也会杀掉悬浮助手," +
                "可以在任务管理界面,给悬浮助手加上锁即可,手机不同加锁方法自行百度," +
                "华为是任务管理器界面按住悬浮助手往下拉,MIUI好像是就有个锁,点一下就好了。\r\n" +
                "8.临时移动模式:悬浮球会向上移动一段距离,可自由移动,点击退出临时移动模式。打开关闭输入法会自动"+
                "进入和退出临时移动模式。\r\n"+
                "9.显示消息通知:当接收到消息时,悬浮球会变成相应的APP图标,并晃动提示,点击打开消息,上滑忽略"+
                "当前消息,下滑忽略所有消息。\r\n"+
                "10.安卓6.0及以上系统出现叠加层解决方法:在系统设置->开发者选项->停用HW叠加层即可。");
        dialog.show();
    }
 
源代码3 项目: QNotified   文件: RepeaterIconSettingDialog.java
public RepeaterIconSettingDialog(Context context) {
    dialog = (AlertDialog) CustomDialog.createFailsafe(context).setTitle("自定义+1图标").setPositiveButton("保存", this)
            .setNegativeButton("取消", null).setCancelable(true).create();
    ctx = dialog.getContext();
    dialog.setCanceledOnTouchOutside(false);
    @SuppressLint("InflateParams") View v = LayoutInflater.from(ctx).inflate(R.layout.select_repeater_icon_dialog, null);
    loadBtn = v.findViewById(R.id.selectRepeaterIcon_buttonLoadFile);
    loadBtn.setOnClickListener(this);
    browseBtn = v.findViewById(R.id.selectRepeaterIcon_buttonBrowseImg);
    browseBtn.setOnClickListener(this);
    restoreDefBtn = v.findViewById(R.id.selectRepeaterIcon_buttonRestoreDefaultIcon);
    restoreDefBtn.setOnClickListener(this);
    prevImgView = v.findViewById(R.id.selectRepeaterIcon_imageViewPreview);
    prevImgView.setPadding(1, 1, 1, 1);
    prevImgView.setBackgroundDrawable(new DebugDrawable(ctx));
    specDpi = v.findViewById(R.id.selectRepeaterIcon_checkBoxSpecifyDpi);
    specDpi.setOnCheckedChangeListener(this);
    dpiGroup = v.findViewById(R.id.selectRepeaterIcon_RadioGroupDpiList);
    dpiGroup.setOnCheckedChangeListener(this);
    pathInput = v.findViewById(R.id.selectRepeaterIcon_editTextIconLocation);
    linearLayoutDpi = v.findViewById(R.id.selectRepeaterIcon_linearLayoutDpi);
    textViewWarning = v.findViewById(R.id.selectRepeaterIcon_textViewWarnMsg);
    physicalDpi = ctx.getResources().getDisplayMetrics().densityDpi;
    dialog.setView(v);
}
 
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    Bundle args = getArguments();

    String msg = "";
    if (args != null) {
        msg = args.getString(EXTRA_MSG);
    }

    LayoutInflater inflater = getActivity().getLayoutInflater();
    View v = inflater.inflate(R.layout.dialog_setting_progress, null);
    TextView messageView = v.findViewById(R.id.message);
    messageView.setText(msg);

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setView(v);
    builder.setCancelable(false);

    AlertDialog dialog = builder.create();
    dialog.setCanceledOnTouchOutside(false);
    return dialog;
}
 
源代码5 项目: TowerCollector   文件: DialogManager.java
private static AlertDialog createHtmlInfoDialog(Context context, int titleId, Integer messageId, String message, boolean largeText, boolean textIsSelectable) {
    if (messageId == null && message == null)
        throw new IllegalArgumentException("MessageId or message values is required");
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    LayoutInflater inflater = LayoutInflater.from(context);
    View dialogLayout = inflater.inflate(R.layout.html_information_dialog, null);
    builder.setView(dialogLayout);
    builder.setPositiveButton(R.string.dialog_ok, null);

    builder.setTitle(titleId);
    HtmlTextView messageView = (HtmlTextView) dialogLayout.findViewById(R.id.html_info_dialog_textview);
    messageView.setTextAppearance(context, (largeText ? android.R.style.TextAppearance_Medium : android.R.style.TextAppearance_Small));
    if (messageId != null) {
        messageView.setHtml(messageId, new HtmlResImageGetter(context));
    } else {
        messageView.setHtml(message, new HtmlResImageGetter(context));
    }
    // don't move above settings content because it won't work
    messageView.setTextIsSelectable(textIsSelectable);

    AlertDialog dialog = builder.create();
    dialog.setCanceledOnTouchOutside(true);
    return dialog;
}
 
源代码6 项目: EFRConnect-android   文件: Dialogs.java
public static Dialog showAlert(CharSequence title, CharSequence message, Context context,
                               CharSequence positiveBtnText, CharSequence negativeBtnText, OnClickListener positiveListener,
                               OnClickListener negativeListener) {

    final AlertDialog alert = new AlertDialog.Builder(context).create();
    alert.setCancelable(false);
    alert.setCanceledOnTouchOutside(false);
    if (positiveListener != null && positiveBtnText != null) {
        alert.setButton(AlertDialog.BUTTON_POSITIVE, positiveBtnText, positiveListener);
    }
    if (negativeListener != null && negativeBtnText != null) {
        alert.setButton(AlertDialog.BUTTON_NEGATIVE, negativeBtnText, negativeListener);
    }
    alert.setTitle(title);
    alert.setMessage(message);
    alert.show();
    return alert;
}
 
源代码7 项目: evercam-android   文件: CustomedDialog.java
/**
 * 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;
}
 
源代码8 项目: libcommon   文件: ConfirmDialogV4.java
@NonNull
@Override
   public Dialog onCreateDialog(final Bundle savedInstanceState) {
	final Bundle args = savedInstanceState != null ? savedInstanceState : requireArguments();
	final int id_title = args.getInt(ARGS_KEY_ID_TITLE);
	final int id_message = args.getInt(ARGS_KEY_ID_MESSAGE);
	final CharSequence message = args.getCharSequence(ARGS_KEY_MESSAGE_STRING);
	final boolean canceledOnTouchOutside = args.getBoolean(ARGS_KEY_CANCELED_ON_TOUCH_OUTSIDE);

	final AlertDialog.Builder builder = new AlertDialog.Builder(requireContext(), getTheme())
		.setIcon(android.R.drawable.ic_dialog_alert)
		.setTitle(id_title)
		.setPositiveButton(android.R.string.ok, mOnClickListener)
		.setNegativeButton(android.R.string.cancel, mOnClickListener);
	if (id_message != 0) {
		builder.setMessage(id_message);
	} else {
		builder.setMessage(message);
	}
	final AlertDialog dialog = builder.create();
	dialog.setCanceledOnTouchOutside(canceledOnTouchOutside);
	return dialog;
}
 
源代码9 项目: Android-Keyboard   文件: LatinIME.java
private void showSubtypeSelectorAndSettings() {
        final CharSequence title = getString(R.string.english_ime_input_options);
        // TODO: Should use new string "Select active input modes".
        final CharSequence languageSelectionTitle = getString(R.string.language_selection_title);
        final CharSequence[] items = new CharSequence[] {
                languageSelectionTitle,
                getString(ApplicationUtils.getActivityTitleResId(this, SettingsActivity.class))
        };
        final String imeId = mRichImm.getInputMethodIdOfThisIme();
        final OnClickListener listener = new OnClickListener() {
            @Override
            public void onClick(DialogInterface di, int position) {
                di.dismiss();
                switch (position) {
                case 0:
//                    final Intent intent = IntentUtils.getInputLanguageSelectionIntent(
//                            imeId,
//                            Intent.FLAG_ACTIVITY_NEW_TASK
//                                    | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
//                                    | Intent.FLAG_ACTIVITY_CLEAR_TOP);
//                    intent.putExtra(Intent.EXTRA_TITLE, languageSelectionTitle);
//                    startActivity(intent);
                    final Intent intent = new Intent(LatinIME.this, LanguageAddedActivity.class);
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                    break;
                case 1:
                    launchSettings(SettingsActivity.EXTRA_ENTRY_VALUE_LONG_PRESS_COMMA);
                    break;
                }
            }
        };
        final AlertDialog.Builder builder = new AlertDialog.Builder(
                DialogUtils.getPlatformDialogThemeContext(this));
        builder.setItems(items, listener).setTitle(title);
        final AlertDialog dialog = builder.create();
        dialog.setCancelable(true /* cancelable */);
        dialog.setCanceledOnTouchOutside(true /* cancelable */);
        showOptionDialog(dialog);
    }
 
源代码10 项目: RecyclerViewSwipeDismiss   文件: MainActivity.java
private void showDialog(String msg){
    AlertDialog alert = new AlertDialog.Builder(MainActivity.this)
            .setTitle("alert")
            .setMessage(msg)
            .setCancelable(false)
            .create();
    alert.setCanceledOnTouchOutside(true);
    alert.show();
}
 
源代码11 项目: nono-android   文件: Util.java
public static AlertDialog showConfirmCancelDialog(Context context,
		String title, String message,
		DialogInterface.OnClickListener posListener) {
	AlertDialog dlg = new AlertDialog.Builder(context).setMessage(message)
			.setPositiveButton("确认", posListener)
			.setNegativeButton("取消", null).create();
	dlg.setCanceledOnTouchOutside(false);
	dlg.show();
	return dlg;
}
 
源代码12 项目: simple-keyboard   文件: LatinIME.java
private void showSubtypeSelectorAndSettings() {
    final CharSequence title = getString(R.string.english_ime_input_options);
    // TODO: Should use new string "Select active input modes".
    final CharSequence languageSelectionTitle = getString(R.string.language_selection_title);
    final CharSequence[] items = new CharSequence[] {
            languageSelectionTitle,
            getString(ApplicationUtils.getActivityTitleResId(this, SettingsActivity.class))
    };
    final String imeId = mRichImm.getInputMethodIdOfThisIme();
    final OnClickListener listener = new OnClickListener() {
        @Override
        public void onClick(DialogInterface di, int position) {
            di.dismiss();
            switch (position) {
            case 0:
                final Intent intent = IntentUtils.getInputLanguageSelectionIntent(
                        imeId,
                        Intent.FLAG_ACTIVITY_NEW_TASK
                                | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
                                | Intent.FLAG_ACTIVITY_CLEAR_TOP);
                intent.putExtra(Intent.EXTRA_TITLE, languageSelectionTitle);
                startActivity(intent);
                break;
            case 1:
                launchSettings();
                break;
            }
        }
    };
    final AlertDialog.Builder builder = new AlertDialog.Builder(
            DialogUtils.getPlatformDialogThemeContext(this));
    builder.setItems(items, listener).setTitle(title);
    final AlertDialog dialog = builder.create();
    dialog.setCancelable(true /* cancelable */);
    dialog.setCanceledOnTouchOutside(true /* cancelable */);
    showOptionDialog(dialog);
}
 
源代码13 项目: travelguide   文件: ArticleInfoListFragment.java
private void showLicense()
{
  final WebView wb = new WebView(getActivity());
  wb.loadUrl("file:///android_asset/license.html");

  final AlertDialog ad =
  new AlertDialog.Builder(getActivity())
     .setTitle(R.string.about)
     .setCancelable(true)
     .create();
  ad.setCanceledOnTouchOutside(true);
  ad.setView(wb);
  ad.show();
}
 
源代码14 项目: AOSP-Kayboard-7.1.2   文件: LatinIME.java
private void showSubtypeSelectorAndSettings() {
    final CharSequence title = getString(R.string.english_ime_input_options);
    // TODO: Should use new string "Select active input modes".
    final CharSequence languageSelectionTitle = getString(R.string.language_selection_title);
    final CharSequence[] items = new CharSequence[] {
            languageSelectionTitle,
            getString(ApplicationUtils.getActivityTitleResId(this, SettingsActivity.class))
    };
    final String imeId = mRichImm.getInputMethodIdOfThisIme();
    final OnClickListener listener = new OnClickListener() {
        @Override
        public void onClick(DialogInterface di, int position) {
            di.dismiss();
            switch (position) {
            case 0:
                final Intent intent = IntentUtils.getInputLanguageSelectionIntent(
                        imeId,
                        Intent.FLAG_ACTIVITY_NEW_TASK
                                | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
                                | Intent.FLAG_ACTIVITY_CLEAR_TOP);
                intent.putExtra(Intent.EXTRA_TITLE, languageSelectionTitle);
                startActivity(intent);
                break;
            case 1:
                launchSettings(SettingsActivity.EXTRA_ENTRY_VALUE_LONG_PRESS_COMMA);
                break;
            }
        }
    };
    final AlertDialog.Builder builder = new AlertDialog.Builder(
            DialogUtils.getPlatformDialogThemeContext(this));
    builder.setItems(items, listener).setTitle(title);
    final AlertDialog dialog = builder.create();
    dialog.setCancelable(true /* cancelable */);
    dialog.setCanceledOnTouchOutside(true /* cancelable */);
    showOptionDialog(dialog);
}
 
源代码15 项目: MissZzzReader   文件: DialogCreator.java
/**
 * 三按键对话框
 *
 * @param context
 * @param title
 * @param msg
 * @param btnText1
 * @param btnText2
 * @param btnText3
 * @param positiveListener
 * @param neutralListener
 * @param negativeListener
 * @return
 */
public static AlertDialog createThreeButtonDialog(Context context, String title, String msg,
                                                  String btnText1, String btnText2, String btnText3,
                                                  DialogInterface.OnClickListener neutralListener,
                                                  DialogInterface.OnClickListener negativeListener,
                                                  DialogInterface.OnClickListener positiveListener) {
  /*  final EditText et = new EditText(context);*/

    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(title);
    if (!StringHelper.isEmpty(msg)) {
        builder.setMessage(msg);
    }
    //  第一个按钮
    builder.setNeutralButton(btnText1, neutralListener);
    //  中间的按钮
    builder.setNegativeButton(btnText2, negativeListener);
    //  第三个按钮
    builder.setPositiveButton(btnText3, positiveListener);

    AlertDialog dialog = builder.show();

    dialog.setCanceledOnTouchOutside(true);
    dialog.setCancelable(true);

    //  Diglog的显示
    return dialog;
}
 
源代码16 项目: TowerCollector   文件: DialogManager.java
public static AlertDialog createConfirmationDialog(Context context, int titleId, int messageId, DialogInterface.OnClickListener confirmedAction) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);

    builder.setPositiveButton(R.string.dialog_proceed, confirmedAction);
    builder.setNegativeButton(R.string.dialog_cancel, null);

    builder.setTitle(titleId);
    builder.setMessage(messageId);

    AlertDialog dialog = builder.create();
    dialog.setCanceledOnTouchOutside(true);
    return dialog;
}
 
源代码17 项目: sctalk   文件: ChatFragment.java
private void handleGroupItemLongClick(final Context ctx, final RecentInfo recentInfo) {

        AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(ctx, android.R.style.Theme_Holo_Light_Dialog));
        builder.setTitle(recentInfo.getName());

        final boolean isTop = imService.getConfigSp().isTopSession(recentInfo.getSessionKey());
        final boolean isForbidden = recentInfo.isForbidden();
        int topMessageRes = isTop?R.string.cancel_top_message:R.string.top_message;
        int forbidMessageRes =isForbidden?R.string.cancel_forbid_group_message:R.string.forbid_group_message;

        String[] items = new String[]{ctx.getString(R.string.delete_session),ctx.getString(topMessageRes),ctx.getString(forbidMessageRes)};

        builder.setItems(items, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                switch (which) {
                    case 0 :
                        imService.getSessionManager().reqRemoveSession(recentInfo);
                        break;
                    case 1:{
                        imService.getConfigSp().setSessionTop(recentInfo.getSessionKey(),!isTop);
                    }break;
                    case 2:{
                        // 底层成功会事件通知
                        int shieldType = isForbidden?DBConstant.GROUP_STATUS_ONLINE:DBConstant.GROUP_STATUS_SHIELD;
                        imService.getGroupManager().reqShieldGroup(recentInfo.getPeerId(),shieldType);
                    }
                    break;
                }
            }
        });
        AlertDialog alertDialog = builder.create();
        alertDialog.setCanceledOnTouchOutside(true);
        alertDialog.show();
    }
 
源代码18 项目: Indic-Keyboard   文件: LatinIME.java
private void showSubtypeSelectorAndSettings() {
    final CharSequence title = getString(R.string.english_ime_input_options);
    // TODO: Should use new string "Select active input modes".
    final CharSequence languageSelectionTitle = getString(R.string.language_selection_title);
    final CharSequence[] items = new CharSequence[] {
            languageSelectionTitle,
            getString(ApplicationUtils.getActivityTitleResId(this, SettingsActivity.class))
    };
    final String imeId = mRichImm.getInputMethodIdOfThisIme();
    final OnClickListener listener = new OnClickListener() {
        @Override
        public void onClick(DialogInterface di, int position) {
            di.dismiss();
            switch (position) {
            case 0:
                final Intent intent = IntentUtils.getInputLanguageSelectionIntent(
                        imeId,
                        Intent.FLAG_ACTIVITY_NEW_TASK
                                | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
                                | Intent.FLAG_ACTIVITY_CLEAR_TOP);
                intent.putExtra(Intent.EXTRA_TITLE, languageSelectionTitle);
                startActivity(intent);
                break;
            case 1:
                launchSettings(SettingsActivity.EXTRA_ENTRY_VALUE_LONG_PRESS_COMMA);
                break;
            }
        }
    };
    final AlertDialog.Builder builder = new AlertDialog.Builder(
            DialogUtils.getPlatformDialogThemeContext(this));
    builder.setItems(items, listener).setTitle(title);
    final AlertDialog dialog = builder.create();
    dialog.setCancelable(true /* cancelable */);
    dialog.setCanceledOnTouchOutside(true /* cancelable */);
    showOptionDialog(dialog);
}
 
源代码19 项目: RedReader   文件: RedditAPICommentAction.java
public static void showActionMenu(
		final AppCompatActivity activity,
		final CommentListingFragment commentListingFragment,
		final RedditRenderableComment comment,
		final RedditCommentView commentView,
		final RedditChangeDataManager changeDataManager,
		final boolean isArchived) {

	final RedditAccount user = RedditAccountManager.getInstance(activity).getDefaultAccount();

	final ArrayList<RCVMenuItem> menu = new ArrayList<>();

	if(!user.isAnonymous()) {

		if (!isArchived) {
			if (!changeDataManager.isUpvoted(comment)) {
				menu.add(new RCVMenuItem(activity, R.string.action_upvote, RedditCommentAction.UPVOTE));
			} else {
				menu.add(new RCVMenuItem(activity, R.string.action_upvote_remove, RedditCommentAction.UNVOTE));
			}

			if (!changeDataManager.isDownvoted(comment)) {
				menu.add(new RCVMenuItem(activity, R.string.action_downvote, RedditCommentAction.DOWNVOTE));
			} else {
				menu.add(new RCVMenuItem(activity, R.string.action_downvote_remove, RedditCommentAction.UNVOTE));
			}
		}

		if(changeDataManager.isSaved(comment)) {
			menu.add(new RCVMenuItem(activity, R.string.action_unsave, RedditCommentAction.UNSAVE));
		} else {
			menu.add(new RCVMenuItem(activity, R.string.action_save, RedditCommentAction.SAVE));
		}

		menu.add(new RCVMenuItem(activity, R.string.action_report, RedditCommentAction.REPORT));

		if (!isArchived)
			menu.add(new RCVMenuItem(activity, R.string.action_reply, RedditCommentAction.REPLY));

		if(user.username.equalsIgnoreCase(comment.getParsedComment().getRawComment().author)) {
			if (!isArchived)
				menu.add(new RCVMenuItem(activity, R.string.action_edit, RedditCommentAction.EDIT));
			menu.add(new RCVMenuItem(activity, R.string.action_delete, RedditCommentAction.DELETE));
		}
	}

	menu.add(new RCVMenuItem(activity, R.string.action_comment_context, RedditCommentAction.CONTEXT));
	menu.add(new RCVMenuItem(activity, R.string.action_comment_go_to, RedditCommentAction.GO_TO_COMMENT));

	menu.add(new RCVMenuItem(activity, R.string.action_comment_links, RedditCommentAction.COMMENT_LINKS));

	if(commentListingFragment != null) {
		menu.add(new RCVMenuItem(activity, R.string.action_collapse, RedditCommentAction.COLLAPSE));
	}

	menu.add(new RCVMenuItem(activity, R.string.action_share, RedditCommentAction.SHARE));
	menu.add(new RCVMenuItem(activity, R.string.action_copy_text, RedditCommentAction.COPY_TEXT));
	menu.add(new RCVMenuItem(activity, R.string.action_copy_link, RedditCommentAction.COPY_URL));
	menu.add(new RCVMenuItem(activity, R.string.action_user_profile, RedditCommentAction.USER_PROFILE));
	menu.add(new RCVMenuItem(activity, R.string.action_properties, RedditCommentAction.PROPERTIES));

	final String[] menuText = new String[menu.size()];

	for(int i = 0; i < menuText.length; i++) {
		menuText[i] = menu.get(i).title;
	}

	final AlertDialog.Builder builder = new AlertDialog.Builder(activity);

	builder.setItems(menuText, new DialogInterface.OnClickListener() {
		@Override
		public void onClick(DialogInterface dialog, int which) {
			onActionMenuItemSelected(
					comment,
					commentView,
					activity,
					commentListingFragment,
					menu.get(which).action,
					changeDataManager);
		}
	});

	final AlertDialog alert = builder.create();
	alert.setCanceledOnTouchOutside(true);
	alert.show();
}
 
源代码20 项目: logmein-android   文件: ManagerUserServices.java
/**
 * Displays dialog box and manages updation of information
 * @param un username whose information is to be updated
 * @param inflater to instantiate layout
 * @return object of Dialog created
 */
public Dialog update(String un,LayoutInflater inflater){
    this.mUsername = un;
    initialize(inflater);
    mTextboxUsername.setText(un);
    final UserStructure us = mDatabaseEngine.getUsernamePassword(un);
    mTextboxPassword.setHint("(unchanged)");


    AlertDialog.Builder builder = new AlertDialog.Builder(this.mContext);
    builder.setView(mView)
           .setTitle("Update user")
           .setPositiveButton("UPDATE",null)
    .setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
        }
    });

    final AlertDialog dialog = builder.create();
    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
    dialog.setCanceledOnTouchOutside(false);
    dialog.show();

    dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            flagAddUpdate = false;
            String tb_username = mTextboxUsername.getText().toString();
            String tb_password = mTextboxPassword.getText().toString();
            if(tb_password.isEmpty()){
                if(tb_username != us.getUsername()){
                    if(add_update(tb_username, us.getPassword())){
                        //Save new username to preference for service
                        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(mContext);
                        SharedPreferences.Editor editor = preferences.edit();
                        editor.putString(SettingsActivity.KEY_CURRENT_USERNAME, tb_username);
                        //XXX: Should we save current position for recovery
                        editor.apply();
                        dialog.dismiss();
                    }
                }else{
                    dialog.dismiss();
                }
            }else if(add_update(mTextboxUsername.getText().toString(), mTextboxPassword.getText().toString())){
                dialog.dismiss();
            }
        }
    });
    return dialog;
}