Search in sources :

Example 1 with GestureDetectorListenerAdapter

use of com.arlib.floatingsearchview.util.adapter.GestureDetectorListenerAdapter in project floatingsearchview by arimorty.

the class FloatingSearchView method setupSuggestionSection.

private void setupSuggestionSection() {
    LinearLayoutManager layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, true);
    mSuggestionsList.setLayoutManager(layoutManager);
    mSuggestionsList.setItemAnimator(null);
    final GestureDetector gestureDetector = new GestureDetector(getContext(), new GestureDetectorListenerAdapter() {

        @Override
        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
            if (mHostActivity != null) {
                Util.closeSoftKeyboard(mHostActivity);
            }
            return false;
        }
    });
    mSuggestionsList.addOnItemTouchListener(new OnItemTouchListenerAdapter() {

        @Override
        public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
            gestureDetector.onTouchEvent(e);
            return false;
        }
    });
    mSuggestionsAdapter = new SearchSuggestionsAdapter(getContext(), mSuggestionsTextSizePx, new SearchSuggestionsAdapter.Listener() {

        @Override
        public void onItemSelected(SearchSuggestion item) {
            mIsFocused = false;
            if (mSearchListener != null) {
                mSearchListener.onSuggestionClicked(item);
            }
            mSkipTextChangeEvent = true;
            if (mIsTitleSet) {
                setSearchBarTitle(item.getBody());
            } else {
                setSearchText(item.getBody());
            }
            setSearchFocusedInternal(false);
        }

        @Override
        public void onMoveItemToSearchClicked(SearchSuggestion item) {
            mSearchInput.setText(item.getBody());
            //move cursor to end of text
            mSearchInput.setSelection(mSearchInput.getText().length());
        }
    });
    refreshShowMoveUpSuggestion();
    mSuggestionsAdapter.setTextColor(this.mSuggestionTextColor);
    mSuggestionsAdapter.setRightIconColor(this.mSuggestionRightIconColor);
    mSuggestionsList.setAdapter(mSuggestionsAdapter);
    int cardViewBottomPadding = Util.dpToPx(CARD_VIEW_CORNERS_AND_TOP_BOTTOM_SHADOW_HEIGHT);
    //move up the suggestions section enough to cover the search bar
    //card's bottom left and right corners
    mSuggestionsSection.setTranslationY(-cardViewBottomPadding);
}
Also used : ViewPropertyAnimatorUpdateListener(android.support.v4.view.ViewPropertyAnimatorUpdateListener) SearchSuggestion(com.arlib.floatingsearchview.suggestions.model.SearchSuggestion) GestureDetectorListenerAdapter(com.arlib.floatingsearchview.util.adapter.GestureDetectorListenerAdapter) GestureDetector(android.view.GestureDetector) OnItemTouchListenerAdapter(com.arlib.floatingsearchview.util.adapter.OnItemTouchListenerAdapter) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) SearchSuggestionsAdapter(com.arlib.floatingsearchview.suggestions.SearchSuggestionsAdapter) MotionEvent(android.view.MotionEvent)

Aggregations

ViewPropertyAnimatorUpdateListener (android.support.v4.view.ViewPropertyAnimatorUpdateListener)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 GestureDetector (android.view.GestureDetector)1 MotionEvent (android.view.MotionEvent)1 SearchSuggestionsAdapter (com.arlib.floatingsearchview.suggestions.SearchSuggestionsAdapter)1 SearchSuggestion (com.arlib.floatingsearchview.suggestions.model.SearchSuggestion)1 GestureDetectorListenerAdapter (com.arlib.floatingsearchview.util.adapter.GestureDetectorListenerAdapter)1 OnItemTouchListenerAdapter (com.arlib.floatingsearchview.util.adapter.OnItemTouchListenerAdapter)1