You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1119 lines
32 KiB
1119 lines
32 KiB
10 years ago
|
/*
|
||
|
* Copyright 2014 A.C.R. Development
|
||
|
*/
|
||
|
|
||
|
package acr.browser.lightning;
|
||
|
|
||
9 years ago
|
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;
|
||
|
|
||
10 years ago
|
import android.annotation.SuppressLint;
|
||
|
import android.app.Activity;
|
||
|
import android.app.AlertDialog;
|
||
9 years ago
|
import android.content.ActivityNotFoundException;
|
||
|
import android.content.Context;
|
||
|
import android.content.DialogInterface;
|
||
|
import android.content.Intent;
|
||
10 years ago
|
import android.graphics.Bitmap;
|
||
10 years ago
|
import android.graphics.ColorMatrix;
|
||
|
import android.graphics.ColorMatrixColorFilter;
|
||
|
import android.graphics.Paint;
|
||
10 years ago
|
import android.net.MailTo;
|
||
|
import android.net.Uri;
|
||
|
import android.net.http.SslError;
|
||
9 years ago
|
import android.os.Build;
|
||
10 years ago
|
import android.os.Message;
|
||
|
import android.text.InputType;
|
||
|
import android.text.method.PasswordTransformationMethod;
|
||
|
import android.util.Log;
|
||
|
import android.view.GestureDetector;
|
||
10 years ago
|
import android.view.GestureDetector.SimpleOnGestureListener;
|
||
10 years ago
|
import android.view.MotionEvent;
|
||
|
import android.view.View;
|
||
|
import android.view.View.OnTouchListener;
|
||
9 years ago
|
import android.webkit.CookieManager;
|
||
9 years ago
|
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;
|
||
10 years ago
|
import android.webkit.WebSettings.LayoutAlgorithm;
|
||
|
import android.webkit.WebSettings.PluginState;
|
||
9 years ago
|
import android.webkit.WebView;
|
||
|
import android.webkit.WebViewClient;
|
||
10 years ago
|
import android.widget.EditText;
|
||
|
import android.widget.LinearLayout;
|
||
|
|
||
|
public class LightningView {
|
||
|
|
||
10 years ago
|
private Title mTitle;
|
||
|
private WebView mWebView;
|
||
|
private BrowserController mBrowserController;
|
||
|
private GestureDetector mGestureDetector;
|
||
|
private Activity mActivity;
|
||
|
private WebSettings mSettings;
|
||
|
private static String mHomepage;
|
||
|
private static String mDefaultUserAgent;
|
||
|
private static Bitmap mWebpageBitmap;
|
||
9 years ago
|
private static PreferenceManager mPreferences;
|
||
10 years ago
|
private AdBlock mAdBlock;
|
||
|
private IntentUtils mIntentUtils;
|
||
9 years ago
|
private final Paint mPaint = new Paint();
|
||
|
private boolean isForegroundTab;
|
||
9 years ago
|
private boolean mTextReflow = false;
|
||
|
private boolean mInvertPage = false;
|
||
9 years ago
|
private static final int API = android.os.Build.VERSION.SDK_INT;
|
||
|
private static final int SCROLL_UP_THRESHOLD = Utils.convertDpToPixels(10);
|
||
|
private static final int SCROLL_DOWN_THRESHOLD = Utils.convertDpToPixels(100);
|
||
10 years ago
|
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
|
||
|
};
|
||
10 years ago
|
|
||
10 years ago
|
@SuppressWarnings("deprecation")
|
||
|
@SuppressLint("NewApi")
|
||
9 years ago
|
public LightningView(Activity activity, String url, boolean darkTheme) {
|
||
10 years ago
|
|
||
10 years ago
|
mActivity = activity;
|
||
|
mWebView = new WebView(activity);
|
||
9 years ago
|
mTitle = new Title(activity, darkTheme);
|
||
9 years ago
|
mAdBlock = AdBlock.getInstance(activity.getApplicationContext());
|
||
9 years ago
|
|
||
9 years ago
|
mWebpageBitmap = Utils.getWebpageBitmap(activity.getResources(), darkTheme);
|
||
10 years ago
|
|
||
10 years ago
|
try {
|
||
|
mBrowserController = (BrowserController) activity;
|
||
|
} catch (ClassCastException e) {
|
||
|
throw new ClassCastException(activity + " must implement BrowserController");
|
||
|
}
|
||
|
mIntentUtils = new IntentUtils(mBrowserController);
|
||
|
mWebView.setDrawingCacheBackgroundColor(0x00000000);
|
||
|
mWebView.setFocusableInTouchMode(true);
|
||
|
mWebView.setFocusable(true);
|
||
|
mWebView.setAnimationCacheEnabled(false);
|
||
9 years ago
|
mWebView.setDrawingCacheEnabled(false);
|
||
|
mWebView.setWillNotCacheDrawing(true);
|
||
|
mWebView.setAlwaysDrawnWithCacheEnabled(false);
|
||
10 years ago
|
mWebView.setBackgroundColor(activity.getResources().getColor(android.R.color.white));
|
||
10 years ago
|
|
||
10 years ago
|
if (API > 15) {
|
||
10 years ago
|
mWebView.setBackground(null);
|
||
10 years ago
|
mWebView.getRootView().setBackground(null);
|
||
9 years ago
|
} else if (mWebView.getRootView() != null) {
|
||
10 years ago
|
mWebView.getRootView().setBackgroundDrawable(null);
|
||
|
}
|
||
|
mWebView.setScrollbarFadingEnabled(true);
|
||
|
mWebView.setSaveEnabled(true);
|
||
|
mWebView.setWebChromeClient(new LightningChromeClient(activity));
|
||
|
mWebView.setWebViewClient(new LightningWebClient(activity));
|
||
|
mWebView.setDownloadListener(new LightningDownloadListener(activity));
|
||
|
mGestureDetector = new GestureDetector(activity, new CustomGestureListener());
|
||
9 years ago
|
mWebView.setOnTouchListener(new TouchListener());
|
||
10 years ago
|
mDefaultUserAgent = mWebView.getSettings().getUserAgentString();
|
||
|
mSettings = mWebView.getSettings();
|
||
|
initializeSettings(mWebView.getSettings(), activity);
|
||
|
initializePreferences(activity);
|
||
10 years ago
|
|
||
10 years ago
|
if (url != null) {
|
||
|
if (!url.trim().isEmpty()) {
|
||
|
mWebView.loadUrl(url);
|
||
|
} else {
|
||
10 years ago
|
// don't load anything, the user is looking for a blank tab
|
||
10 years ago
|
}
|
||
10 years ago
|
} else {
|
||
|
if (mHomepage.startsWith("about:home")) {
|
||
|
mWebView.loadUrl(getHomepage());
|
||
|
} else if (mHomepage.startsWith("about:bookmarks")) {
|
||
|
mBrowserController.openBookmarkPage(mWebView);
|
||
|
} else {
|
||
|
mWebView.loadUrl(mHomepage);
|
||
|
}
|
||
|
}
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
|
public String getHomepage() {
|
||
9 years ago
|
StringBuilder homepageBuilder = new StringBuilder();
|
||
|
homepageBuilder.append(HomepageVariables.HEAD);
|
||
|
String icon;
|
||
|
String searchUrl;
|
||
9 years ago
|
switch (mPreferences.getSearchChoice()) {
|
||
10 years ago
|
case 0:
|
||
|
// CUSTOM SEARCH
|
||
9 years ago
|
icon = "file:///android_asset/lightning.png";
|
||
|
searchUrl = mPreferences.getSearchUrl();
|
||
10 years ago
|
break;
|
||
|
case 1:
|
||
|
// GOOGLE_SEARCH;
|
||
9 years ago
|
icon = "file:///android_asset/google.png";
|
||
|
// "https://www.google.com/images/srpr/logo11w.png";
|
||
|
searchUrl = Constants.GOOGLE_SEARCH;
|
||
10 years ago
|
break;
|
||
|
case 2:
|
||
|
// ANDROID SEARCH;
|
||
9 years ago
|
icon = "file:///android_asset/ask.png";
|
||
|
searchUrl = Constants.ASK_SEARCH;
|
||
10 years ago
|
break;
|
||
|
case 3:
|
||
|
// BING_SEARCH;
|
||
9 years ago
|
icon = "file:///android_asset/bing.png";
|
||
10 years ago
|
// "http://upload.wikimedia.org/wikipedia/commons/thumb/b/b1/Bing_logo_%282013%29.svg/500px-Bing_logo_%282013%29.svg.png";
|
||
9 years ago
|
searchUrl = Constants.BING_SEARCH;
|
||
10 years ago
|
break;
|
||
|
case 4:
|
||
|
// YAHOO_SEARCH;
|
||
9 years ago
|
icon = "file:///android_asset/yahoo.png";
|
||
10 years ago
|
// "http://upload.wikimedia.org/wikipedia/commons/thumb/2/24/Yahoo%21_logo.svg/799px-Yahoo%21_logo.svg.png";
|
||
9 years ago
|
searchUrl = Constants.YAHOO_SEARCH;
|
||
10 years ago
|
break;
|
||
|
case 5:
|
||
|
// STARTPAGE_SEARCH;
|
||
9 years ago
|
icon = "file:///android_asset/startpage.png";
|
||
|
// "https://startpage.com/graphics/startp_logo.gif";
|
||
|
searchUrl = Constants.STARTPAGE_SEARCH;
|
||
10 years ago
|
break;
|
||
|
case 6:
|
||
|
// STARTPAGE_MOBILE
|
||
9 years ago
|
icon = "file:///android_asset/startpage.png";
|
||
|
// "https://startpage.com/graphics/startp_logo.gif";
|
||
|
searchUrl = Constants.STARTPAGE_MOBILE_SEARCH;
|
||
10 years ago
|
case 7:
|
||
|
// DUCK_SEARCH;
|
||
9 years ago
|
icon = "file:///android_asset/duckduckgo.png";
|
||
10 years ago
|
// "https://duckduckgo.com/assets/logo_homepage.normal.v101.png";
|
||
9 years ago
|
searchUrl = Constants.DUCK_SEARCH;
|
||
10 years ago
|
break;
|
||
|
case 8:
|
||
|
// DUCK_LITE_SEARCH;
|
||
9 years ago
|
icon = "file:///android_asset/duckduckgo.png";
|
||
10 years ago
|
// "https://duckduckgo.com/assets/logo_homepage.normal.v101.png";
|
||
9 years ago
|
searchUrl = Constants.DUCK_LITE_SEARCH;
|
||
10 years ago
|
break;
|
||
|
case 9:
|
||
|
// BAIDU_SEARCH;
|
||
9 years ago
|
icon = "file:///android_asset/baidu.png";
|
||
|
// "http://www.baidu.com/img/bdlogo.gif";
|
||
|
searchUrl = Constants.BAIDU_SEARCH;
|
||
10 years ago
|
break;
|
||
|
case 10:
|
||
|
// YANDEX_SEARCH;
|
||
9 years ago
|
icon = "file:///android_asset/yandex.png";
|
||
10 years ago
|
// "http://upload.wikimedia.org/wikipedia/commons/thumb/9/91/Yandex.svg/600px-Yandex.svg.png";
|
||
9 years ago
|
searchUrl = Constants.YANDEX_SEARCH;
|
||
|
break;
|
||
|
default:
|
||
|
// DEFAULT GOOGLE_SEARCH;
|
||
|
icon = "file:///android_asset/google.png";
|
||
|
searchUrl = Constants.GOOGLE_SEARCH;
|
||
10 years ago
|
break;
|
||
10 years ago
|
|
||
|
}
|
||
|
|
||
9 years ago
|
homepageBuilder.append(icon);
|
||
|
homepageBuilder.append(HomepageVariables.MIDDLE);
|
||
|
homepageBuilder.append(searchUrl);
|
||
|
homepageBuilder.append(HomepageVariables.END);
|
||
10 years ago
|
|
||
10 years ago
|
File homepage = new File(mActivity.getFilesDir(), "homepage.html");
|
||
10 years ago
|
try {
|
||
|
FileWriter hWriter = new FileWriter(homepage, false);
|
||
9 years ago
|
hWriter.write(homepageBuilder.toString());
|
||
10 years ago
|
hWriter.close();
|
||
|
} catch (IOException e) {
|
||
|
e.printStackTrace();
|
||
|
}
|
||
|
|
||
|
return Constants.FILE + homepage;
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
@SuppressWarnings("deprecation")
|
||
|
@SuppressLint({ "NewApi", "SetJavaScriptEnabled" })
|
||
|
public synchronized void initializePreferences(Context context) {
|
||
9 years ago
|
mPreferences = PreferenceManager.getInstance();
|
||
|
mHomepage = mPreferences.getHomepage();
|
||
10 years ago
|
mAdBlock.updatePreference();
|
||
|
if (mSettings == null && mWebView != null) {
|
||
|
mSettings = mWebView.getSettings();
|
||
|
} else if (mSettings == null) {
|
||
|
return;
|
||
|
}
|
||
10 years ago
|
|
||
9 years ago
|
setColorMode(mPreferences.getRenderingMode());
|
||
10 years ago
|
|
||
9 years ago
|
if (!mBrowserController.isIncognito()) {
|
||
9 years ago
|
mSettings.setGeolocationEnabled(mPreferences.getLocationEnabled());
|
||
9 years ago
|
} else {
|
||
|
mSettings.setGeolocationEnabled(false);
|
||
|
}
|
||
10 years ago
|
if (API < 19) {
|
||
9 years ago
|
switch (mPreferences.getFlashSupport()) {
|
||
10 years ago
|
case 0:
|
||
|
mSettings.setPluginState(PluginState.OFF);
|
||
|
break;
|
||
|
case 1:
|
||
|
mSettings.setPluginState(PluginState.ON_DEMAND);
|
||
|
break;
|
||
|
case 2:
|
||
|
mSettings.setPluginState(PluginState.ON);
|
||
|
break;
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
9 years ago
|
switch (mPreferences.getUserAgentChoice()) {
|
||
10 years ago
|
case 1:
|
||
10 years ago
|
if (API > 16) {
|
||
|
mSettings.setUserAgentString(WebSettings.getDefaultUserAgent(context));
|
||
|
} else {
|
||
|
mSettings.setUserAgentString(mDefaultUserAgent);
|
||
|
}
|
||
10 years ago
|
break;
|
||
|
case 2:
|
||
10 years ago
|
mSettings.setUserAgentString(Constants.DESKTOP_USER_AGENT);
|
||
10 years ago
|
break;
|
||
10 years ago
|
case 3:
|
||
|
mSettings.setUserAgentString(Constants.MOBILE_USER_AGENT);
|
||
|
break;
|
||
|
case 4:
|
||
9 years ago
|
mSettings.setUserAgentString(mPreferences.getUserAgentString(mDefaultUserAgent));
|
||
10 years ago
|
break;
|
||
|
}
|
||
|
|
||
9 years ago
|
if (mPreferences.getSavePasswordsEnabled() && !mBrowserController.isIncognito()) {
|
||
10 years ago
|
if (API < 18) {
|
||
|
mSettings.setSavePassword(true);
|
||
|
}
|
||
|
mSettings.setSaveFormData(true);
|
||
9 years ago
|
} else {
|
||
|
if (API < 18) {
|
||
|
mSettings.setSavePassword(false);
|
||
|
}
|
||
|
mSettings.setSaveFormData(false);
|
||
10 years ago
|
}
|
||
|
|
||
9 years ago
|
if (mPreferences.getJavaScriptEnabled()) {
|
||
10 years ago
|
mSettings.setJavaScriptEnabled(true);
|
||
|
mSettings.setJavaScriptCanOpenWindowsAutomatically(true);
|
||
|
}
|
||
|
|
||
9 years ago
|
if (mPreferences.getTextReflowEnabled()) {
|
||
9 years ago
|
mTextReflow = true;
|
||
10 years ago
|
mSettings.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS);
|
||
9 years ago
|
if (API >= android.os.Build.VERSION_CODES.KITKAT) {
|
||
9 years ago
|
try {
|
||
|
mSettings.setLayoutAlgorithm(LayoutAlgorithm.TEXT_AUTOSIZING);
|
||
|
} catch (Exception e) {
|
||
|
// This shouldn't be necessary, but there are a number
|
||
|
// of KitKat devices that crash trying to set this
|
||
|
Log.e(Constants.TAG, "Problem setting LayoutAlgorithm to TEXT_AUTOSIZING");
|
||
|
}
|
||
9 years ago
|
}
|
||
10 years ago
|
} else {
|
||
9 years ago
|
mTextReflow = false;
|
||
10 years ago
|
mSettings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);
|
||
|
}
|
||
10 years ago
|
|
||
9 years ago
|
mSettings.setBlockNetworkImage(mPreferences.getBlockImagesEnabled());
|
||
|
mSettings.setSupportMultipleWindows(mPreferences.getPopupsEnabled());
|
||
|
mSettings.setUseWideViewPort(mPreferences.getUseWideViewportEnabled());
|
||
|
mSettings.setLoadWithOverviewMode(mPreferences.getOverviewModeEnabled());
|
||
|
switch (mPreferences.getTextSize()) {
|
||
10 years ago
|
case 1:
|
||
|
mSettings.setTextZoom(200);
|
||
|
break;
|
||
|
case 2:
|
||
|
mSettings.setTextZoom(150);
|
||
|
break;
|
||
|
case 3:
|
||
|
mSettings.setTextZoom(100);
|
||
|
break;
|
||
|
case 4:
|
||
|
mSettings.setTextZoom(75);
|
||
|
break;
|
||
|
case 5:
|
||
|
mSettings.setTextZoom(50);
|
||
|
break;
|
||
10 years ago
|
}
|
||
9 years ago
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||
|
CookieManager.getInstance().setAcceptThirdPartyCookies(mWebView,
|
||
9 years ago
|
!mPreferences.getBlockThirdPartyCookiesEnabled());
|
||
9 years ago
|
}
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
@SuppressWarnings("deprecation")
|
||
|
@SuppressLint({ "SetJavaScriptEnabled", "NewApi" })
|
||
|
public void initializeSettings(WebSettings settings, Context context) {
|
||
|
if (API < 18) {
|
||
|
settings.setAppCacheMaxSize(Long.MAX_VALUE);
|
||
|
}
|
||
|
if (API < 17) {
|
||
|
settings.setEnableSmoothTransition(true);
|
||
|
}
|
||
|
if (API > 16) {
|
||
|
settings.setMediaPlaybackRequiresUserGesture(true);
|
||
|
}
|
||
9 years ago
|
if (API >= Build.VERSION_CODES.LOLLIPOP && !mBrowserController.isIncognito()) {
|
||
|
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
|
||
|
} else if (API >= Build.VERSION_CODES.LOLLIPOP) {
|
||
|
// We're in Incognito mode, reject
|
||
|
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_NEVER_ALLOW);
|
||
9 years ago
|
}
|
||
9 years ago
|
settings.setDomStorageEnabled(true);
|
||
10 years ago
|
settings.setAppCacheEnabled(true);
|
||
|
settings.setCacheMode(WebSettings.LOAD_DEFAULT);
|
||
|
settings.setDatabaseEnabled(true);
|
||
|
settings.setSupportZoom(true);
|
||
|
settings.setBuiltInZoomControls(true);
|
||
|
settings.setDisplayZoomControls(false);
|
||
|
settings.setAllowContentAccess(true);
|
||
9 years ago
|
settings.setAllowFileAccess(true);
|
||
10 years ago
|
settings.setDefaultTextEncodingName("utf-8");
|
||
|
if (API > 16) {
|
||
|
settings.setAllowFileAccessFromFileURLs(false);
|
||
|
settings.setAllowUniversalAccessFromFileURLs(false);
|
||
|
}
|
||
9 years ago
|
|
||
|
settings.setAppCachePath(context.getDir("appcache", 0).getPath());
|
||
|
settings.setGeolocationDatabasePath(context.getDir("geolocation", 0).getPath());
|
||
|
if (API < Build.VERSION_CODES.KITKAT) {
|
||
|
settings.setDatabasePath(context.getDir("databases", 0).getPath());
|
||
|
}
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
public boolean isShown() {
|
||
|
return mWebView != null && mWebView.isShown();
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
public synchronized void onPause() {
|
||
|
if (mWebView != null) {
|
||
|
mWebView.onPause();
|
||
|
}
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
public synchronized void onResume() {
|
||
|
if (mWebView != null) {
|
||
|
mWebView.onResume();
|
||
|
}
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
|
public void setForegroundTab(boolean isForeground) {
|
||
|
isForegroundTab = isForeground;
|
||
|
mBrowserController.update();
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
|
public boolean isForegroundTab() {
|
||
|
return isForegroundTab;
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
public int getProgress() {
|
||
|
if (mWebView != null) {
|
||
|
return mWebView.getProgress();
|
||
|
} else {
|
||
|
return 100;
|
||
|
}
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
public synchronized void stopLoading() {
|
||
|
if (mWebView != null) {
|
||
|
mWebView.stopLoading();
|
||
|
}
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
public void setHardwareRendering() {
|
||
|
mWebView.setLayerType(View.LAYER_TYPE_HARDWARE, mPaint);
|
||
|
}
|
||
|
|
||
|
public void setNormalRendering() {
|
||
9 years ago
|
mWebView.setLayerType(View.LAYER_TYPE_NONE, null);
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
10 years ago
|
public void setSoftwareRendering() {
|
||
9 years ago
|
mWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
|
public void setColorMode(int mode) {
|
||
9 years ago
|
mInvertPage = false;
|
||
10 years ago
|
switch (mode) {
|
||
|
case 0:
|
||
|
mPaint.setColorFilter(null);
|
||
9 years ago
|
// setSoftwareRendering(); // Some devices get segfaults
|
||
|
// in the WebView with Hardware Acceleration enabled,
|
||
|
// the only fix is to disable hardware rendering
|
||
10 years ago
|
setNormalRendering();
|
||
9 years ago
|
mInvertPage = false;
|
||
10 years ago
|
break;
|
||
|
case 1:
|
||
|
ColorMatrixColorFilter filterInvert = new ColorMatrixColorFilter(
|
||
|
mNegativeColorArray);
|
||
|
mPaint.setColorFilter(filterInvert);
|
||
10 years ago
|
setHardwareRendering();
|
||
9 years ago
|
|
||
|
mInvertPage = true;
|
||
10 years ago
|
break;
|
||
|
case 2:
|
||
|
ColorMatrix cm = new ColorMatrix();
|
||
|
cm.setSaturation(0);
|
||
|
ColorMatrixColorFilter filterGray = new ColorMatrixColorFilter(cm);
|
||
|
mPaint.setColorFilter(filterGray);
|
||
10 years ago
|
setHardwareRendering();
|
||
10 years ago
|
break;
|
||
10 years ago
|
case 3:
|
||
|
ColorMatrix matrix = new ColorMatrix();
|
||
|
matrix.set(mNegativeColorArray);
|
||
|
ColorMatrix matrixGray = new ColorMatrix();
|
||
|
matrixGray.setSaturation(0);
|
||
|
ColorMatrix concat = new ColorMatrix();
|
||
|
concat.setConcat(matrix, matrixGray);
|
||
|
ColorMatrixColorFilter filterInvertGray = new ColorMatrixColorFilter(concat);
|
||
|
mPaint.setColorFilter(filterInvertGray);
|
||
|
setHardwareRendering();
|
||
9 years ago
|
|
||
9 years ago
|
mInvertPage = true;
|
||
10 years ago
|
break;
|
||
|
|
||
10 years ago
|
}
|
||
9 years ago
|
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
public synchronized void pauseTimers() {
|
||
|
if (mWebView != null) {
|
||
|
mWebView.pauseTimers();
|
||
|
}
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
|
public synchronized void resumeTimers() {
|
||
|
if (mWebView != null) {
|
||
|
mWebView.resumeTimers();
|
||
|
}
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
public void requestFocus() {
|
||
|
if (mWebView != null && !mWebView.hasFocus()) {
|
||
|
mWebView.requestFocus();
|
||
|
}
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
public void setVisibility(int visible) {
|
||
|
if (mWebView != null) {
|
||
|
mWebView.setVisibility(visible);
|
||
|
}
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
public void clearCache(boolean disk) {
|
||
|
if (mWebView != null) {
|
||
|
mWebView.clearCache(disk);
|
||
|
}
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
public synchronized void reload() {
|
||
|
if (mWebView != null) {
|
||
|
mWebView.reload();
|
||
|
}
|
||
10 years ago
|
}
|
||
|
|
||
9 years ago
|
private void cacheFavicon(Bitmap icon) {
|
||
|
String hash = String.valueOf(Utils.getDomainName(getUrl()).hashCode());
|
||
|
Log.d(Constants.TAG, "Caching icon for " + Utils.getDomainName(getUrl()));
|
||
|
File image = new File(mActivity.getCacheDir(), hash + ".png");
|
||
|
try {
|
||
|
FileOutputStream fos = new FileOutputStream(image);
|
||
|
icon.compress(Bitmap.CompressFormat.PNG, 100, fos);
|
||
|
fos.flush();
|
||
|
fos.close();
|
||
|
} catch (FileNotFoundException e) {
|
||
|
e.printStackTrace();
|
||
|
} catch (IOException e) {
|
||
|
e.printStackTrace();
|
||
|
}
|
||
|
}
|
||
|
|
||
10 years ago
|
@SuppressWarnings("deprecation")
|
||
|
@SuppressLint("NewApi")
|
||
|
public synchronized void find(String text) {
|
||
|
if (mWebView != null) {
|
||
|
if (API > 16) {
|
||
|
mWebView.findAllAsync(text);
|
||
|
} else {
|
||
|
mWebView.findAll(text);
|
||
|
}
|
||
|
}
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
public Activity getActivity() {
|
||
|
return mActivity;
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
public synchronized void onDestroy() {
|
||
|
if (mWebView != null) {
|
||
|
mWebView.stopLoading();
|
||
|
mWebView.onPause();
|
||
|
mWebView.clearHistory();
|
||
|
mWebView.setVisibility(View.GONE);
|
||
|
mWebView.removeAllViews();
|
||
|
mWebView.destroyDrawingCache();
|
||
|
// mWebView.destroy(); //this is causing the segfault
|
||
|
mWebView = null;
|
||
|
}
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
|
public synchronized void goBack() {
|
||
|
if (mWebView != null) {
|
||
|
mWebView.goBack();
|
||
|
}
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
|
public String getUserAgent() {
|
||
|
if (mWebView != null) {
|
||
|
return mWebView.getSettings().getUserAgentString();
|
||
|
} else {
|
||
|
return "";
|
||
|
}
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
public synchronized void goForward() {
|
||
|
if (mWebView != null) {
|
||
|
mWebView.goForward();
|
||
|
}
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
public boolean canGoBack() {
|
||
|
return mWebView != null && mWebView.canGoBack();
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
public boolean canGoForward() {
|
||
|
return mWebView != null && mWebView.canGoForward();
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
public WebView getWebView() {
|
||
|
return mWebView;
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
public Bitmap getFavicon() {
|
||
|
return mTitle.getFavicon();
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
public synchronized void loadUrl(String url) {
|
||
|
if (mWebView != null) {
|
||
|
mWebView.loadUrl(url);
|
||
|
}
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
public synchronized void invalidate() {
|
||
|
if (mWebView != null) {
|
||
|
mWebView.invalidate();
|
||
|
}
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
public String getTitle() {
|
||
|
return mTitle.getTitle();
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
public String getUrl() {
|
||
|
if (mWebView != null) {
|
||
|
return mWebView.getUrl();
|
||
|
} else {
|
||
|
return "";
|
||
|
}
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
public class LightningWebClient extends WebViewClient {
|
||
10 years ago
|
|
||
10 years ago
|
Context mActivity;
|
||
10 years ago
|
|
||
10 years ago
|
LightningWebClient(Context context) {
|
||
|
mActivity = context;
|
||
|
}
|
||
10 years ago
|
|
||
9 years ago
|
@Override
|
||
|
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
|
||
|
if (mAdBlock.isAd(request.getUrl().getHost())) {
|
||
|
ByteArrayInputStream EMPTY = new ByteArrayInputStream("".getBytes());
|
||
|
return new WebResourceResponse("text/plain", "utf-8", EMPTY);
|
||
|
}
|
||
|
|
||
|
return super.shouldInterceptRequest(view, request);
|
||
|
}
|
||
|
|
||
10 years ago
|
@Override
|
||
|
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
|
||
|
if (mAdBlock.isAd(url)) {
|
||
|
ByteArrayInputStream EMPTY = new ByteArrayInputStream("".getBytes());
|
||
|
return new WebResourceResponse("text/plain", "utf-8", EMPTY);
|
||
|
}
|
||
9 years ago
|
return null;
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
@Override
|
||
|
public void onPageFinished(WebView view, String url) {
|
||
|
if (view.isShown()) {
|
||
9 years ago
|
mBrowserController.updateUrl(url, true);
|
||
9 years ago
|
view.postInvalidate();
|
||
10 years ago
|
}
|
||
10 years ago
|
if (view.getTitle() == null || view.getTitle().isEmpty()) {
|
||
10 years ago
|
mTitle.setTitle(mActivity.getString(R.string.untitled));
|
||
|
} else {
|
||
10 years ago
|
mTitle.setTitle(view.getTitle());
|
||
10 years ago
|
}
|
||
9 years ago
|
if (API >= android.os.Build.VERSION_CODES.KITKAT && mInvertPage) {
|
||
9 years ago
|
view.evaluateJavascript(Constants.JAVASCRIPT_INVERT_PAGE, null);
|
||
|
}
|
||
10 years ago
|
mBrowserController.update();
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
@Override
|
||
|
public void onPageStarted(WebView view, String url, Bitmap favicon) {
|
||
|
if (isShown()) {
|
||
9 years ago
|
mBrowserController.updateUrl(url, false);
|
||
10 years ago
|
mBrowserController.showActionBar();
|
||
|
}
|
||
|
mTitle.setFavicon(mWebpageBitmap);
|
||
|
mBrowserController.update();
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
@Override
|
||
|
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);
|
||
|
final EditText password = new EditText(mActivity);
|
||
|
LinearLayout passLayout = new LinearLayout(mActivity);
|
||
|
passLayout.setOrientation(LinearLayout.VERTICAL);
|
||
|
|
||
|
passLayout.addView(name);
|
||
|
passLayout.addView(password);
|
||
|
|
||
|
name.setHint(mActivity.getString(R.string.hint_username));
|
||
9 years ago
|
name.setSingleLine();
|
||
10 years ago
|
password.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
|
||
9 years ago
|
password.setSingleLine();
|
||
10 years ago
|
password.setTransformationMethod(new PasswordTransformationMethod());
|
||
|
password.setHint(mActivity.getString(R.string.hint_password));
|
||
|
builder.setTitle(mActivity.getString(R.string.title_sign_in));
|
||
|
builder.setView(passLayout);
|
||
|
builder.setCancelable(true)
|
||
|
.setPositiveButton(mActivity.getString(R.string.title_sign_in),
|
||
|
new DialogInterface.OnClickListener() {
|
||
|
@Override
|
||
|
public void onClick(DialogInterface dialog, int id) {
|
||
|
String user = name.getText().toString();
|
||
|
String pass = password.getText().toString();
|
||
|
handler.proceed(user.trim(), pass.trim());
|
||
9 years ago
|
Log.d(Constants.TAG, "Request Login");
|
||
10 years ago
|
|
||
|
}
|
||
|
})
|
||
|
.setNegativeButton(mActivity.getString(R.string.action_cancel),
|
||
|
new DialogInterface.OnClickListener() {
|
||
|
@Override
|
||
|
public void onClick(DialogInterface dialog, int id) {
|
||
|
handler.cancel();
|
||
|
|
||
|
}
|
||
|
});
|
||
|
AlertDialog alert = builder.create();
|
||
|
alert.show();
|
||
10 years ago
|
|
||
10 years ago
|
}
|
||
9 years ago
|
|
||
9 years ago
|
private boolean mIsRunning = false;
|
||
|
private float mZoomScale = 0.0f;
|
||
9 years ago
|
|
||
10 years ago
|
@Override
|
||
9 years ago
|
public void onScaleChanged(final WebView view, final float oldScale, final float newScale) {
|
||
|
if (view.isShown() && mTextReflow && API >= android.os.Build.VERSION_CODES.KITKAT) {
|
||
9 years ago
|
if (mIsRunning)
|
||
9 years ago
|
return;
|
||
9 years ago
|
if (Math.abs(mZoomScale - newScale) > 0.01f) {
|
||
|
mIsRunning = view.postDelayed(new Runnable() {
|
||
|
|
||
|
@Override
|
||
|
public void run() {
|
||
|
mZoomScale = newScale;
|
||
|
view.evaluateJavascript(Constants.JAVASCRIPT_TEXT_REFLOW, null);
|
||
|
mIsRunning = false;
|
||
|
}
|
||
|
|
||
|
}, 100);
|
||
|
}
|
||
9 years ago
|
|
||
10 years ago
|
}
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
@Override
|
||
|
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))
|
||
|
.setCancelable(true)
|
||
|
.setPositiveButton(mActivity.getString(R.string.action_yes),
|
||
|
new DialogInterface.OnClickListener() {
|
||
|
@Override
|
||
|
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) {
|
||
|
handler.cancel();
|
||
|
}
|
||
|
});
|
||
|
AlertDialog alert = builder.create();
|
||
|
if (error.getPrimaryError() == SslError.SSL_UNTRUSTED) {
|
||
|
alert.show();
|
||
|
} else {
|
||
|
handler.proceed();
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
10 years ago
|
@Override
|
||
|
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))
|
||
|
.setCancelable(true)
|
||
|
.setPositiveButton(mActivity.getString(R.string.action_yes),
|
||
|
new DialogInterface.OnClickListener() {
|
||
|
@Override
|
||
|
public void onClick(DialogInterface dialog, int id) {
|
||
|
|
||
|
resend.sendToTarget();
|
||
|
}
|
||
|
})
|
||
|
.setNegativeButton(mActivity.getString(R.string.action_no),
|
||
|
new DialogInterface.OnClickListener() {
|
||
|
@Override
|
||
|
public void onClick(DialogInterface dialog, int id) {
|
||
|
|
||
|
dontResend.sendToTarget();
|
||
|
}
|
||
|
});
|
||
|
AlertDialog alert = builder.create();
|
||
|
alert.show();
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
@Override
|
||
|
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
||
10 years ago
|
if (mBrowserController.isIncognito()) {
|
||
|
return super.shouldOverrideUrlLoading(view, url);
|
||
|
}
|
||
10 years ago
|
if (url.startsWith("about:")) {
|
||
|
return super.shouldOverrideUrlLoading(view, url);
|
||
|
}
|
||
|
if (url.contains("mailto:")) {
|
||
|
MailTo mailTo = MailTo.parse(url);
|
||
|
Intent i = Utils.newEmailIntent(mActivity, mailTo.getTo(), mailTo.getSubject(),
|
||
|
mailTo.getBody(), mailTo.getCc());
|
||
|
mActivity.startActivity(i);
|
||
|
view.reload();
|
||
|
return true;
|
||
|
} else if (url.startsWith("intent://")) {
|
||
|
Intent intent = null;
|
||
|
try {
|
||
|
intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
|
||
|
} catch (URISyntaxException ex) {
|
||
|
return false;
|
||
10 years ago
|
}
|
||
10 years ago
|
if (intent != null) {
|
||
|
try {
|
||
|
mActivity.startActivity(intent);
|
||
|
} catch (ActivityNotFoundException e) {
|
||
|
Log.e(Constants.TAG, "ActivityNotFoundException");
|
||
|
}
|
||
|
return true;
|
||
10 years ago
|
}
|
||
10 years ago
|
}
|
||
|
return mIntentUtils.startActivityForUrl(mWebView, url);
|
||
|
}
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
10 years ago
|
public class LightningChromeClient extends WebChromeClient {
|
||
10 years ago
|
|
||
10 years ago
|
Context mActivity;
|
||
10 years ago
|
|
||
10 years ago
|
LightningChromeClient(Context context) {
|
||
|
mActivity = context;
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
@Override
|
||
|
public void onProgressChanged(WebView view, int newProgress) {
|
||
|
if (isShown()) {
|
||
|
mBrowserController.updateProgress(newProgress);
|
||
|
}
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
@Override
|
||
|
public void onReceivedIcon(WebView view, Bitmap icon) {
|
||
|
mTitle.setFavicon(icon);
|
||
|
mBrowserController.update();
|
||
9 years ago
|
cacheFavicon(icon);
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
10 years ago
|
@Override
|
||
|
public void onReceivedTitle(WebView view, String title) {
|
||
|
if (!title.isEmpty()) {
|
||
|
mTitle.setTitle(title);
|
||
|
} else {
|
||
|
mTitle.setTitle(mActivity.getString(R.string.untitled));
|
||
|
}
|
||
|
mBrowserController.update();
|
||
|
mBrowserController.updateHistory(title, view.getUrl());
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
@Override
|
||
|
public void onGeolocationPermissionsShowPrompt(final String origin,
|
||
|
final GeolocationPermissions.Callback callback) {
|
||
|
final boolean remember = true;
|
||
|
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
|
||
|
builder.setTitle(mActivity.getString(R.string.location));
|
||
|
String org = null;
|
||
|
if (origin.length() > 50) {
|
||
|
org = origin.subSequence(0, 50) + "...";
|
||
|
} else {
|
||
|
org = origin;
|
||
|
}
|
||
|
builder.setMessage(org + mActivity.getString(R.string.message_location))
|
||
|
.setCancelable(true)
|
||
|
.setPositiveButton(mActivity.getString(R.string.action_allow),
|
||
|
new DialogInterface.OnClickListener() {
|
||
|
@Override
|
||
|
public void onClick(DialogInterface dialog, int id) {
|
||
|
callback.invoke(origin, true, remember);
|
||
|
}
|
||
|
})
|
||
|
.setNegativeButton(mActivity.getString(R.string.action_dont_allow),
|
||
|
new DialogInterface.OnClickListener() {
|
||
|
@Override
|
||
|
public void onClick(DialogInterface dialog, int id) {
|
||
|
callback.invoke(origin, false, remember);
|
||
|
}
|
||
|
});
|
||
|
AlertDialog alert = builder.create();
|
||
|
alert.show();
|
||
10 years ago
|
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
10 years ago
|
@Override
|
||
|
public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture,
|
||
|
Message resultMsg) {
|
||
|
mBrowserController.onCreateWindow(isUserGesture, resultMsg);
|
||
10 years ago
|
return true;
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
10 years ago
|
@Override
|
||
|
public void onCloseWindow(WebView window) {
|
||
|
// TODO Auto-generated method stub
|
||
|
super.onCloseWindow(window);
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
public void openFileChooser(ValueCallback<Uri> uploadMsg) {
|
||
|
mBrowserController.openFileChooser(uploadMsg);
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) {
|
||
|
mBrowserController.openFileChooser(uploadMsg);
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
|
||
|
mBrowserController.openFileChooser(uploadMsg);
|
||
|
}
|
||
10 years ago
|
|
||
9 years ago
|
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback,
|
||
|
WebChromeClient.FileChooserParams fileChooserParams) {
|
||
|
mBrowserController.showFileChooser(filePathCallback);
|
||
|
return true;
|
||
|
}
|
||
|
|
||
10 years ago
|
@Override
|
||
|
public Bitmap getDefaultVideoPoster() {
|
||
|
return mBrowserController.getDefaultVideoPoster();
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
@Override
|
||
|
public View getVideoLoadingProgressView() {
|
||
|
return mBrowserController.getVideoLoadingProgressView();
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
@Override
|
||
|
public void onHideCustomView() {
|
||
|
mBrowserController.onHideCustomView();
|
||
|
super.onHideCustomView();
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
@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
|
||
|
// if (view instanceof FrameLayout) {
|
||
|
// FrameLayout frame = (FrameLayout) view;
|
||
|
// if (frame.getFocusedChild() instanceof VideoView) {
|
||
|
// VideoView video = (VideoView) frame.getFocusedChild();
|
||
|
// video.stopPlayback();
|
||
|
// frame.removeView(video);
|
||
|
// video.setVisibility(View.GONE);
|
||
|
// }
|
||
|
// } else {
|
||
|
Activity activity = mBrowserController.getActivity();
|
||
|
mBrowserController.onShowCustomView(view, activity.getRequestedOrientation(), callback);
|
||
|
|
||
|
// }
|
||
|
|
||
|
super.onShowCustomView(view, callback);
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
@Override
|
||
|
@Deprecated
|
||
|
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
|
||
|
// if (view instanceof FrameLayout) {
|
||
|
// FrameLayout frame = (FrameLayout) view;
|
||
|
// if (frame.getFocusedChild() instanceof VideoView) {
|
||
|
// VideoView video = (VideoView) frame.getFocusedChild();
|
||
|
// video.stopPlayback();
|
||
|
// frame.removeView(video);
|
||
|
// video.setVisibility(View.GONE);
|
||
|
// }
|
||
|
// } else {
|
||
|
mBrowserController.onShowCustomView(view, requestedOrientation, callback);
|
||
|
|
||
|
// }
|
||
|
|
||
|
super.onShowCustomView(view, requestedOrientation, callback);
|
||
|
}
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
10 years ago
|
public class Title {
|
||
10 years ago
|
|
||
10 years ago
|
private Bitmap mFavicon;
|
||
|
private String mTitle;
|
||
|
private Bitmap mDefaultIcon;
|
||
10 years ago
|
|
||
9 years ago
|
public Title(Context context, boolean darkTheme) {
|
||
9 years ago
|
mDefaultIcon = Utils.getWebpageBitmap(context.getResources(), darkTheme);
|
||
10 years ago
|
mFavicon = mDefaultIcon;
|
||
|
mTitle = mActivity.getString(R.string.action_new_tab);
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
public void setFavicon(Bitmap favicon) {
|
||
9 years ago
|
if (favicon == null) {
|
||
10 years ago
|
mFavicon = mDefaultIcon;
|
||
9 years ago
|
} else {
|
||
9 years ago
|
mFavicon = Utils.padFavicon(favicon);
|
||
10 years ago
|
}
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
public void setTitle(String title) {
|
||
|
if (title == null) {
|
||
|
mTitle = "";
|
||
|
} else {
|
||
|
mTitle = title;
|
||
|
}
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
public void setTitleAndFavicon(String title, Bitmap favicon) {
|
||
|
mTitle = title;
|
||
9 years ago
|
|
||
9 years ago
|
if (favicon == null) {
|
||
10 years ago
|
mFavicon = mDefaultIcon;
|
||
9 years ago
|
} else {
|
||
9 years ago
|
mFavicon = Utils.padFavicon(favicon);
|
||
10 years ago
|
}
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
public String getTitle() {
|
||
|
return mTitle;
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
public Bitmap getFavicon() {
|
||
|
return mFavicon;
|
||
|
}
|
||
9 years ago
|
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
9 years ago
|
private class TouchListener implements OnTouchListener {
|
||
|
|
||
9 years ago
|
float mLocation;
|
||
9 years ago
|
float mY;
|
||
|
int mAction;
|
||
|
|
||
|
@SuppressLint("ClickableViewAccessibility")
|
||
|
@Override
|
||
|
public boolean onTouch(View view, MotionEvent arg1) {
|
||
|
if (view != null && !view.hasFocus()) {
|
||
|
view.requestFocus();
|
||
|
}
|
||
|
mAction = arg1.getAction();
|
||
|
mY = arg1.getY();
|
||
|
if (mAction == MotionEvent.ACTION_DOWN) {
|
||
|
mLocation = mY;
|
||
|
} else if (mAction == MotionEvent.ACTION_UP) {
|
||
9 years ago
|
if ((mY - mLocation) > SCROLL_DOWN_THRESHOLD) {
|
||
9 years ago
|
if (mWebView.getScrollY() != 0) {
|
||
|
mBrowserController.showActionBar();
|
||
|
} else {
|
||
|
mBrowserController.toggleActionBar();
|
||
|
}
|
||
9 years ago
|
} else if ((mY - mLocation) < -SCROLL_UP_THRESHOLD) {
|
||
9 years ago
|
mBrowserController.hideActionBar();
|
||
|
}
|
||
|
mLocation = 0;
|
||
|
}
|
||
|
mGestureDetector.onTouchEvent(arg1);
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
10 years ago
|
private class CustomGestureListener extends SimpleOnGestureListener {
|
||
10 years ago
|
|
||
10 years ago
|
/**
|
||
9 years ago
|
* Without this, onLongPress is not called when user is zooming using
|
||
|
* two fingers, but is when using only one.
|
||
|
*
|
||
|
* The required behaviour is to not trigger this when the user is
|
||
|
* zooming, it shouldn't matter how much fingers the user's using.
|
||
10 years ago
|
*/
|
||
|
private boolean mCanTriggerLongPress = true;
|
||
|
|
||
10 years ago
|
@Override
|
||
|
public void onLongPress(MotionEvent e) {
|
||
9 years ago
|
if (mCanTriggerLongPress)
|
||
10 years ago
|
mBrowserController.onLongPress();
|
||
|
}
|
||
|
|
||
|
/**
|
||
9 years ago
|
* Is called when the user is swiping after the doubletap, which in our
|
||
|
* case means that he is zooming.
|
||
10 years ago
|
*/
|
||
|
@Override
|
||
|
public boolean onDoubleTapEvent(MotionEvent e) {
|
||
|
mCanTriggerLongPress = false;
|
||
|
return false;
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
10 years ago
|
/**
|
||
9 years ago
|
* Is called when something is starting being pressed, always before
|
||
|
* onLongPress.
|
||
10 years ago
|
*/
|
||
|
@Override
|
||
|
public void onShowPress(MotionEvent e) {
|
||
|
mCanTriggerLongPress = true;
|
||
|
}
|
||
10 years ago
|
}
|
||
|
}
|