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.timemachine.controller.ControllerActivity.java

private void createConnectDialog() {
    // Load saved IP address
    String serverIP = prefs.getString("serverIP", "");
    // Instantiate an AlertDialog.Builder with its constructor
    AlertDialog.Builder connectDialogBuilder = new AlertDialog.Builder(ControllerActivity.this);
    // Get the layout inflater
    LayoutInflater inflater = ControllerActivity.this.getLayoutInflater();
    // Inflate the custom view
    final View connectDialogLayout = inflater.inflate(R.layout.connect_dialog, null);
    // Get the text box
    final EditText ipTextbox = (EditText) connectDialogLayout.findViewById(R.id.ipAddress);
    // Restore previous IP
    ipTextbox.setText(serverIP);/*from  w ww. ja v a  2  s .com*/
    // Set layout and title
    connectDialogBuilder.setView(connectDialogLayout);
    connectDialogBuilder.setTitle(connectDialogTitle);
    // Prevent the dialog from canceling when users click outside the dialog
    connectDialogBuilder.setCancelable(false);
    // Add actionButtons
    connectDialogBuilder.setPositiveButton(R.string.connect, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            showProcessDialog("Connecting to server...");
            // Get the text written in IP address section
            ipText = ipTextbox.getText().toString();
            // Save IP address
            SharedPreferences.Editor editor = prefs.edit();
            editor.putString("serverIP", ipText);
            editor.commit();
            // Connect Websocket
            setupSocketConnection(ipText);
        }
    });
    buildDisconnectDialog();
    // Create the AlertDialog
    connectDialog = connectDialogBuilder.create();
    connectDialog.setOwnerActivity(ControllerActivity.this);
    connectDialog.show();
}

From source file:com.corporatetaxi.TaxiArrived_Acitivity.java

public void caceldialog() {

    AlertDialog.Builder builder = new AlertDialog.Builder(TaxiArrived_Acitivity.this);

    AppPreferences.setApprequestTaxiScreen(TaxiArrived_Acitivity.this, false);
    LayoutInflater inflater = getLayoutInflater();
    View header = inflater.inflate(R.layout.dialog_heading, null);
    TextView textView = (TextView) header.findViewById(R.id.text);
    ImageView icon = (ImageView) header.findViewById(R.id.icon);
    icon.setImageResource(R.drawable.ic_launcher);
    textView.setText("Taxi Has Arrived");
    builder.setCustomTitle(header);//ww w  .  j av  a  2  s  . c  o m
    builder.setCancelable(false);

    builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {

            dialog.dismiss();
        }
    });

    builder.show();
}

From source file:com.xrmaddness.offthegrid.ListActivity.java

void send_key_dialog(final contact c) {
    AlertDialog.Builder alert = new AlertDialog.Builder(this);

    alert.setTitle(R.string.action_send_key);
    alert.setMessage(R.string.dialog_send_key);
    alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {

            Log.d("resend key", "resend key");
            send_key(c);//from  w  w w. j av  a2 s.c o m
        }
    });
    alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
        }
    });
    alert.setCancelable(true);
    alert.show();
}

From source file:com.fjn.magazinereturncandidate.activities.SdmScannerActivity.java

@Override
protected void onResume() {

    super.onResume();

    //Event click item detail
    lvBook.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override//from  ww  w . j  a v  a 2s  .  com
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            //Disable scan
            registerLicenseCommon.DisableScan(hsmDecoder);

            ProductDetailFragment dProductDetailFragment = new ProductDetailFragment();
            FragmentManager fm = getSupportFragmentManager();
            Bundle bundleItems = new Bundle();
            bundleItems.putString(Constants.COLUMN_JAN_CD, arrBookInlist.get(position)[0]);
            bundleItems.putString(Constants.COLUMN_STOCK_COUNT, arrBookInlist.get(position)[1]);
            bundleItems.putString(Constants.COLUMN_GOODS_NAME, arrBookInlist.get(position)[2]);
            bundleItems.putString(Constants.COLUMN_WRITER_NAME, arrBookInlist.get(position)[3]);
            bundleItems.putString(Constants.COLUMN_PUBLISHER_NAME, arrBookInlist.get(position)[4]);
            bundleItems.putString(Constants.COLUMN_PRICE, arrBookInlist.get(position)[5]);
            bundleItems.putString(Constants.COLUMN_FIRST_SUPPLY_DATE, arrBookInlist.get(position)[6]);
            bundleItems.putString(Constants.COLUMN_LAST_SUPPLY_DATE, arrBookInlist.get(position)[7]);
            bundleItems.putString(Constants.COLUMN_LAST_SALES_DATE, arrBookInlist.get(position)[8]);
            bundleItems.putString(Constants.COLUMN_LAST_ORDER_DATE, arrBookInlist.get(position)[9]);
            bundleItems.putString(Constants.COLUMN_MEDIA_GROUP1_CD, arrBookInlist.get(position)[10]);
            bundleItems.putString(Constants.COLUMN_MEDIA_GROUP1_NAME, arrBookInlist.get(position)[11]);
            bundleItems.putString(Constants.COLUMN_MEDIA_GROUP2_CD, arrBookInlist.get(position)[12]);
            bundleItems.putString(Constants.COLUMN_MEDIA_GROUP2_NAME, arrBookInlist.get(position)[13]);
            bundleItems.putString(Constants.COLUMN_SALES_DATE, arrBookInlist.get(position)[14]);
            bundleItems.putString(Constants.COLUMN_YEAR_RANK, arrBookInlist.get(position)[18]);
            bundleItems.putString(Constants.COLUMN_JOUBI, arrBookInlist.get(position)[19]);
            bundleItems.putString(Constants.COLUMN_TOTAL_SALES, arrBookInlist.get(position)[20]);
            bundleItems.putString(Constants.COLUMN_TOTAL_SUPPLY, arrBookInlist.get(position)[21]);
            bundleItems.putString(Constants.COLUMN_TOTAL_RETURN, arrBookInlist.get(position)[22]);
            bundleItems.putString(Constants.COLUMN_LOCATION_ID, arrBookInlist.get(position)[23]);
            bundleItems.putInt(Constants.COLUMN_MAX_YEAR_RANK, maxYearRank.getMaxYearRank());
            //put position edit
            bundleItems.putInt(Constants.POSITION_EDIT_PRODUCT, position);
            //put flag switch OCR
            bundleItems.putString(Constants.FLAG_SWITCH_OCR, flagSwitchOCR);

            dProductDetailFragment.setArguments(bundleItems);
            dProductDetailFragment.show(fm, null);
        }
    });

    //Event long press item detail
    lvBook.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {

            //Disable scan
            registerLicenseCommon.DisableScan(hsmDecoder);

            AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(SdmScannerActivity.this);
            alertDialogBuilder.setMessage(
                    String.format(Message.MESSAGE_CONFIRM_DELETE_JAN_CD, arrBookInlist.get(position)[0]));

            alertDialogBuilder.setCancelable(false);
            // Configure alert dialog button
            alertDialogBuilder.setPositiveButton(Message.MESSAGE_SELECT_YES,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            //Remove items long press
                            if (arrBookInlist.size() > 0) {
                                LogManagerCommon.i(TAG, String.format(Message.TAG_SCANNER_ACTIVITY_CANCEL,
                                        arrBookInlist.get(position)[0]));
                                arrBookInlist.remove(position);

                                // Set data adapter to list view
                                ListViewScanAdapter adapterBook = new ListViewScanAdapter(
                                        SdmScannerActivity.this, arrBookInlist);
                                lvBook.setAdapter(adapterBook);
                            }
                        }
                    });
            alertDialogBuilder.setNegativeButton(Message.MESSAGE_SELECT_NO,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    });
            AlertDialog alert = alertDialogBuilder.show();
            TextView messageText = (TextView) alert.findViewById(android.R.id.message);
            assert messageText != null;
            messageText.setGravity(Gravity.CENTER);

            //Enable scan
            isEnableScan = true;
            registerLicenseCommon.EnableOCROrJanCode(flagSwitchOCR, hsmDecoder);
            return true;
        }
    });
}

From source file:com.hackensack.umc.activity.DependentDetailsActivity.java

public void showAlert(Context context, String message, String title, final OuterQuetions outerQuetions) {

    //        new android.app.AlertDialog.Builder(context)
    //                .setTitle(title)
    //                .setMessage(message)
    //                .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
    //                    public void onClick(DialogInterface dialog, int which) {
    //                        dialog.dismiss();
    //                        /*Bundle b = new Bundle();
    //                        b.putParcelable(Constant.QUETIONS_DATA, outerQuetions);
    //                        b.putString(Constant.EMAIL_ID, mEmail.getText().toString());
    //                        b.putParcelable(Constant.PATIENT_FOR_EPIC_CALL, cretepationToSendForEpicCall());*/
    ////  w  w  w . j a v a  2s . co m
    //                        Intent intent = new Intent(DependentDetailsActivity.this, QuetionsActivity.class);
    //                        intent.putExtra(Constant.QUETIONS_DATA, outerQuetions);
    //                        if (mInsuranceInfo == null) {
    //                            mInsuranceInfo = new InsuranceInfo();
    //                        }
    //                        intent.putExtra(Constant.INSURANCE_DATA_TO_SEND, new CoverageJsonCreator(mInsuranceInfo.getPlanProvider(), mInsuranceInfo.getMemberNumber(), mInsuranceInfo.getGroupNumber(), mInsuranceInfo.getSubscriberId(), mInsuranceInfo.getReference(), mInsuranceInfo.getSubscriberName(), mInsuranceInfo.getSubscriberDateOfBirth()));
    //                        intent.putExtra(Constant.EMAIL_ID, mEmail.getText().toString());
    //                        intent.putExtra(Constant.PATIENT_FOR_EPIC_CALL, createPationToSendForEpicCall());
    //                        // intent.putExtra("bundle", b);
    //                        startActivity(intent);
    //                    }
    //                })
    //                .setCancelable(false)
    //                .show();

    if (!isFinishing()) {

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setCancelable(false);
        LayoutInflater inflater = getLayoutInflater();
        View dialogView = inflater.inflate(R.layout.dialog_network_offline, null);
        builder.setView(dialogView);

        ((TextView) dialogView.findViewById(R.id.dialog_title)).setText(title);
        ((TextView) dialogView.findViewById(R.id.text_message)).setText(message);

        Button btnDismiss = (Button) dialogView.findViewById(R.id.button_dialog_ok);
        btnDismiss.setOnClickListener(new Button.OnClickListener() {

            @Override
            public void onClick(View v) {
                alert.dismiss();

                Intent intent = new Intent(DependentDetailsActivity.this, QuetionsActivity.class);
                intent.putExtra(Constant.QUETIONS_DATA, outerQuetions);
                if (mInsuranceInfo == null) {
                    mInsuranceInfo = new InsuranceInfo();
                }
                //with nwe json creator.
                intent.putExtra(Constant.INSURANCE_DATA_TO_SEND,
                        new CoverageJsonCreatorNew(mInsuranceInfo.getPlanProvider(),
                                mInsuranceInfo.getMemberNumber(), mInsuranceInfo.getGroupNumber(),
                                mInsuranceInfo.getSubscriberId(), mInsuranceInfo.getReference(),
                                mInsuranceInfo.getSubscriberName(), mInsuranceInfo.getSubscriberDateOfBirth()));
                intent.putExtra(Constant.EMAIL_ID, mEmail.getText().toString());
                intent.putExtra(Constant.PATIENT_FOR_EPIC_CALL, createPationToSendForEpicCall());
                // intent.putExtra("bundle", b);
                startActivity(intent);

            }
        });

        alert = builder.show();
    }

}

From source file:ca.ualberta.cs.cmput301w15t04team04project.MainActivity.java

/**
 * Will be called when user clicked add Location button, it will pop a
 * dialog and let user choose the method of location which go to the
 * osmMainAcitivity//from w  w  w  .  java2  s .  c  o  m
 * 
 * @param v
 *            View passed to the activity to check which button was pressed.
 */
public void goToMapAction(View v) {
    AlertDialog.Builder adb = new AlertDialog.Builder(MainActivity.this);
    if (user.getHomelocation() != null) {
        adb.setMessage("Current Home Location is " + user.getHomelocation().getLatitude()
                + user.getHomelocation().getLongitude() + "\nChoose the HomeLocation Way");

    } else {
        adb.setMessage("Choose the HomeLocation Way");
    }
    adb.setNegativeButton("GPS", new OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
            Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
            homeLocation = location;
            user.setHomelocation(location);
        }
    });

    adb.setPositiveButton("Map", new OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            Intent intent = new Intent(MainActivity.this, osmMainActivity.class);
            startActivity(intent);
        }
    });

    adb.setCancelable(true);
    adb.show();

}

From source file:com.trukr.shipper.fragment.RequestStatus.java

public void cancelJob() {
    pd = new ProgressDialog(mContext, android.app.AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);
    pd.setMessage("Loading...");
    pd.setCancelable(false);/*from w w w. j a v  a 2  s  . co m*/
    pd.show();
    queue = Volley.newRequestQueue(mContext);

    JSONObject object = null;
    try {
        object = new JSONObject();
        object.put("UserType", IConstant.UserType);
        object.put("UserId", userId);
        object.put("AuthToken", authToken);
        object.put("OrderId", orderId);
        System.out.println("usertype---->" + IConstant.UserType);
        System.out.println("UserId---->" + userId);
        System.out.println("AuthToken---->" + authToken);
        System.out.println("OrderId---->" + orderId);

    } catch (JSONException e1) {
        e1.printStackTrace();
    }
    final JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, IConstant.CancelJob, object,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    Log.d("Test", response.toString());
                    GeneralResponseParams responseData = (GeneralResponseParams) TrukrApplication
                            .getFromJSON(response.toString(), GeneralResponseParams.class);
                    StatusCode = responseData.getStatusCode();
                    String Message = responseData.getMessage();
                    closeprogress();
                    if (StatusCode == 97) {
                        TrukrApplication.unauthorisedAlertDialog(mContext, IConstant.alert, Message);
                    } else {
                        cancelAlertDialog(RequestStatus.this, IConstant.alert, Message, StatusCode);
                    }
                }

            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    closeprogress();
                    Log.d("Response: ", error.toString());
                    String json;
                    if (error.networkResponse != null && error.networkResponse.data != null) {
                        try {
                            json = new String(error.networkResponse.data,
                                    HttpHeaderParser.parseCharset(error.networkResponse.headers));
                            Log.e("Error list-->", json);
                            try {
                                //                             Parsing json object response response will be a json object
                                if (json != null) {
                                    JSONObject jsonObject = new JSONObject(json);
                                    String message = jsonObject.getString("message");
                                    Toast.makeText(RequestStatus.this, message, Toast.LENGTH_LONG).show();
                                    AlertDialog.Builder dlgAlert = new AlertDialog.Builder(RequestStatus.this);
                                    dlgAlert.setMessage(message);
                                    dlgAlert.setTitle("Login ");
                                    dlgAlert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface dialog, int which) {
                                            //dismiss the dialog
                                            dialog.dismiss();

                                        }
                                    });
                                    dlgAlert.setCancelable(true);
                                    dlgAlert.create().show();
                                }
                            } catch (JSONException e) {
                                e.printStackTrace();
                                Toast.makeText(RequestStatus.this, "Error: " + e.getMessage(),
                                        Toast.LENGTH_LONG).show();
                            }
                        } catch (UnsupportedEncodingException e) {
                            Log.e("Error 111", e.getMessage());
                        }
                    }
                }
            });
    // volley time out error
    request.setRetryPolicy(new DefaultRetryPolicy(500000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
    queue.add(request);
}

From source file:com.trukr.shipper.fragment.RequestStatus.java

private void driverEnroute() {
    if (queue == null) {
        queue = Volley.newRequestQueue(mContext);
    }/*from w ww.j a v a2 s. c o m*/
    JSONObject object = null;
    try {
        object = new JSONObject();
        object.put("UserType", IConstant.UserType);
        object.put("UserId", userId);
        object.put("AuthToken", authToken);
        object.put("OrderId", orderId);
        System.out.println("usertype---->" + IConstant.UserType);
        System.out.println("UserId---->" + userId);
        System.out.println("AuthToken---->" + authToken);
        System.out.println("OrderId---->" + orderId);
    } catch (JSONException e1) {
        e1.printStackTrace();
    }
    final JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, IConstant.DriverEnroute,
            object, new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    Log.d("Test", response.toString());
                    try {
                        String latitude = response.getString("latitude");
                        String longitude = response.getString("longitude");
                        System.out.println("driver enroute-->" + latitude + "   " + longitude);
                        Double lat = null;
                        Double lon = null;
                        try {
                            lat = Double.parseDouble(latitude);
                            lon = Double.parseDouble(longitude);
                        } catch (NumberFormatException e) {
                            e.printStackTrace();
                        }
                        try {
                            LatLng enroute = new LatLng(lat, lon);
                            map.addMarker(new MarkerOptions().position(enroute)
                                    .icon(BitmapDescriptorFactory.fromResource(R.drawable.trucker)));
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }

            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.d("Response: ", error.toString());
                    String json;
                    if (error.networkResponse != null && error.networkResponse.data != null) {
                        try {
                            json = new String(error.networkResponse.data,
                                    HttpHeaderParser.parseCharset(error.networkResponse.headers));
                            Log.e("Error list-->", json);
                            try {
                                //   Parsing json object response response will be a json object
                                if (json != null) {
                                    JSONObject jsonObject = new JSONObject(json);
                                    String message = jsonObject.getString("message");
                                    Toast.makeText(RequestStatus.this, message, Toast.LENGTH_LONG).show();
                                    AlertDialog.Builder dlgAlert = new AlertDialog.Builder(RequestStatus.this);
                                    dlgAlert.setMessage(message);
                                    dlgAlert.setTitle("Login ");
                                    dlgAlert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface dialog, int which) {
                                            //dismiss the dialog
                                            dialog.dismiss();

                                        }
                                    });
                                    dlgAlert.setCancelable(true);
                                    dlgAlert.create().show();
                                }
                            } catch (JSONException e) {
                                e.printStackTrace();
                                Toast.makeText(RequestStatus.this, "Error: " + e.getMessage(),
                                        Toast.LENGTH_LONG).show();
                            }
                        } catch (UnsupportedEncodingException e) {
                            Log.e("Error 111", e.getMessage());
                        }
                    }
                }
            });
    // volley time out error
    request.setRetryPolicy(new DefaultRetryPolicy(500000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
    queue.add(request);
}

From source file:com.orangelabs.rcs.ri.messaging.chat.group.GroupChatView.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    try {//from   w  w  w.  jav  a 2s  . c o  m
        switch (item.getItemId()) {
        case R.id.menu_insert_smiley:
            AlertDialog alert = Smileys.showSmileyDialog(this, mComposeText, getResources(),
                    getString(R.string.menu_insert_smiley));
            registerDialog(alert);
            break;

        case R.id.menu_participants:
            alert = Utils.showList(this, getString(R.string.menu_participants),
                    getSetOfParticipants(mGroupChat.getParticipants()));
            registerDialog(alert);
            break;

        case R.id.menu_add_participant:
            addParticipants();
            break;

        case R.id.menu_quicktext:
            addQuickText();
            break;

        case R.id.menu_send_file:
            SendGroupFile.startActivity(this, mChatId);
            break;

        case R.id.menu_send_geoloc:
            getGeoLoc();
            break;

        case R.id.menu_showus_map:
            DisplayGeoloc.showContactsOnMap(this, mGroupChat.getParticipants().keySet());
            break;

        case R.id.menu_close_session:
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle(R.string.title_chat_exit);
            builder.setPositiveButton(R.string.label_ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    if (mGroupChat != null) {
                        try {
                            mGroupChat.leave();
                        } catch (RcsServiceException e) {
                            showExceptionThenExit(e);
                        }
                    }
                    GroupChatView.this.finish();
                }
            });
            builder.setNegativeButton(R.string.label_cancel, null);
            builder.setCancelable(true);
            registerDialog(builder.show());
            break;
        }

    } catch (RcsServiceException e) {
        showException(e);
    }
    return true;
}