2012-07-03 Santiago Munin <burning1@gmail.com>
* src/pandroid_event_viewer/pandorafms/IncidentListItem.java: Deleted, not necessary class. * src/pandroid_event_viewer/pandorafms/IncidentList.java: Deleted, not necessary class. * src/pandroid_event_viewer/pandorafms/EventList.java: The event type images are now fetched from the application (not internet). * src/pandroid_event_viewer/pandorafms/Core.java: Added a method which returns the event type image. * res/res/drawable-ldpi/: Added some images. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6728 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
|
@ -1,8 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="gen"/>
|
||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
||||
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry excluding="*.*" kind="src" path=".svn"/>
|
||||
<classpathentry kind="src" path="gen"/>
|
||||
<classpathentry kind="output" path="bin/classes"/>
|
||||
</classpath>
|
||||
|
|
|
@ -1,3 +1,10 @@
|
|||
2012-07-03 Santiago Munín <burning1@gmail.com>
|
||||
* src/pandroid_event_viewer/pandorafms/IncidentListItem.java: Deleted, not necessary class.
|
||||
* src/pandroid_event_viewer/pandorafms/IncidentList.java: Deleted, not necessary class.
|
||||
* src/pandroid_event_viewer/pandorafms/EventList.java: The event type images are now fetched from the application (not internet).
|
||||
* src/pandroid_event_viewer/pandorafms/Core.java: Added a method which returns the event type image.
|
||||
* res/res/drawable-ldpi/: Added some images.
|
||||
|
||||
2012-06-30 Santiago Munín <burning1@gmail.com>
|
||||
* src/pandroid_event_viewer/pandorafms/Main.java: Added a check in order to prevent profile overwritings.
|
||||
* src/pandroid_event_viewer/pandorafms/Core.java: Added method which finds a string in a list (case insensitive).
|
||||
|
|
After Width: | Height: | Size: 859 B |
After Width: | Height: | Size: 849 B |
After Width: | Height: | Size: 685 B |
After Width: | Height: | Size: 789 B |
After Width: | Height: | Size: 777 B |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 543 B |
After Width: | Height: | Size: 728 B |
After Width: | Height: | Size: 637 B |
After Width: | Height: | Size: 321 B |
After Width: | Height: | Size: 360 B |
After Width: | Height: | Size: 354 B |
After Width: | Height: | Size: 360 B |
After Width: | Height: | Size: 349 B |
After Width: | Height: | Size: 736 B |
|
@ -606,4 +606,71 @@ public class Core {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the corresponding image to the given severity code.
|
||||
*
|
||||
* @param context
|
||||
* Application context.
|
||||
* @param severityCode
|
||||
* Severity code.
|
||||
* @return a Drawable item.
|
||||
*/
|
||||
public static Drawable getSeverityImage(Context context, int severityCode) {
|
||||
switch (severityCode) {
|
||||
case 0:
|
||||
return context.getResources().getDrawable(
|
||||
R.drawable.severity_maintenance);
|
||||
case 1:
|
||||
return context.getResources().getDrawable(
|
||||
R.drawable.severity_informational);
|
||||
|
||||
case 2:
|
||||
return context.getResources().getDrawable(
|
||||
R.drawable.severity_normal);
|
||||
|
||||
case 3:
|
||||
return context.getResources().getDrawable(
|
||||
R.drawable.severity_warning);
|
||||
|
||||
case 4:
|
||||
return context.getResources().getDrawable(
|
||||
R.drawable.severity_critical);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the corresponding image to the given event type.
|
||||
*
|
||||
* @param context
|
||||
* Application context.
|
||||
* @param eventType
|
||||
* Event type.
|
||||
* @return Drawable
|
||||
*/
|
||||
public static Drawable getEventTypeImage(Context context, String eventType) {
|
||||
eventType = eventType.toLowerCase();
|
||||
Map<String, Integer> images = new HashMap<String, Integer>();
|
||||
images.put("alert_recovered", R.drawable.error);
|
||||
images.put("alert_manual_validation", R.drawable.eye);
|
||||
images.put("going_up_warning", R.drawable.b_yellow);
|
||||
images.put("going_up_critical", R.drawable.b_red);
|
||||
images.put("going_down_critical", R.drawable.b_red);
|
||||
images.put("going_up_normal", R.drawable.b_green);
|
||||
images.put("going_down_normal", R.drawable.b_green);
|
||||
images.put("going_down_warning", R.drawable.b_yellow);
|
||||
images.put("alert_fired", R.drawable.bell);
|
||||
images.put("system", R.drawable.cog);
|
||||
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 {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -387,9 +387,9 @@ public class EventList extends ListActivity {
|
|||
timestamp.setText(item.timestamp);
|
||||
|
||||
if (item.criticity_image.length() != 0)
|
||||
Core.setTextViewLeftImage(
|
||||
(TextView) view.findViewById(R.id.event_name),
|
||||
Core.downloadImage(item.criticity_image));
|
||||
Core.setTextViewLeftImage((TextView) view.findViewById(R.id.event_name), Core
|
||||
.getSeverityImage(getApplicationContext(),
|
||||
item.criticity), 16);
|
||||
|
||||
if (item.group_icon.length() != 0)
|
||||
Core.setTextViewLeftImage(
|
||||
|
@ -471,10 +471,9 @@ public class EventList extends ListActivity {
|
|||
text.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
}
|
||||
|
||||
if (item.description_image.length() != 0)
|
||||
Core.setTextViewLeftImage((TextView) viewEventExtended
|
||||
.findViewById(R.id.type_text),
|
||||
item.description_image);
|
||||
Core.setTextViewLeftImage((TextView) viewEventExtended
|
||||
.findViewById(R.id.type_text),
|
||||
Core.getEventTypeImage(getApplicationContext(), item.event_type), 16);
|
||||
|
||||
text = (TextView) viewEventExtended
|
||||
.findViewById(R.id.type_text);
|
||||
|
@ -484,12 +483,10 @@ public class EventList extends ListActivity {
|
|||
text = (TextView) viewEventExtended
|
||||
.findViewById(R.id.severity_text);
|
||||
text.setText(item.criticity_name);
|
||||
|
||||
if (item.criticity_image.length() != 0)
|
||||
Core.setTextViewLeftImage(
|
||||
(TextView) viewEventExtended
|
||||
.findViewById(R.id.severity_text),
|
||||
item.criticity_image);
|
||||
Core.setTextViewLeftImage((TextView) viewEventExtended
|
||||
.findViewById(R.id.severity_text), Core
|
||||
.getSeverityImage(getApplicationContext(),
|
||||
item.criticity), 16);
|
||||
}
|
||||
|
||||
// Set the open and close the extended info event row
|
||||
|
|
|
@ -1,269 +0,0 @@
|
|||
/*
|
||||
Pandora FMS - http://pandorafms.com
|
||||
|
||||
==================================================
|
||||
Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
|
||||
Please see http://pandorafms.org for full contribution list
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public License
|
||||
as published by the Free Software Foundation; version 2
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
*/
|
||||
package pandroid_event_viewer.pandorafms;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import android.app.ListActivity;
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ListView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
* Activity where incidents are displayed.
|
||||
*
|
||||
* @author Santiago Munín González
|
||||
*
|
||||
*/
|
||||
public class IncidentList extends ListActivity {
|
||||
private ListView lv;
|
||||
private MyIncidentListAdapter la;
|
||||
private boolean loadInProgress;
|
||||
private static String TAG = "IncidentList";
|
||||
private List<IncidentListItem> incidents = new ArrayList<IncidentListItem>();
|
||||
private int newIncidents;
|
||||
private int offset, pagination;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.list_view_layout);
|
||||
offset = 0;
|
||||
pagination = 0;
|
||||
la = new MyIncidentListAdapter(getBaseContext());
|
||||
this.toggleLoadingLayout();
|
||||
lv = (ListView) findViewById(android.R.id.list);
|
||||
lv.setAdapter(la);
|
||||
// TODO broadcast receiver went here
|
||||
this.toggleLoadingLayout();
|
||||
loadIncidents();
|
||||
this.toggleLoadingLayout();
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows loading information.
|
||||
*/
|
||||
private void toggleLoadingLayout() {
|
||||
LinearLayout layout;
|
||||
|
||||
layout = (LinearLayout) findViewById(R.id.empty_list_layout);
|
||||
layout.setVisibility(LinearLayout.GONE);
|
||||
|
||||
// layout = (LinearLayout) findViewById(R.id.loading_layout);
|
||||
|
||||
if (loadInProgress) {
|
||||
layout.setVisibility(LinearLayout.VISIBLE);
|
||||
} else {
|
||||
layout.setVisibility(LinearLayout.GONE);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Loads incidents.
|
||||
*
|
||||
*/
|
||||
private void loadIncidents() {
|
||||
la.showLoadingEvents = true;
|
||||
new GetIncidentsTask().execute((Void)null);
|
||||
}
|
||||
private class GetIncidentsTask extends AsyncTask<Void, Void, Void> {
|
||||
List<IncidentListItem> list = new ArrayList<IncidentListItem>();
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
incidents = new ArrayList<IncidentListItem>();
|
||||
//TODO just a tests
|
||||
IncidentListItem i = new IncidentListItem();
|
||||
i.title = "Test";
|
||||
i.description = "asdadsadads";
|
||||
i.timestamp = "ASDD";
|
||||
i.statusImage = "http://www.limpiatumundo.com/imagenes/circle_blue.png";
|
||||
list.add(i);
|
||||
i = new IncidentListItem();
|
||||
i.title = "Test2";
|
||||
list.add(i);
|
||||
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
super.onPostExecute(result);
|
||||
incidents.clear();
|
||||
incidents.addAll(list);
|
||||
la.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Private adapter (incident list).
|
||||
*
|
||||
* @author Santiago Munín González
|
||||
*
|
||||
*/
|
||||
private class MyIncidentListAdapter extends BaseAdapter {
|
||||
private Context mContext;
|
||||
public boolean showLoadingEvents;
|
||||
|
||||
public MyIncidentListAdapter(Context c) {
|
||||
super();
|
||||
mContext = c;
|
||||
showLoadingEvents = false;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
// TODO +1?
|
||||
return incidents.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
View view;
|
||||
|
||||
LayoutInflater inflater = (LayoutInflater) mContext
|
||||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
view = inflater.inflate(R.layout.item_list_incident_layout, null);
|
||||
view.setOnClickListener(new OnIncidentClickListener(position));
|
||||
// If the end of the list.
|
||||
if (incidents.size() == position) {
|
||||
// Show button to get more events
|
||||
if ((!loadInProgress) && (newIncidents != 0)) {
|
||||
if (showLoadingEvents) {
|
||||
LinearLayout layout = (LinearLayout) view
|
||||
.findViewById(R.id.loading_more_incidents);
|
||||
layout.setVisibility(LinearLayout.VISIBLE);
|
||||
|
||||
RelativeLayout layout2 = (RelativeLayout) view
|
||||
.findViewById(R.id.content_incident_item);
|
||||
layout2.setVisibility(RelativeLayout.VISIBLE);
|
||||
|
||||
Button button = (Button) view
|
||||
.findViewById(R.id.button_load_more_incidents);
|
||||
button.setVisibility(Button.GONE);
|
||||
} else {
|
||||
Button button = (Button) view
|
||||
.findViewById(R.id.button_load_more_incidents);
|
||||
|
||||
/* if (incidents.size() == 0) {
|
||||
button.setVisibility(Button.GONE);
|
||||
} else if (incidents.size() >= newIncidents) {
|
||||
button.setVisibility(Button.GONE);
|
||||
} else {
|
||||
button.setVisibility(Button.VISIBLE);
|
||||
}*/
|
||||
|
||||
button.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
offset += pagination;
|
||||
loadIncidents();
|
||||
}
|
||||
});
|
||||
|
||||
/*RelativeLayout content_event_item = (RelativeLayout) view
|
||||
.findViewById(R.id.content_event_item);
|
||||
content_event_item.setVisibility(RelativeLayout.GONE);*/
|
||||
}
|
||||
}
|
||||
} else {
|
||||
IncidentListItem item = incidents.get(position);
|
||||
|
||||
TextView tv = (TextView) view.findViewById(R.id.incident_name);
|
||||
tv.setText(item.title);
|
||||
Core.setTextViewLeftImage(tv, item.statusImage);
|
||||
|
||||
tv = (TextView) view.findViewById(R.id.incident_agent);
|
||||
tv.setText(item.nameAgent);
|
||||
Core.setTextViewLeftImage(tv, item.priorityImage);
|
||||
|
||||
tv = (TextView) view
|
||||
.findViewById(R.id.incident_last_update_timestamp);
|
||||
tv.setText(item.timestamp);
|
||||
|
||||
// Show extended info
|
||||
if (item.opened) {
|
||||
((LinearLayout) view.findViewById(R.id.incident_extra_info)).setVisibility(View.VISIBLE);
|
||||
|
||||
TextView text = (TextView) view.findViewById(R.id.incident_description);
|
||||
text.setText(item.description);
|
||||
|
||||
view.setOnClickListener(new OnIncidentClickListener(position));
|
||||
|
||||
Button button;
|
||||
button = (Button) findViewById(R.id.incident_close_button);
|
||||
// TODO if status == closed then
|
||||
// button.setVisibility(Visibility.GONE);
|
||||
// else
|
||||
/* button.setOnClickListener(new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// TODO close event
|
||||
}
|
||||
});*/
|
||||
|
||||
} else {
|
||||
((LinearLayout) view.findViewById(R.id.incident_extra_info)).setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom click listener (show more information).
|
||||
*
|
||||
* @author Santiago Munín González
|
||||
*
|
||||
*/
|
||||
private class OnIncidentClickListener implements OnClickListener {
|
||||
private int mPosition;
|
||||
|
||||
OnIncidentClickListener(int position) {
|
||||
mPosition = position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
IncidentListItem item = incidents.get(mPosition);
|
||||
item.opened = !item.opened;
|
||||
incidents.set(mPosition, item);
|
||||
la.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package pandroid_event_viewer.pandorafms;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents an incident.
|
||||
*
|
||||
* @author Santiago Munín González
|
||||
*
|
||||
*/
|
||||
public class IncidentListItem {
|
||||
public int id;
|
||||
public int idAgent;
|
||||
public String nameAgent;
|
||||
public String title;
|
||||
public String description;
|
||||
public int priority;
|
||||
public String priorityImage;
|
||||
public int idGroup;
|
||||
public String nameGroup;
|
||||
public List<String> notes;
|
||||
public int status;
|
||||
public String statusImage;
|
||||
public String timestamp;
|
||||
public boolean opened = false;
|
||||
//TODO attachments too?
|
||||
}
|