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
Hide 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
...
@@ -11,11 +11,8 @@ import android.graphics.drawable.ShapeDrawable
import
android.net.Uri
import
android.net.Uri
import
android.text.Spanned
import
android.text.Spanned
import
android.text.style.DynamicDrawableSpan
import
android.text.style.DynamicDrawableSpan
import
android.view.View
import
android.widget.TextView
import
android.widget.TextView
import
androidx.annotation.WorkerThread
import
androidx.annotation.WorkerThread
import
androidx.core.view.marginLeft
import
androidx.core.view.marginRight
import
com.caverock.androidsvg.SVG
import
com.caverock.androidsvg.SVG
import
com.caverock.androidsvg.SVGParseException
import
com.caverock.androidsvg.SVGParseException
import
com.topjohnwu.magisk.core.ResMgr
import
com.topjohnwu.magisk.core.ResMgr
...
@@ -25,8 +22,7 @@ import io.noties.markwon.image.*
...
@@ -25,8 +22,7 @@ import io.noties.markwon.image.*
import
io.noties.markwon.image.data.DataUriSchemeHandler
import
io.noties.markwon.image.data.DataUriSchemeHandler
import
io.noties.markwon.image.network.OkHttpNetworkSchemeHandler
import
io.noties.markwon.image.network.OkHttpNetworkSchemeHandler
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.async
import
kotlinx.coroutines.launch
import
kotlinx.coroutines.awaitAll
import
kotlinx.coroutines.runBlocking
import
kotlinx.coroutines.runBlocking
import
okhttp3.OkHttpClient
import
okhttp3.OkHttpClient
import
org.commonmark.node.Image
import
org.commonmark.node.Image
...
@@ -59,24 +55,17 @@ class MarkwonImagePlugin(okHttp: OkHttpClient) : AbstractMarkwonPlugin() {
...
@@ -59,24 +55,17 @@ class MarkwonImagePlugin(okHttp: OkHttpClient) : AbstractMarkwonPlugin() {
if
(
spans
==
null
||
spans
.
isEmpty
())
if
(
spans
==
null
||
spans
.
isEmpty
())
return
return
// Download and create all drawables in parallel
// 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
)
runBlocking
(
Dispatchers
.
IO
)
{
runBlocking
(
Dispatchers
.
IO
)
{
// Download and decode all drawables in parallel
// Download and decode all drawables in parallel
val
defers
=
spans
.
map
{
async
{
it
.
load
()
}
}
spans
.
forEach
{
launch
{
it
.
load
()
}
}
wr
.
waitUntilDone
()
// 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
spans
.
forEach
{
it
.
canvasWidth
=
width
}
})
// Make sure all is done before returning
defers
.
awaitAll
()
}
}
}
}
...
@@ -157,8 +146,8 @@ class MarkwonImagePlugin(okHttp: OkHttpClient) : AbstractMarkwonPlugin() {
...
@@ -157,8 +146,8 @@ class MarkwonImagePlugin(okHttp: OkHttpClient) : AbstractMarkwonPlugin() {
)
:
DynamicDrawableSpan
(
ALIGN_BOTTOM
)
{
)
:
DynamicDrawableSpan
(
ALIGN_BOTTOM
)
{
var
canvasWidth
=
0
var
canvasWidth
=
0
var
measured
=
false
private
var
measured
=
false
lateinit
var
draw
:
Drawable
private
lateinit
var
draw
:
Drawable
fun
load
()
{
fun
load
()
{
draw
=
loadDrawable
(
dest
)
?:
ShapeDrawable
()
draw
=
loadDrawable
(
dest
)
?:
ShapeDrawable
()
...
@@ -179,9 +168,7 @@ class MarkwonImagePlugin(okHttp: OkHttpClient) : AbstractMarkwonPlugin() {
...
@@ -179,9 +168,7 @@ class MarkwonImagePlugin(okHttp: OkHttpClient) : AbstractMarkwonPlugin() {
}
}
private
fun
measure
(
paint
:
Paint
)
{
private
fun
measure
(
paint
:
Paint
)
{
if
(
measured
)
if
(
measured
||
canvasWidth
==
0
)
return
if
(
canvasWidth
==
0
)
return
return
measured
=
true
measured
=
true
val
bound
=
SizeResolver
.
resolveImageSize
(
size
,
defaultBounds
(),
canvasWidth
,
paint
.
textSize
)
val
bound
=
SizeResolver
.
resolveImageSize
(
size
,
defaultBounds
(),
canvasWidth
,
paint
.
textSize
)
...
@@ -212,8 +199,7 @@ class MarkwonImagePlugin(okHttp: OkHttpClient) : AbstractMarkwonPlugin() {
...
@@ -212,8 +199,7 @@ class MarkwonImagePlugin(okHttp: OkHttpClient) : AbstractMarkwonPlugin() {
override
fun
supportedTypes
()
=
listOf
(
"image/svg+xml"
)
override
fun
supportedTypes
()
=
listOf
(
"image/svg+xml"
)
override
fun
decode
(
contentType
:
String
?,
inputStream
:
InputStream
):
Drawable
{
override
fun
decode
(
contentType
:
String
?,
inputStream
:
InputStream
):
Drawable
{
val
svg
:
SVG
val
svg
=
try
{
svg
=
try
{
SVG
.
getFromInputStream
(
inputStream
)
SVG
.
getFromInputStream
(
inputStream
)
}
catch
(
e
:
SVGParseException
)
{
}
catch
(
e
:
SVGParseException
)
{
throw
IllegalStateException
(
"Exception decoding SVG"
,
e
)
throw
IllegalStateException
(
"Exception decoding SVG"
,
e
)
...
@@ -222,7 +208,7 @@ class MarkwonImagePlugin(okHttp: OkHttpClient) : AbstractMarkwonPlugin() {
...
@@ -222,7 +208,7 @@ class MarkwonImagePlugin(okHttp: OkHttpClient) : AbstractMarkwonPlugin() {
val
w
=
svg
.
documentWidth
val
w
=
svg
.
documentWidth
val
h
=
svg
.
documentHeight
val
h
=
svg
.
documentHeight
if
(
w
==
0f
||
h
==
0f
)
{
if
(
w
<=
0
||
h
<=
0
)
{
val
picture
=
svg
.
renderToPicture
()
val
picture
=
svg
.
renderToPicture
()
return
PictureDrawable
(
picture
)
return
PictureDrawable
(
picture
)
}
}
...
...
app/src/main/java/com/topjohnwu/magisk/ktx/XAndroid.kt
View file @
3f053b85
...
@@ -388,7 +388,7 @@ var TextView.precomputedText: CharSequence
...
@@ -388,7 +388,7 @@ var TextView.precomputedText: CharSequence
coroutineScope
.
launch
(
Dispatchers
.
IO
)
{
coroutineScope
.
launch
(
Dispatchers
.
IO
)
{
if
(
SDK_INT
>=
29
)
{
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
// Due to some stupid crap OEM (Samsung) implementation, this can actually
// crash our app. Directly use platform APIs with some workarounds
// crash our app. Directly use platform APIs with some workarounds
val
pre
=
PrecomputedText
.
create
(
value
,
textMetricsParams
)
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 {
...
@@ -47,7 +47,7 @@ object MarkDownWindow : KoinComponent {
if
(
e
is
CancellationException
)
if
(
e
is
CancellationException
)
throw
e
throw
e
Timber
.
e
(
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