/**
  * @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;
 }
    @Override
    public MaterialChip getChip(Suggestion suggestion) {
      final MaterialChip chip = new MaterialChip();

      String imageChip = suggestion.getDisplayString();
      String textChip = imageChip;

      String s = "<img src=\"";
      if (imageChip.contains(s)) {
        int ix = imageChip.indexOf(s) + s.length();
        imageChip = imageChip.substring(ix, imageChip.indexOf("\"", ix + 1));
        chip.setUrl(imageChip);
        textChip = textChip.replaceAll("[<](/)?img[^>]*[>]", "");
      }
      chip.setText(textChip);

      return chip;
    }
Пример #3
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();
    }
  }
Пример #4
0
        public void onSuggestionSelected(Suggestion s) {

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