use of com.arlib.floatingsearchview.util.adapter.TextWatcherAdapter in project floatingsearchview by arimorty.
the class FloatingSearchView method setupQueryBar.
private void setupQueryBar() {
mSearchInput.setTextColor(mSearchInputTextColor);
mSearchInput.setHintTextColor(mSearchInputHintColor);
if (!isInEditMode() && mHostActivity != null) {
mHostActivity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
}
ViewTreeObserver vto = mQuerySection.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Util.removeGlobalLayoutObserver(mQuerySection, this);
inflateOverflowMenu(mMenuId);
}
});
mMenuView.setMenuCallback(new MenuBuilder.Callback() {
@Override
public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) {
if (mActionMenuItemListener != null) {
mActionMenuItemListener.onActionMenuItemSelected(item);
}
// todo check if we should care about this return or not
return false;
}
@Override
public void onMenuModeChange(MenuBuilder menu) {
}
});
mMenuView.setOnVisibleWidthChanged(new MenuView.OnVisibleWidthChangedListener() {
@Override
public void onItemsMenuVisibleWidthChanged(int newVisibleWidth) {
handleOnVisibleMenuItemsWidthChanged(newVisibleWidth);
}
});
mMenuView.setActionIconColor(mActionMenuItemColor);
mMenuView.setOverflowColor(mOverflowIconColor);
mClearButton.setVisibility(View.INVISIBLE);
mClearButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mSearchInput.setText("");
if (mOnClearSearchActionListener != null) {
mOnClearSearchActionListener.onClearSearchClicked();
}
}
});
mSearchInput.addTextChangedListener(new TextWatcherAdapter() {
public void onTextChanged(final CharSequence s, int start, int before, int count) {
if (mSkipTextChangeEvent || !mIsFocused) {
mSkipTextChangeEvent = false;
} else {
if (mSearchInput.getText().toString().length() != 0 && mClearButton.getVisibility() == View.INVISIBLE) {
mClearButton.setAlpha(0.0f);
mClearButton.setVisibility(View.VISIBLE);
ViewCompat.animate(mClearButton).alpha(1.0f).setDuration(CLEAR_BTN_FADE_ANIM_DURATION).start();
} else if (mSearchInput.getText().toString().length() == 0) {
mClearButton.setVisibility(View.INVISIBLE);
}
if (mQueryListener != null && mIsFocused && !mOldQuery.equals(mSearchInput.getText().toString())) {
mQueryListener.onSearchTextChanged(mOldQuery, mSearchInput.getText().toString());
}
}
mOldQuery = mSearchInput.getText().toString();
}
});
mSearchInput.setOnFocusChangeListener(new TextView.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (mSkipQueryFocusChangeEvent) {
mSkipQueryFocusChangeEvent = false;
} else if (hasFocus != mIsFocused) {
setSearchFocusedInternal(hasFocus);
}
}
});
mSearchInput.setOnKeyboardDismissedListener(new SearchInputView.OnKeyboardDismissedListener() {
@Override
public void onKeyboardDismissed() {
if (mCloseSearchOnSofteKeyboardDismiss) {
setSearchFocusedInternal(false);
}
}
});
mSearchInput.setOnSearchKeyListener(new SearchInputView.OnKeyboardSearchKeyClickListener() {
@Override
public void onSearchKeyClicked() {
if (mSearchListener != null) {
mSearchListener.onSearchAction(getQuery());
}
mSkipTextChangeEvent = true;
mSkipTextChangeEvent = true;
if (mIsTitleSet) {
setSearchBarTitle(getQuery());
} else {
setSearchText(getQuery());
}
setSearchFocusedInternal(false);
}
});
mLeftAction.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (isSearchBarFocused()) {
setSearchFocusedInternal(false);
} else {
switch(mLeftActionMode) {
case LEFT_ACTION_MODE_SHOW_HAMBURGER:
if (mLeftMenuClickListener != null) {
mLeftMenuClickListener.onClick(mLeftAction);
} else {
toggleLeftMenu();
}
break;
case LEFT_ACTION_MODE_SHOW_SEARCH:
setSearchFocusedInternal(true);
break;
case LEFT_ACTION_MODE_SHOW_HOME:
if (mOnHomeActionClickListener != null) {
mOnHomeActionClickListener.onHomeClicked();
}
break;
case LEFT_ACTION_MODE_NO_LEFT_ACTION:
// do nothing
break;
}
}
}
});
refreshLeftIcon();
}
Aggregations