package com.github.feedit.feedit_android;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.JsResult;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.ProgressBar;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		// init loading
		ProgressBar processbar = (ProgressBar) findViewById(R.id.loading);
		// init webview
		WebView webView = (WebView) findViewById(R.id.webview);
		webView.getSettings().setJavaScriptEnabled(true);
		webView.setWebChromeClient(new WebChromeClient() {

			@Override
			public boolean onJsAlert(WebView view, String url, String message,
					JsResult result) {
				// TODO Auto-generated method stub
				return super.onJsAlert(view, url, message, result);
			}

		});

		// start sync task
		Task task = new Task(webView, processbar);
		task.execute(100);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

	class Task extends AsyncTask<Integer, Integer, String> {
		private ProgressBar processbar;
		private WebView webview;
		private String API = "http://xudafeng.com/feedit";
		private String TAG = "feedit";

		public Task(WebView webView, ProgressBar processbar) {
			webview = webView;
			processbar = processbar;
			// TODO Auto-generated constructor stub
		}

		@Override
		protected String doInBackground(Integer... params) {
			// TODO Auto-generated method stub
			HttpClient client = new DefaultHttpClient();
			StringBuilder builder = new StringBuilder();
			HttpGet myget = new HttpGet(API);
			try {
				HttpResponse response = client.execute(myget);
				int statusCode = response.getStatusLine().getStatusCode();
				Log.i(TAG, "status code: " + statusCode);
				if (statusCode == 200) {
					processbar.setVisibility(View.INVISIBLE);
					BufferedReader reader = new BufferedReader(
							new InputStreamReader(response.getEntity()
									.getContent()));

					for (String s = reader.readLine(); s != null; s = reader
							.readLine()) {
						builder.append(s);
					}
					JSONObject jsonObject = new JSONObject(builder.toString());
					Log.i(TAG, jsonObject.toString());
					webview.addJavascriptInterface(jsonObject,
							"dataFromInterface");
					webview.loadUrl("file:///android_asset/index.html");
				} else {
					Log.i(TAG, "failed");
				}
			} catch (ClientProtocolException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return null;
		}
	}
}

@@ -949,95 +949,8 @@
 n);%0A
-%09%09// init loading%0A%09%09ProgressBar processbar = (ProgressBar) findViewById(R.id.loading);%0A
 %09%09//
@@ -1397,20 +1397,8 @@
 View
-, processbar
 );%0A%09
@@ -2069,24 +2069,16 @@
 ng%3E %7B%0A%09%09
-private 
 Progress
@@ -2087,24 +2087,67 @@
 r processbar
+ = (ProgressBar) findViewById(R.id.loading)
 ;%0A%09%09private 
@@ -2283,84 +2283,32 @@
 View
-, ProgressBar processbar) %7B%0A%09%09%09webview = webView;%0A%09%09%09processbar = processbar
+) %7B%0A%09%09%09webview = webView
 ;%0A%09%09
@@ -2793,55 +2793,8 @@
 ) %7B%0A
-%09%09%09%09%09processbar.setVisibility(View.INVISIBLE);%0A
 %09%09%09%09
@@ -3267,24 +3267,30 @@
 dex.html%22);%0A
+%09%09%09%09%09%0A
 %09%09%09%09%7D else %7B
@@ -3641,13 +3641,120 @@
 ll;%0A%09%09%7D%0A
+%09%09%0A%09%09@Override%0A%09%09protected void onPostExecute(String result) %7B%0A%09%09%09processbar.setVisibility(View.GONE);%0A%09%09%7D%0A
 %09%7D%0A%7D%0A

Add loading