├── .gitattributes
├── .gitignore
├── PraiseTextView
├── .gitignore
├── .idea
│ ├── compiler.xml
│ ├── copyright
│ │ └── profiles_settings.xml
│ ├── gradle.xml
│ ├── misc.xml
│ ├── modules.xml
│ └── runConfigurations.xml
├── app
│ ├── .gitignore
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src
│ │ ├── androidTest
│ │ └── java
│ │ │ └── com
│ │ │ └── lujianchao
│ │ │ └── praisetextview
│ │ │ └── praisetextview
│ │ │ └── ExampleInstrumentedTest.java
│ │ ├── main
│ │ ├── AndroidManifest.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── lujianchao
│ │ │ │ └── praisetextview
│ │ │ │ ├── MainActivity.java
│ │ │ │ └── PraiseTextView.java
│ │ └── res
│ │ │ ├── drawable
│ │ │ ├── a.jpg
│ │ │ └── emoji_1f0cf.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
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── lujianchao
│ │ └── praisetextview
│ │ └── praisetextview
│ │ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
├── README.md
├── pic1.jpg
└── pic2.gif
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 |
7 | # Standard to msysgit
8 | *.doc diff=astextplain
9 | *.DOC diff=astextplain
10 | *.docx diff=astextplain
11 | *.DOCX diff=astextplain
12 | *.dot diff=astextplain
13 | *.DOT diff=astextplain
14 | *.pdf diff=astextplain
15 | *.PDF diff=astextplain
16 | *.rtf diff=astextplain
17 | *.RTF diff=astextplain
18 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # Intellij
36 | *.iml
37 |
38 | # Keystore files
39 | *.jks
40 |
41 | # =========================
42 | # Operating System Files
43 | # =========================
44 |
45 | # OSX
46 | # =========================
47 |
48 | .DS_Store
49 | .AppleDouble
50 | .LSOverride
51 |
52 | # Thumbnails
53 | ._*
54 |
55 | # Files that might appear in the root of a volume
56 | .DocumentRevisions-V100
57 | .fseventsd
58 | .Spotlight-V100
59 | .TemporaryItems
60 | .Trashes
61 | .VolumeIcon.icns
62 |
63 | # Directories potentially created on remote AFP share
64 | .AppleDB
65 | .AppleDesktop
66 | Network Trash Folder
67 | Temporary Items
68 | .apdisk
69 |
70 | # Windows
71 | # =========================
72 |
73 | # Windows image file caches
74 | Thumbs.db
75 | ehthumbs.db
76 |
77 | # Folder config file
78 | Desktop.ini
79 |
80 | # Recycle Bin used on file shares
81 | $RECYCLE.BIN/
82 |
83 | # Windows Installer files
84 | *.cab
85 | *.msi
86 | *.msm
87 | *.msp
88 |
89 | # Windows shortcuts
90 | *.lnk
91 |
--------------------------------------------------------------------------------
/PraiseTextView/.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 |
--------------------------------------------------------------------------------
/PraiseTextView/.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 |
--------------------------------------------------------------------------------
/PraiseTextView/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/PraiseTextView/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
17 |
18 |
--------------------------------------------------------------------------------
/PraiseTextView/.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 |
--------------------------------------------------------------------------------
/PraiseTextView/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/PraiseTextView/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/PraiseTextView/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/PraiseTextView/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.1"
6 | defaultConfig {
7 | applicationId "com.lujianchao.praisetextview"
8 | minSdkVersion 16
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(dir: 'libs', include: ['*.jar'])
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.1.0'
28 | testCompile 'junit:junit:4.12'
29 | }
30 |
--------------------------------------------------------------------------------
/PraiseTextView/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 E:\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 |
--------------------------------------------------------------------------------
/PraiseTextView/app/src/androidTest/java/com/lujianchao/praisetextview/praisetextview/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.lujianchao.praisetextview.praisetextview;
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.lujianchao.praisetextview.praisetextview", appContext.getPackageName ());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/PraiseTextView/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/PraiseTextView/app/src/main/java/com/lujianchao/praisetextview/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.lujianchao.praisetextview;
2 |
3 | import android.graphics.Color;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.text.method.ScrollingMovementMethod;
7 | import android.widget.TextView;
8 |
9 | import java.util.ArrayList;
10 | import java.util.List;
11 |
12 | public class MainActivity extends AppCompatActivity {
13 | private PraiseTextView mPraiseTextView;
14 | private TextView mTextView;
15 |
16 | @Override
17 | protected void onCreate (Bundle savedInstanceState) {
18 | super.onCreate (savedInstanceState);
19 | setContentView (R.layout.activity_main);
20 | mPraiseTextView = (PraiseTextView) findViewById (R.id.praisetextview);
21 | mTextView = (TextView) findViewById (R.id.log);
22 | mTextView.setMovementMethod (ScrollingMovementMethod.getInstance ());
23 |
24 |
25 | List mPraiseInfos = new ArrayList<> ();
26 | mPraiseInfos.add (new PraiseTextView.PraiseInfo ().setId (111).setNickname ("张三").setLogo ("http://lujianchao.com/images/headimg/1.jpg"));
27 | mPraiseInfos.add (new PraiseTextView.PraiseInfo ().setId (222).setNickname ("张四").setLogo ("http://lujianchao.com/images/headimg/2.jpg"));
28 | mPraiseInfos.add (new PraiseTextView.PraiseInfo ().setId (333).setNickname ("张五").setLogo ("http://lujianchao.com/images/headimg/3.jpg"));
29 | mPraiseInfos.add (new PraiseTextView.PraiseInfo ().setId (444).setNickname ("张六").setLogo ("http://lujianchao.com/images/headimg/4.jpg"));
30 | mPraiseInfos.add (new PraiseTextView.PraiseInfo ().setId (555).setNickname ("赵四").setLogo ("http://lujianchao.com/images/headimg/5.jpg"));
31 | mPraiseInfos.add (new PraiseTextView.PraiseInfo ().setId (666).setNickname ("赵三").setLogo ("http://lujianchao.com/images/headimg/6.jpg"));
32 | mPraiseInfos.add (new PraiseTextView.PraiseInfo ().setId (777).setNickname ("李大").setLogo ("http://lujianchao.com/images/headimg/7.jpg"));
33 | mPraiseInfos.add (new PraiseTextView.PraiseInfo ().setId (888).setNickname ("李二").setLogo ("http://lujianchao.com/images/headimg/8.jpg"));
34 | mPraiseInfos.add (new PraiseTextView.PraiseInfo ().setId (999).setNickname ("李三").setLogo ("http://lujianchao.com/images/headimg/9.jpg"));
35 | mPraiseTextView.setData (mPraiseInfos);
36 | mPraiseTextView.setNameTextColor (Color.BLUE);
37 | mPraiseTextView.setIcon (R.drawable.emoji_1f0cf);
38 | mPraiseTextView.setMiddleStr (",");
39 | // mPraiseTextView.setIconSize (new Rect (0,0,33,33));
40 | mPraiseTextView.setonPraiseListener (new PraiseTextView.onPraiseClickListener () {
41 | @Override
42 | public void onClick (final int position, final PraiseTextView.PraiseInfo mPraiseInfo) {
43 | mTextView.append ("position = [" + position + "], mPraiseInfo = [" + mPraiseInfo + "]"+"\r\n");
44 | }
45 |
46 | @Override
47 | public void onOtherClick () {
48 | mTextView.append ("onOtherClick"+"\r\n");
49 | }
50 | });
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/PraiseTextView/app/src/main/java/com/lujianchao/praisetextview/PraiseTextView.java:
--------------------------------------------------------------------------------
1 | package com.lujianchao.praisetextview;
2 |
3 | import android.content.Context;
4 | import android.graphics.Color;
5 | import android.graphics.Rect;
6 | import android.graphics.drawable.Drawable;
7 | import android.text.Spannable;
8 | import android.text.SpannableStringBuilder;
9 | import android.text.Spanned;
10 | import android.text.TextPaint;
11 | import android.text.TextUtils;
12 | import android.text.method.LinkMovementMethod;
13 | import android.text.style.ClickableSpan;
14 | import android.text.style.ImageSpan;
15 | import android.util.AttributeSet;
16 | import android.view.View;
17 | import android.widget.TextView;
18 |
19 | import java.util.List;
20 |
21 | /**
22 | * Created by lujianchao on 2017/1/23.
23 | *
24 | * @author lujianchao
25 | */
26 |
27 | public class PraiseTextView extends TextView {
28 | private List mPraiseInfos;
29 | private onPraiseClickListener mListener;
30 | /**
31 | * 第一个显示的图标
32 | */
33 | private int mIcon = R.drawable.emoji_1f0cf;
34 | /**
35 | * 名字文字颜色,分割文本用textview默认的,自行设置即可
36 | */
37 | private int mNameTextColor = Color.GREEN;
38 | /**
39 | * 不设置默认与文字大小匹配
40 | */
41 | private Rect mIconSize = null;
42 | /**
43 | * 中间分割的文本
44 | */
45 | private String mMiddleStr = ",";
46 | private boolean isClickName = false;
47 |
48 | public PraiseTextView (Context context) {
49 | super (context);
50 | }
51 |
52 | public PraiseTextView (Context context, AttributeSet attrs) {
53 | super (context, attrs);
54 | }
55 |
56 | public onPraiseClickListener getonPraiseListener () {
57 | return mListener;
58 | }
59 |
60 | public PraiseTextView setonPraiseListener (onPraiseClickListener mListener) {
61 | this.mListener = mListener;
62 | return this;
63 | }
64 |
65 | public String getMiddleStr () {
66 | return mMiddleStr;
67 | }
68 |
69 | public PraiseTextView setMiddleStr (final String mMiddleStr) {
70 | this.mMiddleStr = mMiddleStr;
71 | return this;
72 | }
73 |
74 | public int getIcon () {
75 | return mIcon;
76 | }
77 |
78 | public PraiseTextView setIcon (int mIcon) {
79 | this.mIcon = mIcon;
80 | return this;
81 | }
82 |
83 | public int getNameTextColor () {
84 | return mNameTextColor;
85 | }
86 |
87 | public PraiseTextView setNameTextColor (int mNameTextColor) {
88 | this.mNameTextColor = mNameTextColor;
89 | return this;
90 | }
91 |
92 | public Rect getIconSize () {
93 | return mIconSize;
94 | }
95 |
96 | /**
97 | * 不设置默认与文字大小匹配
98 | */
99 | public PraiseTextView setIconSize (Rect mIconSize) {
100 | this.mIconSize = mIconSize;
101 | return this;
102 | }
103 |
104 | public PraiseTextView setData (List mPraiseInfos) {
105 | this.mPraiseInfos = mPraiseInfos;
106 | this.setHighlightColor (Color.TRANSPARENT);
107 | this.setMovementMethod (LinkMovementMethod.getInstance ());
108 | this.setText (getPraiseString ());
109 | this.setOnClickListener (new OnClickListener () {
110 | @Override
111 | public void onClick (final View mView) {
112 | if (isClickName) {
113 | isClickName=false;
114 | return;
115 | }
116 | if (mListener != null) {
117 | mListener.onOtherClick ();
118 | }
119 | }
120 | });
121 | return this;
122 | }
123 |
124 | private SpannableStringBuilder getPraiseString () {
125 | SpannableStringBuilder mBuilder = new SpannableStringBuilder ("我");
126 | mBuilder.setSpan (new iconimage (getResources ().getDrawable (mIcon)), 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
127 | for (int mI = 0; mI < mPraiseInfos.size (); mI++) {
128 | if (!TextUtils.isEmpty (mPraiseInfos.get (mI).getNickname ())) {
129 | mBuilder.append (mPraiseInfos.get (mI).getNickname () + mMiddleStr);
130 | final int finalMI = mI;
131 | mBuilder.setSpan (new ClickableSpan () {
132 | @Override
133 | public void onClick (final View mView) {
134 | isClickName = true;
135 | if (mListener != null) {
136 | mListener.onClick (finalMI, mPraiseInfos.get (finalMI));
137 | }
138 | }
139 |
140 | @Override
141 | public void updateDrawState (final TextPaint ds) {
142 | super.updateDrawState (ds);
143 | ds.setUnderlineText (false);
144 | ds.setColor (mNameTextColor);
145 | }
146 | }, mBuilder.length () - mPraiseInfos.get (mI).getNickname ().length () - mMiddleStr.length (), mBuilder.length () - mMiddleStr.length (), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
147 | }
148 | }
149 | mBuilder = new SpannableStringBuilder (mBuilder, 0, mBuilder.length () - 1);
150 | mBuilder.append (" ");
151 | return mBuilder;
152 | }
153 |
154 | public interface onPraiseClickListener {
155 | public void onClick (int position, PraiseInfo mPraiseInfo);
156 |
157 | public void onOtherClick ();
158 | }
159 |
160 | public static class PraiseInfo {
161 | private int id;
162 | private String nickname;
163 | private String logo;
164 |
165 | @Override
166 | public String toString () {
167 | return "PraiseInfo{" +
168 | "id=" + id +
169 | ", nickname='" + nickname + '\'' +
170 | ", logo='" + logo + '\'' +
171 | '}';
172 | }
173 |
174 | public int getId () {
175 | return id;
176 | }
177 |
178 | public PraiseInfo setId (final int mId) {
179 | id = mId;
180 | return this;
181 | }
182 |
183 | public String getNickname () {
184 | return nickname;
185 | }
186 |
187 | public PraiseInfo setNickname (final String mNickname) {
188 | nickname = mNickname;
189 | return this;
190 | }
191 |
192 | public String getLogo () {
193 | return logo;
194 | }
195 |
196 | public PraiseInfo setLogo (final String mLogo) {
197 | logo = mLogo;
198 | return this;
199 | }
200 | }
201 |
202 | public class iconimage extends ImageSpan {
203 | private Drawable mDrawable;
204 |
205 | public iconimage (Drawable d) {
206 | super (d);
207 | mDrawable = d;
208 | }
209 |
210 | @Override
211 | public Drawable getDrawable () {
212 | if (mIconSize == null) {
213 | Rect mRect = new Rect ();
214 | getPaint ().getTextBounds ("我", 0, 1, mRect);
215 | mDrawable.setBounds (mRect);
216 | } else {
217 | mDrawable.setBounds (mIconSize);
218 | }
219 | return mDrawable;
220 | }
221 | }
222 | }
223 |
--------------------------------------------------------------------------------
/PraiseTextView/app/src/main/res/drawable/a.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/itgowo/PraiseTextView/92ae860fec3cc1c4a5044e921cfcc306f0313024/PraiseTextView/app/src/main/res/drawable/a.jpg
--------------------------------------------------------------------------------
/PraiseTextView/app/src/main/res/drawable/emoji_1f0cf.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/itgowo/PraiseTextView/92ae860fec3cc1c4a5044e921cfcc306f0313024/PraiseTextView/app/src/main/res/drawable/emoji_1f0cf.png
--------------------------------------------------------------------------------
/PraiseTextView/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
20 |
21 |
26 |
27 |
--------------------------------------------------------------------------------
/PraiseTextView/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/itgowo/PraiseTextView/92ae860fec3cc1c4a5044e921cfcc306f0313024/PraiseTextView/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/PraiseTextView/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/itgowo/PraiseTextView/92ae860fec3cc1c4a5044e921cfcc306f0313024/PraiseTextView/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/PraiseTextView/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/itgowo/PraiseTextView/92ae860fec3cc1c4a5044e921cfcc306f0313024/PraiseTextView/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/PraiseTextView/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/itgowo/PraiseTextView/92ae860fec3cc1c4a5044e921cfcc306f0313024/PraiseTextView/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/PraiseTextView/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/itgowo/PraiseTextView/92ae860fec3cc1c4a5044e921cfcc306f0313024/PraiseTextView/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/PraiseTextView/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/PraiseTextView/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/PraiseTextView/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/PraiseTextView/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | PraiseTextView
3 |
4 |
--------------------------------------------------------------------------------
/PraiseTextView/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/PraiseTextView/app/src/test/java/com/lujianchao/praisetextview/praisetextview/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.lujianchao.praisetextview.praisetextview;
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 | }
--------------------------------------------------------------------------------
/PraiseTextView/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 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.2.3'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/PraiseTextView/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 |
--------------------------------------------------------------------------------
/PraiseTextView/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/itgowo/PraiseTextView/92ae860fec3cc1c4a5044e921cfcc306f0313024/PraiseTextView/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/PraiseTextView/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 |
--------------------------------------------------------------------------------
/PraiseTextView/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 |
--------------------------------------------------------------------------------
/PraiseTextView/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 |
--------------------------------------------------------------------------------
/PraiseTextView/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # PraiseTextView #
2 |
3 |
4 | ## 说明
5 |
6 | #### 我是将朋友圈分成了几个独立模块单独自定义的View,通过回调完成交互,耦合性算是非常低了,主要有以下及部分:
7 |
8 | 1.评论布局(自定义TextView)
9 |
10 | [CommentListTextView](https://github.com/hnsugar/CommentListTextView/)
11 |
12 | [Lu_PingLunLayout](https://github.com/hnsugar/lu_pinglunlayout/)
13 |
14 | 2.点赞布局(原理和评论的自定义TextView一样,都是用的SpannableString)
15 |
16 | [PraiseTextView](https://github.com/hnsugar/PraiseTextView/)
17 |
18 |
19 | 3.图片列表(出门右转,理论上没有数量限制,和listView配合使用也很好,缓存也自己处理了)
20 |
21 | [MultiImageViewLayout](https://github.com/hnsugar/MultiImageViewLayout/)
22 |
23 | 我也是找第三方例子不好找,于是自己写了一个,我和同事还打算做一套IM系统,app和后台都要做,我们自己定义sdk,我们还要封装H5,类似hbuilder如果有什么问题,可以联系我,
24 |
25 | QQ:1264957104
26 |
27 | CSDN:http://blog.csdn.net/hnsugar
28 |
29 | GitHub:https://github.com/hnsugar
30 |
31 | 个人做测试项目的服务器:http://lujianchao.com
32 |
33 | 链接是跳转到GitHub的,部分文章我会直接贴出关键View的代码。
34 |
35 | ## 示例 ##
36 |
37 | 
38 | 
39 |
40 | 
41 |
42 | ##主要方法##
43 | mPraiseTextView.setData (mPraiseInfos);//设置数据
44 | mPraiseTextView.setNameTextColor (Color.BLUE);//设置名字字体颜色
45 | mPraiseTextView.setIcon (R.drawable.emoji_1f0cf);//设置图标
46 | mPraiseTextView.setMiddleStr (",");//设置分割文本
47 | mPraiseTextView.setIconSize (new Rect (0,0,100,100));//设置图标大小,默认与字号匹配
48 | mPraiseTextView.setonPraiseListener()//设置监听
49 |
50 | ## onClick (int position, PraiseTextView.PraiseInfo mPraiseInfo) ##
51 | position是第几个点赞的人,mInfo是这条点赞的信息
52 |
53 |
54 | ## onOtherClick ##
55 | 内部处理了点击文字会触发两个回调的问题,这个是点击非文字或者没有单独定义点击事件的回调
56 |
57 |
58 |
59 |
60 |
61 |
62 | ## 布局 ##
63 |
64 |
65 |
77 |
78 |
83 |
84 |
89 |
90 |
91 |
92 |
93 |
94 |
95 | ## 代码 ##
96 |
97 | public class MainActivity extends AppCompatActivity {
98 | private PraiseTextView mPraiseTextView;
99 | private TextView mTextView;
100 |
101 | @Override
102 | protected void onCreate (Bundle savedInstanceState) {
103 | super.onCreate (savedInstanceState);
104 | setContentView (R.layout.activity_main);
105 | mPraiseTextView = (PraiseTextView) findViewById (R.id.praisetextview);
106 | mTextView = (TextView) findViewById (R.id.log);
107 | mTextView.setMovementMethod (ScrollingMovementMethod.getInstance ());
108 |
109 |
110 | List mPraiseInfos = new ArrayList<> ();
111 | mPraiseInfos.add (new PraiseTextView.PraiseInfo ().setId (111).setNickname ("张三").setLogo ("http://lujianchao.com/images/headimg/1.jpg"));
112 | mPraiseInfos.add (new PraiseTextView.PraiseInfo ().setId (222).setNickname ("张四").setLogo ("http://lujianchao.com/images/headimg/2.jpg"));
113 | mPraiseInfos.add (new PraiseTextView.PraiseInfo ().setId (333).setNickname ("张五").setLogo ("http://lujianchao.com/images/headimg/3.jpg"));
114 | mPraiseInfos.add (new PraiseTextView.PraiseInfo ().setId (444).setNickname ("张六").setLogo ("http://lujianchao.com/images/headimg/4.jpg"));
115 | mPraiseInfos.add (new PraiseTextView.PraiseInfo ().setId (555).setNickname ("赵四").setLogo ("http://lujianchao.com/images/headimg/5.jpg"));
116 | mPraiseInfos.add (new PraiseTextView.PraiseInfo ().setId (666).setNickname ("赵三").setLogo ("http://lujianchao.com/images/headimg/6.jpg"));
117 | mPraiseInfos.add (new PraiseTextView.PraiseInfo ().setId (777).setNickname ("李大").setLogo ("http://lujianchao.com/images/headimg/7.jpg"));
118 | mPraiseInfos.add (new PraiseTextView.PraiseInfo ().setId (888).setNickname ("李二").setLogo ("http://lujianchao.com/images/headimg/8.jpg"));
119 | mPraiseInfos.add (new PraiseTextView.PraiseInfo ().setId (999).setNickname ("李三").setLogo ("http://lujianchao.com/images/headimg/9.jpg"));
120 | mPraiseTextView.setData (mPraiseInfos);//设置数据
121 | mPraiseTextView.setNameTextColor (Color.BLUE);//设置名字字体颜色
122 | mPraiseTextView.setIcon (R.drawable.emoji_1f0cf);//设置图标
123 | mPraiseTextView.setMiddleStr (",");//设置分割文本
124 | mPraiseTextView.setIconSize (new Rect (0,0,100,100));//设置图标大小,默认与字号匹配
125 | mPraiseTextView.setonPraiseListener (new PraiseTextView.onPraiseClickListener () {
126 | @Override
127 | public void onClick (final int position, final PraiseTextView.PraiseInfo mPraiseInfo) {
128 | mTextView.append ("position = [" + position + "], mPraiseInfo = [" + mPraiseInfo + "]"+"\r\n");
129 | }
130 |
131 | @Override
132 | public void onOtherClick () {
133 | mTextView.append ("onOtherClick"+"\r\n");
134 | }
135 | });
136 | }
137 | }
138 |
139 |
140 | ##源码##
141 | package com.lujianchao.praisetextview;
142 |
143 | import android.content.Context;
144 | import android.graphics.Color;
145 | import android.graphics.Rect;
146 | import android.graphics.drawable.Drawable;
147 | import android.text.Spannable;
148 | import android.text.SpannableStringBuilder;
149 | import android.text.Spanned;
150 | import android.text.TextPaint;
151 | import android.text.TextUtils;
152 | import android.text.method.LinkMovementMethod;
153 | import android.text.style.ClickableSpan;
154 | import android.text.style.ImageSpan;
155 | import android.util.AttributeSet;
156 | import android.view.View;
157 | import android.widget.TextView;
158 |
159 | import java.util.List;
160 |
161 | /**
162 | * Created by lujianchao on 2017/1/23.
163 | *
164 | * @author lujianchao
165 | */
166 |
167 | public class PraiseTextView extends TextView {
168 | private List mPraiseInfos;
169 | private onPraiseClickListener mListener;
170 | /**
171 | * 第一个显示的图标
172 | */
173 | private int mIcon = R.drawable.emoji_1f0cf;
174 | /**
175 | * 名字文字颜色,分割文本用textview默认的,自行设置即可
176 | */
177 | private int mNameTextColor = Color.GREEN;
178 | /**
179 | * 不设置默认与文字大小匹配
180 | */
181 | private Rect mIconSize = null;
182 | /**
183 | * 中间分割的文本
184 | */
185 | private String mMiddleStr = ",";
186 | private boolean isClickName = false;
187 |
188 | public PraiseTextView (Context context) {
189 | super (context);
190 | }
191 |
192 | public PraiseTextView (Context context, AttributeSet attrs) {
193 | super (context, attrs);
194 | }
195 |
196 | public onPraiseClickListener getonPraiseListener () {
197 | return mListener;
198 | }
199 |
200 | public PraiseTextView setonPraiseListener (onPraiseClickListener mListener) {
201 | this.mListener = mListener;
202 | return this;
203 | }
204 |
205 | public String getMiddleStr () {
206 | return mMiddleStr;
207 | }
208 |
209 | public PraiseTextView setMiddleStr (final String mMiddleStr) {
210 | this.mMiddleStr = mMiddleStr;
211 | return this;
212 | }
213 |
214 | public int getIcon () {
215 | return mIcon;
216 | }
217 |
218 | public PraiseTextView setIcon (int mIcon) {
219 | this.mIcon = mIcon;
220 | return this;
221 | }
222 |
223 | public int getNameTextColor () {
224 | return mNameTextColor;
225 | }
226 |
227 | public PraiseTextView setNameTextColor (int mNameTextColor) {
228 | this.mNameTextColor = mNameTextColor;
229 | return this;
230 | }
231 |
232 | public Rect getIconSize () {
233 | return mIconSize;
234 | }
235 |
236 | /**
237 | * 不设置默认与文字大小匹配
238 | */
239 | public PraiseTextView setIconSize (Rect mIconSize) {
240 | this.mIconSize = mIconSize;
241 | return this;
242 | }
243 |
244 | public PraiseTextView setData (List mPraiseInfos) {
245 | this.mPraiseInfos = mPraiseInfos;
246 | this.setHighlightColor (Color.TRANSPARENT);
247 | this.setMovementMethod (LinkMovementMethod.getInstance ());
248 | this.setText (getPraiseString ());
249 | this.setOnClickListener (new OnClickListener () {
250 | @Override
251 | public void onClick (final View mView) {
252 | if (isClickName) {
253 | isClickName=false;
254 | return;
255 | }
256 | if (mListener != null) {
257 | mListener.onOtherClick ();
258 | }
259 | }
260 | });
261 | return this;
262 | }
263 |
264 | private SpannableStringBuilder getPraiseString () {
265 | SpannableStringBuilder mBuilder = new SpannableStringBuilder ("我");
266 | mBuilder.setSpan (new iconimage (getResources ().getDrawable (mIcon)), 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
267 | for (int mI = 0; mI < mPraiseInfos.size (); mI++) {
268 | if (!TextUtils.isEmpty (mPraiseInfos.get (mI).getNickname ())) {
269 | mBuilder.append (mPraiseInfos.get (mI).getNickname () + mMiddleStr);
270 | final int finalMI = mI;
271 | mBuilder.setSpan (new ClickableSpan () {
272 | @Override
273 | public void onClick (final View mView) {
274 | isClickName = true;
275 | if (mListener != null) {
276 | mListener.onClick (finalMI, mPraiseInfos.get (finalMI));
277 | }
278 | }
279 |
280 | @Override
281 | public void updateDrawState (final TextPaint ds) {
282 | super.updateDrawState (ds);
283 | ds.setUnderlineText (false);
284 | ds.setColor (mNameTextColor);
285 | }
286 | }, mBuilder.length () - mPraiseInfos.get (mI).getNickname ().length () - mMiddleStr.length (), mBuilder.length () - mMiddleStr.length (), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
287 | }
288 | }
289 | mBuilder = new SpannableStringBuilder (mBuilder, 0, mBuilder.length () - 1);
290 | mBuilder.append (" ");
291 | return mBuilder;
292 | }
293 |
294 | public interface onPraiseClickListener {
295 | public void onClick (int position, PraiseInfo mPraiseInfo);
296 |
297 | public void onOtherClick ();
298 | }
299 |
300 | public static class PraiseInfo {
301 | private int id;
302 | private String nickname;
303 | private String logo;
304 |
305 | @Override
306 | public String toString () {
307 | return "PraiseInfo{" +
308 | "id=" + id +
309 | ", nickname='" + nickname + '\'' +
310 | ", logo='" + logo + '\'' +
311 | '}';
312 | }
313 |
314 | public int getId () {
315 | return id;
316 | }
317 |
318 | public PraiseInfo setId (final int mId) {
319 | id = mId;
320 | return this;
321 | }
322 |
323 | public String getNickname () {
324 | return nickname;
325 | }
326 |
327 | public PraiseInfo setNickname (final String mNickname) {
328 | nickname = mNickname;
329 | return this;
330 | }
331 |
332 | public String getLogo () {
333 | return logo;
334 | }
335 |
336 | public PraiseInfo setLogo (final String mLogo) {
337 | logo = mLogo;
338 | return this;
339 | }
340 | }
341 |
342 | public class iconimage extends ImageSpan {
343 | private Drawable mDrawable;
344 |
345 | public iconimage (Drawable d) {
346 | super (d);
347 | mDrawable = d;
348 | }
349 |
350 | @Override
351 | public Drawable getDrawable () {
352 | if (mIconSize == null) {
353 | Rect mRect = new Rect ();
354 | getPaint ().getTextBounds ("我", 0, 1, mRect);
355 | mDrawable.setBounds (mRect);
356 | } else {
357 | mDrawable.setBounds (mIconSize);
358 | }
359 | return mDrawable;
360 | }
361 | }
362 | }
363 |
--------------------------------------------------------------------------------
/pic1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/itgowo/PraiseTextView/92ae860fec3cc1c4a5044e921cfcc306f0313024/pic1.jpg
--------------------------------------------------------------------------------
/pic2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/itgowo/PraiseTextView/92ae860fec3cc1c4a5044e921cfcc306f0313024/pic2.gif
--------------------------------------------------------------------------------