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> 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. * 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_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_name_character_not_allowed">The | character is not allowed.</string>
<string name="profile_delete">Delete profile</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> </resources>

View File

@ -1,5 +1,6 @@
package pandroid_event_viewer.pandorafms; package pandroid_event_viewer.pandorafms;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -21,27 +22,26 @@ public class API {
* @param context * @param context
* Application context. * Application context.
* @return Map containing id -> group. * @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>(); Map<Integer, String> result = new HashMap<Integer, String>();
try { List<NameValuePair> parameters = new ArrayList<NameValuePair>();
List<NameValuePair> parameters = new ArrayList<NameValuePair>(); 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", "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", ";"));
parameters.add(new BasicNameValuePair("other", ";"));
String return_api = Core.httpGet(context, parameters); String return_api = Core.httpGet(context, parameters);
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++) {
String[] groups = lines[i].split(";", 21); String[] groups = lines[i].split(";", 21);
result.put(Integer.valueOf(groups[0]), groups[1]); result.put(Integer.valueOf(groups[0]), groups[1]);
}
} catch (Exception e) {
Log.e(TAG + ": getting groups", e.getMessage());
} }
return result; return result;
} }
@ -51,24 +51,23 @@ public class API {
* *
* @param context * @param context
* @return Map containing id -> agent. * @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>(); Map<Integer, String> result = new HashMap<Integer, String>();
try { List<NameValuePair> parameters = new ArrayList<NameValuePair>();
List<NameValuePair> parameters = new ArrayList<NameValuePair>(); parameters.add(new BasicNameValuePair("op", "get"));
parameters.add(new BasicNameValuePair("op", "get")); parameters.add(new BasicNameValuePair("op2", "all_agents"));
parameters.add(new BasicNameValuePair("op2", "all_agents")); parameters.add(new BasicNameValuePair("return_type", "csv"));
parameters.add(new BasicNameValuePair("return_type", "csv"));
String return_api = Core.httpGet(context, parameters); String return_api = Core.httpGet(context, parameters);
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++) {
String[] agents = lines[i].split(";"); String[] agents = lines[i].split(";");
result.put(Integer.valueOf(agents[0]), agents[1]); result.put(Integer.valueOf(agents[0]), agents[1]);
}
} catch (Exception e) {
Log.e(TAG + ": getting groups", e.getMessage());
} }
return result; return result;
} }
@ -79,20 +78,19 @@ public class API {
* @param context * @param context
* Application context. * Application context.
* @return API version or empty string if fails. * @return API version or empty string if fails.
* @throws IOException
* If there is a problem with the connection.
*/ */
public static String getVersion(Context context) { public static String getVersion(Context context) throws IOException {
try { List<NameValuePair> parameters = new ArrayList<NameValuePair>();
List<NameValuePair> parameters = new ArrayList<NameValuePair>(); parameters.add(new BasicNameValuePair("op", "get"));
parameters.add(new BasicNameValuePair("op", "get")); parameters.add(new BasicNameValuePair("op2", "test"));
parameters.add(new BasicNameValuePair("op2", "test")); String return_api;
String return_api = Core.httpGet(context, parameters); return_api = Core.httpGet(context, parameters);
// TODO wait version // TODO wait version
if (return_api.contains("OK")) { if (return_api.contains("OK")) {
return "4.0.2"; return "4.0.2";
} else { } else {
return "";
}
} catch (Exception e) {
return ""; return "";
} }
} }
@ -101,8 +99,11 @@ public class API {
* Get events from pandora console. * Get events from pandora console.
* *
* @param newEvents * @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. // Get total count.
ArrayList<NameValuePair> parameters = new ArrayList<NameValuePair>(); ArrayList<NameValuePair> parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair("op", "get")); parameters.add(new BasicNameValuePair("op", "get"));
@ -118,34 +119,39 @@ public class API {
* Get tags through an api call. * Get tags through an api call.
* *
* @return A list of groups. * @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>(); ArrayList<String> array = new ArrayList<String>();
try { List<NameValuePair> parameters = new ArrayList<NameValuePair>();
List<NameValuePair> parameters = new ArrayList<NameValuePair>(); parameters.add(new BasicNameValuePair("op", "get"));
parameters.add(new BasicNameValuePair("op", "get")); parameters.add(new BasicNameValuePair("op2", "tags"));
parameters.add(new BasicNameValuePair("op2", "tags")); parameters.add(new BasicNameValuePair("return_type", "csv"));
parameters.add(new BasicNameValuePair("return_type", "csv")); String return_api = Core.httpGet(context, parameters);
String return_api = Core.httpGet(context, parameters); String[] lines = return_api.split("\n");
String[] lines = return_api.split("\n"); array.add("");
array.add(""); for (int i = 0; i < lines.length; i++) {
for (int i = 0; i < lines.length; i++) { String[] tags = lines[i].split(";", 2);
String[] tags = lines[i].split(";", 2); array.add(tags[1]);
array.add(tags[1]);
}
} catch (Exception e) {
Log.e(TAG, "getting tags problem");
} }
return array; return array;
} }
/** /**
* Creates new incident in console. * 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, public static void createNewIncident(Context context,
String[] incidentParameters) { String[] incidentParameters) throws IOException {
Log.i(TAG, "Sending new incident"); Log.i(TAG, "Sending new incident");
List<NameValuePair> parameters = new ArrayList<NameValuePair>(); List<NameValuePair> parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair("op", "set")); parameters.add(new BasicNameValuePair("op", "set"));
@ -156,4 +162,36 @@ public class API {
.serializeParams2Api(incidentParameters))); .serializeParams2Api(incidentParameters)));
Core.httpGet(context, parameters); 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.InputStreamReader;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.security.KeyManagementException; import java.security.KeyManagementException;
@ -61,6 +62,7 @@ import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.util.Log; import android.util.Log;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
/** /**
* This class provides basic functions to manage services and some received * This class provides basic functions to manage services and some received
@ -304,9 +306,11 @@ public class Core {
* @param additionalParameters * @param additionalParameters
* Petition additional parameters * Petition additional parameters
* @return Petition result. * @return Petition result.
* @throws IOException
* If there is any problem with the connection.
*/ */
public static String httpGet(Context context, public static String httpGet(Context context,
List<NameValuePair> additionalParameters) { List<NameValuePair> additionalParameters) throws IOException {
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);
@ -324,8 +328,7 @@ public class Core {
if (url.toLowerCase().contains("https")) { if (url.toLowerCase().contains("https")) {
// Secure connection // Secure connection
return Core.httpsGet(url, parameters); return Core.httpsGet(url, parameters);
} } else {
try {
DefaultHttpClient httpClient = new DefaultHttpClient(); DefaultHttpClient httpClient = new DefaultHttpClient();
UrlEncodedFormEntity entity; UrlEncodedFormEntity entity;
HttpPost httpPost; HttpPost httpPost;
@ -340,10 +343,7 @@ public class Core {
return_api = Core return_api = Core
.convertStreamToString(entityResponse.getContent()); .convertStreamToString(entityResponse.getContent());
return return_api; 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) { public static boolean isOnline(URL url) {
try { try {
HttpsURLConnection con = (HttpsURLConnection) url HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
.openConnection();
con.setHostnameVerifier(new HostnameVerifier() { con.setHostnameVerifier(new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) { public boolean verify(String hostname, SSLSession session) {
return true; return true;
@ -485,12 +484,16 @@ public class Core {
* @param parameters * @param parameters
* Petition parameters * Petition parameters
* @return Result of the petition. * @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 = ""; String result = "";
HttpsURLConnection con;
try { try {
HttpsURLConnection con = (HttpsURLConnection) new URL(url) con = (HttpsURLConnection) new URL(url).openConnection();
.openConnection();
con.setHostnameVerifier(new HostnameVerifier() { con.setHostnameVerifier(new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) { public boolean verify(String hostname, SSLSession session) {
return true; return true;
@ -522,8 +525,9 @@ public class Core {
Log.d("CONTENT", temp); Log.d("CONTENT", temp);
result += temp + "\n"; result += temp + "\n";
} }
} catch (IOException e) { } catch (MalformedURLException e) {
return ""; // Can't reach here because the given url is checked when is
// inserted in Options activity.
} }
return result; return result;
} }
@ -553,4 +557,31 @@ public class Core {
} }
return sslSocketFactory; 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; package pandroid_event_viewer.pandorafms;
import java.io.IOException;
import java.util.Map.Entry; import java.util.Map.Entry;
import android.app.Activity; import android.app.Activity;
@ -83,8 +84,10 @@ public class CreateIncidentActivity extends Activity {
* Performs the create incident petition. * Performs the create incident petition.
* *
* @return <b>true</b> if it is created. * @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"); Log.i(TAG, "Sending new incident");
String incidentParams[] = new String[6]; String incidentParams[] = new String[6];
incidentParams[0] = title.getText().toString(); incidentParams[0] = title.getText().toString();
@ -101,11 +104,8 @@ public class CreateIncidentActivity extends Activity {
} }
if (groupCode >= 0) { if (groupCode >= 0) {
incidentParams[5] = String.valueOf(groupCode); incidentParams[5] = String.valueOf(groupCode);
} else {
return false;
} }
API.createNewIncident(getApplicationContext(), incidentParams); API.createNewIncident(getApplicationContext(), incidentParams);
return true;
} }
/** /**
@ -119,7 +119,12 @@ public class CreateIncidentActivity extends Activity {
@Override @Override
protected Boolean doInBackground(Void... params) { protected Boolean doInBackground(Void... params) {
return sendNewIncident(); try {
sendNewIncident();
return true;
} catch (IOException e) {
return false;
}
} }
@Override @Override

View File

@ -129,7 +129,7 @@ public class EventList extends ListActivity {
toggleLoadingLayout(); toggleLoadingLayout();
this.object.showOptionsFirstTime = false; 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.getNewListEvents = true;
this.object.eventList = new ArrayList<EventListItem>(); this.object.eventList = new ArrayList<EventListItem>();
this.toggleLoadingLayout(); this.toggleLoadingLayout();
this.object.executeBackgroundGetEvents(); this.object.executeBackgroundGetEvents(true);
break; break;
case R.id.about_button_menu_options: case R.id.about_button_menu_options:
i = new Intent(this, About.class); i = new Intent(this, About.class);
@ -260,7 +260,7 @@ public class EventList extends ListActivity {
la.showLoadingEvents = true; la.showLoadingEvents = true;
la.notifyDataSetChanged(); 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; package pandroid_event_viewer.pandorafms;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
@ -203,6 +204,8 @@ public class Main extends Activity {
* R.string.profile_already_exists, * R.string.profile_already_exists,
* Toast.LENGTH_SHORT).show(); break; } * Toast.LENGTH_SHORT).show(); break; }
*/ */
// TODO Ask for a confirmation before rewriting the
// profile
if (profileName.getText().toString().contains("|")) { if (profileName.getText().toString().contains("|")) {
Toast.makeText( Toast.makeText(
context, context,
@ -291,38 +294,45 @@ public class Main extends Activity {
* @author Miguel de Dios Matías * @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; private List<String> list;
@Override @Override
protected Void doInBackground(Void... params) { protected Boolean doInBackground(Void... params) {
list = new ArrayList<String>(); list = new ArrayList<String>();
list.addAll(API.getGroups(getApplicationContext()).values()); try {
return null; list.addAll(API.getGroups(getApplicationContext()).values());
} catch (IOException e) {
return false;
}
return true;
} }
@Override @Override
protected void onPostExecute(Void unused) { protected void onPostExecute(Boolean result) {
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);
ProgressBar loadingGroup = (ProgressBar) findViewById(R.id.loading_group); ProgressBar loadingGroup = (ProgressBar) findViewById(R.id.loading_group);
loadingGroup.setVisibility(ProgressBar.GONE); 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); ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(
Button buttonSearch = (Button) findViewById(R.id.button_send); getApplicationContext(),
Button buttonbuttonSetAsFilterWatcher = (Button) findViewById(R.id.button_set_as_filter_watcher); android.R.layout.simple_spinner_item, list);
combo.setAdapter(spinnerArrayAdapter);
combo.setSelection(0);
buttonReset.setEnabled(true); Button buttonReset = (Button) findViewById(R.id.button_reset);
buttonSearch.setEnabled(true); Button buttonSearch = (Button) findViewById(R.id.button_send);
buttonbuttonSetAsFilterWatcher.setEnabled(true); 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 * @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; private List<String> list;
@Override @Override
protected Void doInBackground(Void... params) { protected Boolean doInBackground(Void... params) {
list = API.getTags(getApplicationContext()); try {
return null; list = API.getTags(getApplicationContext());
return true;
} catch (IOException e) {
return false;
}
} }
@Override @Override
protected void onPostExecute(Void unused) { protected void onPostExecute(Boolean result) {
Spinner combo = (Spinner) findViewById(R.id.tag); 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);
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); ProgressBar loadingGroup = (ProgressBar) findViewById(R.id.loading_tag);
loadingGroup.setVisibility(ProgressBar.GONE); loadingGroup.setVisibility(ProgressBar.GONE);
combo.setVisibility(Spinner.VISIBLE);
} }
} }
// For options
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater(); MenuInflater inflater = getMenuInflater();
@ -432,7 +444,7 @@ public class Main extends Activity {
this.object.eventTag = combo.getSelectedItem().toString(); this.object.eventTag = combo.getSelectedItem().toString();
} }
this.object.getNewListEvents = true; this.object.getNewListEvents = true;
this.object.executeBackgroundGetEvents(); this.object.executeBackgroundGetEvents(true);
TabActivity ta = (TabActivity) this.getParent(); TabActivity ta = (TabActivity) this.getParent();
ta.getTabHost().setCurrentTab(1); ta.getTabHost().setCurrentTab(1);

View File

@ -16,6 +16,7 @@ GNU General Public License for more details.
*/ */
package pandroid_event_viewer.pandorafms; package pandroid_event_viewer.pandorafms;
import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
@ -231,7 +232,7 @@ public class Options extends Activity {
Toast.LENGTH_LONG); Toast.LENGTH_LONG);
toast.show(); toast.show();
} }
} }
/** /**
@ -284,27 +285,30 @@ public class Options extends Activity {
* *
*/ */
private class CheckConnectionAsyncTask extends private class CheckConnectionAsyncTask extends
AsyncTask<Void, Void, String> { AsyncTask<Void, Void, Boolean> {
private boolean connectionOk = false; private String version = "";
@Override @Override
protected String doInBackground(Void... arg0) { protected Boolean doInBackground(Void... arg0) {
String version = API.getVersion(getApplicationContext()); try {
if (version.length() > 0) { version = API.getVersion(getApplicationContext());
this.connectionOk = true; if (version.length() > 0) {
} else { return true;
this.connectionOk = false; } 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) { protected void onPostExecute(Boolean result) {
if (this.connectionOk) { if (result) {
connectionStatus.setText(v); connectionStatus.setText(version);
connectionStatus.setCompoundDrawablesWithIntrinsicBounds(0, 0, connectionStatus.setCompoundDrawablesWithIntrinsicBounds(0, 0,
0, R.drawable.ok); 0, R.drawable.ok);
} else { } else {
@ -323,6 +327,12 @@ public class Options extends Activity {
protected Boolean doInBackground(URL... arg0) { protected Boolean doInBackground(URL... arg0) {
url = arg0[0]; url = arg0[0];
online = Core.isOnline(url); 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]); return Core.isValidCertificate(arg0[0]);
} }

View File

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

View File

@ -16,6 +16,7 @@ GNU General Public License for more details.
*/ */
package pandroid_event_viewer.pandorafms; package pandroid_event_viewer.pandorafms;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.List; import java.util.List;
@ -64,7 +65,10 @@ public class PandroidEventviewerService extends IntentService {
@Override @Override
protected void onHandleIntent(Intent intent) { 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. * Checks if there are new events and, in that case, throw a notification.
* *
* @param context * @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 " Log.d(TAG, "Checking events at "
+ Calendar.getInstance().getTime().toGMTString()); + Calendar.getInstance().getTime().toGMTString());
if (this.url == null) { if (this.url == null) {
@ -97,8 +103,9 @@ public class PandroidEventviewerService extends IntentService {
"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));
String return_api = Core.httpGet(getApplicationContext(), String return_api;
parameters); return_api = Core.httpGet(getApplicationContext(), parameters);
Log.i(TAG + " checkNewEvents", return_api); Log.i(TAG + " checkNewEvents", return_api);
return_api = return_api.replace("\n", ""); return_api = return_api.replace("\n", "");
try { try {

View File

@ -16,11 +16,7 @@ GNU General Public License for more details.
*/ */
package pandroid_event_viewer.pandorafms; package pandroid_event_viewer.pandorafms;
import java.util.ArrayList; import java.io.IOException;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
@ -84,64 +80,48 @@ public class PopupValidationEvent extends Activity {
finish(); 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) * Sends a validation (async task)
* *
* @author Miguel de Dios Matías * @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 @Override
protected Void doInBackground(Void... params) { protected Boolean doInBackground(Void... params) {
result = sendValidation(); int idEvent = Integer.valueOf(id_event);
try {
return null; return API.validateEvent(getApplicationContext(), idEvent,
comment);
} catch (IOException e) {
connectionProblem = true;
return false;
}
} }
@Override @Override
protected void onPostExecute(Void unused) { protected void onPostExecute(Boolean result) {
String text; String text;
if (connectionProblem) {
if (result) { Core.showConnectionProblemToast(getApplicationContext(), true);
text = getApplicationContext().getString(
R.string.successful_validate_event_str);
} else { } else {
text = getApplicationContext().getString( if (result) {
R.string.fail_validate_event_str); 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();
} }
} }
} }