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
036b5acf
Commit
036b5acf
authored
Apr 03, 2019
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update Markwon to 3.0.0
parent
056dafc5
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
60 deletions
+19
-60
build.gradle
app/build.gradle
+5
-2
MarkDownWindow.java
...ava/com/topjohnwu/magisk/uicomponents/MarkDownWindow.java
+14
-58
No files found.
app/build.gradle
View file @
036b5acf
...
@@ -25,12 +25,15 @@ dependencies {
...
@@ -25,12 +25,15 @@ dependencies {
implementation
project
(
':net'
)
implementation
project
(
':net'
)
implementation
project
(
':shared'
)
implementation
project
(
':shared'
)
implementation
project
(
':signing'
)
implementation
project
(
':signing'
)
implementation
'ru.noties:markwon:2.0.1'
implementation
'com.caverock:androidsvg-aar:1.3'
implementation
'com.github.topjohnwu:jtar:1.0.0'
implementation
'com.github.topjohnwu:jtar:1.0.0'
implementation
'net.sourceforge.streamsupport:android-retrostreams:1.7.0'
implementation
'net.sourceforge.streamsupport:android-retrostreams:1.7.0'
implementation
'com.github.sevar83:indeterminate-checkbox:1.0.5'
implementation
'com.github.sevar83:indeterminate-checkbox:1.0.5'
def
markwonVersion
=
'3.0.0'
implementation
"ru.noties.markwon:core:${markwonVersion}"
implementation
"ru.noties.markwon:html:${markwonVersion}"
implementation
"ru.noties.markwon:image-svg:${markwonVersion}"
def
androidXVersion
=
"1.0.0"
def
androidXVersion
=
"1.0.0"
implementation
'androidx.constraintlayout:constraintlayout:1.1.3'
implementation
'androidx.constraintlayout:constraintlayout:1.1.3'
implementation
'androidx.appcompat:appcompat:1.0.2'
implementation
'androidx.appcompat:appcompat:1.0.2'
...
...
app/src/main/java/com/topjohnwu/magisk/uicomponents/MarkDownWindow.java
View file @
036b5acf
package
com
.
topjohnwu
.
magisk
.
uicomponents
;
package
com
.
topjohnwu
.
magisk
.
uicomponents
;
import
android.app.Activity
;
import
android.app.Activity
;
import
android.graphics.Bitmap
;
import
android.graphics.Canvas
;
import
android.graphics.drawable.BitmapDrawable
;
import
android.graphics.drawable.Drawable
;
import
android.view.LayoutInflater
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.View
;
import
androidx.annotation.NonNull
;
import
androidx.appcompat.app.AlertDialog
;
import
androidx.appcompat.app.AlertDialog
;
import
com.caverock.androidsvg.SVG
;
import
com.topjohnwu.magisk.App
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.net.Networking
;
import
com.topjohnwu.net.Networking
;
import
com.topjohnwu.net.ResponseListener
;
import
com.topjohnwu.net.ResponseListener
;
import
com.topjohnwu.signing.ByteArrayStream
;
import
com.topjohnwu.superuser.ShellUtils
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.util.
concurrent.Callable
;
import
java.util.
Scanner
;
import
ru.noties.markwon.Markwon
;
import
ru.noties.markwon.Markwon
;
import
ru.noties.markwon.SpannableConfiguration
;
import
ru.noties.markwon.html.HtmlPlugin
;
import
ru.noties.markwon.spans.AsyncDrawable
;
import
ru.noties.markwon.image.ImagesPlugin
;
import
ru.noties.markwon.image.svg.SvgPlugin
;
public
class
MarkDownWindow
{
public
class
MarkDownWindow
{
private
static
final
SpannableConfiguration
config
=
SpannableConfiguration
.
builder
(
App
.
self
)
.
asyncDrawableLoader
(
new
Loader
()).
build
();
public
static
void
show
(
Activity
activity
,
String
title
,
String
url
)
{
public
static
void
show
(
Activity
activity
,
String
title
,
String
url
)
{
Networking
.
get
(
url
).
getAsString
(
new
Listener
(
activity
,
title
));
Networking
.
get
(
url
).
getAsString
(
new
Listener
(
activity
,
title
));
}
}
public
static
void
show
(
Activity
activity
,
String
title
,
InputStream
is
)
{
public
static
void
show
(
Activity
activity
,
String
title
,
InputStream
is
)
{
try
{
try
(
Scanner
s
=
new
Scanner
(
is
,
"UTF-8"
))
{
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
();
s
.
useDelimiter
(
"\\A"
);
ShellUtils
.
pump
(
is
,
baos
);
new
Listener
(
activity
,
title
).
onResponse
(
s
.
next
());
new
Listener
(
activity
,
title
).
onResponse
(
baos
.
toString
());
}
}
catch
(
IOException
ignored
)
{}
}
}
static
class
Listener
implements
ResponseListener
<
String
>
{
static
class
Listener
implements
ResponseListener
<
String
>
{
...
@@ -58,47 +43,18 @@ public class MarkDownWindow {
...
@@ -58,47 +43,18 @@ public class MarkDownWindow {
@Override
@Override
public
void
onResponse
(
String
md
)
{
public
void
onResponse
(
String
md
)
{
Markwon
markwon
=
Markwon
.
builder
(
activity
)
.
usePlugin
(
HtmlPlugin
.
create
())
.
usePlugin
(
ImagesPlugin
.
create
(
activity
))
.
usePlugin
(
SvgPlugin
.
create
(
activity
.
getResources
()))
.
build
();
AlertDialog
.
Builder
alert
=
new
AlertDialog
.
Builder
(
activity
);
AlertDialog
.
Builder
alert
=
new
AlertDialog
.
Builder
(
activity
);
alert
.
setTitle
(
title
);
alert
.
setTitle
(
title
);
View
mv
=
LayoutInflater
.
from
(
activity
).
inflate
(
R
.
layout
.
markdown_window
,
null
);
View
mv
=
LayoutInflater
.
from
(
activity
).
inflate
(
R
.
layout
.
markdown_window
,
null
);
Markwon
.
setMarkdown
(
mv
.
findViewById
(
R
.
id
.
md_txt
),
config
,
md
);
markwon
.
setMarkdown
(
mv
.
findViewById
(
R
.
id
.
md_txt
)
,
md
);
alert
.
setView
(
mv
);
alert
.
setView
(
mv
);
alert
.
setNegativeButton
(
R
.
string
.
close
,
(
dialog
,
id
)
->
dialog
.
dismiss
());
alert
.
setNegativeButton
(
R
.
string
.
close
,
(
dialog
,
id
)
->
dialog
.
dismiss
());
alert
.
show
();
alert
.
show
();
}
}
}
}
static
class
Loader
implements
AsyncDrawable
.
Loader
{
@Override
public
void
load
(
@NonNull
String
url
,
@NonNull
AsyncDrawable
asyncDrawable
)
{
App
.
THREAD_POOL
.
submit
((
Callable
<?>)
()
->
{
InputStream
is
=
Networking
.
get
(
url
).
execForInputStream
().
getResult
();
if
(
is
==
null
)
return
null
;
ByteArrayStream
buf
=
new
ByteArrayStream
();
buf
.
readFrom
(
is
);
// First try default drawables
Drawable
drawable
=
Drawable
.
createFromStream
(
buf
.
getInputStream
(),
""
);
if
(
drawable
==
null
)
{
// SVG
SVG
svg
=
SVG
.
getFromInputStream
(
buf
.
getInputStream
());
int
width
=
Utils
.
dpInPx
((
int
)
svg
.
getDocumentWidth
());
int
height
=
Utils
.
dpInPx
((
int
)
svg
.
getDocumentHeight
());
final
Bitmap
bitmap
=
Bitmap
.
createBitmap
(
width
,
height
,
Bitmap
.
Config
.
ARGB_4444
);
final
Canvas
canvas
=
new
Canvas
(
bitmap
);
float
density
=
App
.
self
.
getResources
().
getDisplayMetrics
().
density
;
canvas
.
scale
(
density
,
density
);
svg
.
renderToCanvas
(
canvas
);
drawable
=
new
BitmapDrawable
(
App
.
self
.
getResources
(),
bitmap
);
}
drawable
.
setBounds
(
0
,
0
,
drawable
.
getIntrinsicWidth
(),
drawable
.
getIntrinsicHeight
());
asyncDrawable
.
setResult
(
drawable
);
return
null
;
});
}
@Override
public
void
cancel
(
@NonNull
String
url
)
{}
}
}
}
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