diff --git a/extras/pandroid_event_viewer/AndroidManifest.xml b/extras/pandroid_event_viewer/AndroidManifest.xml
index b05b965d73..50bf81ecd5 100644
--- a/extras/pandroid_event_viewer/AndroidManifest.xml
+++ b/extras/pandroid_event_viewer/AndroidManifest.xml
@@ -34,5 +34,9 @@
+
+
+
+
\ No newline at end of file
diff --git a/extras/pandroid_event_viewer/ChangeLog b/extras/pandroid_event_viewer/ChangeLog
index bfc614eae8..c364eda4c5 100644
--- a/extras/pandroid_event_viewer/ChangeLog
+++ b/extras/pandroid_event_viewer/ChangeLog
@@ -1,3 +1,20 @@
+2011-09-22 Miguel de Dios
+
+ * AndroidManifest.xml: added the lines for the service and broadcastreciver.
+
+ *src/pandroid_event_viewer/pandorafms/PandroidEventviewerActivity.java,
+ src/pandroid_event_viewer/pandorafms/AlarmReceiver.java,
+ src/pandroid_event_viewer/pandorafms/Main.java,
+ src/pandroid_event_viewer/pandorafms/PandroidEventviewerService.java,
+ src/pandroid_event_viewer/pandorafms/Options.java,
+ src/pandroid_event_viewer/pandorafms/EventList.java: wip, added the first
+ version of service to scan in background the event and other fixes and
+ devs.
+
+ * res/values/arrays.xml, res/values/strings.xml, res/values-en/arrays.xml,
+ res/values-en/strings.xml, res/values-es/arrays.xml,
+ res/values-es/strings.xml, res/layout/options.xml: added more const.
+
2011-09-21 Miguel de Dios
* src/pandroid_event_viewer/pandorafms/PandroidEventviewerActivity.java,
diff --git a/extras/pandroid_event_viewer/res/layout/options.xml b/extras/pandroid_event_viewer/res/layout/options.xml
index 49793eb3cc..3f67d2b259 100644
--- a/extras/pandroid_event_viewer/res/layout/options.xml
+++ b/extras/pandroid_event_viewer/res/layout/options.xml
@@ -76,6 +76,20 @@
android:inputType="textPassword"
/>
+
+
+
+
Warning
- Critical
+
+
+
+ - 30 seconds
+ - 1 minute
+ - 5 minutes
+ - 10 minutes
+ - 15 minutes
+ - 30 minutes
+ - 45 minutes
+ - 1 hour
+ - 1 hour and 30 minutes
+ - 2 hours
+ - 3 hours
+ - 4 hours
+ - 6 hours
+ - 8 hours
+ - 10 hours
+ - 12 hours
+ - 24 hours
+ - 36 hours
+ - 48 hours
+
\ No newline at end of file
diff --git a/extras/pandroid_event_viewer/res/values-en/strings.xml b/extras/pandroid_event_viewer/res/values-en/strings.xml
index 09924216ed..b638c8c145 100644
--- a/extras/pandroid_event_viewer/res/values-en/strings.xml
+++ b/extras/pandroid_event_viewer/res/values-en/strings.xml
@@ -45,6 +45,7 @@
Options
Load more events
Empty list events
+ Refresh time watcher
Update configuration successful.
Update configuration is failed.
diff --git a/extras/pandroid_event_viewer/res/values-es/arrays.xml b/extras/pandroid_event_viewer/res/values-es/arrays.xml
index 25a1060c39..195d76e5d4 100644
--- a/extras/pandroid_event_viewer/res/values-es/arrays.xml
+++ b/extras/pandroid_event_viewer/res/values-es/arrays.xml
@@ -24,4 +24,27 @@
- Alerta
- Critico
+
+
+
+ - 30 segundos
+ - 1 minuto
+ - 5 minutos
+ - 10 minutos
+ - 15 minutos
+ - 30 minutos
+ - 45 minutos
+ - 1 hora
+ - 1 hora y 30 minutos
+ - 2 horas
+ - 3 horas
+ - 4 horas
+ - 6 horas
+ - 8 horas
+ - 10 horas
+ - 12 horas
+ - 24 horas
+ - 36 horas
+ - 48 horas
+
\ No newline at end of file
diff --git a/extras/pandroid_event_viewer/res/values-es/strings.xml b/extras/pandroid_event_viewer/res/values-es/strings.xml
index a3403435d3..860db4b553 100644
--- a/extras/pandroid_event_viewer/res/values-es/strings.xml
+++ b/extras/pandroid_event_viewer/res/values-es/strings.xml
@@ -45,6 +45,7 @@
Opciones
Cargar mas eventos
Lista vacia de eventos
+ Refresco scanner eventos
ConfiguraciĆ³n guardada correctamente.
ConfiguraciĆ³n no ha podido guardarse..
diff --git a/extras/pandroid_event_viewer/res/values/arrays.xml b/extras/pandroid_event_viewer/res/values/arrays.xml
index 305bba77dd..e630bf073d 100644
--- a/extras/pandroid_event_viewer/res/values/arrays.xml
+++ b/extras/pandroid_event_viewer/res/values/arrays.xml
@@ -24,4 +24,27 @@
- Warning
- Critical
+
+
+
+ - 30 seconds
+ - 1 minute
+ - 5 minutes
+ - 10 minutes
+ - 15 minutes
+ - 30 minutes
+ - 45 minutes
+ - 1 hour
+ - 1 hour and 30 minutes
+ - 2 hours
+ - 3 hours
+ - 4 hours
+ - 6 hours
+ - 8 hours
+ - 10 hours
+ - 12 hours
+ - 24 hours
+ - 36 hours
+ - 48 hours
+
\ No newline at end of file
diff --git a/extras/pandroid_event_viewer/res/values/strings.xml b/extras/pandroid_event_viewer/res/values/strings.xml
index ebc82b5f97..3c895a0b3c 100644
--- a/extras/pandroid_event_viewer/res/values/strings.xml
+++ b/extras/pandroid_event_viewer/res/values/strings.xml
@@ -48,6 +48,7 @@
Options
Load more events
Empty list events
+ Refresh time watcher
Update configuration successful.
Update configuration is failed.
diff --git a/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/AlarmReceiver.java b/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/AlarmReceiver.java
new file mode 100644
index 0000000000..c31429eb70
--- /dev/null
+++ b/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/AlarmReceiver.java
@@ -0,0 +1,77 @@
+package pandroid_event_viewer.pandorafms;
+
+import android.app.Activity;
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.util.Log;
+
+public class AlarmReceiver extends BroadcastReceiver {
+ public String url;
+ public String user;
+ public String password;
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ // TODO Auto-generated method stub
+ Log.e("OnetimeAlarmReceiver", "onReceive");
+
+ checkNewEvents(context);
+
+ test(context);
+ }
+
+ public void checkNewEvents(Context context) {
+ if (this.url == null) {
+ SharedPreferences preferences = context.getSharedPreferences(
+ context.getString(R.string.const_string_preferences),
+ Activity.MODE_PRIVATE);
+
+ this.url = preferences.getString("url", "");
+ this.user = preferences.getString("user", "");
+ this.password = preferences.getString("password", "");
+
+ Log.e("checkNewEvents", this.url + "," + this.user + "," + this.password);
+ }
+ }
+
+ private static final int HELLO_ID = 1;
+ public void test(Context context) {
+ String ns = Context.NOTIFICATION_SERVICE;
+ NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns);
+
+
+
+ mNotificationManager.cancel(HELLO_ID);
+
+
+
+ int icon = R.drawable.pandorafms_logo;
+ CharSequence tickerText = "Hello";
+ long when = System.currentTimeMillis();
+
+ Notification notification = new Notification(icon, tickerText, when);
+
+
+
+ notification.flags |= Notification.FLAG_AUTO_CANCEL;
+
+
+
+ CharSequence contentTitle = "My notification";
+ CharSequence contentText = "Hello World!";
+ Intent notificationIntent = new Intent(context, Options.class);
+ PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
+
+ notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
+
+
+
+
+ mNotificationManager.notify(HELLO_ID, notification);
+ }
+}
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 897537a3b7..fb5b966263 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
@@ -20,6 +20,7 @@ import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
+import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
@@ -107,6 +108,19 @@ public class EventList extends ListActivity {
inflater.inflate(R.menu.options_menu, menu);
return true;
}
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case R.id.options_button_menu_options:
+ Intent i = new Intent(this, Options.class);
+ i.putExtra("object", this.object);
+
+ startActivity(i);
+ break;
+ }
+
+ return true;
+ }
public void toggleLoadingLayout() {
LinearLayout loadingLayout = (LinearLayout) findViewById(R.id.loading_layout);
diff --git a/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/Main.java b/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/Main.java
index 23c6f8779a..3f4fca72f4 100644
--- a/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/Main.java
+++ b/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/Main.java
@@ -17,7 +17,11 @@ import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import android.app.Activity;
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
import android.app.TabActivity;
+import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
@@ -73,14 +77,14 @@ public class Main extends Activity {
buttonReset.setEnabled(false);
new GetGroupsAsyncTask().execute();
-
- comboSeverity = (Spinner) findViewById(R.id.severity_combo);
- ArrayAdapter adapter = ArrayAdapter.createFromResource(
- this, R.array.severity_array_values, android.R.layout.simple_spinner_item);
- adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
- comboSeverity.setAdapter(adapter);
}
+ comboSeverity = (Spinner) findViewById(R.id.severity_combo);
+ ArrayAdapter adapter = ArrayAdapter.createFromResource(
+ this, R.array.severity_array_values, android.R.layout.simple_spinner_item);
+ adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ comboSeverity.setAdapter(adapter);
+
buttonReset.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -104,7 +108,7 @@ public class Main extends Activity {
HttpPost httpPost = new HttpPost(this.object.url);
- List parameters = new ArrayList(2);
+ List parameters = new ArrayList();
parameters.add(new BasicNameValuePair("user", this.object.user));
parameters.add(new BasicNameValuePair("pass", this.object.password));
parameters.add(new BasicNameValuePair("op", "get"));
@@ -121,6 +125,7 @@ public class Main extends Activity {
HttpEntity entityResponse = response.getEntity();
String return_api = this.object.convertStreamToString(entityResponse.getContent());
+ Log.e("getGroups", return_api);
String[] lines = return_api.split("\n");
@@ -185,6 +190,7 @@ public class Main extends Activity {
switch (item.getItemId()) {
case R.id.options_button_menu_options:
Intent i = new Intent(this, Options.class);
+ //FAIL//i.putExtra("object", object);
startActivity(i);
break;
diff --git a/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/Options.java b/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/Options.java
index c965692f8f..4484556428 100644
--- a/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/Options.java
+++ b/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/Options.java
@@ -2,23 +2,32 @@ package pandroid_event_viewer.pandorafms;
import android.app.Activity;
import android.content.Context;
+import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
+import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
+import android.widget.Spinner;
import android.widget.Toast;
public class Options extends Activity {
+ PandroidEventviewerActivity object;
+
public String url;
public String user;
public String password;
+ public int refreshTimeKey;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ Intent i = getIntent();
+ this.object = (PandroidEventviewerActivity)i.getSerializableExtra("object");
+
setContentView(R.layout.options);
SharedPreferences preferences = getSharedPreferences(
@@ -28,12 +37,20 @@ public class Options extends Activity {
url = preferences.getString("url", "");
user = preferences.getString("user", "");
password = preferences.getString("password", "");
+ refreshTimeKey = preferences.getInt("refreshTimeKey", 3);
EditText text = (EditText) findViewById(R.id.url);
text.setText(url);
text = (EditText) findViewById(R.id.user);
text.setText(user);
+ Spinner combo = (Spinner) findViewById(R.id.refresh_combo);
+ ArrayAdapter adapter = ArrayAdapter.createFromResource(
+ this, R.array.refresh_combo, android.R.layout.simple_spinner_item);
+ adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ combo.setAdapter(adapter);
+ combo.setSelection(refreshTimeKey);
+
final Button buttonSearch = (Button) findViewById(R.id.update_options);
buttonSearch.setOnClickListener(new View.OnClickListener() {
@Override
@@ -58,10 +75,16 @@ public class Options extends Activity {
text = (EditText) findViewById(R.id.password);
editorPreferences.putString("password", text.getText().toString());
+ Spinner combo = (Spinner) findViewById(R.id.refresh_combo);
+ editorPreferences.putInt("refreshTimeKey", combo.getSelectedItemPosition());
+
Context context = this.getApplicationContext();
int duration = Toast.LENGTH_SHORT;
if (editorPreferences.commit()) {
+ //stopService(this.object.intent_service);
+ //startService(this.object.intent_service);
+
Toast toast = Toast.makeText(context, this.getString(R.string.config_update_succesful_str), duration);
toast.show();
}
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 2675621a06..8d6eea771d 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
@@ -62,6 +62,8 @@ public class PandroidEventviewerActivity extends TabActivity implements Serializ
public int severity;
public int pagination;
public long offset;
+
+ public Intent intent_service;
/** Called when the activity is first created. */
@Override
@@ -77,7 +79,8 @@ public class PandroidEventviewerActivity extends TabActivity implements Serializ
this.user = preferences.getString("user", "");
this.password = preferences.getString("password", "");
- this.timestamp = 1315015715; //= new Date().getTime();
+ //this.timestamp = 1315015715;
+ this.timestamp = new Date().getTime() / 1000;
this.pagination = 20;
this.offset = 0;
this.agentNameStr = "";
@@ -92,7 +95,9 @@ public class PandroidEventviewerActivity extends TabActivity implements Serializ
//Check if the preferences is setted, if not show the option activity.
if ((user.length() == 0) && (password.length() == 0)
&& (url.length() == 0)) {
+
Intent i = new Intent(this, Options.class);
+ i.putExtra("object", this);
startActivity(i);
}
@@ -102,6 +107,11 @@ public class PandroidEventviewerActivity extends TabActivity implements Serializ
executeBackgroundGetEvents();
+ //Start the background service for the notifications
+ //Intent intent_service = new Intent(this, PandroidEventviewerService.class);
+ intent_service = new Intent(this, PandroidEventviewerService.class);
+ startService(intent_service);
+
Intent i_main = new Intent(this, Main.class);
i_main.putExtra("object", this);
diff --git a/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/PandroidEventviewerService.java b/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/PandroidEventviewerService.java
new file mode 100644
index 0000000000..7d07f48fec
--- /dev/null
+++ b/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/PandroidEventviewerService.java
@@ -0,0 +1,109 @@
+package pandroid_event_viewer.pandorafms;
+
+import android.app.Activity;
+import android.app.AlarmManager;
+import android.app.PendingIntent;
+import android.app.Service;
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.os.IBinder;
+import android.util.Log;
+
+public class PandroidEventviewerService extends Service {
+ public AlarmManager alarmM;
+ PendingIntent pendingI;
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void onCreate() {
+ Log.e("testService", "onCreate");
+
+ alarmM = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
+
+ Intent intentAlarm = new Intent(this, AlarmReceiver.class);
+ this.pendingI = PendingIntent.getBroadcast(this, 0, intentAlarm, 0);
+
+ alarmM.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), convertRefreshTimeKeyToTime(), this.pendingI);
+ }
+
+ public int convertRefreshTimeKeyToTime() {
+ int returnvar = 60 * 10;
+
+ SharedPreferences preferences = getSharedPreferences(
+ this.getString(R.string.const_string_preferences),
+ Activity.MODE_PRIVATE);
+
+ int refreshTimeKey = preferences.getInt("refreshTimeKey", 3);
+
+ switch (refreshTimeKey) {
+ case 0:
+ returnvar = 30; //30 seconds
+ break;
+ case 1:
+ returnvar = 60; //1 minute
+ break;
+ case 2:
+ returnvar = 60 * 5; //5 minutes
+ break;
+ case 3:
+ returnvar = 60 * 10; //10 minutes
+ break;
+ case 4:
+ returnvar = 60 * 15; //15 minutes
+ break;
+ case 5:
+ returnvar = 60 * 30; //30 minutes
+ break;
+ case 6:
+ returnvar = 60 * 45; //45 minutes
+ break;
+ case 7:
+ returnvar = 3600; //1 hour
+ break;
+ case 8:
+ returnvar = 3600 + (60 * 30); //1 hour and 30 minutes
+ break;
+ case 9:
+ returnvar = 3600 * 2; //2 hours
+ break;
+ case 10:
+ returnvar = 3600 * 3; //3 hours
+ break;
+ case 11:
+ returnvar = 3600 * 4; //4 hours
+ break;
+ case 12:
+ returnvar = 3600 * 6; //6 hours
+ break;
+ case 13:
+ returnvar = 3600 * 8; //8 hours
+ break;
+ case 14:
+ returnvar = 3600 * 10; //10 hours
+ break;
+ case 15:
+ returnvar = 3600 * 12; //12 hours
+ break;
+ case 16:
+ returnvar = 3600 * 24; //24 hours
+ break;
+ case 17:
+ returnvar = 3600 * 36; //36 hours
+ break;
+ case 18:
+ returnvar = 3600 * 48; //48 hours
+ break;
+ }
+
+ return returnvar * 1000;
+ }
+
+ public void onDestroy() {
+ alarmM.cancel(this.pendingI);
+ }
+}