From 710a75e31cf3de875a876999fab5ba9db3dc988d Mon Sep 17 00:00:00 2001 From: santimunin Date: Fri, 24 Aug 2012 21:02:24 +0000 Subject: [PATCH] =?UTF-8?q?2012-08-24=20Santiago=20Mun=C3=ADn=20=20=09*=20src/pandroid=5Fevent=5Fviewer/pandorafms/Co?= =?UTF-8?q?re.java:=20Fixed=20a=20bug=20(possible=20null=20argument=20as?= =?UTF-8?q?=20image).=20=09*=20src/pandroid=5Fevent=5Fviewer/pandorafms/Ev?= =?UTF-8?q?entList.java:=20Create=20incident=20is=20displayed=20as=20a=20d?= =?UTF-8?q?ialog=20=09*=20src/pandroid=5Fevent=5Fviewer/pandorafms/Pandroi?= =?UTF-8?q?dEventviewerActivity.java:=20FIXME=20comment=20removed.=20=09*?= =?UTF-8?q?=20src/pandroid=5Fevent=5Fviewer/pandorafms/CreateIncidentActiv?= =?UTF-8?q?ity.java:=20No=20longer=20needed.=20Removed.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6912 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- extras/pandroid_event_viewer/ChangeLog | 8 +- .../pandorafms/Core.java | 6 +- .../pandorafms/CreateIncidentActivity.java | 144 -------------- .../pandorafms/EventList.java | 182 +++++++++++++++--- .../PandroidEventviewerActivity.java | 1 - 5 files changed, 168 insertions(+), 173 deletions(-) delete mode 100644 extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/CreateIncidentActivity.java diff --git a/extras/pandroid_event_viewer/ChangeLog b/extras/pandroid_event_viewer/ChangeLog index 718951cbc7..4aaa665e71 100644 --- a/extras/pandroid_event_viewer/ChangeLog +++ b/extras/pandroid_event_viewer/ChangeLog @@ -1,4 +1,10 @@ -2012-08-10 Santiago Munín +2012-08-24 Santiago Munín + * 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 * 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. diff --git a/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/Core.java b/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/Core.java index 8000bccc39..244b19fe6d 100644 --- a/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/Core.java +++ b/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/Core.java @@ -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); + } } /** diff --git a/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/CreateIncidentActivity.java b/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/CreateIncidentActivity.java deleted file mode 100644 index 1750a601e6..0000000000 --- a/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/CreateIncidentActivity.java +++ /dev/null @@ -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 true 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 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 { - - @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(); - } - } - } -} \ No newline at end of file diff --git a/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/EventList.java b/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/EventList.java index b945a74285..d1122fd8c6 100644 --- a/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/EventList.java +++ b/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/EventList.java @@ -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 true 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 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 { + + @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(); + } + } + } } \ No newline at end of file diff --git a/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/PandroidEventviewerActivity.java b/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/PandroidEventviewerActivity.java index 1f95370955..72bb5af576 100644 --- a/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/PandroidEventviewerActivity.java +++ b/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/PandroidEventviewerActivity.java @@ -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";