mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-30 01:05:39 +02:00
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:
parent
1a9d58e3af
commit
dfa8f6f840
@ -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
|
||||
|
@ -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" >
|
||||
|
||||
|
@ -34,7 +34,7 @@ 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", ";"));
|
||||
|
||||
@ -45,7 +45,8 @@ 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;
|
||||
@ -60,7 +61,8 @@ 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"));
|
||||
@ -96,10 +98,12 @@ 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 "";
|
||||
}
|
||||
}
|
||||
@ -144,13 +148,13 @@ 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);
|
||||
}
|
||||
|
||||
@ -176,7 +180,8 @@ 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;
|
||||
@ -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,19 +227,21 @@ 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;
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
|
@ -41,7 +41,7 @@ public class About extends Activity {
|
||||
|
||||
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);
|
||||
@ -51,18 +51,19 @@ public class About extends Activity {
|
||||
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();
|
||||
}
|
||||
|
@ -89,8 +89,8 @@ 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;
|
||||
@ -98,12 +98,15 @@ public class Core {
|
||||
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();
|
||||
}
|
||||
}
|
||||
@ -127,28 +130,29 @@ 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);
|
||||
|
||||
@ -162,7 +166,8 @@ public class Core {
|
||||
* @return Time in milliseconds.
|
||||
*/
|
||||
public static long convertMaxTimeOldEventValuesToTimestamp(long time,
|
||||
int arrayKey) {
|
||||
int arrayKey) {
|
||||
|
||||
long return_var = 0;
|
||||
|
||||
if (time == 0) {
|
||||
@ -171,57 +176,57 @@ public class Core {
|
||||
}
|
||||
|
||||
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;
|
||||
@ -237,69 +242,69 @@ public class Core {
|
||||
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;
|
||||
@ -317,7 +322,9 @@ public class Core {
|
||||
for (int i = 1; i < params.length; i++) {
|
||||
return_var += "|" + params[i];
|
||||
}
|
||||
|
||||
Log.i(TAG + " serializeParams2Api", return_var);
|
||||
|
||||
return return_var;
|
||||
}
|
||||
|
||||
@ -333,10 +340,11 @@ 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", "");
|
||||
@ -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,7 +382,7 @@ 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;
|
||||
}
|
||||
@ -398,7 +407,7 @@ public class Core {
|
||||
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,7 +429,8 @@ public class Core {
|
||||
imgCache.put(fileUrl, img);
|
||||
return img;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
}
|
||||
catch (IOException e) {
|
||||
Log.e(TAG, "Downloading image " + fileUrl + ": error");
|
||||
}
|
||||
return null;
|
||||
@ -462,7 +473,8 @@ 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);
|
||||
@ -479,13 +491,16 @@ 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;
|
||||
}
|
||||
}
|
||||
@ -508,8 +523,10 @@ public class Core {
|
||||
con.setSSLSocketFactory(getSocketFactory());
|
||||
con.setDoOutput(true);
|
||||
con.getInputStream();
|
||||
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
}
|
||||
catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -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,12 +563,12 @@ 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();
|
||||
}
|
||||
@ -558,16 +576,18 @@ public class Core {
|
||||
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;
|
||||
}
|
||||
|
||||
@ -584,16 +604,19 @@ public class Core {
|
||||
context.init(new KeyManager[0], tm, new SecureRandom());
|
||||
|
||||
sslSocketFactory = (SSLSocketFactory) context
|
||||
.getSocketFactory();
|
||||
.getSocketFactory();
|
||||
|
||||
} catch (KeyManagementException e) {
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
@ -608,17 +631,20 @@ 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -652,23 +678,23 @@ 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;
|
||||
@ -703,7 +729,8 @@ public class Core {
|
||||
Integer code = images.get(eventType.toLowerCase());
|
||||
if (code != null) {
|
||||
return context.getResources().getDrawable(code);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user