├── .gitignore
├── LICENSE
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── zhou
│ │ └── demo
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── assets
│ │ └── doge.jpg
│ ├── java
│ │ └── zhou
│ │ │ └── demo
│ │ │ ├── DebugActivity.java
│ │ │ ├── GifActivity.java
│ │ │ ├── ListViewActivity.java
│ │ │ ├── MainActivity.java
│ │ │ ├── RecyclerViewActivity.java
│ │ │ └── TestActivity.java
│ └── res
│ │ ├── drawable
│ │ ├── sl.jpg
│ │ └── test.xml
│ │ ├── layout
│ │ ├── activity_debug.xml
│ │ ├── activity_list.xml
│ │ ├── activity_main.xml
│ │ ├── activity_recycler.xml
│ │ ├── activity_test.xml
│ │ └── item_list.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
│ │ ├── raw
│ │ ├── hello.md
│ │ ├── large
│ │ ├── sl.jpg
│ │ └── tt.md
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ ├── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ │ └── xml
│ │ └── network_security_config.xml
│ └── test
│ └── java
│ └── zhou
│ └── demo
│ └── ExampleUnitTest.java
├── build.gradle
├── glideimagegetter
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── zzhoujay
│ │ │ └── glideimagegetter
│ │ │ ├── GlideImageGetter.java
│ │ │ ├── ImageTarget.java
│ │ │ ├── ImageTargetBitmap.java
│ │ │ └── ImageTargetGif.java
│ └── res
│ │ └── values
│ │ └── zhou_glide_ids.xml
│ └── test
│ └── java
│ └── com
│ └── zzhoujay
│ └── glideimagegetter
│ └── ExampleUnitTest.java
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── image
└── image.jpg
├── okhttpimagedownloader
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ └── java
│ └── com
│ └── zzhoujay
│ └── okhttpimagedownloader
│ └── OkHttpImageDownloader.java
├── richtext
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── zzhoujay
│ │ └── richtext
│ │ ├── CacheType.java
│ │ ├── ImageHolder.java
│ │ ├── LinkHolder.java
│ │ ├── RichState.java
│ │ ├── RichText.java
│ │ ├── RichTextConfig.java
│ │ ├── RichTextPool.java
│ │ ├── RichType.java
│ │ ├── cache
│ │ ├── BitmapPool.java
│ │ └── CacheIOHelper.java
│ │ ├── callback
│ │ ├── BitmapStream.java
│ │ ├── Callback.java
│ │ ├── Closeable.java
│ │ ├── DrawableGetter.java
│ │ ├── ImageFixCallback.java
│ │ ├── ImageGetter.java
│ │ ├── ImageLoadNotify.java
│ │ ├── LinkFixCallback.java
│ │ ├── OnImageClickListener.java
│ │ ├── OnImageLongClickListener.java
│ │ ├── OnUrlClickListener.java
│ │ ├── OnUrlLongClickListener.java
│ │ ├── Recyclable.java
│ │ └── SimpleImageFixCallback.java
│ │ ├── drawable
│ │ ├── DrawableBorderHolder.java
│ │ ├── DrawableSizeHolder.java
│ │ ├── DrawableWrapper.java
│ │ └── GifDrawable.java
│ │ ├── exceptions
│ │ ├── BitmapCacheException.java
│ │ ├── BitmapCacheLoadFailureException.java
│ │ ├── BitmapCacheNotFoundException.java
│ │ ├── BitmapInputStreamNullPointException.java
│ │ ├── HttpResponseCodeException.java
│ │ ├── ImageDecodeException.java
│ │ ├── ImageDownloadTaskAddFailureException.java
│ │ ├── ImageDownloaderNonExistenceException.java
│ │ ├── ImageLoadCancelledException.java
│ │ ├── ImageWrapperMultiSourceException.java
│ │ └── ResetImageSourceException.java
│ │ ├── ext
│ │ ├── Base64.java
│ │ ├── ContextKit.java
│ │ ├── Debug.java
│ │ ├── HtmlTagHandler.java
│ │ ├── ImageKit.java
│ │ ├── LongClickableLinkMovementMethod.java
│ │ ├── MD5.java
│ │ └── TextKit.java
│ │ ├── ig
│ │ ├── AbstractImageLoader.java
│ │ ├── AssetsImageLoader.java
│ │ ├── Base64ImageLoader.java
│ │ ├── CallbackImageLoader.java
│ │ ├── Cancelable.java
│ │ ├── DefaultImageDownloader.java
│ │ ├── DefaultImageGetter.java
│ │ ├── FutureCancelableWrapper.java
│ │ ├── ImageDownloader.java
│ │ ├── ImageDownloaderManager.java
│ │ ├── ImageLoader.java
│ │ ├── ImageWrapper.java
│ │ ├── InputStreamImageLoader.java
│ │ ├── LocalFileImageLoader.java
│ │ └── SourceDecode.java
│ │ ├── parser
│ │ ├── CachedSpannedParser.java
│ │ ├── Html2SpannedParser.java
│ │ ├── ImageGetterWrapper.java
│ │ ├── Markdown2SpannedParser.java
│ │ └── SpannedParser.java
│ │ └── spans
│ │ ├── Clickable.java
│ │ ├── ClickableImageSpan.java
│ │ ├── LongClickable.java
│ │ ├── LongClickableSpan.java
│ │ └── LongClickableURLSpan.java
│ └── res
│ └── values
│ └── zhou_ids.xml
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by .ignore support plugin (hsz.mobi)
2 | ### JetBrains template
3 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio
4 |
5 | *.iml
6 |
7 | ## Directory-based project format:
8 | .idea/
9 | # if you remove the above rule, at least ignore the following:
10 |
11 | # User-specific stuff:
12 | # .idea/workspace.xml
13 | # .idea/tasks.xml
14 | # .idea/dictionaries
15 |
16 | # Sensitive or high-churn files:
17 | # .idea/dataSources.ids
18 | # .idea/dataSources.xml
19 | # .idea/sqlDataSources.xml
20 | # .idea/dynamic.xml
21 | # .idea/uiDesigner.xml
22 |
23 | # Gradle:
24 | # .idea/gradle.xml
25 | # .idea/libraries
26 |
27 | # Mongo Explorer plugin:
28 | # .idea/mongoSettings.xml
29 |
30 | ## File-based project format:
31 | *.ipr
32 | *.iws
33 |
34 | ## Plugin-specific files:
35 |
36 | # IntelliJ
37 | /out/
38 |
39 | # mpeltonen/sbt-idea plugin
40 | .idea_modules/
41 |
42 | # JIRA plugin
43 | atlassian-ide-plugin.xml
44 |
45 | # Crashlytics plugin (for Android Studio and IntelliJ)
46 | com_crashlytics_export_strings.xml
47 | crashlytics.properties
48 | crashlytics-build.properties
49 | ### NetBeans template
50 | nbproject/private/
51 | build/
52 | nbbuild/
53 | dist/
54 | nbdist/
55 | nbactions.xml
56 | nb-configuration.xml
57 | .nb-gradle/
58 | ### Java template
59 | *.class
60 |
61 | # Mobile Tools for Java (J2ME)
62 | .mtj.tmp/
63 |
64 | # Package Files #
65 | *.jar
66 | *.war
67 | *.ear
68 |
69 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
70 | hs_err_pid*
71 | ### Linux template
72 | *~
73 |
74 | # KDE directory preferences
75 | .directory
76 |
77 | # Linux trash folder which might appear on any partition or disk
78 | .Trash-*
79 | ### OSX template
80 | .DS_Store
81 | .AppleDouble
82 | .LSOverride
83 |
84 | # Icon must end with two \r
85 | Icon
86 |
87 | # Thumbnails
88 | ._*
89 |
90 | # Files that might appear in the root of a volume
91 | .DocumentRevisions-V100
92 | .fseventsd
93 | .Spotlight-V100
94 | .TemporaryItems
95 | .Trashes
96 | .VolumeIcon.icns
97 |
98 | # Directories potentially created on remote AFP share
99 | .AppleDB
100 | .AppleDesktop
101 | Network Trash Folder
102 | Temporary Items
103 | .apdisk
104 | ### Windows template
105 | # Windows image file caches
106 | Thumbs.db
107 | ehthumbs.db
108 |
109 | # Folder config file
110 | Desktop.ini
111 |
112 | # Recycle Bin used on file shares
113 | $RECYCLE.BIN/
114 |
115 | # Windows Installer files
116 | *.cab
117 | *.msi
118 | *.msm
119 | *.msp
120 |
121 | # Windows shortcuts
122 | *.lnk
123 | ### Maven template
124 | target/
125 | pom.xml.tag
126 | pom.xml.releaseBackup
127 | pom.xml.versionsBackup
128 | pom.xml.next
129 | release.properties
130 | dependency-reduced-pom.xml
131 | buildNumber.properties
132 | .mvn/timing.properties
133 | ### Android template
134 | # Built application files
135 | *.apk
136 | *.ap_
137 |
138 | # Files for the Dalvik VM
139 | *.dex
140 |
141 | # Java class files
142 |
143 | # Generated files
144 | bin/
145 | gen/
146 |
147 | # Gradle files
148 | .gradle/
149 |
150 | # Local configuration file (sdk path, etc)
151 | local.properties
152 |
153 | # Proguard folder generated by Eclipse
154 | proguard/
155 |
156 | # Log Files
157 | *.log
158 |
159 | # Android Studio Navigation editor temp files
160 | .navigation/
161 | ### Eclipse template
162 | *.pydevproject
163 | .metadata
164 | .gradle
165 | tmp/
166 | *.tmp
167 | *.bak
168 | *.swp
169 | *~.nib
170 | .settings/
171 | .loadpath
172 |
173 | # Eclipse Core
174 | .project
175 |
176 | # External tool builders
177 | .externalToolBuilders/
178 |
179 | # Locally stored "Eclipse launch configurations"
180 | *.launch
181 |
182 | # CDT-specific
183 | .cproject
184 |
185 | # JDT-specific (Eclipse Java Development Tools)
186 | .classpath
187 |
188 | # Java annotation processor (APT)
189 | .factorypath
190 |
191 | # PDT-specific
192 | .buildpath
193 |
194 | # sbteclipse plugin
195 | .target
196 |
197 | # TeXlipse plugin
198 | .texlipse
199 | ### JDeveloper template
200 | # default application storage directory used by the IDE Performance Cache feature
201 | .data/
202 |
203 | # used for ADF styles caching
204 | temp/
205 |
206 | # default output directories
207 | classes/
208 | deploy/
209 | javadoc/
210 |
211 | # lock file, a part of Oracle Credential Store Framework
212 | cwallet.sso.lck### Gradle template
213 |
214 | # Ignore Gradle GUI config
215 | gradle-app.setting
216 |
217 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
218 | !gradle-wrapper.jar
219 |
220 | publish.sh
221 | captures/
222 | glideimagegetter/libs/
223 | projectFilesBackup/
224 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 zzhoujay
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 |
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # RichText-AndroidX
2 |
3 | ### 注意:原项目作者已经不维护了,不支持AndroidX,此项目使用原作者代码改造为支持Androidx
4 |
5 | > Android平台下的富文本解析器
6 |
7 | * 流式操作
8 | * 低侵入性
9 | * 依赖少,只依赖了`disklrucache`和`support v4`
10 | * 支持Html和Markdown格式文本
11 | * 支持图片点击和长按事件
12 | * 链接点击事件和长按事件
13 | * 支持设置加载中和加载错误时的图片
14 | * 支持自定义超链接的点击回调
15 | * 支持修正图片宽高
16 | * 支持GIF图片
17 | * 支持Base64编码、本地图片和Assets目录图片
18 | * 自持自定义图片加载器、图片加载器
19 | * 支持内存和磁盘双缓存
20 | * 已经加入对自定义Html解析器的支持
21 |
22 | ### 效果
23 |
24 | 
25 |
26 |
27 | ### 引入方法
28 |
29 | clone 该项目然后跑起来,打出 aar包然后引入自己的项目
30 |
31 |
32 | 新Html解析器增加了对代码块的支持,代码块可以触发点击事件,通过`urlClick`设置,
33 | 代码块回调的参数由`code://`开头
34 |
35 | 使用新Html解析器遇到问题请在[https://github.com/zzhoujay/Htm](https://github.com/zzhoujay/Html)提issue
36 |
37 | ### 关于issue
38 |
39 | 最近一段时间会比较忙,issue不能及时处理,一般会定时抽空集中解决issue,但时间有限解决速度上不敢保证。
40 |
41 | 欢迎提交pull request帮助完善这个项目
42 |
43 | ### 注意
44 |
45 | 在第一次调用RichText之前先调用`RichText.initCacheDir()`方法设置缓存目录
46 |
47 | ImageFixCallback的回调方法不一定是在主线程回调,注意不要进行UI操作
48 |
49 | 本地图片由根路径`\`开头,Assets目录图片由`file:///android_asset/`开头
50 |
51 | Gif图片播放不支持硬件加速,若要使用Gif图片请先关闭TextView的硬件加速
52 | ```
53 | textView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
54 | ```
55 |
56 | ### 使用方式
57 |
58 | [多看wiki](https://github.com/zzhoujay/RichText/wiki)、[多看wiki](https://github.com/zzhoujay/RichText/wiki)、[多看wiki](https://github.com/zzhoujay/RichText/wiki),重要的事情说三遍
59 |
60 | ### 关于自定义的Html解析器
61 |
62 | Html解析器子项目:[Html](https://github.com/zzhoujay/Htm)
63 |
64 | ### 关于Markdown
65 |
66 | Markdown源于子项目:[Markdown](https://github.com/zzhoujay/Markdown)
67 |
68 | 若在markdown解析过程中发现什么问题可以在该项目中反馈
69 |
70 | ### 关于富文本编辑器
71 |
72 | 编辑器开发已暂停,[RichEditor](https://github.com/zzhoujay/RichEditor)
73 |
74 | ### 具体使用请查看demo
75 |
76 | [ListView Demo](https://github.com/zzhoujay/RichText/blob/master/app/src/main/java/zhou/demo/ListViewActivity.java)、
77 | [RecyclerView Demo](https://github.com/zzhoujay/RichText/blob/master/app/src/main/java/zhou/demo/RecyclerViewActivity.java)、
78 | [Gif Demo](https://github.com/zzhoujay/RichText/blob/master/app/src/main/java/zhou/demo/GifActivity.java)
79 |
80 |
81 | ### License
82 |
83 | ```
84 | The MIT License (MIT)
85 |
86 | Copyright (c) 2016 zzhoujay
87 |
88 | Permission is hereby granted, free of charge, to any person obtaining a copy
89 | of this software and associated documentation files (the "Software"), to deal
90 | in the Software without restriction, including without limitation the rights
91 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
92 | copies of the Software, and to permit persons to whom the Software is
93 | furnished to do so, subject to the following conditions:
94 |
95 | The above copyright notice and this permission notice shall be included in all
96 | copies or substantial portions of the Software.
97 |
98 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
99 |
100 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
101 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
102 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
103 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
104 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
105 | SOFTWARE.
106 | ```
107 |
108 | _by zzhoujay_
109 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdk 33
5 | defaultConfig {
6 | applicationId "zhou.demo"
7 | minSdkVersion 21
8 | targetSdkVersion 33
9 | versionCode 1
10 | versionName "1.0"
11 | }
12 | buildTypes {
13 | release {
14 | minifyEnabled false
15 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
16 | }
17 | }
18 | productFlavors {
19 | }
20 | namespace 'zhou.demo'
21 | lint {
22 | abortOnError false
23 | }
24 | }
25 |
26 | dependencies {
27 | implementation fileTree(include: ['*.jar'], dir: 'libs')
28 | testImplementation 'junit:junit:4.13.2'
29 | // appcompat 1.7.0 会强制 compile = 34 这里先用 1.6.1
30 | implementation 'androidx.appcompat:appcompat:1.6.1'
31 | implementation 'androidx.recyclerview:recyclerview:1.3.2'
32 | implementation project(':richtext')
33 | // implementation project(':okhttpimagedownloader')
34 | // implementation 'com.zzhoujay.richtext:richtext:3.0.8'
35 | implementation 'com.zzhoujay:html:1.0.2'
36 | }
37 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /home/zhou/Android/Sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/zhou/demo/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package zhou.demo;
2 |
3 | import android.app.Application;
4 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
15 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/app/src/main/assets/doge.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/L-X-J/RichText-Androidx/e81cb12ecc3a14047b0c54fe79b1e10fee41b646/app/src/main/assets/doge.jpg
--------------------------------------------------------------------------------
/app/src/main/java/zhou/demo/DebugActivity.java:
--------------------------------------------------------------------------------
1 | package zhou.demo;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import androidx.annotation.Nullable;
6 | import android.util.Log;
7 | import android.widget.ImageView;
8 | import android.widget.TextView;
9 |
10 | import com.zzhoujay.richtext.ImageHolder;
11 | import com.zzhoujay.richtext.RichText;
12 | import com.zzhoujay.richtext.callback.Callback;
13 | import com.zzhoujay.richtext.callback.SimpleImageFixCallback;
14 |
15 | /**
16 | * Created by zhou on 2017/10/8.
17 | */
18 |
19 | public class DebugActivity extends Activity {
20 |
21 | private static final String TAG = "DebugActivity";
22 |
23 | @Override
24 | protected void onCreate(@Nullable Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | setContentView(R.layout.activity_debug);
27 |
28 | RichText.initCacheDir(this);
29 | RichText.debugMode = true;
30 |
31 | TextView textView = findViewById(R.id.test_text);
32 | ImageView imageView = findViewById(R.id.image_view);
33 |
34 | String test_text_2 = "
“黑人”陈建州,16岁就代表中华台北参加“亚洲青年锦标赛”,21岁就成为了职业篮球运动员,身体素质就不用说了,身高189cm,体重90kg,职业球员的身体条件,娱乐圈估计也很难找出第二个了。
imageUrls, int position) {
48 | Calendar calendar = Calendar.getInstance();
49 | int m = calendar.get(Calendar.MINUTE);
50 | int s = calendar.get(Calendar.SECOND);
51 | Toast.makeText(TestActivity.this, "M:" + m + ",S:" + s, Toast.LENGTH_SHORT).show();
52 | }
53 | }).into(textView);
54 |
55 | }
56 |
57 | @Override
58 | protected void onDestroy() {
59 | super.onDestroy();
60 | richText.clear();
61 | richText = null;
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/sl.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/L-X-J/RichText-Androidx/e81cb12ecc3a14047b0c54fe79b1e10fee41b646/app/src/main/res/drawable/sl.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_debug.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
11 |
12 |
16 |
17 |
21 |
22 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
15 |
16 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_recycler.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_test.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
11 |
12 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/L-X-J/RichText-Androidx/e81cb12ecc3a14047b0c54fe79b1e10fee41b646/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/L-X-J/RichText-Androidx/e81cb12ecc3a14047b0c54fe79b1e10fee41b646/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/L-X-J/RichText-Androidx/e81cb12ecc3a14047b0c54fe79b1e10fee41b646/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/L-X-J/RichText-Androidx/e81cb12ecc3a14047b0c54fe79b1e10fee41b646/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/L-X-J/RichText-Androidx/e81cb12ecc3a14047b0c54fe79b1e10fee41b646/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/raw/hello.md:
--------------------------------------------------------------------------------
1 | # RichText
2 |
3 | > Android平台下的富文本解析器
4 |
5 | * 流式操作
6 | * 低侵入性
7 | * 支持Html格式文本
8 | * 支持图片点击事件
9 | * 链接自动回调
10 | * 支持设置加载中和加载错误时的图片
11 | * 支持自定义超链接的点击回调
12 | * 支持修正图片宽高
13 | * 支持GIF图片
14 |
15 | ### 效果
16 |
17 | 
18 |
19 |
20 | ### gradle中引用的方法
21 |
22 | ```
23 | implementation 'com.zzhoujay.richtext:richtext:1.1.5'
24 | ```
25 |
26 | ---
27 |
28 | ### 使用方式
29 |
30 | ```
31 | RichText.from(text).into(textView);
32 | ```
33 |
34 | 高级
35 |
36 | ```
37 | RichText
38 | .from(text) // 数据源
39 | .autoFix(true) // 是否自动修复,默认true
40 | .async(true) // 是否异步,默认false
41 | .fix(imageFixCallback) // 设置自定义修复图片宽高
42 | .imageClick(onImageClickListener) // 设置图片点击回调
43 | .urlClick(onURLClickListener) // 设置链接点击回调
44 | .placeHolder(placeHolder) // 设置加载中显示的占位图
45 | .error(errorImage) // 设置加载失败的错误图
46 | .into(textView); // 设置目标TextView
47 | ```
48 |
49 | ### 自定义修复宽高
50 | `hello`
51 | ```
52 | RichText.from(text).fix(new ImageFixCallback() {
53 | @Override
54 | public void onFix(ImageHolder holder,boolean imageReady) {
55 | if(imageReady){
56 | return;
57 | }
58 | if(holder.getImageType()==ImageHolder.GIF){
59 | holder.setWidth(400);
60 | holder.setHeight(400);
61 | }else {
62 | holder.setAutoFix(true);
63 | }
64 | }
65 | })
66 | ```
67 |
68 | 通过设置`holder.setAutoFix(true)`设置该图片为自动修复,自动修复的效果是图片按宽度充满,所有如果有些小的图片设置了自动填充可能会
69 | 失真,这时候可以取消自动修复设置自定义修复,将比较小的图片过滤出来,将其它的图片自动修复即可。
70 |
71 | 注意,如果img标签中没有宽高的话onFix方法会在图片加载完成前后调用两次,可以通过imageReady来判断
72 |
73 | 如下:
74 | ```
75 | RichText.from(text).autoFix(false).fix(new ImageFixCallback() {
76 | @Override
77 | public void onFix(ImageHolder holder, boolean imageReady) {
78 | if (holder.getWidth() > 500 && holder.getHeight() > 500) {
79 | holder.setAutoFix(true);
80 | }
81 | }
82 | }).into(textView);
83 | ```
84 |
85 | ### 注意
86 |
87 | * gif图片播放在API12以下需要手动调用recycler,不然直到应用退出gif图片都会一直刷新
88 | * 目前只能自动通过src的后缀识别是否为gif图,可以通过设置ImageFixCallback对某个特点的图片设置为GIF
89 | ,例如:`holder.setImageType(ImageHolder.GIF)`
90 | * 只支持Html.fromHtml能够解析的标签,自定义标签的支持后续会跟上的
91 |
92 | ### 后续计划
93 |
94 | * 添加自定义标签的支持
95 | * 添加MarkDown语法的支持
96 |
97 | ### 具体使用请查看demo
98 |
99 | [ListView Demo](https://github.com/zzhoujay/RichText/blob/master/app/src/main/java/zhou/demo/ListViewActivity.java)、
100 | [RecyclerView Demo](https://github.com/zzhoujay/RichText/blob/master/app/src/main/java/zhou/demo/RecyclerViewActivity.java)、
101 | [Gif Demo](https://github.com/zzhoujay/RichText/blob/master/app/src/main/java/zhou/demo/GifActivity.java)
102 |
103 | _by zzhoujay_
--------------------------------------------------------------------------------
/app/src/main/res/raw/large:
--------------------------------------------------------------------------------
1 |
2 | 汉仪喵魂体!
3 | 自己写了小半年的手写字体刚上线,自我感觉还是值得推荐的!
4 | 我先给大家图文并茂地讲讲这字儿怎么值得推荐!
5 |
8 |

9 |
12 |

13 |
16 |

17 |
20 |

21 |
24 |

25 | 字库加标点接近一万字
26 |
我的极速是除了吃饭睡觉
27 | 一刻不停的写
一天最多300字
28 | 极速一天之后第二天就要最少崩溃半天
29 | 哈哈哈哈哈
30 |
上半年因为出书有点拖延
31 |
到临交稿的两个月剩的有点多
32 | 我只好回老家闭关写
33 | (有人做饭啊没有干扰还)
34 | 有一个半月的时间里
35 | 每天都
36 | 从天亮写到天黑
37 | 从睁眼写到闭眼
38 |
微信朋友圈还合作什么的
39 | 啥也不管了不回了
40 |
特别的酸爽
41 | 坚持下来之后感觉耐力提升了一百倍
42 |
之后谁再说什么事儿忍不了抛不下
43 | 我就特别想说
44 | 你去抛下一切功名利禄社交合作
45 | 写俩月字库试试
之后什么矫情都没了
46 |
云淡风轻的
47 |
50 |

51 |
54 |

55 | 啊……
56 | 最近又有一个字体的想法……
57 | 还蛮好看……
58 | 但是写一套太累辣!
59 |
粉丝的话可以加我私人微信号:catsoulmini
60 | (同行或职业达人之类加了备注一下身份即可)
61 |
--------------------------------------------------------------------------------
/app/src/main/res/raw/sl.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/L-X-J/RichText-Androidx/e81cb12ecc3a14047b0c54fe79b1e10fee41b646/app/src/main/res/raw/sl.jpg
--------------------------------------------------------------------------------
/app/src/main/res/raw/tt.md:
--------------------------------------------------------------------------------
1 | # MarkDown
2 |
3 | > Android平台的原生Markdown解析器,已整合进 [RichText](https://github.com/zzhoujay/RichText)
4 |
5 | * 由markdown文本直接转换为Spanned,快捷高效
6 | * 不依赖特定控件,低侵入性
7 | * 遵循 Github Flavored Markdown 标准
8 |
9 | ### 使用
10 |
11 | ```
12 | Markdown.fromMarkdown(text,imageGetter,textView);
13 | ```
14 | **注意:** 此方法需要在textView的Measure完成后调用,因为需要获取textView的宽高
15 |
16 | 例子:
17 | ```
18 | textView.post(new Runnable() {
19 | @Override
20 | public void run() {
21 | Spanned spanned = MarkDown.fromMarkdown(stream, new Html.ImageGetter() {
22 | @Override
23 | public Drawable getDrawable(String source) {
24 | Drawable drawable = getResources().getDrawable(R.mipmap.ic_launcher);
25 | drawable.setBounds(0, 0, 400, 400);
26 | return drawable;
27 | }
28 | }, textView);
29 | textView.setText(spanned);
30 | }
31 | ```
32 |
33 | ### 在RichText中使用
34 |
35 | [RichText](https://github.com/zzhoujay/RichText) 包含了一些对图片和其它东西的处理,使用更简单
36 | ```
37 | RichText.fromMarkdown(markdown).into(textView);
38 | ```
39 |
40 | ### Use in Gradle
41 |
42 | `implementation 'com.zzhoujay.markdown:markdown:0.0.4'`
43 |
44 |
45 | ### 已知问题
46 |
47 | * ~~引用块内不支持Setext-style的标题(后续会想办法修复~~ (已修复)
48 | * 暂不支持使用反斜杠 \\ 转义
49 | * 不支持表格
50 |
51 |
52 | ### 后续计划
53 |
54 | * 修复一些已知问题
55 |
56 | _by zzhoujay_
57 |
--------------------------------------------------------------------------------
/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 | RichTextDemo
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/network_security_config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ww4.sinaimg.cn
5 | baidu.com
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/test/java/zhou/demo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package zhou.demo;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/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 | mavenCentral()
6 | google()
7 | }
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:7.2.2'
10 | }
11 | }
12 |
13 | allprojects {
14 | repositories {
15 | maven { url 'https://maven.aliyun.com/repository/public' }
16 | maven { url 'https://maven.aliyun.com/repository/central' }
17 | maven { url 'https://maven.aliyun.com/repository/jcenter' }
18 | mavenCentral()
19 | google()
20 | }
21 | }
22 |
23 | tasks.register('clean', Delete) {
24 | delete rootProject.buildDir
25 | }
26 |
--------------------------------------------------------------------------------
/glideimagegetter/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 | publish.sh
3 |
--------------------------------------------------------------------------------
/glideimagegetter/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.novoda.bintray-release'
3 |
4 | def version_code = 6
5 | def version_name = "1.0.5"
6 |
7 | android {
8 | compileSdkVersion 33
9 |
10 | defaultConfig {
11 | minSdkVersion 15
12 | targetSdkVersion 33
13 | versionCode version_code
14 | versionName version_name
15 |
16 | resourcePrefix "zhou_glide_"
17 |
18 |
19 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
20 |
21 | }
22 | buildTypes {
23 | release {
24 | minifyEnabled false
25 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
26 | }
27 | }
28 | lintOptions {
29 | abortOnError false
30 | }
31 | }
32 |
33 | dependencies {
34 | implementation fileTree(include: ['*.jar'], dir: 'libs')
35 | testImplementation 'junit:junit:4.13.2'
36 | implementation 'com.github.bumptech.glide:glide:3.7.0'
37 | implementation 'com.zzhoujay.richtext:richtext:3.0.8'
38 | // implementation project(':richtext')
39 | }
40 |
41 | publish {
42 |
43 | Properties properties = new Properties()
44 | properties.load(project.rootProject.file('local.properties').newDataInputStream())
45 | //bintray.com用户名
46 | userOrg = properties.getProperty("bintray.user")
47 | //jcenter上的路径
48 | groupId = "com.zzhoujay.glideimagegetter"
49 | //项目名称
50 | artifactId = 'glideimagegetter'
51 | //版本号
52 | publishVersion = version_name
53 | //描述,不重要
54 | desc = 'RichText的Glide图片加载库的插件'
55 | //网站,不重要
56 | website = 'https://github.com/zzhoujay/RichTex'
57 |
58 | bintrayUser = properties.getProperty("bintray.user")
59 | bintrayKey = properties.getProperty("bintray.apikey")
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/glideimagegetter/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 /Users/zhou/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/glideimagegetter/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/glideimagegetter/src/main/java/com/zzhoujay/glideimagegetter/GlideImageGetter.java:
--------------------------------------------------------------------------------
1 | package com.zzhoujay.glideimagegetter;
2 |
3 | import android.graphics.Rect;
4 | import android.graphics.drawable.Drawable;
5 | import androidx.collection.LruCache;
6 | import android.widget.TextView;
7 |
8 | import com.bumptech.glide.BitmapTypeRequest;
9 | import com.bumptech.glide.DrawableTypeRequest;
10 | import com.bumptech.glide.GenericRequestBuilder;
11 | import com.bumptech.glide.GifTypeRequest;
12 | import com.bumptech.glide.Glide;
13 | import com.zzhoujay.richtext.CacheType;
14 | import com.zzhoujay.richtext.ImageHolder;
15 | import com.zzhoujay.richtext.RichTextConfig;
16 | import com.zzhoujay.richtext.callback.ImageGetter;
17 | import com.zzhoujay.richtext.callback.ImageLoadNotify;
18 | import com.zzhoujay.richtext.drawable.DrawableWrapper;
19 | import com.zzhoujay.richtext.ext.Base64;
20 |
21 | import java.util.HashSet;
22 |
23 | /**
24 | * Created by zhou on 2016/12/3.
25 | * 使用Glide作为图片加载器
26 | *
27 | * 不在建议使用,建议使用DefaultImageGetter基本可以替代此类。
28 | * 此类后面将不会维护了,请尽快转移!
29 | */
30 | @Deprecated
31 | public class GlideImageGetter implements ImageGetter, ImageLoadNotify {
32 |
33 | private static final int TARGET_TAG = R.id.zhou_glide_image_tag_id;
34 |
35 | private static final LruCache imageBoundCache;
36 |
37 | static {
38 | imageBoundCache = new LruCache<>(20);
39 | }
40 |
41 | private static void cache(String source, Rect rect) {
42 | imageBoundCache.put(source, rect);
43 | }
44 |
45 | private static Rect loadCache(String source) {
46 | return imageBoundCache.get(source);
47 | }
48 |
49 | private HashSet targets;
50 | private ImageLoadNotify imageLoadNotify;
51 | private int loadedCount;
52 |
53 | public GlideImageGetter() {
54 | targets = new HashSet<>();
55 | }
56 |
57 | private void checkTag(TextView textView) {
58 | //noinspection unchecked
59 | HashSet ts = (HashSet) textView.getTag(TARGET_TAG);
60 | if (ts != null) {
61 | if (ts == targets) {
62 | return;
63 | }
64 | for (ImageTarget target : ts) {
65 | target.recycle();
66 | }
67 | ts.clear();
68 | }
69 | textView.setTag(TARGET_TAG, targets);
70 | }
71 |
72 | @Override
73 | public Drawable getDrawable(ImageHolder holder, final RichTextConfig config, TextView textView) {
74 | final ImageTarget target;
75 | final GenericRequestBuilder load;
76 | DrawableTypeRequest dtr;
77 | DrawableWrapper drawableWrapper = new DrawableWrapper();
78 | byte[] src = Base64.decode(holder.getSource());
79 | if (src != null) {
80 | dtr = Glide.with(textView.getContext()).load(src);
81 | } else {
82 | dtr = Glide.with(textView.getContext()).load(holder.getSource());
83 | }
84 | Rect rect = null;
85 | if (config.cacheType >= CacheType.LAYOUT) {
86 | rect = loadCache(holder.getSource());
87 | if (rect != null) {
88 | drawableWrapper.setBounds(rect);
89 | }
90 | } else {
91 | drawableWrapper.setBounds(0, 0, holder.getWidth(), holder.getHeight());
92 | }
93 | if (holder.isGif()) {
94 | target = new ImageTargetGif(textView, drawableWrapper, holder, config, this, rect);
95 | load = dtr.asGif();
96 | } else {
97 | target = new ImageTargetBitmap(textView, drawableWrapper, holder, config, this, rect);
98 | load = dtr.asBitmap().atMost();
99 | }
100 | checkTag(textView);
101 | targets.add(target);
102 | if (!config.resetSize && holder.isInvalidateSize()) {
103 | load.override(holder.getWidth(), holder.getHeight());
104 | }
105 | if (holder.getScaleType() == ImageHolder.ScaleType.CENTER_CROP) {
106 | if (holder.isGif()) {
107 | //noinspection ConstantConditions
108 | ((GifTypeRequest) load).centerCrop();
109 | } else {
110 | //noinspection ConstantConditions
111 | ((BitmapTypeRequest) load).centerCrop();
112 | }
113 | } else if (holder.getScaleType() == ImageHolder.ScaleType.FIT_CENTER) {
114 | if (holder.isGif()) {
115 | //noinspection ConstantConditions
116 | ((GifTypeRequest) load).fitCenter();
117 | } else {
118 | //noinspection ConstantConditions
119 | ((BitmapTypeRequest) load).fitCenter();
120 | }
121 | }
122 | textView.post(new Runnable() {
123 | @Override
124 | public void run() {
125 | load.placeholder(config.placeHolder).error(config.errorImage).into(target);
126 | }
127 | });
128 | drawableWrapper.setCallback(textView);
129 | return drawableWrapper;
130 | }
131 |
132 | @Override
133 | public void registerImageLoadNotify(ImageLoadNotify imageLoadNotify) {
134 | this.imageLoadNotify = imageLoadNotify;
135 | }
136 |
137 | @Override
138 | public void done(Object from) {
139 | if (from instanceof ImageTarget) {
140 | ImageTarget imageTarget = (ImageTarget) from;
141 | DrawableWrapper drawableWrapper = (DrawableWrapper) imageTarget.urlDrawableWeakReference.get();
142 | if (drawableWrapper != null && imageTarget.config.cacheType >= CacheType.LAYOUT) {
143 | cache(imageTarget.holder.getSource(), drawableWrapper.getBounds());
144 | }
145 | targets.remove(imageTarget);
146 | loadedCount++;
147 | if (imageLoadNotify != null) {
148 | imageLoadNotify.done(loadedCount);
149 | }
150 | }
151 | }
152 |
153 | @Override
154 | public void recycle() {
155 | for (ImageTarget target : targets) {
156 | target.recycle();
157 | }
158 | targets.clear();
159 | }
160 | }
161 |
--------------------------------------------------------------------------------
/glideimagegetter/src/main/java/com/zzhoujay/glideimagegetter/ImageTarget.java:
--------------------------------------------------------------------------------
1 | package com.zzhoujay.glideimagegetter;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.graphics.Rect;
6 | import android.graphics.drawable.Drawable;
7 | import android.os.Build;
8 | import androidx.appcompat.widget.TintContextWrapper;
9 | import android.widget.TextView;
10 |
11 | import com.bumptech.glide.request.target.BaseTarget;
12 | import com.bumptech.glide.request.target.SizeReadyCallback;
13 | import com.zzhoujay.richtext.ImageHolder;
14 | import com.zzhoujay.richtext.RichTextConfig;
15 | import com.zzhoujay.richtext.callback.ImageLoadNotify;
16 | import com.zzhoujay.richtext.callback.Recyclable;
17 | import com.zzhoujay.richtext.drawable.DrawableWrapper;
18 |
19 | import java.lang.ref.WeakReference;
20 |
21 | /**
22 | * Created by zhou on 16-10-23.
23 | * Image target
24 | */
25 | abstract class ImageTarget extends BaseTarget implements Recyclable {
26 |
27 | final WeakReference textViewWeakReference;
28 | final WeakReference urlDrawableWeakReference;
29 | final ImageHolder holder;
30 | private final WeakReference imageLoadNotifyWeakReference;
31 | final RichTextConfig config;
32 | final Rect rect;
33 |
34 | ImageTarget(TextView textView, DrawableWrapper drawableWrapper, ImageHolder holder, RichTextConfig config, ImageLoadNotify imageLoadNotify, Rect rect) {
35 | this.textViewWeakReference = new WeakReference<>(textView);
36 | this.urlDrawableWeakReference = new WeakReference<>(drawableWrapper);
37 | this.holder = holder;
38 | this.config = config;
39 | this.imageLoadNotifyWeakReference = new WeakReference<>(imageLoadNotify);
40 | this.rect = rect;
41 | }
42 |
43 | @Override
44 | public void onLoadStarted(Drawable placeholder) {
45 | super.onLoadStarted(placeholder);
46 | if (placeholder == null || !activityIsAlive()) {
47 | return;
48 | }
49 | DrawableWrapper drawableWrapper = urlDrawableWeakReference.get();
50 | if (drawableWrapper == null) {
51 | return;
52 | }
53 | holder.setImageState(ImageHolder.ImageState.LOADING);
54 | drawableWrapper.setDrawable(placeholder);
55 | if (rect != null) {
56 | drawableWrapper.setBounds(rect);
57 | } else {
58 | if (!config.autoFix && config.imageFixCallback != null) {
59 | config.imageFixCallback.onLoading(holder);
60 | }
61 | int width;
62 | int height = 0;
63 | if (config.autoFix || holder.isAutoFix() || !holder.isInvalidateSize()) {
64 | width = getRealWidth();
65 | int ow = placeholder.getBounds().width();
66 | if (ow != 0) {
67 | height = placeholder.getBounds().height() * width / ow;
68 | }
69 | if (height == 0) {
70 | height = width / 2;
71 | }
72 | } else {
73 | width = holder.getWidth();
74 | height = holder.getHeight();
75 | }
76 | drawableWrapper.setBounds(0, 0, width, height);
77 | }
78 | resetText();
79 | }
80 |
81 | @Override
82 | public void onLoadFailed(Exception e, Drawable errorDrawable) {
83 | super.onLoadFailed(e, errorDrawable);
84 | if (errorDrawable == null || !activityIsAlive()) {
85 | return;
86 | }
87 | DrawableWrapper drawableWrapper = urlDrawableWeakReference.get();
88 | if (drawableWrapper == null) {
89 | return;
90 | }
91 | holder.setImageState(ImageHolder.ImageState.FAILED);
92 | drawableWrapper.setDrawable(errorDrawable);
93 | if (rect != null) {
94 | drawableWrapper.setBounds(rect);
95 | } else {
96 | if (!config.autoFix && config.imageFixCallback != null) {
97 | config.imageFixCallback.onFailure(holder, e);
98 | }
99 | int width;
100 | int height = 0;
101 | if (config.autoFix || holder.isAutoFix() || !holder.isInvalidateSize()) {
102 | width = getRealWidth();
103 | int ow = errorDrawable.getBounds().width();
104 | if (ow != 0) {
105 | height = errorDrawable.getBounds().height() * width / ow;
106 | }
107 | if (height == 0) {
108 | height = width / 2;
109 | }
110 | } else {
111 | width = holder.getWidth();
112 | height = holder.getHeight();
113 | }
114 | drawableWrapper.setBounds(0, 0, width, height);
115 | }
116 | resetText();
117 | loadDone();
118 | }
119 |
120 | @Override
121 | public void getSize(SizeReadyCallback cb) {
122 | int maxWidth = getRealWidth(), maxHeight = Integer.MAX_VALUE;
123 | if (config.imageFixCallback != null) {
124 | holder.setImageState(ImageHolder.ImageState.SIZE_READY);
125 | ImageHolder.SizeHolder sizeHolder = new ImageHolder.SizeHolder(0, 0);
126 | config.imageFixCallback.onSizeReady(holder, 0, 0, sizeHolder);
127 | if (sizeHolder.isInvalidateSize()) {
128 | maxWidth = sizeHolder.getWidth();
129 | maxHeight = sizeHolder.getHeight();
130 | }
131 | }
132 | cb.onSizeReady(maxWidth, maxHeight);
133 | }
134 |
135 | /**
136 | * 获取可用宽度
137 | *
138 | * @return width
139 | */
140 | int getRealWidth() {
141 | TextView tv = textViewWeakReference.get();
142 | if (tv == null) {
143 | return 0;
144 | }
145 | return tv.getWidth() - tv.getPaddingRight() - tv.getPaddingLeft();
146 | }
147 |
148 | int getReadHeight() {
149 | TextView tv = textViewWeakReference.get();
150 | if (tv == null) {
151 | return 0;
152 | }
153 | return tv.getHeight() - tv.getPaddingTop() - tv.getPaddingBottom();
154 | }
155 |
156 | void resetText() {
157 | TextView tv = textViewWeakReference.get();
158 | if (tv != null) {
159 | CharSequence cs = tv.getText();
160 | tv.setText(cs);
161 | }
162 | }
163 |
164 | void loadDone() {
165 | ImageLoadNotify notify = imageLoadNotifyWeakReference.get();
166 | if (notify != null) {
167 | notify.done(this);
168 | }
169 | }
170 |
171 | /**
172 | * 判断Activity是否已经结束
173 | *
174 | * @return true:已结束
175 | */
176 | boolean activityIsAlive() {
177 | TextView textView = textViewWeakReference.get();
178 | if (textView == null) {
179 | return false;
180 | }
181 | Context context = textView.getContext();
182 | if (context == null) {
183 | return false;
184 | }
185 | if (context instanceof TintContextWrapper) {
186 | context = ((TintContextWrapper) context).getBaseContext();
187 | }
188 | if (context instanceof Activity) {
189 | if (((Activity) context).isFinishing()) {
190 | return false;
191 | } else {
192 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && ((Activity) context).isDestroyed()) {
193 | return false;
194 | }
195 | }
196 | }
197 | return true;
198 | }
199 | }
200 |
--------------------------------------------------------------------------------
/glideimagegetter/src/main/java/com/zzhoujay/glideimagegetter/ImageTargetBitmap.java:
--------------------------------------------------------------------------------
1 | package com.zzhoujay.glideimagegetter;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.Rect;
5 | import android.graphics.drawable.BitmapDrawable;
6 | import android.graphics.drawable.Drawable;
7 | import android.widget.TextView;
8 |
9 | import com.bumptech.glide.Glide;
10 | import com.bumptech.glide.request.animation.GlideAnimation;
11 | import com.zzhoujay.richtext.ImageHolder;
12 | import com.zzhoujay.richtext.RichTextConfig;
13 | import com.zzhoujay.richtext.callback.ImageLoadNotify;
14 | import com.zzhoujay.richtext.drawable.DrawableWrapper;
15 |
16 | /**
17 | * Created by zhou on 16-10-23.
18 | * ImageTarget Bitmap
19 | */
20 | class ImageTargetBitmap extends ImageTarget {
21 |
22 |
23 | ImageTargetBitmap(TextView textView, DrawableWrapper drawableWrapper, ImageHolder holder, RichTextConfig config, ImageLoadNotify imageLoadNotify, Rect rect) {
24 | super(textView, drawableWrapper, holder, config, imageLoadNotify, rect);
25 | }
26 |
27 | @Override
28 | public void recycle() {
29 | Glide.clear(this);
30 | }
31 |
32 | @Override
33 | public void onResourceReady(Bitmap resource, GlideAnimation super Bitmap> glideAnimation) {
34 | if (!activityIsAlive()) {
35 | return;
36 | }
37 | DrawableWrapper drawableWrapper = urlDrawableWeakReference.get();
38 | if (drawableWrapper == null) {
39 | return;
40 | }
41 | TextView textView = textViewWeakReference.get();
42 | holder.setImageState(ImageHolder.ImageState.READY);
43 | holder.setSize(resource.getWidth(), resource.getHeight());
44 | Drawable drawable = new BitmapDrawable(textView.getContext().getResources(), resource);
45 | drawableWrapper.setDrawable(drawable);
46 | if (rect != null) {
47 | drawableWrapper.setBounds(rect);
48 | } else {
49 | if (!config.autoFix && config.imageFixCallback != null) {
50 | config.imageFixCallback.onImageReady(holder, resource.getWidth(), resource.getHeight());
51 | }
52 | if (config.autoFix || holder.isAutoFix() || !holder.isInvalidateSize()) {
53 | int width = getRealWidth();
54 | int height = (int) ((float) resource.getHeight() * width / resource.getWidth());
55 | drawableWrapper.setBounds(0, 0, width, height);
56 | } else {
57 | drawableWrapper.setBounds(0, 0, holder.getWidth(), holder.getHeight());
58 | }
59 | }
60 | resetText();
61 | loadDone();
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/glideimagegetter/src/main/java/com/zzhoujay/glideimagegetter/ImageTargetGif.java:
--------------------------------------------------------------------------------
1 | package com.zzhoujay.glideimagegetter;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.Rect;
5 | import android.graphics.drawable.Drawable;
6 | import androidx.annotation.NonNull;
7 | import android.widget.TextView;
8 |
9 | import com.bumptech.glide.Glide;
10 | import com.bumptech.glide.load.resource.drawable.GlideDrawable;
11 | import com.bumptech.glide.load.resource.gif.GifDrawable;
12 | import com.bumptech.glide.request.animation.GlideAnimation;
13 | import com.zzhoujay.richtext.ImageHolder;
14 | import com.zzhoujay.richtext.RichTextConfig;
15 | import com.zzhoujay.richtext.callback.ImageLoadNotify;
16 | import com.zzhoujay.richtext.drawable.DrawableWrapper;
17 |
18 | import java.lang.ref.SoftReference;
19 |
20 | /**
21 | * Created by zhou on 16-10-23.
22 | * ImageTarget Gif
23 | */
24 | class ImageTargetGif extends ImageTarget implements Drawable.Callback {
25 |
26 | private SoftReference gifDrawableSoftReference;
27 |
28 | ImageTargetGif(TextView textView, DrawableWrapper drawableWrapper, ImageHolder holder, RichTextConfig config, ImageLoadNotify imageLoadNotify, Rect rect) {
29 | super(textView, drawableWrapper, holder, config, imageLoadNotify, rect);
30 | }
31 |
32 |
33 | @Override
34 | public void recycle() {
35 | Glide.clear(this);
36 | if (gifDrawableSoftReference != null) {
37 | GifDrawable gifDrawable = gifDrawableSoftReference.get();
38 | if (gifDrawable != null) {
39 | gifDrawable.setCallback(null);
40 | gifDrawable.stop();
41 | }
42 | }
43 | }
44 |
45 | @Override
46 | public void onResourceReady(GifDrawable resource, GlideAnimation super GifDrawable> glideAnimation) {
47 | if (!activityIsAlive()) {
48 | return;
49 | }
50 | DrawableWrapper drawableWrapper = urlDrawableWeakReference.get();
51 | if (drawableWrapper == null) {
52 | return;
53 | }
54 | holder.setImageState(ImageHolder.ImageState.READY);
55 | gifDrawableSoftReference = new SoftReference<>(resource);
56 | Bitmap first = resource.getFirstFrame();
57 | holder.setSize(first.getWidth(), first.getHeight());
58 | drawableWrapper.setDrawable(resource);
59 | if (rect != null) {
60 | drawableWrapper.setBounds(rect);
61 | } else {
62 | if (!config.autoFix && config.imageFixCallback != null) {
63 | config.imageFixCallback.onImageReady(holder, first.getWidth(), first.getHeight());
64 | }
65 | if (config.autoFix || holder.isAutoFix() || !holder.isInvalidateSize()) {
66 | int width = getRealWidth();
67 | int height = (int) ((float) first.getHeight() * width / first.getWidth());
68 | drawableWrapper.setBounds(0, 0, width, height);
69 | } else {
70 | drawableWrapper.setBounds(0, 0, holder.getWidth(), holder.getHeight());
71 | }
72 | if (holder.isAutoPlay()) {
73 | resource.setCallback(this);
74 | resource.start();
75 | resource.setLoopCount(GlideDrawable.LOOP_FOREVER);
76 | }
77 | }
78 | resetText();
79 | loadDone();
80 | }
81 |
82 | @Override
83 | public void invalidateDrawable(@NonNull Drawable who) {
84 | TextView textView = textViewWeakReference.get();
85 | if (textView != null) {
86 | textView.invalidate();
87 | } else {
88 | recycle();
89 | }
90 | }
91 |
92 | @Override
93 | public void scheduleDrawable(@NonNull Drawable who, @NonNull Runnable what, long when) {
94 |
95 | }
96 |
97 | @Override
98 | public void unscheduleDrawable(@NonNull Drawable who, @NonNull Runnable what) {
99 |
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/glideimagegetter/src/main/res/values/zhou_glide_ids.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/glideimagegetter/src/test/java/com/zzhoujay/glideimagegetter/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.zzhoujay.glideimagegetter;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.assertEquals;
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 | }
--------------------------------------------------------------------------------
/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 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
19 | android.enableJetifier=true
20 | android.useAndroidX=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/L-X-J/RichText-Androidx/e81cb12ecc3a14047b0c54fe79b1e10fee41b646/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Jul 18 17:25:42 CST 2022
2 | distributionBase=GRADLE_USER_HOME
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
4 | distributionPath=wrapper/dists
5 | zipStorePath=wrapper/dists
6 | zipStoreBase=GRADLE_USER_HOME
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
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
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
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 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn ( ) {
37 | echo "$*"
38 | }
39 |
40 | die ( ) {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/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 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
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 |
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 Windows 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 |
--------------------------------------------------------------------------------
/image/image.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/L-X-J/RichText-Androidx/e81cb12ecc3a14047b0c54fe79b1e10fee41b646/image/image.jpg
--------------------------------------------------------------------------------
/okhttpimagedownloader/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/okhttpimagedownloader/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 33
5 |
6 | defaultConfig {
7 | minSdkVersion 15
8 | targetSdkVersion 33
9 |
10 | testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
11 |
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | namespace 'com.zzhoujay.okhttpimagedownloader'
20 | lint {
21 | abortOnError false
22 | }
23 | }
24 |
25 | dependencies {
26 | implementation 'com.squareup.okhttp3:okhttp:3.10.0'
27 | // implementation project(':richtext')
28 | implementation 'com.zzhoujay.richtext:richtext:3.0.8'
29 | }
30 |
--------------------------------------------------------------------------------
/okhttpimagedownloader/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 /Users/zhou/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/okhttpimagedownloader/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/okhttpimagedownloader/src/main/java/com/zzhoujay/okhttpimagedownloader/OkHttpImageDownloader.java:
--------------------------------------------------------------------------------
1 | package com.zzhoujay.okhttpimagedownloader;
2 |
3 | import android.annotation.SuppressLint;
4 |
5 | import com.zzhoujay.richtext.callback.BitmapStream;
6 | import com.zzhoujay.richtext.ig.ImageDownloader;
7 |
8 | import java.io.IOException;
9 | import java.io.InputStream;
10 | import java.security.KeyManagementException;
11 | import java.security.NoSuchAlgorithmException;
12 | import java.security.SecureRandom;
13 | import java.security.cert.X509Certificate;
14 | import java.util.concurrent.TimeUnit;
15 |
16 | import javax.net.ssl.HostnameVerifier;
17 | import javax.net.ssl.SSLContext;
18 | import javax.net.ssl.SSLSession;
19 | import javax.net.ssl.TrustManager;
20 | import javax.net.ssl.X509TrustManager;
21 |
22 | import okhttp3.OkHttpClient;
23 | import okhttp3.Request;
24 | import okhttp3.Response;
25 |
26 | /**
27 | * Created by zhou on 2017/9/11.
28 | * 使用OkHttp实现的图片下载器
29 | */
30 |
31 | @SuppressWarnings("unused")
32 | public class OkHttpImageDownloader implements ImageDownloader {
33 |
34 | @Override
35 | public BitmapStream download(String source) throws IOException {
36 | return new BitmapStreamWrapper(source);
37 | }
38 |
39 | private static class BitmapStreamWrapper implements BitmapStream {
40 |
41 | private final String url;
42 | private Response response;
43 | private InputStream inputStream;
44 |
45 | private BitmapStreamWrapper(String url) {
46 | this.url = url;
47 | }
48 |
49 | @Override
50 | public InputStream getInputStream() throws IOException {
51 | Request request = new Request.Builder().url(url).get().build();
52 | response = getClient().newCall(request).execute();
53 | inputStream = response.body().byteStream();
54 | return inputStream;
55 | }
56 |
57 | @Override
58 | public void close() throws IOException {
59 | if (inputStream != null) {
60 | inputStream.close();
61 | }
62 | if (response != null) {
63 | response.close();
64 | }
65 | }
66 | }
67 |
68 | private static OkHttpClient getClient() {
69 | return OkHttpClientHolder.CLIENT;
70 | }
71 |
72 |
73 | private static class OkHttpClientHolder {
74 | private static final OkHttpClient CLIENT;
75 | private static SSLContext sslContext = null;
76 |
77 | private static HostnameVerifier DO_NOT_VERIFY = new HostnameVerifier() {
78 | @SuppressLint("BadHostnameVerifier")
79 | @Override
80 | public boolean verify(String hostname, SSLSession session) {
81 | return true;
82 | }
83 | };
84 |
85 | static {
86 | // 设置https为全部信任
87 | X509TrustManager xtm = new X509TrustManager() {
88 | @SuppressLint("TrustAllX509TrustManager")
89 | @Override
90 | public void checkClientTrusted(X509Certificate[] chain, String authType) {
91 | }
92 |
93 | @SuppressLint("TrustAllX509TrustManager")
94 | @Override
95 | public void checkServerTrusted(X509Certificate[] chain, String authType) {
96 | }
97 |
98 | @Override
99 | public X509Certificate[] getAcceptedIssuers() {
100 | return new X509Certificate[0];
101 | }
102 | };
103 |
104 |
105 | try {
106 | sslContext = SSLContext.getInstance("SSL");
107 |
108 | sslContext.init(null, new TrustManager[]{xtm}, new SecureRandom());
109 |
110 | } catch (NoSuchAlgorithmException | KeyManagementException e) {
111 | e.printStackTrace();
112 | }
113 |
114 | CLIENT = new OkHttpClient().newBuilder()
115 | .readTimeout(10, TimeUnit.SECONDS)
116 | .writeTimeout(10, TimeUnit.SECONDS)
117 | .connectTimeout(10, TimeUnit.SECONDS)
118 | .sslSocketFactory(sslContext.getSocketFactory(), xtm)
119 | .hostnameVerifier(DO_NOT_VERIFY)
120 | .build();
121 | }
122 |
123 | }
124 | }
125 |
--------------------------------------------------------------------------------
/richtext/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 | publish.sh
--------------------------------------------------------------------------------
/richtext/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 |
4 | android {
5 | compileSdk 34
6 | defaultConfig {
7 | minSdkVersion 21
8 | targetSdkVersion 33
9 | }
10 | buildTypes {
11 | release {
12 | minifyEnabled false
13 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
14 | }
15 | }
16 | namespace 'com.zzhoujay.richtext'
17 | lint {
18 | abortOnError false
19 | }
20 | }
21 |
22 | dependencies {
23 | implementation 'com.zzhoujay.markdown:markdown:1.0.5'
24 | implementation 'com.jakewharton:disklrucache:2.0.2'
25 | implementation 'androidx.annotation:annotation:1.8.2'
26 | // implementation 'androidx.legacy:legacy-support-v4:1.0.0'
27 | }
--------------------------------------------------------------------------------
/richtext/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /home/zhou/Android/Sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/richtext/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/richtext/src/main/java/com/zzhoujay/richtext/CacheType.java:
--------------------------------------------------------------------------------
1 | package com.zzhoujay.richtext;
2 |
3 | /**
4 | * Created by zhou on 2016/12/5.
5 | * CacheType
6 | */
7 | //@IntDef({CacheType.NONE, CacheType.LAYOUT, CacheType.ALL})
8 | public enum CacheType {
9 | none(0), layout(1), all(2);
10 |
11 | int value;
12 |
13 | CacheType(int value) {
14 | this.value = value;
15 | }
16 |
17 | public int intValue() {
18 | return value;
19 | }
20 | // int NONE = 0; // 不进行缓存
21 | // int LAYOUT = 1; // 只缓存文字样式和图片大小信息
22 | // int ALL = 2; // 在LAYOUT的基础上还缓存图片,使用前需先设置缓存目录
23 | }
24 |
--------------------------------------------------------------------------------
/richtext/src/main/java/com/zzhoujay/richtext/LinkHolder.java:
--------------------------------------------------------------------------------
1 | package com.zzhoujay.richtext;
2 |
3 | import android.graphics.Color;
4 | import androidx.annotation.ColorInt;
5 |
6 | /**
7 | * Created by zhou on 2016/11/17.
8 | * LinkHolder
9 | */
10 | @SuppressWarnings("unused")
11 | public class LinkHolder {
12 |
13 | private static final int link_color = Color.parseColor("#4078C0");
14 |
15 | private final String url;
16 | @ColorInt
17 | private int color;
18 | private boolean underLine;
19 |
20 | public LinkHolder(String url) {
21 | this.url = url;
22 | this.color = link_color;
23 | underLine = true;
24 | }
25 |
26 | @ColorInt
27 | public int getColor() {
28 | return color;
29 | }
30 |
31 | public void setColor(@ColorInt int color) {
32 | this.color = color;
33 | }
34 |
35 | public boolean isUnderLine() {
36 | return underLine;
37 | }
38 |
39 | public void setUnderLine(boolean underLine) {
40 | this.underLine = underLine;
41 | }
42 |
43 | public String getUrl() {
44 | return url;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/richtext/src/main/java/com/zzhoujay/richtext/RichState.java:
--------------------------------------------------------------------------------
1 | package com.zzhoujay.richtext;
2 |
3 | /**
4 | * Created by zhou on 16-10-24.
5 | * Image Load State
6 | */
7 | public enum RichState {
8 | ready, loading, loaded
9 | }
10 |
--------------------------------------------------------------------------------
/richtext/src/main/java/com/zzhoujay/richtext/RichTextPool.java:
--------------------------------------------------------------------------------
1 | package com.zzhoujay.richtext;
2 |
3 | import android.text.SpannableStringBuilder;
4 | import android.text.Spanned;
5 | import android.util.LruCache;
6 |
7 | import com.zzhoujay.richtext.ext.Debug;
8 | import com.zzhoujay.richtext.ext.MD5;
9 | import com.zzhoujay.richtext.parser.CachedSpannedParser;
10 | import com.zzhoujay.richtext.spans.ClickableImageSpan;
11 | import com.zzhoujay.richtext.spans.LongClickableURLSpan;
12 |
13 | import java.lang.ref.SoftReference;
14 | import java.lang.ref.WeakReference;
15 | import java.util.HashSet;
16 | import java.util.WeakHashMap;
17 |
18 | /**
19 | * Created by zhou on 2017/3/25.
20 | * RichTextPool
21 | */
22 |
23 | @SuppressWarnings("WeakerAccess")
24 | class RichTextPool {
25 |
26 | private static final String TAG = "RichTextPool";
27 |
28 | private static final int MAX_RICH_TEXT_SIZE = 50;
29 |
30 | private final LruCache> richCache;
31 | private final WeakHashMap