package net.wequick.example.small;

import android.app.ProgressDialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.widget.Toast;

import net.wequick.small.Small;
import net.wequick.small.webkit.WebView;
import net.wequick.small.webkit.WebViewClient;

/**
 * Created by galen on 15/11/3.
 */
public class Application extends android.app.Application {

    public Application() {
        // This should be the very first of the application lifecycle.
        // It's also ahead of the installing of content providers by what we can avoid
        // the ClassNotFound exception on if the provider is unimplemented in the host.
        Small.preSetUp(this);
    }

    @Override
    public void onCreate() {
        super.onCreate();

        // Optional
        Small.setBaseUri("http://m.wequick.net/demo/");
        Small.setWebViewClient(new MyWebViewClient());
        Small.setLoadFromAssets(BuildConfig.LOAD_FROM_ASSETS);
    }

    private static final class MyWebViewClient extends WebViewClient {

        private ProgressDialog mDlg;

        @Override
        public void onPageStarted(Context context, WebView view, String url, Bitmap favicon) {
            mDlg = new ProgressDialog(context);
            mDlg.setMessage("Loading...");
            mDlg.show();
            super.onPageStarted(context, view, url, favicon);
        }

        @Override
        public void onPageFinished(Context context, WebView view, String url) {
            super.onPageFinished(context, view, url);
            mDlg.dismiss();
        }

        @Override
        public void onReceivedError(Context context, WebView view, int errorCode, String description, String failingUrl) {
            super.onReceivedError(context, view, errorCode, description, failingUrl);
            mDlg.dismiss();
            Toast.makeText(context, description, Toast.LENGTH_SHORT).show();
        }
    }
}

@@ -128,16 +128,156 @@
 Bitmap;%0A
+import android.graphics.drawable.ColorDrawable;%0Aimport android.view.View;%0Aimport android.view.ViewGroup;%0Aimport android.widget.ProgressBar;%0A
 import a
@@ -297,16 +297,16 @@
 .Toast;%0A
-
 %0Aimport 
@@ -952,17 +952,20 @@
 %22http://
-m
+code
 .wequick
@@ -973,12 +973,20 @@
 net/
-demo
+small-sample
 /%22);
@@ -1211,19 +1211,16 @@
 ress
-Dialog mDlg
+Bar mBar
 ;%0A%0A 
@@ -1335,186 +1335,9 @@
 ) %7B%0A
-            mDlg = new ProgressDialog(context);%0A            mDlg.setMessage(%22Loading...%22);%0A            mDlg.show();%0A            super.onPageStarted(context, view, url, favicon);
 %0A
+
     
@@ -1445,90 +1445,9 @@
 ) %7B%0A
-            super.onPageFinished(context, view, url);%0A            mDlg.dismiss();
 %0A
+
     
@@ -1594,24 +1594,25 @@
 gUrl) %7B%0A
+%0A
         
     supe
@@ -1607,190 +1607,1667 @@
     
-    super.onReceivedError(context, view, errorCode, description, failingUrl);%0A            mDlg.dismiss();%0A            Toast.makeText(context, description, Toast.LENGTH_SHORT).show();
+%7D%0A%0A        @Override%0A        public void onProgressChanged(Context context, WebView view, int newProgress) %7B%0A            super.onProgressChanged(context, view, newProgress);%0A%0A            final ViewGroup parent = (ViewGroup) view.getParent();%0A            if (mBar == null) %7B%0A                mBar = new ProgressBar(context, null, android.R.attr.progressBarStyleHorizontal);%0A                ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(%0A                        ViewGroup.LayoutParams.MATCH_PARENT,%0A                        5);%0A                parent.addView(mBar, lp);%0A            %7D%0A%0A            if (newProgress == 100) %7B%0A                new Thread(new Runnable() %7B%0A                    @Override%0A                    public void run() %7B%0A                        int progress = mBar.getProgress();%0A                        while (progress %3C= 100) %7B%0A                            try %7B%0A                                Thread.sleep(1);%0A                            %7D catch (InterruptedException e) %7B%0A                                e.printStackTrace();%0A                            %7D%0A%0A                            mBar.setProgress(progress++);%0A                            mBar.postInvalidate();%0A                        %7D%0A%0A                        parent.postDelayed(new Runnable() %7B%0A                            @Override%0A                            public void run() %7B%0A                                parent.removeView(mBar);%0A                                mBar = null;%0A                            %7D%0A                        %7D, 300);%0A                    %7D%0A                %7D).start();%0A            %7D else %7B%0A                mBar.setProgress(newProgress);%0A            %7D
 %0A   

Update sample for webview progress handler