Skip to content

Commit

Permalink
Added load() method to load data to webview
Browse files Browse the repository at this point in the history
  • Loading branch information
TheFinestArtist committed Jan 26, 2016
1 parent 5a707df commit 568899b
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 14 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Easily reference the library in your Android projects using this dependency in y

```java
dependencies {
compile 'com.thefinestartist:finestwebview:1.1.5'
compile 'com.thefinestartist:finestwebview:1.1.6'
}
```

Expand Down Expand Up @@ -112,6 +112,16 @@ Builder(@NonNull Activity activity);
Builder(@NonNull Context context);
```

**Load data or Show url**
```java
load(@StringRes int dataRes);
load(String data);
load(String data, String mimeType, String encoding);

show(@StringRes int urlRes);
show(@NonNull String url);
```

**WebView Listener Options**
```java
setWebViewListener(WebViewListener listener);
Expand Down
4 changes: 2 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ android {
minSdkVersion 7
targetSdkVersion 23
versionCode 1
versionName "1.1.5"
versionName "1.1.6"
}
}

Expand All @@ -34,7 +34,7 @@ publish {
userOrg = 'thefinestartist'
groupId = 'com.thefinestartist'
artifactId = 'finestwebview'
publishVersion = '1.1.5'
publishVersion = '1.1.6'
desc = 'Beautiful and customizable Android Activity that shows web pages within an app.'
website = 'https://github.com/TheFinestArtist/FinestWebView-Android'
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ public static class Builder implements Serializable {
protected Boolean showMenuOpenWith;
protected Integer stringResOpenWith;

protected Integer animationOpenEnter;
protected Integer animationOpenExit;
protected Integer animationOpenEnter = R.anim.modal_activity_open_enter;
protected Integer animationOpenExit = R.anim.modal_activity_open_exit;
protected Integer animationCloseEnter;
protected Integer animationCloseExit;

Expand Down Expand Up @@ -157,6 +157,9 @@ public static class Builder implements Serializable {

protected String injectJavaScript;

protected String mimeType;
protected String encoding;
protected String data;
protected String url;

public Builder setWebViewListener(WebViewListener listener) {
Expand Down Expand Up @@ -869,13 +872,33 @@ public Builder injectJavaScript(String injectJavaScript) {
return this;
}

public void load(@StringRes int dataRes) {
load(context.getString(dataRes));
}

public void load(String data) {
load(data, "text/html", "UTF-8");
}

public void load(String data, String mimeType, String encoding) {
this.mimeType = mimeType;
this.encoding = encoding;
show(null, data);
}

public void show(@StringRes int urlRes) {
show(context.getString(urlRes));
}

public void show(@NonNull String url) {
show(url, null);
}

protected void show(String url, String data) {
this.url = url;
this.data = data;
this.key = System.identityHashCode(this);

if (!listeners.isEmpty()) new BroadCastManager(context, key, listeners);

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

if (context instanceof Activity)
((Activity) context).overridePendingTransition(
animationOpenEnter == null ?
R.anim.modal_activity_open_enter :
animationOpenEnter,
animationOpenExit == null ?
R.anim.modal_activity_open_exit :
animationOpenExit);
((Activity) context).overridePendingTransition(animationOpenEnter, animationOpenExit);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ public class FinestWebViewActivity extends AppCompatActivity implements AppBarLa

protected String injectJavaScript;

protected String mimeType;
protected String encoding;
protected String data;
protected String url;

protected void getOptions() {
Expand Down Expand Up @@ -336,6 +339,10 @@ protected void getOptions() {
webViewOffscreenPreRaster = builder.webViewOffscreenPreRaster;

injectJavaScript = builder.injectJavaScript;

mimeType = builder.mimeType;
encoding = builder.encoding;
data = builder.data;
url = builder.url;
}

Expand Down Expand Up @@ -651,7 +658,10 @@ protected void layoutViews() {
// webView.setScrollbarFadingEnabled(true);
// webView.setVerticalFadingEdgeEnabled(false);

webView.loadUrl(url);
if (data != null)
webView.loadData(data, mimeType, encoding);
else if (url != null)
webView.loadUrl(url);
}

{ // SwipeRefreshLayout
Expand Down
2 changes: 1 addition & 1 deletion sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {
minSdkVersion 7
targetSdkVersion 23
versionCode 9
versionName "1.1.5"
versionName "1.1.6"
}
buildTypes {
release {
Expand Down

0 comments on commit 568899b

Please sign in to comment.