@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { // Get new list case R.id.action_fetch: TkkListViewFragment f = ((TkkListViewFragment) fm.findFragmentById(R.id.fragment_container)); AlertDialog.Builder cDialog = new AlertDialog.Builder((f.getListView().getContext())); cDialog .setMessage( "Do you want to download a new stations list?\n(This will add deleted stations back)") .setPositiveButton( "Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { progBar.setVisibility(View.VISIBLE); tuxData.repopulateStations(); ((ArrayAdapter) ((TkkListViewFragment) fm.findFragmentById(R.id.fragment_container)) .getListView() .getAdapter()) .notifyDataSetChanged(); } }) .setNegativeButton( "No", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { // do nothing } }); AlertDialog a = cDialog.show(); TextView mView = (TextView) a.findViewById(android.R.id.message); if (mView != null) { mView.setGravity(Gravity.CENTER); } return true; // Edit list mode case R.id.action_edit: listEditEnabled = !listEditEnabled; item.setChecked(listEditEnabled); TkkListViewFragment fragment = ((TkkListViewFragment) fm.findFragmentById(R.id.fragment_container)); fragment.getListView().setRearrangeEnabled(listEditEnabled); setDeleteButtons(fragment); return true; // About screen case R.id.action_about: displayAbout(); return true; // The f**k that happen? default: return super.onOptionsItemSelected(item); } }
private void updateTextCount(DialogInterface dialog, CharSequence s, ParcelableStatus status) { if (!(dialog instanceof AlertDialog)) return; final AlertDialog alertDialog = (AlertDialog) dialog; final Button positiveButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE); if (positiveButton == null) return; positiveButton.setText(s.length() > 0 ? R.string.comment : R.string.retweet); final String statusLink = LinkCreator.getTwitterStatusLink(status.user_screen_name, status.id).toString(); final StatusTextCountView textCountView = (StatusTextCountView) alertDialog.findViewById(R.id.comment_text_count); textCountView.setTextCount(mValidator.getTweetLength(s + " " + statusLink)); }
// show information dialog, called by first run private void showInfoDialog() { // read version info from androidmanifest.xml String versionName = "unknown"; int versionCode = 0; PackageManager pm = getPackageManager(); try { PackageInfo pi = pm.getPackageInfo(getPackageName(), 0); versionName = pi.versionName; versionCode = pi.versionCode; } catch (PackageManager.NameNotFoundException e) { Log.e(TAG, "showInfoDialog: " + Log.getStackTraceString(e)); } // generate about_content with version from manifest String content_with_version = getString(R.string.about_content, versionName, versionCode); // linkify final SpannableString msg = new SpannableString(content_with_version); Linkify.addLinks(msg, Linkify.WEB_URLS); final AlertDialog dlg = new AlertDialog.Builder(this) .setIcon(R.drawable.ic_launcher) .setTitle(R.string.about_title) .setMessage(msg) .create(); dlg.setButton( AlertDialog.BUTTON_POSITIVE, getString(R.string.about_close), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // do nothing here } }); dlg.show(); // Make the textview clickable. Must be called after show() ((TextView) dlg.findViewById(android.R.id.message)) .setMovementMethod(LinkMovementMethod.getInstance()); }
protected String getText() { AlertDialog alertDialog = (AlertDialog) getDialog(); final AutoCompleteTextView editText = (AutoCompleteTextView) alertDialog.findViewById(R.id.edit_text); return ParseUtils.parseString(editText.getText()); }
@SmallTest @Feature({"Sync"}) public void testPassphraseCreation() throws Exception { setUpTestAccountAndSignIn(); SyncTestUtil.waitForSyncActive(); final SyncCustomizationFragment fragment = startSyncCustomizationFragment(); ThreadUtils.runOnUiThreadBlocking( new Runnable() { @Override public void run() { fragment.onPassphraseTypeSelected(PassphraseType.CUSTOM_PASSPHRASE); } }); getInstrumentation().waitForIdleSync(); PassphraseCreationDialogFragment pcdf = getPassphraseCreationDialogFragment(); AlertDialog dialog = (AlertDialog) pcdf.getDialog(); Button okButton = dialog.getButton(Dialog.BUTTON_POSITIVE); EditText enterPassphrase = (EditText) dialog.findViewById(R.id.passphrase); EditText confirmPassphrase = (EditText) dialog.findViewById(R.id.confirm_passphrase); // Error if you try to submit empty passphrase. assertNull(confirmPassphrase.getError()); clickButton(okButton); assertTrue(pcdf.isResumed()); assertNotNull(enterPassphrase.getError()); assertNull(confirmPassphrase.getError()); // Error if you try to submit with only the first box filled. clearError(confirmPassphrase); setText(enterPassphrase, "foo"); clickButton(okButton); assertTrue(pcdf.isResumed()); assertNull(enterPassphrase.getError()); assertNotNull(confirmPassphrase.getError()); // Remove first box should only show empty error message setText(enterPassphrase, ""); clickButton(okButton); assertNotNull(enterPassphrase.getError()); assertNull(confirmPassphrase.getError()); // Error if you try to submit with only the second box filled. clearError(confirmPassphrase); setText(confirmPassphrase, "foo"); clickButton(okButton); assertTrue(pcdf.isResumed()); assertNull(enterPassphrase.getError()); assertNotNull(confirmPassphrase.getError()); // No error if text doesn't match without button press. setText(enterPassphrase, "foo"); clearError(confirmPassphrase); setText(confirmPassphrase, "bar"); assertNull(enterPassphrase.getError()); assertNull(confirmPassphrase.getError()); // Error if you try to submit unmatching text. clearError(confirmPassphrase); clickButton(okButton); assertTrue(pcdf.isResumed()); assertNull(enterPassphrase.getError()); assertNotNull(confirmPassphrase.getError()); // Success if text matches. setText(confirmPassphrase, "foo"); clickButton(okButton); assertFalse(pcdf.isResumed()); }
@Override public void onClick(DialogInterface dialog, int which) { Activity ctx = getActivity(); if (ctx == null) { return; } Bundle args = getArguments(); Long accountId = args != null ? args.getLong(KEY_ACCOUNTID) : null; AlertDialog dlg = (AlertDialog) dialog; String format = ((RadioGroup) dlg.findViewById(R.id.format)).getCheckedRadioButtonId() == R.id.csv ? "CSV" : "QIF"; String dateFormat = dateFormatET.getText().toString(); char decimalSeparator = ((RadioGroup) dlg.findViewById(R.id.separator)).getCheckedRadioButtonId() == R.id.dot ? '.' : ','; int handleDeleted; switch (handleDeletedGroup.getCheckedRadioButtonId()) { case R.id.update_balance: handleDeleted = Account.EXPORT_HANDLE_DELETED_UPDATE_BALANCE; break; case R.id.create_helper: handleDeleted = Account.EXPORT_HANDLE_DELETED_CREATE_HELPER; break; default: // -1 handleDeleted = Account.EXPORT_HANDLE_DELETED_DO_NOTHING; } String encoding = (String) ((Spinner) dlg.findViewById(R.id.Encoding)).getSelectedItem(); SharedPreferencesCompat.apply( MyApplication.getInstance() .getSettings() .edit() .putString(MyApplication.PrefKey.EXPORT_FORMAT.getKey(), format) .putString(PREFKEY_EXPORT_DATE_FORMAT, dateFormat) .putString(PREFKEY_EXPORT_ENCODING, encoding) .putInt(ExportTask.KEY_DECIMAL_SEPARATOR, decimalSeparator) .putInt(ExportTask.KEY_EXPORT_HANDLE_DELETED, handleDeleted)); boolean deleteP = deleteCB.isChecked(); boolean notYetExportedP = notYetExportedCB.isChecked(); String fileName = fileNameET.getText().toString(); Result appDirStatus = Utils.checkAppDir(); if (appDirStatus.success) { Bundle b = new Bundle(); b.putInt(ConfirmationDialogFragment.KEY_COMMAND_POSITIVE, R.id.START_EXPORT_COMMAND); if (accountId == null) { } else if (accountId > 0) { b.putLong(KEY_ROWID, accountId); } else { b.putString(KEY_CURRENCY, currency); } b.putString(TaskExecutionFragment.KEY_FORMAT, format); b.putBoolean(ExportTask.KEY_DELETE_P, deleteP); b.putBoolean(ExportTask.KEY_NOT_YET_EXPORTED_P, notYetExportedP); b.putString(TaskExecutionFragment.KEY_DATE_FORMAT, dateFormat); b.putChar(ExportTask.KEY_DECIMAL_SEPARATOR, decimalSeparator); b.putString(TaskExecutionFragment.KEY_ENCODING, encoding); b.putInt(ExportTask.KEY_EXPORT_HANDLE_DELETED, handleDeleted); b.putString(ExportTask.KEY_FILE_NAME, fileName); if (Utils.checkAppFolderWarning()) { ((ConfirmationDialogListener) getActivity()).onPositive(b); } else { b.putInt(ConfirmationDialogFragment.KEY_TITLE, R.string.dialog_title_attention); b.putString( ConfirmationDialogFragment.KEY_MESSAGE, getString(R.string.warning_app_folder_will_be_deleted_upon_uninstall)); b.putString( ConfirmationDialogFragment.KEY_PREFKEY, MyApplication.PrefKey.APP_FOLDER_WARNING_SHOWN.getKey()); ConfirmationDialogFragment.newInstance(b).show(getFragmentManager(), "APP_FOLDER_WARNING"); } } else { Toast.makeText(ctx, appDirStatus.print(ctx), Toast.LENGTH_LONG).show(); } }