Example usage for android.app AlertDialog setCancelable

List of usage examples for android.app AlertDialog setCancelable

Introduction

In this page you can find the example usage for android.app AlertDialog 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.aikidonord.fragments.FragmentDate.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    View view = inflater.inflate(R.layout.fragment_date, null /*container, false*/);

    View rlLoading = view.findViewById(R.id.loadingPanel);
    //View listView = view.getListView();

    if (VerifConnexion.isOnline(this.getActivity())) {
        rlLoading.setVisibility(View.VISIBLE);

        // on va fair l'impasse l dessus vu que je ne suis pas bien sr
        // de la manire dont il faut oprer tant que la vue n'a pas t renvoye.
        //listView.setVisibility(View.GONE);
        this.lancementAsync();
    } else {/*from   ww  w .j  ava2  s .  c  om*/

        AlertDialog alertDialog = new AlertDialog.Builder(this.getActivity()).create();
        alertDialog.setTitle(getResources().getString(R.string.app_name));
        alertDialog.setMessage(getResources().getString(R.string.no_network));
        alertDialog.setIcon(R.drawable.ic_launcher);
        alertDialog.setCancelable(false);
        alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, getResources().getString(R.string.close),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        // if this button is clicked, close
                        // current activity
                        FragmentDate.this.getActivity().finish();
                    }
                });
        alertDialog.show();
    }

    return view;
}

From source file:com.aikidonord.fragments.FragmentLieu.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    View view = inflater.inflate(R.layout.fragment_lieu, null /*container, false*/);

    View rlLoading = view.findViewById(R.id.loadingPanel);
    //View listView = view.getListView();

    if (VerifConnexion.isOnline(this.getActivity())) {
        rlLoading.setVisibility(View.VISIBLE);

        // on va fair l'impasse l dessus vu que je ne suis pas bien sr
        // de la manire dont il faut oprer tant que la vue n'a pas t renvoye.
        //listView.setVisibility(View.GONE);
        this.lancementAsync();
    } else {/*from   ww w .ja  v a 2 s .c om*/

        AlertDialog alertDialog = new AlertDialog.Builder(this.getActivity()).create();
        alertDialog.setTitle(getResources().getString(R.string.app_name));
        alertDialog.setMessage(getResources().getString(R.string.no_network));
        alertDialog.setIcon(R.drawable.ic_launcher);
        alertDialog.setCancelable(false);
        alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, getResources().getString(R.string.close),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        // if this button is clicked, close
                        // current activity
                        FragmentLieu.this.getActivity().finish();
                    }
                });
        alertDialog.show();
    }

    return view;
}

From source file:com.aikidonord.fragments.FragmentType.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    View view = inflater.inflate(R.layout.fragment_type, null /*container, false*/);

    View rlLoading = view.findViewById(R.id.loadingPanel);
    //View listView = view.getListView();

    if (VerifConnexion.isOnline(this.getActivity())) {
        rlLoading.setVisibility(View.VISIBLE);

        // on va fair l'impasse l dessus vu que je ne suis pas bien sr
        // de la manire dont il faut oprer tant que la vue n'a pas t renvoye.
        //listView.setVisibility(View.GONE);
        this.lancementAsync();
    } else {/*from   w  w w .j a  v a2 s.  c o m*/

        AlertDialog alertDialog = new AlertDialog.Builder(this.getActivity()).create();
        alertDialog.setTitle(getResources().getString(R.string.app_name));
        alertDialog.setMessage(getResources().getString(R.string.no_network));
        alertDialog.setIcon(R.drawable.ic_launcher);
        alertDialog.setCancelable(false);
        alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, getResources().getString(R.string.close),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        // if this button is clicked, close
                        // current activity
                        FragmentType.this.getActivity().finish();
                    }
                });
        alertDialog.show();
    }

    return view;
}

From source file:com.hybris.mobile.app.commerce.adapter.CartProductListAdapter.java

/**
 * Display the delete item dialog/*  ww  w  .  java2s.c o m*/
 *
 * @param positionToDelete
 */
private void showDeleteItemDialog(final int positionToDelete) {

    // Creating the dialog
    AlertDialog.Builder builder = new AlertDialog.Builder(
            new ContextThemeWrapper(getContext(), R.style.AlertDialogCustom));
    builder.setMessage(R.string.cart_menu_delete_item_confirmation_title).setPositiveButton(
            R.string.cart_menu_delete_item_remove_button, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    QueryCartEntry queryCartEntry = new QueryCartEntry();
                    queryCartEntry.setEntryNumber(positionToDelete + "");

                    CommerceApplication.getContentServiceHelper()
                            .deleteCartEntry(new ResponseReceiver<CartModification>() {
                                @Override
                                public void onResponse(Response<CartModification> response) {
                                    updateCart();
                                }

                                @Override
                                public void onError(Response<ErrorList> response) {
                                    UIUtils.showError(response, getContext());

                                    // Update the cart
                                    SessionHelper.updateCart(getContext(), mRequestId, false);
                                }
                            }, mRequestId, queryCartEntry, null, false, null, mOnRequestListener);
                }
            }).setNegativeButton(R.string.cancel, null);

    AlertDialog alert = builder.create();

    // The dialog is cancelable by 3 ways: cancel button, click outside the dialog, click on the back button
    alert.setCancelable(true);
    alert.setCanceledOnTouchOutside(true);
    alert.setOnDismissListener(new DialogInterface.OnDismissListener() {

        @Override
        public void onDismiss(DialogInterface dialog) {
            // We revert to the default quantity when we dismiss the dialog
            if (mSelectedQuantity != null) {
                mSelectedQuantity.getEditText().clearFocus();
                mSelectedQuantity.getEditText().setText(mSelectedQuantity.getDefaultValue() + "");
            }
        }
    });

    alert.show();
}

From source file:produvia.com.lights.SmartLightsActivity.java

public void promptLogin(final JSONObject loginService, final JSONObject responseData) {

    runOnUiThread(new Runnable() {
        public void run() {
            try {
                String type = loginService.getString("type");
                //there was a login error. login again
                if (type.equals(WeaverSdk.FIRST_LOGIN_TYPE_NORMAL)) {
                    //prompt for username and password and retry:
                    promptUsernamePassword(loginService, responseData, false, null);

                } else if (type.equals(WeaverSdk.FIRST_LOGIN_TYPE_KEY)) {

                    promptUsernamePassword(loginService, responseData, true,
                            loginService.getString("description"));

                } else if (type.equals(WeaverSdk.FIRST_LOGIN_TYPE_PRESS2LOGIN)) {
                    //prompt for username and password and retry:
                    int countdown = loginService.has("login_timeout") ? loginService.getInt("login_timeout")
                            : 15;//from   w  ww  .j  a v a2  s. c  o m
                    final AlertDialog alertDialog = new AlertDialog.Builder(SmartLightsActivity.this).create();
                    alertDialog.setTitle(loginService.getString("description"));
                    alertDialog.setCancelable(false);
                    alertDialog.setCanceledOnTouchOutside(false);
                    alertDialog.setMessage(loginService.getString("description") + "\n"
                            + "Attempting to login again in " + countdown + " seconds...");
                    alertDialog.show(); //

                    new CountDownTimer(countdown * 1000, 1000) {
                        @Override
                        public void onTick(long millisUntilFinished) {
                            try {
                                alertDialog.setMessage(loginService.getString("description") + "\n"
                                        + "Attempting to login again in " + millisUntilFinished / 1000
                                        + " seconds...");
                            } catch (JSONException e) {

                            }
                        }

                        @Override
                        public void onFinish() {
                            alertDialog.dismiss();
                            new Thread(new Runnable() {
                                public void run() {

                                    try {
                                        JSONArray services = new JSONArray();
                                        services.put(loginService);
                                        responseData.put("services", services);
                                        WeaverSdkApi.servicesSet(SmartLightsActivity.this, responseData);
                                    } catch (JSONException e) {

                                    }
                                }
                            }).start();

                        }
                    }.start();

                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

        }

    });

}

From source file:produvia.com.scanner.DevicesActivity.java

public void promptLogin(final JSONObject loginService, final JSONObject responseData) {

    runOnUiThread(new Runnable() {
        public void run() {
            try {
                String type = loginService.getString("type");
                //there was a login error. login again
                if (type.equals(WeaverSdk.FIRST_LOGIN_TYPE_NORMAL)) {
                    //prompt for username and password and retry:
                    promptUsernamePassword(loginService, responseData, false, null);

                } else if (type.equals(WeaverSdk.FIRST_LOGIN_TYPE_KEY)) {

                    promptUsernamePassword(loginService, responseData, true,
                            loginService.getString("description"));

                } else if (type.equals(WeaverSdk.FIRST_LOGIN_TYPE_PRESS2LOGIN)) {
                    //prompt for username and password and retry:
                    int countdown = loginService.has("login_timeout") ? loginService.getInt("login_timeout")
                            : 15;/*from   ww w.  j a  v  a  2 s. c o m*/
                    final AlertDialog alertDialog = new AlertDialog.Builder(DevicesActivity.this).create();
                    alertDialog.setTitle(loginService.getString("description"));
                    alertDialog.setCancelable(false);
                    alertDialog.setCanceledOnTouchOutside(false);
                    alertDialog.setMessage(loginService.getString("description") + "\n"
                            + "Attempting to login again in " + countdown + " seconds...");
                    alertDialog.show(); //

                    new CountDownTimer(countdown * 1000, 1000) {
                        @Override
                        public void onTick(long millisUntilFinished) {
                            try {
                                alertDialog.setMessage(loginService.getString("description") + "\n"
                                        + "Attempting to login again in " + millisUntilFinished / 1000
                                        + " seconds...");
                            } catch (JSONException e) {

                            }
                        }

                        @Override
                        public void onFinish() {
                            alertDialog.dismiss();
                            new Thread(new Runnable() {
                                public void run() {

                                    try {
                                        JSONArray services = new JSONArray();
                                        services.put(loginService);
                                        responseData.put("services", services);
                                        WeaverSdkApi.servicesSet(DevicesActivity.this, responseData);
                                    } catch (JSONException e) {

                                    }
                                }
                            }).start();

                        }
                    }.start();

                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

        }

    });

}

From source file:ch.fixme.status.Main.java

@Override
protected Dialog onCreateDialog(int id) {
    AlertDialog dialog = null;
    switch (id) {
    case DIALOG_LOADING:
        dialog = new ProgressDialog(this);
        dialog.setCancelable(false);
        dialog.setMessage(getString(R.string.msg_loading));
        dialog.setCancelable(true);/*  w  w w.j  a  v a  2  s  .  c o m*/
        ((ProgressDialog) dialog).setIndeterminate(true);
        break;
    case DIALOG_LIST:
        return createHsDialog();
    }
    return dialog;
}

From source file:org.odk.collect.android.activities.FormChooserList.java

/**
 * Creates a dialog with the given message. Will exit the activity when the user preses "ok" if
 * shouldExit is set to true.//from  w  w w . j  a v  a  2 s  .c  o  m
 */
private void createErrorDialog(String errorMsg, final boolean shouldExit) {

    AlertDialog alertDialog = new AlertDialog.Builder(this).create();
    alertDialog.setIcon(android.R.drawable.ic_dialog_info);
    alertDialog.setMessage(errorMsg);
    DialogInterface.OnClickListener errorListener = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int i) {
            switch (i) {
            case DialogInterface.BUTTON_POSITIVE:
                if (shouldExit) {
                    finish();
                }
                break;
            }
        }
    };
    alertDialog.setCancelable(false);
    alertDialog.setButton(getString(R.string.ok), errorListener);
    alertDialog.show();
}

From source file:com.google.appinventor.components.runtime.FusiontablesControl.java

private void showNoticeAndDie(String message, String title, String buttonText) {
    AlertDialog alertDialog = new AlertDialog.Builder(activity).create();
    alertDialog.setTitle(title);/*from   ww w  . ja v a 2 s.c  o  m*/
    // prevents the user from escaping the dialog by hitting the Back button
    alertDialog.setCancelable(false);
    alertDialog.setMessage(message);
    alertDialog.setButton(buttonText, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            activity.finish();
        }
    });
    alertDialog.show();
}

From source file:com.xperia64.timidityae.FileBrowserFragment.java

public void getDir(String dirPath) {
    currPath = dirPath;//  w  ww  .  j  av  a2 s  .  co m
    fname = new ArrayList<String>();
    path = new ArrayList<String>();
    if (currPath != null) {
        File f = new File(currPath);
        if (f.exists()) {
            File[] files = f.listFiles();
            if (files != null && files.length > 0) {

                Arrays.sort(files, new FileComparator());

                // System.out.println(currPath);
                if (!currPath.matches("[/]+")) {
                    fname.add("../");
                    path.add(f.getParent() + "/");
                    mCallback.needFileBackCallback(true);
                } else {
                    mCallback.needFileBackCallback(false);
                }
                for (int i = 0; i < files.length; i++) {
                    File file = files[i];
                    if ((!file.getName().startsWith(".") && !Globals.showHiddenFiles)
                            || Globals.showHiddenFiles) {
                        if (file.isFile()) {
                            int dotPosition = file.getName().lastIndexOf(".");
                            String extension = "";
                            if (dotPosition != -1) {
                                extension = (file.getName().substring(dotPosition)).toLowerCase(Locale.US);
                                if (extension != null) {

                                    if ((Globals.showVideos ? Globals.musicVideoFiles : Globals.musicFiles)
                                            .contains("*" + extension + "*")) {

                                        path.add(file.getAbsolutePath());
                                        fname.add(file.getName());
                                    }
                                } else if (file.getName().endsWith("/")) {
                                    path.add(file.getAbsolutePath() + "/");
                                    fname.add(file.getName() + "/");
                                }
                            }
                        } else {
                            path.add(file.getAbsolutePath() + "/");
                            fname.add(file.getName() + "/");
                        }
                    }
                }
            } else {
                if (!currPath.matches("[/]+")) {
                    fname.add("../");
                    path.add(f.getParent() + "/");

                }
            }
            ArrayAdapter<String> fileList = new ArrayAdapter<String>(getActivity(), R.layout.row, fname);
            getListView().setFastScrollEnabled(true);
            getListView().setOnItemLongClickListener(new OnItemLongClickListener() {

                @Override
                public boolean onItemLongClick(AdapterView<?> l, View v, final int position, long id) {
                    localfinished = false;
                    if (new File(path.get(position)).isFile() && Globals.isMidi(path.get(position))) {

                        AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());

                        alert.setTitle("Convert to WAV File");
                        alert.setMessage(
                                "Exports the MIDI/MOD file to WAV.\nNative Midi must be disabled in settings.\nWarning: WAV files are large.");
                        InputFilter filter = new InputFilter() {
                            public CharSequence filter(CharSequence source, int start, int end, Spanned dest,
                                    int dstart, int dend) {
                                for (int i = start; i < end; i++) {
                                    String IC = "*/*\n*\r*\t*\0*\f*`*?***\\*<*>*|*\"*:*";
                                    if (IC.contains("*" + source.charAt(i) + "*")) {
                                        return "";
                                    }
                                }
                                return null;
                            }
                        };
                        // Set an EditText view to get user input 
                        final EditText input = new EditText(getActivity());
                        input.setFilters(new InputFilter[] { filter });
                        alert.setView(input);

                        alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                                String value = input.getText().toString();
                                if (!value.toLowerCase(Locale.US).endsWith(".wav"))
                                    value += ".wav";
                                String parent = path.get(position).substring(0,
                                        path.get(position).lastIndexOf('/') + 1);
                                boolean aWrite = true;
                                boolean alreadyExists = new File(parent + value).exists();
                                String needRename = null;
                                String probablyTheRoot = "";
                                String probablyTheDirectory = "";
                                try {
                                    new FileOutputStream(parent + value, true).close();
                                } catch (FileNotFoundException e) {
                                    aWrite = false;
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                                if (!alreadyExists && aWrite)
                                    new File(parent + value).delete();
                                if (aWrite && new File(parent).canWrite()) {
                                    value = parent + value;
                                } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
                                        && Globals.theFold != null) {
                                    // Write the file to getExternalFilesDir, then move it with the Uri
                                    // We need to tell JNIHandler that movement is needed.

                                    String[] tmp = Globals.getDocFilePaths(getActivity(), parent);
                                    probablyTheDirectory = tmp[0];
                                    probablyTheRoot = tmp[1];
                                    if (probablyTheDirectory.length() > 1) {
                                        needRename = parent.substring(
                                                parent.indexOf(probablyTheRoot) + probablyTheRoot.length())
                                                + value;
                                        value = probablyTheDirectory + '/' + value;
                                    } else {
                                        value = Environment.getExternalStorageDirectory().getAbsolutePath()
                                                + '/' + value;
                                    }
                                } else {
                                    value = Environment.getExternalStorageDirectory().getAbsolutePath() + '/'
                                            + value;
                                }
                                final boolean canWrite = aWrite;
                                final String finalval = value;
                                final String needToRename = needRename;
                                final String probRoot = probablyTheRoot;
                                if (new File(finalval).exists()
                                        || (new File(probRoot + needRename).exists() && needToRename != null)) {
                                    AlertDialog dialog2 = new AlertDialog.Builder(getActivity()).create();
                                    dialog2.setTitle("Warning");
                                    dialog2.setMessage("Overwrite WAV file?");
                                    dialog2.setCancelable(false);
                                    dialog2.setButton(DialogInterface.BUTTON_POSITIVE,
                                            getResources().getString(android.R.string.yes),
                                            new DialogInterface.OnClickListener() {
                                                public void onClick(DialogInterface dialog, int buttonId) {
                                                    if (!canWrite
                                                            && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                                                        if (needToRename != null) {
                                                            Globals.tryToDeleteFile(getActivity(),
                                                                    probRoot + needToRename);
                                                            Globals.tryToDeleteFile(getActivity(), finalval);
                                                        } else {
                                                            Globals.tryToDeleteFile(getActivity(), finalval);
                                                        }
                                                    } else {
                                                        new File(finalval).delete();
                                                    }

                                                    saveWavPart2(position, finalval, needToRename);

                                                }

                                            });
                                    dialog2.setButton(DialogInterface.BUTTON_NEGATIVE,
                                            getResources().getString(android.R.string.no),
                                            new DialogInterface.OnClickListener() {
                                                public void onClick(DialogInterface dialog, int buttonId) {

                                                }
                                            });
                                    dialog2.show();
                                } else {
                                    saveWavPart2(position, finalval, needToRename);
                                }

                            }
                        });

                        alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                                // Canceled.
                            }
                        });

                        alert.show();

                        return true;
                    } else {

                    }
                    return false;
                }

            });
            setListAdapter(fileList);
        }
    }
}