2011-09-22 Miguel de Dios <miguel.dedios@artica.es>
* 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. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4987 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
497518132f
commit
e6370655dd
|
@ -34,5 +34,9 @@
|
|||
<activity android:name=".Main"></activity>
|
||||
<activity android:name=".EventList"></activity>
|
||||
<activity android:name=".Options" android:label="@string/option_title_str"></activity>
|
||||
|
||||
<service android:name=".PandroidEventviewerService"></service>
|
||||
|
||||
<receiver android:process=":remote" android:name=".AlarmReceiver"></receiver>
|
||||
</application>
|
||||
</manifest>
|
|
@ -1,3 +1,20 @@
|
|||
2011-09-22 Miguel de Dios <miguel.dedios@artica.es>
|
||||
|
||||
* 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 <miguel.dedios@artica.es>
|
||||
|
||||
* src/pandroid_event_viewer/pandorafms/PandroidEventviewerActivity.java,
|
||||
|
|
|
@ -76,6 +76,20 @@
|
|||
android:inputType="textPassword"
|
||||
/>
|
||||
</TableRow>
|
||||
<TableRow>
|
||||
<TextView
|
||||
android:textColor="#ffffff"
|
||||
android:text="@string/refresh_time_label_str"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingRight="5dip"
|
||||
/>
|
||||
<Spinner
|
||||
android:id="@+id/refresh_combo"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
</TableRow>
|
||||
</TableLayout>
|
||||
<Button
|
||||
android:id="@+id/update_options"
|
||||
|
|
|
@ -24,4 +24,27 @@
|
|||
<item>Warning</item>
|
||||
<item>Critical</item>
|
||||
</string-array>
|
||||
|
||||
<!-- Please change the code in the function convertRefreshTimeKeyToTime -->
|
||||
<string-array name="refresh_combo">
|
||||
<item>30 seconds</item>
|
||||
<item>1 minute</item>
|
||||
<item>5 minutes</item>
|
||||
<item>10 minutes</item>
|
||||
<item>15 minutes</item>
|
||||
<item>30 minutes</item>
|
||||
<item>45 minutes</item>
|
||||
<item>1 hour</item>
|
||||
<item>1 hour and 30 minutes</item>
|
||||
<item>2 hours</item>
|
||||
<item>3 hours</item>
|
||||
<item>4 hours</item>
|
||||
<item>6 hours</item>
|
||||
<item>8 hours</item>
|
||||
<item>10 hours</item>
|
||||
<item>12 hours</item>
|
||||
<item>24 hours</item>
|
||||
<item>36 hours</item>
|
||||
<item>48 hours</item>
|
||||
</string-array>
|
||||
</resources>
|
|
@ -45,6 +45,7 @@
|
|||
<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="refresh_time_label_str">Refresh time watcher</string>
|
||||
|
||||
<string name="config_update_succesful_str">Update configuration successful.</string>
|
||||
<string name="config_update_fail_str">Update configuration is failed.</string>
|
||||
|
|
|
@ -24,4 +24,27 @@
|
|||
<item>Alerta</item>
|
||||
<item>Critico</item>
|
||||
</string-array>
|
||||
|
||||
<!-- Please change the code in the function convertRefreshTimeKeyToTime -->
|
||||
<string-array name="refresh_combo">
|
||||
<item>30 segundos</item>
|
||||
<item>1 minuto</item>
|
||||
<item>5 minutos</item>
|
||||
<item>10 minutos</item>
|
||||
<item>15 minutos</item>
|
||||
<item>30 minutos</item>
|
||||
<item>45 minutos</item>
|
||||
<item>1 hora</item>
|
||||
<item>1 hora y 30 minutos</item>
|
||||
<item>2 horas</item>
|
||||
<item>3 horas</item>
|
||||
<item>4 horas</item>
|
||||
<item>6 horas</item>
|
||||
<item>8 horas</item>
|
||||
<item>10 horas</item>
|
||||
<item>12 horas</item>
|
||||
<item>24 horas</item>
|
||||
<item>36 horas</item>
|
||||
<item>48 horas</item>
|
||||
</string-array>
|
||||
</resources>
|
|
@ -45,6 +45,7 @@
|
|||
<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="refresh_time_label_str">Refresco scanner 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>
|
||||
|
|
|
@ -24,4 +24,27 @@
|
|||
<item>Warning</item>
|
||||
<item>Critical</item>
|
||||
</string-array>
|
||||
|
||||
<!-- Please change the code in the function convertRefreshTimeKeyToTime -->
|
||||
<string-array name="refresh_combo">
|
||||
<item>30 seconds</item>
|
||||
<item>1 minute</item>
|
||||
<item>5 minutes</item>
|
||||
<item>10 minutes</item>
|
||||
<item>15 minutes</item>
|
||||
<item>30 minutes</item>
|
||||
<item>45 minutes</item>
|
||||
<item>1 hour</item>
|
||||
<item>1 hour and 30 minutes</item>
|
||||
<item>2 hours</item>
|
||||
<item>3 hours</item>
|
||||
<item>4 hours</item>
|
||||
<item>6 hours</item>
|
||||
<item>8 hours</item>
|
||||
<item>10 hours</item>
|
||||
<item>12 hours</item>
|
||||
<item>24 hours</item>
|
||||
<item>36 hours</item>
|
||||
<item>48 hours</item>
|
||||
</string-array>
|
||||
</resources>
|
|
@ -48,6 +48,7 @@
|
|||
<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="refresh_time_label_str">Refresh time watcher</string>
|
||||
|
||||
<string name="config_update_succesful_str">Update configuration successful.</string>
|
||||
<string name="config_update_fail_str">Update configuration is failed.</string>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -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<NameValuePair> parameters = new ArrayList<NameValuePair>(2);
|
||||
List<NameValuePair> parameters = new ArrayList<NameValuePair>();
|
||||
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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue