From 568899bc30512a51a203b2a0a81f9ec71f82f049 Mon Sep 17 00:00:00 2001 From: Leonardo Taehwan Kim Date: Wed, 27 Jan 2016 01:09:15 +0900 Subject: [PATCH] Added load() method to load data to webview --- README.md | 12 ++++++- library/build.gradle | 4 +-- .../finestwebview/FinestWebView.java | 35 ++++++++++++++----- .../finestwebview/FinestWebViewActivity.java | 12 ++++++- sample/build.gradle | 2 +- 5 files changed, 51 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 79ccf89..78bab08 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.1.5' + compile 'com.thefinestartist:finestwebview:1.1.6' } ``` @@ -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); diff --git a/library/build.gradle b/library/build.gradle index c516327..fa00291 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -14,7 +14,7 @@ android { minSdkVersion 7 targetSdkVersion 23 versionCode 1 - versionName "1.1.5" + versionName "1.1.6" } } @@ -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' } \ No newline at end of file diff --git a/library/src/main/java/com/thefinestartist/finestwebview/FinestWebView.java b/library/src/main/java/com/thefinestartist/finestwebview/FinestWebView.java index c09c6ca..69cbace 100644 --- a/library/src/main/java/com/thefinestartist/finestwebview/FinestWebView.java +++ b/library/src/main/java/com/thefinestartist/finestwebview/FinestWebView.java @@ -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; @@ -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) { @@ -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); @@ -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); } } } diff --git a/library/src/main/java/com/thefinestartist/finestwebview/FinestWebViewActivity.java b/library/src/main/java/com/thefinestartist/finestwebview/FinestWebViewActivity.java index d11b9af..ba7292e 100644 --- a/library/src/main/java/com/thefinestartist/finestwebview/FinestWebViewActivity.java +++ b/library/src/main/java/com/thefinestartist/finestwebview/FinestWebViewActivity.java @@ -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() { @@ -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; } @@ -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 diff --git a/sample/build.gradle b/sample/build.gradle index 38a3871..f81cbce 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -9,7 +9,7 @@ android { minSdkVersion 7 targetSdkVersion 23 versionCode 9 - versionName "1.1.5" + versionName "1.1.6" } buildTypes { release {