Example usage for android.app AlertDialog.Builder cancel

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

Introduction

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

Prototype

@Override
public void cancel() 

Source Link

Document

Cancel the dialog.

Usage

From source file:de.baumann.browser.helper.helper_main.java

public static void openFilePicker(final Activity activity, final View view, final String startDir) {

    new ChooserDialog().with(activity).withStartFile(startDir).withChosenListener(new ChooserDialog.Result() {
        @Override/*from  w  w w.  java 2  s  .co m*/
        public void onChoosePath(final File pathFile) {

            final String fileExtension = pathFile.getAbsolutePath()
                    .substring(pathFile.getAbsolutePath().lastIndexOf("."));
            final String fileName = pathFile.getAbsolutePath()
                    .substring(pathFile.getAbsolutePath().lastIndexOf("/") + 1);
            final String fileNameWE = fileName.substring(0, fileName.lastIndexOf("."));

            final CharSequence[] options = { activity.getString(R.string.choose_menu_1),
                    activity.getString(R.string.choose_menu_2), activity.getString(R.string.choose_menu_3),
                    activity.getString(R.string.choose_menu_4) };

            final AlertDialog.Builder dialog = new AlertDialog.Builder(activity);
            dialog.setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {
                    dialog.cancel();
                }
            });
            dialog.setItems(options, new DialogInterface.OnClickListener() {
                @SuppressWarnings("ResultOfMethodCallIgnored")
                @Override
                public void onClick(DialogInterface dialog, int item) {
                    if (options[item].equals(activity.getString(R.string.choose_menu_1))) {

                        String text = (activity.getString(R.string.toast_extension) + ": " + fileExtension);

                        switch (fileExtension) {
                        case ".gif":
                        case ".bmp":
                        case ".tiff":
                        case ".svg":
                        case ".png":
                        case ".jpg":
                        case ".jpeg":
                            helper_main.openFile(activity, pathFile, "image/*", view);
                            break;
                        case ".m3u8":
                        case ".mp3":
                        case ".wma":
                        case ".midi":
                        case ".wav":
                        case ".aac":
                        case ".aif":
                        case ".amp3":
                        case ".weba":
                            helper_main.openFile(activity, pathFile, "audio/*", view);
                            break;
                        case ".mpeg":
                        case ".mp4":
                        case ".ogg":
                        case ".webm":
                        case ".qt":
                        case ".3gp":
                        case ".3g2":
                        case ".avi":
                        case ".f4v":
                        case ".flv":
                        case ".h261":
                        case ".h263":
                        case ".h264":
                        case ".asf":
                        case ".wmv":
                            helper_main.openFile(activity, pathFile, "video/*", view);
                            break;
                        case ".rtx":
                        case ".csv":
                        case ".txt":
                        case ".vcs":
                        case ".vcf":
                        case ".css":
                        case ".ics":
                        case ".conf":
                        case ".config":
                        case ".java":
                            helper_main.openFile(activity, pathFile, "text/*", view);
                            break;
                        case ".html":
                            helper_main.openFile(activity, pathFile, "text/html", view);
                            break;
                        case ".apk":
                            helper_main.openFile(activity, pathFile, "application/vnd.android.package-archive",
                                    view);
                            break;
                        case ".pdf":
                            helper_main.openFile(activity, pathFile, "application/pdf", view);
                            break;
                        case ".doc":
                            helper_main.openFile(activity, pathFile, "application/msword", view);
                            break;
                        case ".xls":
                            helper_main.openFile(activity, pathFile, "application/vnd.ms-excel", view);
                            break;
                        case ".ppt":
                            helper_main.openFile(activity, pathFile, "application/vnd.ms-powerpoint", view);
                            break;
                        case ".docx":
                            helper_main.openFile(activity, pathFile,
                                    "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
                                    view);
                            break;
                        case ".pptx":
                            helper_main.openFile(activity, pathFile,
                                    "application/vnd.openxmlformats-officedocument.presentationml.presentation",
                                    view);
                            break;
                        case ".xlsx":
                            helper_main.openFile(activity, pathFile,
                                    "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", view);
                            break;
                        case ".odt":
                            helper_main.openFile(activity, pathFile, "application/vnd.oasis.opendocument.text",
                                    view);
                            break;
                        case ".ods":
                            helper_main.openFile(activity, pathFile,
                                    "application/vnd.oasis.opendocument.spreadsheet", view);
                            break;
                        case ".odp":
                            helper_main.openFile(activity, pathFile,
                                    "application/vnd.oasis.opendocument.presentation", view);
                            break;
                        case ".zip":
                            helper_main.openFile(activity, pathFile, "application/zip", view);
                            break;
                        case ".rar":
                            helper_main.openFile(activity, pathFile, "application/x-rar-compressed", view);
                            break;
                        case ".epub":
                            helper_main.openFile(activity, pathFile, "application/epub+zip", view);
                            break;
                        case ".cbz":
                            helper_main.openFile(activity, pathFile, "application/x-cbz", view);
                            break;
                        case ".cbr":
                            helper_main.openFile(activity, pathFile, "application/x-cbr", view);
                            break;
                        case ".fb2":
                            helper_main.openFile(activity, pathFile, "application/x-fb2", view);
                            break;
                        case ".rtf":
                            helper_main.openFile(activity, pathFile, "application/rtf", view);
                            break;
                        case ".opml":
                            helper_main.openFile(activity, pathFile, "application/opml", view);
                            break;

                        default:
                            Toast.makeText(activity, text, Toast.LENGTH_SHORT).show();
                            break;
                        }

                        String dir = pathFile.getParentFile().getAbsolutePath();
                        helper_main.openFilePicker(activity, view, dir);
                    }
                    if (options[item].equals(activity.getString(R.string.choose_menu_2))) {

                        if (pathFile.exists()) {
                            Intent sharingIntent = new Intent(Intent.ACTION_SEND);
                            sharingIntent.setType("image/png");
                            sharingIntent.putExtra(Intent.EXTRA_SUBJECT, fileName);
                            sharingIntent.putExtra(Intent.EXTRA_TEXT, fileName);
                            Uri bmpUri = Uri.fromFile(pathFile);
                            sharingIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
                            activity.startActivity(Intent.createChooser(sharingIntent,
                                    (activity.getString(R.string.app_share_file))));
                        }
                        String dir = pathFile.getParentFile().getAbsolutePath();
                        helper_main.openFilePicker(activity, view, dir);
                    }
                    if (options[item].equals(activity.getString(R.string.choose_menu_4))) {
                        final AlertDialog.Builder dialog2 = new AlertDialog.Builder(activity);

                        dialog2.setMessage(activity.getString(R.string.choose_delete));
                        dialog2.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() {

                            public void onClick(DialogInterface dialog, int whichButton) {
                                pathFile.delete();
                                new Handler().postDelayed(new Runnable() {
                                    public void run() {
                                        String dir = pathFile.getParentFile().getAbsolutePath();
                                        helper_main.openFilePicker(activity, view, dir);
                                    }
                                }, 500);
                            }
                        });
                        dialog2.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                            public void onClick(DialogInterface dialog, int whichButton) {
                                dialog.cancel();
                            }
                        });
                        dialog2.setOnCancelListener(new DialogInterface.OnCancelListener() {
                            @Override
                            public void onCancel(DialogInterface dialog) {
                                // dialog dismiss without button press
                                String dir = pathFile.getParentFile().getAbsolutePath();
                                helper_main.openFilePicker(activity, view, dir);
                            }
                        });
                        dialog2.show();
                    }
                    if (options[item].equals(activity.getString(R.string.choose_menu_3))) {

                        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
                        View dialogView = View.inflate(activity, R.layout.dialog_edit_file, null);

                        final EditText edit_title = (EditText) dialogView.findViewById(R.id.pass_title);

                        builder.setView(dialogView);
                        builder.setTitle(R.string.choose_title);
                        builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() {

                            public void onClick(DialogInterface dialog, int whichButton) {

                                String inputTag = edit_title.getText().toString().trim();

                                File dir = pathFile.getParentFile();
                                File to = new File(dir, inputTag + fileExtension);

                                pathFile.renameTo(to);
                                pathFile.delete();

                                new Handler().postDelayed(new Runnable() {
                                    public void run() {
                                        String dir = pathFile.getParentFile().getAbsolutePath();
                                        helper_main.openFilePicker(activity, view, dir);
                                    }
                                }, 500);
                            }
                        });
                        builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                            public void onClick(DialogInterface dialog, int whichButton) {
                                dialog.cancel();
                            }
                        });
                        builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
                            @Override
                            public void onCancel(DialogInterface dialog) {
                                // dialog dismiss without button press
                                String dir = pathFile.getParentFile().getAbsolutePath();
                                helper_main.openFilePicker(activity, view, dir);
                            }
                        });

                        final AlertDialog dialog2 = builder.create();
                        // Display the custom alert dialog on interface
                        dialog2.show();
                        helper_editText.showKeyboard(activity, edit_title, 0, fileNameWE,
                                activity.getString(R.string.choose_hint));
                    }
                }
            });
            dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialog) {
                    // dialog dismiss without button press
                    String dir = pathFile.getParentFile().getAbsolutePath();
                    helper_main.openFilePicker(activity, view, dir);
                }
            });
            dialog.show();
        }
    }).build().show();
}

From source file:file_manager.Activity_files.java

private void setFilesList() {

    deleteDatabase("files_DB_v01.db");

    String folder = sharedPref.getString("folder",
            Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath());

    File f = new File(sharedPref.getString("files_startFolder", folder));
    final File[] files = f.listFiles();

    if (files == null || files.length == 0) {
        Snackbar.make(listView, R.string.toast_files, Snackbar.LENGTH_LONG).show();
    } else {//from w  w w  . j  a  va 2 s. com
        // looping through all items <item>
        for (File file : files) {

            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());

            String file_Name = file.getName();
            String file_Size = getReadableFileSize(file.length());
            String file_date = formatter.format(new Date(file.lastModified()));
            String file_path = file.getAbsolutePath();

            String file_ext;
            if (file.isDirectory()) {
                file_ext = ".";
            } else {
                file_ext = file.getAbsolutePath().substring(file.getAbsolutePath().lastIndexOf("."));
            }

            db.open();

            if (file_ext.equals(".") || file_ext.equals(".pdf") || file_ext.equals(".")
                    || file_ext.equals(".jpg") || file_ext.equals(".JPG") || file_ext.equals(".jpeg")
                    || file_ext.equals(".png")) {
                if (db.isExist(file_Name)) {
                    Log.i(TAG, "Entry exists" + file_Name);
                } else {
                    db.insert(file_Name, file_Size, file_ext, file_path, file_date);
                }
            }
        }
    }

    try {
        db.insert("...", "", "", "", "");
    } catch (Exception e) {
        Snackbar.make(listView, R.string.toast_directory, Snackbar.LENGTH_LONG).show();
    }

    //display data
    final int layoutstyle = R.layout.list_item;
    int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.textView_create_notes };
    String[] column = new String[] { "files_title", "files_content", "files_creation" };
    final Cursor row = db.fetchAllData(this);
    adapter = new SimpleCursorAdapter(this, layoutstyle, row, column, xml_id, 0) {
        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {

            Cursor row2 = (Cursor) listView.getItemAtPosition(position);
            final String files_icon = row2.getString(row2.getColumnIndexOrThrow("files_icon"));
            final String files_attachment = row2.getString(row2.getColumnIndexOrThrow("files_attachment"));
            final String files_title = row2.getString(row2.getColumnIndexOrThrow("files_title"));

            final File pathFile = new File(files_attachment);

            View v = super.getView(position, convertView, parent);
            final ImageView iv = (ImageView) v.findViewById(R.id.icon_notes);

            iv.setVisibility(View.VISIBLE);

            if (pathFile.isDirectory()) {
                iv.setImageResource(R.drawable.folder);
            } else {
                switch (files_icon) {
                case ".gif":
                case ".bmp":
                case ".tiff":
                case ".svg":
                case ".png":
                case ".jpg":
                case ".JPG":
                case ".jpeg":
                    try {
                        Uri uri = Uri.fromFile(pathFile);
                        Picasso.with(Activity_files.this).load(uri).resize(76, 76).centerCrop().into(iv);
                    } catch (Exception e) {
                        Log.w("HHS_Moodle", "Error Load image", e);
                    }
                    break;
                case ".pdf":
                    iv.setImageResource(R.drawable.file_pdf);
                    break;
                default:
                    iv.setImageResource(R.drawable.arrow_up_dark);
                    break;
                }
            }

            if (files_title.equals("...")) {
                new Handler().postDelayed(new Runnable() {
                    public void run() {
                        iv.setImageResource(R.drawable.arrow_up_dark);
                    }
                }, 200);
            }
            return v;
        }
    };

    //display data by filter
    final String note_search = sharedPref.getString("filter_filesBY", "files_title");
    sharedPref.edit().putString("filter_filesBY", "files_title").apply();
    filter.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable s) {
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
            adapter.getFilter().filter(s.toString());
        }
    });
    adapter.setFilterQueryProvider(new FilterQueryProvider() {
        public Cursor runQuery(CharSequence constraint) {
            return db.fetchDataByFilter(constraint.toString(), note_search);
        }
    });

    listView.setAdapter(adapter);
    //onClick function
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterview, View view, int position, long id) {

            Cursor row2 = (Cursor) listView.getItemAtPosition(position);
            final String files_icon = row2.getString(row2.getColumnIndexOrThrow("files_icon"));
            final String files_attachment = row2.getString(row2.getColumnIndexOrThrow("files_attachment"));

            final File pathFile = new File(files_attachment);

            if (pathFile.isDirectory()) {
                try {
                    sharedPref.edit().putString("files_startFolder", files_attachment).apply();
                    setFilesList();
                } catch (Exception e) {
                    Snackbar.make(listView, R.string.toast_directory, Snackbar.LENGTH_LONG).show();
                }
            } else if (files_attachment.equals("")) {
                try {
                    final File pathActual = new File(sharedPref.getString("files_startFolder",
                            Environment.getExternalStorageDirectory().getPath()));
                    sharedPref.edit().putString("files_startFolder", pathActual.getParent()).apply();
                    setFilesList();
                } catch (Exception e) {
                    Snackbar.make(listView, R.string.toast_directory, Snackbar.LENGTH_LONG).show();
                }
            } else if (files_icon.equals(".pdf")) {
                Uri uri = Uri.fromFile(pathFile);
                Intent intent = new Intent(Activity_files.this, MuPDFActivity.class);
                intent.setAction(Intent.ACTION_VIEW);
                intent.setData(uri);
                startActivity(intent);
            } else {
                helper_main.open(files_icon, Activity_files.this, pathFile, listView);
            }
        }
    });

    listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {

            Cursor row2 = (Cursor) listView.getItemAtPosition(position);
            final String files_title = row2.getString(row2.getColumnIndexOrThrow("files_title"));
            final String files_attachment = row2.getString(row2.getColumnIndexOrThrow("files_attachment"));

            final File pathFile = new File(files_attachment);

            if (pathFile.isDirectory()) {
                Snackbar snackbar = Snackbar
                        .make(listView, R.string.toast_remove_confirmation, Snackbar.LENGTH_LONG)
                        .setAction(R.string.toast_yes, new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                deleteRecursive(pathFile);
                                setFilesList();
                            }
                        });
                snackbar.show();

            } else {
                final CharSequence[] options = { getString(R.string.choose_menu_2),
                        getString(R.string.choose_menu_3), getString(R.string.choose_menu_4) };

                final AlertDialog.Builder dialog = new AlertDialog.Builder(Activity_files.this);
                dialog.setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int whichButton) {
                        dialog.cancel();
                    }
                });
                dialog.setItems(options, new DialogInterface.OnClickListener() {
                    @SuppressWarnings("ResultOfMethodCallIgnored")
                    @Override
                    public void onClick(DialogInterface dialog, int item) {

                        if (options[item].equals(getString(R.string.choose_menu_2))) {

                            if (pathFile.exists()) {
                                Intent sharingIntent = new Intent(Intent.ACTION_SEND);
                                sharingIntent.setType("image/png");
                                sharingIntent.putExtra(Intent.EXTRA_SUBJECT, files_title);
                                sharingIntent.putExtra(Intent.EXTRA_TEXT, files_title);
                                Uri bmpUri = Uri.fromFile(pathFile);
                                sharingIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
                                startActivity(Intent.createChooser(sharingIntent,
                                        (getString(R.string.app_share_file))));
                            }
                        }
                        if (options[item].equals(getString(R.string.choose_menu_4))) {

                            Snackbar snackbar = Snackbar
                                    .make(listView, R.string.toast_remove_confirmation, Snackbar.LENGTH_LONG)
                                    .setAction(R.string.toast_yes, new View.OnClickListener() {
                                        @Override
                                        public void onClick(View view) {
                                            pathFile.delete();
                                            setFilesList();
                                        }
                                    });
                            snackbar.show();
                        }
                        if (options[item].equals(getString(R.string.choose_menu_3))) {
                            AlertDialog.Builder builder = new AlertDialog.Builder(Activity_files.this);
                            View dialogView = View.inflate(Activity_files.this, R.layout.dialog_edit_file,
                                    null);

                            final EditText edit_title = (EditText) dialogView.findViewById(R.id.pass_title);
                            edit_title.setText(files_title);

                            builder.setView(dialogView);
                            builder.setTitle(R.string.choose_title);
                            builder.setPositiveButton(R.string.toast_yes,
                                    new DialogInterface.OnClickListener() {

                                        public void onClick(DialogInterface dialog, int whichButton) {

                                            String inputTag = edit_title.getText().toString().trim();

                                            File dir = pathFile.getParentFile();
                                            File to = new File(dir, inputTag);

                                            pathFile.renameTo(to);
                                            pathFile.delete();
                                            setFilesList();
                                        }
                                    });
                            builder.setNegativeButton(R.string.toast_cancel,
                                    new DialogInterface.OnClickListener() {

                                        public void onClick(DialogInterface dialog, int whichButton) {
                                            dialog.cancel();
                                        }
                                    });
                            AlertDialog dialog2 = builder.create();
                            // Display the custom alert dialog on interface
                            dialog2.show();
                            helper_main.showKeyboard(Activity_files.this, edit_title);
                        }
                    }
                });
                dialog.show();
            }

            return true;
        }
    });
}

From source file:tcc.iesgo.activity.ClientMapActivity.java

@Override
public void onProviderDisabled(String arg0) {
    final AlertDialog.Builder dialog = new AlertDialog.Builder(getParent());
    dialog.setTitle(getString(R.string.gps_disabled));
    dialog.setMessage(getString(R.string.gps_disabled_message));
    dialog.setIcon(R.drawable.gps_enable);
    dialog.setCancelable(false);/*w  w w  .j  av a2 s .  c  o m*/

    dialog.setPositiveButton(getString(R.string.ad_button_positive), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            Intent intent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            startActivity(intent);
        }
    });

    dialog.setNegativeButton(getString(R.string.ad_button_negative), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
            finish();
        }
    });
    dialog.show();
}

From source file:de.baumann.hhsmoodle.data_files.Files_Fragment.java

public void setFilesList() {

    getActivity().deleteDatabase("files_DB_v01.db");

    File f = new File(sharedPref.getString("files_startFolder",
            Environment.getExternalStorageDirectory().getPath() + "/HHS_Moodle/"));
    final File[] files = f.listFiles();

    // looping through all items <item>
    if (files.length == 0) {
        Snackbar.make(lv, R.string.toast_files, Snackbar.LENGTH_LONG).show();
    }/*from ww  w . j  av a 2  s . co  m*/

    for (File file : files) {

        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());

        String file_Name = file.getName();
        String file_Size = getReadableFileSize(file.length());
        String file_date = formatter.format(new Date(file.lastModified()));
        String file_path = file.getAbsolutePath();

        String file_ext;
        if (file.isDirectory()) {
            file_ext = ".";
        } else {
            file_ext = file.getAbsolutePath().substring(file.getAbsolutePath().lastIndexOf("."));
        }

        db.open();
        if (db.isExist(file_Name)) {
            Log.i(TAG, "Entry exists" + file_Name);
        } else {
            db.insert(file_Name, file_Size, file_ext, file_path, file_date);
        }
    }

    try {
        db.insert("...", "", "", "", "");
    } catch (Exception e) {
        Snackbar.make(lv, R.string.toast_directory, Snackbar.LENGTH_LONG).show();
    }

    //display data
    final int layoutstyle = R.layout.list_item_notes;
    int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.textView_create_notes };
    String[] column = new String[] { "files_title", "files_content", "files_creation" };
    final Cursor row = db.fetchAllData(getActivity());
    adapter = new SimpleCursorAdapter(getActivity(), layoutstyle, row, column, xml_id, 0) {
        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String files_icon = row2.getString(row2.getColumnIndexOrThrow("files_icon"));
            final String files_attachment = row2.getString(row2.getColumnIndexOrThrow("files_attachment"));
            final File pathFile = new File(files_attachment);

            View v = super.getView(position, convertView, parent);
            final ImageView iv = (ImageView) v.findViewById(R.id.icon_notes);

            iv.setVisibility(View.VISIBLE);

            if (pathFile.isDirectory()) {
                iv.setImageResource(R.drawable.folder);
            } else {
                switch (files_icon) {
                case "":
                    new Handler().postDelayed(new Runnable() {
                        public void run() {
                            iv.setImageResource(R.drawable.arrow_up);
                        }
                    }, 200);
                    break;
                case ".gif":
                case ".bmp":
                case ".tiff":
                case ".svg":
                case ".png":
                case ".jpg":
                case ".JPG":
                case ".jpeg":
                    try {
                        Glide.with(getActivity()).load(files_attachment) // or URI/path
                                .override(76, 76).centerCrop().into(iv); //imageView to set thumbnail to
                    } catch (Exception e) {
                        Log.w("HHS_Moodle", "Error load thumbnail", e);
                        iv.setImageResource(R.drawable.file_image);
                    }
                    break;
                case ".m3u8":
                case ".mp3":
                case ".wma":
                case ".midi":
                case ".wav":
                case ".aac":
                case ".aif":
                case ".amp3":
                case ".weba":
                case ".ogg":
                    iv.setImageResource(R.drawable.file_music);
                    break;
                case ".mpeg":
                case ".mp4":
                case ".webm":
                case ".qt":
                case ".3gp":
                case ".3g2":
                case ".avi":
                case ".f4v":
                case ".flv":
                case ".h261":
                case ".h263":
                case ".h264":
                case ".asf":
                case ".wmv":
                    try {
                        Glide.with(getActivity()).load(files_attachment) // or URI/path
                                .override(76, 76).centerCrop().into(iv); //imageView to set thumbnail to
                    } catch (Exception e) {
                        Log.w("HHS_Moodle", "Error load thumbnail", e);
                        iv.setImageResource(R.drawable.file_video);
                    }
                    break;
                case ".vcs":
                case ".vcf":
                case ".css":
                case ".ics":
                case ".conf":
                case ".config":
                case ".java":
                case ".html":
                    iv.setImageResource(R.drawable.file_xml);
                    break;
                case ".apk":
                    iv.setImageResource(R.drawable.android);
                    break;
                case ".pdf":
                    iv.setImageResource(R.drawable.file_pdf);
                    break;
                case ".rtf":
                case ".csv":
                case ".txt":
                case ".doc":
                case ".xls":
                case ".ppt":
                case ".docx":
                case ".pptx":
                case ".xlsx":
                case ".odt":
                case ".ods":
                case ".odp":
                    iv.setImageResource(R.drawable.file_document);
                    break;
                case ".zip":
                case ".rar":
                    iv.setImageResource(R.drawable.zip_box);
                    break;
                default:
                    iv.setImageResource(R.drawable.file);
                    break;
                }
            }
            return v;
        }
    };

    //display data by filter
    final String note_search = sharedPref.getString("filter_filesBY", "files_title");
    sharedPref.edit().putString("filter_filesBY", "files_title").apply();
    filter.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable s) {
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
            adapter.getFilter().filter(s.toString());
        }
    });
    adapter.setFilterQueryProvider(new FilterQueryProvider() {
        public Cursor runQuery(CharSequence constraint) {
            return db.fetchDataByFilter(constraint.toString(), note_search);
        }
    });

    lv.setAdapter(adapter);
    //onClick function
    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterview, View view, int position, long id) {

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String files_attachment = row2.getString(row2.getColumnIndexOrThrow("files_attachment"));

            final File pathFile = new File(files_attachment);

            if (pathFile.isDirectory()) {
                try {
                    sharedPref.edit().putString("files_startFolder", files_attachment).apply();
                    setFilesList();
                } catch (Exception e) {
                    Snackbar.make(lv, R.string.toast_directory, Snackbar.LENGTH_LONG).show();
                }
            } else if (files_attachment.equals("")) {
                try {
                    final File pathActual = new File(sharedPref.getString("files_startFolder",
                            Environment.getExternalStorageDirectory().getPath()));
                    sharedPref.edit().putString("files_startFolder", pathActual.getParent()).apply();
                    setFilesList();
                } catch (Exception e) {
                    Snackbar.make(lv, R.string.toast_directory, Snackbar.LENGTH_LONG).show();
                }
            } else {
                helper_main.openAtt(getActivity(), lv, files_attachment);
            }
        }
    });

    lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String files_title = row2.getString(row2.getColumnIndexOrThrow("files_title"));
            final String files_attachment = row2.getString(row2.getColumnIndexOrThrow("files_attachment"));

            final File pathFile = new File(files_attachment);

            if (pathFile.isDirectory()) {

                Snackbar snackbar = Snackbar.make(lv, R.string.note_remove_confirmation, Snackbar.LENGTH_LONG)
                        .setAction(R.string.toast_yes, new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                sharedPref.edit().putString("files_startFolder", pathFile.getParent()).apply();
                                deleteRecursive(pathFile);
                                setFilesList();
                            }
                        });
                snackbar.show();

            } else {

                final CharSequence[] options = { getString(R.string.choose_menu_2),
                        getString(R.string.choose_menu_3), getString(R.string.choose_menu_4) };

                final AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity());
                dialog.setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int whichButton) {
                        dialog.cancel();
                    }
                });
                dialog.setItems(options, new DialogInterface.OnClickListener() {
                    @SuppressWarnings("ResultOfMethodCallIgnored")
                    @Override
                    public void onClick(DialogInterface dialog, int item) {

                        if (options[item].equals(getString(R.string.choose_menu_2))) {

                            if (pathFile.exists()) {
                                Intent sharingIntent = new Intent(Intent.ACTION_SEND);
                                sharingIntent.setType("image/png");
                                sharingIntent.putExtra(Intent.EXTRA_SUBJECT, files_title);
                                sharingIntent.putExtra(Intent.EXTRA_TEXT, files_title);
                                Uri bmpUri = Uri.fromFile(pathFile);
                                sharingIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
                                startActivity(Intent.createChooser(sharingIntent,
                                        (getString(R.string.app_share_file))));
                            }
                        }
                        if (options[item].equals(getString(R.string.choose_menu_4))) {
                            Snackbar snackbar = Snackbar
                                    .make(lv, R.string.note_remove_confirmation, Snackbar.LENGTH_LONG)
                                    .setAction(R.string.toast_yes, new View.OnClickListener() {
                                        @Override
                                        public void onClick(View view) {
                                            pathFile.delete();
                                            setFilesList();
                                        }
                                    });
                            snackbar.show();
                        }
                        if (options[item].equals(getString(R.string.choose_menu_3))) {

                            android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(
                                    getActivity());
                            View dialogView = View.inflate(getActivity(), R.layout.dialog_edit_file, null);

                            final EditText edit_title = (EditText) dialogView.findViewById(R.id.pass_title);
                            edit_title.setText(files_title);

                            builder.setView(dialogView);
                            builder.setTitle(R.string.choose_title);
                            builder.setPositiveButton(R.string.toast_yes,
                                    new DialogInterface.OnClickListener() {

                                        public void onClick(DialogInterface dialog, int whichButton) {

                                            String inputTag = edit_title.getText().toString().trim();

                                            File dir = pathFile.getParentFile();
                                            File to = new File(dir, inputTag);

                                            pathFile.renameTo(to);
                                            pathFile.delete();
                                            setFilesList();
                                        }
                                    });
                            builder.setNegativeButton(R.string.toast_cancel,
                                    new DialogInterface.OnClickListener() {

                                        public void onClick(DialogInterface dialog, int whichButton) {
                                            dialog.cancel();
                                        }
                                    });
                            AlertDialog dialog2 = builder.create();
                            // Display the custom alert dialog on interface
                            dialog2.show();
                            helper_main.showKeyboard(getActivity(), edit_title);
                        }
                    }
                });
                dialog.show();
            }

            return true;
        }
    });
}

From source file:de.baumann.browser.popups.Popup_files.java

private void setFilesList() {

    deleteDatabase("files_DB_v01.db");

    File f = new File(sharedPref.getString("files_startFolder",
            Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath()));
    final File[] files = f.listFiles();

    Arrays.sort(files, new Comparator<File>() {
        @Override/*from w ww. j  a v  a 2s. co  m*/
        public int compare(File file1, File file2) {
            if (file1.isDirectory()) {
                if (file2.isDirectory()) {
                    return String.valueOf(file1.getName().toLowerCase())
                            .compareTo(file2.getName().toLowerCase());
                } else {
                    return -1;
                }
            } else {
                if (file2.isDirectory()) {
                    return 1;
                } else {
                    return String.valueOf(file1.getName().toLowerCase())
                            .compareTo(file2.getName().toLowerCase());
                }
            }
        }
    });

    // looping through all items <item>
    if (files.length == 0) {
        Snackbar.make(listView, R.string.toast_files, Snackbar.LENGTH_LONG).show();
    }

    for (File file : files) {

        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());

        String file_Name = file.getName().substring(0, 1).toUpperCase() + file.getName().substring(1);
        String file_Size = getReadableFileSize(file.length());
        String file_date = formatter.format(new Date(file.lastModified()));
        String file_path = file.getAbsolutePath();

        String file_ext;
        if (file.isDirectory()) {
            file_ext = ".";
        } else {
            file_ext = file.getAbsolutePath().substring(file.getAbsolutePath().lastIndexOf("."));
        }

        db.open();
        if (db.isExist(file_Name)) {
            Log.i(TAG, "Entry exists" + file_Name);
        } else {
            db.insert(file_Name, file_Size, file_ext, file_path, file_date);
        }
    }

    try {
        db.insert("...", "", "", "", "");
    } catch (Exception e) {
        Snackbar.make(listView, R.string.toast_directory, Snackbar.LENGTH_LONG).show();
    }

    //display data
    final int layoutstyle = R.layout.list_item;
    int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.textView_create_notes };
    String[] column = new String[] { "files_title", "files_content", "files_creation" };
    final Cursor row = db.fetchAllData(this);
    adapter = new SimpleCursorAdapter(this, layoutstyle, row, column, xml_id, 0) {
        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {

            Cursor row2 = (Cursor) listView.getItemAtPosition(position);
            final String files_icon = row2.getString(row2.getColumnIndexOrThrow("files_icon"));
            final String files_attachment = row2.getString(row2.getColumnIndexOrThrow("files_attachment"));
            final File pathFile = new File(files_attachment);

            View v = super.getView(position, convertView, parent);
            final ImageView iv = (ImageView) v.findViewById(R.id.icon_notes);

            iv.setVisibility(View.VISIBLE);

            if (pathFile.isDirectory()) {
                iv.setImageResource(R.drawable.folder);
            } else {
                switch (files_icon) {
                case "":
                    iv.setImageResource(R.drawable.arrow_up_dark);
                    break;
                case ".m3u8":
                case ".mp3":
                case ".wma":
                case ".midi":
                case ".wav":
                case ".aac":
                case ".aif":
                case ".amp3":
                case ".weba":
                case ".ogg":
                    iv.setImageResource(R.drawable.file_music);
                    break;
                case ".mpeg":
                case ".mp4":
                case ".webm":
                case ".qt":
                case ".3gp":
                case ".3g2":
                case ".avi":
                case ".f4v":
                case ".flv":
                case ".h261":
                case ".h263":
                case ".h264":
                case ".asf":
                case ".wmv":
                    try {
                        Glide.with(Popup_files.this).load(files_attachment) // or URI/path
                                .override(76, 76).centerCrop().into(iv); //imageView to set thumbnail to
                    } catch (Exception e) {
                        Log.w("HHS_Moodle", "Error load thumbnail", e);
                        iv.setImageResource(R.drawable.file_video);
                    }
                    break;
                case ".vcs":
                case ".vcf":
                case ".css":
                case ".ics":
                case ".conf":
                case ".config":
                case ".java":
                case ".html":
                    iv.setImageResource(R.drawable.file_xml);
                    break;
                case ".apk":
                    iv.setImageResource(R.drawable.android);
                    break;
                case ".pdf":
                    iv.setImageResource(R.drawable.file_pdf);
                    break;
                case ".rtf":
                case ".csv":
                case ".txt":
                case ".doc":
                case ".xls":
                case ".ppt":
                case ".docx":
                case ".pptx":
                case ".xlsx":
                case ".odt":
                case ".ods":
                case ".odp":
                    iv.setImageResource(R.drawable.file_document);
                    break;
                case ".zip":
                case ".rar":
                    iv.setImageResource(R.drawable.zip_box);
                    break;
                case ".gif":
                case ".bmp":
                case ".tiff":
                case ".svg":
                case ".png":
                case ".jpg":
                case ".JPG":
                case ".jpeg":
                    try {
                        Glide.with(Popup_files.this).load(files_attachment) // or URI/path
                                .diskCacheStrategy(DiskCacheStrategy.NONE).skipMemoryCache(true)
                                .override(76, 76).centerCrop().into(iv); //imageView to set thumbnail to
                    } catch (Exception e) {
                        Log.w("HHS_Moodle", "Error load thumbnail", e);
                        iv.setImageResource(R.drawable.file_image);
                    }
                    break;
                default:
                    iv.setImageResource(R.drawable.file);
                    break;
                }
            }

            if (files_attachment.isEmpty()) {
                new Handler().postDelayed(new Runnable() {
                    public void run() {
                        iv.setImageResource(R.drawable.arrow_up_dark);
                    }
                }, 350);
            }

            return v;
        }
    };

    //display data by filter
    final String note_search = sharedPref.getString("filter_filesBY", "files_title");
    sharedPref.edit().putString("filter_filesBY", "files_title").apply();
    editText.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable s) {
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
            adapter.getFilter().filter(s.toString());
        }
    });
    adapter.setFilterQueryProvider(new FilterQueryProvider() {
        public Cursor runQuery(CharSequence constraint) {
            return db.fetchDataByFilter(constraint.toString(), note_search);
        }
    });

    listView.setAdapter(adapter);
    //onClick function
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterview, View view, int position, long id) {

            Cursor row2 = (Cursor) listView.getItemAtPosition(position);
            final String files_icon = row2.getString(row2.getColumnIndexOrThrow("files_icon"));
            final String files_attachment = row2.getString(row2.getColumnIndexOrThrow("files_attachment"));

            final File pathFile = new File(files_attachment);

            if (pathFile.isDirectory()) {
                try {
                    sharedPref.edit().putString("files_startFolder", files_attachment).apply();
                    setFilesList();
                } catch (Exception e) {
                    Snackbar.make(listView, R.string.toast_directory, Snackbar.LENGTH_LONG).show();
                }
            } else if (files_attachment.equals("")) {
                try {
                    final File pathActual = new File(sharedPref.getString("files_startFolder",
                            Environment.getExternalStorageDirectory().getPath()));
                    sharedPref.edit().putString("files_startFolder", pathActual.getParent()).apply();
                    setFilesList();
                } catch (Exception e) {
                    Snackbar.make(listView, R.string.toast_directory, Snackbar.LENGTH_LONG).show();
                }
            } else {
                helper_main.open(files_icon, Popup_files.this, pathFile, listView);
            }
        }
    });

    listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {

            Cursor row2 = (Cursor) listView.getItemAtPosition(position);
            final String files_title = row2.getString(row2.getColumnIndexOrThrow("files_title"));
            final String files_attachment = row2.getString(row2.getColumnIndexOrThrow("files_attachment"));

            final File pathFile = new File(files_attachment);

            if (pathFile.isDirectory()) {
                Snackbar snackbar = Snackbar
                        .make(listView, R.string.bookmark_remove_confirmation, Snackbar.LENGTH_LONG)
                        .setAction(R.string.toast_yes, new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                sharedPref.edit().putString("files_startFolder", pathFile.getParent()).apply();
                                deleteRecursive(pathFile);
                                setFilesList();
                            }
                        });
                snackbar.show();

            } else {
                final CharSequence[] options = { getString(R.string.choose_menu_2),
                        getString(R.string.choose_menu_3), getString(R.string.choose_menu_4) };

                final AlertDialog.Builder dialog = new AlertDialog.Builder(Popup_files.this);
                dialog.setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int whichButton) {
                        dialog.cancel();
                    }
                });
                dialog.setItems(options, new DialogInterface.OnClickListener() {
                    @SuppressWarnings("ResultOfMethodCallIgnored")
                    @Override
                    public void onClick(DialogInterface dialog, int item) {

                        if (options[item].equals(getString(R.string.choose_menu_2))) {

                            if (pathFile.exists()) {
                                Intent sharingIntent = new Intent(Intent.ACTION_SEND);
                                sharingIntent.setType("image/png");
                                sharingIntent.putExtra(Intent.EXTRA_SUBJECT, files_title);
                                sharingIntent.putExtra(Intent.EXTRA_TEXT, files_title);
                                Uri bmpUri = Uri.fromFile(pathFile);
                                sharingIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
                                startActivity(Intent.createChooser(sharingIntent,
                                        (getString(R.string.app_share_file))));
                            }
                        }
                        if (options[item].equals(getString(R.string.choose_menu_4))) {

                            Snackbar snackbar = Snackbar
                                    .make(listView, R.string.bookmark_remove_confirmation, Snackbar.LENGTH_LONG)
                                    .setAction(R.string.toast_yes, new View.OnClickListener() {
                                        @Override
                                        public void onClick(View view) {
                                            pathFile.delete();
                                            setFilesList();
                                        }
                                    });
                            snackbar.show();
                        }
                        if (options[item].equals(getString(R.string.choose_menu_3))) {
                            sharedPref.edit().putString("pathFile", files_attachment).apply();
                            editText.setVisibility(View.VISIBLE);
                            helper_editText.showKeyboard(Popup_files.this, editText, 2, files_title,
                                    getString(R.string.bookmark_edit_title));
                        }
                    }
                });
                dialog.show();
            }

            return true;
        }
    });
}

From source file:de.baumann.quitsmoking.fragments.FragmentNotes.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_screen_notes, container, false);

    PreferenceManager.setDefaultValues(getActivity(), R.xml.user_settings, false);
    sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity());
    setHasOptionsMenu(true);//from   w  ww .j  a  v a2  s.c om

    listView = (ListView) rootView.findViewById(R.id.notes);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            @SuppressWarnings("unchecked")
            HashMap<String, String> map = (HashMap<String, String>) listView.getItemAtPosition(position);

            final String title = map.get("title");
            final String cont = map.get("cont");
            final String seqnoStr = map.get("seqno");
            final String icon = map.get("icon");
            final String attachment = map.get("attachment");
            final String create = map.get("createDate");

            final Button attachment2;
            final TextView textInput;

            LayoutInflater inflater = getActivity().getLayoutInflater();

            final ViewGroup nullParent = null;
            View dialogView = inflater.inflate(R.layout.dialog_note_show, nullParent);

            final String attName = attachment.substring(attachment.lastIndexOf("/") + 1);
            final String att = getString(R.string.note_attachment) + ": " + attName;

            attachment2 = (Button) dialogView.findViewById(R.id.button_att);
            if (attName.equals("")) {
                attachment2.setVisibility(View.GONE);
            } else {
                attachment2.setText(att);
            }
            File file2 = new File(attachment);
            if (!file2.exists()) {
                attachment2.setVisibility(View.GONE);
            }

            textInput = (TextView) dialogView.findViewById(R.id.note_text_input);
            textInput.setText(cont);

            attachment2.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    openAtt(attachment);
                }
            });

            final ImageView be = (ImageView) dialogView.findViewById(R.id.imageButtonPri);
            assert be != null;

            switch (icon) {
            case "1":
                be.setImageResource(R.drawable.emoticon_neutral);
                sharedPref.edit().putString("handleTextIcon", "1").apply();
                break;
            case "2":
                be.setImageResource(R.drawable.emoticon_happy);
                sharedPref.edit().putString("handleTextIcon", "2").apply();
                break;
            case "3":
                be.setImageResource(R.drawable.emoticon_sad);
                sharedPref.edit().putString("handleTextIcon", "3").apply();
                break;
            case "4":
                be.setImageResource(R.drawable.emoticon);
                sharedPref.edit().putString("handleTextIcon", "4").apply();
                break;
            case "5":
                be.setImageResource(R.drawable.emoticon_cool);
                sharedPref.edit().putString("handleTextIcon", "5").apply();
                break;
            case "6":
                be.setImageResource(R.drawable.emoticon_dead);
                sharedPref.edit().putString("handleTextIcon", "6").apply();
                break;
            case "7":
                be.setImageResource(R.drawable.emoticon_excited);
                sharedPref.edit().putString("handleTextIcon", "7").apply();
                break;
            case "8":
                be.setImageResource(R.drawable.emoticon_tongue);
                sharedPref.edit().putString("handleTextIcon", "8").apply();
                break;
            case "9":
                be.setImageResource(R.drawable.emoticon_devil);
                sharedPref.edit().putString("handleTextIcon", "9").apply();
                break;
            case "":
                be.setImageResource(R.drawable.emoticon_neutral);
                sharedPref.edit().putString("handleTextIcon", "").apply();
                break;
            }

            android.app.AlertDialog.Builder dialog = new android.app.AlertDialog.Builder(getActivity())
                    .setTitle(title).setView(dialogView)
                    .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            dialog.cancel();
                        }
                    }).setNegativeButton(R.string.note_edit, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            sharedPref.edit().putString("handleTextTitle", title)
                                    .putString("handleTextText", cont).putString("handleTextIcon", icon)
                                    .putString("handleTextSeqno", seqnoStr)
                                    .putString("handleTextAttachment", attachment)
                                    .putString("handleTextCreate", create).apply();
                            helper_notes.editNote(getActivity());
                        }
                    });
            dialog.show();
        }
    });

    listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {

            @SuppressWarnings("unchecked")
            HashMap<String, String> map = (HashMap<String, String>) listView.getItemAtPosition(position);

            final String seqnoStr = map.get("seqno");
            final String title = map.get("title");
            final String cont = map.get("cont");
            final String icon = map.get("icon");
            final String attachment = map.get("attachment");
            final String create = map.get("createDate");

            final CharSequence[] options = { getString(R.string.note_edit), getString(R.string.note_share),
                    getString(R.string.note_remove_note) };
            new AlertDialog.Builder(getActivity())
                    .setPositiveButton(R.string.goal_cancel, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            dialog.dismiss();
                        }
                    }).setItems(options, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int item) {
                            if (options[item].equals(getString(R.string.note_edit))) {
                                sharedPref.edit().putString("handleTextTitle", title)
                                        .putString("handleTextText", cont).putString("handleTextIcon", icon)
                                        .putString("handleTextSeqno", seqnoStr)
                                        .putString("handleTextAttachment", attachment)
                                        .putString("handleTextAttachment", create).apply();
                                helper_notes.editNote(getActivity());
                            }

                            if (options[item].equals(getString(R.string.note_share))) {
                                Intent sharingIntent = new Intent(Intent.ACTION_SEND);
                                sharingIntent.setType("text/plain");
                                sharingIntent.putExtra(Intent.EXTRA_SUBJECT, title);
                                sharingIntent.putExtra(Intent.EXTRA_TEXT, cont);
                                startActivity(Intent.createChooser(sharingIntent,
                                        (getString(R.string.note_share_2))));
                            }

                            if (options[item].equals(getString(R.string.note_remove_note))) {
                                try {
                                    Database_Notes db = new Database_Notes(getActivity());
                                    final int count = db.getRecordCount();
                                    db.close();

                                    if (count == 1) {
                                        Snackbar snackbar = Snackbar.make(listView, R.string.note_remove_cannot,
                                                Snackbar.LENGTH_LONG);
                                        snackbar.show();

                                    } else {
                                        Snackbar snackbar = Snackbar
                                                .make(listView, R.string.note_remove_confirmation,
                                                        Snackbar.LENGTH_LONG)
                                                .setAction(R.string.yes, new View.OnClickListener() {
                                                    @Override
                                                    public void onClick(View view) {
                                                        try {
                                                            Database_Notes db = new Database_Notes(
                                                                    getActivity());
                                                            db.deleteNote(Integer.parseInt(seqnoStr));
                                                            db.close();
                                                            setNotesList();
                                                        } catch (PackageManager.NameNotFoundException e) {
                                                            e.printStackTrace();
                                                        }
                                                    }
                                                });
                                        snackbar.show();
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            }
                        }
                    }).show();

            return true;
        }
    });

    setHasOptionsMenu(true);
    setNotesList();
    return rootView;
}

From source file:com.example.skode6.scanenvy.MainActivity.java

private AlertDialog enterDialog(final EditText edit) {
    AlertDialog.Builder dialog = new AlertDialog.Builder(this);

    edit.setKeyListener(new DigitsKeyListener());
    final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(edit, InputMethodManager.SHOW_IMPLICIT);
    //edit.setFocusableInTouchMode(true);
    edit.setFocusable(true);/*from  ww w .j a  v  a  2s. c o m*/
    //edit.setOnClickListener(clickText());
    //edit.requestFocusFromTouch();
    edit.requestFocus();

    dialog.setView(edit);
    dialog.setCancelable(true);
    dialog.setTitle("Enter UPC");
    dialog.setPositiveButton("Submit", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            String upc = edit.getText().toString();
            try {
                Product p = run.lookUp(upc);
                adapter.add(p);
                //run.addProduct(p);
            } catch (IOException e) {
                Toast error = Toast.makeText(getApplicationContext(), "Couldn't find" + upc, Toast.LENGTH_LONG);
                error.show();
            }
        }
    });
    dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });
    return dialog.create();
}

From source file:cgeo.geocaching.cgeocaches.java

public void removeFromHistoryCheck() {
    AlertDialog.Builder dialog = new AlertDialog.Builder(this);
    dialog.setCancelable(true);//w  w  w  . j  av  a 2 s. c om
    dialog.setTitle(res.getString(R.string.caches_removing_from_history));
    dialog.setMessage((adapter != null && adapter.getCheckedCount() > 0)
            ? res.getString(R.string.cache_remove_from_history)
            : res.getString(R.string.cache_clear_history));
    dialog.setPositiveButton(getString(android.R.string.yes), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            removeFromHistory();
            dialog.cancel();
        }
    });
    dialog.setNegativeButton(getString(android.R.string.no), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });

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

From source file:cgeo.geocaching.cgeocaches.java

public void handleCachesLoaded() {
    try {/*w  w  w.j a  v a 2 s.c  o  m*/
        setAdapter();

        updateTitle();

        setDateComparatorForEventList();

        showFooterMoreCaches();

        if (search != null && search.getError() == StatusCode.UNAPPROVED_LICENSE) {
            AlertDialog.Builder dialog = new AlertDialog.Builder(this);
            dialog.setTitle(res.getString(R.string.license));
            dialog.setMessage(res.getString(R.string.err_license));
            dialog.setCancelable(true);
            dialog.setNegativeButton(res.getString(R.string.license_dismiss),
                    new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int id) {
                            Cookies.clearCookies();
                            dialog.cancel();
                        }
                    });
            dialog.setPositiveButton(res.getString(R.string.license_show),
                    new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int id) {
                            Cookies.clearCookies();
                            startActivity(new Intent(Intent.ACTION_VIEW,
                                    Uri.parse("http://www.geocaching.com/software/agreement.aspx?ID=0")));
                        }
                    });

            AlertDialog alert = dialog.create();
            alert.show();
        } else if (search != null && search.getError() != null) {
            showToast(res.getString(R.string.err_download_fail) + ' ' + search.getError().getErrorString(res)
                    + '.');

            hideLoading();
            showProgress(false);

            finish();
            return;
        }

        setAdapterCurrentCoordinates(false);
    } catch (Exception e) {
        showToast(res.getString(R.string.err_detail_cache_find_any));
        Log.e("cgeocaches.loadCachesHandler", e);

        hideLoading();
        showProgress(false);

        finish();
        return;
    }

    try {
        hideLoading();
        showProgress(false);
    } catch (Exception e2) {
        Log.e("cgeocaches.loadCachesHandler.2", e2);
    }

    adapter.setSelectMode(false);
}

From source file:cgeo.geocaching.cgeocaches.java

public void dropStored(final boolean removeListAfterwards) {
    AlertDialog.Builder dialog = new AlertDialog.Builder(this);
    dialog.setCancelable(true);/*from www. jav  a 2 s . c o  m*/
    dialog.setTitle(res.getString(R.string.caches_drop_stored));

    if (adapter.getCheckedCount() > 0) {
        dialog.setMessage(res.getString(R.string.caches_drop_selected_ask));
    } else {
        dialog.setMessage(res.getString(R.string.caches_drop_all_ask));
    }
    dialog.setPositiveButton(getString(android.R.string.yes), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int id) {
            dropSelected(removeListAfterwards);
            dialog.cancel();
        }
    });
    dialog.setNegativeButton(getString(android.R.string.no), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });

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