Example usage for android.app AlertDialog.Builder setCancelable

List of usage examples for android.app AlertDialog.Builder setCancelable

Introduction

In this page you can find the example usage for android.app AlertDialog.Builder setCancelable.

Prototype

public void setCancelable(boolean flag) 

Source Link

Document

Sets whether this dialog is cancelable with the KeyEvent#KEYCODE_BACK BACK key.

Usage

From source file:com.instiwork.RegistrationActivity.java

public void login_User(final String URL) {

    if (pDialogOut != null) {
        pDialogOut.show();//from   w  w w.  ja  v  a  2  s . c o  m
    }

    Logger.showMessage(TAG, "OutSide login_User" + URL);
    JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET, URL, null,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    Logger.showMessage(TAG, "Inside login_User" + URL);
                    Logger.showMessage(TAG, response.toString());
                    Logger.showMessage(TAG, imgPath);

                    ll_image_selection.setEnabled(true);
                    txt_terms_conditions.setEnabled(true);
                    findViewById(R.id.footer).setEnabled(true);
                    findViewById(R.id.help_password).setEnabled(true);
                    findViewById(R.id.help_dob).setEnabled(true);
                    findViewById(R.id.help_license).setEnabled(true);

                    ll_license.setEnabled(true);
                    findViewById(R.id.loginBttn).setEnabled(true);
                    findViewById(R.id.fb_log).setEnabled(true);
                    dateOfBirth.setEnabled(true);
                    ll_image_selection.setClickable(true);
                    txt_terms_conditions.setClickable(true);
                    findViewById(R.id.footer).setClickable(true);
                    findViewById(R.id.help_password).setClickable(true);
                    findViewById(R.id.help_dob).setClickable(true);
                    findViewById(R.id.help_license).setClickable(true);

                    ll_license.setClickable(true);
                    findViewById(R.id.loginBttn).setClickable(true);
                    findViewById(R.id.fb_log).setClickable(true);
                    dateOfBirth.setClickable(true);

                    try {
                        InstiworkApplication.getInstance().setSelectedLicenseArray(null);
                        if (response.getString("status").equalsIgnoreCase("Success")) {

                            SharedPreferences.Editor edit = appSharedPref.edit();
                            edit.putString("USER_ID", response.getJSONObject("details").getString("userid"));
                            try {
                                edit.putString("CURRENCY_ID",
                                        response.getJSONObject("details").getString("currency_id"));
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                            edit.commit();

                            InstiworkApplication.getInstance()
                                    .setUSER_ID(response.getJSONObject("details").getString("userid"));
                            InstiworkApplication.getInstance()
                                    .setUSER_NAME(response.getJSONObject("details").getString("name"));
                            InstiworkApplication.getInstance().setCOMPANY_NAME(
                                    response.getJSONObject("details").getString("companyname"));
                            InstiworkApplication.getInstance()
                                    .setUSER_EMAIL(response.getJSONObject("details").getString("email"));
                            InstiworkApplication.getInstance()
                                    .setMOBILE_NO(response.getJSONObject("details").getString("contact"));
                            try {
                                InstiworkApplication.getInstance().setJOB_SEARCH_RADIUS(
                                        response.getJSONObject("details").getString("distance"));
                                InstiworkApplication.getInstance()
                                        .setUnit_user(response.getJSONObject("details").getString("unit"));
                            } catch (Exception e) {
                                try {
                                    InstiworkApplication.getInstance().setJOB_SEARCH_RADIUS(
                                            response.getJSONObject("details").getString("distance_user"));
                                    InstiworkApplication.getInstance().setUnit_user(
                                            response.getJSONObject("details").getString("unit_user"));
                                } catch (Exception ex) {
                                    ex.printStackTrace();
                                }
                            }

                            try {
                                InstiworkApplication.getInstance().setPush_status(
                                        response.getJSONObject("details").getString("push_status"));
                                InstiworkApplication.getInstance().setEmail_status(
                                        response.getJSONObject("details").getString("email_status"));
                                InstiworkApplication.getInstance().setText_status(
                                        response.getJSONObject("details").getString("text_status"));
                                InstiworkApplication.getInstance().setCountryid(
                                        response.getJSONObject("details").getString("country_id"));
                                InstiworkApplication.getInstance().setCurrency_id(
                                        response.getJSONObject("details").getString("currency_id"));
                                InstiworkApplication.getInstance().setCountry_name(
                                        response.getJSONObject("details").getString("country_name"));
                                InstiworkApplication.getInstance().setCountry_3_code(
                                        response.getJSONObject("details").getString("country_3_code"));
                                InstiworkApplication.getInstance().setCountry_2_code(
                                        response.getJSONObject("details").getString("country_2_code"));
                                InstiworkApplication.getInstance().setCurrency_code(
                                        response.getJSONObject("details").getString("currency_code"));
                                InstiworkApplication.getInstance().setCurrency_name(
                                        response.getJSONObject("details").getString("currency_name"));
                                InstiworkApplication.getInstance().setMember_since(
                                        response.getJSONObject("details").getString("member_since"));

                            } catch (Exception e) {
                                Logger.showMessage(TAG, "Extra Paremeter : " + e.toString());
                            }

                            try {
                                licenseLinkedList = new LinkedList<JSONObject>();
                                if (response.getJSONObject("details").getJSONArray("license").length() > 0) {
                                    for (int i = 0; i < response.getJSONObject("details")
                                            .getJSONArray("license").length(); i++) {
                                        licenseLinkedList.add(response.getJSONObject("details")
                                                .getJSONArray("license").getJSONObject(i));
                                    }
                                    InstiworkApplication.getInstance().setLicenseArray(licenseLinkedList);
                                } else {
                                    InstiworkApplication.getInstance().setLicenseArray(null);
                                }
                            } catch (Exception e) {
                                InstiworkApplication.getInstance().setLicenseArray(null);
                                Logger.showMessage(TAG, "license Exception" + e.toString());
                            }

                            try {
                                Map<String, Object> params = new HashMap<>();
                                params.put("action", "registration");
                                params.put("action_user_id", InstiworkApplication.getInstance().getUSER_ID());
                                params.put("action_user_name",
                                        InstiworkApplication.getInstance().getUSER_NAME());
                                params.put("action_device", "android");
                                AdWordsRemarketingReporter.reportWithConversionId(getApplicationContext(),
                                        getResources().getString(R.string.conversion_id), params);
                            } catch (Exception e) {
                                Logger.showMessage(TAG, "AdWords : " + e.toString());
                            }

                            if (imgPath.equalsIgnoreCase("")) {
                                if (pDialogOut != null) {
                                    pDialogOut.dismiss();
                                }
                                Toast.makeText(RegistrationActivity.this, "Registered successfully",
                                        Toast.LENGTH_SHORT).show();

                                InstiworkApplication.getInstance()
                                        .setUSER_IMG("" + R.drawable.placeholder_circuler);
                                Intent i = new Intent(getApplicationContext(), LandingActivity.class);
                                i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP
                                        | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                                startActivity(i);
                                finish();
                            } else {
                                if (pDialogOut != null) {
                                    pDialogOut.show();
                                }
                                String imgUploadUrl = InstiworkConstants.URL_DOMAIN
                                        + "Signup_ios/add_user_image?user_id="
                                        + response.getJSONObject("details").getString("userid");
                                (new UpdateAccountDetailsWithImage(imgPath, imgUploadUrl))
                                        .executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
                            }
                        } else {
                            pDialogOut.dismiss();

                            try {
                                displayMessage(response.getString("details"));
                            } catch (Exception e) {
                                e.printStackTrace();
                                try {
                                    displayMessage(response.getString("message"));
                                } catch (Exception ee) {
                                    ee.printStackTrace();
                                }
                            }

                            //Toast.makeText(RegistrationActivity.this, response.getString("message"), Toast.LENGTH_SHORT).show();
                            //                                Snackbar.make(findViewById(android.R.id.content), response.getString("details"), Snackbar.LENGTH_LONG)
                            //                                        .setActionTextColor(Color.RED)
                            //                                        .show();
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }, new Response.ErrorListener() {

                @Override
                public void onErrorResponse(VolleyError error) {
                    Logger.showMessage(TAG, "Vollllllllll Error: " + error.getMessage());
                    pDialogOut.hide();

                    ll_image_selection.setEnabled(true);
                    txt_terms_conditions.setEnabled(true);
                    findViewById(R.id.footer).setEnabled(true);
                    findViewById(R.id.help_password).setEnabled(true);
                    findViewById(R.id.help_dob).setEnabled(true);
                    findViewById(R.id.help_license).setEnabled(true);

                    ll_license.setEnabled(true);
                    findViewById(R.id.loginBttn).setEnabled(true);
                    findViewById(R.id.fb_log).setEnabled(true);
                    dateOfBirth.setEnabled(true);
                    ll_image_selection.setClickable(true);
                    txt_terms_conditions.setClickable(true);
                    findViewById(R.id.footer).setClickable(true);
                    findViewById(R.id.help_password).setClickable(true);
                    findViewById(R.id.help_dob).setClickable(true);
                    findViewById(R.id.help_license).setClickable(true);

                    ll_license.setClickable(true);
                    findViewById(R.id.loginBttn).setClickable(true);
                    findViewById(R.id.fb_log).setClickable(true);
                    dateOfBirth.setClickable(true);

                    if (error instanceof NoConnectionError) {
                        android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(
                                RegistrationActivity.this);
                        builder.setTitle("Instiwork");
                        builder.setMessage("You do not have internet connection!");
                        builder.setPositiveButton("retry", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                dialog.dismiss();

                                pDialogOut.show();

                                ll_image_selection.setEnabled(false);
                                txt_terms_conditions.setEnabled(false);
                                findViewById(R.id.footer).setEnabled(false);
                                findViewById(R.id.help_password).setEnabled(false);
                                findViewById(R.id.help_dob).setEnabled(false);
                                findViewById(R.id.help_license).setEnabled(false);

                                ll_license.setEnabled(false);
                                findViewById(R.id.loginBttn).setEnabled(false);
                                findViewById(R.id.fb_log).setEnabled(false);
                                dateOfBirth.setEnabled(false);
                                ll_image_selection.setClickable(false);
                                txt_terms_conditions.setClickable(false);
                                findViewById(R.id.footer).setClickable(false);
                                findViewById(R.id.help_password).setClickable(false);
                                findViewById(R.id.help_dob).setClickable(false);
                                findViewById(R.id.help_license).setClickable(false);

                                ll_license.setClickable(false);
                                findViewById(R.id.loginBttn).setClickable(false);
                                findViewById(R.id.fb_log).setClickable(false);
                                dateOfBirth.setClickable(false);

                                login_User(URL);
                            }
                        });
                        builder.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                dialog.dismiss();
                            }
                        });
                        builder.setCancelable(false);
                        builder.show();
                    } else {
                        String json = null;
                        NetworkResponse response = error.networkResponse;
                        if (response != null && response.data != null) {
                            json = new String(response.data);
                            json = trimMessage(json, "message");
                            if (json != null)
                                //                            displayMessage(json);
                                displayMessage(json + " Error Code : " + response.statusCode);
                        }
                    }
                }
            });
    jsonObjReq.setRetryPolicy(new DefaultRetryPolicy(30000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
    InstiworkApplication.getInstance().addToRequestQueue(jsonObjReq);
}

From source file:com.instiwork.RegistrationActivity.java

public void FB_ChkUser(final String URL, final JSONObject jObject) {

    JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET, URL, null,
            new Response.Listener<JSONObject>() {
                @Override/*from  ww w  . jav a  2s.c  om*/
                public void onResponse(JSONObject response) {
                    Logger.showMessage(TAG, URL);
                    Logger.showMessage(TAG, response.toString());

                    ll_image_selection.setEnabled(true);
                    txt_terms_conditions.setEnabled(true);
                    findViewById(R.id.footer).setEnabled(true);
                    findViewById(R.id.help_password).setEnabled(true);
                    findViewById(R.id.help_dob).setEnabled(true);
                    findViewById(R.id.help_license).setEnabled(true);

                    ll_license.setEnabled(true);
                    findViewById(R.id.loginBttn).setEnabled(true);
                    findViewById(R.id.fb_log).setEnabled(true);
                    dateOfBirth.setEnabled(true);
                    ll_image_selection.setClickable(true);
                    txt_terms_conditions.setClickable(true);
                    findViewById(R.id.footer).setClickable(true);
                    findViewById(R.id.help_password).setClickable(true);
                    findViewById(R.id.help_dob).setClickable(true);
                    findViewById(R.id.help_license).setClickable(true);

                    ll_license.setClickable(true);
                    findViewById(R.id.loginBttn).setClickable(true);
                    findViewById(R.id.fb_log).setClickable(true);
                    dateOfBirth.setClickable(true);

                    try {
                        if (response.getJSONObject("response").getString("status")
                                .equalsIgnoreCase("Success")) {

                            LoginManager.getInstance().logOut();

                            pDialogOut.hide();
                            InstiworkApplication.getInstance()
                                    .setUSER_ID(response.getJSONObject("response").getString("userid"));
                            InstiworkApplication.getInstance()
                                    .setUSER_NAME(response.getJSONObject("response").getString("Company_name"));
                            InstiworkApplication.getInstance()
                                    .setUSER_EMAIL(response.getJSONObject("response").getString("email"));
                            //                                InstiworkApplication.getInstance().setUSER_IMG("https://graph.facebook.com/" + jObject.getString("id") + "/picture?type=large");
                            InstiworkApplication.getInstance()
                                    .setMOBILE_NO(response.getJSONObject("response").getString("email"));
                            InstiworkApplication.getInstance().setUSER_IMG(
                                    (response.getJSONObject("response").getString("profileimage")));

                            try {
                                InstiworkApplication.getInstance().setPush_status(
                                        response.getJSONObject("response").getString("push_status"));
                                InstiworkApplication.getInstance().setEmail_status(
                                        response.getJSONObject("response").getString("email_status"));
                                InstiworkApplication.getInstance().setText_status(
                                        response.getJSONObject("response").getString("text_status"));
                                InstiworkApplication.getInstance().setCountryid(
                                        response.getJSONObject("response").getString("country_id"));
                                InstiworkApplication.getInstance().setCurrency_id(
                                        response.getJSONObject("response").getString("currency_id"));
                                InstiworkApplication.getInstance().setCountry_name(
                                        response.getJSONObject("response").getString("country_name"));
                                InstiworkApplication.getInstance().setCountry_3_code(
                                        response.getJSONObject("response").getString("country_3_code"));
                                InstiworkApplication.getInstance().setCountry_2_code(
                                        response.getJSONObject("response").getString("country_2_code"));
                                InstiworkApplication.getInstance().setCurrency_code(
                                        response.getJSONObject("response").getString("currency_code"));
                                InstiworkApplication.getInstance().setCurrency_name(
                                        response.getJSONObject("response").getString("currency_name"));
                                InstiworkApplication.getInstance().setMember_since(
                                        response.getJSONObject("response").getString("member_since"));

                            } catch (Exception e) {
                                Logger.showMessage(TAG, "Extra Paremeter : " + e.toString());
                            }

                            if (response.getJSONObject("response").getString("contact").equalsIgnoreCase("0")) {
                                InstiworkApplication.getInstance().setMOBILE_NO("");
                            } else {
                                InstiworkApplication.getInstance()
                                        .setMOBILE_NO(response.getJSONObject("response").getString("contact"));
                            }
                            InstiworkApplication.getInstance().setJOB_SEARCH_RADIUS(
                                    response.getJSONObject("response").getString("distance_user"));
                            InstiworkApplication.getInstance()
                                    .setUnit_user(response.getJSONObject("response").getString("unit_user"));
                            try {
                                licenseLinkedList = new LinkedList<JSONObject>();
                                if (response.getJSONObject("response").getJSONArray("license").length() > 0) {
                                    for (int i = 0; i < response.getJSONObject("response")
                                            .getJSONArray("license").length(); i++) {
                                        licenseLinkedList.add(response.getJSONObject("response")
                                                .getJSONArray("license").getJSONObject(i));
                                    }
                                    InstiworkApplication.getInstance().setLicenseArray(licenseLinkedList);
                                } else {
                                    InstiworkApplication.getInstance().setLicenseArray(null);
                                }
                            } catch (Exception e) {
                                InstiworkApplication.getInstance().setLicenseArray(null);
                                Logger.showMessage(TAG, "license Exception" + e.toString());
                            }

                            SharedPreferences.Editor edit = appSharedPref.edit();
                            edit.putString("USER_ID", response.getJSONObject("response").getString("userid"));
                            try {
                                edit.putString("CURRENCY_ID",
                                        response.getJSONObject("response").getString("currency_id"));
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                            edit.commit();

                            try {
                                Map<String, Object> params = new HashMap<>();
                                params.put("action", "facebook_login");
                                params.put("action_user_id", InstiworkApplication.getInstance().getUSER_ID());
                                params.put("action_user_name",
                                        InstiworkApplication.getInstance().getUSER_NAME());
                                AdWordsRemarketingReporter.reportWithConversionId(getApplicationContext(),
                                        getResources().getString(R.string.conversion_id), params);
                                params.put("action_device", "android");
                            } catch (Exception e) {
                                Logger.showMessage(TAG, "AdWords : " + e.toString());
                            }

                            Intent i = new Intent(getApplicationContext(), LandingActivity.class);
                            Toast.makeText(RegistrationActivity.this, "Registered successfully",
                                    Toast.LENGTH_SHORT).show();
                            i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP
                                    | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                            startActivity(i);
                            finish();

                        } else {
                            Toast.makeText(RegistrationActivity.this, "New User Register First.",
                                    Toast.LENGTH_SHORT).show();

                            Intent fbIntent = new Intent(RegistrationActivity.this,
                                    RegistrationFacebookActivity.class);
                            fbIntent.putExtra("FromIntent", "RegistrationActivity");
                            fbIntent.putExtra("FB_ID", "" + jObject.getString("id"));
                            fbIntent.putExtra("FB_ACCESS_TOKEN", "" + fbAccessToken);
                            fbIntent.putExtra("FB_DEVICE_TOKEN", "" + gcmToken);
                            try {
                                fbIntent.putExtra("FB_NAME", "" + jObject.getString("first_name") + " "
                                        + jObject.getString("last_name"));
                            } catch (Exception ee) {
                                fbIntent.putExtra("FB_NAME", "");
                            }
                            try {
                                fbIntent.putExtra("FB_EMAIL", "" + jObject.getString("email"));
                            } catch (Exception ee) {
                                fbIntent.putExtra("FB_EMAIL", "");
                            }
                            try {
                                fbIntent.putExtra("FB_BIRTHDAY", "" + jObject.getString("birthday"));
                            } catch (Exception ee) {
                                fbIntent.putExtra("FB_BIRTHDAY", "");
                            }
                            try {
                                fbIntent.putExtra("FB_GENDER", "" + jObject.getString("gender"));
                            } catch (Exception ee) {
                                fbIntent.putExtra("FB_GENDER", "");
                            }
                            try {
                                fbIntent.putExtra("FB_IMG", "" + "https://graph.facebook.com/"
                                        + jObject.getString("id") + "/picture?type=large");
                            } catch (Exception ee) {
                                fbIntent.putExtra("FB_IMG", "");
                            }
                            startActivity(fbIntent);
                            finish();
                        }

                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }, new Response.ErrorListener() {

                @Override
                public void onErrorResponse(VolleyError error) {
                    Logger.showMessage(TAG, "Error: " + error.getMessage());
                    pDialogOut.hide();

                    ll_image_selection.setEnabled(true);
                    txt_terms_conditions.setEnabled(true);
                    findViewById(R.id.footer).setEnabled(true);
                    findViewById(R.id.help_password).setEnabled(true);
                    findViewById(R.id.help_dob).setEnabled(true);
                    findViewById(R.id.help_license).setEnabled(true);

                    ll_license.setEnabled(true);
                    findViewById(R.id.loginBttn).setEnabled(true);
                    findViewById(R.id.fb_log).setEnabled(true);
                    dateOfBirth.setEnabled(true);
                    ll_image_selection.setClickable(true);
                    txt_terms_conditions.setClickable(true);
                    findViewById(R.id.footer).setClickable(true);
                    findViewById(R.id.help_password).setClickable(true);
                    findViewById(R.id.help_dob).setClickable(true);
                    findViewById(R.id.help_license).setClickable(true);

                    ll_license.setClickable(true);
                    findViewById(R.id.loginBttn).setClickable(true);
                    findViewById(R.id.fb_log).setClickable(true);
                    dateOfBirth.setClickable(true);

                    if (error instanceof NoConnectionError) {
                        android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(
                                RegistrationActivity.this);
                        builder.setTitle("Instiwork");
                        builder.setMessage("You do not have internet connection!");
                        builder.setPositiveButton("retry", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                dialog.dismiss();
                                pDialogOut.show();

                                ll_image_selection.setEnabled(false);
                                txt_terms_conditions.setEnabled(false);
                                findViewById(R.id.footer).setEnabled(false);
                                findViewById(R.id.help_password).setEnabled(false);
                                findViewById(R.id.help_dob).setEnabled(false);
                                findViewById(R.id.help_license).setEnabled(false);

                                ll_license.setEnabled(false);
                                findViewById(R.id.loginBttn).setEnabled(false);
                                findViewById(R.id.fb_log).setEnabled(false);
                                dateOfBirth.setEnabled(false);
                                ll_image_selection.setClickable(false);
                                txt_terms_conditions.setClickable(false);
                                findViewById(R.id.footer).setClickable(false);
                                findViewById(R.id.help_password).setClickable(false);
                                findViewById(R.id.help_dob).setClickable(false);
                                findViewById(R.id.help_license).setClickable(false);

                                ll_license.setClickable(false);
                                findViewById(R.id.loginBttn).setClickable(false);
                                findViewById(R.id.fb_log).setClickable(false);
                                dateOfBirth.setClickable(false);

                                FB_ChkUser(URL, jObject);
                            }
                        });
                        builder.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                dialog.dismiss();
                            }
                        });
                        builder.setCancelable(false);
                        builder.show();
                    } else {
                        try {
                            String json = null;
                            NetworkResponse response = error.networkResponse;
                            if (response != null && response.data != null) {
                                json = new String(response.data);
                                json = trimMessage(json, "message");
                                if (json != null)
                                    //                                displayMessage(json);
                                    displayMessage(json + " Error Code : " + response.statusCode);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }
            });
    jsonObjReq.setRetryPolicy(new DefaultRetryPolicy(10000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
    InstiworkApplication.getInstance().addToRequestQueue(jsonObjReq);
}

From source file:com.owncloud.android.ui.activity.FileDisplayActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    Dialog dialog = null;/* w w  w.j a  v  a  2s  .c  om*/
    AlertDialog.Builder builder;
    switch (id) {
    case DIALOG_SHORT_WAIT: {
        ProgressDialog working_dialog = new ProgressDialog(this);
        working_dialog.setMessage(getResources().getString(R.string.wait_a_moment));
        working_dialog.setIndeterminate(true);
        working_dialog.setCancelable(false);
        dialog = working_dialog;
        break;
    }
    case DIALOG_CHOOSE_UPLOAD_SOURCE: {

        String[] items = null;

        String[] allTheItems = { getString(R.string.actionbar_upload_files),
                getString(R.string.actionbar_upload_from_apps),
                getString(R.string.actionbar_failed_instant_upload) };

        String[] commonItems = { getString(R.string.actionbar_upload_files),
                getString(R.string.actionbar_upload_from_apps) };

        if (InstantUploadActivity.IS_ENABLED)
            items = allTheItems;
        else
            items = commonItems;

        builder = new AlertDialog.Builder(this);
        builder.setTitle(R.string.actionbar_upload);
        builder.setItems(items, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int item) {
                if (item == 0) {
                    // if (!mDualPane) {
                    Intent action = new Intent(FileDisplayActivity.this, UploadFilesActivity.class);
                    action.putExtra(UploadFilesActivity.EXTRA_ACCOUNT, FileDisplayActivity.this.getAccount());
                    startActivityForResult(action, ACTION_SELECT_MULTIPLE_FILES);
                    // } else {
                    // TODO create and handle new fragment
                    // LocalFileListFragment
                    // }
                } else if (item == 1) {
                    Intent action = new Intent(Intent.ACTION_GET_CONTENT);
                    action = action.setType("*/*").addCategory(Intent.CATEGORY_OPENABLE);
                    startActivityForResult(
                            Intent.createChooser(action, getString(R.string.upload_chooser_title)),
                            ACTION_SELECT_CONTENT_FROM_APPS);
                } else if (item == 2 && InstantUploadActivity.IS_ENABLED) {
                    Intent action = new Intent(FileDisplayActivity.this, InstantUploadActivity.class);
                    action.putExtra(FileUploader.KEY_ACCOUNT, FileDisplayActivity.this.getAccount());
                    startActivity(action);
                }
            }
        });
        dialog = builder.create();
        break;
    }
    case DIALOG_SSL_VALIDATOR: {
        dialog = SslValidatorDialog.newInstance(this, mLastSslUntrustedServerResult, this);
        break;
    }
    case DIALOG_CERT_NOT_SAVED: {
        builder = new AlertDialog.Builder(this);
        builder.setMessage(getResources().getString(R.string.ssl_validator_not_saved));
        builder.setCancelable(false);
        builder.setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            };
        });
        dialog = builder.create();
        break;
    }
    default:
        dialog = null;
    }

    return dialog;
}

From source file:com.android.mms.ui.ComposeMessageActivity.java

private void confirmDeleteDialog(OnClickListener listener, boolean locked) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setCancelable(true);
    builder.setMessage(locked ? R.string.confirm_delete_locked_message : R.string.confirm_delete_message);
    builder.setPositiveButton(R.string.delete, listener);
    builder.setNegativeButton(R.string.no, null);
    builder.show();//  www.  jav a 2  s.c  o m
}

From source file:com.android.mms.ui.ComposeMessageActivity.java

private void showSmileyDialog() {
    if (mSmileyDialog == null) {
        int[] icons = SmileyParser.DEFAULT_SMILEY_RES_IDS;
        String[] names = getResources().getStringArray(SmileyParser.DEFAULT_SMILEY_NAMES);
        final String[] texts = getResources().getStringArray(SmileyParser.DEFAULT_SMILEY_TEXTS);

        final int N = names.length;

        List<Map<String, ?>> entries = new ArrayList<Map<String, ?>>();
        for (int i = 0; i < N; i++) {
            // We might have different ASCII for the same icon, skip it if
            // the icon is already added.
            boolean added = false;
            for (int j = 0; j < i; j++) {
                if (icons[i] == icons[j]) {
                    added = true;/*  w  ww . j a  v a2  s .co m*/
                    break;
                }
            }
            if (!added) {
                HashMap<String, Object> entry = new HashMap<String, Object>();

                entry.put("icon", icons[i]);
                entry.put("name", names[i]);
                entry.put("text", texts[i]);

                entries.add(entry);
            }
        }

        final SimpleAdapter a = new SimpleAdapter(this, entries, R.layout.smiley_menu_item,
                new String[] { "icon", "name", "text" },
                new int[] { R.id.smiley_icon, R.id.smiley_name, R.id.smiley_text });
        SimpleAdapter.ViewBinder viewBinder = new SimpleAdapter.ViewBinder() {
            @Override
            public boolean setViewValue(View view, Object data, String textRepresentation) {
                if (view instanceof ImageView) {
                    Drawable img = getResources().getDrawable((Integer) data);
                    ((ImageView) view).setImageDrawable(img);
                    return true;
                }
                return false;
            }
        };
        a.setViewBinder(viewBinder);

        AlertDialog.Builder b = new AlertDialog.Builder(this);

        b.setTitle(getString(R.string.menu_insert_smiley));

        b.setCancelable(true);
        b.setAdapter(a, new DialogInterface.OnClickListener() {
            @Override
            @SuppressWarnings("unchecked")
            public final void onClick(DialogInterface dialog, int which) {
                HashMap<String, Object> item = (HashMap<String, Object>) a.getItem(which);

                String smiley = (String) item.get("text");
                if (mSubjectTextEditor != null && mSubjectTextEditor.hasFocus()) {
                    mSubjectTextEditor.append(smiley);
                } else {
                    mTextEditor.append(smiley);
                }

                dialog.dismiss();
            }
        });

        mSmileyDialog = b.create();
    }

    mSmileyDialog.show();
}

From source file:com.guardtrax.ui.screens.HomeScreen.java

private void showAlert(final String title, final String message, boolean OKOnly) {
    AlertDialog.Builder dialog = new AlertDialog.Builder(HomeScreen.this);
    dialog.setCancelable(false);
    dialog.setTitle(title);/*from   w  w  w .java 2  s .  c  o  m*/
    dialog.setMessage(message);
    dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int place) {
            //if device not registered go straight to scan screen
            if (!Utility.deviceRegistered())
                scan_click(false);

            //if OK entered from updateSync then reboot
            if (restartsyncTimer) {
                Intent restartIntent = getPackageManager().getLaunchIntentForPackage(getPackageName());
                PendingIntent intent = PendingIntent.getActivity(HomeScreen.this, 0, restartIntent,
                        Intent.FLAG_ACTIVITY_CLEAR_TOP);
                AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
                manager.set(AlarmManager.RTC, System.currentTimeMillis() + 500, intent);
                System.exit(2);
            }

            if (taa == 5) {
                taa = 3; //when returning to onResume from signature screen this will execute specific code inside onResume
                signaturefileName = Utility.createSignatureFileName();
                Intent intent = new Intent();
                intent.setClass(HomeScreen.this, SignatureScreen.class);
                intent.putExtra("file_name", Utility.getsharedPreference(HomeScreen.this, "signaturefileName"));
                startActivity(intent);
            }
        }
    });

    if (!OKOnly) {
        dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int place) {
                if (taa == 5) {
                    taa = 3; //tells onResume to execute end shift code
                    onResume();
                }
            }
        });
    }
    dialog.show();
}

From source file:com.metaphyze.hackernewsfrontpage.HackerNewsFrontPageActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_hacker_news_front_page);

    bookFileName = getFilesDir() + File.separator + "bookmarked_posts.js";
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawerList = (ListView) findViewById(R.id.drawer);
    location = (TextView) findViewById(R.id.location);

    webView = (WebView) findViewById(R.id.content_frame);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setDomStorageEnabled(true);
    webView.getSettings().setAppCacheEnabled(true);
    loadingView = findViewById(R.id.loading);
    ProgressBar progressBar = ((ProgressBar) findViewById(R.id.progress_bar));
    progressBar.setIndeterminate(true);/*w w  w  . ja va2s  .com*/
    drawerList.setAdapter(new HackerNewsAdapter(HackerNewsFrontPageActivity.this, R.layout.post_item,
            new ArrayList<HackerNewsPost>(), true));
    getActionBar().setTitle("Hacker News Front Page (Loading Live Stream...)");
    drawerList.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            HackerNewsPost post = (HackerNewsPost) parent.getItemAtPosition(position);

            webView.loadUrl(post.getUrl());
            webView.setWebViewClient(new WebViewClient() {

                @Override
                public void onPageStarted(WebView view, String url, Bitmap favicon) {
                    super.onPageStarted(view, url, favicon);
                    loadingView.setVisibility(View.VISIBLE);
                    location.setText("LOADING......" + url);
                }

                @Override
                public void onPageFinished(WebView view, String url) {
                    super.onPageFinished(view, url);
                    loadingView.setVisibility(View.INVISIBLE);
                    location.setText(url);
                }

                @Override
                public boolean shouldOverrideUrlLoading(WebView view, String url) {
                    view.loadUrl(url);
                    return true;
                }

                @Override
                public void onReceivedError(WebView view, int errorCode, String description,
                        String failingUrl) {
                    loadingView.setVisibility(View.INVISIBLE);
                    location.setText("ERROR LOADING PAGE");
                    view.loadUrl("file:///android_asset/failed_to_load_page.html");
                }

            });
            drawerLayout.closeDrawer(drawerList);
        }
    });

    drawerList.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            final HackerNewsPost clonedPost = ((HackerNewsPost) parent.getItemAtPosition(position)).clone();
            clonedPost.setPostedAgo(new Date().toString());
            AlertDialog.Builder builder = new AlertDialog.Builder(HackerNewsFrontPageActivity.this);
            if (((HackerNewsAdapter) parent.getAdapter()).isLive()) {
                builder.setTitle("Bookmark?");
                builder.setMessage("Do you want to bookmark the post\n" + clonedPost.getTitle());
                builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        try {
                            HackerNewsFrontPageContents contents = readContentsFromBookmarksFile();
                            if (contents == null) {
                                showError("ERROR", "Failed to read bookmark file");
                                dialog.dismiss();
                                return;
                            }

                            if (!contents.addPost(clonedPost)) {
                                showError("Already Exists", "Not added becasue bookmark already exists");
                                dialog.dismiss();
                                return;
                            }

                            if (!saveContentsToBookmarksFile(contents)) {
                                showError("ERROR", "Failed to save bookmark");
                                dialog.dismiss();
                            }

                        } catch (Exception ex) {
                            ex.printStackTrace();
                            showError("ERROR", "Internal error: " + ex);
                        }
                    }
                }).setNegativeButton("No", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
            } else {
                builder.setTitle("Delete?");
                builder.setMessage("Do you want to delete the bookmarked post:\n" + clonedPost.getTitle());
                builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        try {

                            HackerNewsFrontPageContents contents = readContentsFromBookmarksFile();
                            if (contents == null) {
                                showError("ERROR", "Unable to find or generate bookmarks file");
                                dialog.dismiss();
                                return;
                            }

                            if (!contents.removePost(clonedPost)) {
                                showError("Not Removed", "Does not exist? How's that possible?");
                                dialog.dismiss();
                                return;
                            }

                            if (saveContentsToBookmarksFile(contents)) {
                                if (contents.getItems().size() > 0) {
                                    drawerList
                                            .setAdapter(new HackerNewsAdapter(HackerNewsFrontPageActivity.this,
                                                    R.layout.post_item, contents.getItems(), false));
                                } else {
                                    showError("No more bookmarks", "Reverting to live stream");
                                    loadLiveStream();
                                }
                            } else {
                                showError("ERROR", "Failed to save bookmark deletion");
                            }
                            dialog.dismiss();

                        } catch (Exception ex) {
                            ex.printStackTrace();
                            showError("ERROR", "Internal Error: " + ex);
                        }

                    }
                }).setNegativeButton("No", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
            }

            builder.setCancelable(true);
            builder.create().show();

            return false;
        }
    });

    drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.drawable.drawer_icon, 0, 0);
    drawerLayout.setDrawerListener(drawerToggle);

    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    //      actionBar.setHomeButtonEnabled(true);

    requestQueue = Volley.newRequestQueue(this);
    loadLiveStream();

}

From source file:com.example.android.lightcontrol.MainActivity.java

private void light_configure() {
    LayoutInflater inflater = LayoutInflater.from(this);
    final View v = inflater.inflate(R.layout.light_configure, null);
    final AlertDialog.Builder dialog = new AlertDialog.Builder(this);
    helper = new DBHelper(getApplicationContext());
    cursor = helper.select(TABLE_NAME_DALISLAVEADDRESS);
    final EditText change_light_name = (EditText) v.findViewById(R.id.editText3);

    Button change_name = (Button) v.findViewById(R.id.button3);

    final Spinner light_list = (Spinner) v.findViewById(R.id.light_list);

    final SimpleCursorAdapter adapter = new SimpleCursorAdapter(MainActivity.this, R.layout.message, cursor,
            new String[] { "_dali_name" }, new int[] { R.id.message });
    light_list.setAdapter(adapter);/*w ww .  j  a  v a  2s .  c o m*/

    light_list.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {

            cursor.moveToPosition(i);
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {

        }
    });

    change_name.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {

            helper.update(cursor.getInt(0), TABLE_NAME_DALISLAVEADDRESS, FEILD_NAME_DALI,
                    String.valueOf(change_light_name.getText()));
            helper.close();
            cursor.close();
            helper = new DBHelper(getApplicationContext());
            cursor = helper.select(TABLE_NAME_DALISLAVEADDRESS);
            adapter.notifyDataSetChanged();
            final Spinner light_list = (Spinner) v.findViewById(R.id.light_list);
            final SimpleCursorAdapter adapter = new SimpleCursorAdapter(MainActivity.this, R.layout.message,
                    cursor, new String[] { "_dali_name" }, new int[] { R.id.message });
            light_list.setAdapter(adapter);

        }
    });

    dialog.setCancelable(false);
    dialog.setTitle(R.string.about_title);
    dialog.setView(v);
    dialog.setPositiveButton(R.string.ok_label_1, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialoginterface, int i) {
            updatespinner();
            helper.close();
            cursor.close();
        }
    });
    dialog.show();

}

From source file:com.example.android.lightcontrol.MainActivity.java

private void fadetime() {
    LayoutInflater inflater = LayoutInflater.from(this);
    final View v = inflater.inflate(R.layout.fadetime, null);
    final AlertDialog.Builder dialog = new AlertDialog.Builder(this);

    Spinner fade_time = (Spinner) v.findViewById(R.id.fade_time);

    ArrayAdapter<String> fadetimelist;
    final String[] fadetime = { "No Fade Time", "0.7sec", "1sec", "1.4sec", "2sec", "2.8sec", "4sec" };
    fadetimelist = new ArrayAdapter<String>(this, R.layout.my_spinner, fadetime);
    fade_time.setAdapter(fadetimelist);/*from   ww  w.  ja  v  a  2  s .  c o m*/

    fade_time.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            if (fadetime[i].equals("No Fade Time")) {
                GlobalVariable.fade_time = "00";
                GlobalVariable.t = 50;
            }
            if (fadetime[i].equals("0.7sec")) {
                GlobalVariable.fade_time = "01";
                GlobalVariable.t = 700;
            }
            if (fadetime[i].equals("1sec")) {
                GlobalVariable.fade_time = "02";
                GlobalVariable.t = 1000;
            }
            if (fadetime[i].equals("1.4sec")) {
                GlobalVariable.fade_time = "03";
                GlobalVariable.t = 1400;
            }
            if (fadetime[i].equals("2sec")) {
                GlobalVariable.fade_time = "04";
                GlobalVariable.t = 2000;
            }
            if (fadetime[i].equals("2.8sec")) {
                GlobalVariable.fade_time = "05";
                GlobalVariable.t = 2800;
            }
            if (fadetime[i].equals("4sec")) {
                GlobalVariable.fade_time = "06";
                GlobalVariable.t = 4000;
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {

        }
    });

    dialog.setCancelable(false);
    dialog.setTitle(R.string.about_title);
    dialog.setView(v);
    dialog.setPositiveButton(R.string.ok_label_1, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialoginterface, int i) {
            //aa 55 07 01 00 00 00 de 00 xx chk

            String send_mode_1 = GlobalVariable.by1_AA + GlobalVariable.by2_55 + "07" + GlobalVariable.by4_01
                    + "00" + "00" + "00" + "de" + "00" + GlobalVariable.fade_time;

            int checksum = ((Integer.parseInt(GlobalVariable.by1_AA, 16))
                    + (Integer.parseInt(GlobalVariable.by2_55, 16)) + (Integer.parseInt("07", 16))
                    + (Integer.parseInt(GlobalVariable.by4_01, 16)) + (Integer.parseInt("de", 16))
            //     + (Integer.parseInt(GlobalVariable.OnSpinnerItemSelectedOfShort.substring(0, 2), 16))
            //      + (Integer.parseInt(GlobalVariable.OnSpinnerItemSelectedOfShort.substring(2, 4), 16))
                    + (Integer.parseInt(GlobalVariable.fade_time, 16))) % 256;
            if (D)
                Log.e(TAG, "checksum" + checksum);
            String send_group_on1 = send_mode_1 + Integer.toHexString(checksum);
            if (D)
                Log.e(TAG, "send_group_on1" + send_group_on1);
            sendMessage(send_group_on1);
            try {
                Thread.sleep(150);
            } catch (InterruptedException ignored) {
            }
        }
    });
    dialog.show();

}