Search in sources :

Example 1 with SearchView

use of com.lapism.searchview.view.SearchView in project Talon-for-Twitter by klinker24.

the class GiphySearch method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    try {
        getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    } catch (Exception e) {
    }
    setContentView(R.layout.giffy_search_activity);
    recycler = (RecyclerView) findViewById(R.id.recycler_view);
    progressSpinner = findViewById(R.id.list_progress);
    backArrow = (ImageView) findViewById(R.id.imageView_arrow_back);
    toolbar = (SearchView) findViewById(R.id.searchView);
    searchText = (EditText) findViewById(R.id.editText_input);
    final ArrowDrawable drawable = new ArrowDrawable(this);
    drawable.animate(ArrowDrawable.STATE_ARROW);
    backArrow.setImageDrawable(drawable);
    toolbar.setOnSearchMenuListener(new SearchView.SearchMenuListener() {

        @Override
        public void onMenuClick() {
            setResult(Activity.RESULT_CANCELED);
            finish();
        }
    });
    toolbar.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {
            executeQuery(query);
            backArrow.performClick();
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            return false;
        }
    });
    recycler.setOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            adapter.releaseVideo();
        }
    });
    new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {
            drawable.animate(ArrowDrawable.STATE_ARROW);
            loadTrending();
        }
    }, 750);
}
Also used : ArrowDrawable(com.lapism.arrow.ArrowDrawable) SearchView(com.lapism.searchview.view.SearchView) Handler(android.os.Handler) RecyclerView(android.support.v7.widget.RecyclerView)

Example 2 with SearchView

use of com.lapism.searchview.view.SearchView 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

SearchView (com.lapism.searchview.view.SearchView)2 Handler (android.os.Handler)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 ArrowDrawable (com.lapism.arrow.ArrowDrawable)1 SearchAdapter (com.lapism.searchview.adapter.SearchAdapter)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