diff --git a/README.md b/README.md
index 48f5ef4..96aeed9 100644
--- a/README.md
+++ b/README.md
@@ -52,7 +52,7 @@ Easily reference the library in your Android projects using this dependency in y
```java
dependencies {
- compile 'com.thefinestartist:finestwebview:1.2.7'
+ compile 'aom.andan:webview:1.2.1'
}
```
@@ -343,6 +343,39 @@ new FinestWebView.Builder(activity)
.setCustomAnimations(R.anim.activity_open_enter, R.anim.activity_open_exit, R.anim.activity_close_enter, R.anim.activity_close_exit)
.show(url);
```
+#javascrpit interactive#
+**important** you need to new a class like [JsInteration.java](sample/src/main/java/com/thefinestartist/finestwebview/sample/JsInteration.java)
+
+
+```java
+new FinestWebView.Builder(this).theme(R.style.RedTheme)
+ .titleDefault("Bless This Stuff")
+ .webViewBuiltInZoomControls(true)
+ .webViewDisplayZoomControls(true)
+ .dividerHeight(0)
+ .gradientDivider(false)
+ .webViewJavaScriptEnabled(true)//设置可以和JAVA交互
+ .addJavascriptInterface(new JsInteration())//JS将可以调用该类下面的@JavascriptInterface修饰的方法,此类须implements Serializable
+ .setCustomAnimations(R.anim.activity_open_enter, R.anim.activity_open_exit,
+ R.anim.activity_close_enter, R.anim.activity_close_exit)
+ .show("http://test.2000new.com/nyd/water/index.html");
+```
+
+in yout html code:
+```java
+
+
+```
## More customizations
diff --git a/build.gradle b/build.gradle
index 4fdd43f..7ee1255 100644
--- a/build.gradle
+++ b/build.gradle
@@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
- classpath 'com.android.tools.build:gradle:2.1.3'
+ classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath 'com.novoda:bintray-release:0.3.4'
}
diff --git a/library/src/main/java/com/thefinestartist/finestwebview/BaseJsInteration.java b/library/src/main/java/com/thefinestartist/finestwebview/BaseJsInteration.java
new file mode 100644
index 0000000..7e62b1f
--- /dev/null
+++ b/library/src/main/java/com/thefinestartist/finestwebview/BaseJsInteration.java
@@ -0,0 +1,29 @@
+package com.thefinestartist.finestwebview;
+
+import android.app.Activity;
+import android.webkit.WebView;
+
+/**
+ * Created by Administrator on 2017/2/17.
+ */
+
+public class BaseJsInteration {
+
+ protected Activity instance;
+ protected WebView webView;
+
+ public void setContext(Activity activity){
+ instance=activity;
+ }
+ public Activity getContext(){
+ return instance;
+ }
+
+ public WebView getWebView() {
+ return webView;
+ }
+
+ public void setWebView(WebView webView) {
+ this.webView = webView;
+ }
+}
diff --git a/library/src/main/java/com/thefinestartist/finestwebview/FinestWebView.java b/library/src/main/java/com/thefinestartist/finestwebview/FinestWebView.java
index 70440e8..ee53678 100644
--- a/library/src/main/java/com/thefinestartist/finestwebview/FinestWebView.java
+++ b/library/src/main/java/com/thefinestartist/finestwebview/FinestWebView.java
@@ -14,6 +14,8 @@
import android.support.annotation.StyleRes;
import android.support.design.widget.AppBarLayout.LayoutParams.ScrollFlags;
import android.webkit.WebSettings;
+import android.webkit.WebView;
+
import com.thefinestartist.Base;
import com.thefinestartist.finestwebview.enums.Position;
import com.thefinestartist.finestwebview.listeners.BroadCastManager;
@@ -158,12 +160,13 @@ public static class Builder implements Serializable {
protected Boolean webViewOffscreenPreRaster;
protected String injectJavaScript;
+ protected BaseJsInteration jsInteration;
protected String mimeType;
protected String encoding;
protected String data;
protected String url;
-
+ protected WebView webView;
public Builder(@NonNull Activity activity) {
this.context = activity;
Base.initialize(activity);
@@ -190,6 +193,11 @@ public Builder addWebViewListener(WebViewListener listener) {
return this;
}
+ public Builder addJavascriptInterface(BaseJsInteration jsInteration) {
+ this.jsInteration=jsInteration;
+ return this;
+ }
+
public Builder removeWebViewListener(WebViewListener listener) {
listeners.remove(listener);
return this;
@@ -892,6 +900,15 @@ public Builder injectJavaScript(String injectJavaScript) {
return this;
}
+ public WebView getWebView() {
+// webView.getSettings().setJavaScriptEnabled(true);
+ return webView;
+ }
+
+ public void setWebView(WebView webView) {
+ this.webView = webView;
+ }
+
public void load(@StringRes int dataRes) {
load(Res.getString(dataRes));
}
diff --git a/library/src/main/java/com/thefinestartist/finestwebview/FinestWebViewActivity.java b/library/src/main/java/com/thefinestartist/finestwebview/FinestWebViewActivity.java
index 725a8bf..283dcd8 100644
--- a/library/src/main/java/com/thefinestartist/finestwebview/FinestWebViewActivity.java
+++ b/library/src/main/java/com/thefinestartist/finestwebview/FinestWebViewActivity.java
@@ -23,6 +23,7 @@
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.AppCompatImageButton;
import android.support.v7.widget.Toolbar;
+import android.util.Log;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
@@ -32,7 +33,9 @@
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
+import android.view.animation.BaseInterpolator;
import android.webkit.DownloadListener;
+import android.webkit.JavascriptInterface;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
@@ -43,6 +46,7 @@
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
+
import com.nineoldandroids.view.ViewHelper;
import com.thefinestartist.converters.UnitConverter;
import com.thefinestartist.finestwebview.enums.Position;
@@ -57,1187 +61,1232 @@
import com.thefinestartist.utils.ui.DisplayUtil;
import com.thefinestartist.utils.ui.ViewUtil;
+import java.io.Serializable;
+
//MailTo Imports
/**
* Created by Leonardo on 11/14/15.
*/
public class FinestWebViewActivity extends AppCompatActivity
- implements AppBarLayout.OnOffsetChangedListener, View.OnClickListener {
-
- protected int key;
-
- protected boolean rtl;
- protected int theme;
-
- protected int statusBarColor;
-
- protected int toolbarColor;
- protected int toolbarScrollFlags;
-
- protected int iconDefaultColor;
- protected int iconDisabledColor;
- protected int iconPressedColor;
- protected int iconSelector;
-
- protected boolean showIconClose;
- protected boolean disableIconClose;
- protected boolean showIconBack;
- protected boolean disableIconBack;
- protected boolean showIconForward;
- protected boolean disableIconForward;
- protected boolean showIconMenu;
- protected boolean disableIconMenu;
-
- protected boolean showSwipeRefreshLayout;
- protected int swipeRefreshColor;
- protected int[] swipeRefreshColors;
-
- protected boolean showDivider;
- protected boolean gradientDivider;
- protected int dividerColor;
- protected float dividerHeight;
-
- protected boolean showProgressBar;
- protected int progressBarColor;
- protected float progressBarHeight;
- protected Position progressBarPosition;
-
- protected String titleDefault;
- protected boolean updateTitleFromHtml;
- protected float titleSize;
- protected String titleFont;
- protected int titleColor;
-
- protected boolean showUrl;
- protected float urlSize;
- protected String urlFont;
- protected int urlColor;
-
- protected int menuColor;
- protected int menuDropShadowColor;
- protected float menuDropShadowSize;
- protected int menuSelector;
-
- protected float menuTextSize;
- protected String menuTextFont;
- protected int menuTextColor;
-
- protected int menuTextGravity;
- protected float menuTextPaddingLeft;
- protected float menuTextPaddingRight;
-
- protected boolean showMenuRefresh;
- protected int stringResRefresh;
- protected boolean showMenuFind;
- protected int stringResFind;
- protected boolean showMenuShareVia;
- protected int stringResShareVia;
- protected boolean showMenuCopyLink;
- protected int stringResCopyLink;
- protected boolean showMenuOpenWith;
- protected int stringResOpenWith;
-
- protected int animationCloseEnter;
- protected int animationCloseExit;
-
- protected boolean backPressToClose;
- protected int stringResCopiedToClipboard;
-
- protected Boolean webViewSupportZoom;
- protected Boolean webViewMediaPlaybackRequiresUserGesture;
- protected Boolean webViewBuiltInZoomControls;
- protected Boolean webViewDisplayZoomControls;
- protected Boolean webViewAllowFileAccess;
- protected Boolean webViewAllowContentAccess;
- protected Boolean webViewLoadWithOverviewMode;
- protected Boolean webViewSaveFormData;
- protected Integer webViewTextZoom;
- protected Boolean webViewUseWideViewPort;
- protected Boolean webViewSupportMultipleWindows;
- protected WebSettings.LayoutAlgorithm webViewLayoutAlgorithm;
- protected String webViewStandardFontFamily;
- protected String webViewFixedFontFamily;
- protected String webViewSansSerifFontFamily;
- protected String webViewSerifFontFamily;
- protected String webViewCursiveFontFamily;
- protected String webViewFantasyFontFamily;
- protected Integer webViewMinimumFontSize;
- protected Integer webViewMinimumLogicalFontSize;
- protected Integer webViewDefaultFontSize;
- protected Integer webViewDefaultFixedFontSize;
- protected Boolean webViewLoadsImagesAutomatically;
- protected Boolean webViewBlockNetworkImage;
- protected Boolean webViewBlockNetworkLoads;
- protected Boolean webViewJavaScriptEnabled;
- protected Boolean webViewAllowUniversalAccessFromFileURLs;
- protected Boolean webViewAllowFileAccessFromFileURLs;
- protected String webViewGeolocationDatabasePath;
- protected Boolean webViewAppCacheEnabled;
- protected String webViewAppCachePath;
- protected Boolean webViewDatabaseEnabled;
- protected Boolean webViewDomStorageEnabled;
- protected Boolean webViewGeolocationEnabled;
- protected Boolean webViewJavaScriptCanOpenWindowsAutomatically;
- protected String webViewDefaultTextEncodingName;
- protected String webViewUserAgentString;
- protected Boolean webViewNeedInitialFocus;
- protected Integer webViewCacheMode;
- protected Integer webViewMixedContentMode;
- protected Boolean webViewOffscreenPreRaster;
-
- protected String injectJavaScript;
-
- protected String mimeType;
- protected String encoding;
- protected String data;
- protected String url;
- protected CoordinatorLayout coordinatorLayout;
- protected AppBarLayout appBar;
- protected Toolbar toolbar;
- protected RelativeLayout toolbarLayout;
- protected TextView title;
- protected TextView urlTv;
- protected AppCompatImageButton close;
- protected AppCompatImageButton back;
- protected AppCompatImageButton forward;
- protected AppCompatImageButton more;
- protected SwipeRefreshLayout swipeRefreshLayout;
- protected WebView webView;
- protected View gradient;
- protected View divider;
- protected ProgressBar progressBar;
- protected RelativeLayout menuLayout;
- protected ShadowLayout shadowLayout;
- protected LinearLayout menuBackground;
- protected LinearLayout menuRefresh;
- protected TextView menuRefreshTv;
- protected LinearLayout menuFind;
- protected TextView menuFindTv;
- protected LinearLayout menuShareVia;
- protected TextView menuShareViaTv;
- protected LinearLayout menuCopyLink;
- protected TextView menuCopyLinkTv;
- protected LinearLayout menuOpenWith;
- protected TextView menuOpenWithTv;
- protected FrameLayout webLayout;
- DownloadListener downloadListener = new DownloadListener() {
- @Override public void onDownloadStart(String url, String userAgent, String contentDisposition,
- String mimetype, long contentLength) {
- BroadCastManager.onDownloadStart(FinestWebViewActivity.this, key, url, userAgent,
- contentDisposition, mimetype, contentLength);
- }
- };
-
- protected void initializeOptions() {
- Intent intent = getIntent();
- if (intent == null) return;
-
- FinestWebView.Builder builder = (FinestWebView.Builder) intent.getSerializableExtra("builder");
-
- // set theme before resolving attributes depending on those
- setTheme(builder.theme != null ? builder.theme : 0);
-
- // resolve themed attributes
- TypedValue typedValue = new TypedValue();
- TypedArray typedArray = obtainStyledAttributes(typedValue.data, new int[] {
- R.attr.colorPrimaryDark, R.attr.colorPrimary, R.attr.colorAccent,
- android.R.attr.textColorPrimary, android.R.attr.textColorSecondary,
- android.R.attr.selectableItemBackground, android.R.attr.selectableItemBackgroundBorderless
- });
- int colorPrimaryDark = typedArray.getColor(0, ContextCompat.getColor(this, R.color.finestGray));
- int colorPrimary = typedArray.getColor(1, ContextCompat.getColor(this, R.color.finestWhite));
- int colorAccent = typedArray.getColor(2, ContextCompat.getColor(this, R.color.finestBlack));
- int textColorPrimary =
- typedArray.getColor(3, ContextCompat.getColor(this, R.color.finestBlack));
- int textColorSecondary =
- typedArray.getColor(4, ContextCompat.getColor(this, R.color.finestSilver));
- int selectableItemBackground =
- Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ? typedArray.getResourceId(5, 0)
- : R.drawable.selector_light_theme;
- int selectableItemBackgroundBorderless =
- Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? typedArray.getResourceId(6, 0)
- : R.drawable.selector_light_theme;
- typedArray.recycle();
-
- key = builder.key;
-
- rtl = builder.rtl != null ? builder.rtl : getResources().getBoolean(R.bool.is_right_to_left);
-
- statusBarColor = builder.statusBarColor != null ? builder.statusBarColor : colorPrimaryDark;
-
- toolbarColor = builder.toolbarColor != null ? builder.toolbarColor : colorPrimary;
- toolbarScrollFlags = builder.toolbarScrollFlags != null ? builder.toolbarScrollFlags :
- AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL
- | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS;
-
- iconDefaultColor = builder.iconDefaultColor != null ? builder.iconDefaultColor : colorAccent;
- iconDisabledColor = builder.iconDisabledColor != null ? builder.iconDisabledColor
- : ColorHelper.disableColor(iconDefaultColor);
- iconPressedColor =
- builder.iconPressedColor != null ? builder.iconPressedColor : iconDefaultColor;
- iconSelector =
- builder.iconSelector != null ? builder.iconSelector : selectableItemBackgroundBorderless;
-
- showIconClose = builder.showIconClose != null ? builder.showIconClose : true;
- disableIconClose = builder.disableIconClose != null ? builder.disableIconClose : false;
- showIconBack = builder.showIconBack != null ? builder.showIconBack : true;
- disableIconBack = builder.disableIconBack != null ? builder.disableIconBack : false;
- showIconForward = builder.showIconForward != null ? builder.showIconForward : true;
- disableIconForward = builder.disableIconForward != null ? builder.disableIconForward : false;
- showIconMenu = builder.showIconMenu != null ? builder.showIconMenu : true;
- disableIconMenu = builder.disableIconMenu != null ? builder.disableIconMenu : false;
-
- showSwipeRefreshLayout =
- builder.showSwipeRefreshLayout != null ? builder.showSwipeRefreshLayout : true;
- swipeRefreshColor = builder.swipeRefreshColor != null ? builder.swipeRefreshColor : colorAccent;
- if (builder.swipeRefreshColors != null) {
- int[] colors = new int[builder.swipeRefreshColors.length];
- for (int i = 0; i < builder.swipeRefreshColors.length; i++)
- colors[i] = builder.swipeRefreshColors[i];
- swipeRefreshColors = colors;
- }
+ implements AppBarLayout.OnOffsetChangedListener, View.OnClickListener {
+
+ protected int key;
+
+ protected boolean rtl;
+ protected int theme;
+
+ protected int statusBarColor;
+
+ protected int toolbarColor;
+ protected int toolbarScrollFlags;
+
+ protected int iconDefaultColor;
+ protected int iconDisabledColor;
+ protected int iconPressedColor;
+ protected int iconSelector;
+
+ protected boolean showIconClose;
+ protected boolean disableIconClose;
+ protected boolean showIconBack;
+ protected boolean disableIconBack;
+ protected boolean showIconForward;
+ protected boolean disableIconForward;
+ protected boolean showIconMenu;
+ protected boolean disableIconMenu;
+
+ protected boolean showSwipeRefreshLayout;
+ protected int swipeRefreshColor;
+ protected int[] swipeRefreshColors;
+
+ protected boolean showDivider;
+ protected boolean gradientDivider;
+ protected int dividerColor;
+ protected float dividerHeight;
+
+ protected boolean showProgressBar;
+ protected int progressBarColor;
+ protected float progressBarHeight;
+ protected Position progressBarPosition;
+
+ protected String titleDefault;
+ protected boolean updateTitleFromHtml;
+ protected float titleSize;
+ protected String titleFont;
+ protected int titleColor;
+
+ protected boolean showUrl;
+ protected float urlSize;
+ protected String urlFont;
+ protected int urlColor;
+
+ protected int menuColor;
+ protected int menuDropShadowColor;
+ protected float menuDropShadowSize;
+ protected int menuSelector;
+
+ protected float menuTextSize;
+ protected String menuTextFont;
+ protected int menuTextColor;
+
+ protected int menuTextGravity;
+ protected float menuTextPaddingLeft;
+ protected float menuTextPaddingRight;
+
+ protected boolean showMenuRefresh;
+ protected int stringResRefresh;
+ protected boolean showMenuFind;
+ protected int stringResFind;
+ protected boolean showMenuShareVia;
+ protected int stringResShareVia;
+ protected boolean showMenuCopyLink;
+ protected int stringResCopyLink;
+ protected boolean showMenuOpenWith;
+ protected int stringResOpenWith;
+
+ protected int animationCloseEnter;
+ protected int animationCloseExit;
+
+ protected boolean backPressToClose;
+ protected int stringResCopiedToClipboard;
+
+ protected Boolean webViewSupportZoom;
+ protected Boolean webViewMediaPlaybackRequiresUserGesture;
+ protected Boolean webViewBuiltInZoomControls;
+ protected Boolean webViewDisplayZoomControls;
+ protected Boolean webViewAllowFileAccess;
+ protected Boolean webViewAllowContentAccess;
+ protected Boolean webViewLoadWithOverviewMode;
+ protected Boolean webViewSaveFormData;
+ protected Integer webViewTextZoom;
+ protected Boolean webViewUseWideViewPort;
+ protected Boolean webViewSupportMultipleWindows;
+ protected WebSettings.LayoutAlgorithm webViewLayoutAlgorithm;
+ protected String webViewStandardFontFamily;
+ protected String webViewFixedFontFamily;
+ protected String webViewSansSerifFontFamily;
+ protected String webViewSerifFontFamily;
+ protected String webViewCursiveFontFamily;
+ protected String webViewFantasyFontFamily;
+ protected Integer webViewMinimumFontSize;
+ protected Integer webViewMinimumLogicalFontSize;
+ protected Integer webViewDefaultFontSize;
+ protected Integer webViewDefaultFixedFontSize;
+ protected Boolean webViewLoadsImagesAutomatically;
+ protected Boolean webViewBlockNetworkImage;
+ protected Boolean webViewBlockNetworkLoads;
+ protected Boolean webViewJavaScriptEnabled;
+ protected Boolean webViewAllowUniversalAccessFromFileURLs;
+ protected Boolean webViewAllowFileAccessFromFileURLs;
+ protected String webViewGeolocationDatabasePath;
+ protected Boolean webViewAppCacheEnabled;
+ protected String webViewAppCachePath;
+ protected Boolean webViewDatabaseEnabled;
+ protected Boolean webViewDomStorageEnabled;
+ protected Boolean webViewGeolocationEnabled;
+ protected Boolean webViewJavaScriptCanOpenWindowsAutomatically;
+ protected String webViewDefaultTextEncodingName;
+ protected String webViewUserAgentString;
+ protected Boolean webViewNeedInitialFocus;
+ protected Integer webViewCacheMode;
+ protected Integer webViewMixedContentMode;
+ protected Boolean webViewOffscreenPreRaster;
+
+ protected String injectJavaScript;
+ protected BaseJsInteration jsInteration;
+ protected String mimeType;
+ protected String encoding;
+ protected String data;
+ protected String url;
+ protected CoordinatorLayout coordinatorLayout;
+ protected AppBarLayout appBar;
+ protected Toolbar toolbar;
+ protected RelativeLayout toolbarLayout;
+ protected TextView title;
+ protected TextView urlTv;
+ protected AppCompatImageButton close;
+ protected AppCompatImageButton back;
+ protected AppCompatImageButton forward;
+ protected AppCompatImageButton more;
+ protected SwipeRefreshLayout swipeRefreshLayout;
+ protected WebView webView;
+ protected View gradient;
+ protected View divider;
+ protected ProgressBar progressBar;
+ protected RelativeLayout menuLayout;
+ protected ShadowLayout shadowLayout;
+ protected LinearLayout menuBackground;
+ protected LinearLayout menuRefresh;
+ protected TextView menuRefreshTv;
+ protected LinearLayout menuFind;
+ protected TextView menuFindTv;
+ protected LinearLayout menuShareVia;
+ protected TextView menuShareViaTv;
+ protected LinearLayout menuCopyLink;
+ protected TextView menuCopyLinkTv;
+ protected LinearLayout menuOpenWith;
+ protected TextView menuOpenWithTv;
+ protected FrameLayout webLayout;
+ protected FinestWebView.Builder builder;
+ DownloadListener downloadListener = new DownloadListener() {
+ @Override
+ public void onDownloadStart(String url, String userAgent, String contentDisposition,
+ String mimetype, long contentLength) {
+ BroadCastManager.onDownloadStart(FinestWebViewActivity.this, key, url, userAgent,
+ contentDisposition, mimetype, contentLength);
+ }
+ };
- showDivider = builder.showDivider != null ? builder.showDivider : true;
- gradientDivider = builder.gradientDivider != null ? builder.gradientDivider : true;
- dividerColor = builder.dividerColor != null ? builder.dividerColor
- : ContextCompat.getColor(this, R.color.finestBlack10);
- dividerHeight = builder.dividerHeight != null ? builder.dividerHeight
- : getResources().getDimension(R.dimen.defaultDividerHeight);
-
- showProgressBar = builder.showProgressBar != null ? builder.showProgressBar : true;
- progressBarColor = builder.progressBarColor != null ? builder.progressBarColor : colorAccent;
- progressBarHeight = builder.progressBarHeight != null ? builder.progressBarHeight
- : getResources().getDimension(R.dimen.defaultProgressBarHeight);
- progressBarPosition = builder.progressBarPosition != null ? builder.progressBarPosition
- : Position.BOTTON_OF_TOOLBAR;
-
- titleDefault = builder.titleDefault;
- updateTitleFromHtml = builder.updateTitleFromHtml != null ? builder.updateTitleFromHtml : true;
- titleSize = builder.titleSize != null ? builder.titleSize
- : getResources().getDimension(R.dimen.defaultTitleSize);
- titleFont = builder.titleFont != null ? builder.titleFont : "Roboto-Medium.ttf";
- titleColor = builder.titleColor != null ? builder.titleColor : textColorPrimary;
-
- showUrl = builder.showUrl != null ? builder.showUrl : true;
- urlSize = builder.urlSize != null ? builder.urlSize
- : getResources().getDimension(R.dimen.defaultUrlSize);
- urlFont = builder.urlFont != null ? builder.urlFont : "Roboto-Regular.ttf";
- urlColor = builder.urlColor != null ? builder.urlColor : textColorSecondary;
-
- menuColor = builder.menuColor != null ? builder.menuColor
- : ContextCompat.getColor(this, R.color.finestWhite);
- menuDropShadowColor = builder.menuDropShadowColor != null ? builder.menuDropShadowColor
- : ContextCompat.getColor(this, R.color.finestBlack10);
- menuDropShadowSize = builder.menuDropShadowSize != null ? builder.menuDropShadowSize
- : getResources().getDimension(R.dimen.defaultMenuDropShadowSize);
- menuSelector = builder.menuSelector != null ? builder.menuSelector : selectableItemBackground;
-
- menuTextSize = builder.menuTextSize != null ? builder.menuTextSize
- : getResources().getDimension(R.dimen.defaultMenuTextSize);
- menuTextFont = builder.menuTextFont != null ? builder.menuTextFont : "Roboto-Regular.ttf";
- menuTextColor = builder.menuTextColor != null ? builder.menuTextColor
- : ContextCompat.getColor(this, R.color.finestBlack);
-
- menuTextGravity = builder.menuTextGravity != null ? builder.menuTextGravity
- : Gravity.CENTER_VERTICAL | Gravity.START;
- menuTextPaddingLeft = builder.menuTextPaddingLeft != null ? builder.menuTextPaddingLeft
- : rtl ? getResources().getDimension(R.dimen.defaultMenuTextPaddingRight)
- : getResources().getDimension(R.dimen.defaultMenuTextPaddingLeft);
- menuTextPaddingRight = builder.menuTextPaddingRight != null ? builder.menuTextPaddingRight
- : rtl ? getResources().getDimension(R.dimen.defaultMenuTextPaddingLeft)
- : getResources().getDimension(R.dimen.defaultMenuTextPaddingRight);
-
- showMenuRefresh = builder.showMenuRefresh != null ? builder.showMenuRefresh : true;
- stringResRefresh =
- builder.stringResRefresh != null ? builder.stringResRefresh : R.string.refresh;
- showMenuFind = builder.showMenuFind != null ? builder.showMenuFind : false;
- stringResFind = builder.stringResFind != null ? builder.stringResFind : R.string.find;
- showMenuShareVia = builder.showMenuShareVia != null ? builder.showMenuShareVia : true;
- stringResShareVia =
- builder.stringResShareVia != null ? builder.stringResShareVia : R.string.share_via;
- showMenuCopyLink = builder.showMenuCopyLink != null ? builder.showMenuCopyLink : true;
- stringResCopyLink =
- builder.stringResCopyLink != null ? builder.stringResCopyLink : R.string.copy_link;
- showMenuOpenWith = builder.showMenuOpenWith != null ? builder.showMenuOpenWith : true;
- stringResOpenWith =
- builder.stringResOpenWith != null ? builder.stringResOpenWith : R.string.open_with;
-
- animationCloseEnter = builder.animationCloseEnter != null ? builder.animationCloseEnter
- : R.anim.modal_activity_close_enter;
- animationCloseExit = builder.animationCloseExit != null ? builder.animationCloseExit
- : R.anim.modal_activity_close_exit;
-
- backPressToClose = builder.backPressToClose != null ? builder.backPressToClose : false;
- stringResCopiedToClipboard =
- builder.stringResCopiedToClipboard != null ? builder.stringResCopiedToClipboard
- : R.string.copied_to_clipboard;
-
- webViewSupportZoom = builder.webViewSupportZoom;
- webViewMediaPlaybackRequiresUserGesture = builder.webViewMediaPlaybackRequiresUserGesture;
- webViewBuiltInZoomControls =
- builder.webViewBuiltInZoomControls != null ? builder.webViewBuiltInZoomControls : false;
- webViewDisplayZoomControls =
- builder.webViewDisplayZoomControls != null ? builder.webViewDisplayZoomControls : false;
- webViewAllowFileAccess =
- builder.webViewAllowFileAccess != null ? builder.webViewAllowFileAccess : true;
- webViewAllowContentAccess = builder.webViewAllowContentAccess;
- webViewLoadWithOverviewMode =
- builder.webViewLoadWithOverviewMode != null ? builder.webViewLoadWithOverviewMode : true;
- webViewSaveFormData = builder.webViewSaveFormData;
- webViewTextZoom = builder.webViewTextZoom;
- webViewUseWideViewPort = builder.webViewUseWideViewPort;
- webViewSupportMultipleWindows = builder.webViewSupportMultipleWindows;
- webViewLayoutAlgorithm = builder.webViewLayoutAlgorithm;
- webViewStandardFontFamily = builder.webViewStandardFontFamily;
- webViewFixedFontFamily = builder.webViewFixedFontFamily;
- webViewSansSerifFontFamily = builder.webViewSansSerifFontFamily;
- webViewSerifFontFamily = builder.webViewSerifFontFamily;
- webViewCursiveFontFamily = builder.webViewCursiveFontFamily;
- webViewFantasyFontFamily = builder.webViewFantasyFontFamily;
- webViewMinimumFontSize = builder.webViewMinimumFontSize;
- webViewMinimumLogicalFontSize = builder.webViewMinimumLogicalFontSize;
- webViewDefaultFontSize = builder.webViewDefaultFontSize;
- webViewDefaultFixedFontSize = builder.webViewDefaultFixedFontSize;
- webViewLoadsImagesAutomatically = builder.webViewLoadsImagesAutomatically;
- webViewBlockNetworkImage = builder.webViewBlockNetworkImage;
- webViewBlockNetworkLoads = builder.webViewBlockNetworkLoads;
- webViewJavaScriptEnabled =
- builder.webViewJavaScriptEnabled != null ? builder.webViewJavaScriptEnabled : true;
- webViewAllowUniversalAccessFromFileURLs = builder.webViewAllowUniversalAccessFromFileURLs;
- webViewAllowFileAccessFromFileURLs = builder.webViewAllowFileAccessFromFileURLs;
- webViewGeolocationDatabasePath = builder.webViewGeolocationDatabasePath;
- webViewAppCacheEnabled =
- builder.webViewAppCacheEnabled != null ? builder.webViewAppCacheEnabled : true;
- webViewAppCachePath = builder.webViewAppCachePath;
- webViewDatabaseEnabled = builder.webViewDatabaseEnabled;
- webViewDomStorageEnabled =
- builder.webViewDomStorageEnabled != null ? builder.webViewDomStorageEnabled : true;
- webViewGeolocationEnabled = builder.webViewGeolocationEnabled;
- webViewJavaScriptCanOpenWindowsAutomatically =
- builder.webViewJavaScriptCanOpenWindowsAutomatically;
- webViewDefaultTextEncodingName = builder.webViewDefaultTextEncodingName;
- webViewUserAgentString = builder.webViewUserAgentString;
- webViewNeedInitialFocus = builder.webViewNeedInitialFocus;
- webViewCacheMode = builder.webViewCacheMode;
- webViewMixedContentMode = builder.webViewMixedContentMode;
- webViewOffscreenPreRaster = builder.webViewOffscreenPreRaster;
-
- injectJavaScript = builder.injectJavaScript;
-
- mimeType = builder.mimeType;
- encoding = builder.encoding;
- data = builder.data;
- url = builder.url;
- }
-
- protected void bindViews() {
- coordinatorLayout = (CoordinatorLayout) findViewById(R.id.coordinatorLayout);
-
- appBar = (AppBarLayout) findViewById(R.id.appBar);
- toolbar = (Toolbar) findViewById(R.id.toolbar);
- toolbarLayout = (RelativeLayout) findViewById(R.id.toolbarLayout);
-
- title = (TextView) findViewById(R.id.title);
- urlTv = (TextView) findViewById(R.id.url);
-
- close = (AppCompatImageButton) findViewById(R.id.close);
- back = (AppCompatImageButton) findViewById(R.id.back);
- forward = (AppCompatImageButton) findViewById(R.id.forward);
- more = (AppCompatImageButton) findViewById(R.id.more);
-
- close.setOnClickListener(this);
- back.setOnClickListener(this);
- forward.setOnClickListener(this);
- more.setOnClickListener(this);
-
- swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout);
-
- gradient = findViewById(R.id.gradient);
- divider = findViewById(R.id.divider);
- progressBar = (ProgressBar) findViewById(R.id.progressBar);
-
- menuLayout = (RelativeLayout) findViewById(R.id.menuLayout);
- shadowLayout = (ShadowLayout) findViewById(R.id.shadowLayout);
- menuBackground = (LinearLayout) findViewById(R.id.menuBackground);
-
- menuRefresh = (LinearLayout) findViewById(R.id.menuRefresh);
- menuRefreshTv = (TextView) findViewById(R.id.menuRefreshTv);
- menuFind = (LinearLayout) findViewById(R.id.menuFind);
- menuFindTv = (TextView) findViewById(R.id.menuFindTv);
- menuShareVia = (LinearLayout) findViewById(R.id.menuShareVia);
- menuShareViaTv = (TextView) findViewById(R.id.menuShareViaTv);
- menuCopyLink = (LinearLayout) findViewById(R.id.menuCopyLink);
- menuCopyLinkTv = (TextView) findViewById(R.id.menuCopyLinkTv);
- menuOpenWith = (LinearLayout) findViewById(R.id.menuOpenWith);
- menuOpenWithTv = (TextView) findViewById(R.id.menuOpenWithTv);
-
- webLayout = (FrameLayout) findViewById(R.id.webLayout);
- webView = new WebView(this);
- webLayout.addView(webView);
- }
-
- protected void layoutViews() {
- setSupportActionBar(toolbar);
-
- { // AppBar
- float toolbarHeight = getResources().getDimension(R.dimen.toolbarHeight);
- if (!gradientDivider) toolbarHeight += dividerHeight;
- CoordinatorLayout.LayoutParams params =
- new CoordinatorLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
- (int) toolbarHeight);
- appBar.setLayoutParams(params);
- coordinatorLayout.requestLayout();
- }
+ protected void initializeOptions() {
+ Intent intent = getIntent();
+ if (intent == null) return;
- { // Toolbar
- float toolbarHeight = getResources().getDimension(R.dimen.toolbarHeight);
- LinearLayout.LayoutParams params =
- new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int) toolbarHeight);
- toolbarLayout.setMinimumHeight((int) toolbarHeight);
- toolbarLayout.setLayoutParams(params);
- coordinatorLayout.requestLayout();
- }
+ builder = (FinestWebView.Builder) intent.getSerializableExtra("builder");
- { // TextViews
- int maxWidth = getMaxWidth();
- title.setMaxWidth(maxWidth);
- urlTv.setMaxWidth(maxWidth);
- requestCenterLayout();
- }
+ // set theme before resolving attributes depending on those
+ setTheme(builder.theme != null ? builder.theme : 0);
- { // Icons
- updateIcon(close, rtl ? R.drawable.more : R.drawable.close);
- updateIcon(back, R.drawable.back);
- updateIcon(forward, R.drawable.forward);
- updateIcon(more, rtl ? R.drawable.close : R.drawable.more);
- }
+ // resolve themed attributes
+ TypedValue typedValue = new TypedValue();
+ TypedArray typedArray = obtainStyledAttributes(typedValue.data, new int[]{
+ R.attr.colorPrimaryDark, R.attr.colorPrimary, R.attr.colorAccent,
+ android.R.attr.textColorPrimary, android.R.attr.textColorSecondary,
+ android.R.attr.selectableItemBackground, android.R.attr.selectableItemBackgroundBorderless
+ });
+ int colorPrimaryDark = typedArray.getColor(0, ContextCompat.getColor(this, R.color.finestGray));
+ int colorPrimary = typedArray.getColor(1, ContextCompat.getColor(this, R.color.finestWhite));
+ int colorAccent = typedArray.getColor(2, ContextCompat.getColor(this, R.color.finestBlack));
+ int textColorPrimary =
+ typedArray.getColor(3, ContextCompat.getColor(this, R.color.finestBlack));
+ int textColorSecondary =
+ typedArray.getColor(4, ContextCompat.getColor(this, R.color.finestSilver));
+ int selectableItemBackground =
+ Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ? typedArray.getResourceId(5, 0)
+ : R.drawable.selector_light_theme;
+ int selectableItemBackgroundBorderless =
+ Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? typedArray.getResourceId(6, 0)
+ : R.drawable.selector_light_theme;
+ typedArray.recycle();
+
+ key = builder.key;
+
+ rtl = builder.rtl != null ? builder.rtl : getResources().getBoolean(R.bool.is_right_to_left);
+
+ statusBarColor = builder.statusBarColor != null ? builder.statusBarColor : colorPrimaryDark;
+
+ toolbarColor = builder.toolbarColor != null ? builder.toolbarColor : colorPrimary;
+ toolbarScrollFlags = builder.toolbarScrollFlags != null ? builder.toolbarScrollFlags :
+ AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL
+ | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS;
+
+ iconDefaultColor = builder.iconDefaultColor != null ? builder.iconDefaultColor : colorAccent;
+ iconDisabledColor = builder.iconDisabledColor != null ? builder.iconDisabledColor
+ : ColorHelper.disableColor(iconDefaultColor);
+ iconPressedColor =
+ builder.iconPressedColor != null ? builder.iconPressedColor : iconDefaultColor;
+ iconSelector =
+ builder.iconSelector != null ? builder.iconSelector : selectableItemBackgroundBorderless;
+
+ showIconClose = builder.showIconClose != null ? builder.showIconClose : true;
+ disableIconClose = builder.disableIconClose != null ? builder.disableIconClose : false;
+ showIconBack = builder.showIconBack != null ? builder.showIconBack : true;
+ disableIconBack = builder.disableIconBack != null ? builder.disableIconBack : false;
+ showIconForward = builder.showIconForward != null ? builder.showIconForward : true;
+ disableIconForward = builder.disableIconForward != null ? builder.disableIconForward : false;
+ showIconMenu = builder.showIconMenu != null ? builder.showIconMenu : true;
+ disableIconMenu = builder.disableIconMenu != null ? builder.disableIconMenu : false;
+
+ showSwipeRefreshLayout =
+ builder.showSwipeRefreshLayout != null ? builder.showSwipeRefreshLayout : true;
+ swipeRefreshColor = builder.swipeRefreshColor != null ? builder.swipeRefreshColor : colorAccent;
+ if (builder.swipeRefreshColors != null) {
+ int[] colors = new int[builder.swipeRefreshColors.length];
+ for (int i = 0; i < builder.swipeRefreshColors.length; i++)
+ colors[i] = builder.swipeRefreshColors[i];
+ swipeRefreshColors = colors;
+ }
- { // Divider
- if (gradientDivider) {
- float toolbarHeight = getResources().getDimension(R.dimen.toolbarHeight);
- CoordinatorLayout.LayoutParams params =
- (CoordinatorLayout.LayoutParams) gradient.getLayoutParams();
- params.setMargins(0, (int) toolbarHeight, 0, 0);
- gradient.setLayoutParams(params);
- }
+ showDivider = builder.showDivider != null ? builder.showDivider : true;
+ gradientDivider = builder.gradientDivider != null ? builder.gradientDivider : true;
+ dividerColor = builder.dividerColor != null ? builder.dividerColor
+ : ContextCompat.getColor(this, R.color.finestBlack10);
+ dividerHeight = builder.dividerHeight != null ? builder.dividerHeight
+ : getResources().getDimension(R.dimen.defaultDividerHeight);
+
+ showProgressBar = builder.showProgressBar != null ? builder.showProgressBar : true;
+ progressBarColor = builder.progressBarColor != null ? builder.progressBarColor : colorAccent;
+ progressBarHeight = builder.progressBarHeight != null ? builder.progressBarHeight
+ : getResources().getDimension(R.dimen.defaultProgressBarHeight);
+ progressBarPosition = builder.progressBarPosition != null ? builder.progressBarPosition
+ : Position.BOTTON_OF_TOOLBAR;
+
+ titleDefault = builder.titleDefault;
+ updateTitleFromHtml = builder.updateTitleFromHtml != null ? builder.updateTitleFromHtml : true;
+ titleSize = builder.titleSize != null ? builder.titleSize
+ : getResources().getDimension(R.dimen.defaultTitleSize);
+ titleFont = builder.titleFont != null ? builder.titleFont : "Roboto-Medium.ttf";
+ titleColor = builder.titleColor != null ? builder.titleColor : textColorPrimary;
+
+ showUrl = builder.showUrl != null ? builder.showUrl : true;
+ urlSize = builder.urlSize != null ? builder.urlSize
+ : getResources().getDimension(R.dimen.defaultUrlSize);
+ urlFont = builder.urlFont != null ? builder.urlFont : "Roboto-Regular.ttf";
+ urlColor = builder.urlColor != null ? builder.urlColor : textColorSecondary;
+
+ menuColor = builder.menuColor != null ? builder.menuColor
+ : ContextCompat.getColor(this, R.color.finestWhite);
+ menuDropShadowColor = builder.menuDropShadowColor != null ? builder.menuDropShadowColor
+ : ContextCompat.getColor(this, R.color.finestBlack10);
+ menuDropShadowSize = builder.menuDropShadowSize != null ? builder.menuDropShadowSize
+ : getResources().getDimension(R.dimen.defaultMenuDropShadowSize);
+ menuSelector = builder.menuSelector != null ? builder.menuSelector : selectableItemBackground;
+
+ menuTextSize = builder.menuTextSize != null ? builder.menuTextSize
+ : getResources().getDimension(R.dimen.defaultMenuTextSize);
+ menuTextFont = builder.menuTextFont != null ? builder.menuTextFont : "Roboto-Regular.ttf";
+ menuTextColor = builder.menuTextColor != null ? builder.menuTextColor
+ : ContextCompat.getColor(this, R.color.finestBlack);
+
+ menuTextGravity = builder.menuTextGravity != null ? builder.menuTextGravity
+ : Gravity.CENTER_VERTICAL | Gravity.START;
+ menuTextPaddingLeft = builder.menuTextPaddingLeft != null ? builder.menuTextPaddingLeft
+ : rtl ? getResources().getDimension(R.dimen.defaultMenuTextPaddingRight)
+ : getResources().getDimension(R.dimen.defaultMenuTextPaddingLeft);
+ menuTextPaddingRight = builder.menuTextPaddingRight != null ? builder.menuTextPaddingRight
+ : rtl ? getResources().getDimension(R.dimen.defaultMenuTextPaddingLeft)
+ : getResources().getDimension(R.dimen.defaultMenuTextPaddingRight);
+
+ showMenuRefresh = builder.showMenuRefresh != null ? builder.showMenuRefresh : true;
+ stringResRefresh =
+ builder.stringResRefresh != null ? builder.stringResRefresh : R.string.refresh;
+ showMenuFind = builder.showMenuFind != null ? builder.showMenuFind : false;
+ stringResFind = builder.stringResFind != null ? builder.stringResFind : R.string.find;
+ showMenuShareVia = builder.showMenuShareVia != null ? builder.showMenuShareVia : true;
+ stringResShareVia =
+ builder.stringResShareVia != null ? builder.stringResShareVia : R.string.share_via;
+ showMenuCopyLink = builder.showMenuCopyLink != null ? builder.showMenuCopyLink : true;
+ stringResCopyLink =
+ builder.stringResCopyLink != null ? builder.stringResCopyLink : R.string.copy_link;
+ showMenuOpenWith = builder.showMenuOpenWith != null ? builder.showMenuOpenWith : true;
+ stringResOpenWith =
+ builder.stringResOpenWith != null ? builder.stringResOpenWith : R.string.open_with;
+
+ animationCloseEnter = builder.animationCloseEnter != null ? builder.animationCloseEnter
+ : R.anim.modal_activity_close_enter;
+ animationCloseExit = builder.animationCloseExit != null ? builder.animationCloseExit
+ : R.anim.modal_activity_close_exit;
+
+ backPressToClose = builder.backPressToClose != null ? builder.backPressToClose : false;
+ stringResCopiedToClipboard =
+ builder.stringResCopiedToClipboard != null ? builder.stringResCopiedToClipboard
+ : R.string.copied_to_clipboard;
+
+ webViewSupportZoom = builder.webViewSupportZoom;
+ webViewMediaPlaybackRequiresUserGesture = builder.webViewMediaPlaybackRequiresUserGesture;
+ webViewBuiltInZoomControls =
+ builder.webViewBuiltInZoomControls != null ? builder.webViewBuiltInZoomControls : false;
+ webViewDisplayZoomControls =
+ builder.webViewDisplayZoomControls != null ? builder.webViewDisplayZoomControls : false;
+ webViewAllowFileAccess =
+ builder.webViewAllowFileAccess != null ? builder.webViewAllowFileAccess : true;
+ webViewAllowContentAccess = builder.webViewAllowContentAccess;
+ webViewLoadWithOverviewMode =
+ builder.webViewLoadWithOverviewMode != null ? builder.webViewLoadWithOverviewMode : true;
+ webViewSaveFormData = builder.webViewSaveFormData;
+ webViewTextZoom = builder.webViewTextZoom;
+ webViewUseWideViewPort = builder.webViewUseWideViewPort;
+ webViewSupportMultipleWindows = builder.webViewSupportMultipleWindows;
+ webViewLayoutAlgorithm = builder.webViewLayoutAlgorithm;
+ webViewStandardFontFamily = builder.webViewStandardFontFamily;
+ webViewFixedFontFamily = builder.webViewFixedFontFamily;
+ webViewSansSerifFontFamily = builder.webViewSansSerifFontFamily;
+ webViewSerifFontFamily = builder.webViewSerifFontFamily;
+ webViewCursiveFontFamily = builder.webViewCursiveFontFamily;
+ webViewFantasyFontFamily = builder.webViewFantasyFontFamily;
+ webViewMinimumFontSize = builder.webViewMinimumFontSize;
+ webViewMinimumLogicalFontSize = builder.webViewMinimumLogicalFontSize;
+ webViewDefaultFontSize = builder.webViewDefaultFontSize;
+ webViewDefaultFixedFontSize = builder.webViewDefaultFixedFontSize;
+ webViewLoadsImagesAutomatically = builder.webViewLoadsImagesAutomatically;
+ webViewBlockNetworkImage = builder.webViewBlockNetworkImage;
+ webViewBlockNetworkLoads = builder.webViewBlockNetworkLoads;
+ webViewJavaScriptEnabled =
+ builder.webViewJavaScriptEnabled != null ? builder.webViewJavaScriptEnabled : true;
+ webViewAllowUniversalAccessFromFileURLs = builder.webViewAllowUniversalAccessFromFileURLs;
+ webViewAllowFileAccessFromFileURLs = builder.webViewAllowFileAccessFromFileURLs;
+ webViewGeolocationDatabasePath = builder.webViewGeolocationDatabasePath;
+ webViewAppCacheEnabled =
+ builder.webViewAppCacheEnabled != null ? builder.webViewAppCacheEnabled : true;
+ webViewAppCachePath = builder.webViewAppCachePath;
+ webViewDatabaseEnabled = builder.webViewDatabaseEnabled;
+ webViewDomStorageEnabled =
+ builder.webViewDomStorageEnabled != null ? builder.webViewDomStorageEnabled : true;
+ webViewGeolocationEnabled = builder.webViewGeolocationEnabled;
+ webViewJavaScriptCanOpenWindowsAutomatically =
+ builder.webViewJavaScriptCanOpenWindowsAutomatically;
+ webViewDefaultTextEncodingName = builder.webViewDefaultTextEncodingName;
+ webViewUserAgentString = builder.webViewUserAgentString;
+ webViewNeedInitialFocus = builder.webViewNeedInitialFocus;
+ webViewCacheMode = builder.webViewCacheMode;
+ webViewMixedContentMode = builder.webViewMixedContentMode;
+ webViewOffscreenPreRaster = builder.webViewOffscreenPreRaster;
+
+ injectJavaScript = builder.injectJavaScript;
+ jsInteration = builder.jsInteration;
+ mimeType = builder.mimeType;
+ encoding = builder.encoding;
+ data = builder.data;
+ url = builder.url;
}
- { // ProgressBar
- progressBar.setMinimumHeight((int) progressBarHeight);
- CoordinatorLayout.LayoutParams params =
- new CoordinatorLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
- (int) progressBarHeight);
- float toolbarHeight = getResources().getDimension(R.dimen.toolbarHeight);
- switch (progressBarPosition) {
- case TOP_OF_TOOLBAR:
- params.setMargins(0, 0, 0, 0);
- break;
- case BOTTON_OF_TOOLBAR:
- params.setMargins(0, (int) toolbarHeight - (int) progressBarHeight, 0, 0);
- break;
- case TOP_OF_WEBVIEW:
- params.setMargins(0, (int) toolbarHeight, 0, 0);
- break;
- case BOTTOM_OF_WEBVIEW:
- params.setMargins(0, DisplayUtil.getHeight() - (int) progressBarHeight, 0, 0);
- break;
- }
- progressBar.setLayoutParams(params);
- }
+ protected void bindViews() {
+ coordinatorLayout = (CoordinatorLayout) findViewById(R.id.coordinatorLayout);
- { // WebLayout
- float toolbarHeight = getResources().getDimension(R.dimen.toolbarHeight);
- int statusBarHeight = DisplayUtil.getStatusBarHeight();
- int screenHeight = DisplayUtil.getHeight();
- float webLayoutMinimumHeight = screenHeight - toolbarHeight - statusBarHeight;
- if (showDivider && !gradientDivider) webLayoutMinimumHeight -= dividerHeight;
- webLayout.setMinimumHeight((int) webLayoutMinimumHeight);
- }
- }
-
- @SuppressLint("SetJavaScriptEnabled") protected void initializeViews() {
- setSupportActionBar(toolbar);
-
- { // StatusBar
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
- Window window = getWindow();
- window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
- window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
- window.setStatusBarColor(statusBarColor);
- }
- }
+ appBar = (AppBarLayout) findViewById(R.id.appBar);
+ toolbar = (Toolbar) findViewById(R.id.toolbar);
+ toolbarLayout = (RelativeLayout) findViewById(R.id.toolbarLayout);
- { // AppBar
- appBar.addOnOffsetChangedListener(this);
- }
+ title = (TextView) findViewById(R.id.title);
+ urlTv = (TextView) findViewById(R.id.url);
- { // Toolbar
- toolbar.setBackgroundColor(toolbarColor);
- AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbar.getLayoutParams();
- params.setScrollFlags(toolbarScrollFlags);
- toolbar.setLayoutParams(params);
- }
+ close = (AppCompatImageButton) findViewById(R.id.close);
+ back = (AppCompatImageButton) findViewById(R.id.back);
+ forward = (AppCompatImageButton) findViewById(R.id.forward);
+ more = (AppCompatImageButton) findViewById(R.id.more);
- { // TextViews
- title.setText(titleDefault);
- title.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
- title.setTypeface(TypefaceHelper.get(this, titleFont));
- title.setTextColor(titleColor);
+ close.setOnClickListener(this);
+ back.setOnClickListener(this);
+ forward.setOnClickListener(this);
+ more.setOnClickListener(this);
- urlTv.setVisibility(showUrl ? View.VISIBLE : View.GONE);
- urlTv.setText(UrlParser.getHost(url));
- urlTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, urlSize);
- urlTv.setTypeface(TypefaceHelper.get(this, urlFont));
- urlTv.setTextColor(urlColor);
+ swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout);
- requestCenterLayout();
- }
+ gradient = findViewById(R.id.gradient);
+ divider = findViewById(R.id.divider);
+ progressBar = (ProgressBar) findViewById(R.id.progressBar);
+
+ menuLayout = (RelativeLayout) findViewById(R.id.menuLayout);
+ shadowLayout = (ShadowLayout) findViewById(R.id.shadowLayout);
+ menuBackground = (LinearLayout) findViewById(R.id.menuBackground);
+
+ menuRefresh = (LinearLayout) findViewById(R.id.menuRefresh);
+ menuRefreshTv = (TextView) findViewById(R.id.menuRefreshTv);
+ menuFind = (LinearLayout) findViewById(R.id.menuFind);
+ menuFindTv = (TextView) findViewById(R.id.menuFindTv);
+ menuShareVia = (LinearLayout) findViewById(R.id.menuShareVia);
+ menuShareViaTv = (TextView) findViewById(R.id.menuShareViaTv);
+ menuCopyLink = (LinearLayout) findViewById(R.id.menuCopyLink);
+ menuCopyLinkTv = (TextView) findViewById(R.id.menuCopyLinkTv);
+ menuOpenWith = (LinearLayout) findViewById(R.id.menuOpenWith);
+ menuOpenWithTv = (TextView) findViewById(R.id.menuOpenWithTv);
+
+ webLayout = (FrameLayout) findViewById(R.id.webLayout);
+ webView = new WebView(this);
+ webLayout.addView(webView);
- { // Icons
- close.setBackgroundResource(iconSelector);
- back.setBackgroundResource(iconSelector);
- forward.setBackgroundResource(iconSelector);
- more.setBackgroundResource(iconSelector);
-
- close.setVisibility(showIconClose ? View.VISIBLE : View.GONE);
- close.setEnabled(!disableIconClose);
-
- if ((showMenuRefresh
- || showMenuFind
- || showMenuShareVia
- || showMenuCopyLink
- || showMenuOpenWith) && showIconMenu) {
- more.setVisibility(View.VISIBLE);
- } else {
- more.setVisibility(View.GONE);
- }
- more.setEnabled(!disableIconMenu);
}
- { // WebView
- webView.setWebChromeClient(new MyWebChromeClient());
- webView.setWebViewClient(new MyWebViewClient());
- webView.setDownloadListener(downloadListener);
-
- WebSettings settings = webView.getSettings();
-
- if (webViewSupportZoom != null) settings.setSupportZoom(webViewSupportZoom);
- if (webViewMediaPlaybackRequiresUserGesture != null
- && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
- settings.setMediaPlaybackRequiresUserGesture(webViewMediaPlaybackRequiresUserGesture);
- }
- if (webViewBuiltInZoomControls != null) {
- settings.setBuiltInZoomControls(webViewBuiltInZoomControls);
-
- if (webViewBuiltInZoomControls) {
- // Remove NestedScrollView to enable BuiltInZoomControls
- ((ViewGroup) webView.getParent()).removeAllViews();
- swipeRefreshLayout.addView(webView);
- swipeRefreshLayout.removeViewAt(1);
+ protected void layoutViews() {
+ setSupportActionBar(toolbar);
+
+ { // AppBar
+ float toolbarHeight = getResources().getDimension(R.dimen.toolbarHeight);
+ if (!gradientDivider) toolbarHeight += dividerHeight;
+ CoordinatorLayout.LayoutParams params =
+ new CoordinatorLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
+ (int) toolbarHeight);
+ appBar.setLayoutParams(params);
+ coordinatorLayout.requestLayout();
+ }
+
+ { // Toolbar
+ float toolbarHeight = getResources().getDimension(R.dimen.toolbarHeight);
+ LinearLayout.LayoutParams params =
+ new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int) toolbarHeight);
+ toolbarLayout.setMinimumHeight((int) toolbarHeight);
+ toolbarLayout.setLayoutParams(params);
+ coordinatorLayout.requestLayout();
+ }
+
+ { // TextViews
+ int maxWidth = getMaxWidth();
+ title.setMaxWidth(maxWidth);
+ urlTv.setMaxWidth(maxWidth);
+ requestCenterLayout();
+ }
+
+ { // Icons
+ updateIcon(close, rtl ? R.drawable.more : R.drawable.close);
+ updateIcon(back, R.drawable.back);
+ updateIcon(forward, R.drawable.forward);
+ updateIcon(more, rtl ? R.drawable.close : R.drawable.more);
+ }
+
+ { // Divider
+ if (gradientDivider) {
+ float toolbarHeight = getResources().getDimension(R.dimen.toolbarHeight);
+ CoordinatorLayout.LayoutParams params =
+ (CoordinatorLayout.LayoutParams) gradient.getLayoutParams();
+ params.setMargins(0, (int) toolbarHeight, 0, 0);
+ gradient.setLayoutParams(params);
+ }
+ }
+
+ { // ProgressBar
+ progressBar.setMinimumHeight((int) progressBarHeight);
+ CoordinatorLayout.LayoutParams params =
+ new CoordinatorLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
+ (int) progressBarHeight);
+ float toolbarHeight = getResources().getDimension(R.dimen.toolbarHeight);
+ switch (progressBarPosition) {
+ case TOP_OF_TOOLBAR:
+ params.setMargins(0, 0, 0, 0);
+ break;
+ case BOTTON_OF_TOOLBAR:
+ params.setMargins(0, (int) toolbarHeight - (int) progressBarHeight, 0, 0);
+ break;
+ case TOP_OF_WEBVIEW:
+ params.setMargins(0, (int) toolbarHeight, 0, 0);
+ break;
+ case BOTTOM_OF_WEBVIEW:
+ params.setMargins(0, DisplayUtil.getHeight() - (int) progressBarHeight, 0, 0);
+ break;
+ }
+ progressBar.setLayoutParams(params);
+ }
+
+ { // WebLayout
+ float toolbarHeight = getResources().getDimension(R.dimen.toolbarHeight);
+ int statusBarHeight = DisplayUtil.getStatusBarHeight();
+ int screenHeight = DisplayUtil.getHeight();
+ float webLayoutMinimumHeight = screenHeight - toolbarHeight - statusBarHeight;
+ if (showDivider && !gradientDivider) webLayoutMinimumHeight -= dividerHeight;
+ webLayout.setMinimumHeight((int) webLayoutMinimumHeight);
}
- }
- if (webViewDisplayZoomControls != null
- && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
- settings.setDisplayZoomControls(webViewDisplayZoomControls);
- }
-
- if (webViewAllowFileAccess != null) settings.setAllowFileAccess(webViewAllowFileAccess);
- if (webViewAllowContentAccess != null
- && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
- settings.setAllowContentAccess(webViewAllowContentAccess);
- }
- if (webViewLoadWithOverviewMode != null) {
- settings.setLoadWithOverviewMode(webViewLoadWithOverviewMode);
- }
- if (webViewSaveFormData != null) settings.setSaveFormData(webViewSaveFormData);
- if (webViewTextZoom != null
- && Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
- settings.setTextZoom(webViewTextZoom);
- }
- if (webViewUseWideViewPort != null) settings.setUseWideViewPort(webViewUseWideViewPort);
- if (webViewSupportMultipleWindows != null) {
- settings.setSupportMultipleWindows(webViewSupportMultipleWindows);
- }
- if (webViewLayoutAlgorithm != null) settings.setLayoutAlgorithm(webViewLayoutAlgorithm);
- if (webViewStandardFontFamily != null) {
- settings.setStandardFontFamily(webViewStandardFontFamily);
- }
- if (webViewFixedFontFamily != null) settings.setFixedFontFamily(webViewFixedFontFamily);
- if (webViewSansSerifFontFamily != null) {
- settings.setSansSerifFontFamily(webViewSansSerifFontFamily);
- }
- if (webViewSerifFontFamily != null) settings.setSerifFontFamily(webViewSerifFontFamily);
- if (webViewCursiveFontFamily != null) settings.setCursiveFontFamily(webViewCursiveFontFamily);
- if (webViewFantasyFontFamily != null) settings.setFantasyFontFamily(webViewFantasyFontFamily);
- if (webViewMinimumFontSize != null) settings.setMinimumFontSize(webViewMinimumFontSize);
- if (webViewMinimumLogicalFontSize != null) {
- settings.setMinimumLogicalFontSize(webViewMinimumLogicalFontSize);
- }
- if (webViewDefaultFontSize != null) settings.setDefaultFontSize(webViewDefaultFontSize);
- if (webViewDefaultFixedFontSize != null) {
- settings.setDefaultFixedFontSize(webViewDefaultFixedFontSize);
- }
- if (webViewLoadsImagesAutomatically != null) {
- settings.setLoadsImagesAutomatically(webViewLoadsImagesAutomatically);
- }
- if (webViewBlockNetworkImage != null) settings.setBlockNetworkImage(webViewBlockNetworkImage);
- if (webViewBlockNetworkLoads != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
- settings.setBlockNetworkLoads(webViewBlockNetworkLoads);
- }
- if (webViewJavaScriptEnabled != null) settings.setJavaScriptEnabled(webViewJavaScriptEnabled);
- if (webViewAllowUniversalAccessFromFileURLs != null
- && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
- settings.setAllowUniversalAccessFromFileURLs(webViewAllowUniversalAccessFromFileURLs);
- }
- if (webViewAllowFileAccessFromFileURLs != null
- && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
- settings.setAllowFileAccessFromFileURLs(webViewAllowFileAccessFromFileURLs);
- }
- if (webViewGeolocationDatabasePath != null) {
- settings.setGeolocationDatabasePath(webViewGeolocationDatabasePath);
- }
- if (webViewAppCacheEnabled != null) settings.setAppCacheEnabled(webViewAppCacheEnabled);
- if (webViewAppCachePath != null) settings.setAppCachePath(webViewAppCachePath);
- if (webViewDatabaseEnabled != null) settings.setDatabaseEnabled(webViewDatabaseEnabled);
- if (webViewDomStorageEnabled != null) settings.setDomStorageEnabled(webViewDomStorageEnabled);
- if (webViewGeolocationEnabled != null) {
- settings.setGeolocationEnabled(webViewGeolocationEnabled);
- }
- if (webViewJavaScriptCanOpenWindowsAutomatically != null) {
- settings.setJavaScriptCanOpenWindowsAutomatically(
- webViewJavaScriptCanOpenWindowsAutomatically);
- }
- if (webViewDefaultTextEncodingName != null) {
- settings.setDefaultTextEncodingName(webViewDefaultTextEncodingName);
- }
- if (webViewUserAgentString != null) settings.setUserAgentString(webViewUserAgentString);
- if (webViewNeedInitialFocus != null) settings.setNeedInitialFocus(webViewNeedInitialFocus);
- if (webViewCacheMode != null) settings.setCacheMode(webViewCacheMode);
- if (webViewMixedContentMode != null
- && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
- settings.setMixedContentMode(webViewMixedContentMode);
- }
- if (webViewOffscreenPreRaster != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
- settings.setOffscreenPreRaster(webViewOffscreenPreRaster);
- }
-
- // // Other webview options
- // webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
- // webView.setScrollbarFadingEnabled(false);
- // //Additional Webview Properties
- // webView.setSoundEffectsEnabled(true);
- // webView.setHorizontalFadingEdgeEnabled(false);
- // webView.setKeepScreenOn(true);
- // webView.setScrollbarFadingEnabled(true);
- // webView.setVerticalFadingEdgeEnabled(false);
-
- if (data != null) {
- webView.loadData(data, mimeType, encoding);
- } else if (url != null) webView.loadUrl(url);
}
- { // SwipeRefreshLayout
- swipeRefreshLayout.setEnabled(showSwipeRefreshLayout);
- if (showSwipeRefreshLayout) {
- swipeRefreshLayout.post(new Runnable() {
- @Override public void run() {
- swipeRefreshLayout.setRefreshing(true);
- }
- });
- }
+ @SuppressLint("SetJavaScriptEnabled")
+ protected void initializeViews() {
+ setSupportActionBar(toolbar);
+
+ { // StatusBar
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ Window window = getWindow();
+ window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
+ window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
+ window.setStatusBarColor(statusBarColor);
+ }
+ }
+
+ { // AppBar
+ appBar.addOnOffsetChangedListener(this);
+ }
+
+ { // Toolbar
+ toolbar.setBackgroundColor(toolbarColor);
+ AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbar.getLayoutParams();
+ params.setScrollFlags(toolbarScrollFlags);
+ toolbar.setLayoutParams(params);
+ }
+
+ { // TextViews
+ title.setText(titleDefault);
+ title.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
+ title.setTypeface(TypefaceHelper.get(this, titleFont));
+ title.setTextColor(titleColor);
+
+ urlTv.setVisibility(showUrl ? View.VISIBLE : View.GONE);
+ urlTv.setText(UrlParser.getHost(url));
+ urlTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, urlSize);
+ urlTv.setTypeface(TypefaceHelper.get(this, urlFont));
+ urlTv.setTextColor(urlColor);
+
+ requestCenterLayout();
+ }
+
+ { // Icons
+ close.setBackgroundResource(iconSelector);
+ back.setBackgroundResource(iconSelector);
+ forward.setBackgroundResource(iconSelector);
+ more.setBackgroundResource(iconSelector);
+
+ close.setVisibility(showIconClose ? View.VISIBLE : View.GONE);
+ close.setEnabled(!disableIconClose);
+
+ if ((showMenuRefresh
+ || showMenuFind
+ || showMenuShareVia
+ || showMenuCopyLink
+ || showMenuOpenWith) && showIconMenu) {
+ more.setVisibility(View.VISIBLE);
+ } else {
+ more.setVisibility(View.GONE);
+ }
+ more.setEnabled(!disableIconMenu);
+ }
+
+ { // WebView
+ webView.setWebChromeClient(new MyWebChromeClient());
+ webView.setWebViewClient(new MyWebViewClient());
+ webView.setDownloadListener(downloadListener);
+
+ WebSettings settings = webView.getSettings();
+
+ if (webViewSupportZoom != null) settings.setSupportZoom(webViewSupportZoom);
+ if (webViewMediaPlaybackRequiresUserGesture != null
+ && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
+ settings.setMediaPlaybackRequiresUserGesture(webViewMediaPlaybackRequiresUserGesture);
+ }
+ if (webViewBuiltInZoomControls != null) {
+ settings.setBuiltInZoomControls(webViewBuiltInZoomControls);
+
+ if (webViewBuiltInZoomControls) {
+ // Remove NestedScrollView to enable BuiltInZoomControls
+ ((ViewGroup) webView.getParent()).removeAllViews();
+ swipeRefreshLayout.addView(webView);
+ swipeRefreshLayout.removeViewAt(1);
+ }
+ }
+ if (webViewDisplayZoomControls != null
+ && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
+ settings.setDisplayZoomControls(webViewDisplayZoomControls);
+ }
+
+ if (webViewAllowFileAccess != null) settings.setAllowFileAccess(webViewAllowFileAccess);
+ if (webViewAllowContentAccess != null
+ && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
+ settings.setAllowContentAccess(webViewAllowContentAccess);
+ }
+ if (webViewLoadWithOverviewMode != null) {
+ settings.setLoadWithOverviewMode(webViewLoadWithOverviewMode);
+ }
+ if (webViewSaveFormData != null) settings.setSaveFormData(webViewSaveFormData);
+ if (webViewTextZoom != null
+ && Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
+ settings.setTextZoom(webViewTextZoom);
+ }
+ if (webViewUseWideViewPort != null) settings.setUseWideViewPort(webViewUseWideViewPort);
+ if (webViewSupportMultipleWindows != null) {
+ settings.setSupportMultipleWindows(webViewSupportMultipleWindows);
+ }
+ if (webViewLayoutAlgorithm != null) settings.setLayoutAlgorithm(webViewLayoutAlgorithm);
+ if (webViewStandardFontFamily != null) {
+ settings.setStandardFontFamily(webViewStandardFontFamily);
+ }
+ if (webViewFixedFontFamily != null) settings.setFixedFontFamily(webViewFixedFontFamily);
+ if (webViewSansSerifFontFamily != null) {
+ settings.setSansSerifFontFamily(webViewSansSerifFontFamily);
+ }
+ if (webViewSerifFontFamily != null) settings.setSerifFontFamily(webViewSerifFontFamily);
+ if (webViewCursiveFontFamily != null)
+ settings.setCursiveFontFamily(webViewCursiveFontFamily);
+ if (webViewFantasyFontFamily != null)
+ settings.setFantasyFontFamily(webViewFantasyFontFamily);
+ if (webViewMinimumFontSize != null) settings.setMinimumFontSize(webViewMinimumFontSize);
+ if (webViewMinimumLogicalFontSize != null) {
+ settings.setMinimumLogicalFontSize(webViewMinimumLogicalFontSize);
+ }
+ if (webViewDefaultFontSize != null) settings.setDefaultFontSize(webViewDefaultFontSize);
+ if (webViewDefaultFixedFontSize != null) {
+ settings.setDefaultFixedFontSize(webViewDefaultFixedFontSize);
+ }
+ if (webViewLoadsImagesAutomatically != null) {
+ settings.setLoadsImagesAutomatically(webViewLoadsImagesAutomatically);
+ }
+ if (webViewBlockNetworkImage != null)
+ settings.setBlockNetworkImage(webViewBlockNetworkImage);
+ if (webViewBlockNetworkLoads != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
+ settings.setBlockNetworkLoads(webViewBlockNetworkLoads);
+ }
+ if (webViewJavaScriptEnabled != null)
+ settings.setJavaScriptEnabled(webViewJavaScriptEnabled);
+ if (webViewAllowUniversalAccessFromFileURLs != null
+ && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
+ settings.setAllowUniversalAccessFromFileURLs(webViewAllowUniversalAccessFromFileURLs);
+ }
+ if (webViewAllowFileAccessFromFileURLs != null
+ && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
+ settings.setAllowFileAccessFromFileURLs(webViewAllowFileAccessFromFileURLs);
+ }
+ if (webViewGeolocationDatabasePath != null) {
+ settings.setGeolocationDatabasePath(webViewGeolocationDatabasePath);
+ }
+ if (webViewAppCacheEnabled != null) settings.setAppCacheEnabled(webViewAppCacheEnabled);
+ if (webViewAppCachePath != null) settings.setAppCachePath(webViewAppCachePath);
+ if (webViewDatabaseEnabled != null) settings.setDatabaseEnabled(webViewDatabaseEnabled);
+ if (webViewDomStorageEnabled != null)
+ settings.setDomStorageEnabled(webViewDomStorageEnabled);
+ if (webViewGeolocationEnabled != null) {
+ settings.setGeolocationEnabled(webViewGeolocationEnabled);
+ }
+ if (webViewJavaScriptCanOpenWindowsAutomatically != null) {
+ settings.setJavaScriptCanOpenWindowsAutomatically(
+ webViewJavaScriptCanOpenWindowsAutomatically);
+ }
+ if (webViewDefaultTextEncodingName != null) {
+ settings.setDefaultTextEncodingName(webViewDefaultTextEncodingName);
+ }
+ if (webViewUserAgentString != null) settings.setUserAgentString(webViewUserAgentString);
+ if (webViewNeedInitialFocus != null)
+ settings.setNeedInitialFocus(webViewNeedInitialFocus);
+ if (webViewCacheMode != null) settings.setCacheMode(webViewCacheMode);
+ if (webViewMixedContentMode != null
+ && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ settings.setMixedContentMode(webViewMixedContentMode);
+ }
+ if (webViewOffscreenPreRaster != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ settings.setOffscreenPreRaster(webViewOffscreenPreRaster);
+ }
+ if (jsInteration != null) {
+ settings.setJavaScriptEnabled(true);
+ jsInteration.setContext(this);
+ webView.addJavascriptInterface(jsInteration, "android");
+ jsInteration.setWebView(webView);
+ }
+
+ // // Other webview options
+ // webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
+ // webView.setScrollbarFadingEnabled(false);
+ // //Additional Webview Properties
+ // webView.setSoundEffectsEnabled(true);
+ // webView.setHorizontalFadingEdgeEnabled(false);
+ // webView.setKeepScreenOn(true);
+ // webView.setScrollbarFadingEnabled(true);
+ // webView.setVerticalFadingEdgeEnabled(false);
+ builder.setWebView(webView);
+ if (data != null) {
+ webView.loadData(data, mimeType, encoding);
+ } else if (url != null) {
+ webView.loadUrl(url);
+ }
- if (swipeRefreshColors == null) {
- swipeRefreshLayout.setColorSchemeColors(swipeRefreshColor);
- } else {
- swipeRefreshLayout.setColorSchemeColors(swipeRefreshColors);
- }
- swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
- @Override public void onRefresh() {
- webView.reload();
}
- });
+
+ { // SwipeRefreshLayout
+ swipeRefreshLayout.setEnabled(showSwipeRefreshLayout);
+ if (showSwipeRefreshLayout) {
+ swipeRefreshLayout.post(new Runnable() {
+ @Override
+ public void run() {
+ swipeRefreshLayout.setRefreshing(true);
+ }
+ });
+ }
+
+ if (swipeRefreshColors == null) {
+ swipeRefreshLayout.setColorSchemeColors(swipeRefreshColor);
+ } else {
+ swipeRefreshLayout.setColorSchemeColors(swipeRefreshColors);
+ }
+
+ swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
+ @Override
+ public void onRefresh() {
+ webView.reload();
+ }
+ });
+ }
+
+ { // Divider
+ gradient.setVisibility(showDivider && gradientDivider ? View.VISIBLE : View.GONE);
+ divider.setVisibility(showDivider && !gradientDivider ? View.VISIBLE : View.GONE);
+ if (gradientDivider) {
+ int dividerWidth = DisplayUtil.getWidth();
+ Bitmap bitmap =
+ BitmapHelper.getGradientBitmap(dividerWidth, (int) dividerHeight, dividerColor);
+ BitmapDrawable drawable = new BitmapDrawable(getResources(), bitmap);
+ ViewUtil.setBackground(gradient, drawable);
+
+ CoordinatorLayout.LayoutParams params =
+ (CoordinatorLayout.LayoutParams) gradient.getLayoutParams();
+ params.height = (int) dividerHeight;
+ gradient.setLayoutParams(params);
+ } else {
+ divider.setBackgroundColor(dividerColor);
+
+ LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) divider.getLayoutParams();
+ params.height = (int) dividerHeight;
+ divider.setLayoutParams(params);
+ }
+ }
+
+ { // ProgressBar
+ progressBar.setVisibility(showProgressBar ? View.VISIBLE : View.GONE);
+ progressBar.getProgressDrawable().setColorFilter(progressBarColor, PorterDuff.Mode.SRC_IN);
+ progressBar.setMinimumHeight((int) progressBarHeight);
+ CoordinatorLayout.LayoutParams params =
+ new CoordinatorLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
+ (int) progressBarHeight);
+ float toolbarHeight = getResources().getDimension(R.dimen.toolbarHeight);
+ switch (progressBarPosition) {
+ case TOP_OF_TOOLBAR:
+ params.setMargins(0, 0, 0, 0);
+ break;
+ case BOTTON_OF_TOOLBAR:
+ params.setMargins(0, (int) toolbarHeight - (int) progressBarHeight, 0, 0);
+ break;
+ case TOP_OF_WEBVIEW:
+ params.setMargins(0, (int) toolbarHeight, 0, 0);
+ break;
+ case BOTTOM_OF_WEBVIEW:
+ params.setMargins(0, DisplayUtil.getHeight() - (int) progressBarHeight, 0, 0);
+ break;
+ }
+ progressBar.setLayoutParams(params);
+ }
+
+ { // Menu
+ GradientDrawable drawable = new GradientDrawable();
+ drawable.setCornerRadius(getResources().getDimension(R.dimen.defaultMenuCornerRadius));
+ drawable.setColor(menuColor);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
+ menuBackground.setBackground(drawable);
+ } else {
+ menuBackground.setBackgroundDrawable(drawable);
+ }
+
+ shadowLayout.setShadowColor(menuDropShadowColor);
+ shadowLayout.setShadowSize(menuDropShadowSize);
+
+ RelativeLayout.LayoutParams params =
+ new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
+ ViewGroup.LayoutParams.WRAP_CONTENT);
+ int margin =
+ (int) (getResources().getDimension(R.dimen.defaultMenuLayoutMargin) - menuDropShadowSize);
+ params.setMargins(0, margin, margin, 0);
+ params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
+ params.addRule(rtl ? RelativeLayout.ALIGN_PARENT_LEFT : RelativeLayout.ALIGN_PARENT_RIGHT);
+ shadowLayout.setLayoutParams(params);
+
+ menuRefresh.setVisibility(showMenuRefresh ? View.VISIBLE : View.GONE);
+ menuRefresh.setBackgroundResource(menuSelector);
+ menuRefresh.setGravity(menuTextGravity);
+ menuRefreshTv.setText(stringResRefresh);
+ menuRefreshTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, menuTextSize);
+ menuRefreshTv.setTypeface(TypefaceHelper.get(this, menuTextFont));
+ menuRefreshTv.setTextColor(menuTextColor);
+ menuRefreshTv.setPadding((int) menuTextPaddingLeft, 0, (int) menuTextPaddingRight, 0);
+
+ menuFind.setVisibility(showMenuFind ? View.VISIBLE : View.GONE);
+ menuFind.setBackgroundResource(menuSelector);
+ menuFind.setGravity(menuTextGravity);
+ menuFindTv.setText(stringResFind);
+ menuFindTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, menuTextSize);
+ menuFindTv.setTypeface(TypefaceHelper.get(this, menuTextFont));
+ menuFindTv.setTextColor(menuTextColor);
+ menuFindTv.setPadding((int) menuTextPaddingLeft, 0, (int) menuTextPaddingRight, 0);
+
+ menuShareVia.setVisibility(showMenuShareVia ? View.VISIBLE : View.GONE);
+ menuShareVia.setBackgroundResource(menuSelector);
+ menuShareVia.setGravity(menuTextGravity);
+ menuShareViaTv.setText(stringResShareVia);
+ menuShareViaTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, menuTextSize);
+ menuShareViaTv.setTypeface(TypefaceHelper.get(this, menuTextFont));
+ menuShareViaTv.setTextColor(menuTextColor);
+ menuShareViaTv.setPadding((int) menuTextPaddingLeft, 0, (int) menuTextPaddingRight, 0);
+
+ menuCopyLink.setVisibility(showMenuCopyLink ? View.VISIBLE : View.GONE);
+ menuCopyLink.setBackgroundResource(menuSelector);
+ menuCopyLink.setGravity(menuTextGravity);
+ menuCopyLinkTv.setText(stringResCopyLink);
+ menuCopyLinkTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, menuTextSize);
+ menuCopyLinkTv.setTypeface(TypefaceHelper.get(this, menuTextFont));
+ menuCopyLinkTv.setTextColor(menuTextColor);
+ menuCopyLinkTv.setPadding((int) menuTextPaddingLeft, 0, (int) menuTextPaddingRight, 0);
+
+ menuOpenWith.setVisibility(showMenuOpenWith ? View.VISIBLE : View.GONE);
+ menuOpenWith.setBackgroundResource(menuSelector);
+ menuOpenWith.setGravity(menuTextGravity);
+ menuOpenWithTv.setText(stringResOpenWith);
+ menuOpenWithTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, menuTextSize);
+ menuOpenWithTv.setTypeface(TypefaceHelper.get(this, menuTextFont));
+ menuOpenWithTv.setTextColor(menuTextColor);
+ menuOpenWithTv.setPadding((int) menuTextPaddingLeft, 0, (int) menuTextPaddingRight, 0);
+ }
+ }
+
+ protected int getMaxWidth() {
+ if (forward.getVisibility() == View.VISIBLE) {
+ return DisplayUtil.getWidth() - UnitConverter.dpToPx(100);
+ } else {
+ return DisplayUtil.getWidth() - UnitConverter.dpToPx(52);
+ }
}
- { // Divider
- gradient.setVisibility(showDivider && gradientDivider ? View.VISIBLE : View.GONE);
- divider.setVisibility(showDivider && !gradientDivider ? View.VISIBLE : View.GONE);
- if (gradientDivider) {
- int dividerWidth = DisplayUtil.getWidth();
- Bitmap bitmap =
- BitmapHelper.getGradientBitmap(dividerWidth, (int) dividerHeight, dividerColor);
- BitmapDrawable drawable = new BitmapDrawable(getResources(), bitmap);
- ViewUtil.setBackground(gradient, drawable);
-
- CoordinatorLayout.LayoutParams params =
- (CoordinatorLayout.LayoutParams) gradient.getLayoutParams();
- params.height = (int) dividerHeight;
- gradient.setLayoutParams(params);
- } else {
- divider.setBackgroundColor(dividerColor);
-
- LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) divider.getLayoutParams();
- params.height = (int) dividerHeight;
- divider.setLayoutParams(params);
- }
+ protected void updateIcon(ImageButton icon, @DrawableRes int drawableRes) {
+ StateListDrawable states = new StateListDrawable();
+ {
+ Bitmap bitmap = BitmapHelper.getColoredBitmap(this, drawableRes, iconPressedColor);
+ BitmapDrawable drawable = new BitmapDrawable(getResources(), bitmap);
+ states.addState(new int[]{android.R.attr.state_pressed}, drawable);
+ }
+ {
+ Bitmap bitmap = BitmapHelper.getColoredBitmap(this, drawableRes, iconDisabledColor);
+ BitmapDrawable drawable = new BitmapDrawable(getResources(), bitmap);
+ states.addState(new int[]{-android.R.attr.state_enabled}, drawable);
+ }
+ {
+ Bitmap bitmap = BitmapHelper.getColoredBitmap(this, drawableRes, iconDefaultColor);
+ BitmapDrawable drawable = new BitmapDrawable(getResources(), bitmap);
+ states.addState(new int[]{}, drawable);
+ }
+ icon.setImageDrawable(states);
+
+ // int[][] states = new int[][]{
+ // new int[]{-android.R.attr.state_enabled}, // disabled
+ // new int[]{android.R.attr.state_pressed}, // pressed
+ // new int[]{} // default
+ // };
+ //
+ // int[] colors = new int[]{
+ // iconDisabledColor,
+ // iconPressedColor,
+ // iconDefaultColor
+ // };
+ //
+ // ColorStateList colorStateList = new ColorStateList(states, colors);
+ //
+ // Drawable drawable = ContextCompat.getDrawable(this, drawableRes);
+ // if (APILevel.require(21)) {
+ // VectorDrawable vectorDrawable = (VectorDrawable) drawable;
+ // vectorDrawable.setTintList(colorStateList);
+ // icon.setImageDrawable(vectorDrawable);
+ // } else {
+ // VectorDrawableCompat vectorDrawable = (VectorDrawableCompat) drawable;
+ // vectorDrawable.setTintList(colorStateList);
+ // icon.setImageDrawable(vectorDrawable);
+ // }
}
- { // ProgressBar
- progressBar.setVisibility(showProgressBar ? View.VISIBLE : View.GONE);
- progressBar.getProgressDrawable().setColorFilter(progressBarColor, PorterDuff.Mode.SRC_IN);
- progressBar.setMinimumHeight((int) progressBarHeight);
- CoordinatorLayout.LayoutParams params =
- new CoordinatorLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
- (int) progressBarHeight);
- float toolbarHeight = getResources().getDimension(R.dimen.toolbarHeight);
- switch (progressBarPosition) {
- case TOP_OF_TOOLBAR:
- params.setMargins(0, 0, 0, 0);
- break;
- case BOTTON_OF_TOOLBAR:
- params.setMargins(0, (int) toolbarHeight - (int) progressBarHeight, 0, 0);
- break;
- case TOP_OF_WEBVIEW:
- params.setMargins(0, (int) toolbarHeight, 0, 0);
- break;
- case BOTTOM_OF_WEBVIEW:
- params.setMargins(0, DisplayUtil.getHeight() - (int) progressBarHeight, 0, 0);
- break;
- }
- progressBar.setLayoutParams(params);
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ initializeOptions();
+
+ setContentView(R.layout.finest_web_view);
+ bindViews();
+ layoutViews();
+ initializeViews();
}
- { // Menu
- GradientDrawable drawable = new GradientDrawable();
- drawable.setCornerRadius(getResources().getDimension(R.dimen.defaultMenuCornerRadius));
- drawable.setColor(menuColor);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
- menuBackground.setBackground(drawable);
- } else {
- menuBackground.setBackgroundDrawable(drawable);
- }
-
- shadowLayout.setShadowColor(menuDropShadowColor);
- shadowLayout.setShadowSize(menuDropShadowSize);
-
- RelativeLayout.LayoutParams params =
- new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
- ViewGroup.LayoutParams.WRAP_CONTENT);
- int margin =
- (int) (getResources().getDimension(R.dimen.defaultMenuLayoutMargin) - menuDropShadowSize);
- params.setMargins(0, margin, margin, 0);
- params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
- params.addRule(rtl ? RelativeLayout.ALIGN_PARENT_LEFT : RelativeLayout.ALIGN_PARENT_RIGHT);
- shadowLayout.setLayoutParams(params);
-
- menuRefresh.setVisibility(showMenuRefresh ? View.VISIBLE : View.GONE);
- menuRefresh.setBackgroundResource(menuSelector);
- menuRefresh.setGravity(menuTextGravity);
- menuRefreshTv.setText(stringResRefresh);
- menuRefreshTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, menuTextSize);
- menuRefreshTv.setTypeface(TypefaceHelper.get(this, menuTextFont));
- menuRefreshTv.setTextColor(menuTextColor);
- menuRefreshTv.setPadding((int) menuTextPaddingLeft, 0, (int) menuTextPaddingRight, 0);
-
- menuFind.setVisibility(showMenuFind ? View.VISIBLE : View.GONE);
- menuFind.setBackgroundResource(menuSelector);
- menuFind.setGravity(menuTextGravity);
- menuFindTv.setText(stringResFind);
- menuFindTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, menuTextSize);
- menuFindTv.setTypeface(TypefaceHelper.get(this, menuTextFont));
- menuFindTv.setTextColor(menuTextColor);
- menuFindTv.setPadding((int) menuTextPaddingLeft, 0, (int) menuTextPaddingRight, 0);
-
- menuShareVia.setVisibility(showMenuShareVia ? View.VISIBLE : View.GONE);
- menuShareVia.setBackgroundResource(menuSelector);
- menuShareVia.setGravity(menuTextGravity);
- menuShareViaTv.setText(stringResShareVia);
- menuShareViaTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, menuTextSize);
- menuShareViaTv.setTypeface(TypefaceHelper.get(this, menuTextFont));
- menuShareViaTv.setTextColor(menuTextColor);
- menuShareViaTv.setPadding((int) menuTextPaddingLeft, 0, (int) menuTextPaddingRight, 0);
-
- menuCopyLink.setVisibility(showMenuCopyLink ? View.VISIBLE : View.GONE);
- menuCopyLink.setBackgroundResource(menuSelector);
- menuCopyLink.setGravity(menuTextGravity);
- menuCopyLinkTv.setText(stringResCopyLink);
- menuCopyLinkTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, menuTextSize);
- menuCopyLinkTv.setTypeface(TypefaceHelper.get(this, menuTextFont));
- menuCopyLinkTv.setTextColor(menuTextColor);
- menuCopyLinkTv.setPadding((int) menuTextPaddingLeft, 0, (int) menuTextPaddingRight, 0);
-
- menuOpenWith.setVisibility(showMenuOpenWith ? View.VISIBLE : View.GONE);
- menuOpenWith.setBackgroundResource(menuSelector);
- menuOpenWith.setGravity(menuTextGravity);
- menuOpenWithTv.setText(stringResOpenWith);
- menuOpenWithTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, menuTextSize);
- menuOpenWithTv.setTypeface(TypefaceHelper.get(this, menuTextFont));
- menuOpenWithTv.setTextColor(menuTextColor);
- menuOpenWithTv.setPadding((int) menuTextPaddingLeft, 0, (int) menuTextPaddingRight, 0);
+ @Override
+ public void onBackPressed() {
+ if (menuLayout.getVisibility() == View.VISIBLE) {
+ hideMenu();
+ } else if (backPressToClose || !webView.canGoBack()) {
+ exitActivity();
+ } else {
+ webView.goBack();
+ }
}
- }
- protected int getMaxWidth() {
- if (forward.getVisibility() == View.VISIBLE) {
- return DisplayUtil.getWidth() - UnitConverter.dpToPx(100);
- } else {
- return DisplayUtil.getWidth() - UnitConverter.dpToPx(52);
+ @Override
+ public void onClick(View v) {
+ int viewId = v.getId();
+ if (viewId == R.id.close) {
+ if (rtl) {
+ showMenu();
+ } else {
+ exitActivity();
+ }
+ } else if (viewId == R.id.back) {
+ if (rtl) {
+ webView.goForward();
+ } else {
+ webView.goBack();
+ }
+ } else if (viewId == R.id.forward) {
+ if (rtl) {
+ webView.goBack();
+ } else {
+ webView.goForward();
+ }
+ } else if (viewId == R.id.more) {
+ if (rtl) {
+ exitActivity();
+ } else {
+ showMenu();
+ }
+ } else if (viewId == R.id.menuLayout) {
+ hideMenu();
+ } else if (viewId == R.id.menuRefresh) {
+ webView.reload();
+ hideMenu();
+ } else if (viewId == R.id.menuFind) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
+ webView.showFindDialog("", true);
+ hideMenu();
+ } else if (viewId == R.id.menuShareVia) {
+ Intent sendIntent = new Intent();
+ sendIntent.setAction(Intent.ACTION_SEND);
+ sendIntent.putExtra(Intent.EXTRA_TEXT, webView.getUrl());
+ sendIntent.setType("text/plain");
+ startActivity(Intent.createChooser(sendIntent, getResources().getString(stringResShareVia)));
+
+ hideMenu();
+ } else if (viewId == R.id.menuCopyLink) {
+ ClipboardManagerUtil.setText(webView.getUrl());
+
+ Snackbar snackbar = Snackbar.make(coordinatorLayout, getString(stringResCopiedToClipboard),
+ Snackbar.LENGTH_LONG);
+ View snackbarView = snackbar.getView();
+ snackbarView.setBackgroundColor(toolbarColor);
+ if (snackbarView instanceof ViewGroup) updateChildTextView((ViewGroup) snackbarView);
+ snackbar.show();
+
+ hideMenu();
+ } else if (viewId == R.id.menuOpenWith) {
+ Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(webView.getUrl()));
+ startActivity(browserIntent);
+
+ hideMenu();
+ }
}
- }
-
- protected void updateIcon(ImageButton icon, @DrawableRes int drawableRes) {
- StateListDrawable states = new StateListDrawable();
- {
- Bitmap bitmap = BitmapHelper.getColoredBitmap(this, drawableRes, iconPressedColor);
- BitmapDrawable drawable = new BitmapDrawable(getResources(), bitmap);
- states.addState(new int[] { android.R.attr.state_pressed }, drawable);
+
+ protected void updateChildTextView(ViewGroup viewGroup) {
+ if (viewGroup == null || viewGroup.getChildCount() == 0) return;
+
+ for (int i = 0; i < viewGroup.getChildCount(); i++) {
+ View view = viewGroup.getChildAt(i);
+ if (view instanceof TextView) {
+ TextView textView = (TextView) view;
+ textView.setTextColor(titleColor);
+ textView.setTypeface(TypefaceHelper.get(this, titleFont));
+ textView.setLineSpacing(0, 1.1f);
+ textView.setIncludeFontPadding(false);
+ }
+
+ if (view instanceof ViewGroup) updateChildTextView((ViewGroup) view);
+ }
}
- {
- Bitmap bitmap = BitmapHelper.getColoredBitmap(this, drawableRes, iconDisabledColor);
- BitmapDrawable drawable = new BitmapDrawable(getResources(), bitmap);
- states.addState(new int[] { -android.R.attr.state_enabled }, drawable);
+
+ protected void showMenu() {
+ menuLayout.setVisibility(View.VISIBLE);
+ Animation popupAnim = AnimationUtils.loadAnimation(this, R.anim.popup_flyout_show);
+ shadowLayout.startAnimation(popupAnim);
}
- {
- Bitmap bitmap = BitmapHelper.getColoredBitmap(this, drawableRes, iconDefaultColor);
- BitmapDrawable drawable = new BitmapDrawable(getResources(), bitmap);
- states.addState(new int[] {}, drawable);
+
+ protected void hideMenu() {
+ Animation popupAnim = AnimationUtils.loadAnimation(this, R.anim.popup_flyout_hide);
+ shadowLayout.startAnimation(popupAnim);
+ popupAnim.setAnimationListener(new Animation.AnimationListener() {
+ @Override
+ public void onAnimationStart(Animation animation) {
+ }
+
+ @Override
+ public void onAnimationEnd(Animation animation) {
+ menuLayout.setVisibility(View.GONE);
+ }
+
+ @Override
+ public void onAnimationRepeat(Animation animation) {
+ }
+ });
}
- icon.setImageDrawable(states);
-
- // int[][] states = new int[][]{
- // new int[]{-android.R.attr.state_enabled}, // disabled
- // new int[]{android.R.attr.state_pressed}, // pressed
- // new int[]{} // default
- // };
- //
- // int[] colors = new int[]{
- // iconDisabledColor,
- // iconPressedColor,
- // iconDefaultColor
- // };
- //
- // ColorStateList colorStateList = new ColorStateList(states, colors);
- //
- // Drawable drawable = ContextCompat.getDrawable(this, drawableRes);
- // if (APILevel.require(21)) {
- // VectorDrawable vectorDrawable = (VectorDrawable) drawable;
- // vectorDrawable.setTintList(colorStateList);
- // icon.setImageDrawable(vectorDrawable);
- // } else {
- // VectorDrawableCompat vectorDrawable = (VectorDrawableCompat) drawable;
- // vectorDrawable.setTintList(colorStateList);
- // icon.setImageDrawable(vectorDrawable);
- // }
- }
-
- @Override protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- initializeOptions();
-
- setContentView(R.layout.finest_web_view);
- bindViews();
- layoutViews();
- initializeViews();
- }
-
- @Override public void onBackPressed() {
- if (menuLayout.getVisibility() == View.VISIBLE) {
- hideMenu();
- } else if (backPressToClose || !webView.canGoBack()) {
- exitActivity();
- } else {
- webView.goBack();
+
+ protected void exitActivity() {
+ super.onBackPressed();
+ overridePendingTransition(animationCloseEnter, animationCloseExit);
}
- }
-
- @Override public void onClick(View v) {
- int viewId = v.getId();
- if (viewId == R.id.close) {
- if (rtl) {
- showMenu();
- } else {
- exitActivity();
- }
- } else if (viewId == R.id.back) {
- if (rtl) {
- webView.goForward();
- } else {
- webView.goBack();
- }
- } else if (viewId == R.id.forward) {
- if (rtl) {
- webView.goBack();
- } else {
- webView.goForward();
- }
- } else if (viewId == R.id.more) {
- if (rtl) {
- exitActivity();
- } else {
- showMenu();
- }
- } else if (viewId == R.id.menuLayout) {
- hideMenu();
- } else if (viewId == R.id.menuRefresh) {
- webView.reload();
- hideMenu();
- } else if (viewId == R.id.menuFind) {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) webView.showFindDialog("", true);
- hideMenu();
- } else if (viewId == R.id.menuShareVia) {
- Intent sendIntent = new Intent();
- sendIntent.setAction(Intent.ACTION_SEND);
- sendIntent.putExtra(Intent.EXTRA_TEXT, webView.getUrl());
- sendIntent.setType("text/plain");
- startActivity(Intent.createChooser(sendIntent, getResources().getString(stringResShareVia)));
-
- hideMenu();
- } else if (viewId == R.id.menuCopyLink) {
- ClipboardManagerUtil.setText(webView.getUrl());
-
- Snackbar snackbar = Snackbar.make(coordinatorLayout, getString(stringResCopiedToClipboard),
- Snackbar.LENGTH_LONG);
- View snackbarView = snackbar.getView();
- snackbarView.setBackgroundColor(toolbarColor);
- if (snackbarView instanceof ViewGroup) updateChildTextView((ViewGroup) snackbarView);
- snackbar.show();
-
- hideMenu();
- } else if (viewId == R.id.menuOpenWith) {
- Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(webView.getUrl()));
- startActivity(browserIntent);
-
- hideMenu();
+
+ @Override
+ public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
+ if (toolbarScrollFlags == 0) return;
+
+ ViewHelper.setTranslationY(gradient, verticalOffset);
+ ViewHelper.setAlpha(gradient,
+ 1 - (float) Math.abs(verticalOffset) / (float) appBarLayout.getTotalScrollRange());
+
+ switch (progressBarPosition) {
+ case BOTTON_OF_TOOLBAR:
+ ViewHelper.setTranslationY(progressBar,
+ Math.max(verticalOffset, progressBarHeight - appBarLayout.getTotalScrollRange()));
+ break;
+ case TOP_OF_WEBVIEW:
+ ViewHelper.setTranslationY(progressBar, verticalOffset);
+ break;
+ case TOP_OF_TOOLBAR:
+ case BOTTOM_OF_WEBVIEW:
+ default:
+ break;
+ }
+
+ if (menuLayout.getVisibility() == View.VISIBLE
+ && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
+ ViewHelper.setTranslationY(menuLayout,
+ Math.max(verticalOffset, -getResources().getDimension(R.dimen.defaultMenuLayoutMargin)));
+ }
}
- }
-
- protected void updateChildTextView(ViewGroup viewGroup) {
- if (viewGroup == null || viewGroup.getChildCount() == 0) return;
-
- for (int i = 0; i < viewGroup.getChildCount(); i++) {
- View view = viewGroup.getChildAt(i);
- if (view instanceof TextView) {
- TextView textView = (TextView) view;
- textView.setTextColor(titleColor);
- textView.setTypeface(TypefaceHelper.get(this, titleFont));
- textView.setLineSpacing(0, 1.1f);
- textView.setIncludeFontPadding(false);
- }
-
- if (view instanceof ViewGroup) updateChildTextView((ViewGroup) view);
+
+ protected void requestCenterLayout() {
+ int maxWidth;
+ if (webView.canGoBack() || webView.canGoForward()) {
+ maxWidth = DisplayUtil.getWidth() - UnitConverter.dpToPx(48) * 4;
+ } else {
+ maxWidth = DisplayUtil.getWidth() - UnitConverter.dpToPx(48) * 2;
+ }
+
+ title.setMaxWidth(maxWidth);
+ urlTv.setMaxWidth(maxWidth);
+ title.requestLayout();
+ urlTv.requestLayout();
}
- }
-
- protected void showMenu() {
- menuLayout.setVisibility(View.VISIBLE);
- Animation popupAnim = AnimationUtils.loadAnimation(this, R.anim.popup_flyout_show);
- shadowLayout.startAnimation(popupAnim);
- }
-
- protected void hideMenu() {
- Animation popupAnim = AnimationUtils.loadAnimation(this, R.anim.popup_flyout_hide);
- shadowLayout.startAnimation(popupAnim);
- popupAnim.setAnimationListener(new Animation.AnimationListener() {
- @Override public void onAnimationStart(Animation animation) {
- }
-
- @Override public void onAnimationEnd(Animation animation) {
- menuLayout.setVisibility(View.GONE);
- }
-
- @Override public void onAnimationRepeat(Animation animation) {
- }
- });
- }
-
- protected void exitActivity() {
- super.onBackPressed();
- overridePendingTransition(animationCloseEnter, animationCloseExit);
- }
-
- @Override public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
- if (toolbarScrollFlags == 0) return;
-
- ViewHelper.setTranslationY(gradient, verticalOffset);
- ViewHelper.setAlpha(gradient,
- 1 - (float) Math.abs(verticalOffset) / (float) appBarLayout.getTotalScrollRange());
-
- switch (progressBarPosition) {
- case BOTTON_OF_TOOLBAR:
- ViewHelper.setTranslationY(progressBar,
- Math.max(verticalOffset, progressBarHeight - appBarLayout.getTotalScrollRange()));
- break;
- case TOP_OF_WEBVIEW:
- ViewHelper.setTranslationY(progressBar, verticalOffset);
- break;
- case TOP_OF_TOOLBAR:
- case BOTTOM_OF_WEBVIEW:
- default:
- break;
+
+ @Override
+ public void onConfigurationChanged(Configuration newConfig) {
+ super.onConfigurationChanged(newConfig);
+
+ if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
+ layoutViews();
+ } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
+ layoutViews();
+ }
}
- if (menuLayout.getVisibility() == View.VISIBLE
- && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
- ViewHelper.setTranslationY(menuLayout,
- Math.max(verticalOffset, -getResources().getDimension(R.dimen.defaultMenuLayoutMargin)));
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ BroadCastManager.unregister(FinestWebViewActivity.this, key);
+ if (webView == null) return;
+ if (APILevel.require(11)) webView.onPause();
+ destroyWebView();
}
- }
-
- protected void requestCenterLayout() {
- int maxWidth;
- if (webView.canGoBack() || webView.canGoForward()) {
- maxWidth = DisplayUtil.getWidth() - UnitConverter.dpToPx(48) * 4;
- } else {
- maxWidth = DisplayUtil.getWidth() - UnitConverter.dpToPx(48) * 2;
+
+ // Wait for zoom control to fade away
+ // https://code.google.com/p/android/issues/detail?id=15694
+ // http://stackoverflow.com/a/5966151/1797648
+ private void destroyWebView() {
+ new Handler().postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ if (webView != null) webView.destroy();
+ }
+ }, ViewConfiguration.getZoomControlsTimeout() + 1000L);
}
- title.setMaxWidth(maxWidth);
- urlTv.setMaxWidth(maxWidth);
- title.requestLayout();
- urlTv.requestLayout();
- }
+ public class MyWebChromeClient extends WebChromeClient {
+
+ @Override
+ public void onProgressChanged(WebView view, int progress) {
+ BroadCastManager.onProgressChanged(FinestWebViewActivity.this, key, progress);
+
+ if (showSwipeRefreshLayout) {
+ if (swipeRefreshLayout.isRefreshing() && progress == 100) {
+ swipeRefreshLayout.post(new Runnable() {
+ @Override
+ public void run() {
+ swipeRefreshLayout.setRefreshing(false);
+ }
+ });
+ }
+
+ if (!swipeRefreshLayout.isRefreshing() && progress != 100) {
+ swipeRefreshLayout.post(new Runnable() {
+ @Override
+ public void run() {
+ swipeRefreshLayout.setRefreshing(true);
+ }
+ });
+ }
+ }
+
+ if (progress == 100) progress = 0;
+ progressBar.setProgress(progress);
+ }
- @Override public void onConfigurationChanged(Configuration newConfig) {
- super.onConfigurationChanged(newConfig);
+ @Override
+ public void onReceivedTitle(WebView view, String title) {
+ BroadCastManager.onReceivedTitle(FinestWebViewActivity.this, key, title);
+ }
- if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
- layoutViews();
- } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
- layoutViews();
+ @Override
+ public void onReceivedTouchIconUrl(WebView view, String url, boolean precomposed) {
+ BroadCastManager.onReceivedTouchIconUrl(FinestWebViewActivity.this, key, url, precomposed);
+ }
}
- }
-
- @Override protected void onDestroy() {
- super.onDestroy();
- BroadCastManager.unregister(FinestWebViewActivity.this, key);
- if (webView == null) return;
- if (APILevel.require(11)) webView.onPause();
- destroyWebView();
- }
-
- // Wait for zoom control to fade away
- // https://code.google.com/p/android/issues/detail?id=15694
- // http://stackoverflow.com/a/5966151/1797648
- private void destroyWebView() {
- new Handler().postDelayed(new Runnable() {
- @Override public void run() {
- if (webView != null) webView.destroy();
- }
- }, ViewConfiguration.getZoomControlsTimeout() + 1000L);
- }
-
- public class MyWebChromeClient extends WebChromeClient {
-
- @Override public void onProgressChanged(WebView view, int progress) {
- BroadCastManager.onProgressChanged(FinestWebViewActivity.this, key, progress);
-
- if (showSwipeRefreshLayout) {
- if (swipeRefreshLayout.isRefreshing() && progress == 100) {
- swipeRefreshLayout.post(new Runnable() {
- @Override public void run() {
- swipeRefreshLayout.setRefreshing(false);
+
+ public class MyWebViewClient extends WebViewClient {
+
+ @Override
+ public void onPageStarted(WebView view, String url, Bitmap favicon) {
+ BroadCastManager.onPageStarted(FinestWebViewActivity.this, key, url);
+ if (!url.contains("docs.google.com") && url.endsWith(".pdf")) {
+ webView.loadUrl("http://docs.google.com/gview?embedded=true&url=" + url);
}
- });
}
- if (!swipeRefreshLayout.isRefreshing() && progress != 100) {
- swipeRefreshLayout.post(new Runnable() {
- @Override public void run() {
- swipeRefreshLayout.setRefreshing(true);
+ @Override
+ public void onPageFinished(WebView view, String url) {
+ BroadCastManager.onPageFinished(FinestWebViewActivity.this, key, url);
+
+ if (updateTitleFromHtml) title.setText(view.getTitle());
+ urlTv.setText(UrlParser.getHost(url));
+ requestCenterLayout();
+
+ if (view.canGoBack() || view.canGoForward()) {
+ back.setVisibility(showIconBack ? View.VISIBLE : View.GONE);
+ forward.setVisibility(showIconForward ? View.VISIBLE : View.GONE);
+ back.setEnabled(!disableIconBack && (rtl ? view.canGoForward() : view.canGoBack()));
+ forward.setEnabled(!disableIconForward && (rtl ? view.canGoBack() : view.canGoForward()));
+ } else {
+ back.setVisibility(View.GONE);
+ forward.setVisibility(View.GONE);
+ }
+
+ if (injectJavaScript != null) {
+ webView.evaluateJavascript(injectJavaScript, null);
}
- });
}
- }
- if (progress == 100) progress = 0;
- progressBar.setProgress(progress);
- }
+ @Override
+ public boolean shouldOverrideUrlLoading(WebView view, String url) {
+ if (url.endsWith(".mp4")) {
+ Intent intent = new Intent(Intent.ACTION_VIEW);
+ intent.setDataAndType(Uri.parse(url), "video/*");
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ view.getContext().startActivity(intent);
+ // If we return true, onPageStarted, onPageFinished won't be called.
+ return true;
+ } else if (url.startsWith("tel:") || url.startsWith("sms:") || url.startsWith("smsto:") || url
+ .startsWith("mms:") || url.startsWith("mmsto:")) {
+ Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ view.getContext().startActivity(intent);
+ return true; // If we return true, onPageStarted, onPageFinished won't be called.
+ }
+ /*******************************************************
+ * Added in support for mailto:
+ *******************************************************/
+ else if (url.startsWith("mailto:")) {
- @Override public void onReceivedTitle(WebView view, String title) {
- BroadCastManager.onReceivedTitle(FinestWebViewActivity.this, key, title);
- }
+ MailTo mt = MailTo.parse(url);
- @Override public void onReceivedTouchIconUrl(WebView view, String url, boolean precomposed) {
- BroadCastManager.onReceivedTouchIconUrl(FinestWebViewActivity.this, key, url, precomposed);
- }
- }
+ Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
- public class MyWebViewClient extends WebViewClient {
+ emailIntent.setType("text/html");
+ emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{mt.getTo()});
+ emailIntent.putExtra(Intent.EXTRA_SUBJECT, mt.getSubject());
+ emailIntent.putExtra(Intent.EXTRA_CC, mt.getCc());
+ emailIntent.putExtra(Intent.EXTRA_TEXT, mt.getBody());
- @Override public void onPageStarted(WebView view, String url, Bitmap favicon) {
- BroadCastManager.onPageStarted(FinestWebViewActivity.this, key, url);
- if (!url.contains("docs.google.com") && url.endsWith(".pdf")) {
- webView.loadUrl("http://docs.google.com/gview?embedded=true&url=" + url);
- }
- }
-
- @Override public void onPageFinished(WebView view, String url) {
- BroadCastManager.onPageFinished(FinestWebViewActivity.this, key, url);
-
- if (updateTitleFromHtml) title.setText(view.getTitle());
- urlTv.setText(UrlParser.getHost(url));
- requestCenterLayout();
-
- if (view.canGoBack() || view.canGoForward()) {
- back.setVisibility(showIconBack ? View.VISIBLE : View.GONE);
- forward.setVisibility(showIconForward ? View.VISIBLE : View.GONE);
- back.setEnabled(!disableIconBack && (rtl ? view.canGoForward() : view.canGoBack()));
- forward.setEnabled(!disableIconForward && (rtl ? view.canGoBack() : view.canGoForward()));
- } else {
- back.setVisibility(View.GONE);
- forward.setVisibility(View.GONE);
- }
-
- if (injectJavaScript != null) {
- webView.evaluateJavascript(injectJavaScript, null);
- }
- }
+ startActivity(emailIntent);
- @Override public boolean shouldOverrideUrlLoading(WebView view, String url) {
- if (url.endsWith(".mp4")) {
- Intent intent = new Intent(Intent.ACTION_VIEW);
- intent.setDataAndType(Uri.parse(url), "video/*");
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- view.getContext().startActivity(intent);
- // If we return true, onPageStarted, onPageFinished won't be called.
- return true;
- } else if (url.startsWith("tel:") || url.startsWith("sms:") || url.startsWith("smsto:") || url
- .startsWith("mms:") || url.startsWith("mmsto:")) {
- Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- view.getContext().startActivity(intent);
- return true; // If we return true, onPageStarted, onPageFinished won't be called.
- }
- /*******************************************************
- * Added in support for mailto:
- *******************************************************/
- else if (url.startsWith("mailto:")) {
-
- MailTo mt = MailTo.parse(url);
-
- Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
-
- emailIntent.setType("text/html");
- emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { mt.getTo() });
- emailIntent.putExtra(Intent.EXTRA_SUBJECT, mt.getSubject());
- emailIntent.putExtra(Intent.EXTRA_CC, mt.getCc());
- emailIntent.putExtra(Intent.EXTRA_TEXT, mt.getBody());
-
- startActivity(emailIntent);
-
- return true;
- } else {
- return super.shouldOverrideUrlLoading(view, url);
- }
- }
+ return true;
+ } else {
+ return super.shouldOverrideUrlLoading(view, url);
+ }
+ }
- @Override public void onLoadResource(WebView view, String url) {
- BroadCastManager.onLoadResource(FinestWebViewActivity.this, key, url);
- }
+ @Override
+ public void onLoadResource(WebView view, String url) {
+ BroadCastManager.onLoadResource(FinestWebViewActivity.this, key, url);
+ }
- @Override public void onPageCommitVisible(WebView view, String url) {
- BroadCastManager.onPageCommitVisible(FinestWebViewActivity.this, key, url);
+ @Override
+ public void onPageCommitVisible(WebView view, String url) {
+ BroadCastManager.onPageCommitVisible(FinestWebViewActivity.this, key, url);
+ }
}
- }
}
diff --git a/sample/gradle/wrapper/gradle-wrapper.jar b/sample/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 0000000..13372ae
Binary files /dev/null and b/sample/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/sample/gradle/wrapper/gradle-wrapper.properties b/sample/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 0000000..04e285f
--- /dev/null
+++ b/sample/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Mon Dec 28 10:00:20 PST 2015
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
diff --git a/sample/gradlew b/sample/gradlew
new file mode 100644
index 0000000..9d82f78
--- /dev/null
+++ b/sample/gradlew
@@ -0,0 +1,160 @@
+#!/usr/bin/env bash
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn ( ) {
+ echo "$*"
+}
+
+die ( ) {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+esac
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >/dev/null
+APP_HOME="`pwd -P`"
+cd "$SAVED" >/dev/null
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+ JAVACMD=`cygpath --unix "$JAVACMD"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=$((i+1))
+ done
+ case $i in
+ (0) set -- ;;
+ (1) set -- "$args0" ;;
+ (2) set -- "$args0" "$args1" ;;
+ (3) set -- "$args0" "$args1" "$args2" ;;
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
+function splitJvmOpts() {
+ JVM_OPTS=("$@")
+}
+eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
+JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
+
+exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
diff --git a/sample/gradlew.bat b/sample/gradlew.bat
new file mode 100644
index 0000000..8a0b282
--- /dev/null
+++ b/sample/gradlew.bat
@@ -0,0 +1,90 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windowz variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+if "%@eval[2+2]" == "4" goto 4NT_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+goto execute
+
+:4NT_args
+@rem Get arguments from the 4NT Shell from JP Software
+set CMD_LINE_ARGS=%$
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml
index 7865d3d..b1dfc56 100644
--- a/sample/src/main/AndroidManifest.xml
+++ b/sample/src/main/AndroidManifest.xml
@@ -30,6 +30,7 @@
android:theme="@style/FinestWebViewTheme.Light"/>
+
diff --git a/sample/src/main/java/com/thefinestartist/finestwebview/sample/JsInteration.java b/sample/src/main/java/com/thefinestartist/finestwebview/sample/JsInteration.java
new file mode 100644
index 0000000..5aea6f9
--- /dev/null
+++ b/sample/src/main/java/com/thefinestartist/finestwebview/sample/JsInteration.java
@@ -0,0 +1,40 @@
+package com.thefinestartist.finestwebview.sample;
+
+import android.content.Intent;
+import android.webkit.JavascriptInterface;
+
+import com.thefinestartist.finestwebview.BaseJsInteration;
+import com.thefinestartist.utils.log.L;
+
+import java.io.Serializable;
+
+/**
+ * Created by Administrator on 2017/2/17.
+ */
+
+public class JsInteration extends BaseJsInteration implements Serializable {
+
+
+ @JavascriptInterface
+ public void toActivity() {
+ Intent intent = new Intent(instance, TestActivity.class);
+ instance.startActivity(intent);
+ }
+
+ @JavascriptInterface
+ public String jsToAndroid() {
+ instance.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ //这是安卓调用JS中的方法,JS中必须声明了对应androidToJs(param)函数,第二个参数为回调,如果你需要该方法的返回值就加上回调接口
+ //该方法必须在UIThread中调用。如果你是在Fragment中可以用getActivity.runOnUiThread
+ if(webView!=null){
+ webView.evaluateJavascript("javascript:anroidToJs('Android invok JS ')", null);
+ }else{
+ L.e("webview is null");
+ }
+ }
+ });
+ return "JS invok Android";
+ }
+}
diff --git a/sample/src/main/java/com/thefinestartist/finestwebview/sample/MainActivity.java b/sample/src/main/java/com/thefinestartist/finestwebview/sample/MainActivity.java
index e88cdeb..833456a 100644
--- a/sample/src/main/java/com/thefinestartist/finestwebview/sample/MainActivity.java
+++ b/sample/src/main/java/com/thefinestartist/finestwebview/sample/MainActivity.java
@@ -4,86 +4,103 @@
import android.support.v7.app.AppCompatActivity;
import android.view.Gravity;
import android.view.View;
+import android.webkit.JavascriptInterface;
+
import com.thefinestartist.finestwebview.FinestWebView;
-public class MainActivity extends AppCompatActivity {
- @Override protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- }
+public class MainActivity extends AppCompatActivity{
+
+ private FinestWebView.Builder builder;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.main);
+ }
+
+ public void onClick(View view) {
+ if (view.getId() == R.id.defaultTheme) {
+ new FinestWebView.Builder(this).titleDefault("The Finest Artist")
+ .show("http://thefinestartist.com");
+ //// .toolbarScrollFlags(0)
+ // .webViewJavaScriptEnabled(true)
+ // .webViewUseWideViewPort(false)
+ //// .show("http://andrewliu.in/2016/01/30/聊聊Redis的订阅发布/");
+ // .show("http://www.youtube.com");
+ } else if (view.getId() == R.id.redTheme) {
+ // Intent intent = new Intent(this, WebViewActivity.class);
+ // startActivity(intent);
+ new FinestWebView.Builder(this).theme(R.style.RedTheme)
+ .titleDefault("Bless This Stuff")
+ .webViewBuiltInZoomControls(true)
+ .webViewDisplayZoomControls(true)
+ .dividerHeight(0)
+ .gradientDivider(false)
+ .webViewJavaScriptEnabled(true)//设置可以和JAVA交互
+ .addJavascriptInterface(new JsInteration())//JS将可以调用该类下面的@JavascriptInterface修饰的方法,此类须implements Serializable
+ .setCustomAnimations(R.anim.activity_open_enter, R.anim.activity_open_exit,
+ R.anim.activity_close_enter, R.anim.activity_close_exit)
+ .show("http://test.2000new.com/nyd/water/index.html");
+ } else if (view.getId() == R.id.blueTheme) {
+ builder = new FinestWebView.Builder(this).theme(R.style.FinestWebViewTheme)
+ .titleDefault("Vimeo")
+ .showUrl(false)
+ .statusBarColorRes(R.color.bluePrimaryDark)
+ .toolbarColorRes(R.color.bluePrimary)
+ .titleColorRes(R.color.finestWhite)
+ .urlColorRes(R.color.bluePrimaryLight)
+ .iconDefaultColorRes(R.color.finestWhite)
+ .progressBarColorRes(R.color.finestWhite)
+ .stringResCopiedToClipboard(R.string.copied_to_clipboard)
+ .stringResCopiedToClipboard(R.string.copied_to_clipboard)
+ .stringResCopiedToClipboard(R.string.copied_to_clipboard)
+ .showSwipeRefreshLayout(true)
+ .swipeRefreshColorRes(R.color.bluePrimaryDark)
+ .menuSelector(R.drawable.selector_light_theme)
+ .menuTextGravity(Gravity.CENTER)
+ .menuTextPaddingRightRes(R.dimen.defaultMenuTextPaddingLeft)
+ .dividerHeight(0)
+ .gradientDivider(false)
+
+ .setCustomAnimations(R.anim.slide_up, R.anim.hold, R.anim.hold, R.anim.slide_down);
+ builder.show("http://test.2000new.com/nyd/water/index.html");
+ } else if (view.getId() == R.id.blackTheme) {
+ new FinestWebView.Builder(this).theme(R.style.FinestWebViewTheme)
+ .titleDefault("Dribbble")
+ .toolbarScrollFlags(0)
+ .statusBarColorRes(R.color.blackPrimaryDark)
+ .toolbarColorRes(R.color.blackPrimary)
+ .titleColorRes(R.color.finestWhite)
+ .urlColorRes(R.color.blackPrimaryLight)
+ .iconDefaultColorRes(R.color.finestWhite)
+ .progressBarColorRes(R.color.finestWhite)
+ .swipeRefreshColorRes(R.color.blackPrimaryDark)
+ .menuSelector(R.drawable.selector_light_theme)
+ .menuTextGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT)
+ .menuTextPaddingRightRes(R.dimen.defaultMenuTextPaddingLeft)
+ .dividerHeight(0)
+ .gradientDivider(false)
+ // .setCustomAnimations(R.anim.slide_up, R.anim.hold, R.anim.hold, R.anim.slide_down)
+ .setCustomAnimations(R.anim.slide_left_in, R.anim.hold, R.anim.hold,
+ R.anim.slide_right_out)
+ // .setCustomAnimations(R.anim.fade_in_fast, R.anim.fade_out_medium, R.anim.fade_in_medium, R.anim.fade_out_fast)
+ .disableIconBack(true)
+ .disableIconClose(true)
+ .disableIconForward(true)
+ .disableIconMenu(true)
+ .show("https://dribbble.com");
+ }
+ }
- public void onClick(View view) {
- if (view.getId() == R.id.defaultTheme) {
- new FinestWebView.Builder(this).titleDefault("The Finest Artist")
- .show("http://thefinestartist.com");
- //// .toolbarScrollFlags(0)
- // .webViewJavaScriptEnabled(true)
- // .webViewUseWideViewPort(false)
- //// .show("http://andrewliu.in/2016/01/30/聊聊Redis的订阅发布/");
- // .show("http://www.youtube.com");
- } else if (view.getId() == R.id.redTheme) {
- // Intent intent = new Intent(this, WebViewActivity.class);
- // startActivity(intent);
- new FinestWebView.Builder(this).theme(R.style.RedTheme)
- .titleDefault("Bless This Stuff")
- .webViewBuiltInZoomControls(true)
- .webViewDisplayZoomControls(true)
- .dividerHeight(0)
- .gradientDivider(false)
- .setCustomAnimations(R.anim.activity_open_enter, R.anim.activity_open_exit,
- R.anim.activity_close_enter, R.anim.activity_close_exit)
- .injectJavaScript("javascript: document.getElementById('msg').innerHTML='Hello "
- + "TheFinestArtist"
- + "!';")
- .show("http://www.blessthisstuff.com");
- } else if (view.getId() == R.id.blueTheme) {
- new FinestWebView.Builder(this).theme(R.style.FinestWebViewTheme)
- .titleDefault("Vimeo")
- .showUrl(false)
- .statusBarColorRes(R.color.bluePrimaryDark)
- .toolbarColorRes(R.color.bluePrimary)
- .titleColorRes(R.color.finestWhite)
- .urlColorRes(R.color.bluePrimaryLight)
- .iconDefaultColorRes(R.color.finestWhite)
- .progressBarColorRes(R.color.finestWhite)
- .stringResCopiedToClipboard(R.string.copied_to_clipboard)
- .stringResCopiedToClipboard(R.string.copied_to_clipboard)
- .stringResCopiedToClipboard(R.string.copied_to_clipboard)
- .showSwipeRefreshLayout(true)
- .swipeRefreshColorRes(R.color.bluePrimaryDark)
- .menuSelector(R.drawable.selector_light_theme)
- .menuTextGravity(Gravity.CENTER)
- .menuTextPaddingRightRes(R.dimen.defaultMenuTextPaddingLeft)
- .dividerHeight(0)
- .gradientDivider(false)
- .setCustomAnimations(R.anim.slide_up, R.anim.hold, R.anim.hold, R.anim.slide_down)
- .show("http://example.com");
- } else if (view.getId() == R.id.blackTheme) {
- new FinestWebView.Builder(this).theme(R.style.FinestWebViewTheme)
- .titleDefault("Dribbble")
- .toolbarScrollFlags(0)
- .statusBarColorRes(R.color.blackPrimaryDark)
- .toolbarColorRes(R.color.blackPrimary)
- .titleColorRes(R.color.finestWhite)
- .urlColorRes(R.color.blackPrimaryLight)
- .iconDefaultColorRes(R.color.finestWhite)
- .progressBarColorRes(R.color.finestWhite)
- .swipeRefreshColorRes(R.color.blackPrimaryDark)
- .menuSelector(R.drawable.selector_light_theme)
- .menuTextGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT)
- .menuTextPaddingRightRes(R.dimen.defaultMenuTextPaddingLeft)
- .dividerHeight(0)
- .gradientDivider(false)
- // .setCustomAnimations(R.anim.slide_up, R.anim.hold, R.anim.hold, R.anim.slide_down)
- .setCustomAnimations(R.anim.slide_left_in, R.anim.hold, R.anim.hold,
- R.anim.slide_right_out)
- // .setCustomAnimations(R.anim.fade_in_fast, R.anim.fade_out_medium, R.anim.fade_in_medium, R.anim.fade_out_fast)
- .disableIconBack(true)
- .disableIconClose(true)
- .disableIconForward(true)
- .disableIconMenu(true)
- .show("https://dribbble.com");
+ @JavascriptInterface
+ public String jsToAndroid() {
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ builder.getWebView().evaluateJavascript("javascript:anroidToJs('安卓调用JS ')", null);//调用JAVA中的方法
+ }
+ });
+ return "JS调用安卓";
}
- }
}
diff --git a/sample/src/main/java/com/thefinestartist/finestwebview/sample/TestActivity.java b/sample/src/main/java/com/thefinestartist/finestwebview/sample/TestActivity.java
new file mode 100644
index 0000000..fdc5946
--- /dev/null
+++ b/sample/src/main/java/com/thefinestartist/finestwebview/sample/TestActivity.java
@@ -0,0 +1,16 @@
+package com.thefinestartist.finestwebview.sample;
+
+import android.os.Bundle;
+import android.support.annotation.Nullable;
+import android.support.v4.app.FragmentActivity;
+
+/**
+ * Created by Administrator on 2017/2/17.
+ */
+
+public class TestActivity extends FragmentActivity {
+ @Override
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ }
+}