Search in sources :

Example 1 with SearchTask

use of im.actor.sdk.controllers.pickers.file.search.SearchTask in project actor-platform by actorapp.

the class SearchFileFragment method onCreateOptionsMenu.

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.picker_search, menu);
    MenuItem searchMenuItem = menu.getItem(0);
    searchView = (SearchView) searchMenuItem.getActionView();
    searchView.setIconified(false);
    int searchPlateId = searchView.getContext().getResources().getIdentifier("android:id/search_plate", null, null);
    View searchPlate = searchView.findViewById(searchPlateId);
    if (searchPlate != null) {
        // searchPlate.setBackgroundColor(Color.DKGRAY);
        int searchTextId = searchPlate.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
        TextView searchText = (TextView) searchPlate.findViewById(searchTextId);
        if (searchText != null) {
            searchText.setTextColor(Color.WHITE);
            searchText.setHintTextColor(Color.WHITE);
        }
    }
    /*
        SearchViewHacker.setCloseIcon(searchView, R.drawable.bar_clear_search);
        SearchViewHacker.setIcon(searchView, R.drawable.picker_bar_search);
        SearchViewHacker.setText(searchView, getResources().getColor(R.color.picker_file_searchbox_focused_color));
        SearchViewHacker.setEditText(searchView, R.drawable.picker_search_text_box);
        SearchViewHacker.setHint(searchView, getString(R.string.picker_file_search_query_text), 0, getResources().getColor(R.color.picker_file_searchbox_hint_color), null);
        SearchViewHacker.disableMagIcon(searchView);
        */
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String s) {
            hideKeyBoard();
            return true;
        }

        @Override
        public boolean onQueryTextChange(String query) {
            if (query.equals("")) {
                SearchViewHacker.disableCloseButton(searchView);
                return true;
            } else {
                SearchViewHacker.setCloseIcon(searchView, R.drawable.bar_clear_search);
            }
            SearchFileFragment.this.query = query;
            if (searchingTask != null) {
                searchingTask.cancel(true);
                searchingTask = null;
            }
            File rootFile = new File(root);
            if (root == null || root.equals("")) {
                rootFile = null;
            }
            // progress.show();
            searchingTask = new SearchTask(rootFile, query, index) {

                @Override
                public void onSearchEnded(final ArrayList<ExplorerItem> files) {
                    searchingTask = null;
                    // progress.hide();
                    if (files.isEmpty()) {
                        status.setVisibility(View.VISIBLE);
                        status.setText(R.string.picker_empty);
                        items.clear();
                        adapter.notifyDataSetChanged();
                    // listView.setVisibility(View.GONE);
                    } else {
                        showItems(files);
                    /*
                            AnimationSet outAnimation = new AnimationSet(true);
                            outAnimation.addAnimation(new TranslateAnimation(0, 0, 100, 0));
                            outAnimation.addAnimation(new AlphaAnimation(0,1));
                            outAnimation.setDuration(350);
                            outAnimation.setInterpolator(new MaterialInterpolator());
                            outAnimation.setAnimationListener(new Animation.AnimationListener() {
                                @Override
                                public void onAnimationStart(Animation animation) {
                                    animated = true;
                                }

                                @Override
                                public void onAnimationEnd(Animation animation) {
                                    animated = false;
                                }

                                @Override
                                public void onAnimationRepeat(Animation animation) {

                                }
                            });
                            listView.startAnimation(outAnimation);*/
                    }
                }
            };
            if (indexingTask == null || !index.isEmpty()) {
                searchingTask.execute();
            }
            return false;
        }
    });
    searchView.setOnCloseListener(new SearchView.OnCloseListener() {

        @Override
        public boolean onClose() {
            hideKeyBoard();
            getActivity().onBackPressed();
            return false;
        }
    });
    searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {

        @Override
        public void onFocusChange(View view, boolean b) {
            if (searchView.getQuery().length() == 0) {
                searchView.postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        SearchViewHacker.disableCloseButton(searchView);
                    }
                }, 0);
                SearchViewHacker.disableCloseButton(searchView);
            } else
                SearchViewHacker.setCloseIcon(searchView, R.drawable.bar_clear_search);
        }
    });
    searchView.requestFocusFromTouch();
    SearchViewHacker.disableCloseButton(searchView);
    InputMethodManager inputMethodManager = (InputMethodManager) pickerActivity.getSystemService(Context.INPUT_METHOD_SERVICE);
    inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
    if (query != null) {
        searchView.setQuery(query, false);
    }
}
Also used : ArrayList(java.util.ArrayList) MenuItem(android.view.MenuItem) InputMethodManager(android.view.inputmethod.InputMethodManager) SearchView(android.support.v7.widget.SearchView) View(android.view.View) AbsListView(android.widget.AbsListView) TextView(android.widget.TextView) ListView(android.widget.ListView) SearchView(android.support.v7.widget.SearchView) SearchTask(im.actor.sdk.controllers.pickers.file.search.SearchTask) TextView(android.widget.TextView) File(java.io.File)

Aggregations

SearchView (android.support.v7.widget.SearchView)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 InputMethodManager (android.view.inputmethod.InputMethodManager)1 AbsListView (android.widget.AbsListView)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 SearchTask (im.actor.sdk.controllers.pickers.file.search.SearchTask)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1