Example usage for android.content DialogInterface cancel

List of usage examples for android.content DialogInterface cancel

Introduction

In this page you can find the example usage for android.content DialogInterface cancel.

Prototype

void cancel();

Source Link

Document

Cancels the dialog, invoking the OnCancelListener .

Usage

From source file:com.njlabs.amrita.aid.gpms.ui.GpmsActivity.java

@Override
public void init(Bundle savedInstanceState) {
    setupLayout(R.layout.activity_gpms_login, Color.parseColor("#009688"));
    rollNoEditText = (EditText) findViewById(R.id.roll_no);
    passwordEditText = (EditText) findViewById(R.id.pwd);

    AlertDialog.Builder builder = new AlertDialog.Builder(baseContext);
    builder.setMessage("Amrita University does not provide an API for accessing GPMS data. "
            + "So, if any changes are made to the GPMS Website, please be patient while I try to catch up.")
            .setCancelable(true).setIcon(R.drawable.ic_action_info_small)
            .setPositiveButton("Got it !", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                    hideSoftKeyboard();// ww  w. j  av  a  2 s . co  m
                    showConnectToAmritaAlert();
                }
            });
    AlertDialog alert = builder.create();
    alert.requestWindowFeature(Window.FEATURE_NO_TITLE);
    alert.show();

    dialog = new ProgressDialog(baseContext);
    dialog.setIndeterminate(true);
    dialog.setCancelable(false);
    dialog.setInverseBackgroundForced(false);
    dialog.setCanceledOnTouchOutside(false);
    dialog.setMessage("Authenticating your credentials ... ");
    preferences = getSharedPreferences("gpms_prefs", Context.MODE_PRIVATE);
    String rollNo = preferences.getString("roll_no", "");
    String encodedPassword = preferences.getString("password", "");
    if (!rollNo.equals("")) {
        rollNoEditText.setText(rollNo);
        studentRollNo = rollNo;
        hideSoftKeyboard();
    } else {
        SharedPreferences aumsPrefs = getSharedPreferences("aums_prefs", Context.MODE_PRIVATE);
        String aumsRollNo = aumsPrefs.getString("RollNo", "");
        if (!aumsRollNo.equals("")) {
            rollNoEditText.setText(aumsRollNo);
            studentRollNo = aumsRollNo;
            hideSoftKeyboard();
        }
    }

    if (!encodedPassword.equals("")) {
        passwordEditText.setText(Security.decrypt(encodedPassword, MainApplication.key));
        hideSoftKeyboard();
    }
}

From source file:com.giovanniterlingen.windesheim.view.Fragments.ScheduleFragment.java

private void alertConnectionProblem() {
    if (!isMenuVisible()) {
        return;//w w  w  .j  av a  2s.com
    }
    ApplicationLoader.runOnUIThread(new Runnable() {
        @Override
        public void run() {
            new AlertDialog.Builder(getActivity())
                    .setTitle(getResources().getString(R.string.alert_connection_title))
                    .setMessage(getResources().getString(R.string.alert_connection_description))
                    .setPositiveButton(getResources().getString(R.string.connect),
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int id) {
                                    new ScheduleFetcher(true, false, true)
                                            .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                                    dialog.cancel();
                                }
                            })
                    .setNegativeButton(getResources().getString(R.string.cancel),
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int id) {
                                    dialog.cancel();
                                }
                            })
                    .show();
        }
    });
}

From source file:com.mediaexplorer.remote.MexRemoteActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);//from   w  w  w  .  j  a  v  a 2 s.  com

    this.setTitle(R.string.app_name);
    dbg = "MexWebremote";

    text_view = (TextView) findViewById(R.id.text);

    web_view = (WebView) findViewById(R.id.link_view);
    web_view.getSettings().setJavaScriptEnabled(true);/*
                                                      /* Future: setOverScrollMode is API level >8
                                                      * web_view.setOverScrollMode (OVER_SCROLL_NEVER);
                                                      */

    web_view.setBackgroundColor(0);

    web_view.setWebViewClient(new WebViewClient() {
        /* for some reason we only get critical errors so an auth error
         * is not handled here which is why there is some crack that test
         * the connection with a special httpclient
         */
        @Override
        public void onReceivedHttpAuthRequest(final WebView view, final HttpAuthHandler handler,
                final String host, final String realm) {
            String[] userpass = new String[2];

            userpass = view.getHttpAuthUsernamePassword(host, realm);

            HttpResponse response = null;
            HttpGet httpget;
            DefaultHttpClient httpclient;
            String target_host;
            int target_port;

            target_host = MexRemoteActivity.this.target_host;
            target_port = MexRemoteActivity.this.target_port;

            /* We may get null from getHttpAuthUsernamePassword which will
             * break the setCredentials so junk used instead to keep
             * it happy.
             */

            Log.d(dbg, "using the set httpauth, testing auth using client");
            try {
                if (userpass == null) {
                    userpass = new String[2];
                    userpass[0] = "none";
                    userpass[1] = "none";
                }
            } catch (Exception e) {
                userpass = new String[2];
                userpass[0] = "none";
                userpass[1] = "none";
            }

            /* Log.d ("debug",
             *  "trying: GET http://"+userpass[0]+":"+userpass[1]+"@"+target_host+":"+target_port+"/");
             */
            /* We're going to test the authentication credentials that we
             * have before using them so that we can act on the response.
             */

            httpclient = new DefaultHttpClient();

            httpget = new HttpGet("http://" + target_host + ":" + target_port + "/");

            httpclient.getCredentialsProvider().setCredentials(new AuthScope(target_host, target_port),
                    new UsernamePasswordCredentials(userpass[0], userpass[1]));

            try {
                response = httpclient.execute(httpget);
            } catch (IOException e) {
                Log.d(dbg, "Problem executing the http get");
                e.printStackTrace();
            }

            Log.d(dbg, "HTTP reponse:" + Integer.toString(response.getStatusLine().getStatusCode()));
            if (response.getStatusLine().getStatusCode() == 401) {
                /* We got Authentication failed (401) so ask user for u/p */

                /* login dialog box */
                final AlertDialog.Builder logindialog;
                final EditText user;
                final EditText pass;

                LinearLayout layout;
                LayoutParams params;

                TextView label_username;
                TextView label_password;

                logindialog = new AlertDialog.Builder(MexRemoteActivity.this);

                logindialog.setTitle("Mex Webremote login");

                user = new EditText(MexRemoteActivity.this);
                pass = new EditText(MexRemoteActivity.this);

                layout = new LinearLayout(MexRemoteActivity.this);

                pass.setTransformationMethod(new PasswordTransformationMethod());

                layout.setOrientation(LinearLayout.VERTICAL);

                params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);

                layout.setLayoutParams(params);
                user.setLayoutParams(params);
                pass.setLayoutParams(params);

                label_username = new TextView(MexRemoteActivity.this);
                label_password = new TextView(MexRemoteActivity.this);

                label_username.setText("Username:");
                label_password.setText("Password:");

                layout.addView(label_username);
                layout.addView(user);
                layout.addView(label_password);
                layout.addView(pass);
                logindialog.setView(layout);

                logindialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        dialog.cancel();
                    }
                });

                logindialog.setPositiveButton("Login", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        String uvalue = user.getText().toString().trim();
                        String pvalue = pass.getText().toString().trim();
                        view.setHttpAuthUsernamePassword(host, realm, uvalue, pvalue);

                        handler.proceed(uvalue, pvalue);
                    }
                });
                logindialog.show();
                /* End login dialog box */
            } else /* We didn't get a 401 */
            {
                handler.proceed(userpass[0], userpass[1]);
            }
        } /* End onReceivedHttpAuthRequest */
    }); /* End Override */

    /* Run mdns to check for service in a "runnable" (async) */
    handler.post(new Runnable() {
        public void run() {
            startMdns();
        }
    });

    dialog = ProgressDialog.show(MexRemoteActivity.this, "", "Searching...", true);

    /* Let's put something in the webview while we're waiting */
    String summary = "<html><head><style>body { background-color: #000000; color: #ffffff; }></style></head><body><p>Searching for the media explorer webservice</p><p>More infomation on <a href=\"http://media-explorer.github.com\" >Media Explorer's home page</a></p></body></html>";
    web_view.loadData(summary, "text/html", "utf-8");

}

From source file:org.webpki.mobile.android.proxy.BaseProxyActivity.java

public void unconditionalAbort(final String message) {
    final BaseProxyActivity instance = this;
    AlertDialog.Builder alert_dialog = new AlertDialog.Builder(this).setMessage(message).setCancelable(false)
            .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    // The user decided that this is not what he/she wants...
                    dialog.cancel();
                    user_aborted = true;
                    abortTearDown();/*from  w w w . jav  a  2  s. c  o  m*/
                    if (abort_url == null) {
                        instance.finish();
                    } else {
                        launchBrowser(abort_url);
                    }
                }
            });
    // Create and show alert dialog
    alert_dialog.create().show();
}

From source file:com.iss.android.wearable.datalayer.MainActivity.java

private void displaySWBatteryWarning() {
    // Display a cancelable warning that the HRM battery is running low.
    AlertDialog.Builder builder = new AlertDialog.Builder(this);

    String warning = "The Smartwatch battery charge is below 75%. Please charge it to ensure it lasts the night.";
    Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    v.vibrate(100);//from   www  .  ja v a  2s.co  m
    builder.setMessage(warning).setTitle(R.string.battery_warning_title).setCancelable(true)
            .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });

    AlertDialog dialog = builder.create();
    dialog.show();
}

From source file:org.webpki.mobile.android.proxy.BaseProxyActivity.java

public void conditionalAbort(final String message) {
    final BaseProxyActivity instance = this;
    AlertDialog.Builder alert_dialog = new AlertDialog.Builder(this).setMessage(getAbortString())
            .setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    // The user decided that this is not what he/she wants...
                    dialog.cancel();
                    user_aborted = true;
                    abortTearDown();//from  w  w w  .j a v  a  2s . co m
                    if (abort_url == null) {
                        instance.finish();
                    } else {
                        launchBrowser(abort_url);
                    }
                }
            });
    alert_dialog.setNegativeButton("No", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            // The user apparently changed his/her mind and wants to continue...
            dialog.cancel();
            if (message != null && progress_display != null) {
                progress_display = null;
                showHeavyWork(message);
            }
        }
    });

    // Create and show alert dialog
    alert_dialog.create().show();
}

From source file:com.photon.phresco.nativeapp.eshop.activity.PhrescoActivity.java

/**
 * Show error message dialog box with OK and Cancel buttons
 *
 * @param errorMessage//from w w w  .  j  ava2 s  .  co m
 * @param cancelFlag
 */
private void showErrorDialog(String errorMessage, boolean cancelFlag) {
    PhrescoLogger.info(TAG + "showErrorDialog : cancelFlag = " + cancelFlag);
    try {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
            }
        })

                .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                }).setMessage(errorMessage).setTitle(R.string.app_name).setCancelable(false);

        @SuppressWarnings("unused")
        AlertDialog alert = builder.show();
    } catch (Exception ex) {
        PhrescoLogger.info(TAG + "showErrorDialog: " + ex.toString());
        PhrescoLogger.warning(ex);
    }
}

From source file:br.com.GUI.avaliacoes.NovaAvaliacao.java

@Override
public void onBackPressed() {

    AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
    alertDialog.setTitle("Ateno");
    alertDialog.setMessage(//from w  w w  .  j  a v a2 s. c  om
            "Voc tem certeza que deseja sair desta avaliao?\n Todos os dados que no foram salvos sero perdidos!");
    alertDialog.setIcon(R.drawable.critical);
    alertDialog.setPositiveButton("Sim", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            editor.clear();
            editor.commit();
            finish();
        }
    });
    alertDialog.setNegativeButton("No", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });

    alertDialog.show();

}

From source file:amhamogus.com.daysoff.fragments.AddEventFragment.java

private boolean validate() {
    // Check event title exists
    if (summary.getText().length() < 1) {
        summary.setError(getResources().getString(R.string.event_form_error_summary));
        return false;
    }/*from  w  ww .j a  v a  2 s.  c  o  m*/

    // Check start time proceeds end time
    if (start == null) {
        start = DateFormater.getDateTime(startTimeLabel.getText().toString(), currentDate, noonOrNight);
    }
    if (end == null) {
        end = DateFormater.getDateTime(endTimeLabel.getText().toString(), currentDate, noonOrNight);
    }
    Date startDate = new Date(start.getValue());
    Date endDate = new Date(end.getValue());

    if (startDate.after(endDate)) {
        AlertDialog.Builder mAlertBuilder = new AlertDialog.Builder(getActivity()).setTitle("Event time error")
                .setMessage("Start times must proceed end times. Pick new time.")
                .setPositiveButton("Okay", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });
        AlertDialog alertDialog = mAlertBuilder.create();
        alertDialog.show();
        return false;
    }

    if ((food.isChecked() || movie.isChecked() || outdoors.isChecked()) == false) {
        AlertDialog.Builder mAlertBuilder = new AlertDialog.Builder(getActivity())
                .setTitle("Select an activity").setMessage("You must select at least 1 activity.")
                .setPositiveButton("Okay", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });
        AlertDialog alertDialog = mAlertBuilder.create();
        alertDialog.show();
        return false;
    }
    return true;
}

From source file:com.iss.android.wearable.datalayer.MainActivity.java

private void displayBatteryWarning(int warned) {
    // Display a cancelable warning that the HRM battery is running low.
    AlertDialog.Builder builder = new AlertDialog.Builder(this);

    String warning = "";
    switch (warned) {
    case 1://from  w  w w  . j a v a  2 s .  c  o  m
        warning = "HRM Battery Level at 15%";
        break;
    case 2:
        warning = "HRM Battery Level at 10%";
        break;
    case 3:
        warning = "HRM Battery Level at 5%";
        break;
    }
    Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    v.vibrate(100);
    builder.setMessage(warning).setTitle(R.string.battery_warning_title).setCancelable(true)
            .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                    dialog.dismiss();
                }
            });

    AlertDialog dialog = builder.create();
    dialog.setCancelable(true);
    dialog.show();
}