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;
import android.content.*; import android.content.*;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint;
import android.net.MailTo; import android.net.MailTo;
import android.net.Uri; import android.net.Uri;
import android.net.http.SslError; import android.net.http.SslError;
@ -35,34 +38,26 @@ import java.net.*;
public class LightningView { public class LightningView {
private Title mTitle; private Title mTitle;
private WebView mWebView; private WebView mWebView;
private BrowserController mBrowserController; private BrowserController mBrowserController;
private GestureDetector mGestureDetector; private GestureDetector mGestureDetector;
private Activity mActivity; private Activity mActivity;
private WebSettings mSettings; private WebSettings mSettings;
private static int API = android.os.Build.VERSION.SDK_INT; private static int API = android.os.Build.VERSION.SDK_INT;
private static String mHomepage; private static String mHomepage;
private static String mDefaultUserAgent; private static String mDefaultUserAgent;
private static Bitmap mWebpageBitmap; private static Bitmap mWebpageBitmap;
private static SharedPreferences mPreferences; private static SharedPreferences mPreferences;
private static boolean mWideViewPort; private static boolean mWideViewPort;
private AdBlock mAdBlock; private AdBlock mAdBlock;
private boolean isForegroundTab; private boolean isForegroundTab;
private IntentUtils mIntentUtils; 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") @SuppressWarnings("deprecation")
@SuppressLint("NewApi") @SuppressLint("NewApi")
@ -88,6 +83,8 @@ public class LightningView {
mWebView.setAnimationCacheEnabled(false); mWebView.setAnimationCacheEnabled(false);
mWebView.setDrawingCacheEnabled(true); mWebView.setDrawingCacheEnabled(true);
mWebView.setBackgroundColor(activity.getResources().getColor(android.R.color.white)); mWebView.setBackgroundColor(activity.getResources().getColor(android.R.color.white));
mWebView.setBackground(null);
if (API > 15) { if (API > 15) {
mWebView.getRootView().setBackground(null); mWebView.getRootView().setBackground(null);
} else { } else {
@ -142,7 +139,7 @@ public class LightningView {
if (!url.trim().isEmpty()) { if (!url.trim().isEmpty()) {
mWebView.loadUrl(url); mWebView.loadUrl(url);
} else { } 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 { } else {
if (mHomepage.startsWith("about:home")) { if (mHomepage.startsWith("about:home")) {
@ -358,6 +355,7 @@ public class LightningView {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@SuppressLint({ "SetJavaScriptEnabled", "NewApi" }) @SuppressLint({ "SetJavaScriptEnabled", "NewApi" })
public void initializeSettings(WebSettings settings, Context context) { public void initializeSettings(WebSettings settings, Context context) {
this.setNormalRendering();
if (API < 18) { if (API < 18) {
settings.setAppCacheMaxSize(Long.MAX_VALUE); 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() { public synchronized void pauseTimers() {
if (mWebView != null) { if (mWebView != null) {
mWebView.pauseTimers(); mWebView.pauseTimers();

Loading…
Cancel
Save