From 1fcb387ac7c65c1cd3a83a91562f43798d1d4fe3 Mon Sep 17 00:00:00 2001 From: santimunin Date: Thu, 13 Sep 2012 17:28:04 +0000 Subject: [PATCH] =?UTF-8?q?2012-09-13=20Santiago=20Mun=C3=ADn=20=20=09*=20src/pandroid=5Fevent=5Fviewer/pandorafms/Ev?= =?UTF-8?q?entList.java:=20Now,=20if=20an=20element=20is=20validated,=20hi?= =?UTF-8?q?s=20color=20changes=20to=20green.=20=09*=20src/pandroid=5Fevent?= =?UTF-8?q?=5Fviewer/pandorafms/PopupValidationEvent.java:=20Now=20it=20re?= =?UTF-8?q?turns=20a=20result=20(validated=20or=20not)=20which=20will=20be?= =?UTF-8?q?=20processed=20for=20the=20activity=20which=20called=20it.=20?= =?UTF-8?q?=09*=20res/values/colors.xml:=20Added=20colors=20to=20values=20?= =?UTF-8?q?instead=20of=20hardcoding=20them.?= 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@6973 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- extras/pandroid_event_viewer/ChangeLog | 5 ++ .../res/values/colors.xml | 23 ++++++ .../pandorafms/EventList.java | 78 +++++++++++++------ .../pandorafms/PopupValidationEvent.java | 30 ++----- 4 files changed, 90 insertions(+), 46 deletions(-) create mode 100644 extras/pandroid_event_viewer/res/values/colors.xml diff --git a/extras/pandroid_event_viewer/ChangeLog b/extras/pandroid_event_viewer/ChangeLog index b7a5c28aef..c52311ce97 100644 --- a/extras/pandroid_event_viewer/ChangeLog +++ b/extras/pandroid_event_viewer/ChangeLog @@ -1,3 +1,8 @@ +2012-09-13 Santiago Munín + * src/pandroid_event_viewer/pandorafms/EventList.java: Now, if an element is validated, his color changes to green. + * src/pandroid_event_viewer/pandorafms/PopupValidationEvent.java: Now it returns a result (validated or not) which will be processed for the activity which called it. + * res/values/colors.xml: Added colors to values instead of hardcoding them. + 2012-09-13 Miguel de Dios * res/drawable-ldpi/criticity_0.png, diff --git a/extras/pandroid_event_viewer/res/values/colors.xml b/extras/pandroid_event_viewer/res/values/colors.xml new file mode 100644 index 0000000000..33b613dac5 --- /dev/null +++ b/extras/pandroid_event_viewer/res/values/colors.xml @@ -0,0 +1,23 @@ + + + + #BBFFA4 + #CDE2EA + #E4E4E4 + #F4FFBF + #FFC0B5 + \ 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 e30b991254..16138982e2 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 @@ -28,7 +28,6 @@ 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; @@ -63,12 +62,14 @@ public class EventList extends ListActivity { private static int DEFAULT_PRIORITY_CODE = 0; private static String DEFAULT_SOURCE = "Pandora FMS Event"; private static final int CREATE_INCIDENT_DIALOG = 1; + private static final int VALIDATE_EVENT_ACTIVITY = 0; private ListView lv; private MyAdapter la; private PandroidEventviewerActivity object; private BroadcastReceiver onBroadcast; private Dialog creatingIncidentDialog; private Context context = this; + private View currentElement; @Override public void onCreate(Bundle savedInstanceState) { @@ -232,8 +233,10 @@ public class EventList extends ListActivity { context, "", getString(R.string.creating_incident), true); - String title = titleEditText.getText().toString(); - String description = descriptionEditText.getText().toString(); + String title = titleEditText.getText() + .toString(); + String description = descriptionEditText + .getText().toString(); new SetNewIncidentAsyncTask().execute(title, description, group); } else { @@ -292,6 +295,25 @@ public class EventList extends ListActivity { object.executeBackgroundGetEvents(true); } + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + if (requestCode == VALIDATE_EVENT_ACTIVITY) { + if (resultCode == RESULT_OK) { + String text; + if (data.getExtras().getBoolean("validated")) { + currentElement.setBackgroundColor(getResources().getColor( + R.color.Green)); + text = getApplicationContext().getString( + R.string.successful_validate_event_str); + } else { + text = getApplicationContext().getString( + R.string.fail_validate_event_str); + } + Toast.makeText(getApplicationContext(), text, + Toast.LENGTH_SHORT).show(); + } + } + } + /** * Private adapter (event list). * @@ -375,23 +397,29 @@ public class EventList extends ListActivity { switch (item.criticity) { - case 0:// Blue - view.setBackgroundColor(Color.parseColor("#CDE2EA")); + case 0: + view.setBackgroundColor(getResources().getColor( + R.color.Blue)); break; - case 1:// Grey - view.setBackgroundColor(Color.parseColor("#E4E4E4")); + case 1: + view.setBackgroundColor(getResources().getColor( + R.color.Grey)); break; - case 2:// Green - view.setBackgroundColor(Color.parseColor("#BBFFA4")); + case 2: + view.setBackgroundColor(getResources().getColor( + R.color.Green)); break; - case 3:// Yellow - view.setBackgroundColor(Color.parseColor("#F4FFBF")); + case 3: + view.setBackgroundColor(getResources().getColor( + R.color.Yellow)); break; - case 4:// Red - view.setBackgroundColor(Color.parseColor("#FFC0B5")); + case 4: + view.setBackgroundColor(getResources() + .getColor(R.color.Red)); break; - default:// Grey - view.setBackgroundColor(Color.parseColor("#E4E4E4")); + default: + view.setBackgroundColor(getResources().getColor( + R.color.Grey)); break; } @@ -457,8 +485,9 @@ public class EventList extends ListActivity { } if (item.user_comment.length() != 0) { - if (item.user_comment.length()> 200) { - item.user_comment = item.user_comment.substring(0, 197); + if (item.user_comment.length() > 200) { + item.user_comment = item.user_comment.substring(0, + 197); item.user_comment = item.user_comment.concat("..."); } text = (TextView) viewEventExtended @@ -524,8 +553,9 @@ public class EventList extends ListActivity { text.setText(""); text.setVisibility(TextView.VISIBLE); } else if (item.status != 1) { - OnClickListenerButtonValidate clickListener = new OnClickListenerButtonValidate(); - clickListener.id_event = item.id_event; + currentElement = view; + OnClickListenerButtonValidate clickListener = new OnClickListenerButtonValidate( + item.id_event); button.setOnClickListener(clickListener); text = (TextView) viewEventExtended .findViewById(R.id.validate_event_label); @@ -643,13 +673,17 @@ public class EventList extends ListActivity { * */ private class OnClickListenerButtonValidate implements OnClickListener { - public int id_event; + private int idEvent; + + public OnClickListenerButtonValidate(int idEvent) { + this.idEvent = idEvent; + } public void onClick(View v) { Intent i = new Intent(getApplicationContext(), PopupValidationEvent.class); - i.putExtra("id_event", id_event); - startActivity(i); + i.putExtra("id_event", idEvent); + startActivityForResult(i, VALIDATE_EVENT_ACTIVITY); } } } diff --git a/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/PopupValidationEvent.java b/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/PopupValidationEvent.java index 3574f7c7c7..872e1d8acf 100644 --- a/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/PopupValidationEvent.java +++ b/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/PopupValidationEvent.java @@ -26,7 +26,6 @@ import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.ProgressBar; -import android.widget.Toast; /** * Provides the functionality necessary to validate an event. @@ -73,14 +72,7 @@ public class PopupValidationEvent extends Activity { } /** - * Finish the activity - */ - private void destroyPopup() { - finish(); - } - - /** - * Sends a validation (async task) + * Sends a validation request (async task) * * @author Miguel de Dios Matías * @@ -90,7 +82,6 @@ public class PopupValidationEvent extends Activity { private boolean connectionProblem = false; - @Override protected Boolean doInBackground(Void... params) { int idEvent = Integer.valueOf(id_event); try { @@ -100,26 +91,17 @@ public class PopupValidationEvent extends Activity { connectionProblem = true; return false; } + } - @Override protected void onPostExecute(Boolean result) { - String text; if (connectionProblem) { Core.showConnectionProblemToast(getApplicationContext(), true); } else { - if (result) { - text = getApplicationContext().getString( - R.string.successful_validate_event_str); - } else { - text = getApplicationContext().getString( - R.string.fail_validate_event_str); - } - - Toast toast = Toast.makeText(getApplicationContext(), text, - Toast.LENGTH_SHORT); - toast.show(); - destroyPopup(); + Intent resultIntent = new Intent(); + resultIntent.putExtra("validated", result); + setResult(RESULT_OK, resultIntent); + finish(); } } }