2011-09-21 Miguel de Dios <miguel.dedios@artica.es>

* src/pandroid_event_viewer/pandorafms/PandroidEventviewerActivity.java,
	src/pandroid_event_viewer/pandorafms/Main.java,
	src/pandroid_event_viewer/pandorafms/EventListItem.java,
	src/pandroid_event_viewer/pandorafms/EventList.java: wip, now the list
	events run fine, and get asynchronous events and added some checks.
	
	* res/values/strings.xml, res/values-en/strings.xml,
	res/values-es/strings.xml: added more strings.
	
	* res/layout/list_view_layout.xml,
	res/layout/item_list_event_layout.xml: changes for to show the buttons and
	messages.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4978 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2011-09-21 20:50:34 +00:00
parent 249bf6ed93
commit 3e2191e871
10 changed files with 381 additions and 125 deletions

View File

@ -1,3 +1,18 @@
2011-09-21 Miguel de Dios <miguel.dedios@artica.es>
* src/pandroid_event_viewer/pandorafms/PandroidEventviewerActivity.java,
src/pandroid_event_viewer/pandorafms/Main.java,
src/pandroid_event_viewer/pandorafms/EventListItem.java,
src/pandroid_event_viewer/pandorafms/EventList.java: wip, now the list
events run fine, and get asynchronous events and added some checks.
* res/values/strings.xml, res/values-en/strings.xml,
res/values-es/strings.xml: added more strings.
* res/layout/list_view_layout.xml,
res/layout/item_list_event_layout.xml: changes for to show the buttons and
messages.
2011-09-20 Miguel de Dios <miguel.dedios@artica.es>
* res/values/strings.xml, res/values-en/strings.xml,

View File

@ -22,7 +22,7 @@
android:id="@+id/item_linear_layout"
>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/content_event_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
@ -61,12 +61,32 @@
/>
</LinearLayout>
</RelativeLayout>
<!--<ImageButton
android:id="@+id/icon_config"
<Button
android:id="@+id/button_load_more_events"
android:text="@string/load_more_events_button_str"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone"
/>
<LinearLayout
android:id="@+id/loading_more_events"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/config"
android:layout_weight="0"
android:layout_alignParentRight="@layout/item_list_event_layout"
/>-->
android:visibility="gone"
>
<ProgressBar
android:layout_height="wrap_content"
android:layout_width="wrap_content"
style="?android:attr/progressBarStyleSmall"
android:paddingRight="10dip"
/>
<TextView
android:textColor="#ffffff"
android:text="@string/loading_label_str"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
/>
</LinearLayout>
</LinearLayout>

View File

@ -40,6 +40,21 @@
android:textStyle="bold"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/empty_list_layout"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
>
<TextView
android:textColor="#ffffff"
android:text="@string/empty_label_str"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
/>
</LinearLayout>
<ListView
android:id="@id/android:list"
android:layout_width="fill_parent"

View File

@ -43,6 +43,8 @@
<string name="password_label_str">Password</string>
<string name="update_button_str">Update</string>
<string name="option_title_str">Options</string>
<string name="load_more_events_button_str">Load more events</string>
<string name="empty_label_str">Empty list events</string>
<string name="config_update_succesful_str">Update configuration successful.</string>
<string name="config_update_fail_str">Update configuration is failed.</string>

View File

@ -43,6 +43,8 @@
<string name="password_label_str">Contraseña</string>
<string name="update_button_str">Actualizar</string>
<string name="option_title_str">Opciones</string>
<string name="load_more_events_button_str">Cargar mas eventos</string>
<string name="empty_label_str">Lista vacia de eventos</string>
<string name="config_update_succesful_str">Configuración guardada correctamente.</string>
<string name="config_update_fail_str">Configuración no ha podido guardarse..</string>

View File

@ -46,6 +46,8 @@
<string name="password_label_str">Password</string>
<string name="update_button_str">Update</string>
<string name="option_title_str">Options</string>
<string name="load_more_events_button_str">Load more events</string>
<string name="empty_label_str">Empty list events</string>
<string name="config_update_succesful_str">Update configuration successful.</string>
<string name="config_update_fail_str">Update configuration is failed.</string>

View File

@ -8,8 +8,10 @@ import java.net.URL;
import java.util.HashMap;
import android.app.ListActivity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
@ -21,9 +23,11 @@ import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
@ -35,13 +39,16 @@ public class EventList extends ListActivity {
public HashMap<String, Bitmap> imgGroups;
public HashMap<String, Bitmap> imgSeverity;
public HashMap<String, Bitmap> imgType;
public String test;
private BroadcastReceiver onBroadcast;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.openedItem = new HashMap<Integer, Boolean>();
// this.openedItem = new HashMap<Integer, Boolean>();
this.imgGroups = new HashMap<String, Bitmap>();
this.imgSeverity = new HashMap<String, Bitmap>();
this.imgType = new HashMap<String, Bitmap>();
@ -58,11 +65,39 @@ public class EventList extends ListActivity {
la = new MyAdapter(getBaseContext(), object);
lv.setAdapter(la);
test = "666";
onBroadcast = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.e("onReceive", "onReceive");
int load_more = intent.getIntExtra("load_more", 0);
if (load_more == 1) {
la.showLoadingEvents = false;
la.notifyDataSetChanged();
}
else {
LinearLayout layout = (LinearLayout) findViewById(R.id.loading_layout);
layout.setVisibility(LinearLayout.GONE);
if (object.count_events == 0) {
layout = (LinearLayout) findViewById(R.id.empty_list_layout);
layout.setVisibility(LinearLayout.VISIBLE);
}
}
}
};
}
public void onResume() {
super.onResume();
registerReceiver(onBroadcast, new IntentFilter("eventlist.java"));
this.toggleLoadingLayout();
}
@ -174,83 +209,39 @@ public class EventList extends ListActivity {
{
super.onListItemClick(l, v, position, id);
Boolean opened = new Boolean(false);
if (this.openedItem.containsKey(new Integer(position))) {
opened = this.openedItem.get(new Integer(position));
}
LinearLayout itemLinearLayout = (LinearLayout)l.findViewById(R.id.item_linear_layout);
if (!opened.booleanValue()) {
EventListItem item = this.object.eventList.get(position);
View view;
LayoutInflater inflater = (LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.item_list_event_extended, null);
TextView text;
if (item.tags.length() != 0) {
text = (TextView)view.findViewById(R.id.tags_text);
text.setText(item.tags);
}
if (item.user_comment.length() != 0) {
text = (TextView)view.findViewById(R.id.comments_text);
text.setText(item.user_comment);
}
if (item.group_name.length() != 0) {
text = (TextView)view.findViewById(R.id.group_text);
text.setText(item.group_name);
this.setImageGroup(view, item.group_icon, R.id.img_group);
}
else {
//ALL
this.setImageGroup(view, "world", R.id.img_group);
}
if (item.agent_name.length() != 0) {
View row = view.findViewById(R.id.row_agent);
row.setVisibility(View.VISIBLE);
text = (TextView)view.findViewById(R.id.type_text);
text.setText(item.description_event);
this.setImageType(view, item.description_image, R.id.img_type);
}
if (item.criticity_name.length() != 0) {
text = (TextView)view.findViewById(R.id.severity_text);
text.setText(item.criticity_name);
this.setImageType(view, item.criticity_image, R.id.img_severity);
}
Log.e("item", item.criticity_name);
itemLinearLayout.addView(view);
}
else {
itemLinearLayout.removeViewAt(1);
}
opened = new Boolean(!opened.booleanValue());
this.openedItem.put(new Integer(position), opened);
Log.e("onListItemClick", new Integer(position).toString());
EventListItem item = this.object.eventList.get(position);
item.opened = !item.opened;
this.object.eventList.set(position, item);
la.notifyDataSetChanged();
}
public void loadMoreEvents(View v) {
la.showLoadingEvents = true;
la.notifyDataSetChanged();
object.executeBackgroundGetEvents();
}
public class MyAdapter extends BaseAdapter
{
private Context mContext;
public PandroidEventviewerActivity object;
public boolean showLoadingEvents;
public MyAdapter(Context c, PandroidEventviewerActivity object)
{
mContext = c;
this.object = object;
showLoadingEvents = false;
}
@Override
public int getCount() {
return this.object.eventList.size();
return this.object.eventList.size() + 1;
}
@Override
@ -264,60 +255,142 @@ public class EventList extends ListActivity {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view;
EventListItem item = this.object.eventList.get(position);
//The comment lines don't run fine, opened wrong the rows.
//OPTIMIZACIÓN PARA NO CREAR convertView
if (convertView == null)
{
//Optimization for not create convertView all times
//if (convertView == null)
//{
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.item_list_event_layout, null);
}
/*}
else
{
view = convertView;
}
}*/
switch (item.criticity) {
case 0://Blue
view.setBackgroundColor(Color.parseColor("#CDE2EA"));
break;
case 1://Grey
view.setBackgroundColor(Color.parseColor("#E4E4E4"));
break;
case 2://Green
view.setBackgroundColor(Color.parseColor("#BBFFA4"));
break;
case 3://Yellow
view.setBackgroundColor(Color.parseColor("#F4FFBF"));
break;
case 4://Red
view.setBackgroundColor(Color.parseColor("#FFC0B5"));
break;
default://Grey
view.setBackgroundColor(Color.parseColor("#E4E4E4"));
break;
//If the end of the list.
if (this.object.eventList.size() == position) {
//Show button to get more events
if ((!object.loadInProgress) && (object.count_events != 0)) {
if (showLoadingEvents) {
LinearLayout layout = (LinearLayout) view.findViewById(R.id.loading_more_events);
layout.setVisibility(LinearLayout.VISIBLE);
RelativeLayout layout2 = (RelativeLayout) view.findViewById(R.id.content_event_item);
layout2.setVisibility(RelativeLayout.GONE);
Button button = (Button)view.findViewById(R.id.button_load_more_events);
button.setVisibility(Button.GONE);
}
else {
Button button = (Button)view.findViewById(R.id.button_load_more_events);
button.setVisibility(Button.VISIBLE);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
object.offset += object.pagination;
loadMoreEvents(v);
}
});
RelativeLayout content_event_item = (RelativeLayout)view.findViewById(R.id.content_event_item);
content_event_item.setVisibility(RelativeLayout.GONE);
}
}
}
else {
EventListItem item = this.object.eventList.get(position);
switch (item.criticity) {
case 0://Blue
view.setBackgroundColor(Color.parseColor("#CDE2EA"));
break;
case 1://Grey
view.setBackgroundColor(Color.parseColor("#E4E4E4"));
break;
case 2://Green
view.setBackgroundColor(Color.parseColor("#BBFFA4"));
break;
case 3://Yellow
view.setBackgroundColor(Color.parseColor("#F4FFBF"));
break;
case 4://Red
view.setBackgroundColor(Color.parseColor("#FFC0B5"));
break;
default://Grey
view.setBackgroundColor(Color.parseColor("#E4E4E4"));
break;
}
TextView titulo = (TextView)view.findViewById(R.id.agent_name);
if (item.event_type.equals("system")) {
titulo.setText(R.string.system_str);
}
else {
titulo.setText(item.agent_name);
}
TextView descripcion = (TextView)view.findViewById(R.id.event_name);
descripcion.setText(item.event);
TextView timestamp = (TextView)view.findViewById(R.id.timestamp);
timestamp.setText(item.timestamp);
//Show extended info
if (item.opened) {
View viewEventExtended;
viewEventExtended = inflater.inflate(R.layout.item_list_event_extended, null);
TextView text;
if (item.tags.length() != 0) {
text = (TextView)viewEventExtended.findViewById(R.id.tags_text);
text.setText(item.tags);
}
if (item.user_comment.length() != 0) {
text = (TextView)viewEventExtended.findViewById(R.id.comments_text);
text.setText(item.user_comment);
}
if (item.group_name.length() != 0) {
text = (TextView)viewEventExtended.findViewById(R.id.group_text);
text.setText(item.group_name);
setImageGroup(viewEventExtended, item.group_icon, R.id.img_group);
}
else {
//ALL
setImageGroup(viewEventExtended, "world", R.id.img_group);
}
if (item.agent_name.length() != 0) {
View row = viewEventExtended.findViewById(R.id.row_agent);
row.setVisibility(View.VISIBLE);
text = (TextView)viewEventExtended.findViewById(R.id.type_text);
text.setText(item.description_event);
setImageType(viewEventExtended, item.description_image, R.id.img_type);
}
if (item.criticity_name.length() != 0) {
text = (TextView)viewEventExtended.findViewById(R.id.severity_text);
text.setText(item.criticity_name);
setImageType(viewEventExtended, item.criticity_image, R.id.img_severity);
}
LinearLayout itemLinearLayout = (LinearLayout)view.findViewById(R.id.item_linear_layout);
itemLinearLayout.addView(viewEventExtended);
}
}
TextView titulo = (TextView)view.findViewById(R.id.agent_name);
if (item.event_type.equals("system")) {
titulo.setText(R.string.system_str);
}
else {
titulo.setText(item.agent_name);
}
TextView descripcion = (TextView)view.findViewById(R.id.event_name);
descripcion.setText(item.event);
TextView timestamp = (TextView)view.findViewById(R.id.timestamp);
timestamp.setText(item.timestamp);
return view;
}

View File

@ -22,4 +22,6 @@ public class EventListItem {
public String description_image;
public String criticity_name;
public String criticity_image;
public boolean opened;
}

View File

@ -2,8 +2,11 @@ package pandroid_event_viewer.pandorafms;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
@ -16,8 +19,6 @@ import org.apache.http.message.BasicNameValuePair;
import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Region.Op;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
@ -197,6 +198,40 @@ public class Main extends Activity {
this.object.eventList = new ArrayList<EventListItem>();
this.object.loadInProgress = true;
//Get form data
DatePicker datePicker = (DatePicker)findViewById(R.id.date);
TimePicker timePicker = (TimePicker)findViewById(R.id.time);
int day = datePicker.getDayOfMonth();
int month = datePicker.getMonth() + 1;
int year = datePicker.getYear();
int hour = timePicker.getCurrentHour();
int minute = timePicker.getCurrentMinute();
Date date = new Date(year, month, day, minute, hour);
this.object.timestamp = date.getTime() / 1000;
EditText agentName = (EditText) findViewById(R.id.agent_name);
String agentNameStr = agentName.getText().toString();
this.object.id_group = 0;
Spinner combo;
int sel;
combo = (Spinner) findViewById(R.id.group_combo);
String selectedGroup = combo.getSelectedItem().toString();
Iterator it = pandoraGroups.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<Integer, String> e = (Map.Entry<Integer, String>)it.next();
if (e.getValue().equals(selectedGroup)) {
this.object.id_group = e.getKey();
}
}
combo = (Spinner) findViewById(R.id.severity_combo);
this.object.severity = combo.getSelectedItemPosition();
this.object.executeBackgroundGetEvents();
TabActivity ta = (TabActivity) this.getParent();

View File

@ -20,6 +20,7 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.apache.http.HttpEntity;
@ -41,12 +42,26 @@ import android.util.Log;
import android.widget.TabHost;
public class PandroidEventviewerActivity extends TabActivity implements Serializable {
//Data aplication
public ArrayList<EventListItem> eventList;
public long count_events;
//Flags
public boolean loadInProgress;
public boolean getNewListEvents;
//Configuration
public String url;
public String user;
public String password;
//Parameters to search in the API
public String agentNameStr;
public int id_group;
public long timestamp;
public int severity;
public int pagination;
public long offset;
/** Called when the activity is first created. */
@Override
@ -62,6 +77,12 @@ public class PandroidEventviewerActivity extends TabActivity implements Serializ
this.user = preferences.getString("user", "");
this.password = preferences.getString("password", "");
this.timestamp = 1315015715; //= new Date().getTime();
this.pagination = 20;
this.offset = 0;
this.agentNameStr = "";
this.severity = -1;
this.eventList = new ArrayList<EventListItem>();
this.loadInProgress = false;
this.getNewListEvents = true;
@ -75,7 +96,9 @@ public class PandroidEventviewerActivity extends TabActivity implements Serializ
startActivity(i);
}
else {
this.loadInProgress = true;
}
executeBackgroundGetEvents();
@ -108,33 +131,89 @@ public class PandroidEventviewerActivity extends TabActivity implements Serializ
tabHost.getTabWidget().getChildAt(1).getLayoutParams().height=45;
}
public String serializeParams2Api() {
String return_var = "";
return_var += ';'; //Separator for the csv
return_var += "|";
return_var += Integer.toString(this.severity); //Criticity or severity
return_var += "|";
return_var += this.agentNameStr; //The agent name
return_var += "|";
return_var += ""; //Name of module
return_var += "|";
return_var += ""; //Name of alert template
return_var += "|";
return_var += ""; //Id user
return_var += "|";
return_var += Long.toString(this.timestamp); //The minimun timestamp
return_var += "|";
return_var += ""; //The maximum timestamp
return_var += "|";
return_var += Integer.toString(this.pagination); //The pagination of list events
return_var += "|";
return_var += Long.toString(this.offset); //The offset of list events
return return_var;
}
public void getEvents(boolean newEvents) {
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
UrlEncodedFormEntity entity;
HttpPost httpPost;
List<NameValuePair> parameters;
HttpResponse response;
HttpEntity entityResponse;
String return_api;
HttpPost httpPost = new HttpPost(this.url);
httpPost = new HttpPost(this.url);
List<NameValuePair> parameters = new ArrayList<NameValuePair>();
//Get total count.
parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair("user", this.user));
parameters.add(new BasicNameValuePair("pass", this.password));
parameters.add(new BasicNameValuePair("op", "get"));
parameters.add(new BasicNameValuePair("op2", "events"));
parameters.add(new BasicNameValuePair("other_mode", "url_encode_separator_|"));
parameters.add(new BasicNameValuePair("return_type", "csv"));
parameters.add(new BasicNameValuePair("other", ";||||||1315015715||20|1"));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(parameters);
parameters.add(new BasicNameValuePair("other", serializeParams2Api() + "|total"));
entity = new UrlEncodedFormEntity(parameters);
httpPost.setEntity(entity);
response = httpClient.execute(httpPost);
entityResponse = response.getEntity();
return_api = convertStreamToString(entityResponse.getContent());
return_api = return_api.replace("\n", "");
this.count_events = new Long(return_api).longValue();
HttpResponse response = httpClient.execute(httpPost);
HttpEntity entityResponse = response.getEntity();
if (this.count_events == 0) {
return;
}
String return_api = convertStreamToString(entityResponse.getContent());
//Get the list of events.
parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair("user", this.user));
parameters.add(new BasicNameValuePair("pass", this.password));
parameters.add(new BasicNameValuePair("op", "get"));
parameters.add(new BasicNameValuePair("op2", "events"));
parameters.add(new BasicNameValuePair("other_mode", "url_encode_separator_|"));
parameters.add(new BasicNameValuePair("return_type", "csv"));
parameters.add(new BasicNameValuePair("other", serializeParams2Api()));
entity = new UrlEncodedFormEntity(parameters);
httpPost.setEntity(entity);
response = httpClient.execute(httpPost);
entityResponse = response.getEntity();
return_api = convertStreamToString(entityResponse.getContent());
Log.e("return_api", return_api);
String[] lines = return_api.split("\n");
if (return_api.length() == 0) {
return;
}
for (int i= 0; i < lines.length; i++) {
String[] items = lines[i].split(";", 21);
@ -201,6 +280,8 @@ public class PandroidEventviewerActivity extends TabActivity implements Serializ
event.criticity_name = items[19];
event.criticity_image = items[20];
event.opened = false;
this.eventList.add(event);
}
}
@ -258,10 +339,19 @@ public class PandroidEventviewerActivity extends TabActivity implements Serializ
@Override
protected void onPostExecute(Void unused)
{
if (!isFinishing())
{
Intent i = new Intent("eventlist.java");
if (getNewListEvents) {
loadInProgress = false;
getNewListEvents = false;
i.putExtra("load_more", 0);
}
else {
i.putExtra("load_more", 1);
}
getApplicationContext().sendBroadcast(i);
}
}
}