Browse Source

Added new layout algorithm option and formatted code

master
Anthony Restaino 10 years ago
parent
commit
25818dd8e9
  1. 204
      src/acr/browser/lightning/LightningView.java

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

@ -67,8 +67,7 @@ public class LightningView { @@ -67,8 +67,7 @@ public class LightningView {
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
public LightningView(Activity activity, String url,
CookieManager cookieManager) {
public LightningView(Activity activity, String url, CookieManager cookieManager) {
mActivity = activity;
mWebView = new WebView(activity);
@ -81,8 +80,7 @@ public class LightningView { @@ -81,8 +80,7 @@ public class LightningView {
try {
mBrowserController = (BrowserController) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity
+ " must implement BrowserController");
throw new ClassCastException(activity + " must implement BrowserController");
}
mIntentUtils = new IntentUtils(mBrowserController);
mWebView.setDrawingCacheBackgroundColor(0x00000000);
@ -90,8 +88,7 @@ public class LightningView { @@ -90,8 +88,7 @@ public class LightningView {
mWebView.setFocusable(true);
mWebView.setAnimationCacheEnabled(false);
mWebView.setDrawingCacheEnabled(true);
mWebView.setBackgroundColor(activity.getResources().getColor(
android.R.color.white));
mWebView.setBackgroundColor(activity.getResources().getColor(android.R.color.white));
if (API > 15) {
mWebView.getRootView().setBackground(null);
} else {
@ -105,8 +102,7 @@ public class LightningView { @@ -105,8 +102,7 @@ public class LightningView {
mWebView.setWebChromeClient(new LightningChromeClient(activity));
mWebView.setWebViewClient(new LightningWebClient(activity));
mWebView.setDownloadListener(new LightningDownloadListener(activity));
mGestureDetector = new GestureDetector(activity,
new CustomGestureListener());
mGestureDetector = new GestureDetector(activity, new CustomGestureListener());
mWebView.setOnTouchListener(new OnTouchListener() {
float mLocation;
@ -115,6 +111,7 @@ public class LightningView { @@ -115,6 +111,7 @@ public class LightningView {
int mAction;
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouch(View view, MotionEvent arg1) {
if (view != null && !view.hasFocus()) {
@ -213,14 +210,16 @@ public class LightningView { @@ -213,14 +210,16 @@ public class LightningView {
case 7:
// DUCK_SEARCH;
home = home + "file:///android_asset/duckduckgo.png";
// + "https://duckduckgo.com/assets/logo_homepage.normal.v101.png";
// +
// "https://duckduckgo.com/assets/logo_homepage.normal.v101.png";
home = home + HomepageVariables.MIDDLE;
home = home + Constants.DUCK_SEARCH;
break;
case 8:
// DUCK_LITE_SEARCH;
home = home + "file:///android_asset/duckduckgo.png";
// + "https://duckduckgo.com/assets/logo_homepage.normal.v101.png";
// +
// "https://duckduckgo.com/assets/logo_homepage.normal.v101.png";
home = home + HomepageVariables.MIDDLE;
home = home + Constants.DUCK_LITE_SEARCH;
break;
@ -259,21 +258,18 @@ public class LightningView { @@ -259,21 +258,18 @@ public class LightningView {
@SuppressWarnings("deprecation")
@SuppressLint({ "NewApi", "SetJavaScriptEnabled" })
public synchronized void initializePreferences(Context context) {
mPreferences = context.getSharedPreferences(
PreferenceConstants.PREFERENCES, 0);
mHomepage = mPreferences.getString(PreferenceConstants.HOMEPAGE,
Constants.HOMEPAGE);
mPreferences = context.getSharedPreferences(PreferenceConstants.PREFERENCES, 0);
mHomepage = mPreferences.getString(PreferenceConstants.HOMEPAGE, Constants.HOMEPAGE);
mAdBlock.updatePreference();
if (mSettings == null && mWebView != null) {
mSettings = mWebView.getSettings();
} else if (mSettings == null) {
return;
}
mSettings.setGeolocationEnabled(mPreferences.getBoolean(
PreferenceConstants.LOCATION, false));
mSettings.setGeolocationEnabled(mPreferences
.getBoolean(PreferenceConstants.LOCATION, false));
if (API < 19) {
switch (mPreferences.getInt(
PreferenceConstants.ADOBE_FLASH_SUPPORT, 0)) {
switch (mPreferences.getInt(PreferenceConstants.ADOBE_FLASH_SUPPORT, 0)) {
case 0:
mSettings.setPluginState(PluginState.OFF);
break;
@ -291,8 +287,7 @@ public class LightningView { @@ -291,8 +287,7 @@ public class LightningView {
switch (mPreferences.getInt(PreferenceConstants.USER_AGENT, 1)) {
case 1:
if (API > 16) {
mSettings.setUserAgentString(WebSettings
.getDefaultUserAgent(context));
mSettings.setUserAgentString(WebSettings.getDefaultUserAgent(context));
} else {
mSettings.setUserAgentString(mDefaultUserAgent);
}
@ -316,25 +311,26 @@ public class LightningView { @@ -316,25 +311,26 @@ public class LightningView {
mSettings.setSaveFormData(true);
}
if (mPreferences.getBoolean("java", true)) {
if (mPreferences.getBoolean(PreferenceConstants.JAVASCRIPT, true)) {
mSettings.setJavaScriptEnabled(true);
mSettings.setJavaScriptCanOpenWindowsAutomatically(true);
}
if (mPreferences.getBoolean("textreflow", false)) {
if (mPreferences.getBoolean(PreferenceConstants.TEXT_REFLOW, false)) {
mSettings.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS);
} else if (API >= android.os.Build.VERSION_CODES.KITKAT) {
mSettings.setLayoutAlgorithm(LayoutAlgorithm.TEXT_AUTOSIZING);
} else {
mSettings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);
}
mSettings.setBlockNetworkImage(mPreferences.getBoolean(
PreferenceConstants.BLOCK_IMAGES, false));
mSettings.setSupportMultipleWindows(mPreferences.getBoolean(
PreferenceConstants.POPUPS, true));
mSettings.setUseWideViewPort(mPreferences.getBoolean(
PreferenceConstants.USE_WIDE_VIEWPORT, true));
mWideViewPort = mPreferences.getBoolean(
PreferenceConstants.USE_WIDE_VIEWPORT, true);
mSettings.setBlockNetworkImage(mPreferences.getBoolean(PreferenceConstants.BLOCK_IMAGES,
false));
mSettings.setSupportMultipleWindows(mPreferences.getBoolean(PreferenceConstants.POPUPS,
true));
mSettings.setUseWideViewPort(mPreferences.getBoolean(PreferenceConstants.USE_WIDE_VIEWPORT,
true));
mWideViewPort = mPreferences.getBoolean(PreferenceConstants.USE_WIDE_VIEWPORT, true);
mSettings.setLoadWithOverviewMode(mPreferences.getBoolean(
PreferenceConstants.OVERVIEW_MODE, true));
switch (mPreferences.getInt(PreferenceConstants.TEXT_SIZE, 3)) {
@ -357,7 +353,7 @@ public class LightningView { @@ -357,7 +353,7 @@ public class LightningView {
}
@SuppressWarnings("deprecation")
@SuppressLint({"SetJavaScriptEnabled", "NewApi"})
@SuppressLint({ "SetJavaScriptEnabled", "NewApi" })
public void initializeSettings(WebSettings settings, Context context) {
if (API < 18) {
settings.setAppCacheMaxSize(Long.MAX_VALUE);
@ -369,15 +365,13 @@ public class LightningView { @@ -369,15 +365,13 @@ public class LightningView {
settings.setMediaPlaybackRequiresUserGesture(true);
}
if (API < 19) {
settings.setDatabasePath(context.getFilesDir().getAbsolutePath()
+ "/databases");
settings.setDatabasePath(context.getFilesDir().getAbsolutePath() + "/databases");
}
settings.setDomStorageEnabled(true);
settings.setAppCachePath(context.getCacheDir().toString());
settings.setAppCacheEnabled(true);
settings.setCacheMode(WebSettings.LOAD_DEFAULT);
settings.setGeolocationDatabasePath(context.getCacheDir()
.getAbsolutePath());
settings.setGeolocationDatabasePath(context.getCacheDir().getAbsolutePath());
settings.setAllowFileAccess(true);
settings.setDatabaseEnabled(true);
settings.setSupportZoom(true);
@ -564,15 +558,13 @@ public class LightningView { @@ -564,15 +558,13 @@ public class LightningView {
}
@Override
public WebResourceResponse shouldInterceptRequest(WebView view,
String url) {
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
if (mAdBlock.isAd(url)) {
ByteArrayInputStream EMPTY = new ByteArrayInputStream("".getBytes());
return new WebResourceResponse("text/plain", "utf-8", EMPTY);
}
boolean useProxy = mPreferences.getBoolean(
PreferenceConstants.USE_PROXY, false);
boolean useProxy = mPreferences.getBoolean(PreferenceConstants.USE_PROXY, false);
boolean mDoLeakHardening = false;
if (!useProxy) {
@ -590,19 +582,15 @@ public class LightningView { @@ -590,19 +582,15 @@ public class LightningView {
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));
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);
HttpURLConnection conn = (HttpURLConnection) uURl.openConnection(proxy);
conn.setInstanceFollowRedirects(true);
conn.setRequestProperty("User-Agent",
mSettings.getUserAgentString());
conn.setRequestProperty("User-Agent", mSettings.getUserAgentString());
// conn.setRequestProperty("Transfer-Encoding", "chunked");
// conn.setUseCaches(false);
@ -633,8 +621,7 @@ public class LightningView { @@ -633,8 +621,7 @@ public class LightningView {
if (cType != null && cType.startsWith("text")) {
InputStream fStream;
BufferedInputStream bis = new BufferedInputStream(
conn.getInputStream());
BufferedInputStream bis = new BufferedInputStream(conn.getInputStream());
ByteArrayBuffer baf = new ByteArrayBuffer(connLen);
int read;
int bufSize = 2048;
@ -650,17 +637,16 @@ public class LightningView { @@ -650,17 +637,16 @@ public class LightningView {
fStream = new ByteArrayInputStream(plainText);
fStream = new ReplacingInputStream(
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());
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);
}/**
@ -676,8 +662,7 @@ public class LightningView { @@ -676,8 +662,7 @@ public class LightningView {
}
} catch (Exception e) {
Log.e(Constants.TAG, "Error filtering stream", e);
ByteArrayInputStream EMPTY = new ByteArrayInputStream(
"".getBytes());
ByteArrayInputStream EMPTY = new ByteArrayInputStream("".getBytes());
return new WebResourceResponse("text/plain", "utf-8", EMPTY);
}
}
@ -711,9 +696,8 @@ public class LightningView { @@ -711,9 +696,8 @@ public class LightningView {
}
@Override
public void onReceivedHttpAuthRequest(final WebView view,
final HttpAuthHandler handler, final String host,
final String realm) {
public void onReceivedHttpAuthRequest(final WebView view, final HttpAuthHandler handler,
final String host, final String realm) {
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
final EditText name = new EditText(mActivity);
@ -731,12 +715,10 @@ public class LightningView { @@ -731,12 +715,10 @@ public class LightningView {
builder.setTitle(mActivity.getString(R.string.title_sign_in));
builder.setView(passLayout);
builder.setCancelable(true)
.setPositiveButton(
mActivity.getString(R.string.title_sign_in),
.setPositiveButton(mActivity.getString(R.string.title_sign_in),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int id) {
public void onClick(DialogInterface dialog, int id) {
String user = name.getText().toString();
String pass = password.getText().toString();
handler.proceed(user.trim(), pass.trim());
@ -744,12 +726,10 @@ public class LightningView { @@ -744,12 +726,10 @@ public class LightningView {
}
})
.setNegativeButton(
mActivity.getString(R.string.action_cancel),
.setNegativeButton(mActivity.getString(R.string.action_cancel),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int id) {
public void onClick(DialogInterface dialog, int id) {
handler.cancel();
}
@ -767,27 +747,22 @@ public class LightningView { @@ -767,27 +747,22 @@ public class LightningView {
}
@Override
public void onReceivedSslError(WebView view,
final SslErrorHandler handler, SslError error) {
public void onReceivedSslError(WebView view, final SslErrorHandler handler, SslError error) {
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
builder.setTitle(mActivity.getString(R.string.title_warning));
builder.setMessage(
mActivity.getString(R.string.message_untrusted_certificate))
builder.setMessage(mActivity.getString(R.string.message_untrusted_certificate))
.setCancelable(true)
.setPositiveButton(
mActivity.getString(R.string.action_yes),
.setPositiveButton(mActivity.getString(R.string.action_yes),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int id) {
public void onClick(DialogInterface dialog, int id) {
handler.proceed();
}
})
.setNegativeButton(mActivity.getString(R.string.action_no),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int id) {
public void onClick(DialogInterface dialog, int id) {
handler.cancel();
}
});
@ -801,29 +776,23 @@ public class LightningView { @@ -801,29 +776,23 @@ public class LightningView {
}
@Override
public void onFormResubmission(WebView view, final Message dontResend,
final Message resend) {
public void onFormResubmission(WebView view, final Message dontResend, final Message resend) {
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
builder.setTitle(mActivity
.getString(R.string.title_form_resubmission));
builder.setMessage(
mActivity.getString(R.string.message_form_resubmission))
builder.setTitle(mActivity.getString(R.string.title_form_resubmission));
builder.setMessage(mActivity.getString(R.string.message_form_resubmission))
.setCancelable(true)
.setPositiveButton(
mActivity.getString(R.string.action_yes),
.setPositiveButton(mActivity.getString(R.string.action_yes),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int id) {
public void onClick(DialogInterface dialog, int id) {
resend.sendToTarget();
}
})
.setNegativeButton("No",
.setNegativeButton(mActivity.getString(R.string.action_no),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int id) {
public void onClick(DialogInterface dialog, int id) {
dontResend.sendToTarget();
}
@ -839,8 +808,8 @@ public class LightningView { @@ -839,8 +808,8 @@ public class LightningView {
}
if (url.contains("mailto:")) {
MailTo mailTo = MailTo.parse(url);
Intent i = Utils.newEmailIntent(mActivity, mailTo.getTo(),
mailTo.getSubject(), mailTo.getBody(), mailTo.getCc());
Intent i = Utils.newEmailIntent(mActivity, mailTo.getTo(), mailTo.getSubject(),
mailTo.getBody(), mailTo.getCc());
mActivity.startActivity(i);
view.reload();
return true;
@ -908,24 +877,19 @@ public class LightningView { @@ -908,24 +877,19 @@ public class LightningView {
} else {
org = origin;
}
builder.setMessage(
org + mActivity.getString(R.string.message_location))
builder.setMessage(org + mActivity.getString(R.string.message_location))
.setCancelable(true)
.setPositiveButton(
mActivity.getString(R.string.action_allow),
.setPositiveButton(mActivity.getString(R.string.action_allow),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int id) {
public void onClick(DialogInterface dialog, int id) {
callback.invoke(origin, true, remember);
}
})
.setNegativeButton(
mActivity.getString(R.string.action_dont_allow),
.setNegativeButton(mActivity.getString(R.string.action_dont_allow),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int id) {
public void onClick(DialogInterface dialog, int id) {
callback.invoke(origin, false, remember);
}
});
@ -935,8 +899,8 @@ public class LightningView { @@ -935,8 +899,8 @@ public class LightningView {
}
@Override
public boolean onCreateWindow(WebView view, boolean isDialog,
boolean isUserGesture, Message resultMsg) {
public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture,
Message resultMsg) {
mBrowserController.onCreateWindow(isUserGesture, resultMsg);
return isUserGesture;
}
@ -951,13 +915,11 @@ public class LightningView { @@ -951,13 +915,11 @@ public class LightningView {
mBrowserController.openFileChooser(uploadMsg);
}
public void openFileChooser(ValueCallback<Uri> uploadMsg,
String acceptType) {
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) {
mBrowserController.openFileChooser(uploadMsg);
}
public void openFileChooser(ValueCallback<Uri> uploadMsg,
String acceptType, String capture) {
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
mBrowserController.openFileChooser(uploadMsg);
}
@ -980,7 +942,8 @@ public class LightningView { @@ -980,7 +942,8 @@ public class LightningView {
@Override
public void onShowCustomView(View view, CustomViewCallback callback) {
// While these lines might look like they work, in practice,
// Full-screen videos won't work correctly. I may test this out some more
// Full-screen videos won't work correctly. I may test this out some
// more
// if (view instanceof FrameLayout) {
// FrameLayout frame = (FrameLayout) view;
// if (frame.getFocusedChild() instanceof VideoView) {
@ -991,8 +954,7 @@ public class LightningView { @@ -991,8 +954,7 @@ public class LightningView {
// }
// } else {
Activity activity = mBrowserController.getActivity();
mBrowserController.onShowCustomView(view,
activity.getRequestedOrientation(), callback);
mBrowserController.onShowCustomView(view, activity.getRequestedOrientation(), callback);
// }
@ -1004,7 +966,8 @@ public class LightningView { @@ -1004,7 +966,8 @@ public class LightningView {
public void onShowCustomView(View view, int requestedOrientation,
CustomViewCallback callback) {
// While these lines might look like they work, in practice,
// Full-screen videos won't work correctly. I may test this out some more
// Full-screen videos won't work correctly. I may test this out some
// more
// if (view instanceof FrameLayout) {
// FrameLayout frame = (FrameLayout) view;
// if (frame.getFocusedChild() instanceof VideoView) {
@ -1014,8 +977,7 @@ public class LightningView { @@ -1014,8 +977,7 @@ public class LightningView {
// video.setVisibility(View.GONE);
// }
// } else {
mBrowserController.onShowCustomView(view, requestedOrientation,
callback);
mBrowserController.onShowCustomView(view, requestedOrientation, callback);
// }

Loading…
Cancel
Save