Added: Root automator, custom theme color, some helps
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
package com.stardust.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.RequiresApi;
|
||||
import android.util.AttributeSet;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
|
||||
import org.commonmark.node.Node;
|
||||
import org.commonmark.parser.Parser;
|
||||
import org.commonmark.renderer.html.HtmlRenderer;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/3/5.
|
||||
*/
|
||||
|
||||
public class CommonMarkdownView extends WebView {
|
||||
|
||||
private Parser mParser = Parser.builder().build();
|
||||
private HtmlRenderer mHtmlRender = HtmlRenderer.builder().build();
|
||||
|
||||
public CommonMarkdownView(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
public CommonMarkdownView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
public CommonMarkdownView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
setWebViewClient(new WebViewClient() {
|
||||
@Override
|
||||
public void onPageFinished(WebView view, String url) {
|
||||
loadUrl("javascript:document.body.style.margin=\"12%\"; void 0");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
public CommonMarkdownView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
}
|
||||
|
||||
public void loadMarkdown(String markdown) {
|
||||
String html = renderMarkdown(markdown);
|
||||
loadDataWithBaseURL(null, html, "text/html", "utf-8", null);
|
||||
}
|
||||
|
||||
private String renderMarkdown(String markdown) {
|
||||
Node document = mParser.parse(markdown);
|
||||
return mHtmlRender.render(document);
|
||||
}
|
||||
|
||||
public void setText(int resId) {
|
||||
setText(getContext().getString(resId));
|
||||
}
|
||||
|
||||
private void setText(String text) {
|
||||
loadDataWithBaseURL(null, text, "text/plain", "utf-8", null);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package com.stardust.widget;
|
||||
import android.content.Context;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.ThemeColorRecyclerView;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -16,7 +17,7 @@ import com.stardust.scriptdroid.R;
|
||||
* Created by Stardust on 2017/2/4.
|
||||
*/
|
||||
|
||||
public class ExpandableRecyclerView extends RecyclerView {
|
||||
public class ExpandableRecyclerView extends ThemeColorRecyclerView {
|
||||
|
||||
public void setOnChildClickListener(OnChildClickListener onChildClickListener) {
|
||||
mOnChildClickListener = onChildClickListener;
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
package com.stardust.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.RequiresApi;
|
||||
import android.text.Html;
|
||||
import android.text.Spanned;
|
||||
import android.text.method.ScrollingMovementMethod;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.zzhoujay.markdown.MarkDown;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/2/1.
|
||||
*/
|
||||
|
||||
public class MarkdownView extends TextView {
|
||||
public MarkdownView(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
public MarkdownView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
public MarkdownView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init();
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
public MarkdownView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
setMovementMethod(ScrollingMovementMethod.getInstance());
|
||||
setVerticalScrollBarEnabled(true);
|
||||
setTextIsSelectable(true);
|
||||
setClickable(true);
|
||||
}
|
||||
|
||||
public void loadMarkdown(final String text, final Html.ImageGetter imageGetter) {
|
||||
post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Spanned spanned = MarkDown.fromMarkdown(text, imageGetter, MarkdownView.this);
|
||||
setText(spanned);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void loadMarkdown(final String text) {
|
||||
loadMarkdown(text, null);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user