Browse Source

Update project for new API 22, remove another layer of overdraw on the WebView

master
Anthony Restaino 10 years ago
parent
commit
450ba6b0fd
  1. 2
      project.properties
  2. 22
      src/acr/browser/lightning/BrowserActivity.java
  3. 132
      src/acr/browser/lightning/LightningView.java

2
project.properties

@ -11,7 +11,7 @@
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# Project target. # Project target.
target=android-21 target=android-22
android.library.reference.1=external/appcompat android.library.reference.1=external/appcompat
android.library.reference.2=external/palette android.library.reference.2=external/palette
android.library.reference.3=external/netcipher/libnetcipher android.library.reference.3=external/netcipher/libnetcipher

22
src/acr/browser/lightning/BrowserActivity.java

@ -12,6 +12,7 @@ import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.*; import android.content.*;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.content.res.Resources.Theme;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteException;
import android.graphics.Bitmap; import android.graphics.Bitmap;
@ -95,6 +96,7 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
private ValueCallback<Uri> mUploadMessage; private ValueCallback<Uri> mUploadMessage;
private View mCustomView; private View mCustomView;
private int mOriginalOrientation; private int mOriginalOrientation;
private int mBackgroundColor;
private ActionBar mActionBar; private ActionBar mActionBar;
private boolean mFullScreen; private boolean mFullScreen;
private boolean mColorMode; private boolean mColorMode;
@ -276,11 +278,20 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
// create the search EditText in the ToolBar // create the search EditText in the ToolBar
mSearch = (AutoCompleteTextView) mActionBar.getCustomView().findViewById(R.id.search); mSearch = (AutoCompleteTextView) mActionBar.getCustomView().findViewById(R.id.search);
mUntitledTitle = (String) this.getString(R.string.untitled); mUntitledTitle = (String) this.getString(R.string.untitled);
mDeleteIcon = getResources().getDrawable(R.drawable.ic_action_delete); mBackgroundColor = getResources().getColor(R.color.primary_color);
Theme theme = getTheme();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
mDeleteIcon = getResources().getDrawable(R.drawable.ic_action_delete);
mRefreshIcon = getResources().getDrawable(R.drawable.ic_action_refresh);
mCopyIcon = getResources().getDrawable(R.drawable.ic_action_copy);
} else {
mDeleteIcon = getResources().getDrawable(R.drawable.ic_action_delete, theme);
mRefreshIcon = getResources().getDrawable(R.drawable.ic_action_refresh, theme);
mCopyIcon = getResources().getDrawable(R.drawable.ic_action_copy, theme);
}
mDeleteIcon.setBounds(0, 0, Utils.convertDpToPixels(24), Utils.convertDpToPixels(24)); mDeleteIcon.setBounds(0, 0, Utils.convertDpToPixels(24), Utils.convertDpToPixels(24));
mRefreshIcon = getResources().getDrawable(R.drawable.ic_action_refresh);
mRefreshIcon.setBounds(0, 0, Utils.convertDpToPixels(24), Utils.convertDpToPixels(24)); mRefreshIcon.setBounds(0, 0, Utils.convertDpToPixels(24), Utils.convertDpToPixels(24));
mCopyIcon = getResources().getDrawable(R.drawable.ic_action_copy);
mCopyIcon.setBounds(0, 0, Utils.convertDpToPixels(24), Utils.convertDpToPixels(24)); mCopyIcon.setBounds(0, 0, Utils.convertDpToPixels(24), Utils.convertDpToPixels(24));
mIcon = mRefreshIcon; mIcon = mRefreshIcon;
SearchClass search = new SearchClass(); SearchClass search = new SearchClass();
@ -1175,6 +1186,8 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
* the LightningView to show * the LightningView to show
*/ */
private synchronized void showTab(LightningView view) { private synchronized void showTab(LightningView view) {
// Set the background color so the color mode color doesn't show through
mBrowserFrame.setBackgroundColor(mBackgroundColor);
if (view == null) { if (view == null) {
return; return;
} }
@ -1194,6 +1207,8 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
} }
mBrowserFrame.addView(mCurrentView.getWebView(), mMatchParent); mBrowserFrame.addView(mCurrentView.getWebView(), mMatchParent);
// Remove browser frame background to reduce overdraw
mBrowserFrame.setBackgroundColor(0);
mCurrentView.requestFocus(); mCurrentView.requestFocus();
mCurrentView.onResume(); mCurrentView.onResume();
@ -1375,6 +1390,7 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
} }
private void closeBrowser() { private void closeBrowser() {
mBrowserFrame.setBackgroundColor(mBackgroundColor);
if (mPreferences.getBoolean(PreferenceConstants.CLEAR_CACHE_EXIT, false) if (mPreferences.getBoolean(PreferenceConstants.CLEAR_CACHE_EXIT, false)
&& mCurrentView != null && !isIncognito()) { && mCurrentView != null && !isIncognito()) {
mCurrentView.clearCache(true); mCurrentView.clearCache(true);

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

@ -4,10 +4,22 @@
package acr.browser.lightning; package acr.browser.lightning;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.net.URISyntaxException;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.*; import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.ColorMatrix; import android.graphics.ColorMatrix;
@ -26,16 +38,21 @@ import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.View.OnTouchListener; import android.view.View.OnTouchListener;
import android.webkit.*;
import android.webkit.CookieManager; import android.webkit.CookieManager;
import android.webkit.GeolocationPermissions;
import android.webkit.HttpAuthHandler;
import android.webkit.SslErrorHandler;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
import android.webkit.WebSettings;
import android.webkit.WebSettings.LayoutAlgorithm; import android.webkit.WebSettings.LayoutAlgorithm;
import android.webkit.WebSettings.PluginState; import android.webkit.WebSettings.PluginState;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.EditText; import android.widget.EditText;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import org.apache.http.util.ByteArrayBuffer;
import java.io.*;
import java.net.*;
public class LightningView { public class LightningView {
@ -648,108 +665,7 @@ public class LightningView {
ByteArrayInputStream EMPTY = new ByteArrayInputStream("".getBytes()); ByteArrayInputStream EMPTY = new ByteArrayInputStream("".getBytes());
return new WebResourceResponse("text/plain", "utf-8", EMPTY); return new WebResourceResponse("text/plain", "utf-8", EMPTY);
} }
return null;
boolean useProxy = mPreferences.getBoolean(PreferenceConstants.USE_PROXY, false);
boolean mDoLeakHardening = false;
if (!useProxy) {
return null;
}
if (!mDoLeakHardening) {
return null;
}
// now we are going to proxy!
try {
URL uURl = new URL(url);
Proxy proxy = null;
String host = mPreferences.getString(PreferenceConstants.USE_PROXY_HOST,
"localhost");
int port = mPreferences.getInt(PreferenceConstants.USE_PROXY_PORT, 8118);
proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(host, port));
HttpURLConnection.setFollowRedirects(true);
HttpURLConnection conn = (HttpURLConnection) uURl.openConnection(proxy);
conn.setInstanceFollowRedirects(true);
conn.setRequestProperty("User-Agent", mSettings.getUserAgentString());
// conn.setRequestProperty("Transfer-Encoding", "chunked");
// conn.setUseCaches(false);
final int bufferSize = 1024 * 32;
conn.setChunkedStreamingMode(bufferSize);
String cType = conn.getContentType();
String cEnc = conn.getContentEncoding();
int connLen = conn.getContentLength();
if (cType != null) {
String[] ctArray = cType.split(";");
cType = ctArray[0].trim();
if (cEnc == null && ctArray.length > 1) {
cEnc = ctArray[1];
if (cEnc.indexOf('=') != -1) {
cEnc = cEnc.split("=")[1].trim();
}
}
}
if (connLen <= 0) {
connLen = 2048;
}
if (cType != null && cType.startsWith("text")) {
InputStream fStream;
BufferedInputStream bis = new BufferedInputStream(conn.getInputStream());
ByteArrayBuffer baf = new ByteArrayBuffer(connLen);
int read;
int bufSize = 2048;
byte[] buffer = new byte[bufSize];
while (true) {
read = bis.read(buffer);
if (read == -1) {
break;
}
baf.append(buffer, 0, read);
}
byte[] plainText = baf.toByteArray();
fStream = new ByteArrayInputStream(plainText);
fStream = new ReplacingInputStream(new ByteArrayInputStream(plainText),
"poster=".getBytes(), "foo=".getBytes());
fStream = new ReplacingInputStream(fStream, "Poster=".getBytes(),
"foo=".getBytes());
fStream = new ReplacingInputStream(fStream, "Poster=".getBytes(),
"foo=".getBytes());
fStream = new ReplacingInputStream(fStream, ".poster".getBytes(),
".foo".getBytes());
fStream = new ReplacingInputStream(fStream, "\"poster\"".getBytes(),
"\"foo\"".getBytes());
return new WebResourceResponse(cType, cEnc, fStream);
}/**
* else if (mDoLeakHardening) { WebResourceResponse response =
* new WebResourceResponse( cType, cEnc, conn.getInputStream());
*
* return response;
*
* }
*/
else {
return null; // let webkit handle it
}
} catch (Exception e) {
Log.e(Constants.TAG, "Error filtering stream", e);
ByteArrayInputStream EMPTY = new ByteArrayInputStream("".getBytes());
return new WebResourceResponse("text/plain", "utf-8", EMPTY);
}
} }
@Override @Override

Loading…
Cancel
Save