diff --git a/android-clean-http-async-task/AndroidManifest.xml b/android-clean-http-async-task/AndroidManifest.xml
new file mode 100644
index 0000000..c009133
--- /dev/null
+++ b/android-clean-http-async-task/AndroidManifest.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/android-clean-http-async-task/ic_launcher-web.png b/android-clean-http-async-task/ic_launcher-web.png
new file mode 100644
index 0000000..a18cbb4
Binary files /dev/null and b/android-clean-http-async-task/ic_launcher-web.png differ
diff --git a/android-clean-http-async-task/res/drawable-hdpi/ic_launcher.png b/android-clean-http-async-task/res/drawable-hdpi/ic_launcher.png
new file mode 100644
index 0000000..288b665
Binary files /dev/null and b/android-clean-http-async-task/res/drawable-hdpi/ic_launcher.png differ
diff --git a/android-clean-http-async-task/res/layout/activity_main.xml b/android-clean-http-async-task/res/layout/activity_main.xml
new file mode 100644
index 0000000..057324d
--- /dev/null
+++ b/android-clean-http-async-task/res/layout/activity_main.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
diff --git a/android-clean-http-async-task/res/menu/main.xml b/android-clean-http-async-task/res/menu/main.xml
new file mode 100644
index 0000000..c002028
--- /dev/null
+++ b/android-clean-http-async-task/res/menu/main.xml
@@ -0,0 +1,9 @@
+
diff --git a/android-clean-http-async-task/res/values/dimens.xml b/android-clean-http-async-task/res/values/dimens.xml
new file mode 100644
index 0000000..55c1e59
--- /dev/null
+++ b/android-clean-http-async-task/res/values/dimens.xml
@@ -0,0 +1,7 @@
+
+
+
+ 16dp
+ 16dp
+
+
diff --git a/android-clean-http-async-task/res/values/strings.xml b/android-clean-http-async-task/res/values/strings.xml
new file mode 100644
index 0000000..f5fa433
--- /dev/null
+++ b/android-clean-http-async-task/res/values/strings.xml
@@ -0,0 +1,8 @@
+
+
+
+ Clean HTTP AsyncTask
+ Settings
+ Hello world!
+
+
diff --git a/android-clean-http-async-task/res/values/styles.xml b/android-clean-http-async-task/res/values/styles.xml
new file mode 100644
index 0000000..6ce89c7
--- /dev/null
+++ b/android-clean-http-async-task/res/values/styles.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
diff --git a/android-clean-http-async-task/src/com/hmkcode/MainActivity.java b/android-clean-http-async-task/src/com/hmkcode/MainActivity.java
new file mode 100644
index 0000000..32b2f4c
--- /dev/null
+++ b/android-clean-http-async-task/src/com/hmkcode/MainActivity.java
@@ -0,0 +1,75 @@
+package com.hmkcode;
+
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpUriRequest;
+
+import com.hmkcode.http.HttpHandler;
+
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
+import android.os.Bundle;
+import android.app.Activity;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.TextView;
+import android.widget.Toast;
+
+public class MainActivity extends Activity implements OnClickListener {
+
+ private Button btnRequest;
+ private EditText etResponse;
+ private TextView tvIsConnected;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_main);
+
+ tvIsConnected = (TextView) findViewById(R.id.tvIsConnected);
+ btnRequest = (Button) findViewById(R.id.btnRequest);
+ etResponse = (EditText) findViewById(R.id.etRespose);
+
+ if(isConnected()){
+ tvIsConnected.setBackgroundColor(0xFF00CC00);
+ tvIsConnected.setText("You are conncted");
+ }
+ else{
+ tvIsConnected.setText("You are NOT conncted");
+ }
+
+ btnRequest.setOnClickListener(this);
+ }
+
+ @Override
+ public void onClick(View v) {
+
+ new HttpHandler() {
+ @Override
+ public HttpUriRequest getHttpRequestMethod() {
+
+ return new HttpGet("http://hmkcode.com/examples/index.php");
+
+ // return new HttpPost(url)
+ }
+ @Override
+ public void onResponse(String result) {
+ Toast.makeText(getBaseContext(), "Received!", Toast.LENGTH_LONG).show();
+ etResponse.setText(result);
+ }
+
+ }.execute();
+ }
+ public boolean isConnected(){
+ ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Activity.CONNECTIVITY_SERVICE);
+ NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
+ if (networkInfo != null && networkInfo.isConnected())
+ return true;
+ else
+ return false;
+ }
+
+
+
+}
diff --git a/android-clean-http-async-task/src/com/hmkcode/http/AsyncHttpTask.java b/android-clean-http-async-task/src/com/hmkcode/http/AsyncHttpTask.java
new file mode 100644
index 0000000..d3639b1
--- /dev/null
+++ b/android-clean-http-async-task/src/com/hmkcode/http/AsyncHttpTask.java
@@ -0,0 +1,71 @@
+package com.hmkcode.http;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.client.HttpClient;
+import org.apache.http.impl.client.DefaultHttpClient;
+
+import com.hmkcode.http.HttpHandler;
+
+import android.os.AsyncTask;
+import android.util.Log;
+
+public class AsyncHttpTask extends AsyncTask{
+
+ private HttpHandler httpHandler;
+ public AsyncHttpTask(HttpHandler httpHandler){
+
+ this.httpHandler = httpHandler;
+ }
+
+
+ @Override
+ protected String doInBackground(String... arg0) {
+ InputStream inputStream = null;
+ String result = "";
+ try {
+
+ // create HttpClient
+ HttpClient httpclient = new DefaultHttpClient();
+
+ // make the http request
+ HttpResponse httpResponse = httpclient.execute(httpHandler.getHttpRequestMethod());
+
+ // receive response as inputStream
+ inputStream = httpResponse.getEntity().getContent();
+
+ // convert inputstream to string
+ if(inputStream != null)
+ result = convertInputStreamToString(inputStream);
+ else
+ result = "Did not work!";
+
+ } catch (Exception e) {
+ Log.d("InputStream", e.getLocalizedMessage());
+ }
+
+ return result;
+ }
+ @Override
+ protected void onPostExecute(String result) {
+ httpHandler.onResponse(result);
+ }
+
+ //--------------------------------------------------------------------------------------------
+ private static String convertInputStreamToString(InputStream inputStream) throws IOException{
+ BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(inputStream));
+ String line = "";
+ String result = "";
+ while((line = bufferedReader.readLine()) != null)
+ result += line;
+
+ inputStream.close();
+ return result;
+
+ }
+
+}
diff --git a/android-clean-http-async-task/src/com/hmkcode/http/HttpHandler.java b/android-clean-http-async-task/src/com/hmkcode/http/HttpHandler.java
new file mode 100644
index 0000000..d128907
--- /dev/null
+++ b/android-clean-http-async-task/src/com/hmkcode/http/HttpHandler.java
@@ -0,0 +1,18 @@
+package com.hmkcode.http;
+
+import org.apache.http.client.methods.HttpUriRequest;
+
+import com.hmkcode.http.AsyncHttpTask;
+
+public abstract class HttpHandler {
+
+ public abstract HttpUriRequest getHttpRequestMethod();
+
+ public abstract void onResponse(String result);
+
+ public void execute(){
+ new AsyncHttpTask(this).execute();
+ }
+
+
+}