List of usage examples for android.app AlertDialog setCanceledOnTouchOutside
public void setCanceledOnTouchOutside(boolean cancel)
From source file:com.dena.app.usage.watcher.fragment.WatchFragment.java
public void onItemClick(AdapterView adapterview, View view, int i, long l) { final WatchItem item = (WatchItem) adapterview.getItemAtPosition(i); final Intent intent = getActivity().getPackageManager().getLaunchIntentForPackage(item.getPackageName()); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(item.getAppName()); List<String> list = new ArrayList<>(); list.add(getString(R.string.set_usage_limit)); list.add(getString(R.string.reset_usage_limit)); list.add(getString(R.string.hide_this_app)); if (null != intent) { list.add(getString(R.string.launch_this_app)); }/*from ww w . j a va 2 s . com*/ builder.setItems(list.toArray(new String[0]), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialoginterface, int j) { switch (j) { case 0: showSetTimerDialog(item); break; case 1: mDB.setTimerInfo(item.getPackageName(), 0); mDB.setTimerWarning(item.getPackageName(), 0); mDB.setTimerFinish(item.getPackageName(), 0); onRefresh(); break; case 2: (new UnwatchManager(getActivity())).addUnwatch(item.getPackageName()); onRefresh(); break; case 3: if (null != intent) { startActivity(intent); } break; } } }); AlertDialog alertdialog = builder.create(); alertdialog.setCancelable(true); alertdialog.setCanceledOnTouchOutside(true); alertdialog.show(); }
From source file:com.janela.mobile.ui.repo.RepositoryListFragment.java
@Override public boolean onListItemLongClick(ListView list, View v, int position, long itemId) { if (!isUsable()) return false; final Repository repo = (Repository) list.getItemAtPosition(position); if (repo == null) return false; final AlertDialog dialog = LightAlertDialog.create(getActivity()); dialog.setCanceledOnTouchOutside(true); dialog.setTitle(repo.generateId());// ww w . j a va2 s .c o m View view = getActivity().getLayoutInflater().inflate(R.layout.repo_dialog, null); ViewFinder finder = new ViewFinder(view); final User owner = repo.getOwner(); avatars.bind(finder.imageView(R.id.iv_owner_avatar), owner); finder.setText(R.id.tv_owner_name, getString(R.string.navigate_to_user, owner.getLogin())); finder.onClick(R.id.ll_owner_area, new OnClickListener() { public void onClick(View v) { dialog.dismiss(); viewUser(owner); } }); if ((recentRepos != null) && (recentRepos.contains(repo))) { finder.find(R.id.divider).setVisibility(View.VISIBLE); finder.find(R.id.ll_recent_repo_area).setVisibility(View.VISIBLE); finder.onClick(R.id.ll_recent_repo_area, new OnClickListener() { public void onClick(View v) { dialog.dismiss(); recentRepos.remove(repo); refresh(); } }); } dialog.setView(view); dialog.show(); return true; }
From source file:com.github.mobile.ui.repo.RepositoryListFragment.java
@Override public boolean onListItemLongClick(ListView list, View v, int position, long itemId) { if (!isUsable()) return false; final Repository repo = (Repository) list.getItemAtPosition(position); if (repo == null) return false; final AlertDialog dialog = LightAlertDialog.create(getActivity()); dialog.setCanceledOnTouchOutside(true); dialog.setTitle(repo.generateId());//from www . j a v a 2s .c o m View view = getActivity().getLayoutInflater().inflate(layout.repo_dialog, null); ViewFinder finder = new ViewFinder(view); final User owner = repo.getOwner(); avatars.bind(finder.imageView(id.iv_owner_avatar), owner); finder.setText(id.tv_owner_name, getString(string.navigate_to_user, owner.getLogin())); finder.onClick(id.ll_owner_area, new OnClickListener() { public void onClick(View v) { dialog.dismiss(); viewUser(owner); } }); if ((recentRepos != null) && (recentRepos.contains(repo))) { finder.find(id.divider).setVisibility(View.VISIBLE); finder.find(id.ll_recent_repo_area).setVisibility(View.VISIBLE); finder.onClick(id.ll_recent_repo_area, new OnClickListener() { public void onClick(View v) { dialog.dismiss(); recentRepos.remove(repo); refresh(); } }); } dialog.setView(view); dialog.show(); return true; }
From source file:com.github.pockethub.ui.repo.RepositoryListFragment.java
@Override public boolean onListItemLongClick(ListView list, View v, int position, long itemId) { if (!isUsable()) return false; final Repo repo = (Repo) list.getItemAtPosition(position); if (repo == null) return false; final AlertDialog dialog = LightAlertDialog.create(getActivity()); dialog.setCanceledOnTouchOutside(true); dialog.setTitle(InfoUtils.createRepoId(repo)); View view = getActivity().getLayoutInflater().inflate(R.layout.repo_dialog, null); ViewFinder finder = new ViewFinder(view); final User owner = repo.owner; avatars.bind(finder.imageView(R.id.iv_owner_avatar), owner); finder.setText(R.id.tv_owner_name, getString(R.string.navigate_to_user, owner.login)); finder.onClick(R.id.ll_owner_area, new OnClickListener() { public void onClick(View v) { dialog.dismiss();/*from w w w .ja va 2 s . co m*/ viewUser(owner); } }); if ((recentRepos != null) && (recentRepos.contains(repo))) { finder.find(R.id.divider).setVisibility(View.VISIBLE); finder.find(R.id.ll_recent_repo_area).setVisibility(View.VISIBLE); finder.onClick(R.id.ll_recent_repo_area, new OnClickListener() { public void onClick(View v) { dialog.dismiss(); recentRepos.remove(repo); refresh(); } }); } dialog.setView(view); dialog.show(); return true; }
From source file:org.quantumbadger.redreader.adapters.AccountListAdapter.java
@Override protected void onBindContentItemViewHolder(VH holder, final int position) { final VH1Text vh = (VH1Text) holder; final RedditAccount account = accounts.get(position); final BetterSSB username = new BetterSSB(); if (account.isAnonymous()) { username.append(context.getString(R.string.accounts_anon), 0); } else {//from www . j a v a2 s . com username.append(account.username, 0); } if (account.equals(RedditAccountManager.getInstance(context).getDefaultAccount())) { final TypedArray attr = context.obtainStyledAttributes(new int[] { R.attr.rrListSubtitleCol }); final int col = attr.getColor(0, 0); attr.recycle(); username.append(" (" + context.getString(R.string.accounts_active) + ")", BetterSSB.FOREGROUND_COLOR | BetterSSB.SIZE, col, 0, 0.8f); } vh.text.setText(username.get()); vh.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final RedditAccount account = accounts.get(position); final String[] items = account.isAnonymous() ? new String[] { context.getString(R.string.accounts_setactive) } : new String[] { context.getString(R.string.accounts_setactive), context.getString(R.string.accounts_delete) }; final AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { final String selected = items[which]; if (selected.equals(context.getString(R.string.accounts_setactive))) { RedditAccountManager.getInstance(context).setDefaultAccount(account); } else if (selected.equals(context.getString(R.string.accounts_delete))) { new AlertDialog.Builder(context).setTitle(R.string.accounts_delete) .setMessage(R.string.accounts_delete_sure) .setPositiveButton(R.string.accounts_delete, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { RedditAccountManager.getInstance(context) .deleteAccount(account); } }) .setNegativeButton(R.string.dialog_cancel, null).show(); } } }); builder.setNeutralButton(R.string.dialog_cancel, null); final AlertDialog alert = builder.create(); alert.setTitle( account.isAnonymous() ? context.getString(R.string.accounts_anon) : account.username); alert.setCanceledOnTouchOutside(true); alert.show(); } }); }
From source file:org.quantumbadger.redreader.reddit.prepared.RedditPreparedPost.java
public static void onActionMenuItemSelected(final RedditPreparedPost post, final Activity activity, final Action action) { switch (action) { case UPVOTE:/*from w w w.j av a 2 s. c o m*/ post.action(activity, RedditAPI.RedditAction.UPVOTE); break; case DOWNVOTE: post.action(activity, RedditAPI.RedditAction.DOWNVOTE); break; case UNVOTE: post.action(activity, RedditAPI.RedditAction.UNVOTE); break; case SAVE: post.action(activity, RedditAPI.RedditAction.SAVE); break; case UNSAVE: post.action(activity, RedditAPI.RedditAction.UNSAVE); break; case HIDE: post.action(activity, RedditAPI.RedditAction.HIDE); break; case UNHIDE: post.action(activity, RedditAPI.RedditAction.UNHIDE); break; case DELETE: new AlertDialog.Builder(activity).setTitle(R.string.accounts_delete).setMessage(R.string.delete_confirm) .setPositiveButton(R.string.action_delete, new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, final int which) { post.action(activity, RedditAPI.RedditAction.DELETE); } }).setNegativeButton(R.string.dialog_cancel, null).show(); break; case REPORT: new AlertDialog.Builder(activity).setTitle(R.string.action_report) .setMessage(R.string.action_report_sure) .setPositiveButton(R.string.action_report, new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, final int which) { post.action(activity, RedditAPI.RedditAction.REPORT); // TODO update the view to show the result // TODO don't forget, this also hides } }).setNegativeButton(R.string.dialog_cancel, null).show(); break; case EXTERNAL: { final Intent intent = new Intent(Intent.ACTION_VIEW); String url = (activity instanceof WebViewActivity) ? ((WebViewActivity) activity).getCurrentUrl() : post.url; intent.setData(Uri.parse(url)); activity.startActivity(intent); break; } case SELFTEXT_LINKS: { final HashSet<String> linksInComment = LinkHandler .computeAllLinks(StringEscapeUtils.unescapeHtml4(post.src.selftext)); if (linksInComment.isEmpty()) { General.quickToast(activity, R.string.error_toast_no_urls_in_self); } else { final String[] linksArr = linksInComment.toArray(new String[linksInComment.size()]); final AlertDialog.Builder builder = new AlertDialog.Builder(activity); builder.setItems(linksArr, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { LinkHandler.onLinkClicked(activity, linksArr[which], false, post.src); dialog.dismiss(); } }); final AlertDialog alert = builder.create(); alert.setTitle(R.string.action_selftext_links); alert.setCanceledOnTouchOutside(true); alert.show(); } break; } case SAVE_IMAGE: { final RedditAccount anon = RedditAccountManager.getAnon(); LinkHandler.getImageInfo(activity, post.url, Constants.Priority.IMAGE_VIEW, 0, new GetImageInfoListener() { @Override public void onFailure(final RequestFailureType type, final Throwable t, final StatusLine status, final String readableMessage) { final RRError error = General.getGeneralErrorForFailure(activity, type, t, status, post.url); General.showResultDialog(activity, error); } @Override public void onSuccess(final ImgurAPI.ImageInfo info) { CacheManager.getInstance(activity) .makeRequest(new CacheRequest(General.uriFromString(info.urlOriginal), anon, null, Constants.Priority.IMAGE_VIEW, 0, CacheRequest.DownloadType.IF_NECESSARY, Constants.FileType.IMAGE, false, false, false, activity) { @Override protected void onCallbackException(Throwable t) { BugReportActivity.handleGlobalError(context, t); } @Override protected void onDownloadNecessary() { General.quickToast(context, R.string.download_downloading); } @Override protected void onDownloadStarted() { } @Override protected void onFailure(RequestFailureType type, Throwable t, StatusLine status, String readableMessage) { final RRError error = General.getGeneralErrorForFailure(context, type, t, status, url.toString()); General.showResultDialog(activity, error); } @Override protected void onProgress(boolean authorizationInProgress, long bytesRead, long totalBytes) { } @Override protected void onSuccess(CacheManager.ReadableCacheFile cacheFile, long timestamp, UUID session, boolean fromCache, String mimetype) { File dst = new File( Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES), General.uriFromString(info.urlOriginal).getPath()); if (dst.exists()) { int count = 0; while (dst.exists()) { count++; dst = new File( Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES), count + "_" + General.uriFromString(info.urlOriginal) .getPath().substring(1)); } } try { final InputStream cacheFileInputStream = cacheFile.getInputStream(); if (cacheFileInputStream == null) { notifyFailure(RequestFailureType.CACHE_MISS, null, null, "Could not find cached image"); return; } General.copyFile(cacheFileInputStream, dst); } catch (IOException e) { notifyFailure(RequestFailureType.STORAGE, e, null, "Could not copy file"); return; } activity.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + dst.getAbsolutePath()))); General.quickToast(context, context.getString(R.string.action_save_image_success) + " " + dst.getAbsolutePath()); } }); } @Override public void onNotAnImage() { General.quickToast(activity, R.string.selected_link_is_not_image); } }); break; } case SHARE: { final Intent mailer = new Intent(Intent.ACTION_SEND); mailer.setType("text/plain"); mailer.putExtra(Intent.EXTRA_SUBJECT, post.title); mailer.putExtra(Intent.EXTRA_TEXT, post.url); activity.startActivity(Intent.createChooser(mailer, activity.getString(R.string.action_share))); break; } case SHARE_COMMENTS: { final Intent mailer = new Intent(Intent.ACTION_SEND); mailer.setType("text/plain"); mailer.putExtra(Intent.EXTRA_SUBJECT, "Comments for " + post.title); mailer.putExtra(Intent.EXTRA_TEXT, Constants.Reddit.getUri(Constants.Reddit.PATH_COMMENTS + post.idAlone).toString()); activity.startActivity( Intent.createChooser(mailer, activity.getString(R.string.action_share_comments))); break; } case COPY: { ClipboardManager manager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); manager.setText(post.url); break; } case GOTO_SUBREDDIT: { try { final Intent intent = new Intent(activity, PostListingActivity.class); intent.setData(SubredditPostListURL.getSubreddit(post.src.subreddit).generateJsonUri()); activity.startActivityForResult(intent, 1); } catch (RedditSubreddit.InvalidSubredditNameException e) { Toast.makeText(activity, R.string.invalid_subreddit_name, Toast.LENGTH_LONG).show(); } break; } case USER_PROFILE: LinkHandler.onLinkClicked(activity, new UserProfileURL(post.src.author).toString()); break; case PROPERTIES: PostPropertiesDialog.newInstance(post.src).show(activity.getFragmentManager(), null); break; case COMMENTS: ((RedditPostView.PostSelectionListener) activity).onPostCommentsSelected(post); break; case LINK: ((RedditPostView.PostSelectionListener) activity).onPostSelected(post); break; case COMMENTS_SWITCH: if (!(activity instanceof MainActivity)) activity.finish(); ((RedditPostView.PostSelectionListener) activity).onPostCommentsSelected(post); break; case LINK_SWITCH: if (!(activity instanceof MainActivity)) activity.finish(); ((RedditPostView.PostSelectionListener) activity).onPostSelected(post); break; case ACTION_MENU: showActionMenu(activity, post); break; case REPLY: final Intent intent = new Intent(activity, CommentReplyActivity.class); intent.putExtra("parentIdAndType", post.idAndType); activity.startActivity(intent); break; } }
From source file:org.catrobat.catroid.ui.dialogs.LoginRegisterDialog.java
@Override public Dialog onCreateDialog(Bundle bundle) { View rootView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_login_register, null); usernameEditText = (EditText) rootView.findViewById(R.id.username); passwordEditText = (EditText) rootView.findViewById(R.id.password); termsOfUseLinkTextView = (TextView) rootView.findViewById(R.id.register_terms_link); String termsOfUseUrl = getString(R.string.about_link_template, Constants.CATROBAT_TERMS_OF_USE_URL, getString(R.string.register_pocketcode_terms_of_use_text)); termsOfUseLinkTextView.setMovementMethod(LinkMovementMethod.getInstance()); termsOfUseLinkTextView.setText(Html.fromHtml(termsOfUseUrl)); usernameEditText.setText(""); passwordEditText.setText(""); final AlertDialog loginRegisterDialog = new AlertDialog.Builder(getActivity()).setView(rootView) .setTitle(R.string.login_register_dialog_title).setPositiveButton(R.string.login_or_register, null) .setNeutralButton(R.string.password_forgotten, null).create(); loginRegisterDialog.setCanceledOnTouchOutside(true); loginRegisterDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); loginRegisterDialog.setOnShowListener(new OnShowListener() { @Override//w w w .j a v a 2s. co m public void onShow(DialogInterface dialog) { InputMethodManager inputManager = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.showSoftInput(usernameEditText, InputMethodManager.SHOW_IMPLICIT); Button loginRegisterButton = loginRegisterDialog.getButton(AlertDialog.BUTTON_POSITIVE); loginRegisterButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { handleLoginRegisterButtonClick(); } }); Button passwordForgottenButton = loginRegisterDialog.getButton(AlertDialog.BUTTON_NEUTRAL); passwordForgottenButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { handlePasswordForgottenButtonClick(); } }); } }); return loginRegisterDialog; }
From source file:de.schildbach.wallet.ui.send.RaiseFeeDialogFragment.java
@Override public Dialog onCreateDialog(final Bundle savedInstanceState) { final View view = LayoutInflater.from(activity).inflate(R.layout.raise_fee_dialog, null); messageView = (TextView) view.findViewById(R.id.raise_fee_dialog_message); passwordGroup = view.findViewById(R.id.raise_fee_dialog_password_group); passwordView = (EditText) view.findViewById(R.id.raise_fee_dialog_password); passwordView.setText(null);//from w w w. ja v a2 s.c o m badPasswordView = view.findViewById(R.id.raise_fee_dialog_bad_password); final DialogBuilder builder = new DialogBuilder(activity); builder.setTitle(R.string.raise_fee_dialog_title); builder.setView(view); // dummies, just to make buttons show builder.setPositiveButton(R.string.raise_fee_dialog_button_raise, null); builder.setNegativeButton(R.string.button_dismiss, null); builder.setCancelable(false); final AlertDialog dialog = builder.create(); dialog.setCanceledOnTouchOutside(false); dialog.setOnShowListener(new OnShowListener() { @Override public void onShow(final DialogInterface d) { positiveButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE); negativeButton = dialog.getButton(DialogInterface.BUTTON_NEGATIVE); positiveButton.setTypeface(Typeface.DEFAULT_BOLD); positiveButton.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { handleGo(); } }); negativeButton.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { dismissAllowingStateLoss(); } }); passwordView.addTextChangedListener(textWatcher); RaiseFeeDialogFragment.this.dialog = dialog; updateView(); } }); log.info("showing raise fee dialog"); return dialog; }
From source file:com.guidewithme.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();//from www .jav a 2s . c om ad.setCanceledOnTouchOutside(true); ad.setView(wb); ad.show(); }
From source file:com.cpen321.fridgemanager.OcrReader.OcrCaptureActivity.java
private void showFirstTimeDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setCancelable(true);/*from w ww . j a v a 2 s . com*/ builder.setTitle("Scan Your Food"); builder.setMessage(getString(R.string.ocr_explanation)); builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); } }); AlertDialog alert = builder.create(); alert.setCanceledOnTouchOutside(false); alert.show(); }