Search in sources :

Example 1 with FloatingSearchView

use of com.mypopsy.widget.FloatingSearchView in project FloatingSearchView by renaudcerrato.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    DaggerAppComponent.builder().build().inject(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mSearch.setListener(this);
    mSearchView = (FloatingSearchView) findViewById(R.id.search);
    mSearchView.setAdapter(mAdapter = new SearchAdapter());
    mSearchView.showLogo(true);
    mSearchView.setItemAnimator(new CustomSuggestionItemAnimator(mSearchView));
    updateNavigationIcon(R.id.menu_icon_search);
    mSearchView.showIcon(shouldShowNavigationIcon());
    mSearchView.setOnIconClickListener(new FloatingSearchView.OnIconClickListener() {

        @Override
        public void onNavigationClick() {
            // toggle
            mSearchView.setActivated(!mSearchView.isActivated());
        }
    });
    mSearchView.setOnSearchListener(new FloatingSearchView.OnSearchListener() {

        @Override
        public void onSearchAction(CharSequence text) {
            mSearchView.setActivated(false);
        }
    });
    mSearchView.setOnMenuItemClickListener(this);
    mSearchView.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence query, int start, int before, int count) {
            showClearButton(query.length() > 0 && mSearchView.isActivated());
            search(query.toString().trim());
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });
    mSearchView.setOnSearchFocusChangedListener(new FloatingSearchView.OnSearchFocusChangedListener() {

        @Override
        public void onFocusChanged(final boolean focused) {
            boolean textEmpty = mSearchView.getText().length() == 0;
            showClearButton(focused && !textEmpty);
            if (!focused)
                showProgressBar(false);
            mSearchView.showLogo(!focused && textEmpty);
            if (focused)
                mSearchView.showIcon(true);
            else
                mSearchView.showIcon(shouldShowNavigationIcon());
        }
    });
    mSearchView.setText(null);
}
Also used : TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) FloatingSearchView(com.mypopsy.widget.FloatingSearchView)

Aggregations

Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 FloatingSearchView (com.mypopsy.widget.FloatingSearchView)1