Browse Source

ability to show custom error message for webview

tobiasKaminsky 8 years ago
parent
commit
003076eb14

+ 16 - 1
src/main/java/com/owncloud/android/ui/activity/ExternalSiteWebView.java

@@ -38,6 +38,9 @@ import com.owncloud.android.MainApp;
 import com.owncloud.android.R;
 import com.owncloud.android.lib.common.utils.Log_OC;
 
+import java.io.IOException;
+import java.io.InputStream;
+
 /**
  * This activity shows an URL as a web view
  */
@@ -122,7 +125,19 @@ public class ExternalSiteWebView extends FileActivity {
 
         webview.setWebViewClient(new WebViewClient() {
             public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
-                Toast.makeText(activity, getString(R.string.webview_error) + ": " + description, Toast.LENGTH_SHORT).show();
+                try {
+                    InputStream errorPage = getAssets().open("customError.html");
+
+                    if (errorPage != null) {
+                        view.loadUrl("file:///android_asset/customError.html");
+                    } else {
+                        Toast.makeText(activity, getString(R.string.webview_error) + ": " + description,
+                                Toast.LENGTH_SHORT).show();
+                    }
+                } catch (IOException e) {
+                    Toast.makeText(activity, getString(R.string.webview_error) + ": " + description,
+                            Toast.LENGTH_SHORT).show();
+                }
             }
         });
 

+ 4 - 0
src/modified/assets/customError.html

@@ -0,0 +1,4 @@
+<html>
+<h1>Sorry</h1>
+Modified
+</html>