/**
  * @return the item values on autocomplete
  * @see #getValue()
  */
 public List<String> getItemValues() {
   Set<Suggestion> keySet = suggestionMap.keySet();
   List<String> values = new ArrayList<>(keySet.size());
   for (Suggestion suggestion : keySet) {
     values.add(suggestion.getReplacementString());
   }
   return values;
 }
Exemplo n.º 2
0
  protected void complete(Suggestion suggestion, int cursorPosition) {
    SearchSuggestion searchSuggestion = extraSearchSuggestion(suggestion);
    String currentText = getText().toLowerCase();

    if (searchSuggestion.getKind() == SearchSuggestion.Kind.GlobalSavedSearch
        || searchSuggestion.getKind() == SearchSuggestion.Kind.UserSavedSearch) {
      // execute saved searches immediately, since they presumably constitute complete expressions
      Log.debug("selected '" + searchSuggestion.getLabel() + "' saved search suggestion");
      searchBar.activateSavedSearch(searchSuggestion.getValue());
    } else {
      // selecting a simple suggestion or advanced suggestion

      int previousWhitespaceIndex = cursorPosition;
      if (cursorPosition != 0) {
        while (--previousWhitespaceIndex > 0) {
          if (currentText.charAt(previousWhitespaceIndex) == ' ') {
            previousWhitespaceIndex++; // put index right after found whitespace
            break;
          }
        }
      }

      int futureWhitespaceIndex = cursorPosition;
      while (futureWhitespaceIndex < currentText.length()) {
        if (currentText.charAt(futureWhitespaceIndex) == ' ') {
          break;
        }
        futureWhitespaceIndex++;
      }

      String before = getText().substring(0, previousWhitespaceIndex);
      String completion = suggestion.getReplacementString();
      String after = getText().substring(futureWhitespaceIndex);

      setValue(before + completion + after, true);
      currentCursorPosition = before.length() + completion.length();
      getTextBox().setCursorPos(currentCursorPosition);

      showSuggestions();
    }
  }
Exemplo n.º 3
0
        public void onSuggestionSelected(Suggestion s) {

          String sugg = s.getReplacementString();
          autocomplete(sugg, true);
        }