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 1f4b99eaa9
commit fef54fd731
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>
* .classpath: removed the entry for ".svn" folder

View File

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

View File

@ -15,9 +15,9 @@ import android.util.Log;
@SuppressLint("UseSparseArrays")
public class API {
private static String TAG = "API";
/**
* Get groups through an api call.
*
@ -34,10 +34,10 @@ public class API {
parameters.add(new BasicNameValuePair("op", "get"));
parameters.add(new BasicNameValuePair("op2", "groups"));
parameters.add(new BasicNameValuePair("other_mode",
"url_encode_separator_|"));
"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");
try {
@ -45,12 +45,13 @@ public class API {
String[] groups = lines[i].split(";", 21);
result.put(Integer.valueOf(groups[0]), groups[1]);
}
} catch (NumberFormatException e) {
}
catch (NumberFormatException e) {
Log.e(TAG, "Problem parsing number in response");
}
return result;
}
/**
* Get agents through an api call.
*
@ -60,23 +61,24 @@ public class API {
* If there is a problem with the connection.
*/
public static Map<Integer, String> getAgents(Context context)
throws IOException {
throws IOException {
Map<Integer, String> result = new HashMap<Integer, String>();
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");
for (int i = 0; i < lines.length; i++) {
String[] agents = lines[i].split(";");
result.put(Integer.valueOf(agents[0]), agents[1]);
}
return result;
}
/**
* Get API version.
*
@ -96,14 +98,16 @@ public class API {
String[] lines = return_api.split(",");
if (lines.length == 3) {
return lines[1];
} else {
}
else {
return context.getString(R.string.unknown_version);
}
} else {
}
else {
return "";
}
}
/**
* Performs a get_events API call.
*
@ -144,16 +148,16 @@ public class API {
parameters.add(new BasicNameValuePair("op", "get"));
parameters.add(new BasicNameValuePair("op2", "events"));
parameters.add(new BasicNameValuePair("other_mode",
"url_encode_separator_|"));
"url_encode_separator_|"));
parameters.add(new BasicNameValuePair("return_type", "csv"));
parameters.add(new BasicNameValuePair("other",
serializeEventsParamsToAPI(filterAgentName, idGroup,
filterSeverity, filterStatus, filterEventSearch,
filterTag, filterTimestamp, itemsPerPage, offset,
total, more_criticity)));
serializeEventsParamsToAPI(filterAgentName, idGroup,
filterSeverity, filterStatus, filterEventSearch,
filterTag, filterTimestamp, itemsPerPage, offset, total,
more_criticity)));
return Core.httpGet(context, parameters);
}
/**
* Get tags through an api call.
*
@ -176,12 +180,13 @@ public class API {
String[] tags = lines[i].split(";", 2);
array.add(tags[1]);
}
} catch (ArrayIndexOutOfBoundsException e) {
}
catch (ArrayIndexOutOfBoundsException e) {
Log.e(TAG, "There was a problem getting tags: " + e.getMessage());
}
return array;
}
/**
* Creates new incident in console.
*
@ -195,14 +200,15 @@ public class API {
*/
public static void createNewIncident(Context context,
String[] incidentParameters) throws IOException {
Log.i(TAG, "Sending new incident");
List<NameValuePair> parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair("op", "set"));
parameters.add(new BasicNameValuePair("op2", "new_incident"));
parameters.add(new BasicNameValuePair("other_mode",
"url_encode_separator_|"));
"url_encode_separator_|"));
parameters.add(new BasicNameValuePair("other", Core
.serializeParams2Api(incidentParameters)));
.serializeParams2Api(incidentParameters)));
Core.httpGet(context, parameters);
}
@ -221,23 +227,25 @@ public class API {
*/
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()));
.toString()));
parameters.add(new BasicNameValuePair("other", comment));
String return_api = Core.httpGet(context, parameters);
if (return_api.startsWith("Correct validation")) {
return true;
} else {
}
else {
return false;
}
}
/**
* Serialize parameters to api.
*
@ -266,17 +274,17 @@ public class API {
* @return Serialized parameters.
*/
private static String serializeEventsParamsToAPI(String filterAgentName,
int idGroup, int filterSeverity, int filterStatus,
String filterEventSearch, String filterTag, long filterTimestamp,
long itemsPerPage, long offset, boolean total,
boolean more_criticity) {
int idGroup, int filterSeverity, int filterStatus,
String filterEventSearch, String filterTag, long filterTimestamp,
long itemsPerPage, long offset, boolean total,
boolean more_criticity) {
String totalStr = (total) ? "total" : "-1";
if (more_criticity) {
totalStr = "more_criticity";
}
return Core.serializeParams2Api(new String[] { ";", // Separator for the
// csv
return Core.serializeParams2Api(new String[] {
";", // Separator for the csv
Integer.toString(filterSeverity), // criticity or severity
filterAgentName, // The agent name
"", // Name of module

View File

@ -32,37 +32,38 @@ import android.widget.TextView;
*
*/
public class About extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.info);
TextView text = (TextView) findViewById(R.id.url_pandora);
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());
CheckBox check_show = (CheckBox) findViewById(R.id.dont_show_again_extended);
check_show.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
CheckBox check_show = (CheckBox) v;
if (check_show.isChecked()) {
SharedPreferences preferences = getSharedPreferences(
getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
SharedPreferences.Editor editorPreferences = preferences
.edit();
.edit();
editorPreferences.putBoolean("show_popup_info", false);
editorPreferences.commit();
} else {
}
else {
SharedPreferences preferences = getSharedPreferences(
getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
SharedPreferences.Editor editorPreferences = preferences
.edit();
.edit();
editorPreferences.putBoolean("show_popup_info", true);
editorPreferences.commit();
}

View File

@ -81,7 +81,7 @@ public class Core {
private static Map<String, Bitmap> imgCache = new HashMap<String, Bitmap>();
// Don't use this variable, just call getSocketFactory
private static SSLSocketFactory sslSocketFactory;
/**
* Reads from the input stream and returns a string.
*
@ -89,28 +89,31 @@ public class Core {
* @return A string with all data read.
*/
private static String convertStreamToString(InputStream is) {
BufferedReader reader = new BufferedReader(new InputStreamReader(is),
8 * 1024);
BufferedReader reader = new BufferedReader(
new InputStreamReader(is), 8 * 1024);
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
} catch (IOException e) {
}
catch (IOException e) {
e.printStackTrace();
} finally {
}
finally {
try {
is.close();
} catch (IOException e) {
}
catch (IOException e) {
e.printStackTrace();
}
}
return sb.toString();
}
/**
* Sets fetch frequency.
*
@ -127,33 +130,34 @@ public class Core {
ctx.stopService(new Intent(ctx, PandroidEventviewerService.class));
// Sets the launch frequency
AlarmManager alarmM = (AlarmManager) ctx
.getSystemService(Context.ALARM_SERVICE);
.getSystemService(Context.ALARM_SERVICE);
PendingIntent pandroidService = PendingIntent.getService(ctx, 0,
new Intent(ctx, PandroidEventviewerService.class), 0);
new Intent(ctx, PandroidEventviewerService.class), 0);
int sleepTimeAlarm = convertRefreshTimeKeyToTime(ctx);
Log.i(TAG, "sleepTimeAlarm = " + sleepTimeAlarm);
alarmM.setRepeating(AlarmManager.RTC_WAKEUP,
System.currentTimeMillis(), sleepTimeAlarm, pandroidService);
} else {
System.currentTimeMillis(), sleepTimeAlarm, pandroidService);
}
else {
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) {
AlarmManager alarmM = (AlarmManager) ctx
.getSystemService(Context.ALARM_SERVICE);
.getSystemService(Context.ALARM_SERVICE);
PendingIntent pandroidService = PendingIntent.getService(ctx, 0,
new Intent(ctx, PandroidEventviewerService.class), 0);
new Intent(ctx, PandroidEventviewerService.class), 0);
Log.i(TAG, "Background service cancelled");
alarmM.cancel(pandroidService);
}
/**
* Converts the maximum time setted to filter events to a timestamp.
*
@ -162,71 +166,72 @@ public class Core {
* @return Time in milliseconds.
*/
public static long convertMaxTimeOldEventValuesToTimestamp(long time,
int arrayKey) {
int arrayKey) {
long return_var = 0;
if (time == 0) {
Calendar c = Calendar.getInstance();
time = c.getTimeInMillis() / 1000;
}
switch (arrayKey) {
case 0:
return_var = time - 30 * 60;
break;
case 1:
return_var = time - 60 * 60;
break;
case 2:
return_var = time - 2 * (60 * 60);
break;
case 3:
return_var = time - 3 * (60 * 60);
break;
case 4:
return_var = time - 4 * (60 * 60);
break;
case 5:
return_var = time - 5 * (60 * 60);
break;
case 6:
return_var = time - 8 * (60 * 60);
break;
case 7:
return_var = time - 10 * (60 * 60);
break;
case 8:
return_var = time - 12 * (60 * 60);
break;
case 9:
return_var = time - 24 * (60 * 60);
break;
case 10:
return_var = time - 2 * (24 * 60 * 60);
break;
case 11:
return_var = time - 3 * (24 * 60 * 60);
break;
case 12:
return_var = time - 4 * (24 * 60 * 60);
break;
case 13:
return_var = time - 5 * (24 * 60 * 60);
break;
case 14:
return_var = time - 7 * (24 * 60 * 60);
break;
case 15:
return_var = time - 2 * (7 * 24 * 60 * 60);
break;
case 16:
return_var = time - 30 * (24 * 60 * 60);
break;
case 0:
return_var = time - 30 * 60;
break;
case 1:
return_var = time - 60 * 60;
break;
case 2:
return_var = time - 2 * (60 * 60);
break;
case 3:
return_var = time - 3 * (60 * 60);
break;
case 4:
return_var = time - 4 * (60 * 60);
break;
case 5:
return_var = time - 5 * (60 * 60);
break;
case 6:
return_var = time - 8 * (60 * 60);
break;
case 7:
return_var = time - 10 * (60 * 60);
break;
case 8:
return_var = time - 12 * (60 * 60);
break;
case 9:
return_var = time - 24 * (60 * 60);
break;
case 10:
return_var = time - 2 * (24 * 60 * 60);
break;
case 11:
return_var = time - 3 * (24 * 60 * 60);
break;
case 12:
return_var = time - 4 * (24 * 60 * 60);
break;
case 13:
return_var = time - 5 * (24 * 60 * 60);
break;
case 14:
return_var = time - 7 * (24 * 60 * 60);
break;
case 15:
return_var = time - 2 * (7 * 24 * 60 * 60);
break;
case 16:
return_var = time - 30 * (24 * 60 * 60);
break;
}
return return_var;
}
/**
* Converts max event age chosen from spinner to seconds (either are seconds
* or not)
@ -235,76 +240,76 @@ public class Core {
*/
private static int convertRefreshTimeKeyToTime(Context ctx) {
int returnvar = 60 * 10;
SharedPreferences preferences = ctx.getSharedPreferences(
ctx.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
ctx.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
int refreshTimeKey = preferences.getInt("refreshTimeKey", 3);
switch (refreshTimeKey) {
case 0:
returnvar = 30; // 30 seconds
break;
case 1:
returnvar = 60; // 1 minute
break;
case 2:
returnvar = 60 * 5; // 5 minutes
break;
case 3:
returnvar = 60 * 10; // 10 minutes
break;
case 4:
returnvar = 60 * 15; // 15 minutes
break;
case 5:
returnvar = 60 * 30; // 30 minutes
break;
case 6:
returnvar = 60 * 45; // 45 minutes
break;
case 7:
returnvar = 3600; // 1 hour
break;
case 8:
returnvar = 3600 + (60 * 30); // 1 hour and 30 minutes
break;
case 9:
returnvar = 3600 * 2; // 2 hours
break;
case 10:
returnvar = 3600 * 3; // 3 hours
break;
case 11:
returnvar = 3600 * 4; // 4 hours
break;
case 12:
returnvar = 3600 * 6; // 6 hours
break;
case 13:
returnvar = 3600 * 8; // 8 hours
break;
case 14:
returnvar = 3600 * 10; // 10 hours
break;
case 15:
returnvar = 3600 * 12; // 12 hours
break;
case 16:
returnvar = 3600 * 24; // 24 hours
break;
case 17:
returnvar = 3600 * 36; // 36 hours
break;
case 18:
returnvar = 3600 * 48; // 48 hours
break;
case 0:
returnvar = 30; // 30 seconds
break;
case 1:
returnvar = 60; // 1 minute
break;
case 2:
returnvar = 60 * 5; // 5 minutes
break;
case 3:
returnvar = 60 * 10; // 10 minutes
break;
case 4:
returnvar = 60 * 15; // 15 minutes
break;
case 5:
returnvar = 60 * 30; // 30 minutes
break;
case 6:
returnvar = 60 * 45; // 45 minutes
break;
case 7:
returnvar = 3600; // 1 hour
break;
case 8:
returnvar = 3600 + (60 * 30); // 1 hour and 30 minutes
break;
case 9:
returnvar = 3600 * 2; // 2 hours
break;
case 10:
returnvar = 3600 * 3; // 3 hours
break;
case 11:
returnvar = 3600 * 4; // 4 hours
break;
case 12:
returnvar = 3600 * 6; // 6 hours
break;
case 13:
returnvar = 3600 * 8; // 8 hours
break;
case 14:
returnvar = 3600 * 10; // 10 hours
break;
case 15:
returnvar = 3600 * 12; // 12 hours
break;
case 16:
returnvar = 3600 * 24; // 24 hours
break;
case 17:
returnvar = 3600 * 36; // 36 hours
break;
case 18:
returnvar = 3600 * 48; // 48 hours
break;
}
return returnvar * 1000;
}
/**
* Converts params to string.
*
@ -313,14 +318,16 @@ public class Core {
*/
public static String serializeParams2Api(String[] params) {
String return_var = params[0];
for (int i = 1; i < params.length; i++) {
return_var += "|" + params[i];
}
Log.i(TAG + " serializeParams2Api", return_var);
return return_var;
}
/**
* Performs an http get petition.
*
@ -333,11 +340,12 @@ public class Core {
* If there is any problem with the connection.
*/
public static String httpGet(Context context,
List<NameValuePair> additionalParameters) throws IOException {
List<NameValuePair> additionalParameters) throws IOException {
SharedPreferences preferences = context.getSharedPreferences(
context.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
context.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
String url = preferences.getString("url", "") + "/include/api.php";
String user = preferences.getString("user", "");
String password = preferences.getString("password", "");
@ -356,10 +364,11 @@ public class Core {
if (url.toLowerCase().contains("https")) {
// Secure connection
return Core.httpsGet(url, parameters);
} else {
}
else {
HttpParams params = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(params,
CONNECTION_TIMEOUT);
CONNECTION_TIMEOUT);
HttpConnectionParams.setSoTimeout(params, CONNECTION_TIMEOUT);
DefaultHttpClient httpClient = new DefaultHttpClient(params);
UrlEncodedFormEntity entity;
@ -373,12 +382,12 @@ public class Core {
response = httpClient.execute(httpPost);
entityResponse = response.getEntity();
return_api = Core
.convertStreamToString(entityResponse.getContent());
.convertStreamToString(entityResponse.getContent());
Log.i(TAG, "received: " + return_api);
return return_api;
}
}
/**
* Downloads an image
*
@ -393,12 +402,12 @@ public class Core {
}
Log.i(TAG, "Downloading image: " + fileUrl);
URL myFileUrl = null;
try {
myFileUrl = new URL(fileUrl);
if (fileUrl.toLowerCase().contains("https")) {
HttpsURLConnection con = (HttpsURLConnection) new URL(fileUrl)
.openConnection();
.openConnection();
con.setHostnameVerifier(new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
@ -408,9 +417,10 @@ public class Core {
Bitmap img = BitmapFactory.decodeStream(con.getInputStream());
imgCache.put(fileUrl, img);
return img;
} else {
}
else {
HttpURLConnection conn = (HttpURLConnection) myFileUrl
.openConnection();
.openConnection();
conn.setDoInput(true);
conn.setConnectTimeout(CONNECTION_TIMEOUT);
conn.connect();
@ -419,12 +429,13 @@ public class Core {
imgCache.put(fileUrl, img);
return img;
}
} catch (IOException e) {
}
catch (IOException e) {
Log.e(TAG, "Downloading image " + fileUrl + ": error");
}
return null;
}
/**
* Puts the image to the left of theTextView.
*
@ -437,7 +448,7 @@ public class Core {
Drawable d = new BitmapDrawable(image);
setTextViewLeftImage(view, d, 16);
}
/**
* Puts the image to the left of theTextView.
*
@ -450,7 +461,7 @@ public class Core {
Drawable d = new BitmapDrawable(Core.downloadImage(url));
setTextViewLeftImage(view, d, 16);
}
/**
* Puts the image to the left of theTextView.
*
@ -462,13 +473,14 @@ public class Core {
* Image size
*/
public static void setTextViewLeftImage(TextView view, Drawable image,
int size) {
int size) {
if (image != null) {
image.setBounds(0, 0, size, size);
view.setCompoundDrawables(image, null, null, null);
}
}
/**
* Finds out if the given url has a CA signed certificate.
*
@ -479,17 +491,20 @@ public class Core {
*/
public static boolean isValidCertificate(URL url) {
HttpsURLConnection con;
try {
con = (HttpsURLConnection) url.openConnection();
con.setConnectTimeout(CONNECTION_TIMEOUT);
con.connect();
con.disconnect();
return true;
} catch (IOException e) {
}
catch (IOException e) {
return false;
}
}
/**
* Checks if a url is online.
*
@ -508,12 +523,14 @@ public class Core {
con.setSSLSocketFactory(getSocketFactory());
con.setDoOutput(true);
con.getInputStream();
return true;
} catch (IOException e) {
}
catch (IOException e) {
return false;
}
}
/**
* Performs an secure http petition
*
@ -527,7 +544,8 @@ public class Core {
*
*/
private static String httpsGet(String url, List<NameValuePair> parameters)
throws IOException {
throws IOException {
String result = "";
HttpsURLConnection con;
try {
@ -545,32 +563,34 @@ public class Core {
for (NameValuePair nameValuePair : parameters) {
postData = first ? postData : postData + "&";
first = false;
postData += URLEncoder.encode(nameValuePair.getName()) + "="
+ URLEncoder.encode(nameValuePair.getValue());
postData += URLEncoder.encode(nameValuePair.getName())
+ "=" + URLEncoder.encode(nameValuePair.getValue());
}
if (postData.length() > 0) {
OutputStreamWriter wr = new OutputStreamWriter(
con.getOutputStream());
con.getOutputStream());
wr.write(postData);
wr.flush();
}
InputStream inputStream;
inputStream = con.getInputStream();
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(inputStream));
new InputStreamReader(inputStream));
String temp;
while ((temp = bufferedReader.readLine()) != null) {
Log.d("CONTENT", temp);
result += temp + "\n";
}
} catch (MalformedURLException e) {
}
catch (MalformedURLException e) {
// Can't reach here because the given url is checked when is
// inserted in Options activity.
}
return result;
}
/**
* Returns a SSL Factory instance that accepts all server certificates.
*
@ -582,21 +602,24 @@ public class Core {
TrustManager[] tm = new TrustManager[] { new NaiveTrustManager() };
SSLContext context = SSLContext.getInstance("TLS");
context.init(new KeyManager[0], tm, new SecureRandom());
sslSocketFactory = (SSLSocketFactory) context
.getSocketFactory();
} catch (KeyManagementException e) {
.getSocketFactory();
}
catch (KeyManagementException e) {
Log.e("No SSL algorithm support: " + e.getMessage(),
e.toString());
} catch (NoSuchAlgorithmException e) {
e.toString());
}
catch (NoSuchAlgorithmException e) {
Log.e("Exception when setting up the Naive key management.",
e.toString());
e.toString());
}
}
return sslSocketFactory;
}
/**
* Shows a toast which will show the connection problem message. Do not call
* outside the UI's thread.
@ -608,21 +631,24 @@ public class Core {
* correctly configured.
*/
public static void showConnectionProblemToast(Context context,
boolean ignoreConnectionCheck) {
boolean ignoreConnectionCheck) {
SharedPreferences preferences = context.getSharedPreferences(
context.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
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 {
Toast.LENGTH_SHORT).show();
}
else {
if (ignoreConnectionCheck) {
Toast.makeText(context, R.string.connection_settings_problem,
Toast.LENGTH_SHORT).show();
Toast.makeText(context,
R.string.connection_settings_problem,
Toast.LENGTH_SHORT).show();
}
}
}
/**
* Checks if a string is inside the list (case insensitive).
*
@ -640,7 +666,7 @@ public class Core {
}
return false;
}
/**
* Returns the corresponding image to the given severity code.
*
@ -652,28 +678,28 @@ public class Core {
*/
public static Drawable getSeverityImage(Context context, int severityCode) {
switch (severityCode) {
case 0:
return context.getResources().getDrawable(
case 0:
return context.getResources().getDrawable(
R.drawable.severity_maintenance);
case 1:
return context.getResources().getDrawable(
case 1:
return context.getResources().getDrawable(
R.drawable.severity_informational);
case 2:
return context.getResources().getDrawable(
case 2:
return context.getResources().getDrawable(
R.drawable.severity_normal);
case 3:
return context.getResources().getDrawable(
case 3:
return context.getResources().getDrawable(
R.drawable.severity_warning);
case 4:
return context.getResources().getDrawable(
case 4:
return context.getResources().getDrawable(
R.drawable.severity_critical);
}
return null;
}
/**
* Returns the corresponding image to the given event type.
*
@ -699,11 +725,12 @@ public class Core {
images.put("recon_host_detected", R.drawable.network);
images.put("new_agent", R.drawable.wand);
images.put("unknown", R.drawable.err);
Integer code = images.get(eventType.toLowerCase());
if (code != null) {
return context.getResources().getDrawable(code);
} else {
}
else {
return null;
}
}

View File

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