use of com.arlib.floatingsearchview.util.adapter.OnItemTouchListenerAdapter 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);
}
Aggregations