initial markdown support

This commit is contained in:
f43nd1r 2019-04-04 04:34:25 +02:00
parent b664e89946
commit 6e0333b6da
4 changed files with 29 additions and 3 deletions

View file

@ -38,4 +38,6 @@ dependencies {
compile files('libs/dx.jar')
compile 'net.pierrox.android:lsvg:1.0'
compile project(':plugin-api')
implementation 'ru.noties.markwon:core:3.0.0'
implementation 'ru.noties.markwon:html:3.0.0'
}

View file

@ -1,7 +1,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
package="net.pierrox.lightning_launcher">
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-sdk tools:overrideLibrary="ru.noties.markwon.html, ru.noties.markwon.renderer"/>
</manifest>

View file

@ -27,6 +27,9 @@ import net.pierrox.lightning_launcher.views.MyAppWidgetHostView;
import net.pierrox.lightning_launcher.views.NativeImage;
import net.pierrox.lightning_launcher.views.SharedAsyncGraphicsDrawable;
import org.json.JSONObject;
import ru.noties.markwon.Markwon;
import ru.noties.markwon.core.CorePlugin;
import ru.noties.markwon.html.HtmlPlugin;
import java.io.File;
import java.util.ArrayList;
@ -69,6 +72,8 @@ public abstract class LLApp extends Application {
private ArrayList<Screen> mScreens = new ArrayList<>();
protected Screen mBackgroundScreen;
private Markwon mMarkdownParser;
@Override
public void onCreate() {
super.onCreate();
@ -135,6 +140,11 @@ public abstract class LLApp extends Application {
registerReceiver(mBroadcastReceiver, intent_filter);
mBackgroundScreen.runAction(mAppEngine, "STARTUP", mAppEngine.getGlobalConfig().startup);
mMarkdownParser = Markwon.builder(this)
.usePlugin(CorePlugin.create())
.usePlugin(HtmlPlugin.create())
.build();
}
@Override
@ -309,6 +319,10 @@ public abstract class LLApp extends Application {
return mLanguage;
}
public Markwon getMarkdownParser() {
return mMarkdownParser;
}
public abstract Intent getLockscreenServiceIntent();
public abstract Intent getWindowServiceIntent();

View file

@ -2,8 +2,10 @@ package net.pierrox.lightning_launcher.views;
import android.content.Context;
import android.graphics.Canvas;
import android.os.Build;
import android.text.Html;
import android.widget.TextView;
import net.pierrox.lightning_launcher.LLApp;
public class MyTextView extends TextView {
private int mFixWidth;
@ -43,7 +45,13 @@ public class MyTextView extends TextView {
@Override
public void setText(CharSequence text, BufferType type) {
CharSequence t;
if(type == BufferType.NORMAL && looksLikeHtml(text)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
if (text instanceof String) {
t = LLApp.get().getMarkdownParser().toMarkdown((String) text);
} else {
t = text;
}
} else if (type == BufferType.NORMAL && looksLikeHtml(text)) {
t = Html.fromHtml(text.toString());
if(t.length() == 0) {
t = text;