Browse Source

Added some code to allow inverted and grayscale modes in WebView

master
Anthony Restaino 11 years ago
parent
commit
f5de4626ef
  1. 55
      src/acr/browser/lightning/LightningView.java

55
src/acr/browser/lightning/LightningView.java

@ -10,6 +10,9 @@ import android.app.AlertDialog; @@ -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.*; @@ -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 { @@ -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 {
@ -142,7 +139,7 @@ public class LightningView { @@ -142,7 +139,7 @@ public class LightningView {
if (!url.trim().isEmpty()) {
mWebView.loadUrl(url);
} else {
//don't load anything, the user is looking for a blank tab
// don't load anything, the user is looking for a blank tab
}
} else {
if (mHomepage.startsWith("about:home")) {
@ -358,6 +355,7 @@ public class LightningView { @@ -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 { @@ -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…
Cancel
Save