Example usage for android.text Editable toString

List of usage examples for android.text Editable toString

Introduction

In this page you can find the example usage for android.text Editable toString.

Prototype

public String toString();

Source Link

Document

Returns a string containing the characters in this sequence in the same order as this sequence.

Usage

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();
    }/* w w  w . ja v  a2  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 .jav  a 2  s. c  om
        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:com.code.android.vibevault.SearchScreen.java

private void init() {

    // Set up the date selection spinner.
    spinnerAdapter = ArrayAdapter.createFromResource(this, R.array.date_modifier,
            android.R.layout.simple_spinner_item);
    spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    dateModifierSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override//w w  w  .ja va2 s.  c o m
        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
            VibeVault.dateSearchModifierPos = pos;
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    dateModifierSpinner.setAdapter(spinnerAdapter);
    dateModifierSpinner.setSelection(VibeVault.dateSearchModifierPos);

    searchDrawer.setOnDrawerScrollListener(new OnDrawerScrollListener() {

        @Override
        public void onScrollEnded() {
        }

        @Override
        public void onScrollStarted() {
            vibrator.vibrate(50);
        }

    });
    artistSearchInput.addTextChangedListener(new TextWatcher() {

        @Override
        public void afterTextChanged(Editable s) {
            if (isMoreSearch(s.toString(), yearSearchInput.getText().toString())) {
                searchButton.setCompoundDrawablesWithIntrinsicBounds(
                        getResources().getDrawable(R.drawable.morebutton), null, null, null);
                searchButton.setText("More");
            } else {
                searchButton.setCompoundDrawablesWithIntrinsicBounds(
                        getResources().getDrawable(R.drawable.searchbutton_plain), null, null, null);
                searchButton.setText("Search");
            }
        }

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

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

    });
    yearSearchInput.addTextChangedListener(new TextWatcher() {

        @Override
        public void afterTextChanged(Editable s) {
            if (isMoreSearch(artistSearchInput.getText().toString(), s.toString())) {
                searchButton.setCompoundDrawablesWithIntrinsicBounds(
                        getResources().getDrawable(R.drawable.morebutton), null, null, null);
                searchButton.setText("More");
            } else {
                searchButton.setCompoundDrawablesWithIntrinsicBounds(
                        getResources().getDrawable(R.drawable.searchbutton_plain), null, null, null);
                searchButton.setText("Search");
            }
        }

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

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

    });
    searchDrawer.setOnDrawerOpenListener(new OnDrawerOpenListener() {
        @Override
        public void onDrawerOpened() {
            searchList.setBackgroundDrawable(getResources().getDrawable(R.drawable.backgrounddrawableblue));
            searchList.getBackground().setDither(true);
            searchList.setEnabled(false);
            handleText.setText("Search Panel");
            handleText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
            artistSearchInput.setText(VibeVault.artistSearchText);

            if (VibeVault.yearSearchInt != -1) {
                yearSearchInput.setText(String.valueOf(VibeVault.yearSearchInt));
            } else {
                yearSearchInput.setText("");
            }
            dateModifierSpinner.setSelection(VibeVault.dateSearchModifierPos);
        }
    });
    searchDrawer.setOnDrawerCloseListener(new OnDrawerCloseListener() {
        @Override
        public void onDrawerClosed() {
            searchList.setBackgroundColor(Color.BLACK);
            searchList.setEnabled(true);
            handleText.setText("Drag up to search...");
            handleText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 28);
        }
    });

    // Set listeners in the show details and artist search bars for the enter key.
    OnKeyListener enterListener = new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                if (!(artistSearchInput.getText().toString().equals(""))) {
                    VibeVault.artistSearchText = artistSearchInput.getText().toString();
                    if (setDate()) {
                        executeSearch(makeSearchURLString(1));
                        pageNum = 1;
                        searchDrawer.close();
                        return true;
                    }
                }
            }
            return false;
        }
    };
    this.artistSearchInput.setOnKeyListener(enterListener);

    this.searchButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

            String query = artistSearchInput.getText().toString();
            // Blank
            if (query.equals("")) {
                vibrator.vibrate(50);
                Toast.makeText(getBaseContext(), "You need a query first...", Toast.LENGTH_SHORT).show();
                return;
            }
            // Search more
            else if (isMoreSearch(artistSearchInput.getText().toString(),
                    yearSearchInput.getText().toString())) {
                searchButton.setCompoundDrawablesWithIntrinsicBounds(
                        getResources().getDrawable(R.drawable.morebutton), null, null, null);
                searchButton.setText("More");
                dateModifierSpinner.setSelection(VibeVault.dateSearchModifierPos);
                // pageNum is incremented then searched with to get the next
                // page.
                executeSearch(makeSearchURLString(++pageNum));
                vibrator.vibrate(50);
                searchDrawer.close();
            }
            // New search
            else {
                searchButton.setCompoundDrawablesWithIntrinsicBounds(
                        getResources().getDrawable(R.drawable.searchbutton_plain), null, null, null);
                searchButton.setText("Search");
                VibeVault.searchResults.clear();
                VibeVault.artistSearchText = artistSearchInput.getText().toString();
                if (setDate()) {
                    // "1" is passed to retrieve page number 1.
                    vibrator.vibrate(50);
                    executeSearch(makeSearchURLString(1));
                    pageNum = 1;
                    searchDrawer.close();
                }
            }

        }
    });

    this.settingsButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            launchSettingsDialog();
            vibrator.vibrate(50);
        }
    });

    this.clearButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            artistSearchInput.setText("");
            yearSearchInput.setText("");
            VibeVault.artistSearchText = "";
            VibeVault.yearSearchInt = -1;
            searchButton.setCompoundDrawablesWithIntrinsicBounds(
                    getResources().getDrawable(R.drawable.searchbutton_plain), null, null, null);
            searchButton.setText("Search");
            VibeVault.searchResults.clear();
            refreshSearchList();
            vibrator.vibrate(50);
        }
    });

    searchList.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> a, View v, int position, long id) {
            ArchiveShowObj show = (ArchiveShowObj) searchList.getItemAtPosition(position);
            Intent i = new Intent(SearchScreen.this, ShowDetailsScreen.class);
            i.putExtra("Show", show);
            startActivity(i);
        }
    });

    // Create the directory for our app if it don't exist.
    appRootDir = new File(Environment.getExternalStorageDirectory(), VibeVault.APP_DIRECTORY);
    if (!appRootDir.isFile() || !appRootDir.isDirectory()) {
        if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
            appRootDir.mkdirs();
        } else {
            Toast.makeText(getBaseContext(), "sdcard is unwritable...  is it mounted on the computer?",
                    Toast.LENGTH_SHORT).show();
        }
    }
    artistSearchInput.setText(VibeVault.artistSearchText);
    if (VibeVault.yearSearchInt != -1) {
        yearSearchInput.setText(String.valueOf(VibeVault.yearSearchInt));
    } else {
        yearSearchInput.setText("");
    }
    dateModifierSpinner.setSelection(VibeVault.dateSearchModifierPos);

}

From source file:de.uni_koblenz_landau.apow.ObsDetailFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.obs_detail_fragment, container, false);

    // Create UI references.
    mDeleteDialog = (DeleteDialogFragment) getFragmentManager().findFragmentByTag(DELETE_DIALOG_ID);
    if (mDeleteDialog != null) {
        mDeleteDialog.setListener(this);
    }//from w  w w  . j  a  v  a2  s  . c  o m
    mClassLayout = (LinearLayout) view.findViewById(R.id.obs_detail_class);
    mClassSpinner = (Spinner) view.findViewById(R.id.obs_detail_class_spinner);
    mClassSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View v, int pos, long id) {

            mQuestionLayout.setVisibility(View.GONE);
            mTestLayout.setVisibility(View.GONE);
            mFindingLayout.setVisibility(View.GONE);
            mSymptomLayout.setVisibility(View.GONE);

            switch (pos) {
            case Constants.CLASS_QUESTION:
                mQuestionLayout.setVisibility(View.VISIBLE);
                break;
            case Constants.CLASS_TEST:
                mTestLayout.setVisibility(View.VISIBLE);
                break;
            case Constants.CLASS_FINDING:
                mFindingLayout.setVisibility(View.VISIBLE);
                break;
            case Constants.CLASS_SYMPTOM:
                mSymptomLayout.setVisibility(View.VISIBLE);
                break;
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    mQuestionLayout = (LinearLayout) view.findViewById(R.id.obs_detail_question);
    mQuestionTextView = (EditText) view.findViewById(R.id.obs_detail_question_text);
    mTestLayout = (LinearLayout) view.findViewById(R.id.obs_detail_test);
    mTestConceptView = (Spinner) view.findViewById(R.id.obs_detail_test_concept);
    mTestConceptView.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View v, int pos, long id) {
            ListViewItem item = (ListViewItem) parent.getItemAtPosition(pos);
            mTestUnitView.setText(item.getField2());
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    mTestUnitView = (TextView) view.findViewById(R.id.obs_detail_test_unit);
    mTestValueView = (EditText) view.findViewById(R.id.obs_detail_test_value);
    mFindingLayout = (LinearLayout) view.findViewById(R.id.obs_detail_finding);
    mFindingValueCodedView = (AutoCompleteTextView) view.findViewById(R.id.obs_detail_finding_value_coded);
    mFindingValueCodedView.addTextChangedListener(new TextWatcher() {

        @Override
        public void afterTextChanged(Editable s) {
        }

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

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (!findingCodeBlock) {
                findingCode = -1;
            }
            findingCodeBlock = false;
            searchFindings(s.toString().trim());
        }
    });

    mFindingValueCodedView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> listView, View view, int position, long id) {
            findingCode = (int) id;
        }
    });
    mFindingCertaintyView = (CheckBox) view.findViewById(R.id.obs_detail_finding_certainty);
    mFindingSeverityCodedView = (CheckBox) view.findViewById(R.id.obs_detail_finding_severity_coded);
    mSymptomLayout = (LinearLayout) view.findViewById(R.id.obs_detail_symptom);
    mSymptomValueView = (AutoCompleteTextView) view.findViewById(R.id.obs_detail_symptom_value);
    mSymptomValueView.addTextChangedListener(new TextWatcher() {

        @Override
        public void afterTextChanged(Editable s) {
        }

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

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (!symptomCodeBlock) {
                symptomCode = -1;
            }
            symptomCodeBlock = false;
            searchSymptoms(s.toString().trim());
        }
    });
    mSymptomValueView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> listView, View view, int position, long id) {
            symptomCode = (int) id;
        }
    });

    // Restore UI from saved instance or load data.
    if (savedInstanceState != null) {
        findingCode = savedInstanceState.getInt(ARG_FINDING_CODE);
        symptomCode = savedInstanceState.getInt(ARG_SYMPTOM_CODE);

        mObs = (Obs) savedInstanceState.getSerializable(ARG_OBS);
        if (mObs != null) {
            mTestConcepts = savedInstanceState.getParcelableArrayList(ARG_TEST_CONCEPTS);

            ArrayAdapter<ListViewItem> adapter = new ArrayAdapter<>(getActivity(),
                    android.R.layout.simple_spinner_item, mTestConcepts);
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            mTestConceptView.setAdapter(adapter);
            restoreView();
        }
    } else {
        findingCode = -1;
        symptomCode = -1;
        loadObs();
    }
    return view;
}

From source file:de.baumann.hhsmoodle.data_notes.Notes_Fragment.java

public void setNotesList() {

    if (isFABOpen) {
        closeFABMenu();//from  ww  w.j  av  a 2 s.c  o  m
    }

    //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[] { "note_title", "note_content", "note_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 _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String note_title = row2.getString(row2.getColumnIndexOrThrow("note_title"));
            final String note_content = row2.getString(row2.getColumnIndexOrThrow("note_content"));
            final String note_icon = row2.getString(row2.getColumnIndexOrThrow("note_icon"));
            final String note_attachment = row2.getString(row2.getColumnIndexOrThrow("note_attachment"));
            final String note_creation = row2.getString(row2.getColumnIndexOrThrow("note_creation"));

            View v = super.getView(position, convertView, parent);
            ImageView iv_icon = (ImageView) v.findViewById(R.id.icon_notes);
            ImageView iv_attachment = (ImageView) v.findViewById(R.id.att_notes);
            helper_main.switchIcon(getActivity(), note_icon, "note_icon", iv_icon);

            switch (note_attachment) {
            case "":
                iv_attachment.setVisibility(View.GONE);
                break;
            default:
                iv_attachment.setVisibility(View.VISIBLE);
                iv_attachment.setImageResource(R.drawable.ic_attachment);
                break;
            }

            File file = new File(note_attachment);
            if (!file.exists()) {
                iv_attachment.setVisibility(View.GONE);
            }

            iv_icon.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {

                    final helper_main.Item[] items = {
                            new helper_main.Item(getString(R.string.note_priority_0), R.drawable.circle_green),
                            new helper_main.Item(getString(R.string.note_priority_1), R.drawable.circle_yellow),
                            new helper_main.Item(getString(R.string.note_priority_2), R.drawable.circle_red), };

                    ListAdapter adapter = new ArrayAdapter<helper_main.Item>(getActivity(),
                            android.R.layout.select_dialog_item, android.R.id.text1, items) {
                        @NonNull
                        public View getView(int position, View convertView, @NonNull ViewGroup parent) {
                            //Use super class to create the View
                            View v = super.getView(position, convertView, parent);
                            TextView tv = (TextView) v.findViewById(android.R.id.text1);
                            tv.setTextSize(18);
                            tv.setCompoundDrawablesWithIntrinsicBounds(items[position].icon, 0, 0, 0);
                            //Add margin between image and text (support various screen densities)
                            int dp5 = (int) (24 * getResources().getDisplayMetrics().density + 0.5f);
                            tv.setCompoundDrawablePadding(dp5);

                            return v;
                        }
                    };

                    new AlertDialog.Builder(getActivity())
                            .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                                public void onClick(DialogInterface dialog, int whichButton) {
                                    dialog.cancel();
                                }
                            }).setAdapter(adapter, new DialogInterface.OnClickListener() {

                                public void onClick(DialogInterface dialog, int item) {
                                    if (item == 0) {
                                        db.update(Integer.parseInt(_id), note_title, note_content, "3",
                                                note_attachment, note_creation);
                                        setNotesList();
                                    } else if (item == 1) {
                                        db.update(Integer.parseInt(_id), note_title, note_content, "2",
                                                note_attachment, note_creation);
                                        setNotesList();
                                    } else if (item == 2) {
                                        db.update(Integer.parseInt(_id), note_title, note_content, "1",
                                                note_attachment, note_creation);
                                        setNotesList();
                                    }
                                }
                            }).show();
                }
            });
            iv_attachment.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    helper_main.openAtt(getActivity(), lv, note_attachment);
                }
            });
            return v;
        }
    };

    //display data by filter
    final String note_search = sharedPref.getString("filter_noteBY", "note_title");
    sharedPref.edit().putString("filter_noteBY", "note_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) {

            if (isFABOpen) {
                closeFABMenu();
            }

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String note_title = row2.getString(row2.getColumnIndexOrThrow("note_title"));
            final String note_content = row2.getString(row2.getColumnIndexOrThrow("note_content"));
            final String note_icon = row2.getString(row2.getColumnIndexOrThrow("note_icon"));
            final String note_attachment = row2.getString(row2.getColumnIndexOrThrow("note_attachment"));
            final String note_creation = row2.getString(row2.getColumnIndexOrThrow("note_creation"));

            final Button attachment;
            final TextView textInput;

            LayoutInflater inflater = getActivity().getLayoutInflater();

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

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

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

            textInput = (TextView) dialogView.findViewById(R.id.note_text_input);
            if (note_content.isEmpty()) {
                textInput.setVisibility(View.GONE);
            } else {
                textInput.setText(note_content);
                Linkify.addLinks(textInput, Linkify.WEB_URLS);
            }

            attachment.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    helper_main.openAtt(getActivity(), textInput, note_attachment);
                }
            });

            final ImageView be = (ImageView) dialogView.findViewById(R.id.imageButtonPri);
            final ImageView attImage = (ImageView) dialogView.findViewById(R.id.attImage);

            File file2 = new File(note_attachment);
            if (!file2.exists()) {
                attachment.setVisibility(View.GONE);
                attImage.setVisibility(View.GONE);
            } else if (note_attachment.contains(".gif") || note_attachment.contains(".bmp")
                    || note_attachment.contains(".tiff") || note_attachment.contains(".png")
                    || note_attachment.contains(".jpg") || note_attachment.contains(".JPG")
                    || note_attachment.contains(".jpeg") || note_attachment.contains(".mpeg")
                    || note_attachment.contains(".mp4") || note_attachment.contains(".3gp")
                    || note_attachment.contains(".3g2") || note_attachment.contains(".avi")
                    || note_attachment.contains(".flv") || note_attachment.contains(".h261")
                    || note_attachment.contains(".h263") || note_attachment.contains(".h264")
                    || note_attachment.contains(".asf") || note_attachment.contains(".wmv")) {
                attImage.setVisibility(View.VISIBLE);

                try {
                    Glide.with(getActivity()).load(note_attachment) // or URI/path
                            .diskCacheStrategy(DiskCacheStrategy.NONE).skipMemoryCache(true).into(attImage); //imageView to set thumbnail to
                } catch (Exception e) {
                    Log.w("HHS_Moodle", "Error load thumbnail", e);
                    attImage.setVisibility(View.GONE);
                }

                attImage.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View arg0) {
                        helper_main.openAtt(getActivity(), attImage, note_attachment);
                    }
                });
            }

            switch (note_icon) {
            case "3":
                be.setImageResource(R.drawable.circle_green);
                break;
            case "2":
                be.setImageResource(R.drawable.circle_yellow);
                break;
            case "1":
                be.setImageResource(R.drawable.circle_red);
                break;
            }

            android.app.AlertDialog.Builder dialog = new android.app.AlertDialog.Builder(getActivity())
                    .setTitle(note_title).setView(dialogView)
                    .setPositiveButton(R.string.toast_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", note_title)
                                    .putString("handleTextText", note_content)
                                    .putString("handleTextIcon", note_icon).putString("handleTextSeqno", _id)
                                    .putString("handleTextAttachment", note_attachment)
                                    .putString("handleTextCreate", note_creation).apply();
                            helper_main.switchToActivity(getActivity(), Activity_EditNote.class, false);
                        }
                    });
            dialog.show();
        }
    });

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

            if (isFABOpen) {
                closeFABMenu();
            }

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String note_title = row2.getString(row2.getColumnIndexOrThrow("note_title"));
            final String note_content = row2.getString(row2.getColumnIndexOrThrow("note_content"));
            final String note_icon = row2.getString(row2.getColumnIndexOrThrow("note_icon"));
            final String note_attachment = row2.getString(row2.getColumnIndexOrThrow("note_attachment"));
            final String note_creation = row2.getString(row2.getColumnIndexOrThrow("note_creation"));

            final CharSequence[] options = { getString(R.string.number_edit_entry),
                    getString(R.string.bookmark_remove_bookmark), getString(R.string.todo_share),
                    getString(R.string.todo_menu), getString(R.string.count_create),
                    getString(R.string.bookmark_createEvent) };
            new AlertDialog.Builder(getActivity())
                    .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            dialog.cancel();
                        }
                    }).setItems(options, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int item) {
                            if (options[item].equals(getString(R.string.number_edit_entry))) {
                                Notes_helper.newNote(getActivity(), note_title, note_content, note_icon,
                                        note_attachment, note_creation, _id);
                            }

                            if (options[item].equals(getString(R.string.todo_share))) {
                                File attachment = new File(note_attachment);
                                Intent sharingIntent = new Intent(Intent.ACTION_SEND);
                                sharingIntent.setType("text/plain");
                                sharingIntent.putExtra(Intent.EXTRA_SUBJECT, note_title);
                                sharingIntent.putExtra(Intent.EXTRA_TEXT, note_content);

                                if (attachment.exists()) {
                                    Uri bmpUri = Uri.fromFile(attachment);
                                    sharingIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
                                }

                                startActivity(Intent.createChooser(sharingIntent,
                                        (getString(R.string.note_share_2))));
                            }

                            if (options[item].equals(getString(R.string.todo_menu))) {
                                Todo_helper.newTodo(getActivity(), note_title, note_content,
                                        getActivity().getString(R.string.note_content));
                            }

                            if (options[item].equals(getString(R.string.count_create))) {
                                Count_helper.newCount(getActivity(), note_title, note_content,
                                        getActivity().getString(R.string.note_content), false);
                            }

                            if (options[item].equals(getString(R.string.bookmark_createEvent))) {
                                helper_main.createCalendarEvent(getActivity(), note_title, note_content);
                            }

                            if (options[item].equals(getString(R.string.bookmark_remove_bookmark))) {
                                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) {
                                                db.delete(Integer.parseInt(_id));
                                                setNotesList();
                                            }
                                        });
                                snackbar.show();
                            }
                        }
                    }).show();

            return true;
        }
    });
}

From source file:de.baumann.hhsmoodle.data_bookmarks.Bookmarks_Fragment.java

public void setBookmarksList() {

    //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[] { "bookmarks_title", "bookmarks_content", "bookmarks_creation" };
    final Cursor row = db.fetchAllData(getActivity());
    adapter = new SimpleCursorAdapter(getActivity(), layoutstyle, row, column, xml_id, 0) {
        @Override//from  w  w w.  j  a v  a 2  s .c  o  m
        public View getView(final int position, View convertView, ViewGroup parent) {

            Cursor row = (Cursor) lv.getItemAtPosition(position);
            final String _id = row.getString(row.getColumnIndexOrThrow("_id"));
            final String bookmarks_title = row.getString(row.getColumnIndexOrThrow("bookmarks_title"));
            final String bookmarks_content = row.getString(row.getColumnIndexOrThrow("bookmarks_content"));
            final String bookmarks_icon = row.getString(row.getColumnIndexOrThrow("bookmarks_icon"));
            final String bookmarks_attachment = row
                    .getString(row.getColumnIndexOrThrow("bookmarks_attachment"));
            final String bookmarks_creation = row.getString(row.getColumnIndexOrThrow("bookmarks_creation"));

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

            switch (bookmarks_icon) {
            case "01":
                iv_icon.setImageResource(R.drawable.circle_red);
                break;
            case "02":
                iv_icon.setImageResource(R.drawable.circle_yellow);
                break;
            case "03":
                iv_icon.setImageResource(R.drawable.circle_green);
                break;
            case "04":
                iv_icon.setImageResource(R.drawable.ic_school_grey600_48dp);
                break;
            case "05":
                iv_icon.setImageResource(R.drawable.ic_view_dashboard_grey600_48dp);
                break;
            case "06":
                iv_icon.setImageResource(R.drawable.ic_face_profile_grey600_48dp);
                break;
            case "07":
                iv_icon.setImageResource(R.drawable.ic_calendar_grey600_48dp);
                break;
            case "08":
                iv_icon.setImageResource(R.drawable.ic_chart_areaspline_grey600_48dp);
                break;
            case "09":
                iv_icon.setImageResource(R.drawable.ic_bell_grey600_48dp);
                break;
            case "10":
                iv_icon.setImageResource(R.drawable.ic_settings_grey600_48dp);
                break;
            case "11":
                iv_icon.setImageResource(R.drawable.ic_web_grey600_48dp);
                break;
            case "12":
                iv_icon.setImageResource(R.drawable.ic_magnify_grey600_48dp);
                break;
            case "13":
                iv_icon.setImageResource(R.drawable.ic_pencil_grey600_48dp);
                break;
            case "14":
                iv_icon.setImageResource(R.drawable.ic_check_grey600_48dp);
                break;
            case "15":
                iv_icon.setImageResource(R.drawable.ic_clock_grey600_48dp);
                break;
            case "16":
                iv_icon.setImageResource(R.drawable.ic_bookmark_grey600_48dp);
                break;
            }

            switch (bookmarks_attachment) {
            case "":
                iv_attachment.setVisibility(View.VISIBLE);
                iv_attachment.setImageResource(R.drawable.star_outline);
                break;
            default:
                iv_attachment.setVisibility(View.VISIBLE);
                iv_attachment.setImageResource(R.drawable.star_grey);
                break;
            }

            iv_attachment.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    if (bookmarks_attachment.equals("")) {

                        if (db.isExistFav("true")) {
                            Snackbar.make(lv, R.string.bookmark_setFav_not, Snackbar.LENGTH_LONG).show();
                        } else {
                            iv_attachment.setImageResource(R.drawable.star_grey);
                            db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, bookmarks_icon,
                                    "true", bookmarks_creation);
                            setBookmarksList();
                            sharedPref.edit().putString("favoriteURL", bookmarks_content)
                                    .putString("favoriteTitle", bookmarks_title).apply();
                            Snackbar.make(lv, R.string.bookmark_setFav, Snackbar.LENGTH_LONG).show();
                        }
                    } else {
                        iv_attachment.setImageResource(R.drawable.star_outline);
                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, bookmarks_icon, "",
                                bookmarks_creation);
                        setBookmarksList();
                    }
                }
            });

            iv_icon.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    final helper_main.Item[] items = {
                            new helper_main.Item(getString(R.string.note_priority_2), R.drawable.circle_red),
                            new helper_main.Item(getString(R.string.note_priority_1), R.drawable.circle_yellow),
                            new helper_main.Item(getString(R.string.note_priority_0), R.drawable.circle_green),
                            new helper_main.Item(getString(R.string.text_tit_11),
                                    R.drawable.ic_school_grey600_48dp),
                            new helper_main.Item(getString(R.string.text_tit_1),
                                    R.drawable.ic_view_dashboard_grey600_48dp),
                            new helper_main.Item(getString(R.string.text_tit_2),
                                    R.drawable.ic_face_profile_grey600_48dp),
                            new helper_main.Item(getString(R.string.text_tit_8),
                                    R.drawable.ic_calendar_grey600_48dp),
                            new helper_main.Item(getString(R.string.text_tit_3),
                                    R.drawable.ic_chart_areaspline_grey600_48dp),
                            new helper_main.Item(getString(R.string.text_tit_4),
                                    R.drawable.ic_bell_grey600_48dp),
                            new helper_main.Item(getString(R.string.text_tit_5),
                                    R.drawable.ic_settings_grey600_48dp),
                            new helper_main.Item(getString(R.string.text_tit_6),
                                    R.drawable.ic_web_grey600_48dp),
                            new helper_main.Item(getString(R.string.text_tit_7),
                                    R.drawable.ic_magnify_grey600_48dp),
                            new helper_main.Item(getString(R.string.title_notes),
                                    R.drawable.ic_pencil_grey600_48dp),
                            new helper_main.Item(getString(R.string.text_tit_9),
                                    R.drawable.ic_check_grey600_48dp),
                            new helper_main.Item(getString(R.string.text_tit_10),
                                    R.drawable.ic_clock_grey600_48dp),
                            new helper_main.Item(getString(R.string.title_bookmarks),
                                    R.drawable.ic_bookmark_grey600_48dp), };

                    ListAdapter adapter = new ArrayAdapter<helper_main.Item>(getActivity(),
                            android.R.layout.select_dialog_item, android.R.id.text1, items) {
                        @NonNull
                        public View getView(int position, View convertView, @NonNull ViewGroup parent) {
                            //Use super class to create the View
                            View v = super.getView(position, convertView, parent);
                            TextView tv = (TextView) v.findViewById(android.R.id.text1);
                            tv.setTextSize(18);
                            tv.setCompoundDrawablesWithIntrinsicBounds(items[position].icon, 0, 0, 0);
                            //Add margin between image and text (support various screen densities)
                            int dp5 = (int) (24 * getResources().getDisplayMetrics().density + 0.5f);
                            tv.setCompoundDrawablePadding(dp5);

                            return v;
                        }
                    };

                    new AlertDialog.Builder(getActivity())
                            .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                                public void onClick(DialogInterface dialog, int whichButton) {
                                    dialog.cancel();
                                }
                            }).setAdapter(adapter, new DialogInterface.OnClickListener() {

                                public void onClick(DialogInterface dialog, int item) {
                                    if (item == 0) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "01", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 1) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "02", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 2) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "03", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 3) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "04", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 4) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "05", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 5) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "06", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 6) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "07", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 7) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "08", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 8) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "09", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 9) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "10", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 10) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "11", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 11) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "12", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 12) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "13", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 13) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "14", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 14) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "15", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 15) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "16", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    }
                                }
                            }).show();
                }
            });
            return v;
        }
    };

    //display data by filter
    final String note_search = sharedPref.getString("filter_bookmarksBY", "bookmarks_title");
    sharedPref.edit().putString("filter_bookmarksBY", "bookmarks_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 bookmarks_content = row2.getString(row2.getColumnIndexOrThrow("bookmarks_content"));
            sharedPref.edit().putString("load_next", "true").apply();
            sharedPref.edit().putString("loadURL", bookmarks_content).apply();

            ViewPager viewPager = (ViewPager) getActivity().findViewById(R.id.viewpager);
            viewPager.setCurrentItem(0);

        }
    });

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

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String bookmarks_title = row2.getString(row2.getColumnIndexOrThrow("bookmarks_title"));
            final String bookmarks_content = row2.getString(row2.getColumnIndexOrThrow("bookmarks_content"));
            final String bookmarks_icon = row2.getString(row2.getColumnIndexOrThrow("bookmarks_icon"));
            final String bookmarks_attachment = row2
                    .getString(row2.getColumnIndexOrThrow("bookmarks_attachment"));
            final String bookmarks_creation = row2.getString(row2.getColumnIndexOrThrow("bookmarks_creation"));

            final CharSequence[] options = { getString(R.string.number_edit_entry),
                    getString(R.string.bookmark_remove_bookmark), getString(R.string.todo_menu),
                    getString(R.string.bookmark_createNote), getString(R.string.count_create),
                    getString(R.string.bookmark_createShortcut), getString(R.string.bookmark_createEvent) };
            new AlertDialog.Builder(getActivity())
                    .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

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

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

                                final EditText edit_title = (EditText) dialogView.findViewById(R.id.pass_title);
                                edit_title.setHint(R.string.bookmark_edit_title);
                                edit_title.setText(bookmarks_title);

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

                                            public void onClick(DialogInterface dialog, int whichButton) {

                                                String inputTag = edit_title.getText().toString().trim();
                                                db.update(Integer.parseInt(_id), inputTag, bookmarks_content,
                                                        bookmarks_icon, bookmarks_attachment,
                                                        bookmarks_creation);
                                                setBookmarksList();
                                                Snackbar.make(lv, R.string.bookmark_added,
                                                        Snackbar.LENGTH_SHORT).show();
                                            }
                                        });
                                builder.setNegativeButton(R.string.toast_cancel,
                                        new DialogInterface.OnClickListener() {

                                            public void onClick(DialogInterface dialog, int whichButton) {
                                                dialog.cancel();
                                            }
                                        });

                                final AlertDialog dialog2 = builder.create();
                                // Display the custom alert dialog on interface
                                dialog2.show();
                                helper_main.showKeyboard(getActivity(), edit_title);
                            }

                            if (options[item].equals(getString(R.string.todo_menu))) {
                                Todo_helper.newTodo(getActivity(), bookmarks_title, "", "");
                            }

                            if (options[item].equals(getString(R.string.count_create))) {
                                Count_helper.newCount(getActivity(), bookmarks_title, bookmarks_content,
                                        getActivity().getString(R.string.note_content), false);
                            }

                            if (options[item].equals(getString(R.string.bookmark_createEvent))) {
                                helper_main.createCalendarEvent(getActivity(), bookmarks_title,
                                        bookmarks_content);
                            }

                            if (options[item].equals(getString(R.string.bookmark_remove_bookmark))) {
                                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) {
                                                db.delete(Integer.parseInt(_id));
                                                setBookmarksList();
                                            }
                                        });
                                snackbar.show();
                            }

                            if (options[item].equals(getString(R.string.bookmark_createNote))) {
                                Notes_helper.newNote(getActivity(), bookmarks_title, bookmarks_content, "", "",
                                        "", "");
                            }

                            if (options[item].equals(getString(R.string.bookmark_createShortcut))) {
                                Intent i = new Intent();
                                i.setAction(Intent.ACTION_VIEW);
                                i.setData(Uri.parse(bookmarks_content));

                                Intent shortcut = new Intent();
                                shortcut.putExtra("android.intent.extra.shortcut.INTENT", i);
                                shortcut.putExtra("android.intent.extra.shortcut.NAME",
                                        "THE NAME OF SHORTCUT TO BE SHOWN");
                                shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, bookmarks_title);
                                shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                                        Intent.ShortcutIconResource.fromContext(
                                                getActivity().getApplicationContext(), R.mipmap.ic_launcher));
                                shortcut.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
                                getActivity().sendBroadcast(shortcut);
                                Snackbar.make(lv, R.string.toast_shortcut, Snackbar.LENGTH_LONG).show();
                            }

                        }
                    }).show();

            return true;
        }
    });
}

From source file:com.arya.portfolio.view_controller.fragment.UseCasesFragment.java

@Override
public void afterTextChanged(Editable s) {
    String searchString = s.toString().trim();
    if (!TextUtils.isEmpty(searchString)) {
        searchByTitle(searchString);/* w  ww. j a va2s . co  m*/
    } else {
        searchByTitle(null);
    }
}

From source file:org.wso2.iot.agent.activities.AuthenticationActivity.java

/**
 * Initialize the Android IDP SDK by passing credentials,client ID and
 * client secret.//www  .  j  a  v  a2 s  .  co m
 *
 * @param clientKey    client id value to access APIs..
 * @param clientSecret client secret value to access APIs.
 */
private void initializeIDPLib(String clientKey, String clientSecret) {
    String serverIP = Constants.DEFAULT_HOST;
    String prefIP = Preference.getString(AuthenticationActivity.this, Constants.PreferenceFlag.IP);

    if (prefIP != null) {
        serverIP = prefIP;
    }
    if (serverIP != null && !serverIP.isEmpty()) {
        ServerConfig utils = new ServerConfig();
        utils.setServerIP(serverIP);
        String serverURL = utils.getServerURL(context) + Constants.OAUTH_ENDPOINT;
        Editable tenantDomain = etDomain.getText();

        if (tenantDomain != null && !tenantDomain.toString().trim().isEmpty()) {
            username = etUsername.getText().toString().trim()
                    + context.getResources().getString(R.string.intent_extra_at)
                    + tenantDomain.toString().trim();

        } else {
            username = etUsername.getText().toString().trim();
        }

        Preference.putString(context, Constants.CLIENT_ID, clientKey);
        Preference.putString(context, Constants.CLIENT_SECRET, clientSecret);

        CredentialInfo info = new CredentialInfo();
        info.setClientID(clientKey);
        info.setClientSecret(clientSecret);
        info.setUsername(username);

        info.setPassword(passwordVal);
        info.setTokenEndPoint(serverURL);

        if (adminAccessToken != null) {
            info.setAdminAccessToken(adminAccessToken);
        }

        //adding device-specific scope
        String deviceScope = "device_" + deviceInfo.getDeviceId();
        info.setScopes(deviceScope);

        if (tenantDomain != null && !tenantDomain.toString().trim().isEmpty()) {
            info.setTenantDomain(tenantDomain.toString().trim());
        }

        IdentityProxy.getInstance().init(info, AuthenticationActivity.this, this.getApplicationContext());
    }
}

From source file:com.piusvelte.sonet.core.SonetComments.java

@Override
public void afterTextChanged(Editable arg0) {
    mCount.setText(Integer.toString(arg0.toString().length()));
}

From source file:im.vector.activity.HomeActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (CommonActivityUtils.shouldRestartApp()) {
        Log.e(LOG_TAG, "Restart the application.");
        CommonActivityUtils.restartApp(this);
    }/*from   www.  j a  v a 2  s. co m*/

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);

    mMyRoomList = (ExpandableListView) findViewById(R.id.listView_myRooms);
    // the chevron is managed in the header view
    mMyRoomList.setGroupIndicator(null);
    mAdapter = new ConsoleRoomSummaryAdapter(this, Matrix.getMXSessions(this), R.layout.adapter_item_my_rooms,
            R.layout.adapter_room_section_header);

    if (null != savedInstanceState) {
        if (savedInstanceState.containsKey(PUBLIC_ROOMS_LIST_LIST)) {
            Serializable map = savedInstanceState.getSerializable(PUBLIC_ROOMS_LIST_LIST);

            if (null != map) {
                HashMap<String, List<PublicRoom>> hash = (HashMap<String, List<PublicRoom>>) map;
                mPublicRoomsListList = new ArrayList<List<PublicRoom>>(hash.values());
                mHomeServerNames = new ArrayList<>(hash.keySet());
            }
        }
    }

    final Intent intent = getIntent();
    if (intent.hasExtra(EXTRA_JUMP_TO_ROOM_ID)) {
        mAutomaticallyOpenedRoomId = intent.getStringExtra(EXTRA_JUMP_TO_ROOM_ID);
    }

    if (intent.hasExtra(EXTRA_JUMP_MATRIX_ID)) {
        mAutomaticallyOpenedMatrixId = intent.getStringExtra(EXTRA_JUMP_MATRIX_ID);
    }

    if (intent.hasExtra(EXTRA_ROOM_INTENT)) {
        mOpenedRoomIntent = intent.getParcelableExtra(EXTRA_ROOM_INTENT);
    }

    String action = intent.getAction();
    String type = intent.getType();

    // send files from external application
    if ((Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action)) && type != null) {
        this.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                CommonActivityUtils.sendFilesTo(HomeActivity.this, intent);
            }
        });
    }

    mMyRoomList.setAdapter(mAdapter);
    Collection<MXSession> sessions = Matrix.getMXSessions(HomeActivity.this);

    // check if  there is some valid session
    // the home activity could be relaunched after an application crash
    // so, reload the sessions before displaying the hidtory
    if (sessions.size() == 0) {
        Log.e(LOG_TAG, "Weird : onCreate : no session");

        if (null != Matrix.getInstance(this).getDefaultSession()) {
            Log.e(LOG_TAG, "No loaded session : reload them");
            startActivity(new Intent(HomeActivity.this, SplashActivity.class));
            HomeActivity.this.finish();
            return;
        }
    }

    for (MXSession session : sessions) {
        addSessionListener(session);
    }

    mMyRoomList.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
        @Override
        public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition,
                long id) {

            if (mAdapter.isRecentsGroupIndex(groupPosition)) {
                String roomId = null;
                MXSession session = null;

                RoomSummary roomSummary = mAdapter.getRoomSummaryAt(groupPosition, childPosition);
                session = Matrix.getInstance(HomeActivity.this).getSession(roomSummary.getMatrixId());

                roomId = roomSummary.getRoomId();
                Room room = session.getDataHandler().getRoom(roomId);
                // cannot join a leaving room
                if ((null == room) || room.isLeaving()) {
                    roomId = null;
                }

                if (mAdapter.resetUnreadCount(groupPosition, roomId)) {
                    session.getDataHandler().getStore().flushSummary(roomSummary);
                }

                if (null != roomId) {
                    CommonActivityUtils.goToRoomPage(session, roomId, HomeActivity.this, null);
                }

            } else if (mAdapter.isPublicsGroupIndex(groupPosition)) {
                joinPublicRoom(mAdapter.getHomeServerURLAt(groupPosition),
                        mAdapter.getPublicRoomAt(groupPosition, childPosition));
            }

            return true;
        }
    });

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

            if (ExpandableListView.getPackedPositionType(id) == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
                long packedPos = ((ExpandableListView) parent).getExpandableListPosition(position);
                final int groupPosition = ExpandableListView.getPackedPositionGroup(packedPos);

                if (mAdapter.isRecentsGroupIndex(groupPosition)) {
                    final int childPosition = ExpandableListView.getPackedPositionChild(packedPos);

                    FragmentManager fm = HomeActivity.this.getSupportFragmentManager();
                    IconAndTextDialogFragment fragment = (IconAndTextDialogFragment) fm
                            .findFragmentByTag(TAG_FRAGMENT_ROOM_OPTIONS);

                    if (fragment != null) {
                        fragment.dismissAllowingStateLoss();
                    }

                    final Integer[] lIcons = new Integer[] { R.drawable.ic_material_exit_to_app };
                    final Integer[] lTexts = new Integer[] { R.string.action_leave };

                    fragment = IconAndTextDialogFragment.newInstance(lIcons, lTexts, null,
                            HomeActivity.this.getResources().getColor(R.color.vector_title_color));
                    fragment.setOnClickListener(new IconAndTextDialogFragment.OnItemClickListener() {
                        @Override
                        public void onItemClick(IconAndTextDialogFragment dialogFragment, int position) {
                            Integer selectedVal = lTexts[position];

                            if (selectedVal == R.string.action_leave) {
                                HomeActivity.this.runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        final RoomSummary roomSummary = mAdapter.getRoomSummaryAt(groupPosition,
                                                childPosition);
                                        final MXSession roomSession = Matrix.getInstance(HomeActivity.this)
                                                .getSession(roomSummary.getMatrixId());

                                        String roomId = roomSummary.getRoomId();
                                        Room room = roomSession.getDataHandler().getRoom(roomId);

                                        if (null != room) {
                                            room.leave(new SimpleApiCallback<Void>(HomeActivity.this) {
                                                @Override
                                                public void onSuccess(Void info) {
                                                    mAdapter.removeRoomSummary(groupPosition, roomSummary);
                                                    mAdapter.notifyDataSetChanged();
                                                }
                                            });
                                        }
                                    }
                                });
                            }
                        }
                    });

                    fragment.show(fm, TAG_FRAGMENT_ROOM_OPTIONS);

                    return true;
                }
            }

            return false;
        }
    });

    mMyRoomList.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
        @Override
        public void onGroupExpand(int groupPosition) {
            if (mAdapter.isPublicsGroupIndex(groupPosition)) {
                refreshPublicRoomsList();
            }
        }
    });

    mMyRoomList.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
        @Override
        public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
            return mAdapter.getGroupCount() < 2;
        }
    });

    mSearchRoomEditText = (EditText) this.findViewById(R.id.editText_search_room);
    mSearchRoomEditText.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(android.text.Editable s) {
            mAdapter.setSearchedPattern(s.toString());
            mMyRoomList.smoothScrollToPosition(0);
        }

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

        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });
}