├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ └── layout
│ │ │ │ └── activity_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── xsm
│ │ │ └── tedittext
│ │ │ └── MainActivity.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── xsm
│ │ │ └── tedittext
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── xsm
│ │ └── tedittext
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── library
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ └── values
│ │ │ │ ├── strings.xml
│ │ │ │ └── attrs.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── xsm
│ │ │ └── library
│ │ │ ├── TObject.java
│ │ │ └── TEditText.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── xsm
│ │ │ └── library
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── xsm
│ │ └── library
│ │ └── ExampleInstrumentedTest.java
├── build.gradle
└── proguard-rules.pro
├── settings.gradle
├── 1.jpg
├── 2.jpg
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
├── README.md
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':library'
2 |
--------------------------------------------------------------------------------
/1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xiasm/TEditText/HEAD/1.jpg
--------------------------------------------------------------------------------
/2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xiasm/TEditText/HEAD/2.jpg
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xiasm/TEditText/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/library/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Library
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xiasm/TEditText/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xiasm/TEditText/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xiasm/TEditText/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xiasm/TEditText/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xiasm/TEditText/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xiasm/TEditText/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xiasm/TEditText/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xiasm/TEditText/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xiasm/TEditText/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xiasm/TEditText/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | TEditText
3 | 分享新鲜事
4 | 添加话题
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Jul 18 12:27:13 CST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
7 |
--------------------------------------------------------------------------------
/library/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/xsm/tedittext/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.xsm.tedittext;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/library/src/test/java/com/xsm/library/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.xsm.library;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Intellij IDEA
2 | .idea/
3 | *.iml
4 | *.ipr
5 | *.iws
6 | out/
7 |
8 | # Gradle build folder
9 | build/
10 | .gradle/
11 |
12 | # Android
13 | local.properties
14 | bin/
15 | gen/
16 |
17 | # JNI compile files
18 | *.o
19 | *.o.d
20 |
21 | # OS autogen folder information
22 | .DS_Store
23 | Thumbs.db
24 |
25 | # Temp files
26 | *.bak
27 | *.tmp
28 | *.temp
29 | *.swp
30 | *.*~
31 | ~*.*
32 |
33 | # Eclipse project files
34 | .classpath
35 | .settings/
36 | .project
37 |
38 | #Android 2.2 C/C++ compile
39 | .externalNativeBuild/
40 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/library/src/main/java/com/xsm/library/TObject.java:
--------------------------------------------------------------------------------
1 | package com.xsm.library;
2 |
3 | /**
4 | * Author: Xiasem
5 | * Date: 17-2-13
6 | * Email: xiasem@163.com
7 | * Github: https://github.com/Xiasm
8 | *
9 | *
10 | * TObject,话题对象,可通过继承此对象,做一些逻辑上的处理
11 | *
12 | */
13 | public class TObject {
14 |
15 | private String objectRule = "#";// 匹配规则
16 | private String objectText;// 高亮文本
17 |
18 | public String getObjectRule() {
19 | return objectRule;
20 | }
21 |
22 | public void setObjectRule(String objectRule) {
23 | this.objectRule = objectRule;
24 | }
25 |
26 | public String getObjectText() {
27 | return objectText;
28 | }
29 |
30 | public void setObjectText(String objectText) {
31 | this.objectText = objectText;
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/xsm/tedittext/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.xsm.tedittext;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.xsm.tedittext", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/library/src/androidTest/java/com/xsm/library/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.xsm.library;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.xsm.library.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.2"
6 |
7 | defaultConfig {
8 | minSdkVersion 14
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 |
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 |
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | }
23 |
24 | dependencies {
25 | compile fileTree(dir: 'libs', include: ['*.jar'])
26 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
27 | exclude group: 'com.android.support', module: 'support-annotations'
28 | })
29 | compile 'com.android.support:appcompat-v7:25.3.1'
30 | testCompile 'junit:junit:4.12'
31 | }
32 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /home/xsm/Android/Sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/library/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /home/xsm/Android/Sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.2"
6 | defaultConfig {
7 | applicationId "com.xsm.tedittext"
8 | minSdkVersion 14
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(include: ['*.jar'], dir: 'libs')
24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | compile 'com.android.support:appcompat-v7:25.3.1'
28 | compile 'com.android.support.constraint:constraint-layout:1.0.2'
29 | testCompile 'junit:junit:4.12'
30 | compile project(':library')
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
23 |
24 |
29 |
30 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xsm/tedittext/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.xsm.tedittext;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 | import android.os.Bundle;
5 | import android.view.View;
6 |
7 | import com.xsm.library.TEditText;
8 | import com.xsm.library.TObject;
9 |
10 | import java.util.ArrayList;
11 |
12 | public class MainActivity extends AppCompatActivity implements View.OnClickListener {
13 |
14 | private ArrayList mStrings;
15 | private int i = 0;
16 | private TEditText mTEditText;
17 |
18 | @Override
19 | protected void onCreate(Bundle savedInstanceState) {
20 | super.onCreate(savedInstanceState);
21 | setContentView(R.layout.activity_main);
22 | mTEditText = (TEditText) findViewById(R.id.edittext);
23 | findViewById(R.id.topic_button).setOnClickListener(this);
24 |
25 | mStrings = new ArrayList<>();
26 | mStrings.add("鬼畜神曲");
27 | mStrings.add("洛阳的天气");
28 | mStrings.add("麦田收割机");
29 | mStrings.add("人工智能手机");
30 | mStrings.add("大汽车");
31 | }
32 |
33 | @Override
34 | public void onClick(View v) {
35 | //话题对象,可继承此类实现特定的业务逻辑
36 | TObject object = new TObject();
37 | //匹配规则
38 | object.setObjectRule("#");
39 | //话题内容
40 | object.setObjectText(mStrings.get(i));
41 | mTEditText.setObject(object);
42 | i++;
43 | if (i > 4)
44 | i = 0;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # TEditText
2 | TEditText是一款可以添加话题可变色的编辑框,类似于微博的话题选择功能,选中一个话题,添加到编辑框里,话题将会变色,并且当删除话题的时候,会先选中然后再删除.
3 | ## 效果展示
4 | 如图1为添加话题后的UI效果,话题前景色和背景色可以任意设置.
5 |
6 |
7 | 图1添加话题
8 |
9 | 如图2为删除话题时的UI效果,当第一次按删除键时,话题被选中,并显示用户设置的背景色,再按删除键,话题整体被删除.
10 |
11 |
12 | 图2,话题被选中
13 |
14 |
15 | ## 如何使用
16 |
17 | #### gradle:
18 |
19 | Step1. Add it in your root build.gradle at the end of repositories:
20 |
21 | allprojects {
22 | repositories {
23 | ...
24 | maven { url 'https://jitpack.io' }
25 | }
26 | }
27 |
28 | Step2.Add the dependency:
29 |
30 | dependencies {
31 | compile 'com.github.Xiasm:TEditText:v1.0'
32 | }
33 |
34 | ### maven:
35 |
36 |
37 |
38 | jitpack.io
39 | https://jitpack.io
40 |
41 |
42 |
43 | Step 2. Add the dependency:
44 |
45 |
46 | com.github.Xiasm
47 | TEditText
48 | v1.0
49 |
50 |
51 | ## 在项目中使用
52 | //话题对象,可继承此类实现特定的业务逻辑
53 |
54 | TObject object = new TObject();
55 | //匹配规则
56 | object.setObjectRule("#");
57 | //话题内容
58 | object.setObjectText(mStrings.get(i));
59 | mTEditText.setObject(object);
60 |
61 | // xml中使用
62 | object_foreground_color:设置话题Object前景色
63 | object_background_color:设置话题Object背景色
64 |
65 |
76 |
77 | ### 联系方式:
78 |
79 | Email:xiasem@163.com
80 |
81 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/library/src/main/java/com/xsm/library/TEditText.java:
--------------------------------------------------------------------------------
1 | package com.xsm.library;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Color;
6 | import android.text.Editable;
7 | import android.text.Spannable;
8 | import android.text.TextUtils;
9 | import android.text.TextWatcher;
10 | import android.text.style.BackgroundColorSpan;
11 | import android.text.style.ForegroundColorSpan;
12 | import android.util.AttributeSet;
13 |
14 | import java.util.ArrayList;
15 | import java.util.List;
16 |
17 |
18 | /**
19 | * Author: Xiasem
20 | * Date: 17-1-18
21 | * Email: xiasem@163.com
22 | * Github: https://github.com/Xiasm
23 | *
24 | *
25 | * 仿微博实现话题选择输入框
26 | *
27 | */
28 | public class TEditText extends android.support.v7.widget.AppCompatEditText{
29 |
30 | private int preTextLength = 0;
31 | // 默认,话题文本高亮颜色
32 | private static final int FOREGROUND_COLOR = Color.parseColor("#FF8C00");
33 | // 默认,话题背景高亮颜色
34 | private static final int BACKGROUND_COLOR = Color.parseColor("#FFDEAD");
35 |
36 | /**
37 | * 开发者可设置内容
38 | */
39 |
40 | // 话题文本高亮颜色
41 | private int mForegroundColor = FOREGROUND_COLOR;
42 |
43 | // 话题背景高亮颜色
44 | private int mBackgroundColor = BACKGROUND_COLOR;
45 |
46 | private List mTObjectsList = new ArrayList<>();// object集合
47 |
48 | public TEditText(Context context) {
49 | this(context, null);
50 | // 初始化设置
51 | init();
52 | }
53 |
54 | public TEditText(Context context, AttributeSet attrs) {
55 | this(context, attrs, android.support.v7.appcompat.R.attr.editTextStyle);
56 | }
57 |
58 | public TEditText(Context context, AttributeSet attrs, int defStyleAttr) {
59 | super(context, attrs, defStyleAttr);
60 |
61 | TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.TEditText);
62 | mBackgroundColor = typedArray.getColor(R.styleable.TEditText_object_background_color, BACKGROUND_COLOR);
63 | mForegroundColor = typedArray.getColor(R.styleable.TEditText_object_foreground_color, FOREGROUND_COLOR);
64 | typedArray.recycle();
65 |
66 | // 初始化设置
67 | init();
68 | }
69 |
70 | /**
71 | * 监听光标的位置,若光标处于话题内容中间则移动光标到话题结束位置
72 | */
73 | @Override
74 | protected void onSelectionChanged(int selStart, int selEnd) {
75 | super.onSelectionChanged(selStart, selEnd);
76 |
77 | if (mTObjectsList == null || mTObjectsList.size() == 0) {
78 | return;
79 | }
80 |
81 | int startPosition = 0;
82 | int endPosition = 0;
83 | String objectText = "";
84 |
85 | for (int i = 0; i < mTObjectsList.size(); i++) {
86 |
87 | objectText = mTObjectsList.get(i).getObjectText();
88 | int length = getText().toString().length();
89 |
90 | while (true) {
91 | // 获取话题文本开始下标
92 | startPosition = getText().toString().indexOf(objectText, startPosition);
93 | endPosition = startPosition + objectText.length();
94 | if (startPosition == -1) {
95 | break;
96 | }
97 | // 若光标处于话题内容中间则移动光标到话题结束位置
98 | if (selStart > startPosition && selStart <= endPosition) {
99 | if ((endPosition + 1) > length) {
100 | setSelection(endPosition);
101 | } else {
102 | setSelection(endPosition + 1);
103 | }
104 | break;
105 | }
106 | startPosition = endPosition;
107 | }
108 |
109 |
110 | }
111 |
112 | }
113 |
114 | /**
115 | * Description:
116 | *
117 | * 初始化控件,设置一些监听,如文字变化,文字删除
118 | *
119 | * Author: Xiasem, Date: 17-7-17, Email: xiasem@163.com
120 | * Version:
121 | */
122 | private void init() {
123 |
124 | // /*
125 | // * 输入框内容变化监听
126 | // * 1.当文字内容产生变化的时候实时更新UI
127 | // */
128 | // this.addTextChangedListener(new TextWatcher() {
129 | // @Override
130 | // public void beforeTextChanged(CharSequence s, int start, int count,
131 | // int after) {
132 | // }
133 | //
134 | // @Override
135 | // public void onTextChanged(CharSequence s, int start, int before,
136 | // int count) {
137 | // }
138 | //
139 | // @Override
140 | // public void afterTextChanged(Editable s) {
141 | // // 文字改变刷新UI
142 | // refreshEditTextUI(s.toString());
143 | // }
144 | // });
145 |
146 | /*
147 | * 监听软键盘删除按钮(本打算使用setOnKeyListener,但发现在华为手机上Del按钮的keyCode与其他手机不一样,故用此)
148 | * 1.光标在话题后面,将整个话题内容删除
149 | * 2.光标在普通文字后面,删除一个字符
150 | */
151 | this.addTextChangedListener(new TextWatcher() {
152 | @Override
153 | public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
154 |
155 | }
156 |
157 | @Override
158 | public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
159 |
160 | }
161 |
162 | @Override
163 | public void afterTextChanged(Editable editablede) {
164 | Editable editable = getText();
165 | int length = editablede.toString().length();
166 |
167 | //删除
168 | if (length < preTextLength) {
169 | int selectionStart = getSelectionStart();
170 | int selectionEnd = getSelectionEnd();
171 |
172 |
173 | /*
174 | * 如果光标起始和结束不在同一位置,删除文本
175 | */
176 | if (selectionStart != selectionEnd) {
177 | // 查询文本是否属于话题对象,若是移除列表数据
178 | String tagetText = getText().toString().substring(selectionStart, selectionEnd);
179 | for (int i = 0; i < mTObjectsList.size(); i++) {
180 | TObject object = mTObjectsList.get(i);
181 | if (tagetText.equals(object.getObjectText())) {
182 | mTObjectsList.remove(object);
183 | }
184 | }
185 | return;
186 | }
187 |
188 | int lastPos = 0;
189 | if (mTObjectsList != null && mTObjectsList.size() > 0) {
190 | // 遍历判断光标的位置
191 | for (int i = 0; i < mTObjectsList.size(); i++) {
192 |
193 | String objectText = mTObjectsList.get(i).getObjectText();
194 |
195 | lastPos = getText().toString().indexOf(objectText, lastPos);
196 | if (lastPos != -1) {
197 | if (selectionStart != 0 && selectionStart >= lastPos && selectionStart <= (lastPos + objectText.length())) {
198 | // 选中话题
199 | setSelection(lastPos, lastPos + objectText.length());
200 | // 设置背景色
201 | editable.setSpan(new BackgroundColorSpan(
202 | mBackgroundColor), lastPos, lastPos
203 | + objectText.length(),
204 | Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
205 | return;
206 | }
207 | lastPos += objectText.length();
208 | }
209 | }
210 | }
211 |
212 | }
213 | preTextLength = length;
214 | refreshEditTextUI(editable.toString());
215 | }
216 | });
217 |
218 | }
219 |
220 | /**
221 | * Description:
222 | *
223 | * TEditText内容修改之后刷新UI
224 | *
225 | * Author: Xiasem, Date: 17-7-17, Email: xiasem@163.com
226 | * Version: 1.0
227 | * @param content 输入框内容
228 | */
229 | private void refreshEditTextUI(String content) {
230 |
231 | /*
232 | * 内容变化时操作:
233 | * 1.查找匹配所有话题内容
234 | * 2.设置话题内容特殊颜色
235 | */
236 | if (mTObjectsList.size() == 0)
237 | return;
238 |
239 | if (TextUtils.isEmpty(content)) {
240 | mTObjectsList.clear();
241 | return;
242 | }
243 |
244 | /*
245 | * 重新设置span
246 | */
247 | Editable editable = getText();
248 | int textLength = editable.length();
249 |
250 | int findPosition = 0;
251 | for (int i = 0; i < mTObjectsList.size(); i++) {
252 | final TObject object = mTObjectsList.get(i);
253 | // 文本
254 | String objectText = object.getObjectText();
255 | while (findPosition <= length()) {
256 | // 获取文本开始下标
257 | findPosition = content.indexOf(objectText, findPosition);
258 | if (findPosition != -1) {
259 | // 设置话题内容前景色高亮
260 | ForegroundColorSpan colorSpan = new ForegroundColorSpan(mForegroundColor);
261 | editable.setSpan(colorSpan, findPosition, findPosition + objectText.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
262 | findPosition += objectText.length();
263 | } else {
264 | break;
265 | }
266 | }
267 |
268 | }
269 |
270 | }
271 |
272 | /**
273 | * 插入/设置话题
274 | *
275 | * @param object 话题对象
276 | */
277 | public void setObject(TObject object) {
278 |
279 | if (object == null) {
280 | return;
281 | }
282 |
283 | String objectRule = object.getObjectRule();
284 | String objectText = object.getObjectText();
285 | if (TextUtils.isEmpty(objectText) || TextUtils.isEmpty(objectRule)) {
286 | return;
287 | }
288 |
289 | // 拼接字符# %s #,并保存
290 | objectText = objectRule + objectText + objectRule;
291 | object.setObjectText(objectText);
292 |
293 | /*
294 | * 1.添加话题内容到数据集合
295 | */
296 | mTObjectsList.add(object);
297 |
298 | /*
299 | * 2.将话题内容添加到EditText中展示
300 | */
301 | // 光标位置
302 | int selectionStart = getSelectionStart();
303 | // 原先内容
304 | Editable editable = getText();
305 |
306 | if (selectionStart >= 0) {
307 | // 在光标位置插入内容 话题后面插入空格,至关重要
308 | editable.insert(selectionStart, objectText + " ");
309 | // editable.insert(getSelectionStart(), " ");
310 |
311 | setSelection(getSelectionStart());// 移动光标到添加的内容后面
312 | }
313 |
314 | }
315 |
316 | /**
317 | * 获取object列表数据
318 | */
319 | public List getObjects() {
320 | List objectsList = new ArrayList();
321 | // 由于保存时候文本内容添加了匹配字符#,此处去除,还原数据
322 | if (mTObjectsList != null && mTObjectsList.size() > 0) {
323 | for (int i = 0; i < mTObjectsList.size(); i++) {
324 | TObject object = mTObjectsList.get(i);
325 | String objectText = object.getObjectText();
326 | String objectRule = object.getObjectRule();
327 | object.setObjectText(objectText.replace(objectRule, ""));// 将匹配规则字符替换
328 | objectsList.add(object);
329 | }
330 | }
331 | return objectsList;
332 | }
333 |
334 | }
335 |
--------------------------------------------------------------------------------