Skip to content

Commit 568899b

Browse files
Added load() method to load data to webview
1 parent 5a707df commit 568899b

File tree

5 files changed

+51
-14
lines changed

5 files changed

+51
-14
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Easily reference the library in your Android projects using this dependency in y
5252

5353
```java
5454
dependencies {
55-
compile 'com.thefinestartist:finestwebview:1.1.5'
55+
compile 'com.thefinestartist:finestwebview:1.1.6'
5656
}
5757
```
5858

@@ -112,6 +112,16 @@ Builder(@NonNull Activity activity);
112112
Builder(@NonNull Context context);
113113
```
114114

115+
**Load data or Show url**
116+
```java
117+
load(@StringRes int dataRes);
118+
load(String data);
119+
load(String data, String mimeType, String encoding);
120+
121+
show(@StringRes int urlRes);
122+
show(@NonNull String url);
123+
```
124+
115125
**WebView Listener Options**
116126
```java
117127
setWebViewListener(WebViewListener listener);

library/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ android {
1414
minSdkVersion 7
1515
targetSdkVersion 23
1616
versionCode 1
17-
versionName "1.1.5"
17+
versionName "1.1.6"
1818
}
1919
}
2020

@@ -34,7 +34,7 @@ publish {
3434
userOrg = 'thefinestartist'
3535
groupId = 'com.thefinestartist'
3636
artifactId = 'finestwebview'
37-
publishVersion = '1.1.5'
37+
publishVersion = '1.1.6'
3838
desc = 'Beautiful and customizable Android Activity that shows web pages within an app.'
3939
website = 'https://github.com/TheFinestArtist/FinestWebView-Android'
4040
}

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

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ public static class Builder implements Serializable {
105105
protected Boolean showMenuOpenWith;
106106
protected Integer stringResOpenWith;
107107

108-
protected Integer animationOpenEnter;
109-
protected Integer animationOpenExit;
108+
protected Integer animationOpenEnter = R.anim.modal_activity_open_enter;
109+
protected Integer animationOpenExit = R.anim.modal_activity_open_exit;
110110
protected Integer animationCloseEnter;
111111
protected Integer animationCloseExit;
112112

@@ -157,6 +157,9 @@ public static class Builder implements Serializable {
157157

158158
protected String injectJavaScript;
159159

160+
protected String mimeType;
161+
protected String encoding;
162+
protected String data;
160163
protected String url;
161164

162165
public Builder setWebViewListener(WebViewListener listener) {
@@ -869,13 +872,33 @@ public Builder injectJavaScript(String injectJavaScript) {
869872
return this;
870873
}
871874

875+
public void load(@StringRes int dataRes) {
876+
load(context.getString(dataRes));
877+
}
878+
879+
public void load(String data) {
880+
load(data, "text/html", "UTF-8");
881+
}
882+
883+
public void load(String data, String mimeType, String encoding) {
884+
this.mimeType = mimeType;
885+
this.encoding = encoding;
886+
show(null, data);
887+
}
888+
872889
public void show(@StringRes int urlRes) {
873890
show(context.getString(urlRes));
874891
}
875892

876893
public void show(@NonNull String url) {
894+
show(url, null);
895+
}
896+
897+
protected void show(String url, String data) {
877898
this.url = url;
899+
this.data = data;
878900
this.key = System.identityHashCode(this);
901+
879902
if (!listeners.isEmpty()) new BroadCastManager(context, key, listeners);
880903

881904
Intent intent = new Intent(context, FinestWebViewActivity.class);
@@ -884,13 +907,7 @@ public void show(@NonNull String url) {
884907
context.startActivity(intent);
885908

886909
if (context instanceof Activity)
887-
((Activity) context).overridePendingTransition(
888-
animationOpenEnter == null ?
889-
R.anim.modal_activity_open_enter :
890-
animationOpenEnter,
891-
animationOpenExit == null ?
892-
R.anim.modal_activity_open_exit :
893-
animationOpenExit);
910+
((Activity) context).overridePendingTransition(animationOpenEnter, animationOpenExit);
894911
}
895912
}
896913
}

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ public class FinestWebViewActivity extends AppCompatActivity implements AppBarLa
178178

179179
protected String injectJavaScript;
180180

181+
protected String mimeType;
182+
protected String encoding;
183+
protected String data;
181184
protected String url;
182185

183186
protected void getOptions() {
@@ -336,6 +339,10 @@ protected void getOptions() {
336339
webViewOffscreenPreRaster = builder.webViewOffscreenPreRaster;
337340

338341
injectJavaScript = builder.injectJavaScript;
342+
343+
mimeType = builder.mimeType;
344+
encoding = builder.encoding;
345+
data = builder.data;
339346
url = builder.url;
340347
}
341348

@@ -651,7 +658,10 @@ protected void layoutViews() {
651658
// webView.setScrollbarFadingEnabled(true);
652659
// webView.setVerticalFadingEdgeEnabled(false);
653660

654-
webView.loadUrl(url);
661+
if (data != null)
662+
webView.loadData(data, mimeType, encoding);
663+
else if (url != null)
664+
webView.loadUrl(url);
655665
}
656666

657667
{ // SwipeRefreshLayout

sample/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ android {
99
minSdkVersion 7
1010
targetSdkVersion 23
1111
versionCode 9
12-
versionName "1.1.5"
12+
versionName "1.1.6"
1313
}
1414
buildTypes {
1515
release {

0 commit comments

Comments
 (0)