예제 #1
0
  private void initiateView() {
    LayoutInflater.from(mContext).inflate((R.layout.search_view), this, true);

    mSearchLayout = findViewById(R.id.search_layout);
    mCardView = (CardView) mSearchLayout.findViewById(R.id.cardView);

    LinearLayoutManager layoutManager =
        new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false);
    mSuggestionsRecyclerView = (RecyclerView) mSearchLayout.findViewById(R.id.recyclerView);
    mSuggestionsRecyclerView.setLayoutManager(layoutManager);
    mSuggestionsRecyclerView.setItemAnimator(new DefaultItemAnimator());
    mSuggestionsRecyclerView.setVisibility(GONE);

    mSearchEditText = (EditText) mSearchLayout.findViewById(R.id.editText_input);
    mBackImageView = (ImageView) mSearchLayout.findViewById(R.id.imageView_arrow_back);
    mVoiceImageView = (ImageView) mSearchLayout.findViewById(R.id.imageView_mic);
    mEmptyImageView = (ImageView) mSearchLayout.findViewById(R.id.imageView_clear); // CLEAR
    mTintView = mSearchLayout.findViewById(R.id.view_transparent);
    mSeparatorView = mSearchLayout.findViewById(R.id.view_separator);

    mSearchEditText.setOnClickListener(mOnClickListener);
    mBackImageView.setOnClickListener(mOnClickListener);
    mVoiceImageView.setOnClickListener(mOnClickListener);
    mEmptyImageView.setOnClickListener(mOnClickListener);
    mTintView.setOnClickListener(mOnClickListener);
    mSeparatorView.setVisibility(GONE);

    showVoice(true);
    initSearchView();
  }
예제 #2
0
  private void onTextChanged(CharSequence newText) {
    CharSequence text = mSearchEditText.getText();
    mUserQuery = text;
    boolean hasText = !TextUtils.isEmpty(text);
    if (hasText) {
      mEmptyImageView.setVisibility(VISIBLE);
      showVoice(false);
    } else {
      mEmptyImageView.setVisibility(GONE);
      showVoice(true);
    }

    if (mOnQueryChangeListener != null && !TextUtils.equals(newText, mOldQueryText)) {
      mOnQueryChangeListener.onQueryTextChange(newText.toString());
    }
    mOldQueryText = newText.toString();
  }