├── .gitignore
├── .idea
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── gradle.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── adapter
│ │ └── smart
│ │ └── more
│ │ ├── DensityUtil.java
│ │ └── MainActivity.java
│ └── res
│ ├── drawable
│ ├── down.png
│ └── up.png
│ ├── layout
│ └── activity_main.xml
│ ├── mipmap-hdpi
│ └── ic_launcher.png
│ ├── mipmap-mdpi
│ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxxhdpi
│ └── ic_launcher.png
│ ├── values-w820dp
│ └── dimens.xml
│ └── values
│ ├── colors.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── build.gradle
├── gif
└── 3.gif
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── moretext
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── smart
│ │ └── moretext
│ │ ├── CenterAlignImageSpan.java
│ │ └── UtilMoreText.java
│ └── res
│ └── values
│ └── strings.xml
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 | app/app-release.apk
11 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
19 |
20 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 | C:\Users\smart\AppData\Roaming\Subversion
102 |
103 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## MoreTextView
2 | 一行代码实现TextView的“展开”和“收起”
3 | #### 引用
4 | compile 'com.smart.moretext:moretext:1.0.0
5 | # 需求介绍:
6 | 1、在文本末尾,实现点击“展开”---展开所有文本,并把“展开”改为“收起”;点击“收起”,则收起文本;
7 | 2、“展开”和“收起”紧跟文本末尾。并且不换行。
8 | ### 函数说明
9 | #### 1.1 构造函函数
10 |
11 | ##### 1.1.1 文字形式
12 | /**
13 | * @param textView 文本框
14 | * @param oriMsg 原始信息
15 | * @param textOpen 展开性质的文字
16 | * @param textClose 关闭性质的文字
17 | */
18 | public UtilMoreText(final TextView textView, String oriMsg, String textOpen, String textClose) {
19 | }
20 | ##### 1.1.2 文字形式
21 | /**
22 | * @param textView 文本框
23 | * @param oriMsg 原始文字
24 | */
25 | public UtilMoreText(final TextView textView, String oriMsg) {
26 |
27 | }
28 | ##### 1.1.3 图片形式
29 | /**
30 | * @param textView 文本框
31 | * @param oriMsg 原始文字
32 | * @param drawableOpen 展开图标
33 | * @param drawableColse 关闭图标
34 | */
35 | public UtilMoreText(final TextView textView, String oriMsg, Drawable drawableOpen, Drawable drawableColse) {
36 | }
37 | ####成员方法介绍
38 |
39 | /** 设置结尾 文字的颜色
40 | * @param spanTextColor 颜色id
41 | * @return 本类实例
42 | */
43 | public UtilMoreText setSpanTextColor(int spanTextColor) {
44 |
45 | }
46 | ### 使用说明
47 | #### 设置文本
48 | new UtilMoreText(tv1,msg).setSpanTextColor(R.color.colorAccent).createString();
49 | #### 设置图标
50 | new UtilMoreText(tv2,msg,down,up).createImg();
51 | #### UtilMoreText.java 源码地址
52 | https://github.com/XBean1024/MoreTextView/blob/master/moretext/src/main/java/com/smart/moretext/UtilMoreText.java
53 | #### 效果图,(结尾随意找的图片,项目中更换一下)
54 | 
55 |
56 | #### 推荐,其他网友的一个组合view实现的,效果也不错
57 | ##### 先看下效果图吧:
58 | 
59 | ##### 地址
60 | https://github.com/XBean1024/MoreTextView-1
61 | ##### QQ:交流群 :192268854
62 | 
63 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 26
5 | buildToolsVersion '26.0.2'
6 | defaultConfig {
7 | applicationId "com.adapter.smart.more"
8 | minSdkVersion 15
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 | compile 'com.android.support:appcompat-v7:26.1.0'
25 | compile project(":moretext")
26 | }
27 |
--------------------------------------------------------------------------------
/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 D:\AndroidSDK\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 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/adapter/smart/more/DensityUtil.java:
--------------------------------------------------------------------------------
1 | package com.adapter.smart.more;
2 |
3 | import android.content.Context;
4 | import android.util.TypedValue;
5 |
6 | /**
7 | * Created by yxm on 16-6-23.
8 | */
9 | public class DensityUtil {
10 |
11 | private DensityUtil() {
12 | throw new UnsupportedOperationException("cannot be instantiated");
13 | }
14 |
15 | /**
16 | * dp转px
17 | */
18 | public static int dp2px(Context context, float dpVal) {
19 | return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
20 | dpVal, context.getResources().getDisplayMetrics());
21 | }
22 |
23 | /**
24 | * sp转px
25 | */
26 | public static int sp2px(Context context, float spVal) {
27 | return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,
28 | spVal, context.getResources().getDisplayMetrics());
29 | }
30 |
31 | /**
32 | * px转dp
33 | */
34 | public static float px2dp(Context context, float pxVal) {
35 | final float scale = context.getResources().getDisplayMetrics().density;
36 | return (pxVal / scale);
37 | }
38 |
39 | /**
40 | * px转sp
41 | */
42 | public static float px2sp(Context context, float pxVal) {
43 | return (pxVal / context.getResources().getDisplayMetrics().scaledDensity);
44 | }
45 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/adapter/smart/more/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.adapter.smart.more;
2 |
3 | import android.content.res.Resources;
4 | import android.graphics.drawable.Drawable;
5 | import android.os.Bundle;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.util.DisplayMetrics;
8 | import android.util.Log;
9 | import android.widget.TextView;
10 |
11 | import com.smart.moretext.UtilMoreText;
12 |
13 |
14 | public class MainActivity extends AppCompatActivity {
15 |
16 |
17 | private TextView tv2;
18 | private TextView tv1;
19 | private TextView tv;
20 | private String msg ="在Android开发中,有许多信息展示需要通过TextView来展现有许多" +
21 | "信息展示需要通过TextView来展现有许多信息展示需要通过TextView来展现有许多信" +
22 | "息展示需要通过TextView来展现,如果只是普通的信息展现,使用TextView setText(CharSequence " +
23 | "str)设置即可,但是当在TextView里的这段内容需要截取某一部分字段,可以被点击以及响应响应的操" +
24 | "作,这时候就需要用到SpannableString了,下面通过一段简单的代码实现部分文字被点击响应,及富文本表情的实现";
25 | public static final String TAG = "main";
26 | @Override
27 | protected void onCreate(Bundle savedInstanceState) {
28 | super.onCreate(savedInstanceState);
29 | setContentView(R.layout.activity_main);
30 |
31 | tv2 = (TextView) findViewById(R.id.tv2);
32 | tv1 = (TextView) findViewById(R.id.tv1);
33 | tv = (TextView) findViewById(R.id.tv);
34 |
35 | tv2.setTextSize(25);
36 | tv1.setTextSize(25);
37 | tv.setTextSize(25);
38 |
39 | tv.setText(msg);
40 | Resources resources = this.getResources();
41 | DisplayMetrics dm = resources.getDisplayMetrics();
42 | float density = dm.density;
43 | int width = dm.widthPixels;
44 | int height = dm.heightPixels;
45 | Log.i(TAG, "onCreate: "+width);
46 |
47 | Drawable down = getResources().getDrawable(R.drawable.down);
48 | Drawable up = getResources().getDrawable(R.drawable.up);
49 | new UtilMoreText(tv2,msg,down,up).createImg();
50 | float real = DensityUtil.px2sp(this,width);
51 | Log.i(TAG, "onCreate: "+real);
52 | new UtilMoreText(tv1,msg).setSpanTextColor(R.color.colorAccent).createString();
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/down.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/binny1024/MoreTextView/2c4c1a75aebc4c6d9b954472378a9f7b95607e51/app/src/main/res/drawable/down.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/up.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/binny1024/MoreTextView/2c4c1a75aebc4c6d9b954472378a9f7b95607e51/app/src/main/res/drawable/up.png
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
14 |
21 |
22 |
27 |
33 |
38 |
45 |
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/binny1024/MoreTextView/2c4c1a75aebc4c6d9b954472378a9f7b95607e51/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/binny1024/MoreTextView/2c4c1a75aebc4c6d9b954472378a9f7b95607e51/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/binny1024/MoreTextView/2c4c1a75aebc4c6d9b954472378a9f7b95607e51/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/binny1024/MoreTextView/2c4c1a75aebc4c6d9b954472378a9f7b95607e51/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/binny1024/MoreTextView/2c4c1a75aebc4c6d9b954472378a9f7b95607e51/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | More
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | maven {
7 | url 'https://maven.google.com/'
8 | name 'Google'
9 | }
10 | }
11 | dependencies {
12 | classpath 'com.android.tools.build:gradle:2.2.0'
13 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7'
14 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
15 | // NOTE: Do not place your application dependencies here; they belong
16 | // in the individual module build.gradle files
17 | }
18 | }
19 |
20 | allprojects {
21 | repositories {
22 | jcenter()
23 | maven {
24 | url 'https://maven.google.com/'
25 | name 'Google'
26 | }
27 | }
28 | }
29 |
30 | task clean(type: Delete) {
31 | delete rootProject.buildDir
32 | }
33 |
--------------------------------------------------------------------------------
/gif/3.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/binny1024/MoreTextView/2c4c1a75aebc4c6d9b954472378a9f7b95607e51/gif/3.gif
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/binny1024/MoreTextView/2c4c1a75aebc4c6d9b954472378a9f7b95607e51/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
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-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/moretext/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/moretext/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 | apply plugin: 'com.jfrog.bintray'
4 |
5 | version = "1.0.0"//这个是版本号,必须填写
6 | android {
7 | compileSdkVersion 25
8 | buildToolsVersion "25.0.2"
9 |
10 | // resourcePrefix "holder_" //资源前缀
11 | defaultConfig {
12 | minSdkVersion 15
13 | targetSdkVersion 25
14 | versionCode 1
15 | versionName "1.0"
16 |
17 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
18 |
19 | }
20 | buildTypes {
21 | release {
22 | minifyEnabled false
23 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
24 | }
25 | }
26 | }
27 |
28 | dependencies {
29 | compile fileTree(dir: 'libs', include: ['*.jar'])
30 | }
31 | def siteUrl = 'https://github.com/XBean1024' // 项目的主页 这个是说明,可随便填
32 | def gitUrl = 'https://github.com/XBean1024' // Git仓库的url 这个是说明,可随便填
33 | group = "com.smart.moretext" // 这里是groupId ,必须填写 一般填你唯一的包名,一旦写好好,就不要修改了
34 |
35 | install {
36 | repositories.mavenInstaller {
37 | // This generates POM.xml with proper parameters
38 | pom {
39 | project {
40 | packaging 'aar'
41 | // Add your description here
42 | name 'Android Custom ViewHolder' //项目描述
43 | url siteUrl
44 | // Set your license
45 | licenses {
46 | license {
47 | name 'The Apache Software License, Version 2.0'
48 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
49 | }
50 | }
51 | developers {
52 | developer {
53 | id 'ouyangmuyuan' //填写开发者的一些基本信息
54 | name 'ouyangmuyuan' //填写开发者的一些基本信息
55 | email '596928539@qq.com' //填写开发者的一些基本信息
56 | }
57 | }
58 | scm {
59 | connection gitUrl
60 | developerConnection gitUrl
61 | url siteUrl
62 | }
63 | }
64 | }
65 | }
66 | }
67 |
68 | task sourcesJar(type: Jar) {
69 | from android.sourceSets.main.java.srcDirs
70 | classifier = 'sources'
71 | }
72 | task javadoc(type: Javadoc) {
73 | source = android.sourceSets.main.java.srcDirs
74 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
75 | }
76 | task javadocJar(type: Jar, dependsOn: javadoc) {
77 | classifier = 'javadoc'
78 | from javadoc.destinationDir
79 | }
80 | artifacts {
81 | archives javadocJar
82 | archives sourcesJar
83 | }
84 |
85 | Properties properties = new Properties()
86 | properties.load(project.rootProject.file('local.properties').newDataInputStream())
87 | bintray {
88 | user = properties.getProperty("bintray.user") //读取 local.properties 文件里面的 bintray.user
89 | key = properties.getProperty("bintray.apikey") //读取 local.properties 文件里面的 bintray.apikey
90 | configurations = ['archives']
91 | pkg {
92 | repo = "maven"
93 | name = "more_text_view" //发布到JCenter上的项目名字,必须填写(新库修改)=================================================================================================
94 | websiteUrl = siteUrl
95 | vcsUrl = gitUrl
96 | licenses = ["Apache-2.0"]
97 | publish = true
98 | }
99 | }
100 |
101 | javadoc {
102 | options{
103 | encoding "UTF-8"
104 | charSet 'UTF-8'
105 | author true
106 | version true
107 | links "http://docs.oracle.com/javase/7/docs/api"
108 | }
109 | }
110 |
111 |
--------------------------------------------------------------------------------
/moretext/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 D:\AndroidSDK\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 |
--------------------------------------------------------------------------------
/moretext/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/moretext/src/main/java/com/smart/moretext/CenterAlignImageSpan.java:
--------------------------------------------------------------------------------
1 | package com.smart.moretext;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.Canvas;
5 | import android.graphics.Paint;
6 | import android.graphics.drawable.Drawable;
7 | import android.text.style.ImageSpan;
8 |
9 | public class CenterAlignImageSpan extends ImageSpan {
10 |
11 | public CenterAlignImageSpan(Drawable drawable) {
12 | super(drawable);
13 |
14 | }
15 |
16 | public CenterAlignImageSpan(Bitmap b) {
17 | super(b);
18 | }
19 |
20 | @Override
21 | public void draw( Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom,
22 | Paint paint) {
23 |
24 | Drawable b = getDrawable();
25 | Paint.FontMetricsInt fm = paint.getFontMetricsInt();
26 | int transY = (y + fm.descent + y + fm.ascent) / 2 - b.getBounds().bottom / 2;//计算y方向的位移
27 | canvas.save();
28 | canvas.translate(x, transY);//绘制图片位移一段距离
29 | b.draw(canvas);
30 | canvas.restore();
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/moretext/src/main/java/com/smart/moretext/UtilMoreText.java:
--------------------------------------------------------------------------------
1 | package com.smart.moretext;
2 |
3 |
4 | import android.graphics.Color;
5 | import android.graphics.drawable.Drawable;
6 | import android.text.SpannableString;
7 | import android.text.Spanned;
8 | import android.text.TextPaint;
9 | import android.text.method.LinkMovementMethod;
10 | import android.text.style.ClickableSpan;
11 | import android.util.DisplayMetrics;
12 | import android.util.Log;
13 | import android.view.View;
14 | import android.widget.TextView;
15 |
16 | /**
17 | * Created by xbb on 2017/5/10.
18 | */
19 |
20 | /*
21 | * 简单的富文本工具类
22 | *
23 | * 使用说明 new UtilMoreText(tv2,msg);
24 | * */
25 | public final class UtilMoreText {
26 |
27 | private float mExpectedWidth; //期望行宽度
28 | private TextView mTextView;//显示富文本的控件
29 | private String mOriMsg;//全部文本信息
30 |
31 | /**
32 | * 是否展开
33 | */
34 | private boolean spread = true;
35 |
36 | /**
37 | * 文字颜色
38 | */
39 | private Integer mSpanTextColor;
40 |
41 | /**
42 | * 设置图片
43 | */
44 | private Drawable mDrawableOpen;
45 | private Drawable mDrawableClose;
46 |
47 | /**
48 | * 文字
49 | */
50 | private String mTextOpen = "...展开";
51 | private String mTextClose = "收起";
52 |
53 | /**
54 | * 行数
55 | */
56 | private int mLines = 2;
57 |
58 | /**
59 | * @param textView 文本框
60 | * @param oriMsg 原始信息
61 | * @param textOpen 展开性质的文字
62 | * @param textClose 关闭性质的文字
63 | */
64 | public UtilMoreText(final TextView textView, String oriMsg, String textOpen, String textClose) {
65 | mTextView = textView;
66 | mOriMsg = oriMsg;
67 | mTextOpen = textOpen;
68 | mTextClose = textClose;
69 | }
70 |
71 | /**
72 | * @param textView 文本框
73 | * @param oriMsg 原始文字
74 | */
75 | public UtilMoreText(final TextView textView, String oriMsg) {
76 | mTextView = textView;
77 | mOriMsg = oriMsg;
78 | }
79 |
80 | /**
81 | * @param textView 文本框
82 | * @param oriMsg 原始文字
83 | * @param drawableOpen 展开图标
84 | * @param drawableColse 关闭图标
85 | */
86 | public UtilMoreText(final TextView textView, String oriMsg, Drawable drawableOpen, Drawable drawableColse) {
87 | mTextView = textView;
88 | mOriMsg = oriMsg + "XX";
89 | mDrawableOpen = drawableOpen;
90 | mDrawableClose = drawableColse;
91 | }
92 |
93 | private static final String TAG = "ddd";
94 |
95 | /**
96 | * 设置行数
97 | *
98 | * @param lineNum 函数
99 | * @return UtilMoreText
100 | */
101 | private UtilMoreText setLines(int lineNum) {
102 | Log.i(TAG, "setLines: " + lineNum);
103 | this.mLines = lineNum;
104 | return this;
105 | }
106 |
107 | /**
108 | * 创建文本形式的结尾
109 | */
110 | public void createString() {
111 | mTextView.setMovementMethod(LinkMovementMethod.getInstance());//必须设置否则无效
112 | mTextView.setText(compressedWithString());
113 | }
114 |
115 | /**
116 | * 创建图片形似的结尾
117 | */
118 | public void createImg() {
119 | mTextView.setMovementMethod(LinkMovementMethod.getInstance());//必须设置否则无效
120 | mTextView.setText(compressedWithImg());
121 | }
122 |
123 | private UtilMoreText setExpectedWidth(float expectedWidth) {
124 | this.mExpectedWidth = expectedWidth;
125 | return this;
126 | }
127 |
128 | /** 设置结尾 文字的颜色
129 | * @param spanTextColor 颜色id
130 | * @return 本类实例
131 | */
132 | public UtilMoreText setSpanTextColor(int spanTextColor) {
133 | mSpanTextColor = spanTextColor;
134 | return this;
135 | }
136 |
137 |
138 | class spanImgClickable extends ClickableSpan {
139 | @Override
140 | public void onClick(View widget) {
141 | Log.i("colick", "onClick: ");
142 | TextView textView = (TextView) widget;
143 | if (spread) {//调用展开的方法
144 | spread = false;
145 | textView.setText(getSpannableImg(mOriMsg, mDrawableClose));
146 |
147 | } else {
148 | spread = true;
149 | textView.setText(getSpannableImg(textView.getText().subSequence(0, mOriMsg.length() >> 1), mDrawableOpen));
150 | }
151 | }
152 |
153 | @Override
154 | public void updateDrawState(TextPaint ds) {
155 | super.updateDrawState(ds);
156 | }
157 | }
158 |
159 | class SpanTextClickable extends ClickableSpan {
160 | @Override
161 | public void onClick(View widget) {
162 | if (spread) {//调用展开的方法
163 | spread = false;
164 | mTextView.setText(getSpannableString(mOriMsg + mTextClose));
165 | } else {
166 | spread = true;
167 | mTextView.setText(compressedWithString());
168 | }
169 | }
170 |
171 | @Override
172 | public void updateDrawState(TextPaint ds) {
173 | if (mSpanTextColor == null) {
174 | ds.setColor(mSpanTextColor);
175 | } else {
176 | ds.setColor(ds.linkColor);
177 | }
178 | ds.setUnderlineText(false); //去除超链接的下划线
179 | }
180 | }
181 |
182 | private SpannableString compressedWithImg() {
183 | return getSpannableImg(mOriMsg.substring(0, mOriMsg.length() >> 1), mDrawableOpen);
184 | }
185 |
186 | /**
187 | * 压缩字符串
188 | *
189 | * @return 富文本字符串
190 | */
191 | private SpannableString compressedWithString() {
192 | if (mOriMsg.length() == 0) {
193 | return getSpannableString(mOriMsg);
194 | }
195 | String resultText = mOriMsg.substring(0, mOriMsg.length() >> 1) + mTextOpen;
196 | return getSpannableString(resultText);
197 | }
198 |
199 | private SpannableString compressedWithString1() {
200 | if (mOriMsg.length() == 0) {
201 | return getSpannableString(mOriMsg);
202 | }
203 | String resultText = "";//处理后的字符串
204 | String tempResultText = mOriMsg + mTextOpen;
205 | TextPaint paint = mTextView.getPaint();
206 | paint.setTextSize(mTextView.getTextSize());
207 |
208 | float num = mExpectedWidth * mLines;
209 | if (paint.measureText(tempResultText) < num) {
210 | resultText = mOriMsg;
211 | } else {
212 | boolean continuation = true;
213 | int mPos = 0;
214 | while (continuation) {
215 | mPos++;
216 | resultText = mOriMsg.substring(0, mPos);
217 | float len = paint.measureText(resultText);
218 | if (len > num) {
219 | continuation = false;
220 | }
221 | }
222 | }
223 | resultText = resultText + mTextOpen;
224 | return getSpannableString(resultText);
225 | }
226 |
227 | /**
228 | * 文字
229 | *
230 | * @param text 文字
231 | * @return SpannableString
232 | */
233 | private SpannableString getSpannableString(CharSequence text) {
234 | int len = text.length();
235 |
236 | if (len == 0 || len < 5) {
237 | text = "请输入要展示的信息!";
238 | return new SpannableString(text);
239 | }
240 | SpannableString spanableInfo = new SpannableString(text);
241 | spanableInfo.setSpan(new SpanTextClickable(), text.length() - mTextOpen.length() + 3, text.length(),
242 | Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
243 | return spanableInfo;
244 | }
245 |
246 | /**
247 | * 设置富文本 图片
248 | *
249 | * @param text 文字
250 | * @param drawable 图片
251 | * @return SpannableString
252 | */
253 | private SpannableString getSpannableImg(CharSequence text, Drawable drawable) {
254 | int len = text.length();
255 | if (len == 0 || len < 5) {
256 | text = "请输入要展示的信息!";
257 | return new SpannableString(text);
258 | }
259 | SpannableString spanableInfo = new SpannableString(text);
260 | int drawHeight = drawable.getMinimumHeight();
261 | drawable.setBounds(0, 0, drawHeight, drawHeight);
262 | CenterAlignImageSpan imageSpan = new CenterAlignImageSpan(drawable);
263 | spanableInfo.setSpan(imageSpan, len - 2, len, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
264 | spanableInfo.setSpan(new spanImgClickable(), text.length() - 2, text.length(),
265 | Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
266 | return spanableInfo;
267 | }
268 | }
269 |
--------------------------------------------------------------------------------
/moretext/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | MoreText
3 |
4 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':moretext'
2 |
--------------------------------------------------------------------------------