2011-09-23 Miguel de Dios <miguel.dedios@artica.es>

* src/pandroid_event_viewer/pandorafms/AlarmReceiver.java,
	src/pandroid_event_viewer/pandorafms/PandroidEventviewerActivity.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 in the event
	notification, now there are notifications and need that I develop the
	hook to activity list event.
	
	* src/pandroid_event_viewer/pandorafms/Core.java: move some functions to
	this file for use in other class.

	* res/values/strings.xml, res/values-en/strings.xml,
	res/values-es/strings.xml: added more string values. 
	
	* res/drawable-ldpi/criticity_0.png, res/drawable-ldpi/criticity_1.png, 
	res/drawable-ldpi/criticity_2.png, res/drawable-ldpi/criticity_3.png, 
	res/drawable-ldpi/criticity_4.png, res/drawable-ldpi/criticity_default.png:
	added first version of icons for the notifications.
	
	* res/layout/main.xml: added a third button, the filter, to set the actual
	search as filter for the background event watcher.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4996 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2011-09-23 20:53:46 +00:00
parent 09881f2a70
commit 6bf71ab753
18 changed files with 414 additions and 51 deletions

View File

@ -1,3 +1,29 @@
2011-09-23 Miguel de Dios <miguel.dedios@artica.es>
* src/pandroid_event_viewer/pandorafms/AlarmReceiver.java,
src/pandroid_event_viewer/pandorafms/PandroidEventviewerActivity.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 in the event
notification, now there are notifications and need that I develop the
hook to activity list event.
* src/pandroid_event_viewer/pandorafms/Core.java: move some functions to
this file for use in other class.
* res/values/strings.xml, res/values-en/strings.xml,
res/values-es/strings.xml: added more string values.
* res/drawable-ldpi/criticity_0.png, res/drawable-ldpi/criticity_1.png,
res/drawable-ldpi/criticity_2.png, res/drawable-ldpi/criticity_3.png,
res/drawable-ldpi/criticity_4.png, res/drawable-ldpi/criticity_default.png:
added first version of icons for the notifications.
* res/layout/main.xml: added a third button, the filter, to set the actual
search as filter for the background event watcher.
2011-09-22 Miguel de Dios <miguel.dedios@artica.es>
* AndroidManifest.xml: added the lines for the service and broadcastreciver.

Binary file not shown.

After

Width:  |  Height:  |  Size: 576 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 545 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 550 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 536 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 551 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 545 B

View File

@ -118,6 +118,12 @@
android:layout_weight="1"
/>
</LinearLayout>
<Button
android:text="@string/set_as_filter_watcher_button_str"
android:id="@+id/button_set_as_filter_watcher"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
</ScrollView>
</LinearLayout>

View File

@ -46,8 +46,17 @@
<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="set_as_filter_watcher_button_str">Set as filter for watcher</string>
<string name="config_update_succesful_str">Update configuration successful.</string>
<string name="config_update_fail_str">Update configuration is failed.</string>
<string name="please_set_preferences_str">Please set the preferences as the API URL, user and password for your Pandora FMS.</string>
<string name="filter_update_succesful_str">Update filter sucessful.</string>
<string name="filter_update_fail_str">Update filter is failed.</string>
<string name="notification_criticity_0_str">There are %s events and all in Maintenance state.</string>
<string name="notification_criticity_1_str">There are %s events and some are in Informational state.</string>
<string name="notification_criticity_2_str">There are %s events and some are in Normal state.</string>
<string name="notification_criticity_3_str">There are %s events and some are in Warning state.</string>
<string name="notification_criticity_4_str">There are %s events and some are in Critical state.</string>
</resources>

View File

@ -46,8 +46,17 @@
<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="set_as_filter_watcher_button_str">Hacerlo filtro para 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>
<string name="please_set_preferences_str">Por favor configure sus preferencias, como la API URL, usuario y contraseña de su Pandora FMS.</string>
<string name="filter_update_succesful_str">Actualizado filtro correctamente.</string>
<string name="filter_update_fail_str">Actualización filtro no ha podido guardarse.</string>
<string name="notification_criticity_0_str">Hay %s eventos y todos son de Mantenimiento.</string>
<string name="notification_criticity_1_str">Hay %s eventos y algunos son Información.</string>
<string name="notification_criticity_2_str">Hay %s eventos y algunos son Normales.</string>
<string name="notification_criticity_3_str">Hay %s eventos y algunos son Aviso.</string>
<string name="notification_criticity_4_str">Hay %s eventos y algunos son Criticos.</string>
</resources>

View File

@ -16,6 +16,8 @@
-->
<resources>
<!-- CONST -->
<string name="pandroid_event_viewer_str">Pandroid Event Viewer</string>
<string name="const_string_preferences">PANDROID_EVENT_VIEWER_PREFERENCES</string>
<string name="item_tab_main_text">Main</string>
@ -49,8 +51,17 @@
<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="set_as_filter_watcher_button_str">Set as filter for watcher</string>
<string name="config_update_succesful_str">Update configuration successful.</string>
<string name="config_update_fail_str">Update configuration is failed.</string>
<string name="please_set_preferences_str">Please set the preferences as the API URL, ser and password for your Pandora FMS.</string>
<string name="please_set_preferences_str">Please set the preferences as the API URL, user and password for your Pandora FMS.</string>
<string name="filter_update_succesful_str">Update filter successful.</string>
<string name="filter_update_fail_str">Update filter is failed.</string>
<string name="notification_criticity_0_str">There are %s events and all in Maintenance state.</string>
<string name="notification_criticity_1_str">There are %s events and some are in Informational state.</string>
<string name="notification_criticity_2_str">There are %s events and some are in Normal state.</string>
<string name="notification_criticity_3_str">There are %s events and some are in Warning state.</string>
<string name="notification_criticity_4_str">There are %s events and some are in Critical state.</string>
</resources>

View File

@ -1,5 +1,17 @@
package pandroid_event_viewer.pandorafms;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
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;
@ -8,12 +20,17 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.SystemClock;
import android.util.Log;
public class AlarmReceiver extends BroadcastReceiver {
public String url;
public String user;
public String password;
public long count_events;
public int more_criticity;
@Override
public void onReceive(Context context, Intent intent) {
@ -21,8 +38,6 @@ public class AlarmReceiver extends BroadcastReceiver {
Log.e("OnetimeAlarmReceiver", "onReceive");
checkNewEvents(context);
test(context);
}
public void checkNewEvents(Context context) {
@ -35,23 +50,165 @@ public class AlarmReceiver extends BroadcastReceiver {
this.user = preferences.getString("user", "");
this.password = preferences.getString("password", "");
Log.e("checkNewEvents", this.url + "," + this.user + "," + this.password);
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
UrlEncodedFormEntity entity;
HttpPost httpPost;
List<NameValuePair> parameters;
HttpResponse response;
HttpEntity entityResponse;
String return_api;
httpPost = new HttpPost(this.url);
String parametersAPI = serializeParams2Api(context);
//Get total count.
parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair("user", this.user));
parameters.add(new BasicNameValuePair("pass", this.password));
parameters.add(new BasicNameValuePair("op", "get"));
parameters.add(new BasicNameValuePair("op2", "events"));
parameters.add(new BasicNameValuePair("other_mode", "url_encode_separator_|"));
parameters.add(new BasicNameValuePair("return_type", "csv"));
parameters.add(new BasicNameValuePair("other", parametersAPI + "|total"));
entity = new UrlEncodedFormEntity(parameters);
httpPost.setEntity(entity);
response = httpClient.execute(httpPost);
entityResponse = response.getEntity();
return_api = Core.convertStreamToString(entityResponse.getContent());
Log.e("checkNewEvents count", return_api);
return_api = return_api.replace("\n", "");
this.count_events = new Long(return_api).longValue();
//Check the event more critical
if (this.count_events != 0) {
parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair("user", this.user));
parameters.add(new BasicNameValuePair("pass", this.password));
parameters.add(new BasicNameValuePair("op", "get"));
parameters.add(new BasicNameValuePair("op2", "events"));
parameters.add(new BasicNameValuePair("other_mode", "url_encode_separator_|"));
parameters.add(new BasicNameValuePair("return_type", "csv"));
parameters.add(new BasicNameValuePair("other", parametersAPI + "|more_criticity"));
entity = new UrlEncodedFormEntity(parameters);
httpPost.setEntity(entity);
response = httpClient.execute(httpPost);
entityResponse = response.getEntity();
return_api = Core.convertStreamToString(entityResponse.getContent());
Log.e("checkNewEvents criticity", return_api);
return_api = return_api.replace("\n", "");
this.more_criticity = new Integer(return_api).intValue();
notificationEvent(context);
}
else {
this.more_criticity = -1;
}
}
catch (Exception e) {
Log.e("ERROR THE ", e.getMessage());
return;
}
}
}
public String serializeParams2Api(Context context) {
SharedPreferences preferences = context.getSharedPreferences(
context.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
String filterAgentName = preferences.getString("filterAgentName", "");
int filterIDGroup = preferences.getInt("filterIDGroup", 0);
int filterSeverity = preferences.getInt("filterSeverity", -1);
Calendar c = Calendar.getInstance();
long now = (c.getTimeInMillis() / 1000);
long filterTimestamp = preferences.getLong("filterTimestamp", now);
SharedPreferences.Editor editorPreferences = preferences.edit();
editorPreferences.putLong("filterTimestamp", now); //Save for the next execution.
editorPreferences.commit();
String return_var = "";
return_var += ';'; //Separator for the csv
return_var += "|";
return_var += Integer.toString(filterSeverity); //Criticity or severity
return_var += "|";
return_var += filterAgentName; //The agent name
return_var += "|";
return_var += ""; //Name of module
return_var += "|";
return_var += ""; //Name of alert template
return_var += "|";
return_var += ""; //Id user
return_var += "|";
return_var += Long.toString(filterTimestamp); //The minimun timestamp
return_var += "|";
return_var += ""; //The maximum timestamp
return_var += "|";
return_var += Integer.toString(0); //The pagination of list events
return_var += "|";
return_var += Long.toString(0); //The offset of list events
Log.e("serializeParams2Api", return_var);
return return_var;
}
private static final int HELLO_ID = 1;
public void test(Context context) {
private static final int NOTIFICATION_PANDROID_EVENT_VIEWER = 666;
public void notificationEvent(Context context) {
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns);
mNotificationManager.cancel(HELLO_ID);
mNotificationManager.cancel(NOTIFICATION_PANDROID_EVENT_VIEWER);
int icon;
CharSequence tickerText;
switch (this.more_criticity) {
case 0:
icon = R.drawable.criticity_0;
tickerText = context.getString(R.string.notification_criticity_0_str)
.replace("%s", new Long(this.count_events).toString());
break;
case 1:
icon = R.drawable.criticity_1;
tickerText = context.getString(R.string.notification_criticity_1_str)
.replace("%s", new Long(this.count_events).toString());
break;
case 2:
icon = R.drawable.criticity_2;
tickerText = context.getString(R.string.notification_criticity_2_str)
.replace("%s", new Long(this.count_events).toString());
break;
case 3:
icon = R.drawable.criticity_3;
tickerText = context.getString(R.string.notification_criticity_3_str)
.replace("%s", new Long(this.count_events).toString());
break;
case 4:
icon = R.drawable.criticity_4;
tickerText = context.getString(R.string.notification_criticity_4_str)
.replace("%s", new Long(this.count_events).toString());
break;
default:
icon = R.drawable.criticity_default;
tickerText = context.getString(R.string.notification_criticity_2_str)
.replace("%s", new Long(this.count_events).toString());
break;
}
int icon = R.drawable.pandorafms_logo;
CharSequence tickerText = "Hello";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
@ -62,16 +219,16 @@ public class AlarmReceiver extends BroadcastReceiver {
CharSequence contentTitle = "My notification";
CharSequence contentText = "Hello World!";
Intent notificationIntent = new Intent(context, Options.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
CharSequence title = context.getString(R.string.pandroid_event_viewer_str);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
notification.setLatestEventInfo(context, title, tickerText, contentIntent);
mNotificationManager.notify(HELLO_ID, notification);
mNotificationManager.notify(NOTIFICATION_PANDROID_EVENT_VIEWER, notification);
}
}

View File

@ -0,0 +1,95 @@
package pandroid_event_viewer.pandorafms;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import android.content.Context;
import android.content.Intent;
import android.os.Parcel;
import android.os.Parcelable;
public class Core implements Parcelable{
public Intent intent_service;
//public Context context; //Fucking marshall exception
public Core() {
intent_service = null;
//context = null; //Fucking marshall exception
}
public Core(Parcel in) {
intent_service = (Intent)in.readValue(null);
//context = (Context)in.readValue(null); //Fucking marshall exception
}
public void startServiceEventWatcher(Context context) {
if (intent_service == null) {
intent_service = new Intent(context, PandroidEventviewerService.class);
//this.context = context; //Fucking marshall exception
}
context.startService(intent_service);
}
public void stopServiceEventWatcher(Context context) {
context.stopService(this.intent_service);
}
public static final Parcelable.Creator<Core> CREATOR
= new Parcelable.Creator<Core>() {
@Override
public Core createFromParcel(Parcel source) {
// TODO Auto-generated method stub
return new Core(source);
}
@Override
public Core[] newArray(int size) {
// TODO Auto-generated method stub
return new Core[size];
}
};
@Override
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
// TODO Auto-generated method stub
dest.writeValue(this.intent_service);
//dest.writeValue(this.context); //Fucking marshall exception
}
public static String convertStreamToString (InputStream is)
{
BufferedReader reader = new BufferedReader(new
InputStreamReader(is), 8*1024);
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return sb.toString();
}
}

View File

@ -35,7 +35,10 @@ import android.widget.Toast;
public class EventList extends ListActivity {
private ListView lv;
private MyAdapter la;
public PandroidEventviewerActivity object;
public Core core;
public HashMap<Integer, Boolean> openedItem;
public HashMap<String, Bitmap> imgGroups;
public HashMap<String, Bitmap> imgSeverity;
@ -56,6 +59,7 @@ public class EventList extends ListActivity {
Intent i = getIntent();
this.object = (PandroidEventviewerActivity)i.getSerializableExtra("object");
this.core = (Core)i.getParcelableExtra("core");
setContentView(R.layout.list_view_layout);
@ -113,7 +117,8 @@ public class EventList extends ListActivity {
switch (item.getItemId()) {
case R.id.options_button_menu_options:
Intent i = new Intent(this, Options.class);
i.putExtra("object", this.object);
//FAIL//i.putExtra("object", object);
i.putExtra("core", this.core);
startActivity(i);
break;

View File

@ -23,6 +23,7 @@ import android.app.PendingIntent;
import android.app.TabActivity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
@ -43,6 +44,7 @@ public class Main extends Activity {
public PandroidEventviewerActivity object;
public HashMap<Integer, String> pandoraGroups;
public Spinner comboSeverity;
public Core core;
/** Called when the activity is first created. */
@Override
@ -51,6 +53,7 @@ public class Main extends Activity {
Intent i = getIntent();
this.object = (PandroidEventviewerActivity)i.getSerializableExtra("object");
this.core = (Core)i.getParcelableExtra("core");
this.pandoraGroups = new HashMap<Integer, String>();
@ -58,6 +61,7 @@ public class Main extends Activity {
final Button buttonReset = (Button) findViewById(R.id.button_reset);
final Button buttonSearch = (Button) findViewById(R.id.button_send);
final Button buttonbuttonSetAsFilterWatcher = (Button) findViewById(R.id.button_set_as_filter_watcher);
//Check if the user preferences it is set.
if ((object.user.length() == 0) && (object.password.length() == 0)
@ -69,12 +73,14 @@ public class Main extends Activity {
buttonReset.setEnabled(false);
buttonSearch.setEnabled(false);
buttonbuttonSetAsFilterWatcher.setEnabled(false);
}
else {
Spinner combo;
buttonSearch.setEnabled(false);
buttonReset.setEnabled(false);
buttonbuttonSetAsFilterWatcher.setEnabled(false);
new GetGroupsAsyncTask().execute();
}
@ -98,6 +104,15 @@ public class Main extends Activity {
search_form();
}
});
buttonbuttonSetAsFilterWatcher.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
save_filter_watcher();
}
});
}
public ArrayList<String> getGroups() {
@ -124,7 +139,7 @@ public class Main extends Activity {
HttpResponse response = httpClient.execute(httpPost);
HttpEntity entityResponse = response.getEntity();
String return_api = this.object.convertStreamToString(entityResponse.getContent());
String return_api = Core.convertStreamToString(entityResponse.getContent());
Log.e("getGroups", return_api);
String[] lines = return_api.split("\n");
@ -172,9 +187,11 @@ public class Main extends Activity {
Button buttonReset = (Button) findViewById(R.id.button_reset);
Button buttonSearch = (Button) findViewById(R.id.button_send);
Button buttonbuttonSetAsFilterWatcher = (Button) findViewById(R.id.button_set_as_filter_watcher);
buttonReset.setEnabled(true);
buttonSearch.setEnabled(true);
buttonbuttonSetAsFilterWatcher.setEnabled(true);
}
}
@ -191,6 +208,7 @@ public class Main extends Activity {
case R.id.options_button_menu_options:
Intent i = new Intent(this, Options.class);
//FAIL//i.putExtra("object", object);
i.putExtra("core", this.core);
startActivity(i);
break;
@ -244,6 +262,56 @@ public class Main extends Activity {
ta.getTabHost().setCurrentTab(1);
}
public void save_filter_watcher() {
String filterAgentName = "";
int filterIDGroup = 0;
int filterSeverity = -1;
EditText agentName = (EditText) findViewById(R.id.agent_name);
filterAgentName = agentName.getText().toString();
Spinner combo;
combo = (Spinner) findViewById(R.id.group_combo);
String selectedGroup = combo.getSelectedItem().toString();
Iterator it = pandoraGroups.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<Integer, String> e = (Map.Entry<Integer, String>)it.next();
if (e.getValue().equals(selectedGroup)) {
filterIDGroup = e.getKey();
}
}
combo = (Spinner) findViewById(R.id.severity_combo);
filterSeverity = combo.getSelectedItemPosition();
SharedPreferences preferences = getSharedPreferences(
this.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
SharedPreferences.Editor editorPreferences = preferences.edit();
editorPreferences.putString("filterAgentName", filterAgentName);
editorPreferences.putInt("filterIDGroup", filterIDGroup);
editorPreferences.putInt("filterSeverity", filterSeverity);
if (editorPreferences.commit()) {
this.core.stopServiceEventWatcher(getApplicationContext());
this.core.startServiceEventWatcher(getApplicationContext());
Toast toast = Toast.makeText(getApplicationContext(),
this.getString(R.string.filter_update_succesful_str), Toast.LENGTH_SHORT);
toast.show();
}
else {
Toast toast = Toast.makeText(getApplicationContext(),
this.getString(R.string.filter_update_fail_str), Toast.LENGTH_SHORT);
toast.show();
}
}
public void reset_form() {
EditText agentEditText = (EditText)findViewById(R.id.agent_name);
agentEditText.setText("");

View File

@ -14,19 +14,19 @@ 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;
public Core core;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent i = getIntent();
this.object = (PandroidEventviewerActivity)i.getSerializableExtra("object");
this.core = (Core)i.getParcelableExtra("core");
setContentView(R.layout.options);
@ -64,7 +64,6 @@ public class Options extends Activity {
SharedPreferences preferences = getSharedPreferences(
this.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
SharedPreferences.Editor editorPreferences = preferences.edit();
EditText text = (EditText) findViewById(R.id.url);
@ -82,8 +81,8 @@ public class Options extends Activity {
int duration = Toast.LENGTH_SHORT;
if (editorPreferences.commit()) {
//stopService(this.object.intent_service);
//startService(this.object.intent_service);
this.core.stopServiceEventWatcher(getApplicationContext());
this.core.startServiceEventWatcher(getApplicationContext());
Toast toast = Toast.makeText(context, this.getString(R.string.config_update_succesful_str), duration);
toast.show();

View File

@ -64,6 +64,8 @@ public class PandroidEventviewerActivity extends TabActivity implements Serializ
public long offset;
public Intent intent_service;
public Core core;
/** Called when the activity is first created. */
@Override
@ -108,13 +110,12 @@ 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);
this.core = new Core();
this.core.startServiceEventWatcher(getApplicationContext());
Intent i_main = new Intent(this, Main.class);
i_main.putExtra("object", this);
i_main.putExtra("core", this.core);
tabHost.addTab
(
@ -193,7 +194,7 @@ public class PandroidEventviewerActivity extends TabActivity implements Serializ
httpPost.setEntity(entity);
response = httpClient.execute(httpPost);
entityResponse = response.getEntity();
return_api = convertStreamToString(entityResponse.getContent());
return_api = Core.convertStreamToString(entityResponse.getContent());
return_api = return_api.replace("\n", "");
this.count_events = new Long(return_api).longValue();
@ -215,7 +216,7 @@ public class PandroidEventviewerActivity extends TabActivity implements Serializ
response = httpClient.execute(httpPost);
entityResponse = response.getEntity();
return_api = convertStreamToString(entityResponse.getContent());
return_api = Core.convertStreamToString(entityResponse.getContent());
Log.e("return_api", return_api);
String[] lines = return_api.split("\n");
@ -302,30 +303,6 @@ public class PandroidEventviewerActivity extends TabActivity implements Serializ
}
}
public String convertStreamToString (InputStream is)
{
BufferedReader reader = new BufferedReader(new
InputStreamReader(is), 8*1024);
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return sb.toString();
}
public void executeBackgroundGetEvents() {
new GetEventsAsyncTask().execute();
}

View File

@ -104,6 +104,7 @@ public class PandroidEventviewerService extends Service {
}
public void onDestroy() {
Log.e("testService", "onDestroy");
alarmM.cancel(this.pendingI);
}
}