diff --git a/README.md b/README.md index 3b37c50..dcfea19 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# RichText [ ![Download](https://api.bintray.com/packages/zzhoujay/maven/richtext/images/download.svg) ](https://bintray.com/zzhoujay/maven/richtext/_latestVersion) +# RichText-AndroidX -### 注意:此项目已不再维护 +### 注意:原项目作者已经不维护了,不支持AndroidX,此项目使用原作者代码改造为支持Androidx > Android平台下的富文本解析器 @@ -24,18 +24,10 @@ ![演示](image/image.jpg "演示") -### gradle中引用的方法 +### 引入方法 + +clone 该项目然后跑起来,打出 aar包然后引入自己的项目 -``` -compile 'com.zzhoujay.richtext:richtext:latest-version' -``` - -### 使用新的Html解析器 - -只需加入此依赖即可,无须其他操作,新Html解析器对原生Html解析器的功能做了补充 -``` -compile 'com.zzhoujay:html:latest-version' -``` 新Html解析器增加了对代码块的支持,代码块可以触发点击事件,通过`urlClick`设置, 代码块回调的参数由`code://`开头 diff --git a/app/build.gradle b/app/build.gradle index a2b7b58..f42deb1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,12 +1,11 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 26 - buildToolsVersion "25.0.2" + compileSdk 33 defaultConfig { applicationId "zhou.demo" - minSdkVersion 15 - targetSdkVersion 26 + minSdkVersion 21 + targetSdkVersion 33 versionCode 1 versionName "1.0" } @@ -16,24 +15,22 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } - lintOptions { - abortOnError false - } productFlavors { } - dexOptions { - preDexLibraries = false + namespace 'zhou.demo' + lint { + abortOnError false } } dependencies { - compile fileTree(include: ['*.jar'], dir: 'libs') - testCompile 'junit:junit:4.12' - compile 'com.android.support:appcompat-v7:26.1.0' - compile 'com.android.support:recyclerview-v7:26.1.0' - compile project(':richtext') -// compile project(':okhttpimagedownloader') -// compile 'com.zzhoujay.richtext:richtext:3.0.7' - compile 'com.zzhoujay:html:1.0.1' - // compile 'com.zzhoujay.okhttpimagedownloader:OkHttpImageDownloader:1.0.0' + implementation fileTree(include: ['*.jar'], dir: 'libs') + testImplementation 'junit:junit:4.13.2' + // appcompat 1.7.0 会强制 compile = 34 这里先用 1.6.1 + implementation 'androidx.appcompat:appcompat:1.6.1' + implementation 'androidx.recyclerview:recyclerview:1.3.2' + implementation project(':richtext') +// implementation project(':okhttpimagedownloader') +// implementation 'com.zzhoujay.richtext:richtext:3.0.8' + implementation 'com.zzhoujay:html:1.0.2' } diff --git a/app/src/androidTest/java/zhou/demo/ApplicationTest.java b/app/src/androidTest/java/zhou/demo/ApplicationTest.java index de58360..78fa1dc 100644 --- a/app/src/androidTest/java/zhou/demo/ApplicationTest.java +++ b/app/src/androidTest/java/zhou/demo/ApplicationTest.java @@ -1,13 +1,3 @@ package zhou.demo; import android.app.Application; -import android.test.ApplicationTestCase; - -/** - * Testing Fundamentals - */ -public class ApplicationTest extends ApplicationTestCase { - public ApplicationTest() { - super(Application.class); - } -} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9e1bacb..c3f062c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -10,8 +10,10 @@ android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" + android:networkSecurityConfig="@xml/network_security_config" android:theme="@style/AppTheme"> - + diff --git a/app/src/main/java/zhou/demo/DebugActivity.java b/app/src/main/java/zhou/demo/DebugActivity.java index c4008f3..0d94aa9 100644 --- a/app/src/main/java/zhou/demo/DebugActivity.java +++ b/app/src/main/java/zhou/demo/DebugActivity.java @@ -2,7 +2,7 @@ import android.app.Activity; import android.os.Bundle; -import android.support.annotation.Nullable; +import androidx.annotation.Nullable; import android.util.Log; import android.widget.ImageView; import android.widget.TextView; diff --git a/app/src/main/java/zhou/demo/GifActivity.java b/app/src/main/java/zhou/demo/GifActivity.java index 36c8050..6b423ef 100644 --- a/app/src/main/java/zhou/demo/GifActivity.java +++ b/app/src/main/java/zhou/demo/GifActivity.java @@ -1,8 +1,8 @@ package zhou.demo; import android.os.Bundle; -import android.support.annotation.Nullable; -import android.support.v7.app.AppCompatActivity; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; import android.view.View; import android.widget.TextView; diff --git a/app/src/main/java/zhou/demo/ListViewActivity.java b/app/src/main/java/zhou/demo/ListViewActivity.java index f296a34..cb6c401 100644 --- a/app/src/main/java/zhou/demo/ListViewActivity.java +++ b/app/src/main/java/zhou/demo/ListViewActivity.java @@ -1,8 +1,8 @@ package zhou.demo; import android.os.Bundle; -import android.support.annotation.Nullable; -import android.support.v7.app.AppCompatActivity; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -21,7 +21,7 @@ public class ListViewActivity extends AppCompatActivity { // private static final String[] testString = new String[]{ -// "

Test1

", +// "

Test1

", // "

Test2

", // "

Test3

", // "

Test4

", @@ -35,20 +35,20 @@ public class ListViewActivity extends AppCompatActivity { private static final String gifTest = "

Gif Test

"; private static final String[] testString = { - "

Test1

", - "

Test2

", - "

Test3

", - "

Test4

", - "

Test5

", - "

Test6

", - "

Test7

", - "

Test8

", - "

Test9

" + "

Test1

", + "

Test2

", + "

Test3

", + "

Test4

", + "

Test5

", + "

Test6

", + "

Test7

", + "

Test8

", + "

Test9

" }; private static final String[] testString__ = { - "

Test1

", - "

Test2

", - "

Test9

", + "

Test1

", + "

Test2

", + "

Test9

", "

Test3

", "

Test4

", "

Test5

", diff --git a/app/src/main/java/zhou/demo/MainActivity.java b/app/src/main/java/zhou/demo/MainActivity.java index 57eece3..96c92f0 100644 --- a/app/src/main/java/zhou/demo/MainActivity.java +++ b/app/src/main/java/zhou/demo/MainActivity.java @@ -2,7 +2,7 @@ import android.content.Intent; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatActivity; import android.view.Menu; import android.view.MenuItem; import android.widget.TextView; @@ -78,7 +78,7 @@ public class MainActivity extends AppCompatActivity { "

效果

\n" + "

\"演示\"

\n" + "

gradle中引用的方法

\n" + - "
compile 'com.zzhoujay.richtext:richtext:3.0.5'\n" +
+            "
implementation 'com.zzhoujay.richtext:richtext:3.0.5'\n" +
             "
\n" + "

关于issue

\n" + "

最近一段时间会比较忙,issue不能及时处理,一般会定时抽空集中解决issue,但时间有限解决速度上不敢保证。

\n" + diff --git a/app/src/main/java/zhou/demo/RecyclerViewActivity.java b/app/src/main/java/zhou/demo/RecyclerViewActivity.java index dede0d9..6832c4d 100644 --- a/app/src/main/java/zhou/demo/RecyclerViewActivity.java +++ b/app/src/main/java/zhou/demo/RecyclerViewActivity.java @@ -1,10 +1,10 @@ package zhou.demo; import android.os.Bundle; -import android.support.annotation.Nullable; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -18,7 +18,7 @@ public class RecyclerViewActivity extends AppCompatActivity { private static final String[] testString1 = new String[]{ - "

Test1

", + "

Test1

", "

Test2

", "

Test3

", "

Test4

", diff --git a/app/src/main/java/zhou/demo/TestActivity.java b/app/src/main/java/zhou/demo/TestActivity.java index f71548b..805e930 100644 --- a/app/src/main/java/zhou/demo/TestActivity.java +++ b/app/src/main/java/zhou/demo/TestActivity.java @@ -1,8 +1,8 @@ package zhou.demo; import android.os.Bundle; -import android.support.annotation.Nullable; -import android.support.v7.app.AppCompatActivity; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; import android.widget.TextView; import android.widget.Toast; diff --git a/app/src/main/res/layout/activity_recycler.xml b/app/src/main/res/layout/activity_recycler.xml index f0e9565..8812a52 100644 --- a/app/src/main/res/layout/activity_recycler.xml +++ b/app/src/main/res/layout/activity_recycler.xml @@ -4,7 +4,7 @@ android:layout_height="match_parent" android:orientation="vertical"> - diff --git a/app/src/main/res/raw/hello.md b/app/src/main/res/raw/hello.md index bd293d1..41fd0bf 100644 --- a/app/src/main/res/raw/hello.md +++ b/app/src/main/res/raw/hello.md @@ -20,7 +20,7 @@ ### gradle中引用的方法 ``` -compile 'com.zzhoujay.richtext:richtext:1.1.5' +implementation 'com.zzhoujay.richtext:richtext:1.1.5' ``` --- diff --git a/app/src/main/res/raw/tt.md b/app/src/main/res/raw/tt.md index e3b2d1a..741665c 100644 --- a/app/src/main/res/raw/tt.md +++ b/app/src/main/res/raw/tt.md @@ -39,7 +39,7 @@ RichText.fromMarkdown(markdown).into(textView); ### Use in Gradle -`compile 'com.zzhoujay.markdown:markdown:0.0.4'` +`implementation 'com.zzhoujay.markdown:markdown:0.0.4'` ### 已知问题 diff --git a/app/src/main/res/xml/network_security_config.xml b/app/src/main/res/xml/network_security_config.xml new file mode 100644 index 0000000..2cc2c36 --- /dev/null +++ b/app/src/main/res/xml/network_security_config.xml @@ -0,0 +1,7 @@ + + + + ww4.sinaimg.cn + baidu.com + + diff --git a/build.gradle b/build.gradle index 3a6183c..3011b23 100644 --- a/build.gradle +++ b/build.gradle @@ -2,39 +2,24 @@ buildscript { repositories { - jcenter() - maven { - url 'https://maven.google.com/' - name 'Google' - } + mavenCentral() + google() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.1' - classpath 'com.novoda:bintray-release:0.7.0' - - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files + classpath 'com.android.tools.build:gradle:7.2.2' } } allprojects { repositories { - jcenter() - maven { - url 'https://maven.google.com/' - name 'Google' - } - } - - tasks.withType(Javadoc) { - options { - encoding "UTF-8" - charSet 'UTF-8' - links "http://docs.oracle.com/javase/7/docs/api" - } + maven { url 'https://maven.aliyun.com/repository/public' } + maven { url 'https://maven.aliyun.com/repository/central' } + maven { url 'https://maven.aliyun.com/repository/jcenter' } + mavenCentral() + google() } } -task clean(type: Delete) { +tasks.register('clean', Delete) { delete rootProject.buildDir } diff --git a/glideimagegetter/build.gradle b/glideimagegetter/build.gradle index b105dd7..f8e852c 100644 --- a/glideimagegetter/build.gradle +++ b/glideimagegetter/build.gradle @@ -5,12 +5,11 @@ def version_code = 6 def version_name = "1.0.5" android { - compileSdkVersion 24 - buildToolsVersion "25.0.0" + compileSdkVersion 33 defaultConfig { - minSdkVersion 7 - targetSdkVersion 24 + minSdkVersion 15 + targetSdkVersion 33 versionCode version_code versionName version_name @@ -32,11 +31,11 @@ android { } dependencies { - compile fileTree(include: ['*.jar'], dir: 'libs') - testCompile 'junit:junit:4.12' - compile 'com.github.bumptech.glide:glide:3.7.0' - compile 'com.zzhoujay.richtext:richtext:2.5.+' -// compile project(':richtext') + implementation fileTree(include: ['*.jar'], dir: 'libs') + testImplementation 'junit:junit:4.13.2' + implementation 'com.github.bumptech.glide:glide:3.7.0' + implementation 'com.zzhoujay.richtext:richtext:3.0.8' +// implementation project(':richtext') } publish { diff --git a/glideimagegetter/src/main/java/com/zzhoujay/glideimagegetter/GlideImageGetter.java b/glideimagegetter/src/main/java/com/zzhoujay/glideimagegetter/GlideImageGetter.java index 84b0653..40bb6bd 100644 --- a/glideimagegetter/src/main/java/com/zzhoujay/glideimagegetter/GlideImageGetter.java +++ b/glideimagegetter/src/main/java/com/zzhoujay/glideimagegetter/GlideImageGetter.java @@ -2,7 +2,7 @@ import android.graphics.Rect; import android.graphics.drawable.Drawable; -import android.support.v4.util.LruCache; +import androidx.collection.LruCache; import android.widget.TextView; import com.bumptech.glide.BitmapTypeRequest; diff --git a/glideimagegetter/src/main/java/com/zzhoujay/glideimagegetter/ImageTarget.java b/glideimagegetter/src/main/java/com/zzhoujay/glideimagegetter/ImageTarget.java index 93c1929..bcdcbc6 100644 --- a/glideimagegetter/src/main/java/com/zzhoujay/glideimagegetter/ImageTarget.java +++ b/glideimagegetter/src/main/java/com/zzhoujay/glideimagegetter/ImageTarget.java @@ -5,7 +5,7 @@ import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.os.Build; -import android.support.v7.widget.TintContextWrapper; +import androidx.appcompat.widget.TintContextWrapper; import android.widget.TextView; import com.bumptech.glide.request.target.BaseTarget; diff --git a/glideimagegetter/src/main/java/com/zzhoujay/glideimagegetter/ImageTargetGif.java b/glideimagegetter/src/main/java/com/zzhoujay/glideimagegetter/ImageTargetGif.java index fc27aab..b523974 100644 --- a/glideimagegetter/src/main/java/com/zzhoujay/glideimagegetter/ImageTargetGif.java +++ b/glideimagegetter/src/main/java/com/zzhoujay/glideimagegetter/ImageTargetGif.java @@ -3,7 +3,7 @@ import android.graphics.Bitmap; import android.graphics.Rect; import android.graphics.drawable.Drawable; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import android.widget.TextView; import com.bumptech.glide.Glide; diff --git a/gradle.properties b/gradle.properties index 1d3591c..915f0e6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,4 +15,6 @@ # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects -# org.gradle.parallel=true \ No newline at end of file +# org.gradle.parallel=true +android.enableJetifier=true +android.useAndroidX=true \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index beb3abc..f5dea25 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Wed Nov 15 23:17:18 CST 2017 +#Mon Jul 18 17:25:42 CST 2022 distributionBase=GRADLE_USER_HOME +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip +zipStoreBase=GRADLE_USER_HOME diff --git a/okhttpimagedownloader/build.gradle b/okhttpimagedownloader/build.gradle index b7e4256..57ced7e 100644 --- a/okhttpimagedownloader/build.gradle +++ b/okhttpimagedownloader/build.gradle @@ -1,20 +1,13 @@ apply plugin: 'com.android.library' -apply plugin: 'com.novoda.bintray-release' - -def version_code = 3 -def version_name = "1.0.2" android { - compileSdkVersion 26 - buildToolsVersion "25.0.2" + compileSdkVersion 33 defaultConfig { - minSdkVersion 14 - targetSdkVersion 26 - versionCode version_code - versionName version_name + minSdkVersion 15 + targetSdkVersion 33 - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' } buildTypes { @@ -23,29 +16,14 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } - lintOptions { + namespace 'com.zzhoujay.okhttpimagedownloader' + lint { abortOnError false } } dependencies { - compile 'com.squareup.okhttp3:okhttp:3.7.0' -// compile project(':richtext') - compile 'com.zzhoujay.richtext:richtext:3.0.1' -} - -publish { - - Properties properties = new Properties() - properties.load(project.rootProject.file('local.properties').newDataInputStream()) - userOrg = properties.getProperty("bintray.user") - groupId = "com.zzhoujay.okhttpimagedownloader" - artifactId = 'OkHttpImageDownloader' - publishVersion = version_name - desc = '使用okhttp实现的图片下载器' - website = 'https://github.com/zzhoujay/RichTex' - - bintrayUser=properties.getProperty("bintray.user") - bintrayKey=properties.getProperty("bintray.key") - + implementation 'com.squareup.okhttp3:okhttp:3.10.0' +// implementation project(':richtext') + implementation 'com.zzhoujay.richtext:richtext:3.0.8' } diff --git a/richtext/build.gradle b/richtext/build.gradle index f605853..2d1ab0c 100644 --- a/richtext/build.gradle +++ b/richtext/build.gradle @@ -1,20 +1,11 @@ apply plugin: 'com.android.library' -apply plugin: 'com.novoda.bintray-release' -def version_code = 65 -def version_name = "3.0.8" android { - compileSdkVersion 26 - buildToolsVersion "25.0.2" - - resourcePrefix "zhou_" - + compileSdk 34 defaultConfig { - minSdkVersion 14 - targetSdkVersion 26 - versionCode version_code - versionName version_name + minSdkVersion 21 + targetSdkVersion 33 } buildTypes { release { @@ -22,32 +13,15 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } - lintOptions { + namespace 'com.zzhoujay.richtext' + lint { abortOnError false } - dexOptions { - preDexLibraries = false - } } dependencies { - compile 'com.zzhoujay.markdown:markdown:1.0.5' - compile 'com.jakewharton:disklrucache:2.0.2' - compile 'com.android.support:support-v4:26.1.0' -} - -publish { - - Properties properties = new Properties() - properties.load(project.rootProject.file('local.properties').newDataInputStream()) - userOrg = properties.getProperty("bintray.user") - bintrayUser=properties.getProperty("bintray.user") - bintrayKey=properties.getProperty("bintray.key") - - groupId = "com.zzhoujay.richtext" - artifactId = 'richtext' - publishVersion = version_name - desc = 'Android端的富文本解析器' - website = 'https://github.com/zzhoujay/RichTex' - + implementation 'com.zzhoujay.markdown:markdown:1.0.5' + implementation 'com.jakewharton:disklrucache:2.0.2' + implementation 'androidx.annotation:annotation:1.8.2' +// implementation 'androidx.legacy:legacy-support-v4:1.0.0' } \ No newline at end of file diff --git a/richtext/src/main/java/com/zzhoujay/richtext/ImageHolder.java b/richtext/src/main/java/com/zzhoujay/richtext/ImageHolder.java index 0cb9e74..029c909 100644 --- a/richtext/src/main/java/com/zzhoujay/richtext/ImageHolder.java +++ b/richtext/src/main/java/com/zzhoujay/richtext/ImageHolder.java @@ -1,10 +1,12 @@ package com.zzhoujay.richtext; import android.graphics.drawable.Drawable; -import android.support.annotation.ColorInt; -import android.support.annotation.IntDef; import android.widget.TextView; +import androidx.annotation.ColorInt; +import androidx.annotation.IntDef; +import androidx.annotation.NonNull; + import com.zzhoujay.richtext.drawable.DrawableBorderHolder; import com.zzhoujay.richtext.exceptions.ResetImageSourceException; import com.zzhoujay.richtext.ext.MD5; @@ -33,7 +35,7 @@ public enum ScaleType { none(0), center(1), center_crop(2), center_inside(3), fit_center(4), fit_start(5), fit_end(6), fit_xy(7), fit_auto(8); - int value; + final int value; ScaleType(int value) { this.value = value; @@ -113,10 +115,10 @@ public boolean isInvalidateSize() { private boolean autoPlay; private boolean show; private boolean isGif; - private DrawableBorderHolder borderHolder; + private final DrawableBorderHolder borderHolder; private Drawable placeHolder, errorImage; - private String prefixCode; - private int configHashcode; + private final String prefixCode; + private final int configHashcode; public ImageHolder(String source, int position, RichTextConfig config, TextView textView) { this.source = source; @@ -348,6 +350,7 @@ public int hashCode() { return result; } + @NonNull @Override public String toString() { return "ImageHolder{" + diff --git a/richtext/src/main/java/com/zzhoujay/richtext/LinkHolder.java b/richtext/src/main/java/com/zzhoujay/richtext/LinkHolder.java index 067b612..dca287a 100644 --- a/richtext/src/main/java/com/zzhoujay/richtext/LinkHolder.java +++ b/richtext/src/main/java/com/zzhoujay/richtext/LinkHolder.java @@ -1,7 +1,7 @@ package com.zzhoujay.richtext; import android.graphics.Color; -import android.support.annotation.ColorInt; +import androidx.annotation.ColorInt; /** * Created by zhou on 2016/11/17. diff --git a/richtext/src/main/java/com/zzhoujay/richtext/RichText.java b/richtext/src/main/java/com/zzhoujay/richtext/RichText.java index 04a6b46..ff3dc9b 100644 --- a/richtext/src/main/java/com/zzhoujay/richtext/RichText.java +++ b/richtext/src/main/java/com/zzhoujay/richtext/RichText.java @@ -3,7 +3,7 @@ import android.content.Context; import android.graphics.drawable.Drawable; import android.os.AsyncTask; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import android.text.SpannableString; import android.text.SpannableStringBuilder; import android.text.Spanned; diff --git a/richtext/src/main/java/com/zzhoujay/richtext/RichTextConfig.java b/richtext/src/main/java/com/zzhoujay/richtext/RichTextConfig.java index 109ce4c..f5d48e7 100644 --- a/richtext/src/main/java/com/zzhoujay/richtext/RichTextConfig.java +++ b/richtext/src/main/java/com/zzhoujay/richtext/RichTextConfig.java @@ -6,8 +6,9 @@ import android.os.Handler; import android.os.Looper; import android.os.Message; -import android.support.annotation.ColorInt; -import android.support.v4.util.Pair; +import androidx.annotation.ColorInt; + +import android.util.Pair; import android.widget.TextView; import com.zzhoujay.richtext.callback.Callback; @@ -519,28 +520,20 @@ public void dispatchMessage(Message msg) { } }; - private static final DrawableGetter PLACE_HOLDER_DRAWABLE_GETTER = new DrawableGetter() { - - @Override - public Drawable getDrawable(ImageHolder holder, RichTextConfig config, TextView textView) { - ColorDrawable drawable = new ColorDrawable(Color.LTGRAY); - int width = textView.getWidth() ; - drawable.setBounds(0, 0, width, width / 2); - HANDLER.obtainMessage(SET_BOUNDS, Pair.create(drawable, textView)).sendToTarget(); - return drawable; - } + private static final DrawableGetter PLACE_HOLDER_DRAWABLE_GETTER = (holder, config, textView) -> { + ColorDrawable drawable = new ColorDrawable(Color.LTGRAY); + int width = textView.getWidth() ; + drawable.setBounds(0, 0, width, width / 2); + HANDLER.obtainMessage(SET_BOUNDS, Pair.create(drawable, textView)).sendToTarget(); + return drawable; }; - private static final DrawableGetter ERROR_IMAGE_DRAWABLE_GETTER = new DrawableGetter() { - - @Override - public Drawable getDrawable(ImageHolder holder, RichTextConfig config, TextView textView) { - ColorDrawable drawable = new ColorDrawable(Color.DKGRAY); - int width = textView.getWidth(); - drawable.setBounds(0, 0, width, width / 2); - HANDLER.obtainMessage(SET_BOUNDS, Pair.create(drawable, textView)).sendToTarget(); - return drawable; - } + private static final DrawableGetter ERROR_IMAGE_DRAWABLE_GETTER = (holder, config, textView) -> { + ColorDrawable drawable = new ColorDrawable(Color.DKGRAY); + int width = textView.getWidth(); + drawable.setBounds(0, 0, width, width / 2); + HANDLER.obtainMessage(SET_BOUNDS, Pair.create(drawable, textView)).sendToTarget(); + return drawable; }; /** diff --git a/richtext/src/main/java/com/zzhoujay/richtext/RichTextPool.java b/richtext/src/main/java/com/zzhoujay/richtext/RichTextPool.java index 3d41e19..36ecfee 100644 --- a/richtext/src/main/java/com/zzhoujay/richtext/RichTextPool.java +++ b/richtext/src/main/java/com/zzhoujay/richtext/RichTextPool.java @@ -1,8 +1,8 @@ package com.zzhoujay.richtext; -import android.support.v4.util.LruCache; import android.text.SpannableStringBuilder; import android.text.Spanned; +import android.util.LruCache; import com.zzhoujay.richtext.ext.Debug; import com.zzhoujay.richtext.ext.MD5; @@ -72,7 +72,7 @@ SpannableStringBuilder clearSpans(SpannableStringBuilder ssb) { } LongClickableURLSpan[] lcus = ssb.getSpans(0, ssb.length(), LongClickableURLSpan.class); - if (lcus != null && lcus.length > 0) { + if (lcus != null) { for (LongClickableURLSpan span : lcus) { int start = ssb.getSpanStart(span); int end = ssb.getSpanEnd(span); diff --git a/richtext/src/main/java/com/zzhoujay/richtext/cache/BitmapPool.java b/richtext/src/main/java/com/zzhoujay/richtext/cache/BitmapPool.java index a46039b..bbef881 100644 --- a/richtext/src/main/java/com/zzhoujay/richtext/cache/BitmapPool.java +++ b/richtext/src/main/java/com/zzhoujay/richtext/cache/BitmapPool.java @@ -1,7 +1,7 @@ package com.zzhoujay.richtext.cache; import android.graphics.Bitmap; -import android.support.v4.util.LruCache; +import android.util.LruCache; import com.jakewharton.disklrucache.DiskLruCache; import com.zzhoujay.richtext.drawable.DrawableSizeHolder; @@ -27,8 +27,8 @@ public class BitmapPool { private static final String SIZE_DIR_NAME = "_s"; private static final String TEMP_DIR_NAME = "_t"; - private LruCache bitmapCache; - private LruCache sizeHolderCache; + private final LruCache bitmapCache; + private final LruCache sizeHolderCache; private static File cacheDir; private static final int version = 1; diff --git a/richtext/src/main/java/com/zzhoujay/richtext/drawable/DrawableBorderHolder.java b/richtext/src/main/java/com/zzhoujay/richtext/drawable/DrawableBorderHolder.java index 1317396..5d6ec62 100644 --- a/richtext/src/main/java/com/zzhoujay/richtext/drawable/DrawableBorderHolder.java +++ b/richtext/src/main/java/com/zzhoujay/richtext/drawable/DrawableBorderHolder.java @@ -1,7 +1,7 @@ package com.zzhoujay.richtext.drawable; import android.graphics.Color; -import android.support.annotation.ColorInt; +import androidx.annotation.ColorInt; /** * Created by zhou on 2017/10/4. diff --git a/richtext/src/main/java/com/zzhoujay/richtext/drawable/DrawableWrapper.java b/richtext/src/main/java/com/zzhoujay/richtext/drawable/DrawableWrapper.java index 3b032ec..a097f99 100644 --- a/richtext/src/main/java/com/zzhoujay/richtext/drawable/DrawableWrapper.java +++ b/richtext/src/main/java/com/zzhoujay/richtext/drawable/DrawableWrapper.java @@ -9,7 +9,7 @@ import android.graphics.RectF; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import com.zzhoujay.richtext.ImageHolder; diff --git a/richtext/src/main/java/com/zzhoujay/richtext/drawable/GifDrawable.java b/richtext/src/main/java/com/zzhoujay/richtext/drawable/GifDrawable.java index a533a8c..5f2f699 100644 --- a/richtext/src/main/java/com/zzhoujay/richtext/drawable/GifDrawable.java +++ b/richtext/src/main/java/com/zzhoujay/richtext/drawable/GifDrawable.java @@ -10,7 +10,7 @@ import android.os.Handler; import android.os.Looper; import android.os.Message; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import android.widget.TextView; /**