Search in sources :

Example 1 with SearchAdapter

use of com.lapism.searchview.adapter.SearchAdapter in project AisenWeiBo by wangdan.

the class SearchFragment method setupSearchView.

private void setupSearchView() {
    // SearchView basic attributes  ------------------------------------------------------------
    int mVersion = SearchCodes.VERSION_MENU_ITEM;
    int mStyle = SearchCodes.STYLE_MENU_ITEM_CLASSIC;
    int mTheme = SearchCodes.THEME_LIGHT;
    mSearchView.setVersion(mVersion);
    mSearchView.setStyle(mStyle);
    mSearchView.setTheme(mTheme);
    mSearchView.setDivider(false);
    mSearchView.setHint(R.string.search_hint);
    mSearchView.setHintSize(getResources().getDimension(R.dimen.search_text_medium));
    mSearchView.setVoice(false);
    mSearchView.setAnimationDuration(300);
    mSearchView.setShadowColor(ContextCompat.getColor(getActivity(), R.color.background_dim_overlay));
    mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {
            if (!TextUtils.isEmpty(query)) {
                onQuery(query);
            }
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            if (suggestList != null && searchAdapter != null)
                onQuerySuggestChange(newText);
            return true;
        }
    });
    mSearchView.setOnSearchViewListener(new SearchView.SearchViewListener() {

        @Override
        public void onSearchViewShown() {
        }

        @Override
        public void onSearchViewClosed() {
            if (getSwipeRefreshLayout().getVisibility() == View.VISIBLE) {
                getSwipeRefreshLayout().setVisibility(View.GONE);
            }
            getActivity().finish();
            getActivity().overridePendingTransition(0, 0);
        }
    });
    try {
        Field editField = SearchView.class.getDeclaredField("mEditText");
        editField.setAccessible(true);
        editSearch = (EditText) editField.get(mSearchView);
        editSearch.setOnFocusChangeListener(new View.OnFocusChangeListener() {

            @Override
            public void onFocusChange(View v, boolean hasFocus) {
            }
        });
        Field shadowField = SearchView.class.getDeclaredField("mShadow");
        shadowField.setAccessible(true);
        shadowView = (View) shadowField.get(mSearchView);
    } catch (Exception e) {
        e.printStackTrace();
    }
    suggestList = new ArrayList<>();
    //        searchAdapter = new SearchAdapter(getActivity(), new ArrayList<SearchItem>(), suggestList, SearchCodes.THEME_LIGHT);
    searchAdapter = new SearchsSuggestAdapter(getActivity(), new ArrayList<SearchItem>(), suggestList, SearchCodes.THEME_LIGHT);
    searchAdapter.setOnItemClickListener(new SearchAdapter.OnItemClickListener() {

        @Override
        public void onItemClick(View view, int position) {
            if (suggestList.size() > position) {
                onQuery(suggestList.get(position).get_text().toString());
                editSearch.setText(q);
                editSearch.setSelection(q.length());
            }
        }
    });
    mSearchView.setAdapter(searchAdapter);
    if (!TextUtils.isEmpty(q))
        mSearchView.setQuery(q);
    mSearchView.show(true);
    searchIn();
}
Also used : SearchAdapter(com.lapism.searchview.adapter.SearchAdapter) ArrayList(java.util.ArrayList) IITemView(org.aisen.android.ui.fragment.itemview.IITemView) View(android.view.View) SearchView(com.lapism.searchview.view.SearchView) TaskException(org.aisen.android.network.task.TaskException) Field(java.lang.reflect.Field) SearchView(com.lapism.searchview.view.SearchView)

Aggregations

View (android.view.View)1 SearchAdapter (com.lapism.searchview.adapter.SearchAdapter)1 SearchView (com.lapism.searchview.view.SearchView)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 TaskException (org.aisen.android.network.task.TaskException)1 IITemView (org.aisen.android.ui.fragment.itemview.IITemView)1