Skip to content

Commit 0551bb5

Browse files
committed
做了一些优化
1 parent e591919 commit 0551bb5

File tree

13 files changed

+126
-53
lines changed

13 files changed

+126
-53
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
### gradle中引用的方法
2222

2323
```
24-
compile 'com.zzhoujay.richtext:richtext:2.1.1'
24+
compile 'com.zzhoujay.richtext:richtext:2.1.2'
2525
```
2626

2727

app/build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
apply plugin: 'com.android.application'
22

33
android {
4-
compileSdkVersion 23
5-
buildToolsVersion "23.0.1"
4+
compileSdkVersion 24
5+
buildToolsVersion "25"
66

77
defaultConfig {
88
applicationId "zhou.demo"
99
minSdkVersion 15
10-
targetSdkVersion 23
10+
targetSdkVersion 24
1111
versionCode 1
1212
versionName "1.0"
1313
}
@@ -25,8 +25,8 @@ android {
2525
dependencies {
2626
compile fileTree(include: ['*.jar'], dir: 'libs')
2727
testCompile 'junit:junit:4.12'
28-
compile 'com.android.support:appcompat-v7:23.1.0'
28+
compile 'com.android.support:appcompat-v7:24.0.0'
2929
compile project(':richtext')
3030
// compile 'com.zzhoujay.richtext:richtext:2.0.0'
31-
compile 'com.android.support:recyclerview-v7:23.4.0'
31+
compile 'com.android.support:recyclerview-v7:24.0.0'
3232
}

app/src/main/java/zhou/demo/RecyclerViewActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class Holder extends RecyclerView.ViewHolder {
131131
public Holder(View itemView) {
132132
super(itemView);
133133
text = (TextView) itemView.findViewById(R.id.text_item);
134-
id = (TextView) itemView.findViewById(R.id.text_id);
134+
// id = (TextView) itemView.findViewById(R.id.text_id);
135135
}
136136
}
137137
});

build.gradle

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ buildscript {
55
jcenter()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:2.1.3'
9-
// classpath 'com.github.dcendents:android-maven-plugin:1.2'
10-
// classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
11-
// classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
8+
classpath 'com.android.tools.build:gradle:2.2.2'
129
classpath 'com.novoda:bintray-release:0.3.4'
1310

1411
// NOTE: Do not place your application dependencies here; they belong

gradle/wrapper/gradle-wrapper.jar

3.35 KB
Binary file not shown.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Sat Aug 20 20:31:51 CST 2016
1+
#Mon Nov 07 12:35:21 CST 2016
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-bin.zip

gradlew

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,30 @@
66
##
77
##############################################################################
88

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=""
9+
# Attempt to set APP_HOME
10+
# Resolve links: $0 may be a link
11+
PRG="$0"
12+
# Need this for relative symlinks.
13+
while [ -h "$PRG" ] ; do
14+
ls=`ls -ld "$PRG"`
15+
link=`expr "$ls" : '.*-> \(.*\)$'`
16+
if expr "$link" : '/.*' > /dev/null; then
17+
PRG="$link"
18+
else
19+
PRG=`dirname "$PRG"`"/$link"
20+
fi
21+
done
22+
SAVED="`pwd`"
23+
cd "`dirname \"$PRG\"`/" >/dev/null
24+
APP_HOME="`pwd -P`"
25+
cd "$SAVED" >/dev/null
1126

1227
APP_NAME="Gradle"
1328
APP_BASE_NAME=`basename "$0"`
1429

30+
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31+
DEFAULT_JVM_OPTS=""
32+
1533
# Use the maximum available, or set MAX_FD != -1 to use that value.
1634
MAX_FD="maximum"
1735

@@ -30,6 +48,7 @@ die ( ) {
3048
cygwin=false
3149
msys=false
3250
darwin=false
51+
nonstop=false
3352
case "`uname`" in
3453
CYGWIN* )
3554
cygwin=true
@@ -40,31 +59,11 @@ case "`uname`" in
4059
MINGW* )
4160
msys=true
4261
;;
62+
NONSTOP* )
63+
nonstop=true
64+
;;
4365
esac
4466

45-
# For Cygwin, ensure paths are in UNIX format before anything is touched.
46-
if $cygwin ; then
47-
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48-
fi
49-
50-
# Attempt to set APP_HOME
51-
# Resolve links: $0 may be a link
52-
PRG="$0"
53-
# Need this for relative symlinks.
54-
while [ -h "$PRG" ] ; do
55-
ls=`ls -ld "$PRG"`
56-
link=`expr "$ls" : '.*-> \(.*\)$'`
57-
if expr "$link" : '/.*' > /dev/null; then
58-
PRG="$link"
59-
else
60-
PRG=`dirname "$PRG"`"/$link"
61-
fi
62-
done
63-
SAVED="`pwd`"
64-
cd "`dirname \"$PRG\"`/" >&-
65-
APP_HOME="`pwd -P`"
66-
cd "$SAVED" >&-
67-
6867
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
6968

7069
# Determine the Java command to use to start the JVM.
@@ -90,7 +89,7 @@ location of your Java installation."
9089
fi
9190

9291
# Increase the maximum file descriptors if we can.
93-
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
92+
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
9493
MAX_FD_LIMIT=`ulimit -H -n`
9594
if [ $? -eq 0 ] ; then
9695
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
@@ -114,6 +113,7 @@ fi
114113
if $cygwin ; then
115114
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116115
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116+
JAVACMD=`cygpath --unix "$JAVACMD"`
117117

118118
# We build the pattern for arguments to be converted via cygpath
119119
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`

gradlew.bat

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
@rem Set local scope for the variables with windows NT shell
99
if "%OS%"=="Windows_NT" setlocal
1010

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-
1411
set DIRNAME=%~dp0
1512
if "%DIRNAME%" == "" set DIRNAME=.
1613
set APP_BASE_NAME=%~n0
1714
set APP_HOME=%DIRNAME%
1815

16+
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17+
set DEFAULT_JVM_OPTS=
18+
1919
@rem Find java.exe
2020
if defined JAVA_HOME goto findJavaFromJavaHome
2121

@@ -46,7 +46,7 @@ echo location of your Java installation.
4646
goto fail
4747

4848
:init
49-
@rem Get command-line arguments, handling Windowz variants
49+
@rem Get command-line arguments, handling Windows variants
5050

5151
if not "%OS%" == "Windows_NT" goto win9xME_args
5252
if "%@eval[2+2]" == "4" goto 4NT_args

richtext/build.gradle

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
apply plugin: 'com.android.library'
22
apply plugin: 'com.novoda.bintray-release'
33

4-
def version_code = 27
5-
def version_name = "2.1.1"
4+
def version_code = 28
5+
def version_name = "2.1.2"
66

77
android {
8-
compileSdkVersion 23
9-
buildToolsVersion "23.0.2"
8+
compileSdkVersion 24
9+
buildToolsVersion "25"
1010

1111
resourcePrefix "zhou_"
1212

1313
defaultConfig {
1414
minSdkVersion 7
15-
targetSdkVersion 23
15+
targetSdkVersion 24
1616
versionCode version_code
1717
versionName version_name
1818
}
@@ -30,7 +30,7 @@ android {
3030
dependencies {
3131
compile fileTree(include: ['*.jar'], dir: 'libs')
3232
testCompile 'junit:junit:4.12'
33-
compile 'com.android.support:appcompat-v7:23.4.0'
33+
compile 'com.android.support:appcompat-v7:24.0.0'
3434
compile 'com.github.bumptech.glide:glide:3.7.0'
3535
compile 'com.zzhoujay.markdown:markdown:1.0.0'
3636
}

richtext/src/main/java/com/zzhoujay/richtext/RichText.java

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package com.zzhoujay.richtext;
22

3+
import android.app.Activity;
4+
import android.content.Context;
35
import android.graphics.Color;
46
import android.graphics.drawable.ColorDrawable;
57
import android.graphics.drawable.Drawable;
8+
import android.os.Build;
69
import android.support.annotation.DrawableRes;
710
import android.support.annotation.Nullable;
11+
import android.support.v7.widget.TintContextWrapper;
812
import android.text.Html;
913
import android.text.SpannableStringBuilder;
1014
import android.text.Spanned;
@@ -253,12 +257,21 @@ public boolean onLongClick(View widget) {
253257
return spanned;
254258
}
255259

260+
// 图片异步加载器
256261
private final Html.ImageGetter asyncImageGetter = new Html.ImageGetter() {
257262
@Override
258263
public Drawable getDrawable(String source) {
259264
if (noImage) {
260265
return new ColorDrawable(Color.TRANSPARENT);
261266
}
267+
TextView textView = textViewWeakReference.get();
268+
if (textView == null) {
269+
return null;
270+
}
271+
// 判断activity是否已结束
272+
if (!activityIsAlive(textView.getContext())) {
273+
return null;
274+
}
262275
final URLDrawable urlDrawable = new URLDrawable();
263276
ImageHolder imageHolder;
264277
if (type == RichType.MARKDOWN) {
@@ -281,10 +294,6 @@ public Drawable getDrawable(String source) {
281294
}
282295
DrawableTypeRequest dtr;
283296
byte[] src = Base64.decode(source);
284-
TextView textView = textViewWeakReference.get();
285-
if (textView == null) {
286-
return null;
287-
}
288297
if (src != null) {
289298
dtr = Glide.with(textView.getContext()).load(src);
290299
} else {
@@ -373,6 +382,30 @@ private void matchImages(String text) {
373382
}
374383
}
375384

385+
/**
386+
* 判断Activity是否已经结束
387+
* @param context context
388+
* @return true:已结束
389+
*/
390+
private static boolean activityIsAlive(Context context) {
391+
if (context == null) {
392+
return false;
393+
}
394+
if (context instanceof TintContextWrapper) {
395+
context = ((TintContextWrapper) context).getBaseContext();
396+
}
397+
if (context instanceof Activity) {
398+
if (((Activity) context).isFinishing()) {
399+
return false;
400+
} else {
401+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && ((Activity) context).isDestroyed()) {
402+
return false;
403+
}
404+
}
405+
}
406+
return true;
407+
}
408+
376409
private static int parseStringToInteger(String integerStr) {
377410
int result = -1;
378411
if (!TextUtils.isEmpty(integerStr)) {

0 commit comments

Comments
 (0)