2012-08-24 Santiago Munín <burning1@gmail.com>

* src/pandroid_event_viewer/pandorafms/Core.java: Fixed a bug (possible null argument as image).
	* src/pandroid_event_viewer/pandorafms/EventList.java: Create incident is displayed as a dialog
	* src/pandroid_event_viewer/pandorafms/PandroidEventviewerActivity.java: FIXME comment removed.
	* src/pandroid_event_viewer/pandorafms/CreateIncidentActivity.java: No longer needed. Removed.


git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6912 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
santimunin 2012-08-24 21:02:24 +00:00
parent bbeccb9726
commit 710a75e31c
5 changed files with 168 additions and 173 deletions

View File

@ -1,4 +1,10 @@
2012-08-10 Santiago Munín <burning1@gmail.com>
2012-08-24 Santiago Munín <burning1@gmail.com>
* src/pandroid_event_viewer/pandorafms/Core.java: Fixed a bug (possible null argument as image).
* src/pandroid_event_viewer/pandorafms/EventList.java: Create incident is displayed as a dialog
* src/pandroid_event_viewer/pandorafms/PandroidEventviewerActivity.java: FIXME comment removed.
* src/pandroid_event_viewer/pandorafms/CreateIncidentActivity.java: No longer needed. Removed.
2012-08-24 Santiago Munín <burning1@gmail.com>
* src/pandroid_event_viewer/pandorafms/Options.java: Fixed a little bug with the connection status textview.
* res/layout/options.xml: Connection status textview now has a fixed width.
* res/values/strings.xml: Added an entry.

View File

@ -463,8 +463,10 @@ public class Core {
*/
public static void setTextViewLeftImage(TextView view, Drawable image,
int size) {
image.setBounds(0, 0, size, size);
view.setCompoundDrawables(image, null, null, null);
if (image != null) {
image.setBounds(0, 0, size, size);
view.setCompoundDrawables(image, null, null, null);
}
}
/**

View File

@ -1,144 +0,0 @@
package pandroid_event_viewer.pandorafms;
import java.io.IOException;
import java.util.Map.Entry;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
/**
* Allows user to create an incident.
*
* @author Santiago Munín González
*
*/
public class CreateIncidentActivity extends Activity {
private static String TAG = "CreateIncidentActivity";
private static int DEFAULT_STATUS_CODE = 0;
private static int DEFAULT_PRIORITY_CODE = 0;
private static String DEFAULT_SOURCE = "Pandora FMS Event";
private EditText title, description;
private ProgressDialog dialog;
private String eventTitle, eventDescription, eventGroup;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle extras = getIntent().getExtras();
if (extras != null) {
eventTitle = extras.getString("title");
eventDescription = extras.getString("description");
eventGroup = extras.getString("group");
}
setContentView(R.layout.create_incident);
initializeViews();
resetViews();
}
/**
* Initializes views.
*/
private void initializeViews() {
title = (EditText) findViewById(R.id.incident_title);
description = (EditText) findViewById(R.id.incident_description);
((Button) findViewById(R.id.incident_create_button))
.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (title != null && title.length() > 0) {
dialog = ProgressDialog
.show(CreateIncidentActivity.this,
"",
getString(R.string.creating_incident),
true);
new SetNewIncidentAsyncTask().execute((Void) null);
} else {
Toast.makeText(getApplicationContext(),
R.string.title_empty, Toast.LENGTH_SHORT)
.show();
}
}
});
}
/**
* Resets views.
*/
private void resetViews() {
title.setText(eventTitle);
description.setText(eventDescription);
}
/**
* Performs the create incident petition.
*
* @return <b>true</b> if it is created.
* @throws IOException
* If there is a problem with the connection.
*/
private void sendNewIncident() throws IOException {
Log.i(TAG, "Sending new incident");
String incidentParams[] = new String[6];
incidentParams[0] = title.getText().toString();
incidentParams[1] = description.getText().toString();
incidentParams[2] = String.valueOf(DEFAULT_SOURCE);
incidentParams[3] = String.valueOf(DEFAULT_PRIORITY_CODE);
incidentParams[4] = String.valueOf(DEFAULT_STATUS_CODE);
int groupCode = -1;
for (Entry<Integer, String> entry : API.getGroups(
getApplicationContext()).entrySet()) {
if (entry.getValue().equals(eventGroup)) {
groupCode = entry.getKey();
}
}
if (groupCode >= 0) {
incidentParams[5] = String.valueOf(groupCode);
}
API.createNewIncident(getApplicationContext(), incidentParams);
}
/**
* Performs the api call to add the new incident
*
* @author Santiago Munín González
*
*/
private class SetNewIncidentAsyncTask extends
AsyncTask<Void, Void, Boolean> {
@Override
protected Boolean doInBackground(Void... params) {
try {
sendNewIncident();
return true;
} catch (IOException e) {
return false;
}
}
@Override
protected void onPostExecute(Boolean result) {
if (result) {
Toast.makeText(getApplicationContext(),
R.string.incident_created, Toast.LENGTH_SHORT).show();
dialog.dismiss();
finish();
} else {
Toast.makeText(getApplicationContext(),
R.string.create_incident_group_error,
Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
}
}
}

View File

@ -16,18 +16,24 @@ GNU General Public License for more details.
*/
package pandroid_event_viewer.pandorafms;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Map.Entry;
import android.app.Dialog;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@ -37,10 +43,12 @@ import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
/**
* Activity where events are displayed.
@ -49,11 +57,18 @@ import android.widget.TextView;
*
*/
public class EventList extends ListActivity {
private static String TAG = "EventList";
private static int DEFAULT_STATUS_CODE = 0;
private static int DEFAULT_PRIORITY_CODE = 0;
private static String DEFAULT_SOURCE = "Pandora FMS Event";
private static final int CREATE_INCIDENT_DIALOG = 1;
private ListView lv;
private MyAdapter la;
private PandroidEventviewerActivity object;
private BroadcastReceiver onBroadcast;
private Dialog creatingIncidentDialog;
private Context context = this;
@Override
public void onCreate(Bundle savedInstanceState) {
@ -179,6 +194,60 @@ public class EventList extends ListActivity {
return true;
}
@Override
protected Dialog onCreateDialog(int id, Bundle args) {
switch (id) {
case CREATE_INCIDENT_DIALOG:
final String group;
Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.create_incident);
dialog.setTitle(getString(R.string.create_incident));
final EditText titleEditText = (EditText) dialog
.findViewById(R.id.incident_title);
final EditText descriptionEditText = (EditText) dialog
.findViewById(R.id.incident_description);
String temp = args.getString("title");
if (temp != null) {
titleEditText.setText(temp);
}
temp = args.getString("description");
if (temp != null) {
descriptionEditText.setText(temp);
}
temp = args.getString("group");
if (temp != null) {
group = temp;
} else {
group = "";
}
dialog.findViewById(R.id.incident_create_button)
.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (titleEditText != null
&& titleEditText.length() > 0) {
creatingIncidentDialog = ProgressDialog.show(
context, "",
getString(R.string.creating_incident),
true);
String title = titleEditText.getText().toString();
String description = descriptionEditText.getText().toString();
new SetNewIncidentAsyncTask().execute(title,
description, group);
} else {
Toast.makeText(getApplicationContext(),
R.string.title_empty,
Toast.LENGTH_SHORT).show();
}
}
});
return dialog;
}
return null;
}
/**
* Shows loading information.
*/
@ -202,12 +271,12 @@ public class EventList extends ListActivity {
super.onListItemClick(l, v, position, id);
try {
EventListItem item = this.object.eventList.get(position);
item.opened = !item.opened;
this.object.eventList.set(position, item);
la.notifyDataSetChanged();
EventListItem item = this.object.eventList.get(position);
item.opened = !item.opened;
this.object.eventList.set(position, item);
la.notifyDataSetChanged();
} catch (IndexOutOfBoundsException e) {
}
}
@ -240,19 +309,19 @@ public class EventList extends ListActivity {
this.object = object;
showLoadingEvents = false;
}
public int getCount() {
return this.object.eventList.size() + 1;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
public View getView(int position, View convertView, ViewGroup parent) {
View view;
@ -289,7 +358,7 @@ public class EventList extends ListActivity {
}
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
object.offset += object.pagination;
loadMoreEvents();
@ -343,7 +412,8 @@ 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
Core.setTextViewLeftImage((TextView) view
.findViewById(R.id.event_name), Core
.getSeverityImage(getApplicationContext(),
item.criticity), 16);
@ -416,8 +486,9 @@ public class EventList extends ListActivity {
}
Core.setTextViewLeftImage((TextView) viewEventExtended
.findViewById(R.id.type_text),
Core.getEventTypeImage(getApplicationContext(), item.event_type), 16);
.findViewById(R.id.type_text), Core
.getEventTypeImage(getApplicationContext(),
item.event_type), 16);
text = (TextView) viewEventExtended
.findViewById(R.id.type_text);
@ -458,17 +529,14 @@ public class EventList extends ListActivity {
((Button) viewEventExtended
.findViewById(R.id.create_incident_button))
.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(
getBaseContext(),
CreateIncidentActivity.class);
intent.putExtra("group",
item.group_name);
intent.putExtra("title", item.event);
intent.putExtra("description",
Bundle b = new Bundle();
b.putString("group", item.group_name);
b.putString("title", item.event);
b.putString("description",
item.description_event);
startActivity(intent);
showDialog(CREATE_INCIDENT_DIALOG, b);
}
});
} else {
@ -555,7 +623,7 @@ public class EventList extends ListActivity {
mPosition = position;
this.object = object;
}
public void onClick(View arg0) {
EventListItem item = this.object.eventList.get(mPosition);
item.opened = !item.opened;
@ -572,7 +640,7 @@ public class EventList extends ListActivity {
*/
private class OnClickListenerButtonValidate implements OnClickListener {
public int id_event;
public void onClick(View v) {
Intent i = new Intent(getApplicationContext(),
PopupValidationEvent.class);
@ -581,4 +649,68 @@ public class EventList extends ListActivity {
}
}
}
/**
* Performs the create incident petition.
*
* @return <b>true</b> if it is created.
* @throws IOException
* If there is a problem with the connection.
*/
private void sendNewIncident(String title, String description, String group)
throws IOException {
Log.i(TAG, "Sending new incident");
String incidentParams[] = new String[6];
incidentParams[0] = title;
incidentParams[1] = description;
incidentParams[2] = String.valueOf(DEFAULT_SOURCE);
incidentParams[3] = String.valueOf(DEFAULT_PRIORITY_CODE);
incidentParams[4] = String.valueOf(DEFAULT_STATUS_CODE);
int groupCode = -1;
for (Entry<Integer, String> entry : API.getGroups(
getApplicationContext()).entrySet()) {
if (entry.getValue().equals(group)) {
groupCode = entry.getKey();
}
}
if (groupCode >= 0) {
incidentParams[5] = String.valueOf(groupCode);
}
API.createNewIncident(getApplicationContext(), incidentParams);
}
/**
* Performs the api call to add the new incident
*
* @author Santiago Munín González
*
*/
private class SetNewIncidentAsyncTask extends
AsyncTask<String, Void, Boolean> {
@Override
protected Boolean doInBackground(String... params) {
try {
sendNewIncident(params[0], params[1], params[2]);
return true;
} catch (IOException e) {
return false;
}
}
@Override
protected void onPostExecute(Boolean result) {
if (result) {
Toast.makeText(getApplicationContext(),
R.string.incident_created, Toast.LENGTH_SHORT).show();
creatingIncidentDialog.dismiss();
finish();
} else {
Toast.makeText(getApplicationContext(),
R.string.create_incident_group_error,
Toast.LENGTH_SHORT).show();
creatingIncidentDialog.dismiss();
}
}
}
}

View File

@ -40,7 +40,6 @@ import android.util.Log;
import android.widget.BaseAdapter;
import android.widget.TabHost;
import android.widget.Toast;
//FIXME grey buttons doesn't become white when connection is correctly set
public class PandroidEventviewerActivity extends TabActivity implements
Serializable {
private static String TAG = "PandroidEventviewerActivity";