2012-06-26 Santiago Munin <burning1@gmail.com>

* src/pandroid_event_viewer/pandorafms/API.java: Added new api calls.
	* src/pandroid_event_viewer/pandorafms/Core.java: Now connections can throw IOExceptions.
	* res/values/strings.xml: Added new entries.
	* src/pandroid_event_viewer/pandorafms/Options.java,
	  src/pandroid_event_viewer/pandorafms/CreateIncidentActivity.java,
      	  src/pandroid_event_viewer/pandorafms/PandroidEventviewerActivity.java,
      	  src/pandroid_event_viewer/pandorafms/PandroidEventviewerService.java,
      	  src/pandroid_event_viewer/pandorafms/EventList.java,
      	  src/pandroid_event_viewer/pandorafms/PopupValidationEvent.java,
      	  src/pandroid_event_viewer/pandorafms/Main.java: Now a toast is shown if there was any connection problem.


git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6707 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
santimunin 2012-06-25 22:38:24 +00:00
parent f73aed8d7b
commit b5ca8b4a47
11 changed files with 311 additions and 202 deletions

View File

@ -1,3 +1,16 @@
2012-06-26 Santiago Munín <burning1@gmail.com>
* src/pandroid_event_viewer/pandorafms/API.java: Added new api calls.
* src/pandroid_event_viewer/pandorafms/Core.java: Now connections can throw IOExceptions.
* res/values/strings.xml: Added new entries.
* src/pandroid_event_viewer/pandorafms/Options.java,
src/pandroid_event_viewer/pandorafms/CreateIncidentActivity.java,
src/pandroid_event_viewer/pandorafms/PandroidEventviewerActivity.java,
src/pandroid_event_viewer/pandorafms/PandroidEventviewerService.java,
src/pandroid_event_viewer/pandorafms/EventList.java,
src/pandroid_event_viewer/pandorafms/PopupValidationEvent.java,
src/pandroid_event_viewer/pandorafms/Main.java: Now a toast is shown if there was any connection problem.
2012-06-25 Santiago Munín <burning1@gmail.com>
* src/pandroid_event_viewer/pandorafms/CreateIncidentActivity.java: Fixed a UI bug and refactorized the API call.

View File

@ -128,4 +128,6 @@
<string name="profile_already_exists">A profile with that name already exists.</string>
<string name="profile_name_character_not_allowed">The | character is not allowed.</string>
<string name="profile_delete">Delete profile</string>
<string name="connection_problem">There was a problem. Check your connection.</string>
<string name="connection_settings_problem">The operation can not be performed until you configure a correct connection.</string>
</resources>

View File

@ -1,5 +1,6 @@
package pandroid_event_viewer.pandorafms;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -21,27 +22,26 @@ public class API {
* @param context
* Application context.
* @return Map containing id -> group.
* @throws IOException
* If there is a problem with the connection.
*/
public static Map<Integer, String> getGroups(Context context) {
public static Map<Integer, String> getGroups(Context context)
throws IOException {
Map<Integer, String> result = new HashMap<Integer, String>();
try {
List<NameValuePair> parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair("op", "get"));
parameters.add(new BasicNameValuePair("op2", "groups"));
parameters.add(new BasicNameValuePair("other_mode",
"url_encode_separator_|"));
parameters.add(new BasicNameValuePair("return_type", "csv"));
parameters.add(new BasicNameValuePair("other", ";"));
List<NameValuePair> parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair("op", "get"));
parameters.add(new BasicNameValuePair("op2", "groups"));
parameters.add(new BasicNameValuePair("other_mode",
"url_encode_separator_|"));
parameters.add(new BasicNameValuePair("return_type", "csv"));
parameters.add(new BasicNameValuePair("other", ";"));
String return_api = Core.httpGet(context, parameters);
String[] lines = return_api.split("\n");
String return_api = Core.httpGet(context, parameters);
String[] lines = return_api.split("\n");
for (int i = 0; i < lines.length; i++) {
String[] groups = lines[i].split(";", 21);
result.put(Integer.valueOf(groups[0]), groups[1]);
}
} catch (Exception e) {
Log.e(TAG + ": getting groups", e.getMessage());
for (int i = 0; i < lines.length; i++) {
String[] groups = lines[i].split(";", 21);
result.put(Integer.valueOf(groups[0]), groups[1]);
}
return result;
}
@ -51,24 +51,23 @@ public class API {
*
* @param context
* @return Map containing id -> agent.
* @throws IOException
* If there is a problem with the connection.
*/
public static Map<Integer, String> getAgents(Context context) {
public static Map<Integer, String> getAgents(Context context)
throws IOException {
Map<Integer, String> result = new HashMap<Integer, String>();
try {
List<NameValuePair> parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair("op", "get"));
parameters.add(new BasicNameValuePair("op2", "all_agents"));
parameters.add(new BasicNameValuePair("return_type", "csv"));
List<NameValuePair> parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair("op", "get"));
parameters.add(new BasicNameValuePair("op2", "all_agents"));
parameters.add(new BasicNameValuePair("return_type", "csv"));
String return_api = Core.httpGet(context, parameters);
String[] lines = return_api.split("\n");
String return_api = Core.httpGet(context, parameters);
String[] lines = return_api.split("\n");
for (int i = 0; i < lines.length; i++) {
String[] agents = lines[i].split(";");
result.put(Integer.valueOf(agents[0]), agents[1]);
}
} catch (Exception e) {
Log.e(TAG + ": getting groups", e.getMessage());
for (int i = 0; i < lines.length; i++) {
String[] agents = lines[i].split(";");
result.put(Integer.valueOf(agents[0]), agents[1]);
}
return result;
}
@ -79,20 +78,19 @@ public class API {
* @param context
* Application context.
* @return API version or empty string if fails.
* @throws IOException
* If there is a problem with the connection.
*/
public static String getVersion(Context context) {
try {
List<NameValuePair> parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair("op", "get"));
parameters.add(new BasicNameValuePair("op2", "test"));
String return_api = Core.httpGet(context, parameters);
// TODO wait version
if (return_api.contains("OK")) {
return "4.0.2";
} else {
return "";
}
} catch (Exception e) {
public static String getVersion(Context context) throws IOException {
List<NameValuePair> parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair("op", "get"));
parameters.add(new BasicNameValuePair("op2", "test"));
String return_api;
return_api = Core.httpGet(context, parameters);
// TODO wait version
if (return_api.contains("OK")) {
return "4.0.2";
} else {
return "";
}
}
@ -101,8 +99,11 @@ public class API {
* Get events from pandora console.
*
* @param newEvents
* @throws IOException
* If there is a problem with the connection.
*/
public static String getEvents(Context context, String other) {
public static String getEvents(Context context, String other)
throws IOException {
// Get total count.
ArrayList<NameValuePair> parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair("op", "get"));
@ -118,34 +119,39 @@ public class API {
* Get tags through an api call.
*
* @return A list of groups.
* @throws IOException
* If there is a problem with the connection.
*
*/
public static List<String> getTags(Context context) {
public static List<String> getTags(Context context) throws IOException {
ArrayList<String> array = new ArrayList<String>();
try {
List<NameValuePair> parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair("op", "get"));
parameters.add(new BasicNameValuePair("op2", "tags"));
parameters.add(new BasicNameValuePair("return_type", "csv"));
String return_api = Core.httpGet(context, parameters);
String[] lines = return_api.split("\n");
array.add("");
for (int i = 0; i < lines.length; i++) {
String[] tags = lines[i].split(";", 2);
array.add(tags[1]);
}
} catch (Exception e) {
Log.e(TAG, "getting tags problem");
List<NameValuePair> parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair("op", "get"));
parameters.add(new BasicNameValuePair("op2", "tags"));
parameters.add(new BasicNameValuePair("return_type", "csv"));
String return_api = Core.httpGet(context, parameters);
String[] lines = return_api.split("\n");
array.add("");
for (int i = 0; i < lines.length; i++) {
String[] tags = lines[i].split(";", 2);
array.add(tags[1]);
}
return array;
}
/**
* Creates new incident in console.
* @param context Application context
* @param incidentParameters Incident data
*
* @param context
* Application context
* @param incidentParameters
* Incident data
* @throws IOException
* If there is any problem with the connection.
*
*/
public static void createNewIncident(Context context,
String[] incidentParameters) {
String[] incidentParameters) throws IOException {
Log.i(TAG, "Sending new incident");
List<NameValuePair> parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair("op", "set"));
@ -156,4 +162,36 @@ public class API {
.serializeParams2Api(incidentParameters)));
Core.httpGet(context, parameters);
}
/**
* Validates an event.
*
* @param context
* Application context.
* @param idEvent
* Id of event.
* @param comment
* Validation comment.
* @return <b>true</b> if validation was done.
* @throws IOException
* If here is any connection problem.
*/
public static boolean validateEvent(Context context, int idEvent,
String comment) throws IOException {
List<NameValuePair> parameters;
// Set event validation.
parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair("op", "set"));
parameters.add(new BasicNameValuePair("op2", "validate_events"));
parameters.add(new BasicNameValuePair("id", Integer.valueOf(idEvent)
.toString()));
parameters.add(new BasicNameValuePair("other", comment));
String return_api = Core.httpGet(context, parameters);
if (return_api.startsWith("Correct validation")) {
return true;
} else {
return false;
}
}
}

View File

@ -22,6 +22,7 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.security.KeyManagementException;
@ -61,6 +62,7 @@ import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;
/**
* This class provides basic functions to manage services and some received
@ -304,9 +306,11 @@ public class Core {
* @param additionalParameters
* Petition additional parameters
* @return Petition result.
* @throws IOException
* If there is any problem with the connection.
*/
public static String httpGet(Context context,
List<NameValuePair> additionalParameters) {
List<NameValuePair> additionalParameters) throws IOException {
SharedPreferences preferences = context.getSharedPreferences(
context.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
@ -324,8 +328,7 @@ public class Core {
if (url.toLowerCase().contains("https")) {
// Secure connection
return Core.httpsGet(url, parameters);
}
try {
} else {
DefaultHttpClient httpClient = new DefaultHttpClient();
UrlEncodedFormEntity entity;
HttpPost httpPost;
@ -340,10 +343,7 @@ public class Core {
return_api = Core
.convertStreamToString(entityResponse.getContent());
return return_api;
} catch (Exception e) {
Log.e(TAG + " http petition", e.getMessage());
}
return "";
}
/**
@ -461,8 +461,7 @@ public class Core {
*/
public static boolean isOnline(URL url) {
try {
HttpsURLConnection con = (HttpsURLConnection) url
.openConnection();
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
con.setHostnameVerifier(new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
@ -485,12 +484,16 @@ public class Core {
* @param parameters
* Petition parameters
* @return Result of the petition.
* @throws IOException
* If there is any problem with connection.
*
*/
private static String httpsGet(String url, List<NameValuePair> parameters) {
private static String httpsGet(String url, List<NameValuePair> parameters)
throws IOException {
String result = "";
HttpsURLConnection con;
try {
HttpsURLConnection con = (HttpsURLConnection) new URL(url)
.openConnection();
con = (HttpsURLConnection) new URL(url).openConnection();
con.setHostnameVerifier(new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
@ -522,8 +525,9 @@ public class Core {
Log.d("CONTENT", temp);
result += temp + "\n";
}
} catch (IOException e) {
return "";
} catch (MalformedURLException e) {
// Can't reach here because the given url is checked when is
// inserted in Options activity.
}
return result;
}
@ -553,4 +557,31 @@ public class Core {
}
return sslSocketFactory;
}
/**
* Shows a toast which will show the connection problem message. Do not call
* outside the UI's thread.
*
* @param context
* Application context.
* @param ignoreConnectionCheck
* If true it shows the toast even if the connection is not
* correctly configured.
*/
public static void showConnectionProblemToast(Context context,
boolean ignoreConnectionCheck) {
SharedPreferences preferences = context.getSharedPreferences(
context.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
if (preferences.getBoolean("online", false)) {
Toast.makeText(context, R.string.connection_problem,
Toast.LENGTH_SHORT).show();
} else {
if (ignoreConnectionCheck) {
Toast.makeText(context, R.string.connection_settings_problem,
Toast.LENGTH_SHORT).show();
}
}
}
}

View File

@ -1,5 +1,6 @@
package pandroid_event_viewer.pandorafms;
import java.io.IOException;
import java.util.Map.Entry;
import android.app.Activity;
@ -83,8 +84,10 @@ public class CreateIncidentActivity extends Activity {
* Performs the create incident petition.
*
* @return <b>true</b> if it is created.
* @throws IOException
* If there is a problem with the connection.
*/
private boolean sendNewIncident() {
private void sendNewIncident() throws IOException {
Log.i(TAG, "Sending new incident");
String incidentParams[] = new String[6];
incidentParams[0] = title.getText().toString();
@ -101,11 +104,8 @@ public class CreateIncidentActivity extends Activity {
}
if (groupCode >= 0) {
incidentParams[5] = String.valueOf(groupCode);
} else {
return false;
}
API.createNewIncident(getApplicationContext(), incidentParams);
return true;
}
/**
@ -119,7 +119,12 @@ public class CreateIncidentActivity extends Activity {
@Override
protected Boolean doInBackground(Void... params) {
return sendNewIncident();
try {
sendNewIncident();
return true;
} catch (IOException e) {
return false;
}
}
@Override

View File

@ -129,7 +129,7 @@ public class EventList extends ListActivity {
toggleLoadingLayout();
this.object.showOptionsFirstTime = false;
this.object.executeBackgroundGetEvents();
this.object.executeBackgroundGetEvents(false);
}
}
@ -171,7 +171,7 @@ public class EventList extends ListActivity {
this.object.getNewListEvents = true;
this.object.eventList = new ArrayList<EventListItem>();
this.toggleLoadingLayout();
this.object.executeBackgroundGetEvents();
this.object.executeBackgroundGetEvents(true);
break;
case R.id.about_button_menu_options:
i = new Intent(this, About.class);
@ -260,7 +260,7 @@ public class EventList extends ListActivity {
la.showLoadingEvents = true;
la.notifyDataSetChanged();
object.executeBackgroundGetEvents();
object.executeBackgroundGetEvents(true);
}
/**

View File

@ -16,6 +16,7 @@ GNU General Public License for more details.
*/
package pandroid_event_viewer.pandorafms;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
@ -203,6 +204,8 @@ public class Main extends Activity {
* R.string.profile_already_exists,
* Toast.LENGTH_SHORT).show(); break; }
*/
// TODO Ask for a confirmation before rewriting the
// profile
if (profileName.getText().toString().contains("|")) {
Toast.makeText(
context,
@ -291,38 +294,45 @@ public class Main extends Activity {
* @author Miguel de Dios Matías
*
*/
private class GetGroupsAsyncTask extends AsyncTask<Void, Void, Void> {
private class GetGroupsAsyncTask extends AsyncTask<Void, Void, Boolean> {
private List<String> list;
@Override
protected Void doInBackground(Void... params) {
protected Boolean doInBackground(Void... params) {
list = new ArrayList<String>();
list.addAll(API.getGroups(getApplicationContext()).values());
return null;
try {
list.addAll(API.getGroups(getApplicationContext()).values());
} catch (IOException e) {
return false;
}
return true;
}
@Override
protected void onPostExecute(Void unused) {
Spinner combo = (Spinner) findViewById(R.id.group_combo);
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(
getApplicationContext(),
android.R.layout.simple_spinner_item, list);
combo.setAdapter(spinnerArrayAdapter);
combo.setSelection(0);
protected void onPostExecute(Boolean result) {
ProgressBar loadingGroup = (ProgressBar) findViewById(R.id.loading_group);
loadingGroup.setVisibility(ProgressBar.GONE);
combo.setVisibility(Spinner.VISIBLE);
if (result) {
Spinner combo = (Spinner) findViewById(R.id.group_combo);
Button buttonReset = (Button) findViewById(R.id.button_reset);
Button buttonSearch = (Button) findViewById(R.id.button_send);
Button buttonbuttonSetAsFilterWatcher = (Button) findViewById(R.id.button_set_as_filter_watcher);
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(
getApplicationContext(),
android.R.layout.simple_spinner_item, list);
combo.setAdapter(spinnerArrayAdapter);
combo.setSelection(0);
buttonReset.setEnabled(true);
buttonSearch.setEnabled(true);
buttonbuttonSetAsFilterWatcher.setEnabled(true);
Button buttonReset = (Button) findViewById(R.id.button_reset);
Button buttonSearch = (Button) findViewById(R.id.button_send);
Button buttonbuttonSetAsFilterWatcher = (Button) findViewById(R.id.button_set_as_filter_watcher);
buttonReset.setEnabled(true);
buttonSearch.setEnabled(true);
buttonbuttonSetAsFilterWatcher.setEnabled(true);
} else {
// Only this task will show the toast in order to prevent a
// message repeated.
Core.showConnectionProblemToast(getApplicationContext(), false);
}
}
}
@ -332,33 +342,35 @@ public class Main extends Activity {
* @author Santiago Munín González
*
*/
private class GetTagsAsyncTask extends AsyncTask<Void, Void, Void> {
private class GetTagsAsyncTask extends AsyncTask<Void, Void, Boolean> {
private List<String> list;
@Override
protected Void doInBackground(Void... params) {
list = API.getTags(getApplicationContext());
return null;
protected Boolean doInBackground(Void... params) {
try {
list = API.getTags(getApplicationContext());
return true;
} catch (IOException e) {
return false;
}
}
@Override
protected void onPostExecute(Void unused) {
Spinner combo = (Spinner) findViewById(R.id.tag);
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(
getApplicationContext(),
android.R.layout.simple_spinner_item, list);
combo.setAdapter(spinnerArrayAdapter);
combo.setSelection(0);
protected void onPostExecute(Boolean result) {
if (result) {
Spinner combo = (Spinner) findViewById(R.id.tag);
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(
getApplicationContext(),
android.R.layout.simple_spinner_item, list);
combo.setAdapter(spinnerArrayAdapter);
combo.setSelection(0);
}
ProgressBar loadingGroup = (ProgressBar) findViewById(R.id.loading_tag);
loadingGroup.setVisibility(ProgressBar.GONE);
combo.setVisibility(Spinner.VISIBLE);
}
}
// For options
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
@ -432,7 +444,7 @@ public class Main extends Activity {
this.object.eventTag = combo.getSelectedItem().toString();
}
this.object.getNewListEvents = true;
this.object.executeBackgroundGetEvents();
this.object.executeBackgroundGetEvents(true);
TabActivity ta = (TabActivity) this.getParent();
ta.getTabHost().setCurrentTab(1);

View File

@ -16,6 +16,7 @@ GNU General Public License for more details.
*/
package pandroid_event_viewer.pandorafms;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
@ -231,7 +232,7 @@ public class Options extends Activity {
Toast.LENGTH_LONG);
toast.show();
}
}
/**
@ -284,27 +285,30 @@ public class Options extends Activity {
*
*/
private class CheckConnectionAsyncTask extends
AsyncTask<Void, Void, String> {
AsyncTask<Void, Void, Boolean> {
private boolean connectionOk = false;
private String version = "";
@Override
protected String doInBackground(Void... arg0) {
String version = API.getVersion(getApplicationContext());
if (version.length() > 0) {
this.connectionOk = true;
} else {
this.connectionOk = false;
protected Boolean doInBackground(Void... arg0) {
try {
version = API.getVersion(getApplicationContext());
if (version.length() > 0) {
return true;
} else {
return false;
}
} catch (IOException e) {
return false;
}
return version;
}
/**
* Choose an image (ok or wrong)
* Chooses an image (ok or wrong)
*/
protected void onPostExecute(String v) {
if (this.connectionOk) {
connectionStatus.setText(v);
protected void onPostExecute(Boolean result) {
if (result) {
connectionStatus.setText(version);
connectionStatus.setCompoundDrawablesWithIntrinsicBounds(0, 0,
0, R.drawable.ok);
} else {
@ -323,6 +327,12 @@ public class Options extends Activity {
protected Boolean doInBackground(URL... arg0) {
url = arg0[0];
online = Core.isOnline(url);
SharedPreferences preferences = getSharedPreferences(
context.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
SharedPreferences.Editor editorPreferences = preferences.edit();
editorPreferences.putBoolean("online", online);
editorPreferences.commit();
return Core.isValidCertificate(arg0[0]);
}

View File

@ -17,6 +17,7 @@ GNU General Public License for more details.
package pandroid_event_viewer.pandorafms;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
@ -173,7 +174,7 @@ public class PandroidEventviewerActivity extends TabActivity implements
process_notification(i);
}
if (changes || this.showTabListFirstTime) {
executeBackgroundGetEvents();
executeBackgroundGetEvents(false);
this.showTabListFirstTime = false;
}
@ -254,7 +255,7 @@ public class PandroidEventviewerActivity extends TabActivity implements
this.loadInProgress = true;
this.getNewListEvents = true;
this.eventList = new ArrayList<EventListItem>();
executeBackgroundGetEvents();
executeBackgroundGetEvents(true);
}
}
@ -288,8 +289,11 @@ public class PandroidEventviewerActivity extends TabActivity implements
/**
* Get events from pandora console.
*
* @throws IOException
* If there is any connection problem.
*
*/
private void getEvents() {
private void getEvents() throws IOException {
// Get total count.
String return_api = API.getEvents(getApplicationContext(),
serializeParams2Api(true));
@ -417,13 +421,12 @@ public class PandroidEventviewerActivity extends TabActivity implements
/**
* Executes the async task of getting events.
*
* @param underDemand
* <b>true</b> if the petition was under demand.
*/
public void executeBackgroundGetEvents() {
if (adapter != null) {
new GetEventsAsyncTask(adapter).execute();
} else {
new GetEventsAsyncTask(null).execute();
}
public void executeBackgroundGetEvents(boolean underDemand) {
new GetEventsAsyncTask(underDemand).execute();
}
/**
@ -434,22 +437,30 @@ public class PandroidEventviewerActivity extends TabActivity implements
*/
public class GetEventsAsyncTask extends AsyncTask<Void, Void, Void> {
private BaseAdapter adapter;
private boolean underDemand;
private boolean connectionProblem = false;
public GetEventsAsyncTask(BaseAdapter adapter) {
this.adapter = adapter;
public GetEventsAsyncTask(Boolean underDemand) {
this.underDemand = underDemand;
}
@Override
protected Void doInBackground(Void... params) {
Log.i(TAG + " GetEventsAsyncTask", "doInBackground");
getEvents();
try {
getEvents();
} catch (IOException e) {
connectionProblem = true;
}
return null;
}
@Override
protected void onPostExecute(Void unused) {
protected void onPostExecute(Void result) {
if (connectionProblem) {
Core.showConnectionProblemToast(getApplicationContext(),
underDemand);
}
Intent i = new Intent("eventlist.java");
if (getNewListEvents) {

View File

@ -16,6 +16,7 @@ GNU General Public License for more details.
*/
package pandroid_event_viewer.pandorafms;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
@ -64,7 +65,10 @@ public class PandroidEventviewerService extends IntentService {
@Override
protected void onHandleIntent(Intent intent) {
checkNewEvents(getApplicationContext());
try {
checkNewEvents(getApplicationContext());
} catch (IOException e) {
}
}
@ -72,8 +76,10 @@ public class PandroidEventviewerService extends IntentService {
* Checks if there are new events and, in that case, throw a notification.
*
* @param context
* @throws IOException
* If there is any connection problem.
*/
public void checkNewEvents(Context context) {
public void checkNewEvents(Context context) throws IOException {
Log.d(TAG, "Checking events at "
+ Calendar.getInstance().getTime().toGMTString());
if (this.url == null) {
@ -97,8 +103,9 @@ public class PandroidEventviewerService extends IntentService {
"url_encode_separator_|"));
parameters.add(new BasicNameValuePair("return_type", "csv"));
parameters.add(new BasicNameValuePair("other", parametersAPI));
String return_api = Core.httpGet(getApplicationContext(),
parameters);
String return_api;
return_api = Core.httpGet(getApplicationContext(), parameters);
Log.i(TAG + " checkNewEvents", return_api);
return_api = return_api.replace("\n", "");
try {

View File

@ -16,11 +16,7 @@ GNU General Public License for more details.
*/
package pandroid_event_viewer.pandorafms;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import java.io.IOException;
import android.app.Activity;
import android.content.Intent;
@ -84,64 +80,48 @@ public class PopupValidationEvent extends Activity {
finish();
}
/**
* Sends the validation to server.
*
* @return <b>true</b> if it was done.
*/
private boolean sendValidation() {
boolean return_var = false;
List<NameValuePair> parameters;
// Set event validation.
parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair("op", "set"));
parameters.add(new BasicNameValuePair("op2", "validate_events"));
parameters.add(new BasicNameValuePair("id", Integer.valueOf(this.id_event)
.toString()));
parameters.add(new BasicNameValuePair("other", this.comment));
String return_api = Core.httpGet(getApplicationContext(), parameters);
if (return_api.startsWith("Correct validation")) {
return_var = true;
}
return return_var;
}
/**
* Sends a validation (async task)
*
* @author Miguel de Dios Matías
*
*/
private class SendValidationAsyncTask extends AsyncTask<Void, Void, Void> {
private class SendValidationAsyncTask extends
AsyncTask<Void, Void, Boolean> {
private boolean result;
private boolean connectionProblem = false;
@Override
protected Void doInBackground(Void... params) {
result = sendValidation();
return null;
protected Boolean doInBackground(Void... params) {
int idEvent = Integer.valueOf(id_event);
try {
return API.validateEvent(getApplicationContext(), idEvent,
comment);
} catch (IOException e) {
connectionProblem = true;
return false;
}
}
@Override
protected void onPostExecute(Void unused) {
protected void onPostExecute(Boolean result) {
String text;
if (result) {
text = getApplicationContext().getString(
R.string.successful_validate_event_str);
if (connectionProblem) {
Core.showConnectionProblemToast(getApplicationContext(), true);
} else {
text = getApplicationContext().getString(
R.string.fail_validate_event_str);
if (result) {
text = getApplicationContext().getString(
R.string.successful_validate_event_str);
} else {
text = getApplicationContext().getString(
R.string.fail_validate_event_str);
}
Toast toast = Toast.makeText(getApplicationContext(), text,
Toast.LENGTH_SHORT);
toast.show();
destroyPopup();
}
Toast toast = Toast.makeText(getApplicationContext(), text,
Toast.LENGTH_SHORT);
toast.show();
destroyPopup();
}
}
}