Skip to content

Commit

Permalink
correct utf8 handling in http post
Browse files Browse the repository at this point in the history
  • Loading branch information
elsbrock committed Sep 26, 2011
1 parent 76ad2f2 commit 329f06f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 26 deletions.
Expand Up @@ -14,6 +14,7 @@
import com.google.zxing.integration.android.IntentResult;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
Expand All @@ -30,7 +31,8 @@
import android.widget.Toast;

public class CreateProductActivity extends Activity {

private final int DIALOG_PRODUCT_LOOKUP_WAIT = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -127,7 +129,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {

@Override
public <Product> void onTaskComplete(Product product) {
dialog.dismiss();
CreateProductActivity.this.removeDialog(DIALOG_PRODUCT_LOOKUP_WAIT);

if (product != null) {
Toast.makeText(CreateProductActivity.this, "product found", Toast.LENGTH_LONG).show();
Expand All @@ -140,7 +142,7 @@ public <Product> void onTaskComplete(Product product) {

@Override
public void onTaskError(Exception error) {
dialog.dismiss();
CreateProductActivity.this.removeDialog(DIALOG_PRODUCT_LOOKUP_WAIT);
String msg = error.getLocalizedMessage();

if (error instanceof HttpStatusException) {
Expand All @@ -160,8 +162,7 @@ public void onTaskError(Exception error) {

@Override
public void onTaskStart() {
dialog = ProgressDialog.show(CreateProductActivity.this, "",
CreateProductActivity.this.getString(R.string.product_lookup_wait), true);
CreateProductActivity.this.showDialog(DIALOG_PRODUCT_LOOKUP_WAIT);
}
});

Expand All @@ -170,4 +171,18 @@ public void onTaskStart() {
Toast.makeText(this, getString(R.string.scan_canceled), Toast.LENGTH_SHORT).show();
}
}

@Override
protected Dialog onCreateDialog(int id) {
Dialog dialog = null;

switch(id) {
case DIALOG_PRODUCT_LOOKUP_WAIT:
dialog = ProgressDialog.show(CreateProductActivity.this, "",
CreateProductActivity.this.getString(R.string.product_lookup_wait), true);
break;
}

return dialog;
}
}
8 changes: 4 additions & 4 deletions src/org/raumzeitlabor/cashpoint/activities/GroupActivity.java
Expand Up @@ -85,10 +85,10 @@ public void onClick(DialogInterface dialog, int whichButton) {
}
});

alert.setNegativeButton(getString(R.string.group_add_btn_cancel),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {}
});
// alert.setNegativeButton(getString(R.string.group_add_btn_cancel),
// new DialogInterface.OnClickListener() {
// public void onClick(DialogInterface dialog, int whichButton) {}
// });

alert.create().show();
}
Expand Down
13 changes: 2 additions & 11 deletions src/org/raumzeitlabor/cashpoint/client/tasks/CreateGroupTask.java
@@ -1,22 +1,13 @@
package org.raumzeitlabor.cashpoint.client.tasks;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.BasicHttpEntity;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.json.JSONArray;
import org.apache.http.entity.StringEntity;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;
import org.raumzeitlabor.cashpoint.R;
import org.raumzeitlabor.cashpoint.activities.LoginActivity;
import org.raumzeitlabor.cashpoint.client.Cashpoint;
Expand Down Expand Up @@ -98,7 +89,7 @@ protected Group doInBackground(String... params) {
try {
JSONObject json = new JSONObject();
json.put("name", params[0]);
request.setEntity(new ByteArrayEntity(json.toString().getBytes("UTF8")));
request.setEntity(new StringEntity(json.toString(), "UTF-8"));
HttpResponse response = Cashpoint.getHttpClient().execute(request);
int statusCode = response.getStatusLine().getStatusCode();

Expand Down
Expand Up @@ -4,11 +4,7 @@

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.entity.StringEntity;
import org.json.JSONException;
import org.json.JSONObject;
import org.raumzeitlabor.cashpoint.R;
Expand Down Expand Up @@ -81,7 +77,7 @@ protected Boolean doInBackground(String... params) {
json.put("name", params[1]);
json.put("threshold", params[2]);

request.setEntity(new ByteArrayEntity(json.toString().getBytes("UTF8")));
request.setEntity(new StringEntity(json.toString(), "UTF-8"));
HttpResponse response = Cashpoint.getHttpClient().execute(request);
int statusCode = response.getStatusLine().getStatusCode();

Expand Down

0 comments on commit 329f06f

Please sign in to comment.