package mozilla.org.webmaker.view;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.ViewGroup;
import android.webkit.WebView;

import mozilla.org.webmaker.client.WebClient;
import mozilla.org.webmaker.javascript.WebAppInterface;
import org.json.JSONObject;

public class WebmakerWebView extends WebView {

    public WebmakerWebView(Context context, String pageName) {
        this(context, pageName, null);
    }

    @SuppressLint("SetJavaScriptEnabled")
    public WebmakerWebView(Context context, String pageName, JSONObject routeParams) {
        super(context);
        this.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        this.getSettings().setJavaScriptEnabled(true);
        this.setWebViewClient(new WebClient());
        this.loadUrl("file:///android_asset/www/pages/" + pageName + "/index.html");
        this.setBackgroundColor(0x00000000);
        this.addJavascriptInterface(new WebAppInterface(context, routeParams), "Android");
        setWebContentsDebuggingEnabled(true);
    }
}

@@ -125,21 +125,188 @@
 iew.View
-Group
+;%0Aimport android.view.ViewGroup;%0Aimport android.view.animation.AlphaAnimation;%0Aimport android.view.animation.Animation;%0Aimport android.view.animation.DecelerateInterpolator
 ;%0Aimport
@@ -326,25 +326,26 @@
 it.WebView;%0A
-%0A
+//
 import mozil
@@ -374,24 +374,101 @@
 .WebClient;%0A
+import android.webkit.JsPromptResult;%0Aimport android.webkit.WebChromeClient;%0A
 import mozil
@@ -1033,24 +1033,26 @@
 bled(true);%0A
+//
         this
@@ -1083,24 +1083,1047 @@
 bClient());%0A
+        this.setWebChromeClient(new WebChromeClient() %7B%0A            private void animate(WebView view) %7B%0A                Animation fadeIn = new AlphaAnimation(0, 1);%0A                fadeIn.setInterpolator(new DecelerateInterpolator());%0A                fadeIn.setDuration(1000);%0A                view.startAnimation(fadeIn);%0A            %7D%0A            @Override%0A            public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result) %7B%0A                return super.onJsPrompt(view, url, message, defaultValue, result);%0A            %7D%0A            @Override%0A            public void onProgressChanged(WebView view, int newProgress) %7B%0A                if (newProgress == 0) %7B%0A                    view.setVisibility(View.GONE);%0A                %7D%0A                if (newProgress == 100) %7B%0A                    animate(view);%0A                    view.setVisibility(View.VISIBLE);%0A                %7D%0A                super.onProgressChanged(view, newProgress);%0A            %7D%0A        %7D);%0A
         this

Add webChromeClient based on Pomax's work