-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8722 from cketti/integrate_TokenAutoComplete
Copy the TokenAutoComplete library into our repository
- Loading branch information
Showing
23 changed files
with
2,008 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# TokenAutoComplete | ||
|
||
Gmail style `MultiAutoCompleteTextView` for Android. | ||
|
||
--- | ||
|
||
Forked from https://github.com/splitwise/TokenAutoComplete (licensed under the Apache License, Version 2.0). | ||
|
||
Based on https://github.com/splitwise/TokenAutoComplete/commit/bb51c96b39d90d43e74b2b8cf709ec58dd633c45 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
plugins { | ||
id(ThunderbirdPlugins.Library.android) | ||
} | ||
|
||
android { | ||
namespace = "app.k9mail.library.tokenautocomplete" | ||
} | ||
|
||
dependencies { | ||
implementation(libs.androidx.annotation) | ||
implementation(libs.androidx.appcompat) | ||
|
||
testImplementation(libs.junit) | ||
} |
121 changes: 121 additions & 0 deletions
121
library/TokenAutoComplete/src/main/java/com/tokenautocomplete/CharacterTokenizer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
package com.tokenautocomplete; | ||
|
||
import android.os.Parcel; | ||
import android.os.Parcelable; | ||
import androidx.annotation.NonNull; | ||
import android.text.SpannableString; | ||
import android.text.Spanned; | ||
import android.text.TextUtils; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Tokenizer with configurable array of characters to tokenize on. | ||
* | ||
* Created on 2/3/15. | ||
* @author mgod | ||
*/ | ||
public class CharacterTokenizer implements Tokenizer { | ||
private ArrayList<Character> splitChar; | ||
private String tokenTerminator; | ||
|
||
@SuppressWarnings("WeakerAccess") | ||
public CharacterTokenizer(List<Character> splitChar, String tokenTerminator){ | ||
super(); | ||
this.splitChar = new ArrayList<>(splitChar); | ||
this.tokenTerminator = tokenTerminator; | ||
} | ||
|
||
@Override | ||
public boolean containsTokenTerminator(CharSequence charSequence) { | ||
for (int i = 0; i < charSequence.length(); ++i) { | ||
if (splitChar.contains(charSequence.charAt(i))) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
@NonNull | ||
public List<Range> findTokenRanges(CharSequence charSequence, int start, int end) { | ||
ArrayList<Range>result = new ArrayList<>(); | ||
|
||
if (start == end) { | ||
//Can't have a 0 length token | ||
return result; | ||
} | ||
|
||
int tokenStart = start; | ||
|
||
for (int cursor = start; cursor < end; ++cursor) { | ||
char character = charSequence.charAt(cursor); | ||
|
||
//Avoid including leading whitespace, tokenStart will match the cursor as long as we're at the start | ||
if (tokenStart == cursor && Character.isWhitespace(character)) { | ||
tokenStart = cursor + 1; | ||
} | ||
|
||
//Either this is a split character, or we contain some content and are at the end of input | ||
if (splitChar.contains(character) || cursor == end - 1) { | ||
boolean hasTokenContent = | ||
//There is token content befor the current character | ||
cursor > tokenStart || | ||
//If the current single character is valid token content, not a split char or whitespace | ||
(cursor == tokenStart && !splitChar.contains(character)); | ||
if (hasTokenContent) { | ||
//There is some token content | ||
//Add one to range end as the end of the ranges is not inclusive | ||
result.add(new Range(tokenStart, cursor + 1)); | ||
} | ||
|
||
tokenStart = cursor + 1; | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
@Override | ||
@NonNull | ||
public CharSequence wrapTokenValue(CharSequence text) { | ||
CharSequence wrappedText = text + tokenTerminator; | ||
|
||
if (text instanceof Spanned) { | ||
SpannableString sp = new SpannableString(wrappedText); | ||
TextUtils.copySpansFrom((Spanned) text, 0, text.length(), | ||
Object.class, sp, 0); | ||
return sp; | ||
} else { | ||
return wrappedText; | ||
} | ||
} | ||
|
||
public static final Parcelable.Creator<CharacterTokenizer> CREATOR = new Parcelable.Creator<CharacterTokenizer>() { | ||
@SuppressWarnings("unchecked") | ||
public CharacterTokenizer createFromParcel(Parcel in) { | ||
return new CharacterTokenizer(in); | ||
} | ||
|
||
public CharacterTokenizer[] newArray(int size) { | ||
return new CharacterTokenizer[size]; | ||
} | ||
}; | ||
|
||
@Override | ||
public int describeContents() { | ||
return 0; | ||
} | ||
|
||
@SuppressWarnings({"WeakerAccess", "unchecked"}) | ||
CharacterTokenizer(Parcel in) { | ||
this(in.readArrayList(Character.class.getClassLoader()), in.readString()); | ||
} | ||
|
||
@Override | ||
public void writeToParcel(Parcel parcel, int i) { | ||
parcel.writeList(splitChar); | ||
parcel.writeString(tokenTerminator); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
library/TokenAutoComplete/src/main/java/com/tokenautocomplete/CountSpan.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.tokenautocomplete; | ||
|
||
import android.text.Layout; | ||
import android.text.TextPaint; | ||
import android.text.style.CharacterStyle; | ||
|
||
import java.util.Locale; | ||
|
||
/** | ||
* Span that displays +[x] | ||
* | ||
* Created on 2/3/15. | ||
* @author mgod | ||
*/ | ||
|
||
class CountSpan extends CharacterStyle { | ||
private String countText; | ||
|
||
CountSpan() { | ||
super(); | ||
countText = ""; | ||
} | ||
|
||
@Override | ||
public void updateDrawState(TextPaint textPaint) { | ||
//Do nothing, we are using this span as a location marker | ||
} | ||
|
||
void setCount(int c) { | ||
if (c > 0) { | ||
countText = String.format(Locale.getDefault(), " +%d", c); | ||
} else { | ||
countText = ""; | ||
} | ||
} | ||
|
||
String getCountText() { | ||
return countText; | ||
} | ||
|
||
float getCountTextWidthForPaint(TextPaint paint) { | ||
return Layout.getDesiredWidth(countText, 0, countText.length(), paint); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
library/TokenAutoComplete/src/main/java/com/tokenautocomplete/DummySpan.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.tokenautocomplete; | ||
|
||
import android.text.TextPaint; | ||
import android.text.style.MetricAffectingSpan; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
/** | ||
* Invisible MetricAffectingSpan that will trigger a redraw when it is being added to or removed from an Editable. | ||
* | ||
* @see TokenCompleteTextView#redrawTokens() | ||
*/ | ||
class DummySpan extends MetricAffectingSpan { | ||
static final DummySpan INSTANCE = new DummySpan(); | ||
|
||
private DummySpan() {} | ||
|
||
@Override | ||
public void updateMeasureState(@NonNull TextPaint textPaint) {} | ||
|
||
@Override | ||
public void updateDrawState(TextPaint tp) {} | ||
} |
Oops, something went wrong.