List of usage examples for android.app AlertDialog findViewById
@Nullable public <T extends View> T findViewById(@IdRes int id)
From source file:jp.watnow.plugins.dialog.Notification.java
@SuppressLint("NewApi") private void changeTextDirection(Builder dlg) { int currentapiVersion = android.os.Build.VERSION.SDK_INT; dlg.create();//from www . j a va 2s . c om AlertDialog dialog = dlg.show(); if (currentapiVersion >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) { TextView messageview = (TextView) dialog.findViewById(android.R.id.message); if (messageview != null) messageview.setTextDirection(android.view.View.TEXT_DIRECTION_LOCALE); } }
From source file:github.daneren2005.dsub.util.Util.java
private static void showDialog(Context context, int icon, String title, String message, boolean linkify) { SpannableString ss = new SpannableString(message); if (linkify) { Linkify.addLinks(ss, Linkify.ALL); }//from w ww . j a va2 s . c o m AlertDialog dialog = new AlertDialog.Builder(context).setIcon(icon).setTitle(title).setMessage(ss) .setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int i) { dialog.dismiss(); } }).show(); ((TextView) dialog.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance()); }
From source file:org.rm3l.ddwrt.mgmt.AbstractRouterMgmtDialogFragment.java
@Override public void onStart() { super.onStart(); //super.onStart() is where dialog.show() is actually called on the underlying dialog, so we have to do it after this point final AlertDialog d = (AlertDialog) getDialog(); if (d != null) { d.findViewById(R.id.router_add_privkey).setOnClickListener(new View.OnClickListener() { @TargetApi(Build.VERSION_CODES.KITKAT) @Override/*from w w w . ja v a2s . c om*/ public void onClick(View view) { //Open up file picker // ACTION_OPEN_DOCUMENT is the intent to choose a file via the system's file // browser. final Intent intent = new Intent(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { intent.setAction(Intent.ACTION_OPEN_DOCUMENT); } else { intent.setAction(Intent.ACTION_GET_CONTENT); } // Filter to only show results that can be "opened", such as a // file (as opposed to a list of contacts or timezones) intent.addCategory(Intent.CATEGORY_OPENABLE); // search for all documents available via installed storage providers intent.setType("*/*"); AbstractRouterMgmtDialogFragment.this.startActivityForResult(intent, READ_REQUEST_CODE); } }); d.getButton(Dialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //Validate form boolean validForm = validateForm(d); if (validForm) { // Now check actual connection to router ... new CheckRouterConnectionAsyncTask( ((EditText) d.findViewById(R.id.router_add_ip)).getText().toString(), getSherlockActivity() .getSharedPreferences(DEFAULT_SHARED_PREFERENCES_KEY, Context.MODE_PRIVATE) .getBoolean(ALWAYS_CHECK_CONNECTION_PREF_KEY, true)).execute(d); } ///else dialog stays open. 'Cancel' button can still close it. } }); } }
From source file:org.rm3l.ddwrt.mgmt.RouterManagementActivity.java
@Override public void onClick(@Nullable View view) { if (view == null) { return;/*from w w w .java2 s .c o m*/ } if (view.getId() == R.id.router_list_add) { this.openAddRouterForm(); } else if (view.getId() == R.id.container_list_item) { // item click final int idx = mRecyclerView.getChildPosition(view); final RouterListRecycleViewAdapter adapter = (RouterListRecycleViewAdapter) mAdapter; if (actionMode != null) { final int previousSelectedItemCount = adapter.getSelectedItemCount(); myToggleSelection(idx); //Set background color, depending on whether this is a selection or a de-selection final int currentSelectedItemCount = adapter.getSelectedItemCount(); if (currentSelectedItemCount == previousSelectedItemCount - 1) { //De-selection: remove background view.setBackgroundResource(android.R.color.transparent); } else if (currentSelectedItemCount == previousSelectedItemCount + 1) { //Selection: apply background view.setBackgroundResource(android.R.color.background_light); } //other cases should not occur (as this is a single selection) //Now hide ActionMode if selected items count falls to 0 if (currentSelectedItemCount == 0) { actionMode.finish(); } return; } final AlertDialog alertDialog = Utils.buildAlertDialog(this, null, "Loading...", false, false); alertDialog.show(); ((TextView) alertDialog.findViewById(android.R.id.message)).setGravity(Gravity.CENTER_HORIZONTAL); new Handler().postDelayed(new Runnable() { @Override public void run() { //No action mode - normal mode => open up main activity for this router final List<Router> routersList = adapter.getRoutersList(); final Router router; if (idx < 0 || idx >= routersList.size() || (router = routersList.get(idx)) == null) { Crouton.makeText(RouterManagementActivity.this, "Unknown router - please refresh list or add a new one.", Style.ALERT).show(); return; } final Intent ddWrtMainIntent = new Intent(RouterManagementActivity.this, DDWRTMainActivity.class); ddWrtMainIntent.putExtra(ROUTER_SELECTED, router.getUuid()); RouterManagementActivity.this.startActivity(ddWrtMainIntent); alertDialog.cancel(); } }, 2000); } }
From source file:org.rm3l.ddwrt.mgmt.AbstractRouterMgmtDialogFragment.java
private boolean validateForm(@NotNull AlertDialog d) { @NotNull//from w ww .j a v a 2 s.com final EditText ipAddrView = (EditText) d.findViewById(R.id.router_add_ip); final Editable ipAddrViewText = ipAddrView.getText(); if (!(Patterns.IP_ADDRESS.matcher(ipAddrViewText).matches() || Patterns.DOMAIN_NAME.matcher(ipAddrViewText).matches())) { displayMessage(getString(R.string.router_add_dns_or_ip_invalid) + ":" + ipAddrViewText, ALERT); ipAddrView.requestFocus(); openKeyboard(ipAddrView); return false; } boolean validPort; @NotNull final EditText portView = (EditText) d.findViewById(R.id.router_add_port); try { final String portStr = portView.getText().toString(); validPort = (!isNullOrEmpty(portStr) && (Integer.parseInt(portStr) > 0)); } catch (@NotNull final Exception e) { e.printStackTrace(); validPort = false; } if (!validPort) { displayMessage(getString(R.string.router_add_port_invalid) + ":" + portView.getText(), ALERT); portView.requestFocus(); openKeyboard(portView); return false; } @NotNull final EditText sshUsernameView = (EditText) d.findViewById(R.id.router_add_username); if (isNullOrEmpty(sshUsernameView.getText().toString())) { displayMessage(getString(R.string.router_add_username_invalid), ALERT); sshUsernameView.requestFocus(); openKeyboard(sshUsernameView); return false; } final int checkedAuthMethodRadioButtonId = ((RadioGroup) d.findViewById(R.id.router_add_ssh_auth_method)) .getCheckedRadioButtonId(); if (checkedAuthMethodRadioButtonId == R.id.router_add_ssh_auth_method_password) { //Check password @NotNull final EditText sshPasswordView = (EditText) d.findViewById(R.id.router_add_password); if (isNullOrEmpty(sshPasswordView.getText().toString())) { displayMessage(getString(R.string.router_add_password_invalid), ALERT); sshPasswordView.requestFocus(); openKeyboard(sshPasswordView); return false; } } else if (checkedAuthMethodRadioButtonId == R.id.router_add_ssh_auth_method_privkey) { //Check privkey @NotNull final TextView sshPrivKeyView = (TextView) d.findViewById(R.id.router_add_privkey_path); if (isNullOrEmpty(sshPrivKeyView.getText().toString())) { displayMessage(getString(R.string.router_add_privkey_invalid), ALERT); sshPrivKeyView.requestFocus(); return false; } } return true; }
From source file:com.yeldi.yeldibazaar.ManageRepo.java
@Override public boolean onMenuItemSelected(int featureId, MenuItem item) { super.onMenuItemSelected(featureId, item); LayoutInflater li = LayoutInflater.from(this); switch (item.getItemId()) { case ADD_REPO: View view = li.inflate(R.layout.addrepo, null); Builder p = new AlertDialog.Builder(this).setView(view); final AlertDialog alrt = p.create(); alrt.setIcon(android.R.drawable.ic_menu_add); alrt.setTitle(getString(R.string.repo_add_title)); alrt.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.repo_add_add), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { EditText uri = (EditText) alrt.findViewById(R.id.edit_uri); String uri_str = uri.getText().toString(); try { DB db = DB.getDB(); db.addRepo(uri_str, null, null, 10, null, true); } finally { DB.releaseDB(); }/*from w w w. j av a2 s . c o m*/ changed = true; redraw(); } }); alrt.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { return; } }); alrt.show(); return true; case REM_REPO: final List<String> rem_lst = new ArrayList<String>(); CharSequence[] b = new CharSequence[repos.size()]; for (int i = 0; i < repos.size(); i++) { b[i] = repos.get(i).address; } AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(getString(R.string.repo_delete_title)); builder.setIcon(android.R.drawable.ic_menu_close_clear_cancel); builder.setMultiChoiceItems(b, null, new DialogInterface.OnMultiChoiceClickListener() { public void onClick(DialogInterface dialog, int whichButton, boolean isChecked) { if (isChecked) { rem_lst.add(repos.get(whichButton).address); } else { rem_lst.remove(repos.get(whichButton).address); } } }); builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { try { DB db = DB.getDB(); removeRepos(rem_lst); } finally { DB.releaseDB(); } changed = true; redraw(); } }); builder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { return; } }); AlertDialog alert = builder.create(); alert.show(); return true; } return true; }
From source file:org.rm3l.ddwrt.DDWRTMainActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { Log.d(TAG, "onActivityResult(" + requestCode + "," + resultCode + "," + data); // Check which request we're responding to switch (requestCode) { case LISTENED_REQUEST_CODE: //Forward to listener if (mCurrentActivityResultListener != null) { final DDWRTTile.ActivityResultListener listener = mCurrentActivityResultListener; mCurrentActivityResultListener = null; listener.onResultCode(resultCode, data); }//ww w .ja va 2 s . c o m break; case ROUTER_SETTINGS_ACTIVITY_CODE: // Make sure the request was successful and reload U if necessary if (resultCode == RESULT_OK) { if (this.mCurrentSyncInterval != this.mPreferences.getLong(SYNC_INTERVAL_MILLIS_PREF, -1l) || this.mCurrentTheme != this.mPreferences.getLong(THEMING_PREF, -1l) || !this.mCurrentSortingStrategy .equals(this.mPreferences.getString(SORTING_STRATEGY_PREF, ""))) { //Reload UI final AlertDialog alertDialog = Utils.buildAlertDialog(this, null, "Reloading UI...", false, false); alertDialog.show(); ((TextView) alertDialog.findViewById(android.R.id.message)) .setGravity(Gravity.CENTER_HORIZONTAL); new Handler().postDelayed(new Runnable() { @Override public void run() { finish(); startActivity(getIntent()); alertDialog.cancel(); } }, 2000); } } break; } super.onActivityResult(requestCode, resultCode, data); }
From source file:org.rm3l.ddwrt.mgmt.AbstractRouterMgmtDialogFragment.java
private void displayMessage(final String msg, final Style style) { if (isNullOrEmpty(msg)) { return;/*www . j a va 2 s .co m*/ } @org.jetbrains.annotations.Nullable final AlertDialog d = (AlertDialog) getDialog(); Crouton.makeText(getActivity(), msg, style, (ViewGroup) (d == null ? getView() : d.findViewById(R.id.router_add_notification_viewgroup))) .show(); }
From source file:de.baumann.thema.Screen_Main.java
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.license) { SpannableString s;/*from ww w.j av a2 s .co m*/ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { s = new SpannableString(Html.fromHtml(getString(R.string.about_text), Html.FROM_HTML_MODE_LEGACY)); } else { //noinspection deprecation s = new SpannableString(Html.fromHtml(getString(R.string.about_text))); } Linkify.addLinks(s, Linkify.WEB_URLS); final AlertDialog d = new AlertDialog.Builder(Screen_Main.this).setTitle(R.string.about_title) .setMessage(s) .setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }).show(); d.show(); ((TextView) d.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance()); } if (id == R.id.changelog) { Uri uri = Uri.parse("https://github.com/scoute-dich/Blue-Minimal/blob/master/CHANGELOG.md"); // missing 'http://' will cause crashed Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivity(intent); } if (id == R.id.donate) { Uri uri = Uri .parse("https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=NP6TGYDYP9SHY"); // missing 'http://' will cause crashed Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivity(intent); } return super.onOptionsItemSelected(item); }
From source file:org.sufficientlysecure.ical.ui.UrlDialog.java
@Override public void onStart() { super.onStart(); final AlertDialog dlg = (AlertDialog) getDialog(); if (dlg == null) return;// w w w. j a va 2 s . c om View.OnClickListener onClickTask; onClickTask = new View.OnClickListener() { @Override public void onClick(View view) { String url = mTextCalendarUrl.getText().toString(); boolean loginRequired = mCheckboxLoginRequired.isChecked(); String username = loginRequired ? mTextUsername.getText().toString() : ""; String password = loginRequired ? mTextPassword.getText().toString() : ""; if (!mActivity.setSource(url, null, username, password)) { TextView label = (TextView) dlg.findViewById(R.id.TextViewUrlError); label.setText(R.string.invalid_url); return; } Settings settings = mActivity.getSettings(); settings.putString(Settings.PREF_LASTURL, url); if (loginRequired) { settings.putString(Settings.PREF_LASTURLUSERNAME, username); if (settings.getSavePasswords()) settings.putString(Settings.PREF_LASTURLPASSWORD, password); } dlg.dismiss(); } }; dlg.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(onClickTask); }