@Override
    public void afterTextChanged(Editable s) {
      final String searchTerm = s.toString();

      if (searchTerm.length() > 0) {
        if (mHistoryRecyclerView != null) {
          mHistoryRecyclerView.setVisibility(View.GONE);
        }
        mSearchResultRecyclerView.setVisibility(View.VISIBLE);
      } else {
        mHandler.removeMessages(MESSAGE_TEXT_CHANGED);
        if (mHistoryRecyclerView != null) {
          mHistoryRecyclerView.setVisibility(View.VISIBLE);
        }
        mSearchResultRecyclerView.setVisibility(View.GONE);
        mProgressBar.hide();
      }

      if (TextUtils.getTrimmedLength(searchTerm) <= 1) {
        if (TextUtils.getTrimmedLength(searchTerm) == 0) {
          mSearchResultAdapter.clear();
        }
        mProgressBar.hide();
        return;
      }

      mProgressBar.show();
      mHandler.removeMessages(MESSAGE_TEXT_CHANGED);
      mHandler.sendMessageDelayed(
          mHandler.obtainMessage(MESSAGE_TEXT_CHANGED, searchTerm.trim()), AUTO_COMPLETE_DELAY);
    }
Exemplo n.º 2
0
 @Test
 public void testGetTrimmedLength() {
   assertThat(TextUtils.getTrimmedLength("123456"), equalTo(6));
   assertThat(TextUtils.getTrimmedLength(" \n \t 123456"), equalTo(6));
   assertThat(TextUtils.getTrimmedLength("123456  \n \t "), equalTo(6));
   assertThat(TextUtils.getTrimmedLength(" \n \t  123456  \n \t "), equalTo(6));
   assertThat(TextUtils.getTrimmedLength(" \n \t  \n \t "), equalTo(0));
 }
  /**
   * ********************************************************
   *
   * @return true if mApiKey is 32 alpha-numeric characters
   *     *******************************************************
   */
  private boolean apiKeyFormatValid() {
    if (TextUtils.isEmpty(mApiKey) || TextUtils.getTrimmedLength(mApiKey) != 32) {
      return false;
    }

    String isAlphaNumericPattern = "^[a-zA-Z0-9]*$";
    return mApiKey.matches(isAlphaNumericPattern);
  }
Exemplo n.º 4
0
 private void onSubmitQuery() {
   CharSequence query = mSearchEditText.getText();
   if (query != null && TextUtils.getTrimmedLength(query) > 0) {
     if (mOnQueryChangeListener == null
         || !mOnQueryChangeListener.onQueryTextSubmit(query.toString())) {
       closeSearch();
       mSearchEditText.setText(null);
     }
   }
 }
Exemplo n.º 5
0
  @Override
  public void onClick(View v) {
    switch (v.getId()) {
      case R.id.btn_sign_in:
        // Submit phone number and data

        boolean cancel = false;
        View focusView = null;
        String nameString = etName.getText().toString();
        String phoneString = etPhone.getText().toString();

        if (TextUtils.isEmpty(nameString) & TextUtils.isEmpty(phoneString)) {
          Snackbar.make(v, "Please enter your Alias and Phone Number", Snackbar.LENGTH_SHORT)
              .show();
          etName.setError("Name field cannot be empty");
          etPhone.setError("Phone Number cannot be empty");
        }
        if (TextUtils.isEmpty(phoneString)) {
          // show snackbar to enter credentials
          Snackbar.make(v, "Please enter your Phone Number", Snackbar.LENGTH_SHORT).show();
          etPhone.setError("Phone Number cannot be empty");
          focusView = etPhone;
          cancel = true;
          break;
        }

        if (!(TextUtils.getTrimmedLength(phoneString) > 10)) {
          Snackbar.make(v, "Phone Number Cannot be less than 11 characters", Snackbar.LENGTH_SHORT)
              .show();
          etPhone.setError("Invalid Phone Number");
          focusView = etPhone;
          cancel = true;
          break;
        }

        if (TextUtils.isEmpty(nameString)) {
          // show snackbar to enter credentials
          Snackbar.make(v, "Please enter your Alias or Name", Snackbar.LENGTH_SHORT).show();
          etName.setError("Invalid Name");
          focusView = etName;
          cancel = true;
          break;
        } else signIn();

        break;
    }
  }
Exemplo n.º 6
0
  /** @return true if a search was performed as a result of this click, false otherwise. */
  protected boolean onSearchClicked(int method) {
    String query = CharMatcher.WHITESPACE.trimAndCollapseFrom(getQuery(), ' ');
    if (DBG) Log.d(TAG, "Search clicked, query=" + query);

    // Don't do empty queries
    if (TextUtils.getTrimmedLength(query) == 0) return false;

    Corpus searchCorpus = getSearchCorpus();
    if (searchCorpus == null) return false;

    mTookAction = true;

    // Log search start
    getLogger().logSearch(getCorpus(), method, query.length());

    // Start search
    startSearch(searchCorpus, query);
    return true;
  }
Exemplo n.º 7
0
  private boolean validateForm() {

    boolean isFieldSet;

    if (TextUtils.isEmpty(emailLogin.getText().toString())) {
      emailLogin.setError(getString(R.string.txt_registrar_type_email));
      isFieldSet = false;
    } else if (!emailLogin.getText().toString().contains("@")) {
      emailLogin.setError(getString(R.string.txt_registrar_type_valid_email));
      isFieldSet = false;
    } else if (TextUtils.isEmpty(passwordLogin.getText().toString())) {
      passwordLogin.setError(getString(R.string.txt_registrar_type_password));
      isFieldSet = false;

    } else if (TextUtils.getTrimmedLength(passwordLogin.getText()) < 6) {
      passwordLogin.setError(getString(R.string.txt_registrar_min_chars_password));
      isFieldSet = false;
    } else {
      isFieldSet = true;
    }

    return isFieldSet;
  }
Exemplo n.º 8
0
 /** Returns true if the text field is empty, or contains only whitespace. */
 private boolean isEmpty() {
   return TextUtils.getTrimmedLength(getText()) == 0;
 }