|
|
@ -67,39 +67,43 @@ import acr.browser.lightning.utils.Utils; |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class LightningView { |
|
|
|
public class LightningView { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final String TAG = LightningView.class.getSimpleName(); |
|
|
|
|
|
|
|
|
|
|
|
public static final String HEADER_REQUESTED_WITH = "X-Requested-With"; |
|
|
|
public static final String HEADER_REQUESTED_WITH = "X-Requested-With"; |
|
|
|
public static final String HEADER_WAP_PROFILE = "X-Wap-Profile"; |
|
|
|
public static final String HEADER_WAP_PROFILE = "X-Wap-Profile"; |
|
|
|
private static final String HEADER_DNT = "DNT"; |
|
|
|
private static final String HEADER_DNT = "DNT"; |
|
|
|
|
|
|
|
|
|
|
|
@NonNull private final LightningViewTitle mTitle; |
|
|
|
|
|
|
|
@Nullable private WebView mWebView; |
|
|
|
|
|
|
|
private final boolean mIsIncognitoTab; |
|
|
|
|
|
|
|
@NonNull private final UIController mUIController; |
|
|
|
|
|
|
|
@NonNull private final GestureDetector mGestureDetector; |
|
|
|
|
|
|
|
@NonNull private final Activity mActivity; |
|
|
|
|
|
|
|
private static String mHomepage; |
|
|
|
|
|
|
|
private static String mDefaultUserAgent; |
|
|
|
|
|
|
|
private final Paint mPaint = new Paint(); |
|
|
|
|
|
|
|
private boolean isForegroundTab; |
|
|
|
|
|
|
|
private boolean mInvertPage = false; |
|
|
|
|
|
|
|
private boolean mToggleDesktop = false; |
|
|
|
|
|
|
|
private static float mMaxFling; |
|
|
|
|
|
|
|
private static final int API = android.os.Build.VERSION.SDK_INT; |
|
|
|
private static final int API = android.os.Build.VERSION.SDK_INT; |
|
|
|
private static final int SCROLL_UP_THRESHOLD = Utils.dpToPx(10); |
|
|
|
private static final int SCROLL_UP_THRESHOLD = Utils.dpToPx(10); |
|
|
|
private static final float[] mNegativeColorArray = { |
|
|
|
|
|
|
|
|
|
|
|
private static String sHomepage; |
|
|
|
|
|
|
|
private static String sDefaultUserAgent; |
|
|
|
|
|
|
|
private static float mMaxFling; |
|
|
|
|
|
|
|
private static final float[] sNegativeColorArray = { |
|
|
|
-1.0f, 0, 0, 0, 255, // red
|
|
|
|
-1.0f, 0, 0, 0, 255, // red
|
|
|
|
0, -1.0f, 0, 0, 255, // green
|
|
|
|
0, -1.0f, 0, 0, 255, // green
|
|
|
|
0, 0, -1.0f, 0, 255, // blue
|
|
|
|
0, 0, -1.0f, 0, 255, // blue
|
|
|
|
0, 0, 0, 1.0f, 0 // alpha
|
|
|
|
0, 0, 0, 1.0f, 0 // alpha
|
|
|
|
}; |
|
|
|
}; |
|
|
|
private static final float[] mIncreaseContrastColorArray = { |
|
|
|
private static final float[] sIncreaseContrastColorArray = { |
|
|
|
2.0f, 0, 0, 0, -160.f, // red
|
|
|
|
2.0f, 0, 0, 0, -160.f, // red
|
|
|
|
0, 2.0f, 0, 0, -160.f, // green
|
|
|
|
0, 2.0f, 0, 0, -160.f, // green
|
|
|
|
0, 0, 2.0f, 0, -160.f, // blue
|
|
|
|
0, 0, 2.0f, 0, -160.f, // blue
|
|
|
|
0, 0, 0, 1.0f, 0 // alpha
|
|
|
|
0, 0, 0, 1.0f, 0 // alpha
|
|
|
|
}; |
|
|
|
}; |
|
|
|
private final WebViewHandler mWebViewHandler = new WebViewHandler(this); |
|
|
|
|
|
|
|
private final Map<String, String> mRequestHeaders = new ArrayMap<>(); |
|
|
|
@NonNull private final LightningViewTitle mTitle; |
|
|
|
|
|
|
|
@Nullable private WebView mWebView; |
|
|
|
|
|
|
|
@NonNull private final UIController mUIController; |
|
|
|
|
|
|
|
@NonNull private final GestureDetector mGestureDetector; |
|
|
|
|
|
|
|
@NonNull private final Activity mActivity; |
|
|
|
|
|
|
|
@NonNull private final Paint mPaint = new Paint(); |
|
|
|
|
|
|
|
@Nullable private Object mTag; |
|
|
|
|
|
|
|
private final boolean mIsIncognitoTab; |
|
|
|
|
|
|
|
private boolean isForegroundTab; |
|
|
|
|
|
|
|
private boolean mInvertPage = false; |
|
|
|
|
|
|
|
private boolean mToggleDesktop = false; |
|
|
|
|
|
|
|
@NonNull private final WebViewHandler mWebViewHandler = new WebViewHandler(this); |
|
|
|
|
|
|
|
@NonNull private final Map<String, String> mRequestHeaders = new ArrayMap<>(); |
|
|
|
|
|
|
|
|
|
|
|
@Inject Bus mEventBus; |
|
|
|
@Inject Bus mEventBus; |
|
|
|
@Inject PreferenceManager mPreferences; |
|
|
|
@Inject PreferenceManager mPreferences; |
|
|
@ -107,7 +111,6 @@ public class LightningView { |
|
|
|
@Inject ProxyUtils mProxyUtils; |
|
|
|
@Inject ProxyUtils mProxyUtils; |
|
|
|
@Inject BookmarkManager mBookmarkManager; |
|
|
|
@Inject BookmarkManager mBookmarkManager; |
|
|
|
|
|
|
|
|
|
|
|
@SuppressLint("NewApi") |
|
|
|
|
|
|
|
public LightningView(@NonNull Activity activity, @Nullable String url, boolean isIncognito) { |
|
|
|
public LightningView(@NonNull Activity activity, @Nullable String url, boolean isIncognito) { |
|
|
|
BrowserApp.getAppComponent().inject(this); |
|
|
|
BrowserApp.getAppComponent().inject(this); |
|
|
|
mActivity = activity; |
|
|
|
mActivity = activity; |
|
|
@ -139,7 +142,7 @@ public class LightningView { |
|
|
|
mWebView.setDownloadListener(new LightningDownloadListener(activity)); |
|
|
|
mWebView.setDownloadListener(new LightningDownloadListener(activity)); |
|
|
|
mGestureDetector = new GestureDetector(activity, new CustomGestureListener()); |
|
|
|
mGestureDetector = new GestureDetector(activity, new CustomGestureListener()); |
|
|
|
mWebView.setOnTouchListener(new TouchListener()); |
|
|
|
mWebView.setOnTouchListener(new TouchListener()); |
|
|
|
mDefaultUserAgent = mWebView.getSettings().getUserAgentString(); |
|
|
|
sDefaultUserAgent = mWebView.getSettings().getUserAgentString(); |
|
|
|
initializeSettings(); |
|
|
|
initializeSettings(); |
|
|
|
initializePreferences(activity); |
|
|
|
initializePreferences(activity); |
|
|
|
|
|
|
|
|
|
|
@ -154,6 +157,28 @@ public class LightningView { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Sets the tag on the object, |
|
|
|
|
|
|
|
* a reference to this object is held |
|
|
|
|
|
|
|
* indefinitely. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param tag the tag to set, may be null. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public void setTag(@Nullable Object tag) { |
|
|
|
|
|
|
|
mTag = tag; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* The tag set on the object. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @return the tag set on the object, |
|
|
|
|
|
|
|
* may be null. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@Nullable |
|
|
|
|
|
|
|
public Object getTag() { |
|
|
|
|
|
|
|
return mTag; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* This method loads the homepage for the browser. Either |
|
|
|
* This method loads the homepage for the browser. Either |
|
|
|
* it loads the URL stored as the homepage, or loads the |
|
|
|
* it loads the URL stored as the homepage, or loads the |
|
|
@ -164,7 +189,7 @@ public class LightningView { |
|
|
|
if (mWebView == null) { |
|
|
|
if (mWebView == null) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
switch (mHomepage) { |
|
|
|
switch (sHomepage) { |
|
|
|
case "about:home": |
|
|
|
case "about:home": |
|
|
|
loadStartpage(); |
|
|
|
loadStartpage(); |
|
|
|
break; |
|
|
|
break; |
|
|
@ -172,7 +197,7 @@ public class LightningView { |
|
|
|
loadBookmarkpage(); |
|
|
|
loadBookmarkpage(); |
|
|
|
break; |
|
|
|
break; |
|
|
|
default: |
|
|
|
default: |
|
|
|
mWebView.loadUrl(mHomepage, mRequestHeaders); |
|
|
|
mWebView.loadUrl(sHomepage, mRequestHeaders); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -227,7 +252,7 @@ public class LightningView { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
settings.setDefaultTextEncodingName(mPreferences.getTextEncoding()); |
|
|
|
settings.setDefaultTextEncodingName(mPreferences.getTextEncoding()); |
|
|
|
mHomepage = mPreferences.getHomepage(); |
|
|
|
sHomepage = mPreferences.getHomepage(); |
|
|
|
setColorMode(mPreferences.getRenderingMode()); |
|
|
|
setColorMode(mPreferences.getRenderingMode()); |
|
|
|
|
|
|
|
|
|
|
|
if (!mIsIncognitoTab) { |
|
|
|
if (!mIsIncognitoTab) { |
|
|
@ -286,7 +311,7 @@ public class LightningView { |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
// This shouldn't be necessary, but there are a number
|
|
|
|
// This shouldn't be necessary, but there are a number
|
|
|
|
// of KitKat devices that crash trying to set this
|
|
|
|
// of KitKat devices that crash trying to set this
|
|
|
|
Log.e(Constants.TAG, "Problem setting LayoutAlgorithm to TEXT_AUTOSIZING"); |
|
|
|
Log.e(TAG, "Problem setting LayoutAlgorithm to TEXT_AUTOSIZING"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -376,7 +401,8 @@ public class LightningView { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
getPathObservable("appcache") |
|
|
|
getPathObservable("appcache") |
|
|
|
.subscribeOn(Schedulers.worker()) |
|
|
|
.subscribeOn(Schedulers.io()) |
|
|
|
|
|
|
|
.observeOn(Schedulers.main()) |
|
|
|
.subscribe(new OnSubscribe<File>() { |
|
|
|
.subscribe(new OnSubscribe<File>() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onNext(File item) { |
|
|
|
public void onNext(File item) { |
|
|
@ -388,7 +414,8 @@ public class LightningView { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
getPathObservable("geolocation") |
|
|
|
getPathObservable("geolocation") |
|
|
|
.subscribeOn(Schedulers.worker()) |
|
|
|
.subscribeOn(Schedulers.io()) |
|
|
|
|
|
|
|
.observeOn(Schedulers.main()) |
|
|
|
.subscribe(new OnSubscribe<File>() { |
|
|
|
.subscribe(new OnSubscribe<File>() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onNext(File item) { |
|
|
|
public void onNext(File item) { |
|
|
@ -400,7 +427,8 @@ public class LightningView { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
getPathObservable("databases") |
|
|
|
getPathObservable("databases") |
|
|
|
.subscribeOn(Schedulers.worker()) |
|
|
|
.subscribeOn(Schedulers.io()) |
|
|
|
|
|
|
|
.observeOn(Schedulers.main()) |
|
|
|
.subscribe(new OnSubscribe<File>() { |
|
|
|
.subscribe(new OnSubscribe<File>() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onNext(File item) { |
|
|
|
public void onNext(File item) { |
|
|
@ -488,7 +516,7 @@ public class LightningView { |
|
|
|
if (API >= Build.VERSION_CODES.JELLY_BEAN_MR1) { |
|
|
|
if (API >= Build.VERSION_CODES.JELLY_BEAN_MR1) { |
|
|
|
settings.setUserAgentString(WebSettings.getDefaultUserAgent(context)); |
|
|
|
settings.setUserAgentString(WebSettings.getDefaultUserAgent(context)); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
settings.setUserAgentString(mDefaultUserAgent); |
|
|
|
settings.setUserAgentString(sDefaultUserAgent); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 2: |
|
|
|
case 2: |
|
|
@ -498,7 +526,7 @@ public class LightningView { |
|
|
|
settings.setUserAgentString(Constants.MOBILE_USER_AGENT); |
|
|
|
settings.setUserAgentString(Constants.MOBILE_USER_AGENT); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 4: |
|
|
|
case 4: |
|
|
|
String ua = mPreferences.getUserAgentString(mDefaultUserAgent); |
|
|
|
String ua = mPreferences.getUserAgentString(sDefaultUserAgent); |
|
|
|
if (ua == null || ua.isEmpty()) { |
|
|
|
if (ua == null || ua.isEmpty()) { |
|
|
|
ua = " "; |
|
|
|
ua = " "; |
|
|
|
} |
|
|
|
} |
|
|
@ -663,7 +691,7 @@ public class LightningView { |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 1: |
|
|
|
case 1: |
|
|
|
ColorMatrixColorFilter filterInvert = new ColorMatrixColorFilter( |
|
|
|
ColorMatrixColorFilter filterInvert = new ColorMatrixColorFilter( |
|
|
|
mNegativeColorArray); |
|
|
|
sNegativeColorArray); |
|
|
|
mPaint.setColorFilter(filterInvert); |
|
|
|
mPaint.setColorFilter(filterInvert); |
|
|
|
setHardwareRendering(); |
|
|
|
setHardwareRendering(); |
|
|
|
|
|
|
|
|
|
|
@ -678,7 +706,7 @@ public class LightningView { |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 3: |
|
|
|
case 3: |
|
|
|
ColorMatrix matrix = new ColorMatrix(); |
|
|
|
ColorMatrix matrix = new ColorMatrix(); |
|
|
|
matrix.set(mNegativeColorArray); |
|
|
|
matrix.set(sNegativeColorArray); |
|
|
|
ColorMatrix matrixGray = new ColorMatrix(); |
|
|
|
ColorMatrix matrixGray = new ColorMatrix(); |
|
|
|
matrixGray.setSaturation(0); |
|
|
|
matrixGray.setSaturation(0); |
|
|
|
ColorMatrix concat = new ColorMatrix(); |
|
|
|
ColorMatrix concat = new ColorMatrix(); |
|
|
@ -692,7 +720,7 @@ public class LightningView { |
|
|
|
|
|
|
|
|
|
|
|
case 4: |
|
|
|
case 4: |
|
|
|
ColorMatrixColorFilter IncreaseHighContrast = new ColorMatrixColorFilter( |
|
|
|
ColorMatrixColorFilter IncreaseHighContrast = new ColorMatrixColorFilter( |
|
|
|
mIncreaseContrastColorArray); |
|
|
|
sIncreaseContrastColorArray); |
|
|
|
mPaint.setColorFilter(IncreaseHighContrast); |
|
|
|
mPaint.setColorFilter(IncreaseHighContrast); |
|
|
|
setHardwareRendering(); |
|
|
|
setHardwareRendering(); |
|
|
|
break; |
|
|
|
break; |
|
|
@ -800,7 +828,7 @@ public class LightningView { |
|
|
|
// before calling destroy() so that a memory leak is not created
|
|
|
|
// before calling destroy() so that a memory leak is not created
|
|
|
|
ViewGroup parent = (ViewGroup) mWebView.getParent(); |
|
|
|
ViewGroup parent = (ViewGroup) mWebView.getParent(); |
|
|
|
if (parent != null) { |
|
|
|
if (parent != null) { |
|
|
|
Log.e(Constants.TAG, "WebView was not detached from window before onDestroy"); |
|
|
|
Log.e(TAG, "WebView was not detached from window before onDestroy"); |
|
|
|
parent.removeView(mWebView); |
|
|
|
parent.removeView(mWebView); |
|
|
|
} |
|
|
|
} |
|
|
|
mWebView.stopLoading(); |
|
|
|
mWebView.stopLoading(); |
|
|
|