package com.ucla.anonycomm;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;


import com.ucla.anonycomm.R;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

public class DisplayMessageActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_display_message);
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
			getActionBar().setDisplayHomeAsUpEnabled(true);
		}
		Intent intent = getIntent();
		String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
		
		// Create the text view
		TextView textView = new TextView(this);
		textView.setTextSize(40);
		textView.setText(message);
		
		new HTTPConn().execute();
		
		setContentView(textView);
	}

	/**
	 * Set up the {@link android.app.ActionBar}, if the API is available.
	 */
	@TargetApi(Build.VERSION_CODES.HONEYCOMB)
	private void setupActionBar() {
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
			getActionBar().setDisplayHomeAsUpEnabled(true);
		}
	}

	 private class HTTPConn extends AsyncTask<Void, Void, Void> {
	        @Override
	        protected Void doInBackground(Void... arg) {
	              
	        	HttpClient httpclient = new DefaultHttpClient();
	    	    HttpPost httppost = new HttpPost("http://108.168.239.90:8080/session/send");
	    		
	    	    try {
	    	        // Add your data
	    	        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3);
	    	        nameValuePairs.add(new BasicNameValuePair("offset", "0"));
	    	        nameValuePairs.add(new BasicNameValuePair("count", "1"));
	    	        nameValuePairs.add(new BasicNameValuePair("wait", "false"));
	    	        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

	    	        // Execute HTTP Post Request
	    	        HttpResponse response = httpclient.execute(httppost);
	    	    } catch (Exception e) {
	    	    }
	    	    return null;
	        }
	        // onPostExecute displays the results of the AsyncTask.
	        @Override
	        protected void onPostExecute(Void res) {
	       }
	    }
	 
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.display_message, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			// This ID represents the Home or Up button. In the case of this
			// activity, the Up button is shown. Use NavUtils to allow users
			// to navigate up one level in the application structure. For
			// more details, see the Navigation pattern on Android Design:
			//
			// http://developer.android.com/design/patterns/navigation.html#up-vs-back
			//
			NavUtils.navigateUpFromSameTask(this);
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
	

}

@@ -22,16 +22,37 @@
 ycomm;%0A%0A
+import java.io.File;%0A
 import j
@@ -67,24 +67,24 @@
 .ArrayList;%0A
-
 import java.
@@ -425,16 +425,230 @@
 ePair;%0A%0A
+import org.apache.http.entity.mime.HttpMultipartMode;%0Aimport org.apache.http.entity.mime.MultipartEntity;%0Aimport org.apache.http.entity.mime.content.FileBody;%0Aimport org.apache.http.entity.mime.content.StringBody;%0A
 %0Aimport 
@@ -2186,16 +2186,584 @@
 %0A%09    %09%09
+/* New code */%0A%09    %09    try %7B%0A%09    %09    %09MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);%0A%09    %09    %09// Change 'path' to get input from box instead of hard-coded%0A%09    %09    %09NameValuePair p = new BasicNameValuePair(%22image%22, %22ic_launcher-web.png%22);%0A%09    %09    %09entity.addPart(p.getName(), new FileBody(new File(p.getValue())));%0A%09    %09    %09httppost.setEntity(entity);%0A%09    %09    %09%0A%09    %09    %09HttpResponse response = httpclient.execute(httppost);%0A%09    %09    %7D catch (Exception e)%7B%7D%0A%09    %09    /* New code */%0A%09    %09    %0A%09    %09    /* Old Code
 %0A%09    %09 
@@ -3324,24 +3324,24 @@
 eption e) %7B%0A
-
 %09    %09    %7D%0A
@@ -3363,16 +3363,52 @@
 n null;%0A
+%09    %09    */%0A%09    %09    return null;%0A
 %09       

Update DisplayMessageActivity.java