diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/us/minak/PostTask.java | 54 | ||||
-rw-r--r-- | src/us/minak/SettingsActivity.java | 72 |
2 files changed, 72 insertions, 54 deletions
diff --git a/src/us/minak/PostTask.java b/src/us/minak/PostTask.java deleted file mode 100644 index 84ab633..0000000 --- a/src/us/minak/PostTask.java +++ /dev/null @@ -1,54 +0,0 @@ -package us.minak; - -import java.io.IOException; - -import org.apache.http.HttpResponse; -import org.apache.http.client.ClientProtocolException; -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.entity.FileEntity; -import org.apache.http.impl.client.DefaultHttpClient; - -import android.app.Activity; -import android.os.AsyncTask; -import android.widget.Toast; - -class PostTask extends AsyncTask<String, String, String>{ - - private SettingsActivity mThis; - - @Override - protected String doInBackground(String... uri) { - HttpClient httpclient = new DefaultHttpClient(); - HttpPost httppost = new HttpPost("https://lukeshu.com/minak-server"); - HttpResponse response = null; - try { - //FileInputStream stream = new FileInputStream(SettingsUtil.getGestureFile(this)); - httppost.setEntity(new FileEntity(SettingsUtil.getGestureFile(mThis), "application/octet-stream")); - response = httpclient.execute(httppost); - - Toast toast = Toast.makeText(mThis, response.toString(), Toast.LENGTH_LONG); - toast.show(); - } catch (ClientProtocolException e) { - // TODO Auto-generated catch block - } catch (IOException e) { - // TODO Auto-generated catch block - } - if (response != null){ - return response.toString(); - } else { - return ""; - } - } - - @Override - protected void onPostExecute(String result) { - //Do anything with response.. - ; - } - - public void setActivity(Activity ack) { - mThis = (SettingsActivity) ack; - } - -}
\ No newline at end of file diff --git a/src/us/minak/SettingsActivity.java b/src/us/minak/SettingsActivity.java index 93629ea..b333002 100644 --- a/src/us/minak/SettingsActivity.java +++ b/src/us/minak/SettingsActivity.java @@ -16,11 +16,21 @@ package us.minak; +import java.io.IOException; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.Map; +import org.apache.http.Header; +import org.apache.http.HttpResponse; +import org.apache.http.client.ClientProtocolException; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.FileEntity; +import org.apache.http.impl.client.DefaultHttpClient; + +import android.app.Activity; import android.app.ListActivity; import android.content.Context; import android.content.Intent; @@ -33,6 +43,7 @@ import android.graphics.drawable.Drawable; import android.os.AsyncTask; import android.os.Bundle; import android.os.Environment; +import android.util.Log; import android.view.ContextMenu; import android.view.LayoutInflater; import android.view.MenuItem; @@ -321,4 +332,65 @@ public class SettingsActivity extends ListActivity { return convertView; } } + + class PostTask extends AsyncTask<String, String, String>{ + + private SettingsActivity mThis; + + @Override + protected String doInBackground(String... uri) { + + Log.w(NOTIFICATION_SERVICE, "Begin request"); + + HttpClient httpclient = new DefaultHttpClient(); + HttpPost httppost = new HttpPost("http://lukeshu.com/minak-server"); + if (!httppost.containsHeader("Host")) { + httppost.addHeader("Host", "lukeshu.com"); + Log.w(NOTIFICATION_SERVICE, "added host header"); + }else{ + Log.w(NOTIFICATION_SERVICE, "did not add host header"); + } + for (Header header : httppost.getAllHeaders()) { + Log.d("header", header.toString()); + } + + HttpResponse response = null; + try { + httppost.setEntity(new FileEntity(SettingsUtil.getGestureFile(mThis), "application/octet-stream")); + Log.d("postdata", httppost.getEntity().getContent().toString()); + response = httpclient.execute(httppost); + Log.w(NOTIFICATION_SERVICE, "Extend"); + + Toast toast = Toast.makeText(mThis, response.toString(), Toast.LENGTH_LONG); + toast.show(); + + } catch (ClientProtocolException e) { + Log.w(NOTIFICATION_SERVICE, "fil"); + // TODO Auto-generated catch block + } catch (IOException e) { + Log.w(NOTIFICATION_SERVICE, e.getMessage()); + e.printStackTrace(); + // TODO Auto-generated catch block + }catch (Exception e){ + Log.w(NOTIFICATION_SERVICE, e.getMessage()); + } + + if (response != null){ + return response.toString(); + } else { + return ""; + } + } + + @Override + protected void onPostExecute(String result) { + //Do anything with response.. + ; + } + + public void setActivity(Activity ack) { + mThis = (SettingsActivity) ack; + } + + } } |