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.smc.tw.waltz.MainActivity.java

private void showAccessCodeNotMatchDialog() {
    if (DEBUG)//from   w ww  .  j a va  2  s.c o m
        Log.d(TAG, "showAccessCodeNotMatchDialog");

    AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.WaltzDialog);

    builder.setIcon(R.drawable.ic_launcher);
    builder.setTitle(R.string.app_name);
    builder.setMessage(R.string.dialog_access_code_not_match);
    builder.setCancelable(false);
    builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int id) {
        }
    });

    builder.create().show();
}

From source file:com.smc.tw.waltz.MainActivity.java

private void showStartAllowJoinDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.WaltzDialog);

    builder.setIcon(R.drawable.sensor_other);
    builder.setTitle(R.string.sensor_allow_join);
    builder.setMessage(R.string.sensor_start_allow_join);
    builder.setCancelable(false);
    builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
        @Override//from  w w w .j  av  a 2  s .  co m
        public void onClick(DialogInterface dialogInterface, int id) {
        }
    });

    builder.create().show();
}

From source file:com.smc.tw.waltz.MainActivity.java

private void showAccessCodeLengthWrongDialog() {
    if (DEBUG)/*from w w w.  j a va  2  s  .c o  m*/
        Log.d(TAG, "showAccessCodeLengthWrongDialog");

    AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.WaltzDialog);

    builder.setIcon(R.drawable.ic_launcher);
    builder.setTitle(R.string.app_name);
    builder.setMessage(R.string.dialog_access_code_length_wrong);
    builder.setCancelable(false);
    builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int id) {
            showInputAccessCodeDialog(mCurrentDeviceIndex);
        }
    });

    builder.create().show();
}

From source file:com.andrewshu.android.reddit.comments.CommentsListActivity.java

/**
 * Helper function to add links from mVoteTargetThing to the button
 * @param linkButton Button that should open list of links
 *//*ww w.j ava2 s . c  o m*/
private void linkToEmbeddedURLs(Button linkButton) {
    final ArrayList<String> urls = new ArrayList<String>();
    final ArrayList<MarkdownURL> vtUrls = mVoteTargetThing.getUrls();
    int urlsCount = vtUrls.size();
    for (int i = 0; i < urlsCount; i++) {
        urls.add(vtUrls.get(i).url);
    }
    if (urlsCount == 0) {
        linkButton.setEnabled(false);
    } else {
        linkButton.setEnabled(true);
        linkButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                removeDialog(Constants.DIALOG_COMMENT_CLICK);

                ArrayAdapter<MarkdownURL> adapter = new ArrayAdapter<MarkdownURL>(CommentsListActivity.this,
                        android.R.layout.select_dialog_item, vtUrls) {
                    public View getView(int position, View convertView, ViewGroup parent) {
                        TextView tv;
                        if (convertView == null) {
                            tv = (TextView) ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE))
                                    .inflate(android.R.layout.select_dialog_item, null);
                        } else {
                            tv = (TextView) convertView;
                        }

                        String url = getItem(position).url;
                        String anchorText = getItem(position).anchorText;
                        if (Constants.LOGGING)
                            Log.d(TAG, "links url=" + url + " anchorText=" + anchorText);

                        Drawable d = null;
                        try {
                            d = getPackageManager()
                                    .getActivityIcon(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
                        } catch (NameNotFoundException ignore) {
                        }
                        if (d != null) {
                            d.setBounds(0, 0, d.getIntrinsicHeight(), d.getIntrinsicHeight());
                            tv.setCompoundDrawablePadding(10);
                            tv.setCompoundDrawables(d, null, null, null);
                        }

                        final String telPrefix = "tel:";
                        if (url.startsWith(telPrefix)) {
                            url = PhoneNumberUtils.formatNumber(url.substring(telPrefix.length()));
                        }

                        if (anchorText != null)
                            tv.setText(Html.fromHtml(
                                    "<span>" + anchorText + "</span><br /><small>" + url + "</small>"));
                        else
                            tv.setText(Html.fromHtml(url));

                        return tv;
                    }
                };

                AlertDialog.Builder b = new AlertDialog.Builder(
                        new ContextThemeWrapper(CommentsListActivity.this, mSettings.getDialogTheme()));

                DialogInterface.OnClickListener click = new DialogInterface.OnClickListener() {
                    public final void onClick(DialogInterface dialog, int which) {
                        if (which >= 0) {
                            Common.launchBrowser(CommentsListActivity.this, urls.get(which),
                                    Util.createThreadUri(getOpThingInfo()).toString(), false, false,
                                    mSettings.isUseExternalBrowser(), mSettings.isSaveHistory());
                        }
                    }
                };

                b.setTitle(R.string.select_link_title);
                b.setCancelable(true);
                b.setAdapter(adapter, click);

                b.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    public final void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });

                b.show();
            }
        });
    }
}

From source file:com.smc.tw.waltz.MainActivity.java

private void showInitializationFailDialog(String name, String uid, int error) {
    if (DEBUG)// ww w. j ava  2 s . c om
        Log.d(TAG, "showInitializationFailDialog n:" + name + " u:" + uid + " e:" + error);

    String message = getString(R.string.dialog_fail_to_connect) + " " + name;

    switch (error) {
    case TutkErrorCode.TUTK_ERROR_IOTC_NOT_INITIALIZED: {
        message = getString(R.string.tutk_error_not_initialized);
        break;
    }

    case TutkErrorCode.TUTK_ERROR_IOTC_DEVICE_NOT_FOUND: {
        message = String.format(getString(R.string.tutk_error_device_not_found), name);
        break;
    }

    case TutkErrorCode.TUTK_ERROR_IOTC_TIMEOUT:
    case TutkErrorCode.TUTK_ERROR_IOTC_TIMEOUT_DISCONNECT: {
        message = String.format(getString(R.string.tutk_error_connection_timeout), name);
        break;
    }

    case TutkErrorCode.TUTK_ERROR_IOTC_RELAY_FAIL: {
        message = String.format(getString(R.string.tutk_error_relay_fail), name);
        break;
    }

    case TutkErrorCode.TUTK_ERROR_TUNNEL_UID_NO_PERMISSION:
    case TutkErrorCode.TUTK_ERROR_TUNNEL_UID_RELAY_NOT_SUPPORT:
    case TutkErrorCode.TUTK_ERROR_IOTC_NO_PERMISSION:
    case TutkErrorCode.TUTK_ERROR_IOTC_RELAY_NOT_SUPPORT: {
        message = String.format(getString(R.string.tutk_error_relay_not_support), name);
        break;
    }

    case TutkErrorCode.TUTK_ERROR_TUNNEL_AUTH_FAIL: {
        message = String.format(getString(R.string.tutk_error_auth_fail), name);
        break;
    }

    case TutkErrorCode.TUTK_ERROR_TUNNEL_NETWORK_UNREACHABLE:
    case TutkErrorCode.TUTK_ERROR_IOTC_NETWORK_UNREACHABLE: {
        message = getString(R.string.tutk_error_network_unreachable);
        break;
    }

    case TutkErrorCode.TUTK_ERROR_TUNNEL_MAX_CONNECTION_EXCEED:
    case TutkErrorCode.TUTK_ERROR_TUNNEL_MAX_SESSION_EXCEED:
    case TutkErrorCode.TUTK_ERROR_IOTC_MAX_SESSION_EXCEED:
    case TutkErrorCode.TUTK_ERROR_IOTC_MAX_CHANNEL_EXCEED:
    case TutkErrorCode.TUTK_ERROR_IOTC_DEVICE_MAX_SESSION_EXCEED: {
        message = String.format(getString(R.string.tutk_error_max_connection_exceed), name);
        break;
    }

    case TutkErrorCode.TUTK_ERROR_TUNNEL_UID_NOT_LICENSED:
    case TutkErrorCode.TUTK_ERROR_IOTC_UID_NOT_LICENSED: {
        message = String.format(getString(R.string.tutk_error_uid_not_licensed), uid, name);
        break;
    }

    case TutkErrorCode.TUTK_ERROR_IOTC_INVALID_SID:
    case TutkErrorCode.TUTK_ERROR_TUNNEL_INVALID_SID: {
        message = String.format(getString(R.string.tutk_error_sid_invalid), name);
        break;
    }

    case TutkErrorCode.TUTK_ERROR_IOTC_SERVER_NO_RESPONSE:
    case TutkErrorCode.TUTK_ERROR_IOTC_SERVER_HOSTNAME_FAIL: {
        message = getString(R.string.tutk_error_server_unreachable);
        break;
    }

    case TutkErrorCode.TUTK_ERROR_TUNNEL_DISCONNECTED: {
        message = String.format(getString(R.string.tutk_error_disconnected), name);
        break;
    }

    default:
        message = getString(R.string.dialog_fail_to_connect) + " " + name;
        break;
    }

    if (mInitializationFailDialog != null) {
        mInitializationFailDialog.setMessage(message);
        mInitializationFailDialog.show();
    } else {
        AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.WaltzDialog);

        builder.setIcon(R.drawable.ic_launcher);
        builder.setTitle(R.string.dialog_connection_fail);
        builder.setCancelable(false);
        builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int id) {
                showDeviceList();
            }
        });

        builder.setMessage(message);

        builder.create().show();
    }
}

From source file:com.smc.tw.waltz.MainActivity.java

private void showRestoreDeviceDialog(WaltzDevice device) {
    if (DEBUG)//from  w w w .  j  a  v  a  2s .  c o  m
        Log.d(TAG, "showRestoreDeviceDialog d:" + device);

    if (device == null)
        return;

    AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.WaltzDialog);

    builder.setIcon(R.drawable.ic_launcher);
    builder.setTitle(R.string.app_name);
    builder.setMessage(getString(R.string.sure_to_restore) + " (" + device.getName() + ") ?");
    builder.setCancelable(false);
    builder.setPositiveButton(R.string.restore_default, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int id) {
            device.restoreSystemDefault();
        }
    });

    builder.setNeutralButton(R.string.restore_network, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int id) {
            device.restoreSystemKeepNetwork();
        }
    });

    builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int id) {
        }
    });

    builder.create().show();
}

From source file:com.smc.tw.waltz.MainActivity.java

private void showSignOutDialog() {
    if (DEBUG)/*from  w  w w .  ja va2s  .c  o  m*/
        Log.d(TAG, "showSignOutDialog");

    UserManager userManager = MainApplication.getUserManager();

    if (!MainApplication.isUserSignedIn())
        return;

    if (userManager == null)
        return;

    AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.WaltzDialog);

    builder.setIcon(R.drawable.ic_launcher);
    builder.setTitle(R.string.app_name);
    builder.setMessage(getString(R.string.sure_to_sign_out) + " (" + userManager.getUsername() + ") ?");
    builder.setCancelable(false);
    builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int id) {

            for (int i = 0; i < MainApplication.getWaltzDeviceNumber(); i++) {
                WaltzDevice device = MainApplication.getWaltzDevice(i);

                ParsePush.unsubscribeInBackground("WALTZ_" + device.getSerial());
                unsubscribeGcmChannel("WALTZ_" + device.getSerial());
            }

            MainApplication.removeAllWaltzDevices();

            signOut();
            MainApplication.saveDeviceList();
        }
    });

    builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int id) {
        }
    });

    builder.create().show();
}

From source file:com.instiwork.RegistrationActivity.java

public void getTermsUse(final String URL) {
    Logger.showMessage(TAG, "Privacy " + URL);

    JsonObjectRequest jsonReq = new JsonObjectRequest(Request.Method.GET, URL, null,
            new Response.Listener<JSONObject>() {
                @Override//from w ww . ja  va  2  s . co m
                public void onResponse(JSONObject response) {
                    pBarTermsUse.setVisibility(View.GONE);
                    webViewTermsUse.setVisibility(View.VISIBLE);
                    try {
                        if (response.getString("status").equalsIgnoreCase("Success")) {
                            //                                txtTermsUse.setText(Html.fromHtml(response.getString("Terms")));
                            webViewTermsUse.loadDataWithBaseURL(URL, response.getString("Terms"), "text/html",
                                    "UTF-8", null);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        //                            txtTermsUse.setText("");
                    }
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError volleyError) {
                    pBarTermsUse.setVisibility(View.GONE);
                    if (volleyError 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();
                                pBarTermsUse.setVisibility(View.VISIBLE);
                                webViewTermsUse.setVisibility(View.GONE);
                                getTermsUse(URL);
                            }
                        });
                        builder.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                dialog.dismiss();
                            }
                        });
                        builder.setCancelable(false);
                        builder.show();
                    }
                }
            });
    jsonReq.setRetryPolicy(new DefaultRetryPolicy(10000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
    InstiworkApplication.getInstance().addToRequestQueue(jsonReq);
}

From source file:com.smc.tw.waltz.MainActivity.java

private void showDeleteDeviceDialog(final int index) {
    if (DEBUG)/*  w  w  w  . j a v a  2s.com*/
        Log.d(TAG, "showDeleteDeviceDialog i:" + index);

    final WaltzDevice device = MainApplication.getWaltzDevice(index);

    if (MainApplication.isUserSignedIn() && device.isOwnerScope()) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.WaltzDialog);

        builder.setIcon(R.drawable.ic_launcher);
        builder.setTitle(R.string.app_name);
        builder.setMessage(getString(R.string.device_owner) + " (" + device.getName() + ").");
        builder.setCancelable(false);
        builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int id) {
                //               ParsePush.unsubscribeInBackground("WALTZ_" + device.getSerial());
                //               unsubscribeGcmChannel("WALTZ_" + device.getSerial());
            }
        });

        builder.create().show();
    } else {
        AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.WaltzDialog);

        builder.setIcon(R.drawable.ic_launcher);
        builder.setTitle(R.string.app_name);
        builder.setMessage(getString(R.string.sure_to_remove) + " (" + device.getName() + ") ?");
        builder.setCancelable(false);
        builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int id) {
                MainApplication.removeWaltzDevice(index);

                mDeviceListFragment.notifyDataSetChanged();

                onRefreshDevice();

                ParsePush.unsubscribeInBackground("WALTZ_" + device.getSerial());
                unsubscribeGcmChannel("WALTZ_" + device.getSerial());
            }
        });

        builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int id) {
            }
        });

        builder.create().show();
    }
}

From source file:com.mdlive.sav.MDLiveProviderDetails.java

/**
 * Parses JSON response from Cigna Coach request and displays popup displaying the extracted info
 *
 * data structure:/*www.  j a va2  s . com*/
 * "appointment_instructions" : {
 *      "title" : "Schedule an Appointment",
 *      "description" : "To schedule a video coaching appointment, please call:",
 *      "team_name" : "Marriott TakeCare Team",
 *      "toll_free_number" : "1-800-700-1092",
 *      "additional_info" : "Se habla Espaol"
 *  }
 *
 * @param response      HTTP response object
 */
private void handleCignaCoachSuccessResponse(String response) {
    //Fetch Data From the Services
    //Log.e("Response details", "************\n**********"+response.toString());
    JsonParser parser = new JsonParser();
    JsonObject responseObj = null, profileObj = null, providerObj = null, appointment_obj = null;
    String dialog_title = null, dialog_desc = null, dialog_teamname = null, dialog_extrainfo = null,
            phonenumber = null;
    try {
        responseObj = (JsonObject) parser.parse(response.toString());
        profileObj = responseObj.get("doctor_profile").getAsJsonObject();
        providerObj = profileObj.get("provider_details").getAsJsonObject();
        appointment_obj = providerObj.get("appointment_instructions").getAsJsonObject();

        dialog_title = appointment_obj.get("title").getAsString();
        dialog_desc = appointment_obj.get("description").getAsString();
        dialog_teamname = appointment_obj.get("team_name").getAsString();
        phonenumber = appointment_obj.get("toll_free_number").getAsString();
        dialog_extrainfo = appointment_obj.get("additional_info").getAsString();

    } catch (NullPointerException nex) {
        //Log.e("Error details", "************\n" + nex.getMessage());
        /*Toast.makeText(this, R.string.mdl_cignacoach_data_error, Toast.LENGTH_SHORT).show();*/
        Snackbar.make(findViewById(android.R.id.content), getString(R.string.mdl_cignacoach_data_error),
                Snackbar.LENGTH_SHORT).show();
        return;
    }

    final String dialog_phonenumber = phonenumber;

    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(MDLiveProviderDetails.this);
    LayoutInflater inflater = MDLiveProviderDetails.this.getLayoutInflater();
    View dialogView = inflater.inflate(R.layout.cignacoach_popup, null);
    messagesView = dialogView;
    alertDialogBuilder.setView(dialogView);

    // populate the dialog's text fields
    final TextView txt_title = (TextView) dialogView.findViewById(R.id.title);
    txt_title.setText(dialog_title);
    final TextView txt_desc = (TextView) dialogView.findViewById(R.id.desc);
    txt_desc.setText(dialog_desc);
    final TextView txt_team = (TextView) dialogView.findViewById(R.id.team);
    txt_team.setText(dialog_teamname);
    final TextView txt_phone = (TextView) dialogView.findViewById(R.id.phone);
    txt_phone.setText(getString(R.string.mdl_cignacoach_phonenumber, dialog_phonenumber));
    final TextView txt_extra = (TextView) dialogView.findViewById(R.id.extra);
    txt_extra.setText(dialog_extrainfo);

    alertDialogBuilder.setCancelable(true);

    // create alert dialog
    final AlertDialog alertDialog = alertDialogBuilder.create();
    // suppress default background to allow rounded corners to show through
    alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));

    txt_phone.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (ContextCompat.checkSelfPermission(MDLiveProviderDetails.this,
                    Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {

                ActivityCompat.requestPermissions(MDLiveProviderDetails.this,
                        new String[] { android.Manifest.permission.CALL_PHONE },
                        MDLiveProviderDetails.PERMISSION_ACCESS_PHONE);
            } else {
                Intent callIntent = new Intent(Intent.ACTION_CALL);
                callIntent.setData(Uri.parse("tel:" + dialog_phonenumber));
                startActivity(callIntent);
            }
            alertDialog.dismiss();
        }
    });

    // display it
    alertDialog.show();

}