Java Code Examples for android.text.method.QwertyKeyListener

The following are top voted examples for showing how to use android.text.method.QwertyKeyListener. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: talk-android   File: RecipientEditTextView.java   Source Code and License 6 votes vote down vote up
private void handleEdit(int start, int end) {
    if (start == -1 || end == -1) {
        // This chip no longer exists in the field.
        dismissDropDown();
        return;
    }
    // This is in the middle of a chip, so select out the whole chip
    // and commit it.
    Editable editable = getText();
    setSelection(end);
    String text = getText().toString().substring(start, end);
    if (!TextUtils.isEmpty(text)) {
        RecipientEntry entry = RecipientEntry.constructFakeEntry(text, isValid(text));
        QwertyKeyListener.markAsReplaced(editable, start, end, "");
        CharSequence chipText = createChip(entry, false);
        int selEnd = getSelectionEnd();
        if (chipText != null && start > -1 && selEnd > -1) {
            editable.replace(start, selEnd, chipText);
        }
    }
    dismissDropDown();
}
 
Example 2
Project: talk-android   File: RecipientEditTextView.java   Source Code and License 6 votes vote down vote up
private void submitItem(RecipientEntry entry) {
    if (entry == null) {
        return;
    }
    clearComposingText();

    int end = getSelectionEnd();
    int start = mTokenizer.findTokenStart(getText(), end);

    Editable editable = getText();
    QwertyKeyListener.markAsReplaced(editable, start, end, "");
    CharSequence chip = createChip(entry, false);
    if (chip != null && start >= 0 && end >= 0) {
        editable.replace(start, end, chip);
    }
    sanitizeBetween();
}
 
Example 3
Project: talk-android   File: TextChipsEditView.java   Source Code and License 6 votes vote down vote up
private void handleEdit(int start, int end) {
    if (start == -1 || end == -1) {
        // This chip no longer exists in the field.
        dismissDropDown();
        return;
    }
    // This is in the middle of a chip, so select out the whole chip
    // and commit it.
    Editable editable = getText();
    setSelection(end);
    String text = getText().toString().substring(start, end);
    if (!TextUtils.isEmpty(text)) {
        RecipientEntry entry = RecipientEntry.constructFakeEntry(text, isValid(text));
        QwertyKeyListener.markAsReplaced(editable, start, end, "");
        CharSequence chipText = createChip(entry, false);
        int selEnd = getSelectionEnd();
        if (chipText != null && start > -1 && selEnd > -1) {
            editable.replace(start, selEnd, chipText);
        }
    }
    dismissDropDown();
}
 
Example 4
Project: talk-android   File: TextChipsEditView.java   Source Code and License 6 votes vote down vote up
private void submitItem(RecipientEntry entry) {
    if (entry == null) {
        return;
    }
    clearComposingText();

    int end = getSelectionEnd();
    int start = mTokenizer.findTokenStart(getText(), end);

    Editable editable = getText();
    QwertyKeyListener.markAsReplaced(editable, start, end, "");
    CharSequence chip = createChip(entry, false);
    if (chip != null && start >= 0 && end >= 0) {
        editable.replace(start, end, chip);
    }
    sanitizeBetween();
}
 
Example 5
Project: talk-android   File: TextChipsEditView.java   Source Code and License 6 votes vote down vote up
/**
 * Remove selection from this chip. Unselecting a RecipientChip will render
 * the chip without a delete icon and with an unfocused background. This is
 * called when the RecipientChip no longer has focus.
 */
private void unselectChip(DrawableRecipientChip chip) {
    int start = getChipStart(chip);
    int end = getChipEnd(chip);
    Editable editable = getText();
    mSelectedChip = null;
    if (start == -1 || end == -1) {
        Log.w(TAG, "The chip doesn't exist or may be a chip a user was editing");
        setSelection(editable.length());
        commitDefault();
    } else {
        getSpannable().removeSpan(chip);
        QwertyKeyListener.markAsReplaced(editable, start, end, "");
        editable.removeSpan(chip);
        try {
            if (!mNoChips) {
                editable.setSpan(constructChipSpan(chip.getEntry(), false, false),
                        start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        } catch (NullPointerException e) {
            Log.e(TAG, e.getMessage(), e);
        }
    }
    setCursorVisible(true);
    setSelection(editable.length());
}
 
Example 6
Project: sms_DualCard   File: RecipientEditTextView.java   Source Code and License 6 votes vote down vote up
private void handleEdit(int start, int end) {
    if (start == -1 || end == -1) {
        // This chip no longer exists in the field.
        dismissDropDown();
        return;
    }
    // This is in the middle of a chip, so select out the whole chip
    // and commit it.
    Editable editable = getText();
    setSelection(end);
    String text = getText().toString().substring(start, end);
    if (!TextUtils.isEmpty(text)) {
        RecipientEntry entry = RecipientEntry.constructFakeEntry(text);
        QwertyKeyListener.markAsReplaced(editable, start, end, "");
        CharSequence chipText = createChip(entry, false);
        int selEnd = getSelectionEnd();
        if (chipText != null && start > -1 && selEnd > -1) {
            editable.replace(start, selEnd, chipText);
        }
    }
    dismissDropDown();
}
 
Example 7
Project: sms_DualCard   File: RecipientEditTextView.java   Source Code and License 6 votes vote down vote up
private void submitItemAtPosition(int position) {
    RecipientEntry entry = createValidatedEntry(
            (RecipientEntry)getAdapter().getItem(position));
    if (entry == null) {
        return;
    }
    clearComposingText();

    int end = getSelectionEnd();
    int start = mTokenizer.findTokenStart(getText(), end);

    Editable editable = getText();
    QwertyKeyListener.markAsReplaced(editable, start, end, "");
    CharSequence chip = createChip(entry, false);
    if (chip != null && start >= 0 && end >= 0) {
        editable.replace(start, end, chip);
    }
    sanitizeBetween();
}
 
Example 8
Project: android-chip-edittextview   File: ChipEditTextView.java   Source Code and License 6 votes vote down vote up
private void handleEdit(int start, int end) {
    if (start == -1 || end == -1) {
        // This chip no longer exists in the field.
        dismissDropDown();
        return;
    }
    // This is in the middle of a chip, so select out the whole chip
    // and commit it.
    Editable editable = getText();
    setSelection(end);
    String text = getText().toString().substring(start, end);
    if (!TextUtils.isEmpty(text)) {

        QwertyKeyListener.markAsReplaced(editable, start, end, "");
        CharSequence chipText = createChip(text, false);
        int selEnd = getSelectionEnd();
        if (chipText != null && start > -1 && selEnd > -1) {
            editable.replace(start, selEnd, chipText);
        }
    }
    dismissDropDown();
}
 
Example 9
Project: android-chip-edittextview   File: ChipEditTextView.java   Source Code and License 6 votes vote down vote up
private void submitItemAtPosition(int position) {
    CharSequence text = getFilter().convertResultToString(
    		getAdapter().getItem(position));

    if (TextUtils.isEmpty(text)) {
        return;
    }
    
    clearComposingText();

    int end = getSelectionEnd();
    int start = mTokenizer.findTokenStart(getText(), end);

    Editable editable = getText();
    QwertyKeyListener.markAsReplaced(editable, start, end, "");
    CharSequence chip = createChip(text, false);
    if (chip != null && start >= 0 && end >= 0) {
        editable.replace(start, end, chip);
    }
    sanitizeBetween();
}
 
Example 10
Project: ChipsLibrary   File: RecipientEditTextView.java   Source Code and License 6 votes vote down vote up
private void handleEdit(final int start,final int end)
{
if(start==-1||end==-1)
  {
  // This chip no longer exists in the field.
  dismissDropDown();
  return;
  }
// This is in the middle of a chip, so select out the whole chip
// and commit it.
final Editable editable=getText();
setSelection(end);
final String text=getText().toString().substring(start,end);
if(!TextUtils.isEmpty(text))
  {
  final RecipientEntry entry=RecipientEntry.constructFakeEntry(text,isValid(text));
  QwertyKeyListener.markAsReplaced(editable,start,end,"");
  final CharSequence chipText=createChip(entry,false);
  final int selEnd=getSelectionEnd();
  if(chipText!=null&&start>-1&&selEnd>-1)
    editable.replace(start,selEnd,chipText);
  }
dismissDropDown();
}
 
Example 11
Project: ChipsLibrary   File: RecipientEditTextView.java   Source Code and License 6 votes vote down vote up
private void submitItemAtPosition(final int position)
{
final RecipientEntry entry=createValidatedEntry(getAdapter().getItem(position));
if(entry==null)
  return;
clearComposingText();
final int end=getSelectionEnd();
final int start=mTokenizer.findTokenStart(getText(),end);
final Editable editable=getText();
QwertyKeyListener.markAsReplaced(editable,start,end,"");
final CharSequence chip=createChip(entry,false);
if(chip!=null&&start>=0&&end>=0)
  editable.replace(start,end,chip);
sanitizeBetween();
if(mChipListener!=null)
  mChipListener.onDataChanged();
}
 
Example 12
Project: Calendar_lunar   File: RecipientEditTextView.java   Source Code and License 6 votes vote down vote up
private void handleEdit(int start, int end) {
    if (start == -1 || end == -1) {
        // This chip no longer exists in the field.
        dismissDropDown();
        return;
    }
    // This is in the middle of a chip, so select out the whole chip
    // and commit it.
    Editable editable = getText();
    setSelection(end);
    String text = getText().toString().substring(start, end);
    if (!TextUtils.isEmpty(text)) {
        RecipientEntry entry = RecipientEntry.constructFakeEntry(text);
        QwertyKeyListener.markAsReplaced(editable, start, end, "");
        CharSequence chipText = createChip(entry, false);
        int selEnd = getSelectionEnd();
        if (chipText != null && start > -1 && selEnd > -1) {
            editable.replace(start, selEnd, chipText);
        }
    }
    dismissDropDown();
}
 
Example 13
Project: Calendar_lunar   File: RecipientEditTextView.java   Source Code and License 6 votes vote down vote up
private void submitItemAtPosition(int position) {
    RecipientEntry entry = createValidatedEntry(
            (RecipientEntry)getAdapter().getItem(position));
    if (entry == null) {
        return;
    }
    clearComposingText();

    int end = getSelectionEnd();
    int start = mTokenizer.findTokenStart(getText(), end);

    Editable editable = getText();
    QwertyKeyListener.markAsReplaced(editable, start, end, "");
    CharSequence chip = createChip(entry, false);
    if (chip != null && start >= 0 && end >= 0) {
        editable.replace(start, end, chip);
    }
    sanitizeBetween();
}
 
Example 14
Project: talk-android   File: RecipientEditTextView.java   Source Code and License 5 votes vote down vote up
private boolean commitChip(int start, int end, Editable editable) {
    ListAdapter adapter = getAdapter();
    if (adapter != null && adapter.getCount() > 0 && enoughToFilter()
            && end == getSelectionEnd() && !isPhoneQuery()) {
        // choose the first entry.
        submitItemAtPosition(0);
        dismissDropDown();
        return true;
    } else {
        int tokenEnd = mTokenizer.findTokenEnd(editable, start);
        if (editable.length() > tokenEnd + 1) {
            char charAt = editable.charAt(tokenEnd + 1);
            if (charAt == COMMIT_CHAR_COMMA || charAt == COMMIT_CHAR_SEMICOLON) {
                tokenEnd++;
            }
        }
        String text = editable.toString().substring(start, tokenEnd).trim();
        clearComposingText();
        if (text != null && text.length() > 0 && !text.equals(" ")) {
            RecipientEntry entry = createTokenizedEntry(text);
            if (entry != null) {
                QwertyKeyListener.markAsReplaced(editable, start, end, "");
                CharSequence chipText = createChip(entry, false);
                if (chipText != null && start > -1 && end > -1) {
                    editable.replace(start, end, chipText);
                }
            }
            // Only dismiss the dropdown if it is related to the text we
            // just committed.
            // For paste, it may not be as there are possibly multiple
            // tokens being added.
            if (end == getSelectionEnd()) {
                dismissDropDown();
            }
            sanitizeBetween();
            return true;
        }
    }
    return false;
}
 
Example 15
Project: talk-android   File: RecipientEditTextView.java   Source Code and License 5 votes vote down vote up
/**
 * Remove selection from this chip. Unselecting a RecipientChip will render
 * the chip without a delete icon and with an unfocused background. This is
 * called when the RecipientChip no longer has focus.
 */
private void unselectChip(DrawableRecipientChip chip) {
    int start = getChipStart(chip);
    int end = getChipEnd(chip);
    Editable editable = getText();
    mSelectedChip = null;
    if (start == -1 || end == -1) {
        Log.w(TAG, "The chip doesn't exist or may be a chip a user was editing");
        setSelection(editable.length());
        commitDefault();
    } else {
        getSpannable().removeSpan(chip);
        QwertyKeyListener.markAsReplaced(editable, start, end, "");
        editable.removeSpan(chip);
        try {
            if (!mNoChips) {
                editable.setSpan(constructChipSpan(chip.getEntry(), false, false),
                        start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        } catch (NullPointerException e) {
            Log.e(TAG, e.getMessage(), e);
        }
    }
    setCursorVisible(true);
    setSelection(editable.length());
    if (mAlternatesPopup != null && mAlternatesPopup.isShowing()) {
        mAlternatesPopup.dismiss();
    }
}
 
Example 16
Project: talk-android   File: TextChipsEditView.java   Source Code and License 5 votes vote down vote up
private boolean commitChip(int start, int end, Editable editable) {
    ListAdapter adapter = getAdapter();
    if (adapter != null && adapter.getCount() > 0 && enoughToFilter()
            && end == getSelectionEnd() && !isPhoneQuery()) {
        // choose the first entry.
        submitItemAtPosition(0);
        dismissDropDown();
        return true;
    } else {
        int tokenEnd = mTokenizer.findTokenEnd(editable, start);
        if (editable.length() > tokenEnd + 1) {
            char charAt = editable.charAt(tokenEnd + 1);
            if (charAt == COMMIT_CHAR_COMMA || charAt == COMMIT_CHAR_SEMICOLON) {
                tokenEnd++;
            }
        }
        String text = editable.toString().substring(start, tokenEnd).trim();
        clearComposingText();
        if (text != null && text.length() > 0 && !text.equals(" ")) {
            RecipientEntry entry = createTokenizedEntry(text);
            if (entry != null) {
                QwertyKeyListener.markAsReplaced(editable, start, end, "");
                CharSequence chipText = createChip(entry, false);
                if (chipText != null && start > -1 && end > -1) {
                    editable.replace(start, end, chipText);
                }
            }
            // Only dismiss the dropdown if it is related to the text we
            // just committed.
            // For paste, it may not be as there are possibly multiple
            // tokens being added.
            if (end == getSelectionEnd()) {
                dismissDropDown();
            }
            sanitizeBetween();
            return true;
        }
    }
    return false;
}
 
Example 17
Project: yelo-android   File: TokenCompleteTextView.java   Source Code and License 5 votes vote down vote up
@Override
protected void replaceText(CharSequence text) {
    clearComposingText();
    SpannableStringBuilder ssb = buildSpannableForText(text);
    TokenImageSpan tokenSpan = buildSpanForObject(selectedObject);

    Editable editable = getText();
    int end = getSelectionEnd();
    int start = tokenizer.findTokenStart(editable, end);
    if (start < prefix.length()) {
        start = prefix.length();
    }
    String original = TextUtils.substring(editable, start, end);

    if (editable != null) {
        if (tokenSpan == null) {
            editable.replace(start, end, " ");
        } else if (!allowDuplicates && objects.contains(tokenSpan.getToken())) {
            editable.replace(start, end, " ");
        } else {
            QwertyKeyListener.markAsReplaced(editable, start, end, original);
            editable.replace(start, end, ssb);
            editable.setSpan(tokenSpan, start, start + ssb.length() - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            //spanWatcher.onSpanAdded(editable, tokenSpan, start, start + ssb.length() - 1);
        }
    }
}
 
Example 18
Project: sms_DualCard   File: RecipientEditTextView.java   Source Code and License 5 votes vote down vote up
private boolean commitChip(int start, int end, Editable editable) {
    ListAdapter adapter = getAdapter();
    if (adapter != null && adapter.getCount() > 0 && enoughToFilter()
            && end == getSelectionEnd() && !isPhoneQuery()) {
        // choose the first entry.
        submitItemAtPosition(0);
        dismissDropDown();
        return true;
    } else {
        int tokenEnd = mTokenizer.findTokenEnd(editable, start);
        if (editable.length() > tokenEnd + 1) {
            char charAt = editable.charAt(tokenEnd + 1);
            if (charAt == COMMIT_CHAR_COMMA || charAt == COMMIT_CHAR_SEMICOLON) {
                tokenEnd++;
            }
        }
        String text = editable.toString().substring(start, tokenEnd).trim();
        clearComposingText();
        if (text != null && text.length() > 0 && !text.equals(" ")) {
            RecipientEntry entry = createTokenizedEntry(text);
            if (entry != null) {
                QwertyKeyListener.markAsReplaced(editable, start, end, "");
                CharSequence chipText = createChip(entry, false);
                if (chipText != null && start > -1 && end > -1) {
                    editable.replace(start, end, chipText);
                }
            }
            // Only dismiss the dropdown if it is related to the text we
            // just committed.
            // For paste, it may not be as there are possibly multiple
            // tokens being added.
            if (end == getSelectionEnd()) {
                dismissDropDown();
            }
            sanitizeBetween();
            return true;
        }
    }
    return false;
}
 
Example 19
Project: sms_DualCard   File: RecipientEditTextView.java   Source Code and License 5 votes vote down vote up
/**
 * Remove selection from this chip. Unselecting a RecipientChip will render
 * the chip without a delete icon and with an unfocused background. This is
 * called when the RecipientChip no longer has focus.
 */
private void unselectChip(RecipientChip chip) {
    int start = getChipStart(chip);
    int end = getChipEnd(chip);
    Editable editable = getText();
    mSelectedChip = null;
    if (start == -1 || end == -1) {
        Log.w(TAG, "The chip doesn't exist or may be a chip a user was editing");
        setSelection(editable.length());
        commitDefault();
    } else {
        getSpannable().removeSpan(chip);
        QwertyKeyListener.markAsReplaced(editable, start, end, "");
        editable.removeSpan(chip);
        try {
            if (!mNoChips) {
                editable.setSpan(constructChipSpan(chip.getEntry(), start, false), start, end,
                        Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        } catch (NullPointerException e) {
            Log.e(TAG, e.getMessage(), e);
        }
    }
    setCursorVisible(true);
    setSelection(editable.length());
    if (mAlternatesPopup != null && mAlternatesPopup.isShowing()) {
        mAlternatesPopup.dismiss();
    }
}
 
Example 20
Project: gloomy-dungeons-2   File: MultiAutoCompleteTextView.java   Source Code and License 5 votes vote down vote up
@Override
protected void replaceText(CharSequence text) {
    clearComposingText();
    int end = getSelectionEnd();
    int start = mTokenizer.findTokenStart(getText(), end);
    Editable editable = getText();
    String original = TextUtils.substring(editable, start, end);
    QwertyKeyListener.markAsReplaced(editable, start, end, original);
    editable.replace(start, end, mTokenizer.terminateToken(text));
}
 
Example 21
Project: android-chip-edittextview   File: ChipEditTextView.java   Source Code and License 5 votes vote down vote up
private boolean commitChip(int start, int end, Editable editable) {
    ListAdapter adapter = getAdapter();
    if (adapter != null && adapter.getCount() > 0 && enoughToFilter()
            && end == getSelectionEnd()) {
        // choose the first entry.
        submitItemAtPosition(0);
        dismissDropDown();
        return true;
    } else {
        int tokenEnd = mTokenizer.findTokenEnd(editable, start);
        if (editable.length() > tokenEnd + 1) {
            char charAt = editable.charAt(tokenEnd + 1);
            if (charAt == COMMIT_CHAR_COMMA || charAt == COMMIT_CHAR_SEMICOLON) {
                tokenEnd++;
            }
        }
        String text = editable.toString().substring(start, tokenEnd).trim();
        clearComposingText();
        if (text != null && text.length() > 0 && !text.equals(" ")) {
            String entry = createTokenizedEntry(text);
            if (entry != null) {
                QwertyKeyListener.markAsReplaced(editable, start, end, "");
                CharSequence chipText = createChip(entry, false);
                if (chipText != null && start > -1 && end > -1) {
                    editable.replace(start, end, chipText);
                }
            }
            // Only dismiss the dropdown if it is related to the text we
            // just committed.
            // For paste, it may not be as there are possibly multiple
            // tokens being added.
            if (end == getSelectionEnd()) {
                dismissDropDown();
            }
            sanitizeBetween();
            return true;
        }
    }
    return false;
}
 
Example 22
Project: android-chip-edittextview   File: ChipEditTextView.java   Source Code and License 5 votes vote down vote up
/**
 * Remove selection from this chip. Unselecting a RecipientChip will render
 * the chip without a delete icon and with an unfocused background. This is
 * called when the RecipientChip no longer has focus.
 */
private void unselectChip(DrawableChip currentChip) {
    int start = getChipStart(currentChip);
    int end = getChipEnd(currentChip);
    Editable editable = getText();
    mSelectedChip = null;
    if (start == -1 || end == -1) {
        Log.w(TAG, "The chip doesn't exist or may be a chip a user was editing");
        setSelection(editable.length());
        commitDefault();
    } else {
        getSpannable().removeSpan(currentChip);
        QwertyKeyListener.markAsReplaced(editable, start, end, "");
        editable.removeSpan(currentChip);
        try {
            if (!mNoChips) {
            	DrawableChip newChip = constructChipSpan(
            			currentChip.getDelegate(), false);
            	
            	// transfer the original text.
            	newChip.setOriginalText(currentChip.getOriginalText());
            	
                editable.setSpan(newChip,
                        start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        } catch (NullPointerException e) {
            Log.e(TAG, e.getMessage(), e);
        }
    }
    setCursorVisible(true);
    setSelection(editable.length());
  
}
 
Example 23
Project: ChipsLibrary   File: RecipientEditTextView.java   Source Code and License 5 votes vote down vote up
/**
 * Remove selection from this chip. Unselecting a RecipientChip will render the chip without a delete icon and with
 * an unfocused background. This is called when the RecipientChip no longer has focus.
 */
private void unselectChip(final DrawableRecipientChip chip)
  {
  final int start=getChipStart(chip);
  final int end=getChipEnd(chip);
  final Editable editable=getText();
  mSelectedChip=null;
  if(start==-1||end==-1)
    {
    Log.w(TAG,"The chip doesn't exist or may be a chip a user was editing");
    setSelection(editable.length());
    commitDefault();
    }
  else
    {
    getSpannable().removeSpan(chip);
    QwertyKeyListener.markAsReplaced(editable,start,end,"");
    editable.removeSpan(chip);
    try
      {
      if(!mNoChips)
        editable.setSpan(constructChipSpan(chip.getEntry(),false,false),start,end,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
      }
    catch(final NullPointerException e)
      {
      Log.e(TAG,e.getMessage(),e);
      }
    }
  setCursorVisible(true);
  setSelection(editable.length());
  if(mAlternatesPopup!=null&&mAlternatesPopup.isShowing())
    mAlternatesPopup.dismiss();
  }
 
Example 24
Project: SocialTokenAutoComplete   File: TokenCompleteTextView.java   Source Code and License 5 votes vote down vote up
@Override
protected void replaceText(CharSequence text) {
    clearComposingText();
    SpannableStringBuilder ssb = buildSpannableForText(text);
    TokenImageSpan tokenSpan = buildSpanForObject(selectedObject);

    Editable editable = getText();
    int end = getSelectionEnd();
    int start = tokenizer.findTokenStart(editable, end);
    if (start < prefix.length()) {
        start = prefix.length();
    }
    
    start = beforeReplacingText(editable,start,end);
    
    String original = TextUtils.substring(editable, start, end);

    if (editable != null) {
        if (tokenSpan == null) {
            editable.replace(start, end, " ");
        } else if (!allowDuplicates && objects.contains(tokenSpan.getToken())) {
            editable.replace(start, end, " ");
        } else {
            QwertyKeyListener.markAsReplaced(editable, start, end, original);
            editable.replace(start, end, ssb);
            editable.setSpan(tokenSpan, start, start + ssb.length() - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
    
    afterReplacingText(editable);
}
 
Example 25
Project: laposte-android   File: MultiAutoCompleteTextView.java   Source Code and License 5 votes vote down vote up
@Override
protected void replaceText(CharSequence text) {
    clearComposingText();
    int end = getSelectionEnd();
    int start = mTokenizer.findTokenStart(getText(), end);
    Editable editable = getText();
    String original = TextUtils.substring(editable, start, end);
    QwertyKeyListener.markAsReplaced(editable, start, end, original);
    editable.replace(start, end, mTokenizer.terminateToken(text));
}
 
Example 26
Project: Calendar_lunar   File: RecipientEditTextView.java   Source Code and License 5 votes vote down vote up
private boolean commitChip(int start, int end, Editable editable) {
    ListAdapter adapter = getAdapter();
    if (adapter != null && adapter.getCount() > 0 && enoughToFilter()
            && end == getSelectionEnd() && !isPhoneQuery()) {
        // choose the first entry.
        submitItemAtPosition(0);
        dismissDropDown();
        return true;
    } else {
        int tokenEnd = mTokenizer.findTokenEnd(editable, start);
        if (editable.length() > tokenEnd + 1) {
            char charAt = editable.charAt(tokenEnd + 1);
            if (charAt == COMMIT_CHAR_COMMA || charAt == COMMIT_CHAR_SEMICOLON) {
                tokenEnd++;
            }
        }
        String text = editable.toString().substring(start, tokenEnd).trim();
        clearComposingText();
        if (text != null && text.length() > 0 && !text.equals(" ")) {
            RecipientEntry entry = createTokenizedEntry(text);
            if (entry != null) {
                QwertyKeyListener.markAsReplaced(editable, start, end, "");
                CharSequence chipText = createChip(entry, false);
                if (chipText != null && start > -1 && end > -1) {
                    editable.replace(start, end, chipText);
                }
            }
            // Only dismiss the dropdown if it is related to the text we
            // just committed.
            // For paste, it may not be as there are possibly multiple
            // tokens being added.
            if (end == getSelectionEnd()) {
                dismissDropDown();
            }
            sanitizeBetween();
            return true;
        }
    }
    return false;
}
 
Example 27
Project: Calendar_lunar   File: RecipientEditTextView.java   Source Code and License 5 votes vote down vote up
/**
 * Remove selection from this chip. Unselecting a RecipientChip will render
 * the chip without a delete icon and with an unfocused background. This is
 * called when the RecipientChip no longer has focus.
 */
private void unselectChip(RecipientChip chip) {
    int start = getChipStart(chip);
    int end = getChipEnd(chip);
    Editable editable = getText();
    mSelectedChip = null;
    if (start == -1 || end == -1) {
        Log.w(TAG, "The chip doesn't exist or may be a chip a user was editing");
        setSelection(editable.length());
        commitDefault();
    } else {
        getSpannable().removeSpan(chip);
        QwertyKeyListener.markAsReplaced(editable, start, end, "");
        editable.removeSpan(chip);
        try {
            if (!mNoChips) {
                editable.setSpan(constructChipSpan(chip.getEntry(), start, false), start, end,
                        Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        } catch (NullPointerException e) {
            Log.e(TAG, e.getMessage(), e);
        }
    }
    setCursorVisible(true);
    setSelection(editable.length());
    if (mAlternatesPopup != null && mAlternatesPopup.isShowing()) {
        mAlternatesPopup.dismiss();
    }
}
 
Example 28
Project: TflTravelAlerts   File: MultiAutoCompleteTextView.java   Source Code and License 5 votes vote down vote up
@Override
protected void replaceText(CharSequence text) {
    clearComposingText();
    int end = getSelectionEnd();
    int start = mTokenizer.findTokenStart(getText(), end);
    Editable editable = getText();
    String original = TextUtils.substring(editable, start, end);
    QwertyKeyListener.markAsReplaced(editable, start, end, original);
    editable.replace(start, end, mTokenizer.terminateToken(text));
}
 
Example 29
Project: android-chip-edittextview   File: ChipEditTextView.java   Source Code and License 4 votes vote down vote up
/**
 * Show specified chip as selected. If the RecipientChip is just an email address,
 * selecting the chip will take the contents of the chip and place it at
 * the end of the RecipientEditTextView for inline editing. If the
 * RecipientChip is a complete contact, then selecting the chip
 * will change the background color of the chip, show the delete icon,
 * and a popup window with the address in use highlighted and any other
 * alternate addresses for the contact.
 * @param currentChip Chip to select.
 * @return A RecipientChip in the selected state or null if the chip
 * just contained an email address.
 */
private DrawableChip selectChip(DrawableChip currentChip) {
	
	
	// small additinal feature.
	if(!currentChip.isSelectable()) {
		return null;
	}
	
	CharSequence text = currentChip.getText();
	Editable editable = getText();
	Spannable spannable = getSpannable();
	DrawableChip newChip = null;
	
    if (currentChip.isEditable()) {
        int spanStart = spannable.getSpanStart(currentChip);
        int spanEnd = spannable.getSpanEnd(currentChip);
        
        spannable.removeSpan(currentChip);
        editable.delete(spanStart, spanEnd);
        setCursorVisible(true);
        setSelection(editable.length());
        editable.append(text);
        
        newChip = constructChipSpan(currentChip.getDelegate(), true);
        
    } else {
        int start = getChipStart(currentChip);
        int end = getChipEnd(currentChip);
        
        spannable.removeSpan(currentChip);

        try {
            newChip = constructChipSpan(currentChip.getDelegate(), true);
        } catch (NullPointerException e) {
            Log.e(TAG, e.getMessage(), e);
            return null;
        }
        
        QwertyKeyListener.markAsReplaced(editable, start, end, "");
        if (start == -1 || end == -1) {
            Log.d(TAG, "The chip being selected no longer exists but should.");
        } else {
            editable.setSpan(newChip, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        newChip.setSelected(true);
        if (newChip.isEditable()) {
            scrollLineIntoView(getLayout().getLineForOffset(getChipStart(newChip)));
        }

        setCursorVisible(false);
    }
    // transfer the original text.
    newChip.setOriginalText(currentChip.getOriginalText());
    return newChip;
}
 
Example 30
Project: ChipsLibrary   File: RecipientEditTextView.java   Source Code and License 4 votes vote down vote up
private boolean commitChip(final int start,final int end,final Editable editable)
{
final ListAdapter adapter=getAdapter();
if(adapter!=null&&adapter.getCount()>0&&enoughToFilter()&&end==getSelectionEnd()&&!isPhoneQuery())
  {
  // choose the first entry.
  submitItemAtPosition(0);
  dismissDropDown();
  return true;
  }
else
  {
  int tokenEnd=mTokenizer.findTokenEnd(editable,start);
  if(editable.length()>tokenEnd+1)
    {
    final char charAt=editable.charAt(tokenEnd+1);
    if(charAt==COMMIT_CHAR_COMMA||charAt==COMMIT_CHAR_SEMICOLON)
      tokenEnd++;
    }
  final String text=editable.toString().substring(start,tokenEnd).trim();
  clearComposingText();
  if(text!=null&&text.length()>0&&!text.equals(" "))
    {
    final RecipientEntry entry=createTokenizedEntry(text);
    if(entry!=null)
      {
      QwertyKeyListener.markAsReplaced(editable,start,end,"");
      final CharSequence chipText=createChip(entry,false);
      if(chipText!=null&&start>-1&&end>-1)
        editable.replace(start,end,chipText);
      }
    // Only dismiss the dropdown if it is related to the text we
    // just committed.
    // For paste, it may not be as there are possibly multiple
    // tokens being added.
    if(end==getSelectionEnd())
      dismissDropDown();
    sanitizeBetween();
    return true;
    }
  }
return false;
}
 
Example 31
Project: TokenAutoComplete   File: TokenCompleteTextView.java   Source Code and License 4 votes vote down vote up
@Override
protected void replaceText(CharSequence ignore) {
    clearComposingText();

    // Don't build a token for an empty String
    if (selectedObject == null || selectedObject.toString().equals("")) return;

    TokenImageSpan tokenSpan = buildSpanForObject(selectedObject);

    Editable editable = getText();
    int cursorPosition = getSelectionEnd();
    int end = cursorPosition;
    int start = cursorPosition;
    if (!hintVisible) {
        //If you force the drop down to show when the hint is visible, you can run a completion
        //on the hint. If the hint includes commas, this truncates and inserts the hint in the field
        end = getCorrectedTokenEnd();
        start = getCorrectedTokenBeginning(end);
    }

    String original = TextUtils.substring(editable, start, end);

    //Keep track of  replacements for a bug workaround
    if (original.length() > 0) {
        lastCompletionText = original;
    }

    if (editable != null) {
        if (tokenSpan == null) {
            editable.replace(start, end, "");
        } else if (!allowDuplicates && objects.contains(tokenSpan.getToken())) {
            editable.replace(start, end, "");
            if (listener != null) {
                listener.onDuplicateRemoved(tokenSpan.getToken());
            }
        } else {
            QwertyKeyListener.markAsReplaced(editable, start, end, original);
            SpannableStringBuilder ssb = buildTokenSpannable();
            editable.replace(start, end, ssb);
            editable.setSpan(tokenSpan, start, start + ssb.length() - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
}