List of usage examples for android.app AlertDialog setCanceledOnTouchOutside
public void setCanceledOnTouchOutside(boolean cancel)
From source file:com.oasis.sdk.activity.OasisSdkPayEpinActivity.java
private void showResultDialog(final String res) { final AlertDialog d = new AlertDialog.Builder(this).create(); d.show();//from w ww . jav a 2 s .co m d.setContentView(BaseUtils.getResourceValue("layout", "oasisgames_sdk_common_dialog_notitle")); d.setCanceledOnTouchOutside(false); TextView tv_content = (TextView) d .findViewById(BaseUtils.getResourceValue("id", "oasisgames_sdk_common_dialog_notitle_content")); String content = getResources().getString(BaseUtils.getResourceValue("string", TextUtils.isEmpty(res) ? "oasisgames_sdk_epin_notice_3" : "oasisgames_sdk_epin_notice_4")); content = content.replace("DIAMOND", res); tv_content.setText(content); TextView tv_sure = (TextView) d .findViewById(BaseUtils.getResourceValue("id", "oasisgames_sdk_common_dialog_notitle_sure")); tv_sure.setText( getResources().getString(BaseUtils.getResourceValue("string", "oasisgames_sdk_common_btn_sure"))); tv_sure.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { if (!TextUtils.isEmpty(res)) et_code.setText(""); d.dismiss(); } }); TextView tv_cancle = (TextView) d .findViewById(BaseUtils.getResourceValue("id", "oasisgames_sdk_common_dialog_notitle_cancle")); tv_cancle.setVisibility(View.GONE); TextView tv_text = (TextView) d .findViewById(BaseUtils.getResourceValue("id", "oasisgames_sdk_common_dialog_notitle_text")); tv_text.setVisibility(View.GONE); }
From source file:hku.fyp14017.blencode.ui.dialogs.LoginRegisterDialog.java
@Override public Dialog onCreateDialog(Bundle bundle) { View rootView = LayoutInflater.from(getActivity()) .inflate(hku.fyp14017.blencode.R.layout.dialog_login_register, null); usernameEditText = (EditText) rootView.findViewById(hku.fyp14017.blencode.R.id.username); passwordEditText = (EditText) rootView.findViewById(hku.fyp14017.blencode.R.id.password); termsOfUseLinkTextView = (TextView) rootView.findViewById(hku.fyp14017.blencode.R.id.register_terms_link); String termsOfUseUrl = getString(hku.fyp14017.blencode.R.string.about_link_template, Constants.CATROBAT_TERMS_OF_USE_URL, getString(hku.fyp14017.blencode.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(hku.fyp14017.blencode.R.string.login_register_dialog_title) .setPositiveButton(hku.fyp14017.blencode.R.string.login_or_register, null) .setNeutralButton(hku.fyp14017.blencode.R.string.password_forgotten, null).create(); loginRegisterDialog.setCanceledOnTouchOutside(true); loginRegisterDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); loginRegisterDialog.setOnShowListener(new OnShowListener() { @Override// ww w. j a v a2s . c o 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 passwordFhkuottenButton = loginRegisterDialog.getButton(AlertDialog.BUTTON_NEUTRAL); passwordFhkuottenButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { handlePasswordForgottenButtonClick(); } }); } }); return loginRegisterDialog; }
From source file:ab.util.AbDialogUtil.java
/** * AlertDialog ??/*from w w w . j a v a2 s. c o m*/ */ public static AlertDialog getAlertDialogWithoutRemove(Context mContext, int layout, double showWidth) { final AlertDialog alerDialog = new AlertDialog.Builder(mContext).create(); alerDialog.show(); alerDialog.setCanceledOnTouchOutside(true); Window window = alerDialog.getWindow(); // ?? int height = ScreenUtils.getScreenHeight(mContext); int width = ScreenUtils.getScreenWidth(mContext); WindowManager.LayoutParams params = window.getAttributes(); params.width = (int) (width * showWidth); params.gravity = Gravity.CENTER_HORIZONTAL; alerDialog.onWindowAttributesChanged(params); window.setContentView(layout); return alerDialog; }
From source file:com.wellsandwhistles.android.redditsp.reddit.prepared.RedditPreparedPost.java
public static void onActionMenuItemSelected(final RedditPreparedPost post, final AppCompatActivity activity, final Action action) { switch (action) { case UPVOTE://from www. j ava 2 s .c o m post.action(activity, RedditAPI.ACTION_UPVOTE); break; case DOWNVOTE: post.action(activity, RedditAPI.ACTION_DOWNVOTE); break; case UNVOTE: post.action(activity, RedditAPI.ACTION_UNVOTE); break; case SAVE: post.action(activity, RedditAPI.ACTION_SAVE); break; case UNSAVE: post.action(activity, RedditAPI.ACTION_UNSAVE); break; case HIDE: post.action(activity, RedditAPI.ACTION_HIDE); break; case UNHIDE: post.action(activity, RedditAPI.ACTION_UNHIDE); break; case EDIT: final Intent editIntent = new Intent(activity, CommentEditActivity.class); editIntent.putExtra("commentIdAndType", post.src.getIdAndType()); editIntent.putExtra("commentText", StringEscapeUtils.unescapeHtml4(post.src.getRawSelfText())); editIntent.putExtra("isSelfPost", true); activity.startActivity(editIntent); 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() { @Override public void onClick(final DialogInterface dialog, final int which) { post.action(activity, RedditAPI.ACTION_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() { @Override public void onClick(final DialogInterface dialog, final int which) { post.action(activity, RedditAPI.ACTION_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.src.getUrl(); intent.setData(Uri.parse(url)); activity.startActivity(intent); break; } case SELFTEXT_LINKS: { final HashSet<String> linksInComment = LinkHandler .computeAllLinks(StringEscapeUtils.unescapeHtml4(post.src.getRawSelfText())); 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() { @Override public void onClick(DialogInterface dialog, int which) { LinkHandler.onLinkClicked(activity, linksArr[which], false, post.src.getSrc()); dialog.dismiss(); } }); final AlertDialog alert = builder.create(); alert.setTitle(R.string.action_selftext_links); alert.setCanceledOnTouchOutside(true); alert.show(); } break; } case SAVE_IMAGE: { ((BaseActivity) activity).requestPermissionWithCallback(Manifest.permission.WRITE_EXTERNAL_STORAGE, new SaveImageCallback(activity, post.src.getUrl())); break; } case SHARE: { final Intent mailer = new Intent(Intent.ACTION_SEND); mailer.setType("text/plain"); mailer.putExtra(Intent.EXTRA_SUBJECT, post.src.getTitle()); mailer.putExtra(Intent.EXTRA_TEXT, post.src.getUrl()); activity.startActivity(Intent.createChooser(mailer, activity.getString(R.string.action_share))); break; } case SHARE_COMMENTS: { final boolean shareAsPermalink = PrefsUtility.pref_behaviour_share_permalink(activity, PreferenceManager.getDefaultSharedPreferences(activity)); final Intent mailer = new Intent(Intent.ACTION_SEND); mailer.setType("text/plain"); mailer.putExtra(Intent.EXTRA_SUBJECT, "Comments for " + post.src.getTitle()); if (shareAsPermalink) { mailer.putExtra(Intent.EXTRA_TEXT, Constants.Reddit.getNonAPIUri(post.src.getPermalink()).toString()); } else { mailer.putExtra(Intent.EXTRA_TEXT, Constants.Reddit .getNonAPIUri(Constants.Reddit.PATH_COMMENTS + post.src.getIdAlone()).toString()); } activity.startActivity( Intent.createChooser(mailer, activity.getString(R.string.action_share_comments))); break; } case SHARE_IMAGE: { ((BaseActivity) activity).requestPermissionWithCallback(Manifest.permission.WRITE_EXTERNAL_STORAGE, new ShareImageCallback(activity, post.src.getUrl())); break; } case COPY: { ClipboardManager manager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); manager.setText(post.src.getUrl()); break; } case GOTO_SUBREDDIT: { try { final Intent intent = new Intent(activity, PostListingActivity.class); intent.setData(SubredditPostListURL.getSubreddit(post.src.getSubreddit()).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.getAuthor()).toString()); break; case PROPERTIES: PostPropertiesDialog.newInstance(post.src.getSrc()).show(activity.getSupportFragmentManager(), null); break; case COMMENTS: ((PostSelectionListener) activity).onPostCommentsSelected(post); new Thread() { @Override public void run() { post.markAsRead(activity); } }.start(); break; case LINK: ((PostSelectionListener) activity).onPostSelected(post); break; case COMMENTS_SWITCH: if (!(activity instanceof MainActivity)) activity.finish(); ((PostSelectionListener) activity).onPostCommentsSelected(post); break; case LINK_SWITCH: if (!(activity instanceof MainActivity)) activity.finish(); ((PostSelectionListener) activity).onPostSelected(post); break; case ACTION_MENU: showActionMenu(activity, post); break; case REPLY: final Intent intent = new Intent(activity, CommentReplyActivity.class); intent.putExtra(CommentReplyActivity.PARENT_ID_AND_TYPE_KEY, post.src.getIdAndType()); intent.putExtra(CommentReplyActivity.PARENT_MARKDOWN_KEY, post.src.getUnescapedSelfText()); activity.startActivity(intent); break; case BACK: activity.onBackPressed(); break; case PIN: try { String subredditCanonicalName = RedditSubreddit.getCanonicalName(post.src.getSubreddit()); List<String> pinnedSubreddits = PrefsUtility.pref_pinned_subreddits(activity, PreferenceManager.getDefaultSharedPreferences(activity)); if (!pinnedSubreddits.contains(subredditCanonicalName)) { PrefsUtility.pref_pinned_subreddits_add(activity, PreferenceManager.getDefaultSharedPreferences(activity), subredditCanonicalName); } else { Toast.makeText(activity, R.string.mainmenu_toast_pinned, Toast.LENGTH_SHORT).show(); } } catch (RedditSubreddit.InvalidSubredditNameException e) { throw new RuntimeException(e); } break; case UNPIN: try { String subredditCanonicalName = RedditSubreddit.getCanonicalName(post.src.getSubreddit()); List<String> pinnedSubreddits = PrefsUtility.pref_pinned_subreddits(activity, PreferenceManager.getDefaultSharedPreferences(activity)); if (pinnedSubreddits.contains(subredditCanonicalName)) { PrefsUtility.pref_pinned_subreddits_remove(activity, PreferenceManager.getDefaultSharedPreferences(activity), subredditCanonicalName); } else { Toast.makeText(activity, R.string.mainmenu_toast_not_pinned, Toast.LENGTH_SHORT).show(); } } catch (RedditSubreddit.InvalidSubredditNameException e) { throw new RuntimeException(e); } break; case BLOCK: try { String subredditCanonicalName = RedditSubreddit.getCanonicalName(post.src.getSubreddit()); List<String> blockedSubreddits = PrefsUtility.pref_blocked_subreddits(activity, PreferenceManager.getDefaultSharedPreferences(activity)); if (!blockedSubreddits.contains(subredditCanonicalName)) { PrefsUtility.pref_blocked_subreddits_add(activity, PreferenceManager.getDefaultSharedPreferences(activity), subredditCanonicalName); } else { Toast.makeText(activity, R.string.mainmenu_toast_blocked, Toast.LENGTH_SHORT).show(); } } catch (RedditSubreddit.InvalidSubredditNameException e) { throw new RuntimeException(e); } break; case UNBLOCK: try { String subredditCanonicalName = RedditSubreddit.getCanonicalName(post.src.getSubreddit()); List<String> blockedSubreddits = PrefsUtility.pref_blocked_subreddits(activity, PreferenceManager.getDefaultSharedPreferences(activity)); if (blockedSubreddits.contains(subredditCanonicalName)) { PrefsUtility.pref_blocked_subreddits_remove(activity, PreferenceManager.getDefaultSharedPreferences(activity), subredditCanonicalName); } else { Toast.makeText(activity, R.string.mainmenu_toast_not_blocked, Toast.LENGTH_SHORT).show(); } } catch (RedditSubreddit.InvalidSubredditNameException e) { throw new RuntimeException(e); } break; case SUBSCRIBE: try { String subredditCanonicalName = RedditSubreddit.getCanonicalName(post.src.getSubreddit()); RedditSubredditSubscriptionManager subMan = RedditSubredditSubscriptionManager .getSingleton(activity, RedditAccountManager.getInstance(activity).getDefaultAccount()); if (subMan.getSubscriptionState( subredditCanonicalName) == RedditSubredditSubscriptionManager.SubredditSubscriptionState.NOT_SUBSCRIBED) { subMan.subscribe(subredditCanonicalName, activity); Toast.makeText(activity, R.string.options_subscribing, Toast.LENGTH_SHORT).show(); } else { Toast.makeText(activity, R.string.mainmenu_toast_subscribed, Toast.LENGTH_SHORT).show(); } } catch (RedditSubreddit.InvalidSubredditNameException e) { throw new RuntimeException(e); } break; case UNSUBSCRIBE: try { String subredditCanonicalName = RedditSubreddit.getCanonicalName(post.src.getSubreddit()); RedditSubredditSubscriptionManager subMan = RedditSubredditSubscriptionManager .getSingleton(activity, RedditAccountManager.getInstance(activity).getDefaultAccount()); if (subMan.getSubscriptionState( subredditCanonicalName) == RedditSubredditSubscriptionManager.SubredditSubscriptionState.SUBSCRIBED) { subMan.unsubscribe(subredditCanonicalName, activity); Toast.makeText(activity, R.string.options_unsubscribing, Toast.LENGTH_SHORT).show(); } else { Toast.makeText(activity, R.string.mainmenu_toast_not_subscribed, Toast.LENGTH_SHORT).show(); } } catch (RedditSubreddit.InvalidSubredditNameException e) { throw new RuntimeException(e); } break; } }
From source file:com.hybris.mobile.app.commerce.adapter.CartProductListAdapter.java
/** * Display the delete item dialog//from w w w. ja v a2s . c om * * @param positionToDelete */ private void showDeleteItemDialog(final int positionToDelete) { // Creating the dialog AlertDialog.Builder builder = new AlertDialog.Builder( new ContextThemeWrapper(getContext(), R.style.AlertDialogCustom)); builder.setMessage(R.string.cart_menu_delete_item_confirmation_title).setPositiveButton( R.string.cart_menu_delete_item_remove_button, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { QueryCartEntry queryCartEntry = new QueryCartEntry(); queryCartEntry.setEntryNumber(positionToDelete + ""); CommerceApplication.getContentServiceHelper() .deleteCartEntry(new ResponseReceiver<CartModification>() { @Override public void onResponse(Response<CartModification> response) { updateCart(); } @Override public void onError(Response<ErrorList> response) { UIUtils.showError(response, getContext()); // Update the cart SessionHelper.updateCart(getContext(), mRequestId, false); } }, mRequestId, queryCartEntry, null, false, null, mOnRequestListener); } }).setNegativeButton(R.string.cancel, null); AlertDialog alert = builder.create(); // The dialog is cancelable by 3 ways: cancel button, click outside the dialog, click on the back button alert.setCancelable(true); alert.setCanceledOnTouchOutside(true); alert.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { // We revert to the default quantity when we dismiss the dialog if (mSelectedQuantity != null) { mSelectedQuantity.getEditText().clearFocus(); mSelectedQuantity.getEditText().setText(mSelectedQuantity.getDefaultValue() + ""); } } }); alert.show(); }
From source file:com.wikonos.fingerprint.activities.MainActivity.java
/** * Create dialog list of logs//from www . ja va2 s . c o m * * @return */ public AlertDialog getDialogReviewLogs() { /** * List of logs */ File folder = new File(LogWriter.APPEND_PATH); final String[] files = folder.list(new FilenameFilter() { public boolean accept(File dir, String filename) { if (filename.contains(".log") && !filename.equals(LogWriter.DEFAULT_NAME) && !filename.equals(LogWriterSensors.DEFAULT_NAME) && !filename.equals(ErrorLog.DEFAULT_NAME)) return true; else return false; } }); Arrays.sort(files); ArrayUtils.reverse(files); String[] files_with_status = new String[files.length]; String[] sent_mode = { "", "(s) ", "(e) ", "(s+e) " }; for (int i = 0; i < files.length; ++i) { //0 -- not sent //1 -- server //2 -- email files_with_status[i] = sent_mode[getSentFlags(files[i], this)] + files[i]; } if (files != null && files.length > 0) { final boolean[] selected = new boolean[files.length]; final AlertDialog ald = new AlertDialog.Builder(MainActivity.this) .setMultiChoiceItems(files_with_status, selected, new DialogInterface.OnMultiChoiceClickListener() { public void onClick(DialogInterface dialog, int which, boolean isChecked) { selected[which] = isChecked; } }) .setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { // removeDialog(DIALOG_ID_REVIEW); } }) /** * Delete log */ .setNegativeButton("Delete", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { //Show delete confirm standardConfirmDialog("Delete Logs", "Are you sure you want to delete selected logs?", new OnClickListener() { //Confrim Delete @Override public void onClick(DialogInterface dialog, int which) { int deleteCount = 0; boolean flagSelected = false; for (int i = 0; i < selected.length; i++) { if (selected[i]) { flagSelected = true; LogWriter.delete(files[i]); LogWriter.delete(files[i].replace(".log", ".dev")); deleteCount++; } } reviewLogsCheckItems(flagSelected); removeDialog(DIALOG_ID_REVIEW); Toast.makeText(getApplicationContext(), deleteCount + " logs deleted.", Toast.LENGTH_SHORT).show(); } }, new OnClickListener() { //Cancel Delete @Override public void onClick(DialogInterface dialog, int which) { //Do nothing dialog.dismiss(); Toast.makeText(getApplicationContext(), "Delete cancelled.", Toast.LENGTH_SHORT).show(); } }, false); } }) /** * Send to server functional **/ .setNeutralButton("Send to Server", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { if (isOnline()) { ArrayList<String> filesList = new ArrayList<String>(); for (int i = 0; i < selected.length; i++) if (selected[i]) { filesList.add(LogWriter.APPEND_PATH + files[i]); //Move to httplogsender //setSentFlags(files[i], 1, MainActivity.this); //Mark file as sent } if (reviewLogsCheckItems(filesList.size() > 0 ? true : false)) { DataPersistence d = new DataPersistence(getApplicationContext()); new HttpLogSender(MainActivity.this, d.getServerName() + getString(R.string.submit_log_url), filesList) .setToken(getToken()).execute(); } // removeDialog(DIALOG_ID_REVIEW); } else { standardAlertDialog(getString(R.string.msg_alert), getString(R.string.msg_no_internet), null); } } }) /** * Email **/ .setPositiveButton("eMail", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { boolean flagSelected = false; // convert from paths to Android friendly // Parcelable Uri's ArrayList<Uri> uris = new ArrayList<Uri>(); for (int i = 0; i < selected.length; i++) if (selected[i]) { flagSelected = true; /** wifi **/ File fileIn = new File(LogWriter.APPEND_PATH + files[i]); Uri u = Uri.fromFile(fileIn); uris.add(u); /** sensors **/ File fileInSensors = new File( LogWriter.APPEND_PATH + files[i].replace(".log", ".dev")); Uri uSens = Uri.fromFile(fileInSensors); uris.add(uSens); setSentFlags(files[i], 2, MainActivity.this); //Mark file as emailed } if (reviewLogsCheckItems(flagSelected)) { /** * Run sending email activity */ Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE); emailIntent.setType("plain/text"); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Wifi Searcher Scan Log"); emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); startActivity(Intent.createChooser(emailIntent, "Send mail...")); } // removeDialog(DIALOG_ID_REVIEW); } }).create(); ald.getListView().setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) { AlertDialog segmentNameAlert = segmentNameDailog("Rename Segment", ald.getContext(), files[position], null, view, files, position); segmentNameAlert.setCanceledOnTouchOutside(false); segmentNameAlert.show(); return false; } }); return ald; } else { return standardAlertDialog(getString(R.string.msg_alert), getString(R.string.msg_log_nocount), new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { removeDialog(DIALOG_ID_REVIEW); } }); } }
From source file:com.mobicage.rogerthat.SendMessageButtonActivity.java
private void addButton() { final View dialog = getLayoutInflater().inflate(R.layout.new_button_dialog, null); final TextInputLayout captionViewLayout = (TextInputLayout) dialog.findViewById(R.id.button_caption); mCaptionView = captionViewLayout.getEditText(); mActionView = (EditText) dialog.findViewById(R.id.button_action); final ImageButton actionHelpButton = (ImageButton) dialog.findViewById(R.id.action_help_button); final RadioButton noneRadio = (RadioButton) dialog.findViewById(R.id.action_none); final RadioButton telRadio = (RadioButton) dialog.findViewById(R.id.action_tel); final RadioButton geoRadio = (RadioButton) dialog.findViewById(R.id.action_geo); final RadioButton wwwRadio = (RadioButton) dialog.findViewById(R.id.action_www); final int iconColor = LookAndFeelConstants.getPrimaryIconColor(SendMessageButtonActivity.this); noneRadio.setChecked(true);/* ww w. j av a2 s . c o m*/ mActionView.setVisibility(View.GONE); actionHelpButton.setVisibility(View.GONE); noneRadio.setOnClickListener(new SafeViewOnClickListener() { @Override public void safeOnClick(View v) { mActionView.setVisibility(View.GONE); actionHelpButton.setVisibility(View.GONE); } }); telRadio.setOnClickListener(new SafeViewOnClickListener() { @Override public void safeOnClick(View v) { mActionView.setText(""); mActionView.setVisibility(View.VISIBLE); mActionView.setInputType(InputType.TYPE_CLASS_PHONE); actionHelpButton.setVisibility(View.VISIBLE); actionHelpButton.setImageDrawable(new IconicsDrawable(mService, FontAwesome.Icon.faw_address_book_o) .color(iconColor).sizeDp(24)); } }); geoRadio.setOnClickListener(new SafeViewOnClickListener() { @Override public void safeOnClick(View v) { mActionView.setText(""); mActionView.setVisibility(View.VISIBLE); mActionView.setInputType(InputType.TYPE_CLASS_TEXT); actionHelpButton.setVisibility(View.VISIBLE); actionHelpButton.setImageDrawable( new IconicsDrawable(mService, FontAwesome.Icon.faw_map_marker).color(iconColor).sizeDp(24)); } }); wwwRadio.setOnClickListener(new SafeViewOnClickListener() { @Override public void safeOnClick(View v) { mActionView.setText("http://"); mActionView.setVisibility(View.VISIBLE); mActionView.setInputType(InputType.TYPE_CLASS_TEXT); actionHelpButton.setVisibility(View.GONE); } }); actionHelpButton.setOnClickListener(new SafeViewOnClickListener() { @Override public void safeOnClick(View v) { if (telRadio.isChecked()) { Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.CommonDataKinds.Phone.CONTENT_URI); startActivityForResult(intent, PICK_CONTACT); } else if (geoRadio.isChecked()) { Intent intent = new Intent(SendMessageButtonActivity.this, GetLocationActivity.class); startActivityForResult(intent, GET_LOCATION); } } }); String message = getString(R.string.create_button_title); String positiveCaption = getString(R.string.ok); String negativeCaption = getString(R.string.cancel); SafeDialogClick positiveClick = new SafeDialogClick() { @Override public void safeOnClick(DialogInterface di, int id) { String caption = mCaptionView.getText().toString(); if ("".equals(caption.trim())) { UIUtils.showLongToast(SendMessageButtonActivity.this, getString(R.string.caption_required)); return; } CannedButton cannedButton; if (!noneRadio.isChecked()) { String actionText = mActionView.getText().toString(); if ("".equals(caption.trim())) { UIUtils.showLongToast(SendMessageButtonActivity.this, getString(R.string.action_not_valid)); return; } if (telRadio.isChecked()) { actionText = "tel://" + actionText; } else if (geoRadio.isChecked()) { actionText = "geo://" + actionText; } Matcher action = actionPattern.matcher(actionText); if (!action.matches()) { UIUtils.showLongToast(SendMessageButtonActivity.this, getString(R.string.action_not_valid)); return; } cannedButton = new CannedButton(caption, "".equals(action.group(2)) ? null : action.group()); } else { cannedButton = new CannedButton(caption, null); } mCannedButtons.add(cannedButton); cannedButton.setSelected(true); mCannedButtonAdapter.notifyDataSetChanged(); mButtons.add(cannedButton.getId()); di.dismiss(); } }; AlertDialog alertDialog = UIUtils.showDialog(SendMessageButtonActivity.this, null, message, positiveCaption, positiveClick, negativeCaption, null, dialog); alertDialog.setCanceledOnTouchOutside(true); }
From source file:com.wellsandwhistles.android.redditsp.adapters.MainMenuListingManager.java
private GroupedRecyclerViewItemListItemView makeSubredditItem(final String name, final boolean hideDivider) { final View.OnClickListener clickListener = new View.OnClickListener() { @Override/*from w ww . j a va 2 s . c om*/ public void onClick(final View view) { try { mListener.onSelected((PostListingURL) SubredditPostListURL .getSubreddit(RedditSubreddit.getCanonicalName(name))); } catch (RedditSubreddit.InvalidSubredditNameException e) { throw new RuntimeException(e); } } }; final View.OnLongClickListener longClickListener = new View.OnLongClickListener() { @Override public boolean onLongClick(final View view) { try { final EnumSet<SubredditAction> itemPref = PrefsUtility.pref_menus_subreddit_context_items( mActivity, PreferenceManager.getDefaultSharedPreferences(mActivity)); List<String> pinnedSubreddits = PrefsUtility.pref_pinned_subreddits(mActivity, PreferenceManager.getDefaultSharedPreferences(mActivity)); if (itemPref.isEmpty()) { return true; } final String subredditCanonicalName = RedditSubreddit.getCanonicalName(name); final ArrayList<SubredditMenuItem> menu = new ArrayList<>(); if (itemPref.contains(SubredditAction.COPY_URL)) { menu.add(new SubredditMenuItem(mActivity, R.string.action_copy_link, SubredditAction.COPY_URL)); } if (itemPref.contains(SubredditAction.EXTERNAL)) { menu.add(new SubredditMenuItem(mActivity, R.string.action_external, SubredditAction.EXTERNAL)); } if (itemPref.contains(SubredditAction.SHARE)) { menu.add(new SubredditMenuItem(mActivity, R.string.action_share, SubredditAction.SHARE)); } if (itemPref.contains(SubredditAction.BLOCK)) { final List<String> blockedSubreddits = PrefsUtility.pref_blocked_subreddits(mActivity, PreferenceManager.getDefaultSharedPreferences(mActivity)); if (blockedSubreddits.contains(subredditCanonicalName)) { menu.add(new SubredditMenuItem(mActivity, R.string.unblock_subreddit, SubredditAction.UNBLOCK)); } else { menu.add(new SubredditMenuItem(mActivity, R.string.block_subreddit, SubredditAction.BLOCK)); } } if (itemPref.contains(SubredditAction.PIN)) { if (pinnedSubreddits.contains(subredditCanonicalName)) { menu.add(new SubredditMenuItem(mActivity, R.string.unpin_subreddit, SubredditAction.UNPIN)); } else { menu.add(new SubredditMenuItem(mActivity, R.string.pin_subreddit, SubredditAction.PIN)); } } if (!RedditAccountManager.getInstance(mActivity).getDefaultAccount().isAnonymous()) { if (itemPref.contains(SubredditAction.SUBSCRIBE)) { if (RedditSubredditSubscriptionManager .getSingleton(mActivity, RedditAccountManager.getInstance(mActivity).getDefaultAccount()) .getSubscriptionState( subredditCanonicalName) == RedditSubredditSubscriptionManager.SubredditSubscriptionState.SUBSCRIBED) { menu.add(new SubredditMenuItem(mActivity, R.string.options_unsubscribe, SubredditAction.UNSUBSCRIBE)); } else { menu.add(new SubredditMenuItem(mActivity, R.string.options_subscribe, SubredditAction.SUBSCRIBE)); } } } 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(mActivity); builder.setItems(menuText, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { onSubredditActionMenuItemSelected(subredditCanonicalName, mActivity, menu.get(which).action); } }); final AlertDialog alert = builder.create(); alert.setCanceledOnTouchOutside(true); alert.show(); } catch (RedditSubreddit.InvalidSubredditNameException e) { throw new RuntimeException(e); } return true; } }; return new GroupedRecyclerViewItemListItemView(null, name, hideDivider, clickListener, longClickListener); }
From source file:produvia.com.lights.SmartLightsActivity.java
public void promptLogin(final JSONObject loginService, final JSONObject responseData) { runOnUiThread(new Runnable() { public void run() { try { String type = loginService.getString("type"); //there was a login error. login again if (type.equals(WeaverSdk.FIRST_LOGIN_TYPE_NORMAL)) { //prompt for username and password and retry: promptUsernamePassword(loginService, responseData, false, null); } else if (type.equals(WeaverSdk.FIRST_LOGIN_TYPE_KEY)) { promptUsernamePassword(loginService, responseData, true, loginService.getString("description")); } else if (type.equals(WeaverSdk.FIRST_LOGIN_TYPE_PRESS2LOGIN)) { //prompt for username and password and retry: int countdown = loginService.has("login_timeout") ? loginService.getInt("login_timeout") : 15;// ww w. jav a 2s . c o m final AlertDialog alertDialog = new AlertDialog.Builder(SmartLightsActivity.this).create(); alertDialog.setTitle(loginService.getString("description")); alertDialog.setCancelable(false); alertDialog.setCanceledOnTouchOutside(false); alertDialog.setMessage(loginService.getString("description") + "\n" + "Attempting to login again in " + countdown + " seconds..."); alertDialog.show(); // new CountDownTimer(countdown * 1000, 1000) { @Override public void onTick(long millisUntilFinished) { try { alertDialog.setMessage(loginService.getString("description") + "\n" + "Attempting to login again in " + millisUntilFinished / 1000 + " seconds..."); } catch (JSONException e) { } } @Override public void onFinish() { alertDialog.dismiss(); new Thread(new Runnable() { public void run() { try { JSONArray services = new JSONArray(); services.put(loginService); responseData.put("services", services); WeaverSdkApi.servicesSet(SmartLightsActivity.this, responseData); } catch (JSONException e) { } } }).start(); } }.start(); } } catch (JSONException e) { e.printStackTrace(); } } }); }
From source file:org.shaastra.helper.SuperAwesomeCardFragment2.java
@SuppressLint("NewApi") @Override//from w ww . j a v a 2s . com public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); ListView lv; EditText inputSearch; FrameLayout fl = new FrameLayout(getActivity()); fl.setLayoutParams(params); final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics()); TextView v = new TextView(getActivity()); params.setMargins(margin, margin, margin, margin); v.setLayoutParams(params); v.setLayoutParams(params); v.setGravity(Gravity.CENTER); //v.setBackgroundResource(R.drawable.background_card); v.setText("CARD " + (position + 1)); View v1 = inflater.inflate(R.layout.contacts_list, container, false); lv = (ListView) v1.findViewById(R.id.list1); inputSearch = (EditText) v1.findViewById(R.id.inputSearch); ArrayList<Coord> rowItems = new ArrayList<Coord>(); if (position == 0) for (int i = 0; i < con.size(); i++) { Coord item = new Coord(con.get(i), pon.get(i), eon.get(i), eson.get(i)); rowItems.add(item); } else { for (int i = 0; i < len[position]; i++) { Coord item = new Coord(cString[position][i], pString[position][i], eString[position][i], evString[position][i]); rowItems.add(item); } } /*final ArrayAdapter<String> files = new ArrayAdapter<String>(getActivity(), R.layout.custom_list_item ); files.addAll(values); */ final CoordAdapter files = new CoordAdapter(getActivity(), R.layout.cordlist, rowItems); v1.setBackgroundColor(0xbba0d9ea); lv.setAdapter(files); lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, final View view, int position, long id) { b1 = new AlertDialog.Builder(getActivity()); b1.setMessage("What do you want to do?"); b1.setNegativeButton("Call", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub TextView t = (TextView) view.findViewById(R.id.cordphone); String url = "tel:" + t.getText(); Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); startActivity(intent); } }); b1.setPositiveButton("Message", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub TextView t = (TextView) view.findViewById(R.id.cordphone); String url = "sms:" + t.getText(); Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse(url)); startActivity(intent); } }); AlertDialog a1 = b1.create(); a1.setCanceledOnTouchOutside(true); a1.show(); //Open the browser here } }); inputSearch.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) { // When user changed the Text files.getFilter().filter(cs.toString()); } @Override public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { // TODO Auto-generated method stub } @Override public void afterTextChanged(Editable arg0) { // TODO Auto-generated method stub } }); //v1.setLayoutParams(params); return v1; }