Skip to content

Commit

Permalink
Added getTags & setSeparator methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mabbas007 committed May 10, 2017
1 parent 95a76c4 commit ebf2cc9
Show file tree
Hide file tree
Showing 7 changed files with 2,852 additions and 33 deletions.
8 changes: 1 addition & 7 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions TagsEditText/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
compileSdkVersion 25
buildToolsVersion "25.0.3"

defaultConfig {
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
targetSdkVersion 25
versionCode 2
versionName "1.1"
}
buildTypes {
release {
Expand All @@ -21,5 +21,5 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:appcompat-v7:25.3.1'
}
25 changes: 14 additions & 11 deletions TagsEditText/src/main/java/mabbas007/tagsedittext/TagsEditText.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
*/
public class TagsEditText extends AutoCompleteTextView {

private static final String SEPARATOR = " ";
public static final String NEW_LINE = "\n";

private static final String LAST_STRING = "lastString";
Expand All @@ -65,11 +64,8 @@ public class TagsEditText extends AutoCompleteTextView {
private static final String LEFT_DRAWABLE_RESOURCE = "leftDrawable";
private static final String RIGHT_DRAWABLE_RESOURCE = "rightDrawable";
private static final String DRAWABLE_PADDING = "drawablePadding";
private static final String TAGS_PADDING_LEFT = "tagsPaddingLeft";
private static final String TAGS_PADDING_RIGHT = "tagsPaddingRight";
private static final String TAGS_PADDING_TOP = "tagsPaddingTop";
private static final String TAGS_PADDING_BOTTOM = "tagsPaddingBottom";

private String mSeparator = " ";
private String mLastString = "";
private boolean mIsAfterTextWatcherEnabled = true;

Expand Down Expand Up @@ -115,6 +111,13 @@ public void afterTextChanged(Editable s) {
}
};

public List<String> getTags(){
return convertTagSpanToList(mTagSpans);
}

public void setSeparator(String separator) {
mSeparator = separator;
}

public TagsEditText(Context context) {
super(context);
Expand Down Expand Up @@ -310,7 +313,7 @@ private void buildStringWithTags(List<Tag> tags) {
mIsAfterTextWatcherEnabled = false;
getText().clear();
for (Tag tag : tags) {
getText().append(tag.getSource()).append(SEPARATOR);
getText().append(tag.getSource()).append(mSeparator);
}
mLastString = getText().toString();
if (!TextUtils.isEmpty(mLastString)) {
Expand Down Expand Up @@ -442,7 +445,7 @@ private void setTags() {
}

boolean isDeleting = mLastString.length() > str.length();
if (mLastString.endsWith(SEPARATOR)
if (mLastString.endsWith(mSeparator)
&& !str.endsWith(NEW_LINE)
&& isDeleting
&& !mTagSpans.isEmpty()) {
Expand All @@ -458,7 +461,7 @@ private void setTags() {
performFiltering(getNewTag(str), 0);
}

if (str.endsWith(NEW_LINE) || (!mIsSpacesAllowedInTags && str.endsWith(SEPARATOR)) && !isDeleting) {
if (str.endsWith(NEW_LINE) || (!mIsSpacesAllowedInTags && str.endsWith(mSeparator)) && !isDeleting) {
buildTags(str);
}

Expand Down Expand Up @@ -509,7 +512,7 @@ private void updateTags(String newString) {
String source = getNewTag(newString);
if (!TextUtils.isEmpty(source) && !source.equals(NEW_LINE)) {
boolean isSpan = source.endsWith(NEW_LINE) ||
(!mIsSpacesAllowedInTags && source.endsWith(SEPARATOR));
(!mIsSpacesAllowedInTags && source.endsWith(mSeparator));
if (isSpan) {
source = source.substring(0, source.length() - 1);
source = source.trim();
Expand All @@ -534,14 +537,14 @@ private String getNewTag(String newString) {
StringBuilder builder = new StringBuilder();
for (Tag tag : mTags) {
if (!tag.isSpan()) continue;
builder.append(tag.getSource()).append(SEPARATOR);
builder.append(tag.getSource()).append(mSeparator);
}
return newString.replace(builder.toString(), "");
}

private void addTagSpan(SpannableStringBuilder sb, final TagSpan tagSpan) {
String source = tagSpan.getSource();
sb.append(source).append(SEPARATOR);
sb.append(source).append(mSeparator);
int length = sb.length();
int startSpan = length - (source.length() + 1);
int endSpan = length - 1;
Expand Down
12 changes: 6 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
compileSdkVersion 25
buildToolsVersion "25.0.3"

defaultConfig {
applicationId "mabbas007.myapplication"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
targetSdkVersion 25
versionCode 2
versionName "1.1"
}
buildTypes {
release {
Expand All @@ -22,6 +22,6 @@ android {
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:appcompat-v7:25.3.1'
compile project(':TagsEditText')
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'com.android.tools.build:gradle:2.2.3'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Dec 28 10:00:20 PST 2015
#Wed May 10 22:28:01 GMT+02:00 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
Loading

0 comments on commit ebf2cc9

Please sign in to comment.