Skip to content

Commit 2a4f734

Browse files
author
TheFinestArtist
committed
Add webview setting options
1 parent 43a6be7 commit 2a4f734

File tree

4 files changed

+445
-73
lines changed

4 files changed

+445
-73
lines changed

README.md

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -253,15 +253,47 @@ stringResCopiedToClipboard(@StringRes int stringResCopiedToClipboard);
253253

254254
**WebView Options**
255255
```java
256-
webViewJavaScriptEnabled(boolean webViewJavaScriptEnabled);
257-
webViewAppCacheEnabled(boolean webViewAppCacheEnabled);
258-
webViewAllowFileAccess(boolean webViewAllowFileAccess);
259-
webViewUseWideViewPort(boolean webViewUseWideViewPort);
260-
webViewLoadWithOverviewMode(boolean webViewLoadWithOverviewMode);
261-
webViewDomStorageEnabled(boolean webViewDomStorageEnabled);
262-
webViewDisplayZoomControls(boolean webViewDisplayZoomControls);
263-
webViewBuiltInZoomControls(boolean webViewBuiltInZoomControls);
264-
webViewDesktopMode(boolean webViewDesktopMode);
256+
webViewSupportZoom(boolean webViewSupportZoom);
257+
webViewMediaPlaybackRequiresUserGesture (boolean webViewMediaPlaybackRequiresUserGesture);
258+
webViewBuiltInZoomControls (boolean webViewBuiltInZoomControls);
259+
webViewDisplayZoomControls (boolean webViewDisplayZoomControls);
260+
webViewAllowFileAccess (boolean webViewAllowFileAccess);
261+
webViewAllowContentAccess (boolean webViewAllowContentAccess);
262+
webViewLoadWithOverviewMode (boolean webViewLoadWithOverviewMode);
263+
webViewSaveFormData (boolean webViewSaveFormData);
264+
webViewTextZoom (int webViewTextZoom);
265+
webViewUseWideViewPort (boolean webViewUseWideViewPort);
266+
webViewSupportMultipleWindows (boolean webViewSupportMultipleWindows);
267+
webViewLayoutAlgorithm (WebSettings.LayoutAlgorithm webViewLayoutAlgorithm);
268+
webViewStandardFontFamily (String webViewStandardFontFamily);
269+
webViewFixedFontFamily (String webViewFixedFontFamily);
270+
webViewSansSerifFontFamily (String webViewSansSerifFontFamily);
271+
webViewSerifFontFamily (String webViewSerifFontFamily);
272+
webViewCursiveFontFamily (String webViewCursiveFontFamily);
273+
webViewFantasyFontFamily (String webViewFantasyFontFamily);
274+
webViewMinimumFontSize (int webViewMinimumFontSize);
275+
webViewMinimumLogicalFontSize (int webViewMinimumLogicalFontSize);
276+
webViewDefaultFontSize (int webViewDefaultFontSize);
277+
webViewDefaultFixedFontSize (int webViewDefaultFixedFontSize);
278+
webViewLoadsImagesAutomatically (boolean webViewLoadsImagesAutomatically);
279+
webViewBlockNetworkImage (boolean webViewBlockNetworkImage);
280+
webViewBlockNetworkLoads (boolean webViewBlockNetworkLoads);
281+
webViewJavaScriptEnabled (boolean webViewJavaScriptEnabled);
282+
webViewAllowUniversalAccessFromFileURLs (boolean webViewAllowUniversalAccessFromFileURLs);
283+
webViewAllowFileAccessFromFileURLs (boolean webViewAllowFileAccessFromFileURLs);
284+
webViewGeolocationDatabasePath (String webViewGeolocationDatabasePath);
285+
webViewAppCacheEnabled (boolean webViewAppCacheEnabled);
286+
webViewAppCachePath (String webViewAppCachePath);
287+
webViewDatabaseEnabled (boolean webViewDatabaseEnabled);
288+
webViewDomStorageEnabled (boolean webViewDomStorageEnabled);
289+
webViewGeolocationEnabled (boolean webViewGeolocationEnabled);
290+
webViewJavaScriptCanOpenWindowsAutomatically (boolean webViewJavaScriptCanOpenWindowsAutomatically);
291+
webViewDefaultTextEncodingName (String webViewDefaultTextEncodingName);
292+
webViewUserAgentString (String webViewUserAgentString);
293+
webViewNeedInitialFocus (boolean webViewNeedInitialFocus);
294+
webViewCacheMode (int webViewCacheMode);
295+
webViewMixedContentMode (int webViewMixedContentMode);
296+
webViewOffscreenPreRaster (boolean webViewOffscreenPreRaster);
265297

266298
injectJavaScript(String injectJavaScript);
267299
```
@@ -408,6 +440,10 @@ new FinestWebView.Builder(activity)
408440
.show(url);
409441
```
410442

443+
#### WebView Desktop Mode
444+
445+
You can force WebView to show in desktop mode by setting `webViewUserAgentString("Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.4) Gecko/20100101 Firefox/4.0")`.
446+
411447
## Designer
412448

413449
#### [Min Kim](https://github.com/openyourboxes)

library/src/main/java/com/thefinestartist/finestwebview/FinestWebView.java

Lines changed: 222 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import android.support.annotation.StyleRes;
1414
import android.support.design.widget.AppBarLayout.LayoutParams.ScrollFlags;
1515
import android.support.v4.content.ContextCompat;
16+
import android.webkit.WebSettings;
1617

1718
import com.thefinestartist.finestwebview.enums.Position;
1819

@@ -104,15 +105,47 @@ public static class Builder implements Serializable {
104105
protected Boolean backPressToClose;
105106
protected Integer stringResCopiedToClipboard;
106107

107-
protected Boolean webViewJavaScriptEnabled;
108-
protected Boolean webViewAppCacheEnabled;
108+
protected Boolean webViewSupportZoom;
109+
protected Boolean webViewMediaPlaybackRequiresUserGesture;
110+
protected Boolean webViewBuiltInZoomControls;
111+
protected Boolean webViewDisplayZoomControls;
109112
protected Boolean webViewAllowFileAccess;
110-
protected Boolean webViewUseWideViewPort;
113+
protected Boolean webViewAllowContentAccess;
111114
protected Boolean webViewLoadWithOverviewMode;
115+
protected Boolean webViewSaveFormData;
116+
protected Integer webViewTextZoom;
117+
protected Boolean webViewUseWideViewPort;
118+
protected Boolean webViewSupportMultipleWindows;
119+
protected WebSettings.LayoutAlgorithm webViewLayoutAlgorithm;
120+
protected String webViewStandardFontFamily;
121+
protected String webViewFixedFontFamily;
122+
protected String webViewSansSerifFontFamily;
123+
protected String webViewSerifFontFamily;
124+
protected String webViewCursiveFontFamily;
125+
protected String webViewFantasyFontFamily;
126+
protected Integer webViewMinimumFontSize;
127+
protected Integer webViewMinimumLogicalFontSize;
128+
protected Integer webViewDefaultFontSize;
129+
protected Integer webViewDefaultFixedFontSize;
130+
protected Boolean webViewLoadsImagesAutomatically;
131+
protected Boolean webViewBlockNetworkImage;
132+
protected Boolean webViewBlockNetworkLoads;
133+
protected Boolean webViewJavaScriptEnabled;
134+
protected Boolean webViewAllowUniversalAccessFromFileURLs;
135+
protected Boolean webViewAllowFileAccessFromFileURLs;
136+
protected String webViewGeolocationDatabasePath;
137+
protected Boolean webViewAppCacheEnabled;
138+
protected String webViewAppCachePath;
139+
protected Boolean webViewDatabaseEnabled;
112140
protected Boolean webViewDomStorageEnabled;
113-
protected Boolean webViewBuiltInZoomControls;
114-
protected Boolean webViewDisplayZoomControls;
115-
protected Boolean webViewDesktopMode;
141+
protected Boolean webViewGeolocationEnabled;
142+
protected Boolean webViewJavaScriptCanOpenWindowsAutomatically;
143+
protected String webViewDefaultTextEncodingName;
144+
protected String webViewUserAgentString;
145+
protected Boolean webViewNeedInitialFocus;
146+
protected Integer webViewCacheMode;
147+
protected Integer webViewMixedContentMode;
148+
protected Boolean webViewOffscreenPreRaster;
116149

117150
protected String injectJavaScript;
118151

@@ -586,51 +619,219 @@ public Builder stringResCopiedToClipboard(@StringRes int stringResCopiedToClipbo
586619
return this;
587620
}
588621

589-
public Builder webViewJavaScriptEnabled(boolean webViewJavaScriptEnabled) {
590-
this.webViewJavaScriptEnabled = webViewJavaScriptEnabled;
622+
public Builder webViewSupportZoom(boolean webViewSupportZoom) {
623+
this.webViewSupportZoom = webViewSupportZoom;
591624
return this;
592625
}
593626

594-
public Builder webViewAppCacheEnabled(boolean webViewAppCacheEnabled) {
595-
this.webViewAppCacheEnabled = webViewAppCacheEnabled;
627+
public Builder webViewMediaPlaybackRequiresUserGesture (boolean webViewMediaPlaybackRequiresUserGesture) {
628+
this.webViewMediaPlaybackRequiresUserGesture = webViewMediaPlaybackRequiresUserGesture;
629+
return this;
630+
}
631+
632+
public Builder webViewBuiltInZoomControls (boolean webViewBuiltInZoomControls) {
633+
this.webViewBuiltInZoomControls = webViewBuiltInZoomControls;
596634
return this;
597635
}
598636

599-
public Builder webViewAllowFileAccess(boolean webViewAllowFileAccess) {
637+
public Builder webViewDisplayZoomControls (boolean webViewDisplayZoomControls) {
638+
this.webViewDisplayZoomControls = webViewDisplayZoomControls;
639+
return this;
640+
}
641+
642+
public Builder webViewAllowFileAccess (boolean webViewAllowFileAccess) {
600643
this.webViewAllowFileAccess = webViewAllowFileAccess;
601644
return this;
602645
}
603646

604-
public Builder webViewUseWideViewPort(boolean webViewUseWideViewPort) {
605-
this.webViewUseWideViewPort = webViewUseWideViewPort;
647+
public Builder webViewAllowContentAccess (boolean webViewAllowContentAccess) {
648+
this.webViewAllowContentAccess = webViewAllowContentAccess;
606649
return this;
607650
}
608651

609-
public Builder webViewLoadWithOverviewMode(boolean webViewLoadWithOverviewMode) {
652+
public Builder webViewLoadWithOverviewMode (boolean webViewLoadWithOverviewMode) {
610653
this.webViewLoadWithOverviewMode = webViewLoadWithOverviewMode;
611654
return this;
612655
}
613656

614-
public Builder webViewDomStorageEnabled(boolean webViewDomStorageEnabled) {
657+
public Builder webViewSaveFormData (boolean webViewSaveFormData) {
658+
this.webViewSaveFormData = webViewSaveFormData;
659+
return this;
660+
}
661+
662+
public Builder webViewTextZoom (int webViewTextZoom) {
663+
this.webViewTextZoom = webViewTextZoom;
664+
return this;
665+
}
666+
667+
public Builder webViewUseWideViewPort (boolean webViewUseWideViewPort) {
668+
this.webViewUseWideViewPort = webViewUseWideViewPort;
669+
return this;
670+
}
671+
672+
public Builder webViewSupportMultipleWindows (boolean webViewSupportMultipleWindows) {
673+
this.webViewSupportMultipleWindows = webViewSupportMultipleWindows;
674+
return this;
675+
}
676+
677+
public Builder webViewLayoutAlgorithm (WebSettings.LayoutAlgorithm webViewLayoutAlgorithm) {
678+
this.webViewLayoutAlgorithm = webViewLayoutAlgorithm;
679+
return this;
680+
}
681+
682+
public Builder webViewStandardFontFamily (String webViewStandardFontFamily) {
683+
this.webViewStandardFontFamily = webViewStandardFontFamily;
684+
return this;
685+
}
686+
687+
public Builder webViewFixedFontFamily (String webViewFixedFontFamily) {
688+
this.webViewFixedFontFamily = webViewFixedFontFamily;
689+
return this;
690+
}
691+
692+
public Builder webViewSansSerifFontFamily (String webViewSansSerifFontFamily) {
693+
this.webViewSansSerifFontFamily = webViewSansSerifFontFamily;
694+
return this;
695+
}
696+
697+
public Builder webViewSerifFontFamily (String webViewSerifFontFamily) {
698+
this.webViewSerifFontFamily = webViewSerifFontFamily;
699+
return this;
700+
}
701+
702+
public Builder webViewCursiveFontFamily (String webViewCursiveFontFamily) {
703+
this.webViewCursiveFontFamily = webViewCursiveFontFamily;
704+
return this;
705+
}
706+
707+
public Builder webViewFantasyFontFamily (String webViewFantasyFontFamily) {
708+
this.webViewFantasyFontFamily = webViewFantasyFontFamily;
709+
return this;
710+
}
711+
712+
public Builder webViewMinimumFontSize (int webViewMinimumFontSize) {
713+
this.webViewMinimumFontSize = webViewMinimumFontSize;
714+
return this;
715+
}
716+
717+
public Builder webViewMinimumLogicalFontSize (int webViewMinimumLogicalFontSize) {
718+
this.webViewMinimumLogicalFontSize = webViewMinimumLogicalFontSize;
719+
return this;
720+
}
721+
722+
public Builder webViewDefaultFontSize (int webViewDefaultFontSize) {
723+
this.webViewDefaultFontSize = webViewDefaultFontSize;
724+
return this;
725+
}
726+
727+
public Builder webViewDefaultFixedFontSize (int webViewDefaultFixedFontSize) {
728+
this.webViewDefaultFixedFontSize = webViewDefaultFixedFontSize;
729+
return this;
730+
}
731+
732+
public Builder webViewLoadsImagesAutomatically (boolean webViewLoadsImagesAutomatically) {
733+
this.webViewLoadsImagesAutomatically = webViewLoadsImagesAutomatically;
734+
return this;
735+
}
736+
737+
public Builder webViewBlockNetworkImage (boolean webViewBlockNetworkImage) {
738+
this.webViewBlockNetworkImage = webViewBlockNetworkImage;
739+
return this;
740+
}
741+
742+
public Builder webViewBlockNetworkLoads (boolean webViewBlockNetworkLoads) {
743+
this.webViewBlockNetworkLoads = webViewBlockNetworkLoads;
744+
return this;
745+
}
746+
747+
public Builder webViewJavaScriptEnabled (boolean webViewJavaScriptEnabled) {
748+
this.webViewJavaScriptEnabled = webViewJavaScriptEnabled;
749+
return this;
750+
}
751+
752+
public Builder webViewAllowUniversalAccessFromFileURLs (boolean webViewAllowUniversalAccessFromFileURLs) {
753+
this.webViewAllowUniversalAccessFromFileURLs = webViewAllowUniversalAccessFromFileURLs;
754+
return this;
755+
}
756+
757+
public Builder webViewAllowFileAccessFromFileURLs (boolean webViewAllowFileAccessFromFileURLs) {
758+
this.webViewAllowFileAccessFromFileURLs = webViewAllowFileAccessFromFileURLs;
759+
return this;
760+
}
761+
762+
public Builder webViewGeolocationDatabasePath (String webViewGeolocationDatabasePath) {
763+
this.webViewGeolocationDatabasePath = webViewGeolocationDatabasePath;
764+
return this;
765+
}
766+
767+
public Builder webViewAppCacheEnabled (boolean webViewAppCacheEnabled) {
768+
this.webViewAppCacheEnabled = webViewAppCacheEnabled;
769+
return this;
770+
}
771+
772+
public Builder webViewAppCachePath (String webViewAppCachePath) {
773+
this.webViewAppCachePath = webViewAppCachePath;
774+
return this;
775+
}
776+
777+
public Builder webViewDatabaseEnabled (boolean webViewDatabaseEnabled) {
778+
this.webViewDatabaseEnabled = webViewDatabaseEnabled;
779+
return this;
780+
}
781+
782+
public Builder webViewDomStorageEnabled (boolean webViewDomStorageEnabled) {
615783
this.webViewDomStorageEnabled = webViewDomStorageEnabled;
616784
return this;
617785
}
618786

619-
public Builder webViewBuiltInZoomControls(boolean webViewBuiltInZoomControls) {
620-
this.webViewBuiltInZoomControls = webViewBuiltInZoomControls;
787+
public Builder webViewGeolocationEnabled (boolean webViewGeolocationEnabled) {
788+
this.webViewGeolocationEnabled = webViewGeolocationEnabled;
621789
return this;
622790
}
623791

624-
public Builder webViewDisplayZoomControls(boolean webViewDisplayZoomControls) {
625-
this.webViewDisplayZoomControls = webViewDisplayZoomControls;
792+
public Builder webViewJavaScriptCanOpenWindowsAutomatically (boolean webViewJavaScriptCanOpenWindowsAutomatically) {
793+
this.webViewJavaScriptCanOpenWindowsAutomatically = webViewJavaScriptCanOpenWindowsAutomatically;
626794
return this;
627795
}
628796

629-
public Builder webViewDesktopMode(boolean webViewDesktopMode) {
630-
this.webViewDesktopMode = webViewDesktopMode;
797+
public Builder webViewDefaultTextEncodingName (String webViewDefaultTextEncodingName) {
798+
this.webViewDefaultTextEncodingName = webViewDefaultTextEncodingName;
799+
return this;
800+
}
801+
802+
public Builder webViewUserAgentString (String webViewUserAgentString) {
803+
this.webViewUserAgentString = webViewUserAgentString;
804+
return this;
805+
}
806+
807+
public Builder webViewNeedInitialFocus (boolean webViewNeedInitialFocus) {
808+
this.webViewNeedInitialFocus = webViewNeedInitialFocus;
809+
return this;
810+
}
811+
812+
public Builder webViewCacheMode (int webViewCacheMode) {
813+
this.webViewCacheMode = webViewCacheMode;
631814
return this;
632815
}
633816

817+
public Builder webViewMixedContentMode (int webViewMixedContentMode) {
818+
this.webViewMixedContentMode = webViewMixedContentMode;
819+
return this;
820+
}
821+
822+
public Builder webViewOffscreenPreRaster (boolean webViewOffscreenPreRaster) {
823+
this.webViewOffscreenPreRaster = webViewOffscreenPreRaster;
824+
return this;
825+
}
826+
827+
/**
828+
* @deprecated As of release 1.1.1, replaced by {@link #webViewUserAgentString(String)}
829+
* Use setUserAgentString("Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.4) Gecko/20100101 Firefox/4.0") instead
830+
*/
831+
public Builder webViewDesktopMode(boolean webViewDesktopMode) {
832+
return webViewUserAgentString("Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.4) Gecko/20100101 Firefox/4.0");
833+
}
834+
634835
public Builder injectJavaScript(String injectJavaScript) {
635836
this.injectJavaScript = injectJavaScript;
636837
return this;

0 commit comments

Comments
 (0)