Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
Magisk
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Magisk
Commits
3f053b85
Commit
3f053b85
authored
Aug 14, 2020
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor code changes
parent
79aa261c
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
31 deletions
+17
-31
MarkwonImagePlugin.kt
...ava/com/topjohnwu/magisk/core/utils/MarkwonImagePlugin.kt
+15
-29
XAndroid.kt
app/src/main/java/com/topjohnwu/magisk/ktx/XAndroid.kt
+1
-1
MarkDownWindow.kt
...src/main/java/com/topjohnwu/magisk/view/MarkDownWindow.kt
+1
-1
No files found.
app/src/main/java/com/topjohnwu/magisk/core/utils/MarkwonImagePlugin.kt
View file @
3f053b85
...
...
@@ -11,11 +11,8 @@ import android.graphics.drawable.ShapeDrawable
import
android.net.Uri
import
android.text.Spanned
import
android.text.style.DynamicDrawableSpan
import
android.view.View
import
android.widget.TextView
import
androidx.annotation.WorkerThread
import
androidx.core.view.marginLeft
import
androidx.core.view.marginRight
import
com.caverock.androidsvg.SVG
import
com.caverock.androidsvg.SVGParseException
import
com.topjohnwu.magisk.core.ResMgr
...
...
@@ -25,8 +22,7 @@ import io.noties.markwon.image.*
import
io.noties.markwon.image.data.DataUriSchemeHandler
import
io.noties.markwon.image.network.OkHttpNetworkSchemeHandler
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.async
import
kotlinx.coroutines.awaitAll
import
kotlinx.coroutines.launch
import
kotlinx.coroutines.runBlocking
import
okhttp3.OkHttpClient
import
org.commonmark.node.Image
...
...
@@ -59,24 +55,17 @@ class MarkwonImagePlugin(okHttp: OkHttpClient) : AbstractMarkwonPlugin() {
if
(
spans
==
null
||
spans
.
isEmpty
())
return
// Download and create all drawables in parallel
runBlocking
(
Dispatchers
.
IO
)
{
// Download and decode all drawables in parallel
val
defers
=
spans
.
map
{
async
{
it
.
load
()
}
}
// Get TextView sizes beforehand to resize all images
// We get its parent here as the TextView itself might be hidden
val
parent
=
tv
.
parent
as
View
parent
.
post
(
WaitRunnable
{
// Make sure it is rendered
val
width
=
parent
.
width
-
tv
.
paddingLeft
-
tv
.
paddingRight
-
tv
.
marginLeft
-
tv
.
marginRight
// Get TextView sizes before setText() to resize all images
val
wr
=
WaitRunnable
{
val
width
=
tv
.
width
-
tv
.
paddingLeft
-
tv
.
paddingRight
spans
.
forEach
{
it
.
canvasWidth
=
width
}
})
}
tv
.
post
(
wr
)
// Make sure all is done before returning
defers
.
awaitAll
()
runBlocking
(
Dispatchers
.
IO
)
{
// Download and decode all drawables in parallel
spans
.
forEach
{
launch
{
it
.
load
()
}
}
wr
.
waitUntilDone
()
}
}
...
...
@@ -157,8 +146,8 @@ class MarkwonImagePlugin(okHttp: OkHttpClient) : AbstractMarkwonPlugin() {
)
:
DynamicDrawableSpan
(
ALIGN_BOTTOM
)
{
var
canvasWidth
=
0
var
measured
=
false
lateinit
var
draw
:
Drawable
private
var
measured
=
false
private
lateinit
var
draw
:
Drawable
fun
load
()
{
draw
=
loadDrawable
(
dest
)
?:
ShapeDrawable
()
...
...
@@ -179,9 +168,7 @@ class MarkwonImagePlugin(okHttp: OkHttpClient) : AbstractMarkwonPlugin() {
}
private
fun
measure
(
paint
:
Paint
)
{
if
(
measured
)
return
if
(
canvasWidth
==
0
)
if
(
measured
||
canvasWidth
==
0
)
return
measured
=
true
val
bound
=
SizeResolver
.
resolveImageSize
(
size
,
defaultBounds
(),
canvasWidth
,
paint
.
textSize
)
...
...
@@ -212,8 +199,7 @@ class MarkwonImagePlugin(okHttp: OkHttpClient) : AbstractMarkwonPlugin() {
override
fun
supportedTypes
()
=
listOf
(
"image/svg+xml"
)
override
fun
decode
(
contentType
:
String
?,
inputStream
:
InputStream
):
Drawable
{
val
svg
:
SVG
svg
=
try
{
val
svg
=
try
{
SVG
.
getFromInputStream
(
inputStream
)
}
catch
(
e
:
SVGParseException
)
{
throw
IllegalStateException
(
"Exception decoding SVG"
,
e
)
...
...
@@ -222,7 +208,7 @@ class MarkwonImagePlugin(okHttp: OkHttpClient) : AbstractMarkwonPlugin() {
val
w
=
svg
.
documentWidth
val
h
=
svg
.
documentHeight
if
(
w
==
0f
||
h
==
0f
)
{
if
(
w
<=
0
||
h
<=
0
)
{
val
picture
=
svg
.
renderToPicture
()
return
PictureDrawable
(
picture
)
}
...
...
app/src/main/java/com/topjohnwu/magisk/ktx/XAndroid.kt
View file @
3f053b85
...
...
@@ -388,7 +388,7 @@ var TextView.precomputedText: CharSequence
coroutineScope
.
launch
(
Dispatchers
.
IO
)
{
if
(
SDK_INT
>=
29
)
{
// Internally PrecomputedTextCompat will platform API on API 29+
// Internally PrecomputedTextCompat will
use
platform API on API 29+
// Due to some stupid crap OEM (Samsung) implementation, this can actually
// crash our app. Directly use platform APIs with some workarounds
val
pre
=
PrecomputedText
.
create
(
value
,
textMetricsParams
)
...
...
app/src/main/java/com/topjohnwu/magisk/view/MarkDownWindow.kt
View file @
3f053b85
...
...
@@ -47,7 +47,7 @@ object MarkDownWindow : KoinComponent {
if
(
e
is
CancellationException
)
throw
e
Timber
.
e
(
e
)
tv
.
setText
(
R
.
string
.
download_file_error
)
tv
.
post
{
tv
.
setText
(
R
.
string
.
download_file_error
)
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment