2012-05-31 Santiago Munín <burnin1@gmail.com>

* src/pandroid_event_viewer/pandorafms/Core.java: Added a method which performs http petitions.
	* src/pandroid_event_viewer/pandorafms/EventList.java: Added javadoc comments.
	* src/pandroid_event_viewer/pandorafms/PopupValidationEvent.java,
	  src/pandroid_event_viewer/pandorafms/PandroidEventviewerActivity.java,
	  src/pandroid_event_viewer/pandorafms/Main.java,
	  src/pandroid_event_viewer/pandorafms/PandroidEventviewerService.java: Changed api request (now they use Core's new method).


git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6394 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
santimunin 2012-05-31 20:11:56 +00:00
parent abe4634acf
commit 4ebdcee15d
7 changed files with 266 additions and 346 deletions

View File

@ -1,3 +1,12 @@
2012-05-31 Santiago Munín <burnin1@gmail.com>
* src/pandroid_event_viewer/pandorafms/Core.java: Added a method which performs http petitions.
* src/pandroid_event_viewer/pandorafms/EventList.java: Added javadoc comments.
* src/pandroid_event_viewer/pandorafms/PopupValidationEvent.java,
src/pandroid_event_viewer/pandorafms/PandroidEventviewerActivity.java,
src/pandroid_event_viewer/pandorafms/Main.java,
src/pandroid_event_viewer/pandorafms/PandroidEventviewerService.java: Changed api request (now they use Core's new method).
2012-05-31 Santiago Munín <burnin1@gmail.com> 2012-05-31 Santiago Munín <burnin1@gmail.com>
* src/pandroid_event_viewer/pandorafms/Main.java: Now, on MainActivity's restart, fetches groups and tags if url was changed. * src/pandroid_event_viewer/pandorafms/Main.java: Now, on MainActivity's restart, fetches groups and tags if url was changed.
* src/pandroid_event_viewer/pandorafms/Options.java: Puts a boolean in SharedPreferences if url was changed. * src/pandroid_event_viewer/pandorafms/Options.java: Puts a boolean in SharedPreferences if url was changed.

View File

@ -20,7 +20,17 @@ import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
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 android.app.Activity; import android.app.Activity;
import android.app.AlarmManager; import android.app.AlarmManager;
@ -168,7 +178,8 @@ public class Core {
} }
/** /**
* Converts max event age chosen from spinner to seconds (either are seconds or not) * Converts max event age chosen from spinner to seconds (either are seconds
* or not)
* *
* @return Time in milliseconds. * @return Time in milliseconds.
*/ */
@ -243,6 +254,7 @@ public class Core {
return returnvar * 1000; return returnvar * 1000;
} }
/** /**
* *
* @param params * @param params
@ -252,10 +264,53 @@ public class Core {
String return_var = params[0]; String return_var = params[0];
for (int i = 1; i < params.length; i++) { for (int i = 1; i < params.length; i++) {
return_var+= "|" + params[i]; return_var += "|" + params[i];
} }
Log.i(TAG + " serializeParams2Api", return_var); Log.i(TAG + " serializeParams2Api", return_var);
return return_var; return return_var;
} }
/**
* Performs an http get petition.
* @param context Application context.
* @param additionalParameters Petition additional parameters
* @return Petition result.
*/
public static String httpGet(Context context,
List<NameValuePair> additionalParameters) {
SharedPreferences preferences = context.getSharedPreferences(
context.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
String url = preferences.getString("url", "") + "/include/api.php";
String user = preferences.getString("user", "");
String password = preferences.getString("password", "");
if (url.length() == 0 || user.length() == 0) {
return "";
} }
ArrayList<NameValuePair> parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair("user", user));
parameters.add(new BasicNameValuePair("pass", password));
parameters.addAll(additionalParameters);
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
UrlEncodedFormEntity entity;
HttpPost httpPost;
HttpResponse response;
HttpEntity entityResponse;
String return_api;
httpPost = new HttpPost(url);
entity = new UrlEncodedFormEntity(parameters);
httpPost.setEntity(entity);
response = httpClient.execute(httpPost);
entityResponse = response.getEntity();
return_api = Core
.convertStreamToString(entityResponse.getContent());
return return_api;
} catch (Exception e) {
Log.e(TAG+" http petition", e.getMessage());
}
return "";
}
}

View File

@ -302,7 +302,12 @@ public class EventList extends ListActivity {
} }
} }
// TODO comment /**
* Sets an image to the left of a TextView.
* @param view Parent view.
* @param url Image uri.
* @param id TextView's id;
*/
private void setTextViewImage(View view, String url, int id) { private void setTextViewImage(View view, String url, int id) {
TextView tview = (TextView) view.findViewById(id); TextView tview = (TextView) view.findViewById(id);
Bitmap img = null; Bitmap img = null;
@ -324,7 +329,12 @@ public class EventList extends ListActivity {
} }
} }
// TODO comment /**
* Sets an image to the left of group's TextView.
* @param view Parent view.
* @param group_icon Icon name.
* @param id Group's TextView id;
*/
private void setTextViewGroupImage(View view, String group_icon, int id) { private void setTextViewGroupImage(View view, String group_icon, int id) {
TextView tview = (TextView) view.findViewById(id); TextView tview = (TextView) view.findViewById(id);
Bitmap img = null; Bitmap img = null;

View File

@ -201,22 +201,8 @@ public class Main extends Activity {
private List<String> getGroups() { private List<String> getGroups() {
ArrayList<String> array = new ArrayList<String>(); ArrayList<String> array = new ArrayList<String>();
SharedPreferences preferences = getSharedPreferences(
this.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
String url = preferences.getString("url", "");
String user = preferences.getString("user", "");
String password = preferences.getString("password", "");
try { try {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url + "/include/api.php");
List<NameValuePair> parameters = new ArrayList<NameValuePair>(); List<NameValuePair> parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair("user", user));
parameters.add(new BasicNameValuePair("pass", password));
parameters.add(new BasicNameValuePair("op", "get")); parameters.add(new BasicNameValuePair("op", "get"));
parameters.add(new BasicNameValuePair("op2", "groups")); parameters.add(new BasicNameValuePair("op2", "groups"));
parameters.add(new BasicNameValuePair("other_mode", parameters.add(new BasicNameValuePair("other_mode",
@ -224,16 +210,7 @@ public class Main extends Activity {
parameters.add(new BasicNameValuePair("return_type", "csv")); parameters.add(new BasicNameValuePair("return_type", "csv"));
parameters.add(new BasicNameValuePair("other", ";")); parameters.add(new BasicNameValuePair("other", ";"));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(parameters); String return_api = Core.httpGet(getApplicationContext(), parameters);
httpPost.setEntity(entity);
HttpResponse response = httpClient.execute(httpPost);
HttpEntity entityResponse = response.getEntity();
String return_api = Core.convertStreamToString(entityResponse
.getContent());
String[] lines = return_api.split("\n"); String[] lines = return_api.split("\n");
for (int i = 0; i < lines.length; i++) { for (int i = 0; i < lines.length; i++) {
@ -352,7 +329,6 @@ public class Main extends Activity {
@Override @Override
protected Void doInBackground(Void... params) { protected Void doInBackground(Void... params) {
// TODO here
list = getTags(); list = getTags();
return null; return null;
} }

View File

@ -20,16 +20,10 @@ package pandroid_event_viewer.pandorafms;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair; import org.apache.http.NameValuePair;
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 org.apache.http.message.BasicNameValuePair;
import android.app.Activity; import android.app.Activity;
@ -163,7 +157,7 @@ public class PandroidEventviewerActivity extends TabActivity implements
Activity.MODE_PRIVATE); Activity.MODE_PRIVATE);
boolean changes = false; boolean changes = false;
//Checks if there are filter changes // Checks if there are filter changes
if (!preferences.getBoolean("filterChanges", false)) { if (!preferences.getBoolean("filterChanges", false)) {
SharedPreferences.Editor editorPreferences = preferences.edit(); SharedPreferences.Editor editorPreferences = preferences.edit();
editorPreferences.putBoolean("filterChanges", false); editorPreferences.putBoolean("filterChanges", false);
@ -173,7 +167,7 @@ public class PandroidEventviewerActivity extends TabActivity implements
if (count_events > 0) { if (count_events > 0) {
process_notification(i); process_notification(i);
} }
if (changes || this.showTabListFirstTime ) { if (changes || this.showTabListFirstTime) {
executeBackgroundGetEvents(); executeBackgroundGetEvents();
this.showTabListFirstTime = false; this.showTabListFirstTime = false;
} }
@ -283,8 +277,7 @@ public class PandroidEventviewerActivity extends TabActivity implements
String.valueOf(this.offset), // Event list offset String.valueOf(this.offset), // Event list offset
totalStr, // Count or show totalStr, // Count or show
String.valueOf(this.id_group), // Group id String.valueOf(this.id_group), // Group id
this.eventTag this.eventTag });
});
} }
/** /**
@ -293,29 +286,8 @@ public class PandroidEventviewerActivity extends TabActivity implements
* @param newEvents * @param newEvents
*/ */
private void getEvents(boolean newEvents) { private void getEvents(boolean newEvents) {
SharedPreferences preferences = getSharedPreferences(
this.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
String url = preferences.getString("url", "");
String user = preferences.getString("user", "");
String password = preferences.getString("password", "");
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
UrlEncodedFormEntity entity;
HttpPost httpPost;
List<NameValuePair> parameters;
HttpResponse response;
HttpEntity entityResponse;
String return_api;
httpPost = new HttpPost(url + "/include/api.php");
// Get total count. // Get total count.
parameters = new ArrayList<NameValuePair>(); ArrayList<NameValuePair> parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair("user", user));
parameters.add(new BasicNameValuePair("pass", password));
parameters.add(new BasicNameValuePair("op", "get")); parameters.add(new BasicNameValuePair("op", "get"));
parameters.add(new BasicNameValuePair("op2", "events")); parameters.add(new BasicNameValuePair("op2", "events"));
parameters.add(new BasicNameValuePair("other_mode", parameters.add(new BasicNameValuePair("other_mode",
@ -323,15 +295,15 @@ public class PandroidEventviewerActivity extends TabActivity implements
parameters.add(new BasicNameValuePair("return_type", "csv")); parameters.add(new BasicNameValuePair("return_type", "csv"));
parameters.add(new BasicNameValuePair("other", parameters.add(new BasicNameValuePair("other",
serializeParams2Api(true))); serializeParams2Api(true)));
entity = new UrlEncodedFormEntity(parameters); String return_api = Core.httpGet(getApplicationContext(), parameters);
httpPost.setEntity(entity);
response = httpClient.execute(httpPost);
entityResponse = response.getEntity();
return_api = Core
.convertStreamToString(entityResponse.getContent());
return_api = return_api.replace("\n", "");
Log.i(TAG + " getEvents", return_api); Log.i(TAG + " getEvents", return_api);
return_api = return_api.replace("\n", "");
try {
this.count_events = new Long(return_api).longValue(); this.count_events = new Long(return_api).longValue();
} catch (NumberFormatException e) {
Log.e(TAG, e.getMessage());
return;
}
if (this.count_events == 0) { if (this.count_events == 0) {
return; return;
@ -339,8 +311,6 @@ public class PandroidEventviewerActivity extends TabActivity implements
// Get the list of events. // Get the list of events.
parameters = new ArrayList<NameValuePair>(); parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair("user", user));
parameters.add(new BasicNameValuePair("pass", password));
parameters.add(new BasicNameValuePair("op", "get")); parameters.add(new BasicNameValuePair("op", "get"));
parameters.add(new BasicNameValuePair("op2", "events")); parameters.add(new BasicNameValuePair("op2", "events"));
parameters.add(new BasicNameValuePair("other_mode", parameters.add(new BasicNameValuePair("other_mode",
@ -348,15 +318,7 @@ public class PandroidEventviewerActivity extends TabActivity implements
parameters.add(new BasicNameValuePair("return_type", "csv")); parameters.add(new BasicNameValuePair("return_type", "csv"));
parameters.add(new BasicNameValuePair("other", parameters.add(new BasicNameValuePair("other",
serializeParams2Api(false))); serializeParams2Api(false)));
entity = new UrlEncodedFormEntity(parameters); return_api = Core.httpGet(getApplicationContext(), parameters);
httpPost.setEntity(entity);
response = httpClient.execute(httpPost);
entityResponse = response.getEntity();
return_api = Core
.convertStreamToString(entityResponse.getContent());
return_api = return_api.replaceAll("\\<.*?\\>", ""); // Clean html
// tags.
Pattern pattern = Pattern Pattern pattern = Pattern
.compile("Unable to process XML data file '(.*)'"); .compile("Unable to process XML data file '(.*)'");
@ -390,7 +352,7 @@ public class PandroidEventviewerActivity extends TabActivity implements
} }
for (int i = 0; i < lines.length; i++) { for (int i = 0; i < lines.length; i++) {
String[] items = lines[i].split(";",23); String[] items = lines[i].split(";", 23);
EventListItem event = new EventListItem(); EventListItem event = new EventListItem();
@ -456,11 +418,6 @@ public class PandroidEventviewerActivity extends TabActivity implements
} }
this.eventList.add(event); this.eventList.add(event);
} }
} catch (Exception e) {
Log.e(TAG + " getEvents", e.getMessage());
return;
}
} }
/** /**

View File

@ -20,12 +20,7 @@ import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.List; import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair; import org.apache.http.NameValuePair;
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 org.apache.http.message.BasicNameValuePair;
import android.app.Activity; import android.app.Activity;
@ -85,77 +80,46 @@ public class PandroidEventviewerService extends IntentService {
SharedPreferences preferences = context.getSharedPreferences( SharedPreferences preferences = context.getSharedPreferences(
context.getString(R.string.const_string_preferences), context.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE); Activity.MODE_PRIVATE);
this.url = preferences.getString("url", "");
this.user = preferences.getString("user", "");
this.password = preferences.getString("password", "");
Calendar c = Calendar.getInstance(); Calendar c = Calendar.getInstance();
long now = (c.getTimeInMillis() / 1000); long now = (c.getTimeInMillis() / 1000);
long old_previous_filterTimestamp = preferences.getLong( long old_previous_filterTimestamp = preferences.getLong(
"previous_filterTimestamp", now); "previous_filterTimestamp", now);
if ((user.length() == 0) && (password.length() == 0) List<NameValuePair> parameters = new ArrayList<NameValuePair>();
&& (url.length() == 0)) { String parametersAPI = serializeParams2Api(context, true, false,
return; false);
}
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
UrlEncodedFormEntity entity;
HttpPost httpPost;
List<NameValuePair> parameters;
HttpResponse response;
HttpEntity entityResponse;
String return_api;
httpPost = new HttpPost(this.url + "/include/api.php");
String parametersAPI = serializeParams2Api(context, true,
false, false);
Log.d(TAG, "Parameters checking new events: " + parametersAPI);
// Get total count. // Get total count.
parameters = new ArrayList<NameValuePair>(); parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair("user", this.user));
parameters.add(new BasicNameValuePair("pass", this.password));
parameters.add(new BasicNameValuePair("op", "get")); parameters.add(new BasicNameValuePair("op", "get"));
parameters.add(new BasicNameValuePair("op2", "events")); parameters.add(new BasicNameValuePair("op2", "events"));
parameters.add(new BasicNameValuePair("other_mode", parameters.add(new BasicNameValuePair("other_mode",
"url_encode_separator_|")); "url_encode_separator_|"));
parameters.add(new BasicNameValuePair("return_type", "csv")); parameters.add(new BasicNameValuePair("return_type", "csv"));
parameters.add(new BasicNameValuePair("other", parametersAPI)); parameters.add(new BasicNameValuePair("other", parametersAPI));
entity = new UrlEncodedFormEntity(parameters); String return_api = Core.httpGet(getApplicationContext(),
httpPost.setEntity(entity); parameters);
response = httpClient.execute(httpPost);
entityResponse = response.getEntity();
return_api = Core.convertStreamToString(entityResponse
.getContent());
return_api = return_api.replace("\n", "");
Log.i(TAG + " checkNewEvents", return_api); Log.i(TAG + " checkNewEvents", return_api);
return_api = return_api.replace("\n", "");
try {
this.count_events = new Long(return_api).longValue(); this.count_events = new Long(return_api).longValue();
} catch (NumberFormatException e) {
Log.e(TAG, e.getMessage());
return;
}
// Check the event more critical // Check the event more critical
if (this.count_events != 0) { if (this.count_events != 0) {
Log.i(TAG, "There are new events"); Log.i(TAG, "There are new events");
parameters = new ArrayList<NameValuePair>(); parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair("user", this.user));
parameters
.add(new BasicNameValuePair("pass", this.password));
parameters.add(new BasicNameValuePair("op", "get")); parameters.add(new BasicNameValuePair("op", "get"));
parameters.add(new BasicNameValuePair("op2", "events")); parameters.add(new BasicNameValuePair("op2", "events"));
parameters.add(new BasicNameValuePair("other_mode", parameters.add(new BasicNameValuePair("other_mode",
"url_encode_separator_|")); "url_encode_separator_|"));
parameters parameters.add(new BasicNameValuePair("return_type", "csv"));
.add(new BasicNameValuePair("return_type", "csv"));
parameters.add(new BasicNameValuePair("other", parameters.add(new BasicNameValuePair("other",
serializeParams2Api(context, false, true, true))); serializeParams2Api(context, false, true, true)));
entity = new UrlEncodedFormEntity(parameters); return_api = Core.httpGet(getApplicationContext(), parameters);
httpPost.setEntity(entity);
response = httpClient.execute(httpPost);
entityResponse = response.getEntity();
return_api = Core.convertStreamToString(entityResponse
.getContent());
return_api = return_api.replace("\n", ""); return_api = return_api.replace("\n", "");
this.more_criticity = new Integer(return_api).intValue(); this.more_criticity = new Integer(return_api).intValue();
notificationEvent(context); notificationEvent(context);
@ -163,17 +127,11 @@ public class PandroidEventviewerService extends IntentService {
this.more_criticity = -1; this.more_criticity = -1;
// Restore timestamp // Restore timestamp
SharedPreferences.Editor editorPreferences = preferences SharedPreferences.Editor editorPreferences = preferences.edit();
.edit();
editorPreferences.putLong("previous_filterTimestamp", editorPreferences.putLong("previous_filterTimestamp",
old_previous_filterTimestamp); old_previous_filterTimestamp);
editorPreferences.commit(); editorPreferences.commit();
} }
} catch (Exception e) {
Log.e(TAG + " EXCEPTION checkNewEvents", e.getMessage());
return;
}
} }
Log.d(TAG, "Check finished at " Log.d(TAG, "Check finished at "
+ Calendar.getInstance().getTime().toGMTString()); + Calendar.getInstance().getTime().toGMTString());
@ -199,7 +157,6 @@ public class PandroidEventviewerService extends IntentService {
String filterAgentName = preferences.getString("filterAgentName", ""); String filterAgentName = preferences.getString("filterAgentName", "");
int idGroup = preferences.getInt("filterIDGroup", 0); int idGroup = preferences.getInt("filterIDGroup", 0);
Log.d(TAG, "idGroup: " + idGroup);
int filterSeverity = preferences.getInt("filterSeverity", -1); int filterSeverity = preferences.getInt("filterSeverity", -1);
int filterStatus = preferences.getInt("filterStatus", 3); int filterStatus = preferences.getInt("filterStatus", 3);
String filterEventSearch = preferences.getString("filterEventSearch", String filterEventSearch = preferences.getString("filterEventSearch",
@ -244,7 +201,7 @@ public class PandroidEventviewerService extends IntentService {
Long.toString(0), // The offset of list events Long.toString(0), // The offset of list events
totalStr, // Count or show totalStr, // Count or show
Integer.toString(idGroup), // Group ID Integer.toString(idGroup), // Group ID
filterTag }); filterTag }); // Tag
} }
/** /**
@ -351,5 +308,4 @@ public class PandroidEventviewerService extends IntentService {
mNotificationManager.notify(NOTIFICATION_PANDROID_EVENT_VIEWER, mNotificationManager.notify(NOTIFICATION_PANDROID_EVENT_VIEWER,
notification); notification);
} }
} }

View File

@ -19,20 +19,13 @@ package pandroid_event_viewer.pandorafms;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair; import org.apache.http.NameValuePair;
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 org.apache.http.message.BasicNameValuePair;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
@ -48,9 +41,6 @@ import android.widget.Toast;
public class PopupValidationEvent extends Activity { public class PopupValidationEvent extends Activity {
private int id_event; private int id_event;
private String comment; private String comment;
private String url;
private String user;
private String password;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
@ -102,52 +92,19 @@ public class PopupValidationEvent extends Activity {
private boolean sendValidation() { private boolean sendValidation() {
boolean return_var = false; boolean return_var = false;
if (this.url == null) {
SharedPreferences preferences = getApplicationContext()
.getSharedPreferences(
getApplicationContext().getString(
R.string.const_string_preferences),
Activity.MODE_PRIVATE);
this.url = preferences.getString("url", "");
this.user = preferences.getString("user", "");
this.password = preferences.getString("password", "");
}
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
UrlEncodedFormEntity entity;
HttpPost httpPost;
List<NameValuePair> parameters; List<NameValuePair> parameters;
HttpResponse response;
HttpEntity entityResponse;
String return_api;
httpPost = new HttpPost(this.url + "/include/api.php");
// Set event validation. // Set event validation.
parameters = new ArrayList<NameValuePair>(); parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair("user", this.user));
parameters.add(new BasicNameValuePair("pass", this.password));
parameters.add(new BasicNameValuePair("op", "set")); parameters.add(new BasicNameValuePair("op", "set"));
parameters.add(new BasicNameValuePair("op2", "validate_events")); parameters.add(new BasicNameValuePair("op2", "validate_events"));
parameters.add(new BasicNameValuePair("id", new Integer( parameters.add(new BasicNameValuePair("id", new Integer(this.id_event)
this.id_event).toString())); .toString()));
parameters.add(new BasicNameValuePair("other", this.comment)); parameters.add(new BasicNameValuePair("other", this.comment));
entity = new UrlEncodedFormEntity(parameters); String return_api = Core.httpGet(getApplicationContext(), parameters);
httpPost.setEntity(entity);
response = httpClient.execute(httpPost);
entityResponse = response.getEntity();
return_api = Core
.convertStreamToString(entityResponse.getContent());
return_api = return_api.replace("\n", "");
if (return_api.startsWith("Correct validation")) { if (return_api.startsWith("Correct validation")) {
return_var = true; return_var = true;
} }
} catch (Exception e) {
Log.e("EXCEPTION sendValidation", e.getMessage());
}
return return_var; return return_var;
} }