|
|
@ -69,10 +69,10 @@ public class LightningView { |
|
|
|
|
|
|
|
|
|
|
|
private final Title mTitle; |
|
|
|
private final Title mTitle; |
|
|
|
private WebView mWebView; |
|
|
|
private WebView mWebView; |
|
|
|
|
|
|
|
private boolean mIsIncognitoTab; |
|
|
|
private BrowserController mBrowserController; |
|
|
|
private BrowserController mBrowserController; |
|
|
|
private GestureDetector mGestureDetector; |
|
|
|
private GestureDetector mGestureDetector; |
|
|
|
private final Activity mActivity; |
|
|
|
private final Activity mActivity; |
|
|
|
private WebSettings mSettings; |
|
|
|
|
|
|
|
private static String mHomepage; |
|
|
|
private static String mHomepage; |
|
|
|
private static String mDefaultUserAgent; |
|
|
|
private static String mDefaultUserAgent; |
|
|
|
private static Bitmap mWebpageBitmap; |
|
|
|
private static Bitmap mWebpageBitmap; |
|
|
@ -93,10 +93,11 @@ public class LightningView { |
|
|
|
0, 0, 0, 1.0f, 0 // alpha
|
|
|
|
0, 0, 0, 1.0f, 0 // alpha
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
public LightningView(Activity activity, String url, boolean darkTheme) { |
|
|
|
public LightningView(Activity activity, String url, boolean darkTheme, boolean isIncognito) { |
|
|
|
|
|
|
|
|
|
|
|
mActivity = activity; |
|
|
|
mActivity = activity; |
|
|
|
mWebView = new WebView(activity); |
|
|
|
mWebView = new WebView(activity); |
|
|
|
|
|
|
|
mIsIncognitoTab = isIncognito; |
|
|
|
mTitle = new Title(activity, darkTheme); |
|
|
|
mTitle = new Title(activity, darkTheme); |
|
|
|
mAdBlock = AdBlock.getInstance(activity.getApplicationContext()); |
|
|
|
mAdBlock = AdBlock.getInstance(activity.getApplicationContext()); |
|
|
|
|
|
|
|
|
|
|
@ -134,9 +135,8 @@ public class LightningView { |
|
|
|
mGestureDetector = new GestureDetector(activity, new CustomGestureListener()); |
|
|
|
mGestureDetector = new GestureDetector(activity, new CustomGestureListener()); |
|
|
|
mWebView.setOnTouchListener(new TouchListener()); |
|
|
|
mWebView.setOnTouchListener(new TouchListener()); |
|
|
|
mDefaultUserAgent = mWebView.getSettings().getUserAgentString(); |
|
|
|
mDefaultUserAgent = mWebView.getSettings().getUserAgentString(); |
|
|
|
mSettings = mWebView.getSettings(); |
|
|
|
|
|
|
|
initializeSettings(mWebView.getSettings(), activity); |
|
|
|
initializeSettings(mWebView.getSettings(), activity); |
|
|
|
initializePreferences(activity); |
|
|
|
initializePreferences(mWebView.getSettings(), activity); |
|
|
|
|
|
|
|
|
|
|
|
if (url != null) { |
|
|
|
if (url != null) { |
|
|
|
if (!url.trim().isEmpty()) { |
|
|
|
if (!url.trim().isEmpty()) { |
|
|
@ -155,6 +155,12 @@ public class LightningView { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* This method builds the homepage and returns the local URL to be loaded |
|
|
|
|
|
|
|
* when it finishes building. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @return the URL to load |
|
|
|
|
|
|
|
*/ |
|
|
|
private String getHomepage() { |
|
|
|
private String getHomepage() { |
|
|
|
StringBuilder homepageBuilder = new StringBuilder(); |
|
|
|
StringBuilder homepageBuilder = new StringBuilder(); |
|
|
|
homepageBuilder.append(StartPage.HEAD); |
|
|
|
homepageBuilder.append(StartPage.HEAD); |
|
|
@ -252,35 +258,42 @@ public class LightningView { |
|
|
|
return Constants.FILE + homepage; |
|
|
|
return Constants.FILE + homepage; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public synchronized void initializePreferences(Context context) { |
|
|
|
/** |
|
|
|
|
|
|
|
* Initialize the preference driven settings of the WebView |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param settings the WebSettings object to use, you can pass in null |
|
|
|
|
|
|
|
* if you don't have a reference to them |
|
|
|
|
|
|
|
* @param context the context in which the WebView was created |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public synchronized void initializePreferences(@Nullable WebSettings settings, Context context) { |
|
|
|
|
|
|
|
if (settings == null && mWebView == null) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} else if (settings == null) { |
|
|
|
|
|
|
|
settings = mWebView.getSettings(); |
|
|
|
|
|
|
|
} |
|
|
|
mPreferences = PreferenceManager.getInstance(); |
|
|
|
mPreferences = PreferenceManager.getInstance(); |
|
|
|
|
|
|
|
|
|
|
|
mSettings.setDefaultTextEncodingName(mPreferences.getTextEncoding()); |
|
|
|
settings.setDefaultTextEncodingName(mPreferences.getTextEncoding()); |
|
|
|
mHomepage = mPreferences.getHomepage(); |
|
|
|
mHomepage = mPreferences.getHomepage(); |
|
|
|
mAdBlock.updatePreference(); |
|
|
|
mAdBlock.updatePreference(); |
|
|
|
if (mSettings == null && mWebView != null) { |
|
|
|
|
|
|
|
mSettings = mWebView.getSettings(); |
|
|
|
|
|
|
|
} else if (mSettings == null) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setColorMode(mPreferences.getRenderingMode()); |
|
|
|
setColorMode(mPreferences.getRenderingMode()); |
|
|
|
|
|
|
|
|
|
|
|
if (!mBrowserController.isIncognito()) { |
|
|
|
if (!mIsIncognitoTab) { |
|
|
|
mSettings.setGeolocationEnabled(mPreferences.getLocationEnabled()); |
|
|
|
settings.setGeolocationEnabled(mPreferences.getLocationEnabled()); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
mSettings.setGeolocationEnabled(false); |
|
|
|
settings.setGeolocationEnabled(false); |
|
|
|
} |
|
|
|
} |
|
|
|
if (API < 19) { |
|
|
|
if (API < 19) { |
|
|
|
switch (mPreferences.getFlashSupport()) { |
|
|
|
switch (mPreferences.getFlashSupport()) { |
|
|
|
case 0: |
|
|
|
case 0: |
|
|
|
mSettings.setPluginState(PluginState.OFF); |
|
|
|
settings.setPluginState(PluginState.OFF); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 1: |
|
|
|
case 1: |
|
|
|
mSettings.setPluginState(PluginState.ON_DEMAND); |
|
|
|
settings.setPluginState(PluginState.ON_DEMAND); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 2: |
|
|
|
case 2: |
|
|
|
mSettings.setPluginState(PluginState.ON); |
|
|
|
settings.setPluginState(PluginState.ON); |
|
|
|
break; |
|
|
|
break; |
|
|
|
default: |
|
|
|
default: |
|
|
|
break; |
|
|
|
break; |
|
|
@ -289,29 +302,29 @@ public class LightningView { |
|
|
|
|
|
|
|
|
|
|
|
setUserAgent(context, mPreferences.getUserAgentChoice()); |
|
|
|
setUserAgent(context, mPreferences.getUserAgentChoice()); |
|
|
|
|
|
|
|
|
|
|
|
if (mPreferences.getSavePasswordsEnabled() && !mBrowserController.isIncognito()) { |
|
|
|
if (mPreferences.getSavePasswordsEnabled() && !mIsIncognitoTab) { |
|
|
|
if (API < 18) { |
|
|
|
if (API < 18) { |
|
|
|
mSettings.setSavePassword(true); |
|
|
|
settings.setSavePassword(true); |
|
|
|
} |
|
|
|
} |
|
|
|
mSettings.setSaveFormData(true); |
|
|
|
settings.setSaveFormData(true); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if (API < 18) { |
|
|
|
if (API < 18) { |
|
|
|
mSettings.setSavePassword(false); |
|
|
|
settings.setSavePassword(false); |
|
|
|
} |
|
|
|
} |
|
|
|
mSettings.setSaveFormData(false); |
|
|
|
settings.setSaveFormData(false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (mPreferences.getJavaScriptEnabled()) { |
|
|
|
if (mPreferences.getJavaScriptEnabled()) { |
|
|
|
mSettings.setJavaScriptEnabled(true); |
|
|
|
settings.setJavaScriptEnabled(true); |
|
|
|
mSettings.setJavaScriptCanOpenWindowsAutomatically(true); |
|
|
|
settings.setJavaScriptCanOpenWindowsAutomatically(true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (mPreferences.getTextReflowEnabled()) { |
|
|
|
if (mPreferences.getTextReflowEnabled()) { |
|
|
|
mTextReflow = true; |
|
|
|
mTextReflow = true; |
|
|
|
mSettings.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS); |
|
|
|
settings.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS); |
|
|
|
if (API >= android.os.Build.VERSION_CODES.KITKAT) { |
|
|
|
if (API >= android.os.Build.VERSION_CODES.KITKAT) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
mSettings.setLayoutAlgorithm(LayoutAlgorithm.TEXT_AUTOSIZING); |
|
|
|
settings.setLayoutAlgorithm(LayoutAlgorithm.TEXT_AUTOSIZING); |
|
|
|
} 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
|
|
|
@ -320,31 +333,35 @@ public class LightningView { |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
mTextReflow = false; |
|
|
|
mTextReflow = false; |
|
|
|
mSettings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL); |
|
|
|
settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
mSettings.setBlockNetworkImage(mPreferences.getBlockImagesEnabled()); |
|
|
|
settings.setBlockNetworkImage(mPreferences.getBlockImagesEnabled()); |
|
|
|
mSettings.setSupportMultipleWindows(mPreferences.getPopupsEnabled()); |
|
|
|
if (!mIsIncognitoTab) { |
|
|
|
mSettings.setUseWideViewPort(mPreferences.getUseWideViewportEnabled()); |
|
|
|
settings.setSupportMultipleWindows(mPreferences.getPopupsEnabled()); |
|
|
|
mSettings.setLoadWithOverviewMode(mPreferences.getOverviewModeEnabled()); |
|
|
|
} else { |
|
|
|
|
|
|
|
settings.setSupportMultipleWindows(false); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
settings.setUseWideViewPort(mPreferences.getUseWideViewportEnabled()); |
|
|
|
|
|
|
|
settings.setLoadWithOverviewMode(mPreferences.getOverviewModeEnabled()); |
|
|
|
switch (mPreferences.getTextSize()) { |
|
|
|
switch (mPreferences.getTextSize()) { |
|
|
|
case 0: |
|
|
|
case 0: |
|
|
|
mSettings.setTextZoom(200); |
|
|
|
settings.setTextZoom(200); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 1: |
|
|
|
case 1: |
|
|
|
mSettings.setTextZoom(150); |
|
|
|
settings.setTextZoom(150); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 2: |
|
|
|
case 2: |
|
|
|
mSettings.setTextZoom(125); |
|
|
|
settings.setTextZoom(125); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 3: |
|
|
|
case 3: |
|
|
|
mSettings.setTextZoom(100); |
|
|
|
settings.setTextZoom(100); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 4: |
|
|
|
case 4: |
|
|
|
mSettings.setTextZoom(75); |
|
|
|
settings.setTextZoom(75); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 5: |
|
|
|
case 5: |
|
|
|
mSettings.setTextZoom(50); |
|
|
|
settings.setTextZoom(50); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { |
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { |
|
|
@ -353,6 +370,13 @@ public class LightningView { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Initialize the settings of the WebView that are intrinsic to Lightning and cannot |
|
|
|
|
|
|
|
* be altered by the user. Distinguish between Incognito and Regular tabs here. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param settings the WebSettings object to use. |
|
|
|
|
|
|
|
* @param context the Context which was used to construct the WebView. |
|
|
|
|
|
|
|
*/ |
|
|
|
private void initializeSettings(WebSettings settings, Context context) { |
|
|
|
private void initializeSettings(WebSettings settings, Context context) { |
|
|
|
if (API < Build.VERSION_CODES.JELLY_BEAN_MR2) { |
|
|
|
if (API < Build.VERSION_CODES.JELLY_BEAN_MR2) { |
|
|
|
settings.setAppCacheMaxSize(Long.MAX_VALUE); |
|
|
|
settings.setAppCacheMaxSize(Long.MAX_VALUE); |
|
|
@ -363,16 +387,23 @@ public class LightningView { |
|
|
|
if (API > Build.VERSION_CODES.JELLY_BEAN) { |
|
|
|
if (API > Build.VERSION_CODES.JELLY_BEAN) { |
|
|
|
settings.setMediaPlaybackRequiresUserGesture(true); |
|
|
|
settings.setMediaPlaybackRequiresUserGesture(true); |
|
|
|
} |
|
|
|
} |
|
|
|
if (API >= Build.VERSION_CODES.LOLLIPOP && !mBrowserController.isIncognito()) { |
|
|
|
if (API >= Build.VERSION_CODES.LOLLIPOP && !mIsIncognitoTab) { |
|
|
|
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE); |
|
|
|
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE); |
|
|
|
} else if (API >= Build.VERSION_CODES.LOLLIPOP) { |
|
|
|
} else if (API >= Build.VERSION_CODES.LOLLIPOP) { |
|
|
|
// We're in Incognito mode, reject
|
|
|
|
// We're in Incognito mode, reject
|
|
|
|
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_NEVER_ALLOW); |
|
|
|
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_NEVER_ALLOW); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!mIsIncognitoTab) { |
|
|
|
settings.setDomStorageEnabled(true); |
|
|
|
settings.setDomStorageEnabled(true); |
|
|
|
settings.setAppCacheEnabled(true); |
|
|
|
settings.setAppCacheEnabled(true); |
|
|
|
settings.setCacheMode(WebSettings.LOAD_DEFAULT); |
|
|
|
settings.setCacheMode(WebSettings.LOAD_DEFAULT); |
|
|
|
settings.setDatabaseEnabled(true); |
|
|
|
settings.setDatabaseEnabled(true); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
settings.setDomStorageEnabled(false); |
|
|
|
|
|
|
|
settings.setAppCacheEnabled(false); |
|
|
|
|
|
|
|
settings.setDatabaseEnabled(false); |
|
|
|
|
|
|
|
settings.setCacheMode(WebSettings.LOAD_NO_CACHE); |
|
|
|
|
|
|
|
} |
|
|
|
settings.setSupportZoom(true); |
|
|
|
settings.setSupportZoom(true); |
|
|
|
settings.setBuiltInZoomControls(true); |
|
|
|
settings.setBuiltInZoomControls(true); |
|
|
|
settings.setDisplayZoomControls(false); |
|
|
|
settings.setDisplayZoomControls(false); |
|
|
@ -401,22 +432,24 @@ public class LightningView { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setUserAgent(Context context, int choice) { |
|
|
|
public void setUserAgent(Context context, int choice) { |
|
|
|
|
|
|
|
if (mWebView == null) return; |
|
|
|
|
|
|
|
WebSettings settings = mWebView.getSettings(); |
|
|
|
switch (choice) { |
|
|
|
switch (choice) { |
|
|
|
case 1: |
|
|
|
case 1: |
|
|
|
if (API > 16) { |
|
|
|
if (API > 16) { |
|
|
|
mSettings.setUserAgentString(WebSettings.getDefaultUserAgent(context)); |
|
|
|
settings.setUserAgentString(WebSettings.getDefaultUserAgent(context)); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
mSettings.setUserAgentString(mDefaultUserAgent); |
|
|
|
settings.setUserAgentString(mDefaultUserAgent); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 2: |
|
|
|
case 2: |
|
|
|
mSettings.setUserAgentString(Constants.DESKTOP_USER_AGENT); |
|
|
|
settings.setUserAgentString(Constants.DESKTOP_USER_AGENT); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 3: |
|
|
|
case 3: |
|
|
|
mSettings.setUserAgentString(Constants.MOBILE_USER_AGENT); |
|
|
|
settings.setUserAgentString(Constants.MOBILE_USER_AGENT); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 4: |
|
|
|
case 4: |
|
|
|
mSettings.setUserAgentString(mPreferences.getUserAgentString(mDefaultUserAgent)); |
|
|
|
settings.setUserAgentString(mPreferences.getUserAgentString(mDefaultUserAgent)); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -854,7 +887,7 @@ public class LightningView { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (mBrowserController.isIncognito()) { |
|
|
|
if (mIsIncognitoTab) { |
|
|
|
return super.shouldOverrideUrlLoading(view, url); |
|
|
|
return super.shouldOverrideUrlLoading(view, url); |
|
|
|
} |
|
|
|
} |
|
|
|
if (url.startsWith("about:")) { |
|
|
|
if (url.startsWith("about:")) { |
|
|
|