2012-09-13 Miguel de Dios <miguel.dedios@artica.es>

* res/layout/main.xml: removed the typo bug.
	
	* src/pandroid_event_viewer/pandorafms/Core.java, 
	src/pandroid_event_viewer/pandorafms/API.java,
	src/pandroid_event_viewer/pandorafms/About.java,
	src/pandroid_event_viewer/pandorafms/EventList.java: fixed the code
	style.




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@8942 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2013-10-21 12:00:42 +00:00
parent 1a9d58e3af
commit dfa8f6f840
6 changed files with 329 additions and 284 deletions

View File

@ -1,3 +1,13 @@
2012-09-13 Miguel de Dios <miguel.dedios@artica.es>
* res/layout/main.xml: removed the typo bug.
* src/pandroid_event_viewer/pandorafms/Core.java,
src/pandroid_event_viewer/pandorafms/API.java,
src/pandroid_event_viewer/pandorafms/About.java,
src/pandroid_event_viewer/pandorafms/EventList.java: fixed the code
style.
2012-09-13 Miguel de Dios <miguel.dedios@artica.es> 2012-09-13 Miguel de Dios <miguel.dedios@artica.es>
* .classpath: removed the entry for ".svn" folder * .classpath: removed the entry for ".svn" folder

View File

@ -232,7 +232,6 @@
android:stretchColumns="0,1" > android:stretchColumns="0,1" >
<TableRow <TableRow
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" > android:layout_height="wrap_content" >
@ -250,7 +249,6 @@
</TableRow> </TableRow>
<TableRow <TableRow
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" > android:layout_height="wrap_content" >

View File

@ -34,7 +34,7 @@ public class API {
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", ";"));
@ -45,7 +45,8 @@ public class API {
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 (NumberFormatException e) { }
catch (NumberFormatException e) {
Log.e(TAG, "Problem parsing number in response"); Log.e(TAG, "Problem parsing number in response");
} }
return result; return result;
@ -60,7 +61,8 @@ public class API {
* If there is a problem with the connection. * 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 { throws IOException {
Map<Integer, String> result = new HashMap<Integer, String>(); Map<Integer, String> result = new HashMap<Integer, String>();
List<NameValuePair> parameters = new ArrayList<NameValuePair>(); List<NameValuePair> parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair("op", "get")); parameters.add(new BasicNameValuePair("op", "get"));
@ -96,10 +98,12 @@ public class API {
String[] lines = return_api.split(","); String[] lines = return_api.split(",");
if (lines.length == 3) { if (lines.length == 3) {
return lines[1]; return lines[1];
} else { }
else {
return context.getString(R.string.unknown_version); return context.getString(R.string.unknown_version);
} }
} else { }
else {
return ""; return "";
} }
} }
@ -144,13 +148,13 @@ public class API {
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", parameters.add(new BasicNameValuePair("other",
serializeEventsParamsToAPI(filterAgentName, idGroup, serializeEventsParamsToAPI(filterAgentName, idGroup,
filterSeverity, filterStatus, filterEventSearch, filterSeverity, filterStatus, filterEventSearch,
filterTag, filterTimestamp, itemsPerPage, offset, filterTag, filterTimestamp, itemsPerPage, offset, total,
total, more_criticity))); more_criticity)));
return Core.httpGet(context, parameters); return Core.httpGet(context, parameters);
} }
@ -176,7 +180,8 @@ public class API {
String[] tags = lines[i].split(";", 2); String[] tags = lines[i].split(";", 2);
array.add(tags[1]); array.add(tags[1]);
} }
} catch (ArrayIndexOutOfBoundsException e) { }
catch (ArrayIndexOutOfBoundsException e) {
Log.e(TAG, "There was a problem getting tags: " + e.getMessage()); Log.e(TAG, "There was a problem getting tags: " + e.getMessage());
} }
return array; return array;
@ -195,14 +200,15 @@ public class API {
*/ */
public static void createNewIncident(Context context, public static void createNewIncident(Context context,
String[] incidentParameters) throws IOException { 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"));
parameters.add(new BasicNameValuePair("op2", "new_incident")); parameters.add(new BasicNameValuePair("op2", "new_incident"));
parameters.add(new BasicNameValuePair("other_mode", parameters.add(new BasicNameValuePair("other_mode",
"url_encode_separator_|")); "url_encode_separator_|"));
parameters.add(new BasicNameValuePair("other", Core parameters.add(new BasicNameValuePair("other", Core
.serializeParams2Api(incidentParameters))); .serializeParams2Api(incidentParameters)));
Core.httpGet(context, parameters); Core.httpGet(context, parameters);
} }
@ -221,19 +227,21 @@ public class API {
*/ */
public static boolean validateEvent(Context context, int idEvent, public static boolean validateEvent(Context context, int idEvent,
String comment) throws IOException { String comment) throws IOException {
List<NameValuePair> parameters; List<NameValuePair> parameters;
// Set event validation. // Set event validation.
parameters = new ArrayList<NameValuePair>(); parameters = new ArrayList<NameValuePair>();
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", Integer.valueOf(idEvent) parameters.add(new BasicNameValuePair("id", Integer.valueOf(idEvent)
.toString())); .toString()));
parameters.add(new BasicNameValuePair("other", comment)); parameters.add(new BasicNameValuePair("other", comment));
String return_api = Core.httpGet(context, parameters); String return_api = Core.httpGet(context, parameters);
if (return_api.startsWith("Correct validation")) { if (return_api.startsWith("Correct validation")) {
return true; return true;
} else { }
else {
return false; return false;
} }
} }
@ -266,17 +274,17 @@ public class API {
* @return Serialized parameters. * @return Serialized parameters.
*/ */
private static String serializeEventsParamsToAPI(String filterAgentName, private static String serializeEventsParamsToAPI(String filterAgentName,
int idGroup, int filterSeverity, int filterStatus, int idGroup, int filterSeverity, int filterStatus,
String filterEventSearch, String filterTag, long filterTimestamp, String filterEventSearch, String filterTag, long filterTimestamp,
long itemsPerPage, long offset, boolean total, long itemsPerPage, long offset, boolean total,
boolean more_criticity) { boolean more_criticity) {
String totalStr = (total) ? "total" : "-1"; String totalStr = (total) ? "total" : "-1";
if (more_criticity) { if (more_criticity) {
totalStr = "more_criticity"; totalStr = "more_criticity";
} }
return Core.serializeParams2Api(new String[] { ";", // Separator for the return Core.serializeParams2Api(new String[] {
// csv ";", // Separator for the csv
Integer.toString(filterSeverity), // criticity or severity Integer.toString(filterSeverity), // criticity or severity
filterAgentName, // The agent name filterAgentName, // The agent name
"", // Name of module "", // Name of module

View File

@ -41,7 +41,7 @@ public class About extends Activity {
TextView text = (TextView) findViewById(R.id.url_pandora); TextView text = (TextView) findViewById(R.id.url_pandora);
text.setText(Html text.setText(Html
.fromHtml("<a href='http://pandorafms.org/'>PandoraFMS.org</a>")); .fromHtml("<a href='http://pandorafms.org/'>PandoraFMS.org</a>"));
text.setMovementMethod(LinkMovementMethod.getInstance()); text.setMovementMethod(LinkMovementMethod.getInstance());
CheckBox check_show = (CheckBox) findViewById(R.id.dont_show_again_extended); CheckBox check_show = (CheckBox) findViewById(R.id.dont_show_again_extended);
@ -51,18 +51,19 @@ public class About extends Activity {
CheckBox check_show = (CheckBox) v; CheckBox check_show = (CheckBox) v;
if (check_show.isChecked()) { if (check_show.isChecked()) {
SharedPreferences preferences = getSharedPreferences( SharedPreferences preferences = getSharedPreferences(
getString(R.string.const_string_preferences), getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE); Activity.MODE_PRIVATE);
SharedPreferences.Editor editorPreferences = preferences SharedPreferences.Editor editorPreferences = preferences
.edit(); .edit();
editorPreferences.putBoolean("show_popup_info", false); editorPreferences.putBoolean("show_popup_info", false);
editorPreferences.commit(); editorPreferences.commit();
} else { }
else {
SharedPreferences preferences = getSharedPreferences( SharedPreferences preferences = getSharedPreferences(
getString(R.string.const_string_preferences), getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE); Activity.MODE_PRIVATE);
SharedPreferences.Editor editorPreferences = preferences SharedPreferences.Editor editorPreferences = preferences
.edit(); .edit();
editorPreferences.putBoolean("show_popup_info", true); editorPreferences.putBoolean("show_popup_info", true);
editorPreferences.commit(); editorPreferences.commit();
} }

View File

@ -89,8 +89,8 @@ public class Core {
* @return A string with all data read. * @return A string with all data read.
*/ */
private static String convertStreamToString(InputStream is) { private static String convertStreamToString(InputStream is) {
BufferedReader reader = new BufferedReader(new InputStreamReader(is), BufferedReader reader = new BufferedReader(
8 * 1024); new InputStreamReader(is), 8 * 1024);
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
String line = null; String line = null;
@ -98,12 +98,15 @@ public class Core {
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
sb.append(line + "\n"); sb.append(line + "\n");
} }
} catch (IOException e) { }
catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} finally { }
finally {
try { try {
is.close(); is.close();
} catch (IOException e) { }
catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -127,28 +130,29 @@ public class Core {
ctx.stopService(new Intent(ctx, PandroidEventviewerService.class)); ctx.stopService(new Intent(ctx, PandroidEventviewerService.class));
// Sets the launch frequency // Sets the launch frequency
AlarmManager alarmM = (AlarmManager) ctx AlarmManager alarmM = (AlarmManager) ctx
.getSystemService(Context.ALARM_SERVICE); .getSystemService(Context.ALARM_SERVICE);
PendingIntent pandroidService = PendingIntent.getService(ctx, 0, PendingIntent pandroidService = PendingIntent.getService(ctx, 0,
new Intent(ctx, PandroidEventviewerService.class), 0); new Intent(ctx, PandroidEventviewerService.class), 0);
int sleepTimeAlarm = convertRefreshTimeKeyToTime(ctx); int sleepTimeAlarm = convertRefreshTimeKeyToTime(ctx);
Log.i(TAG, "sleepTimeAlarm = " + sleepTimeAlarm); Log.i(TAG, "sleepTimeAlarm = " + sleepTimeAlarm);
alarmM.setRepeating(AlarmManager.RTC_WAKEUP, alarmM.setRepeating(AlarmManager.RTC_WAKEUP,
System.currentTimeMillis(), sleepTimeAlarm, pandroidService); System.currentTimeMillis(), sleepTimeAlarm, pandroidService);
} else { }
else {
Log.i(TAG, Log.i(TAG,
"Service wasn't started because the options aren't configured yet"); "Service wasn't started because the options aren't configured yet");
} }
} }
public static void cancelBackgroundService(Context ctx) { public static void cancelBackgroundService(Context ctx) {
AlarmManager alarmM = (AlarmManager) ctx AlarmManager alarmM = (AlarmManager) ctx
.getSystemService(Context.ALARM_SERVICE); .getSystemService(Context.ALARM_SERVICE);
PendingIntent pandroidService = PendingIntent.getService(ctx, 0, PendingIntent pandroidService = PendingIntent.getService(ctx, 0,
new Intent(ctx, PandroidEventviewerService.class), 0); new Intent(ctx, PandroidEventviewerService.class), 0);
Log.i(TAG, "Background service cancelled"); Log.i(TAG, "Background service cancelled");
alarmM.cancel(pandroidService); alarmM.cancel(pandroidService);
@ -162,7 +166,8 @@ public class Core {
* @return Time in milliseconds. * @return Time in milliseconds.
*/ */
public static long convertMaxTimeOldEventValuesToTimestamp(long time, public static long convertMaxTimeOldEventValuesToTimestamp(long time,
int arrayKey) { int arrayKey) {
long return_var = 0; long return_var = 0;
if (time == 0) { if (time == 0) {
@ -171,57 +176,57 @@ public class Core {
} }
switch (arrayKey) { switch (arrayKey) {
case 0: case 0:
return_var = time - 30 * 60; return_var = time - 30 * 60;
break; break;
case 1: case 1:
return_var = time - 60 * 60; return_var = time - 60 * 60;
break; break;
case 2: case 2:
return_var = time - 2 * (60 * 60); return_var = time - 2 * (60 * 60);
break; break;
case 3: case 3:
return_var = time - 3 * (60 * 60); return_var = time - 3 * (60 * 60);
break; break;
case 4: case 4:
return_var = time - 4 * (60 * 60); return_var = time - 4 * (60 * 60);
break; break;
case 5: case 5:
return_var = time - 5 * (60 * 60); return_var = time - 5 * (60 * 60);
break; break;
case 6: case 6:
return_var = time - 8 * (60 * 60); return_var = time - 8 * (60 * 60);
break; break;
case 7: case 7:
return_var = time - 10 * (60 * 60); return_var = time - 10 * (60 * 60);
break; break;
case 8: case 8:
return_var = time - 12 * (60 * 60); return_var = time - 12 * (60 * 60);
break; break;
case 9: case 9:
return_var = time - 24 * (60 * 60); return_var = time - 24 * (60 * 60);
break; break;
case 10: case 10:
return_var = time - 2 * (24 * 60 * 60); return_var = time - 2 * (24 * 60 * 60);
break; break;
case 11: case 11:
return_var = time - 3 * (24 * 60 * 60); return_var = time - 3 * (24 * 60 * 60);
break; break;
case 12: case 12:
return_var = time - 4 * (24 * 60 * 60); return_var = time - 4 * (24 * 60 * 60);
break; break;
case 13: case 13:
return_var = time - 5 * (24 * 60 * 60); return_var = time - 5 * (24 * 60 * 60);
break; break;
case 14: case 14:
return_var = time - 7 * (24 * 60 * 60); return_var = time - 7 * (24 * 60 * 60);
break; break;
case 15: case 15:
return_var = time - 2 * (7 * 24 * 60 * 60); return_var = time - 2 * (7 * 24 * 60 * 60);
break; break;
case 16: case 16:
return_var = time - 30 * (24 * 60 * 60); return_var = time - 30 * (24 * 60 * 60);
break; break;
} }
return return_var; return return_var;
@ -237,69 +242,69 @@ public class Core {
int returnvar = 60 * 10; int returnvar = 60 * 10;
SharedPreferences preferences = ctx.getSharedPreferences( SharedPreferences preferences = ctx.getSharedPreferences(
ctx.getString(R.string.const_string_preferences), ctx.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE); Activity.MODE_PRIVATE);
int refreshTimeKey = preferences.getInt("refreshTimeKey", 3); int refreshTimeKey = preferences.getInt("refreshTimeKey", 3);
switch (refreshTimeKey) { switch (refreshTimeKey) {
case 0: case 0:
returnvar = 30; // 30 seconds returnvar = 30; // 30 seconds
break; break;
case 1: case 1:
returnvar = 60; // 1 minute returnvar = 60; // 1 minute
break; break;
case 2: case 2:
returnvar = 60 * 5; // 5 minutes returnvar = 60 * 5; // 5 minutes
break; break;
case 3: case 3:
returnvar = 60 * 10; // 10 minutes returnvar = 60 * 10; // 10 minutes
break; break;
case 4: case 4:
returnvar = 60 * 15; // 15 minutes returnvar = 60 * 15; // 15 minutes
break; break;
case 5: case 5:
returnvar = 60 * 30; // 30 minutes returnvar = 60 * 30; // 30 minutes
break; break;
case 6: case 6:
returnvar = 60 * 45; // 45 minutes returnvar = 60 * 45; // 45 minutes
break; break;
case 7: case 7:
returnvar = 3600; // 1 hour returnvar = 3600; // 1 hour
break; break;
case 8: case 8:
returnvar = 3600 + (60 * 30); // 1 hour and 30 minutes returnvar = 3600 + (60 * 30); // 1 hour and 30 minutes
break; break;
case 9: case 9:
returnvar = 3600 * 2; // 2 hours returnvar = 3600 * 2; // 2 hours
break; break;
case 10: case 10:
returnvar = 3600 * 3; // 3 hours returnvar = 3600 * 3; // 3 hours
break; break;
case 11: case 11:
returnvar = 3600 * 4; // 4 hours returnvar = 3600 * 4; // 4 hours
break; break;
case 12: case 12:
returnvar = 3600 * 6; // 6 hours returnvar = 3600 * 6; // 6 hours
break; break;
case 13: case 13:
returnvar = 3600 * 8; // 8 hours returnvar = 3600 * 8; // 8 hours
break; break;
case 14: case 14:
returnvar = 3600 * 10; // 10 hours returnvar = 3600 * 10; // 10 hours
break; break;
case 15: case 15:
returnvar = 3600 * 12; // 12 hours returnvar = 3600 * 12; // 12 hours
break; break;
case 16: case 16:
returnvar = 3600 * 24; // 24 hours returnvar = 3600 * 24; // 24 hours
break; break;
case 17: case 17:
returnvar = 3600 * 36; // 36 hours returnvar = 3600 * 36; // 36 hours
break; break;
case 18: case 18:
returnvar = 3600 * 48; // 48 hours returnvar = 3600 * 48; // 48 hours
break; break;
} }
return returnvar * 1000; return returnvar * 1000;
@ -317,7 +322,9 @@ public class Core {
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;
} }
@ -333,10 +340,11 @@ public class Core {
* If there is any problem with the connection. * If there is any problem with the connection.
*/ */
public static String httpGet(Context context, public static String httpGet(Context context,
List<NameValuePair> additionalParameters) throws IOException { 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);
String url = preferences.getString("url", "") + "/include/api.php"; String url = preferences.getString("url", "") + "/include/api.php";
String user = preferences.getString("user", ""); String user = preferences.getString("user", "");
@ -356,10 +364,11 @@ 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 { }
else {
HttpParams params = new BasicHttpParams(); HttpParams params = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(params, HttpConnectionParams.setConnectionTimeout(params,
CONNECTION_TIMEOUT); CONNECTION_TIMEOUT);
HttpConnectionParams.setSoTimeout(params, CONNECTION_TIMEOUT); HttpConnectionParams.setSoTimeout(params, CONNECTION_TIMEOUT);
DefaultHttpClient httpClient = new DefaultHttpClient(params); DefaultHttpClient httpClient = new DefaultHttpClient(params);
UrlEncodedFormEntity entity; UrlEncodedFormEntity entity;
@ -373,7 +382,7 @@ public class Core {
response = httpClient.execute(httpPost); response = httpClient.execute(httpPost);
entityResponse = response.getEntity(); entityResponse = response.getEntity();
return_api = Core return_api = Core
.convertStreamToString(entityResponse.getContent()); .convertStreamToString(entityResponse.getContent());
Log.i(TAG, "received: " + return_api); Log.i(TAG, "received: " + return_api);
return return_api; return return_api;
} }
@ -398,7 +407,7 @@ public class Core {
myFileUrl = new URL(fileUrl); myFileUrl = new URL(fileUrl);
if (fileUrl.toLowerCase().contains("https")) { if (fileUrl.toLowerCase().contains("https")) {
HttpsURLConnection con = (HttpsURLConnection) new URL(fileUrl) HttpsURLConnection con = (HttpsURLConnection) new URL(fileUrl)
.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;
@ -408,9 +417,10 @@ public class Core {
Bitmap img = BitmapFactory.decodeStream(con.getInputStream()); Bitmap img = BitmapFactory.decodeStream(con.getInputStream());
imgCache.put(fileUrl, img); imgCache.put(fileUrl, img);
return img; return img;
} else { }
else {
HttpURLConnection conn = (HttpURLConnection) myFileUrl HttpURLConnection conn = (HttpURLConnection) myFileUrl
.openConnection(); .openConnection();
conn.setDoInput(true); conn.setDoInput(true);
conn.setConnectTimeout(CONNECTION_TIMEOUT); conn.setConnectTimeout(CONNECTION_TIMEOUT);
conn.connect(); conn.connect();
@ -419,7 +429,8 @@ public class Core {
imgCache.put(fileUrl, img); imgCache.put(fileUrl, img);
return img; return img;
} }
} catch (IOException e) { }
catch (IOException e) {
Log.e(TAG, "Downloading image " + fileUrl + ": error"); Log.e(TAG, "Downloading image " + fileUrl + ": error");
} }
return null; return null;
@ -462,7 +473,8 @@ public class Core {
* Image size * Image size
*/ */
public static void setTextViewLeftImage(TextView view, Drawable image, public static void setTextViewLeftImage(TextView view, Drawable image,
int size) { int size) {
if (image != null) { if (image != null) {
image.setBounds(0, 0, size, size); image.setBounds(0, 0, size, size);
view.setCompoundDrawables(image, null, null, null); view.setCompoundDrawables(image, null, null, null);
@ -479,13 +491,16 @@ public class Core {
*/ */
public static boolean isValidCertificate(URL url) { public static boolean isValidCertificate(URL url) {
HttpsURLConnection con; HttpsURLConnection con;
try { try {
con = (HttpsURLConnection) url.openConnection(); con = (HttpsURLConnection) url.openConnection();
con.setConnectTimeout(CONNECTION_TIMEOUT); con.setConnectTimeout(CONNECTION_TIMEOUT);
con.connect(); con.connect();
con.disconnect(); con.disconnect();
return true; return true;
} catch (IOException e) { }
catch (IOException e) {
return false; return false;
} }
} }
@ -508,8 +523,10 @@ public class Core {
con.setSSLSocketFactory(getSocketFactory()); con.setSSLSocketFactory(getSocketFactory());
con.setDoOutput(true); con.setDoOutput(true);
con.getInputStream(); con.getInputStream();
return true; return true;
} catch (IOException e) { }
catch (IOException e) {
return false; return false;
} }
} }
@ -527,7 +544,8 @@ public class Core {
* *
*/ */
private static String httpsGet(String url, List<NameValuePair> parameters) private static String httpsGet(String url, List<NameValuePair> parameters)
throws IOException { throws IOException {
String result = ""; String result = "";
HttpsURLConnection con; HttpsURLConnection con;
try { try {
@ -545,12 +563,12 @@ public class Core {
for (NameValuePair nameValuePair : parameters) { for (NameValuePair nameValuePair : parameters) {
postData = first ? postData : postData + "&"; postData = first ? postData : postData + "&";
first = false; first = false;
postData += URLEncoder.encode(nameValuePair.getName()) + "=" postData += URLEncoder.encode(nameValuePair.getName())
+ URLEncoder.encode(nameValuePair.getValue()); + "=" + URLEncoder.encode(nameValuePair.getValue());
} }
if (postData.length() > 0) { if (postData.length() > 0) {
OutputStreamWriter wr = new OutputStreamWriter( OutputStreamWriter wr = new OutputStreamWriter(
con.getOutputStream()); con.getOutputStream());
wr.write(postData); wr.write(postData);
wr.flush(); wr.flush();
} }
@ -558,16 +576,18 @@ public class Core {
InputStream inputStream; InputStream inputStream;
inputStream = con.getInputStream(); inputStream = con.getInputStream();
BufferedReader bufferedReader = new BufferedReader( BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(inputStream)); new InputStreamReader(inputStream));
String temp; String temp;
while ((temp = bufferedReader.readLine()) != null) { while ((temp = bufferedReader.readLine()) != null) {
Log.d("CONTENT", temp); Log.d("CONTENT", temp);
result += temp + "\n"; result += temp + "\n";
} }
} catch (MalformedURLException e) { }
catch (MalformedURLException e) {
// Can't reach here because the given url is checked when is // Can't reach here because the given url is checked when is
// inserted in Options activity. // inserted in Options activity.
} }
return result; return result;
} }
@ -584,16 +604,19 @@ public class Core {
context.init(new KeyManager[0], tm, new SecureRandom()); context.init(new KeyManager[0], tm, new SecureRandom());
sslSocketFactory = (SSLSocketFactory) context sslSocketFactory = (SSLSocketFactory) context
.getSocketFactory(); .getSocketFactory();
} catch (KeyManagementException e) { }
catch (KeyManagementException e) {
Log.e("No SSL algorithm support: " + e.getMessage(), Log.e("No SSL algorithm support: " + e.getMessage(),
e.toString()); e.toString());
} catch (NoSuchAlgorithmException e) { }
catch (NoSuchAlgorithmException e) {
Log.e("Exception when setting up the Naive key management.", Log.e("Exception when setting up the Naive key management.",
e.toString()); e.toString());
} }
} }
return sslSocketFactory; return sslSocketFactory;
} }
@ -608,17 +631,20 @@ public class Core {
* correctly configured. * correctly configured.
*/ */
public static void showConnectionProblemToast(Context context, public static void showConnectionProblemToast(Context context,
boolean ignoreConnectionCheck) { boolean ignoreConnectionCheck) {
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);
if (preferences.getBoolean("online", false)) { if (preferences.getBoolean("online", false)) {
Toast.makeText(context, R.string.connection_problem, Toast.makeText(context, R.string.connection_problem,
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();
} else { }
else {
if (ignoreConnectionCheck) { if (ignoreConnectionCheck) {
Toast.makeText(context, R.string.connection_settings_problem, Toast.makeText(context,
Toast.LENGTH_SHORT).show(); R.string.connection_settings_problem,
Toast.LENGTH_SHORT).show();
} }
} }
} }
@ -652,23 +678,23 @@ public class Core {
*/ */
public static Drawable getSeverityImage(Context context, int severityCode) { public static Drawable getSeverityImage(Context context, int severityCode) {
switch (severityCode) { switch (severityCode) {
case 0: case 0:
return context.getResources().getDrawable( return context.getResources().getDrawable(
R.drawable.severity_maintenance); R.drawable.severity_maintenance);
case 1: case 1:
return context.getResources().getDrawable( return context.getResources().getDrawable(
R.drawable.severity_informational); R.drawable.severity_informational);
case 2: case 2:
return context.getResources().getDrawable( return context.getResources().getDrawable(
R.drawable.severity_normal); R.drawable.severity_normal);
case 3: case 3:
return context.getResources().getDrawable( return context.getResources().getDrawable(
R.drawable.severity_warning); R.drawable.severity_warning);
case 4: case 4:
return context.getResources().getDrawable( return context.getResources().getDrawable(
R.drawable.severity_critical); R.drawable.severity_critical);
} }
return null; return null;
@ -703,7 +729,8 @@ public class Core {
Integer code = images.get(eventType.toLowerCase()); Integer code = images.get(eventType.toLowerCase());
if (code != null) { if (code != null) {
return context.getResources().getDrawable(code); return context.getResources().getDrawable(code);
} else { }
else {
return null; return null;
} }
} }

View File

@ -392,42 +392,43 @@ public class EventList extends ListActivity {
content_event_item.setVisibility(RelativeLayout.GONE); content_event_item.setVisibility(RelativeLayout.GONE);
} }
} }
} else { }
else {
final EventListItem item = this.object.eventList.get(position); final EventListItem item = this.object.eventList.get(position);
switch (item.criticity) { switch (item.criticity) {
case 0:
case 0: view.setBackgroundColor(getResources().getColor(
view.setBackgroundColor(getResources().getColor( R.color.Blue));
R.color.Blue)); break;
break; case 1:
case 1: view.setBackgroundColor(getResources().getColor(
view.setBackgroundColor(getResources().getColor( R.color.Grey));
R.color.Grey)); break;
break; case 2:
case 2: view.setBackgroundColor(getResources().getColor(
view.setBackgroundColor(getResources().getColor( R.color.Green));
R.color.Green)); break;
break; case 3:
case 3: view.setBackgroundColor(getResources().getColor(
view.setBackgroundColor(getResources().getColor( R.color.Yellow));
R.color.Yellow)); break;
break; case 4:
case 4: view.setBackgroundColor(getResources()
view.setBackgroundColor(getResources() .getColor(R.color.Red));
.getColor(R.color.Red)); break;
break; default:
default: view.setBackgroundColor(getResources().getColor(
view.setBackgroundColor(getResources().getColor( R.color.Grey));
R.color.Grey)); break;
break;
} }
TextView titulo = (TextView) view.findViewById(R.id.agent_name); TextView titulo = (TextView) view.findViewById(R.id.agent_name);
if (item.event_type.equals("system")) { if (item.event_type.equals("system")) {
titulo.setText(R.string.system_str); titulo.setText(R.string.system_str);
} else { }
else {
titulo.setText(item.agent_name); titulo.setText(item.agent_name);
} }