List of usage examples for android.app AlertDialog getButton
public Button getButton(int whichButton)
From source file:sysnetlab.android.sdc.test.TestHelper.java
public static Activity stopExperiment(ActivityInstrumentationTestCase2<?> testCase, Activity activity) { Assert.assertTrue("The activity must be a CreateExperimentActivity.", activity instanceof CreateExperimentActivity); Fragment fragment = ((CreateExperimentActivity) activity).getSupportFragmentManager() .findFragmentById(R.id.fragment_container); Assert.assertNotNull("The ExperimentRunFragment should not be null.", fragment); Assert.assertTrue("The fragment should be an ExperimentRunFragment.", fragment instanceof ExperimentRunFragment); Button buttonExperimentDone = (Button) fragment.getView().findViewById(R.id.button_experiment_done); Assert.assertNotNull("The Experiment-Done button shoud not be null.", buttonExperimentDone); TouchUtils.clickView(testCase, buttonExperimentDone); testCase.getInstrumentation().waitForIdleSync(); AlertDialog dialog = ((CreateExperimentActivity) activity).getAlertDialog(); Button positiveButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE); ActivityMonitor monitor = testCase.getInstrumentation() .addMonitor(SensorDataCollectorActivity.class.getName(), null, false); TouchUtils.clickView(testCase, positiveButton); testCase.getInstrumentation().waitForIdleSync(); SensorDataCollectorActivity sensorDataCollectorActivity = (SensorDataCollectorActivity) testCase .getInstrumentation().waitForMonitor(monitor); testCase.getInstrumentation().removeMonitor(monitor); Assert.assertNotNull("SensorDataCollector Activity was not loaded", sensorDataCollectorActivity); return sensorDataCollectorActivity; }
From source file:com.android.talkback.TalkBackKeyboardShortcutPreferencesActivity.java
private static void focusCancelButton(AlertDialog alertDialog) { Button cancelButton = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE); cancelButton.setFocusableInTouchMode(true); cancelButton.requestFocus();/*from w ww . j a va 2 s.c o m*/ }
From source file:com.otaupdater.utils.UserUtils.java
public static void showLoginDialog(final Context ctx, String defUsername, final DialogCallback dlgCallback, final LoginCallback loginCallback) { @SuppressLint("InflateParams") View view = LayoutInflater.from(ctx).inflate(R.layout.login_dialog, null); if (view == null) return;//from www.j a va2 s . c o m final EditText inputUsername = (EditText) view.findViewById(R.id.auth_username); final EditText inputPassword = (EditText) view.findViewById(R.id.auth_password); if (defUsername != null) inputUsername.setText(defUsername); AlertDialog.Builder builder = new AlertDialog.Builder(ctx); builder.setTitle(R.string.alert_login_title); builder.setView(view); builder.setPositiveButton(R.string.login, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { /* set below */ } }); builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); if (loginCallback != null) loginCallback.onCancel(); } }); final AlertDialog dlg = builder.create(); dlg.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { if (dlgCallback != null) dlgCallback.onDialogShown(dlg); Button button = dlg.getButton(DialogInterface.BUTTON_POSITIVE); if (button == null) return; button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final String username = inputUsername.getText().toString(); final String password = inputPassword.getText().toString(); if (username.length() == 0 || password.length() == 0) { Toast.makeText(ctx, R.string.toast_blank_userpass_error, Toast.LENGTH_LONG).show(); return; } dlg.dismiss(); APIUtils.userLogin(ctx, username, password, new APIUtils.ProgressDialogAPICallback(ctx, ctx.getString(R.string.alert_logging_in), dlgCallback) { @Override public void onSuccess(String message, JSONObject respObj) { try { String realUsername = respObj.getString("username"); String hmacKey = respObj.getString("key"); Config.getInstance(ctx).storeLogin(realUsername, hmacKey); if (loginCallback != null) loginCallback.onLoggedIn(realUsername); } catch (JSONException e) { e.printStackTrace(); } } @Override public void onError(String message, JSONObject respObj) { //TODO show some error } }); } }); } }); dlg.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { if (dlgCallback != null) dlgCallback.onDialogClosed(dlg); } }); dlg.show(); }
From source file:Main.java
public static void setEdittextListener(EditText et, final AlertDialog dialog) { et.addTextChangedListener(new TextWatcher() { @Override/*from ww w. j a va2s. co m*/ public void afterTextChanged(Editable s) { } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { if (s.toString().isEmpty()) { //disable "create" button if folder name is not specified dialog.getButton(Dialog.BUTTON_POSITIVE).setEnabled(false); } else { dialog.getButton(Dialog.BUTTON_POSITIVE).setEnabled(true); } } }); }
From source file:im.vector.util.BugReporter.java
/** * Send a bug report either with email or with Vector. *///from w w w. jav a2s .co m public static void sendBugReport() { final Activity currentActivity = VectorApp.getCurrentActivity(); // no current activity so cannot display an alert if (null == currentActivity) { sendBugReport(VectorApp.getInstance().getApplicationContext(), true, true, "", null); return; } final Context appContext = currentActivity.getApplicationContext(); LayoutInflater inflater = currentActivity.getLayoutInflater(); View dialogLayout = inflater.inflate(R.layout.dialog_bug_report, null); final AlertDialog.Builder dialog = new AlertDialog.Builder(currentActivity); dialog.setTitle(R.string.send_bug_report); dialog.setView(dialogLayout); final EditText bugReportText = (EditText) dialogLayout.findViewById(R.id.bug_report_edit_text); final CheckBox includeLogsButton = (CheckBox) dialogLayout .findViewById(R.id.bug_report_button_include_logs); final CheckBox includeCrashLogsButton = (CheckBox) dialogLayout .findViewById(R.id.bug_report_button_include_crash_logs); final ProgressBar progressBar = (ProgressBar) dialogLayout.findViewById(R.id.bug_report_progress_view); final TextView progressTextView = (TextView) dialogLayout.findViewById(R.id.bug_report_progress_text_view); dialog.setPositiveButton(R.string.send, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // will be overridden to avoid dismissing the dialog while displaying the progress } }); dialog.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // will be overridden to avoid dismissing the dialog while displaying the progress } }); // final AlertDialog bugReportDialog = dialog.show(); final Button cancelButton = bugReportDialog.getButton(AlertDialog.BUTTON_NEGATIVE); final Button sendButton = bugReportDialog.getButton(AlertDialog.BUTTON_POSITIVE); if (null != cancelButton) { cancelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // check if there is no upload in progress if (includeLogsButton.isEnabled()) { bugReportDialog.dismiss(); } else { mIsCancelled = true; cancelButton.setEnabled(false); } } }); } if (null != sendButton) { sendButton.setEnabled(false); sendButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // disable the active area while uploading the bug report bugReportText.setEnabled(false); sendButton.setEnabled(false); includeLogsButton.setEnabled(false); includeCrashLogsButton.setEnabled(false); progressTextView.setVisibility(View.VISIBLE); progressTextView.setText(appContext.getString(R.string.send_bug_report_progress, 0 + "")); progressBar.setVisibility(View.VISIBLE); progressBar.setProgress(0); sendBugReport(VectorApp.getInstance(), includeLogsButton.isChecked(), includeCrashLogsButton.isChecked(), bugReportText.getText().toString(), new IMXBugReportListener() { @Override public void onUploadFailed(String reason) { try { if (null != VectorApp.getInstance() && !TextUtils.isEmpty(reason)) { Toast.makeText(VectorApp.getInstance(), VectorApp.getInstance() .getString(R.string.send_bug_report_failed, reason), Toast.LENGTH_LONG).show(); } } catch (Exception e) { Log.e(LOG_TAG, "## onUploadFailed() : failed to display the toast " + e.getMessage()); } try { // restore the dialog if the upload failed bugReportText.setEnabled(true); sendButton.setEnabled(true); includeLogsButton.setEnabled(true); includeCrashLogsButton.setEnabled(true); cancelButton.setEnabled(true); progressTextView.setVisibility(View.GONE); progressBar.setVisibility(View.GONE); } catch (Exception e) { Log.e(LOG_TAG, "## onUploadFailed() : failed to restore the dialog button " + e.getMessage()); try { bugReportDialog.dismiss(); } catch (Exception e2) { Log.e(LOG_TAG, "## onUploadFailed() : failed to dismiss the dialog " + e2.getMessage()); } } mIsCancelled = false; } @Override public void onUploadCancelled() { onUploadFailed(null); } @Override public void onProgress(int progress) { if (progress > 100) { Log.e(LOG_TAG, "## onProgress() : progress > 100"); progress = 100; } else if (progress < 0) { Log.e(LOG_TAG, "## onProgress() : progress < 0"); progress = 0; } progressBar.setProgress(progress); progressTextView.setText( appContext.getString(R.string.send_bug_report_progress, progress + "")); } @Override public void onUploadSucceed() { try { if (null != VectorApp.getInstance()) { Toast.makeText(VectorApp.getInstance(), VectorApp.getInstance().getString( R.string.send_bug_report_sent), Toast.LENGTH_LONG).show(); } } catch (Exception e) { Log.e(LOG_TAG, "## onUploadSucceed() : failed to dismiss the toast " + e.getMessage()); } try { bugReportDialog.dismiss(); } catch (Exception e) { Log.e(LOG_TAG, "## onUploadSucceed() : failed to dismiss the dialog " + e.getMessage()); } } }); } }); } bugReportText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { if (null != sendButton) { sendButton.setEnabled(bugReportText.getText().toString().length() > 10); } } @Override public void afterTextChanged(Editable s) { } }); }
From source file:com.cc.signalinfo.dialogs.ChangelogDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { super.onCreateDialog(savedInstanceState); form = getActivity().getLayoutInflater().inflate(R.layout.warning_dialog, null); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); ((CheckBox) form.findViewById(R.id.dialogNoPrompt)).setOnCheckedChangeListener(this); builder.setTitle(R.string.warningDialogTitle).setView(form).setPositiveButton(android.R.string.ok, this) .setNegativeButton(android.R.string.cancel, null).create(); AlertDialog ad = builder.show(); ad.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(false); return ad;/*from w w w . java 2s . c o m*/ }
From source file:com.example.igorklimov.popularmoviesdemo.fragments.NoInternet.java
@Override public void onStart() { super.onStart(); final AlertDialog d = (AlertDialog) getDialog(); if (d != null) { Button positiveButton = d.getButton(AlertDialog.BUTTON_POSITIVE); positiveButton.setOnClickListener(new View.OnClickListener() { @Override//from ww w . j a va2 s . c om public void onClick(View v) { ConnectivityManager systemService = (ConnectivityManager) getActivity() .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetworkInfo = systemService.getActiveNetworkInfo(); if (activeNetworkInfo != null) { if (getTag().equals("2")) ((DetailFragment) getTargetFragment()).initLoader(); d.dismiss(); } } }); } }
From source file:com.iklimov.alexandria.fragments.NoInternet.java
@Override public void onStart() { super.onStart(); final AlertDialog d = (AlertDialog) getDialog(); if (d != null) { Button positiveButton = d.getButton(AlertDialog.BUTTON_POSITIVE); positiveButton.setOnClickListener(new View.OnClickListener() { @Override/* w ww. j a v a 2s .c o m*/ public void onClick(View v) { ConnectivityManager systemService = (ConnectivityManager) getActivity() .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetworkInfo = systemService.getActiveNetworkInfo(); if (activeNetworkInfo != null && activeNetworkInfo.isConnected()) { if (getTag().equals("1")) { ((SignInActivity) getActivity()).new SyncFavorites().execute(); } d.dismiss(); } } }); } }
From source file:de.persoapp.android.activity.dialog.NfcDeactivatedDialog.java
@SuppressWarnings("ConstantConditions") @Override/* w ww. j a v a 2 s. co m*/ public void onResume() { super.onResume(); if (mNfcManager.getDefaultAdapter().isEnabled()) { dismiss(); mEventBus.post(new InitializeAppFragment.OnAppInitialized(true)); } else { AlertDialog dialog = (AlertDialog) getDialog(); dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(Settings.ACTION_NFC_SETTINGS)); } }); } }
From source file:com.rstar.mobile.thermocouple.ui.LegalDialogFragment.java
@Override public void onStart() { super.onStart(); AlertDialog d = (AlertDialog) getDialog(); if (d != null) { mOkButton = (Button) d.getButton(Dialog.BUTTON_POSITIVE); }/* www . j a v a 2 s.co m*/ }