Added some code to allow inverted and grayscale modes in WebView
This commit is contained in:
parent
e5fd921965
commit
f5de4626ef
@ -10,6 +10,9 @@ import android.app.AlertDialog;
|
||||
import android.content.*;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.ColorMatrix;
|
||||
import android.graphics.ColorMatrixColorFilter;
|
||||
import android.graphics.Paint;
|
||||
import android.net.MailTo;
|
||||
import android.net.Uri;
|
||||
import android.net.http.SslError;
|
||||
@ -35,34 +38,26 @@ import java.net.*;
|
||||
public class LightningView {
|
||||
|
||||
private Title mTitle;
|
||||
|
||||
private WebView mWebView;
|
||||
|
||||
private BrowserController mBrowserController;
|
||||
|
||||
private GestureDetector mGestureDetector;
|
||||
|
||||
private Activity mActivity;
|
||||
|
||||
private WebSettings mSettings;
|
||||
|
||||
private static int API = android.os.Build.VERSION.SDK_INT;
|
||||
|
||||
private static String mHomepage;
|
||||
|
||||
private static String mDefaultUserAgent;
|
||||
|
||||
private static Bitmap mWebpageBitmap;
|
||||
|
||||
private static SharedPreferences mPreferences;
|
||||
|
||||
private static boolean mWideViewPort;
|
||||
|
||||
private AdBlock mAdBlock;
|
||||
|
||||
private boolean isForegroundTab;
|
||||
|
||||
private IntentUtils mIntentUtils;
|
||||
private Paint mPaint = new Paint();
|
||||
private static final float[] mNegativeColorArray = { -1.0f, 0, 0, 0, 255, // red
|
||||
0, -1.0f, 0, 0, 255, // green
|
||||
0, 0, -1.0f, 0, 255, // blue
|
||||
0, 0, 0, 1.0f, 0 // alpha
|
||||
};
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@SuppressLint("NewApi")
|
||||
@ -88,6 +83,8 @@ public class LightningView {
|
||||
mWebView.setAnimationCacheEnabled(false);
|
||||
mWebView.setDrawingCacheEnabled(true);
|
||||
mWebView.setBackgroundColor(activity.getResources().getColor(android.R.color.white));
|
||||
mWebView.setBackground(null);
|
||||
|
||||
if (API > 15) {
|
||||
mWebView.getRootView().setBackground(null);
|
||||
} else {
|
||||
@ -358,6 +355,7 @@ public class LightningView {
|
||||
@SuppressWarnings("deprecation")
|
||||
@SuppressLint({ "SetJavaScriptEnabled", "NewApi" })
|
||||
public void initializeSettings(WebSettings settings, Context context) {
|
||||
this.setNormalRendering();
|
||||
if (API < 18) {
|
||||
settings.setAppCacheMaxSize(Long.MAX_VALUE);
|
||||
}
|
||||
@ -427,6 +425,33 @@ public class LightningView {
|
||||
}
|
||||
}
|
||||
|
||||
public void setHardwareRendering() {
|
||||
mWebView.setLayerType(View.LAYER_TYPE_HARDWARE, mPaint);
|
||||
}
|
||||
|
||||
public void setNormalRendering() {
|
||||
mWebView.setLayerType(View.LAYER_TYPE_NONE, mPaint);
|
||||
}
|
||||
|
||||
public void setColorMode(int mode) {
|
||||
switch (mode) {
|
||||
case 0:
|
||||
mPaint.setColorFilter(null);
|
||||
break;
|
||||
case 1:
|
||||
ColorMatrixColorFilter filterInvert = new ColorMatrixColorFilter(
|
||||
mNegativeColorArray);
|
||||
mPaint.setColorFilter(filterInvert);
|
||||
break;
|
||||
case 2:
|
||||
ColorMatrix cm = new ColorMatrix();
|
||||
cm.setSaturation(0);
|
||||
ColorMatrixColorFilter filterGray = new ColorMatrixColorFilter(cm);
|
||||
mPaint.setColorFilter(filterGray);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void pauseTimers() {
|
||||
if (mWebView != null) {
|
||||
mWebView.pauseTimers();
|
||||
|
Loading…
x
Reference in New Issue
Block a user