|
|
@ -9,17 +9,13 @@ import android.os.Handler;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.view.Gravity;
|
|
|
|
import android.view.Gravity;
|
|
|
|
import android.view.MotionEvent;
|
|
|
|
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewConfiguration;
|
|
|
|
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.webkit.WebSettings;
|
|
|
|
import android.webkit.WebSettings;
|
|
|
|
import android.webkit.WebView;
|
|
|
|
import android.webkit.WebView;
|
|
|
|
import android.webkit.WebViewClient;
|
|
|
|
import android.webkit.WebViewClient;
|
|
|
|
import android.widget.FrameLayout;
|
|
|
|
import android.widget.FrameLayout;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Containerview for an WebView which renders LaTex using MathJax
|
|
|
|
* Containerview for an WebView which renders LaTex using MathJax
|
|
|
@ -88,20 +84,26 @@ public class MathJaxView extends FrameLayout {
|
|
|
|
this.onMathJaxRenderListener = onMathJaxRenderListener;
|
|
|
|
this.onMathJaxRenderListener = onMathJaxRenderListener;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setTextColor(String color) {
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
|
|
|
|
|
|
|
mWebView.evaluateJavascript("document.body.style.color=\"" + color + "\";", null);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressLint({"SetJavaScriptEnabled", "AddJavascriptInterface"})
|
|
|
|
@SuppressLint({"SetJavaScriptEnabled", "AddJavascriptInterface"})
|
|
|
|
private void init(Context context, AttributeSet attrSet, MathJaxConfig config) {
|
|
|
|
private void init(Context context, AttributeSet attrSet, MathJaxConfig config) {
|
|
|
|
mWebView = new WebView(context);
|
|
|
|
mWebView = new WebView(context);
|
|
|
|
|
|
|
|
|
|
|
|
int gravity = Gravity.START;
|
|
|
|
int gravity = Gravity.START;
|
|
|
|
boolean verticalScrollbarsEnabled = false;
|
|
|
|
boolean verticalScrollbarsEnabled = false;
|
|
|
|
boolean horizontalScrollbarsEnabled = true;
|
|
|
|
boolean horizontalScrollbarsEnabled = false;
|
|
|
|
String textColor = config != null ? config.getTextColor() : null;
|
|
|
|
String textColor = config != null ? config.getTextColor() : null;
|
|
|
|
|
|
|
|
|
|
|
|
if (attrSet != null) {
|
|
|
|
if (attrSet != null) {
|
|
|
|
TypedArray attrs = context.obtainStyledAttributes(attrSet, R.styleable.MathJaxView);
|
|
|
|
TypedArray attrs = context.obtainStyledAttributes(attrSet, R.styleable.MathJaxView);
|
|
|
|
gravity = attrs.getInteger(R.styleable.MathJaxView_android_gravity, Gravity.START);
|
|
|
|
gravity = attrs.getInteger(R.styleable.MathJaxView_android_gravity, Gravity.START);
|
|
|
|
verticalScrollbarsEnabled = attrs.getBoolean(R.styleable.MathJaxView_verticalScrollbarsEnabled, false);
|
|
|
|
verticalScrollbarsEnabled = attrs.getBoolean(R.styleable.MathJaxView_verticalScrollbarsEnabled, false);
|
|
|
|
horizontalScrollbarsEnabled = attrs.getBoolean(R.styleable.MathJaxView_horizontalScrollbarsEnabled, true);
|
|
|
|
horizontalScrollbarsEnabled = attrs.getBoolean(R.styleable.MathJaxView_horizontalScrollbarsEnabled, false);
|
|
|
|
textColor = attrs.getString(R.styleable.MathJaxView_textColor);
|
|
|
|
textColor = attrs.getString(R.styleable.MathJaxView_textColor);
|
|
|
|
config = new MathJaxConfig(attrs);
|
|
|
|
config = new MathJaxConfig(attrs);
|
|
|
|
attrs.recycle();
|
|
|
|
attrs.recycle();
|
|
|
@ -153,31 +155,6 @@ public class MathJaxView extends FrameLayout {
|
|
|
|
mWebView.setHorizontalScrollBarEnabled(horizontalScrollbarsEnabled);
|
|
|
|
mWebView.setHorizontalScrollBarEnabled(horizontalScrollbarsEnabled);
|
|
|
|
mWebView.setBackgroundColor(0);
|
|
|
|
mWebView.setBackgroundColor(0);
|
|
|
|
mWebView.getSettings().setLoadWithOverviewMode(true);
|
|
|
|
mWebView.getSettings().setLoadWithOverviewMode(true);
|
|
|
|
float touchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
|
|
|
|
|
|
|
|
final boolean[] scrollFlag = {true};
|
|
|
|
|
|
|
|
AtomicReference<Float> downX = new AtomicReference<>((float) 0);
|
|
|
|
|
|
|
|
AtomicReference<Float> downY = new AtomicReference<>((float) 0);
|
|
|
|
|
|
|
|
mWebView.setOnTouchListener((View v, MotionEvent event) -> {
|
|
|
|
|
|
|
|
if (!scrollFlag[0] && event.getY() < getHeight() / 2) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (event.getAction()) {
|
|
|
|
|
|
|
|
case MotionEvent.ACTION_DOWN:
|
|
|
|
|
|
|
|
downX.set(event.getX());
|
|
|
|
|
|
|
|
downY.set(event.getY());
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MotionEvent.ACTION_MOVE:
|
|
|
|
|
|
|
|
if (Math.abs(event.getY() - downY.get()) < touchSlop && Math.abs(event.getX() - downX.get()) > touchSlop) {
|
|
|
|
|
|
|
|
getParent().requestDisallowInterceptTouchEvent(true);
|
|
|
|
|
|
|
|
scrollFlag[0] = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event.getAction() == MotionEvent.ACTION_UP)
|
|
|
|
|
|
|
|
scrollFlag[0] = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|