2012-05-12 Santiago Munín <burning1@gmail.com>

* Licenses and javadoc comments added to all files, refactorized code.
       
    * Main.java: fixed a bug which was making the app crash when "Reset" button was clicked.
    
    * res/drawable-ldpi/help.png,
      res/drawable-ldpi/cross.png,
      res/drawable-ldpi/ok.png,
      res/values/styles.xml: Added in order to build the new notification options' UI.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6298 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
santimunin 2012-05-14 11:59:53 +00:00
parent f220046f1e
commit fc4e7ab23f
21 changed files with 2715 additions and 2088 deletions

View File

@ -3,5 +3,6 @@
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="output" path="bin"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>

View File

@ -18,7 +18,11 @@
package="pandroid_event_viewer.pandorafms"
android:versionCode="2"
android:versionName="1.1" >
<uses-sdk android:minSdkVersion="8" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
@ -29,61 +33,60 @@
two things.
-->
<application android:icon="@drawable/pandorafms_logo"
android:label="Pandroid Event viewer"
<application
android:description="@string/pandroid_event_viewer_description_str"
>
android:icon="@drawable/pandorafms_logo"
android:label="Pandroid Event viewer" >
<activity
android:name=".PandroidEventviewerActivity"
android:label="Pandroid Event viewer"
android:theme="@android:style/Theme.NoTitleBar"
android:configChanges="orientation|keyboardHidden"
>
android:label="Pandroid Event viewer"
android:theme="@android:style/Theme.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Main"
android:configChanges="orientation|keyboardHidden"
>
android:configChanges="orientation|keyboardHidden" >
</activity>
<activity
android:name=".EventList"
android:configChanges="orientation|keyboardHidden"
>
android:configChanges="orientation|keyboardHidden" >
</activity>
<activity
android:name=".Options"
android:label="@string/option_title_str"
android:configChanges="orientation|keyboardHidden"
>
android:label="@string/option_title_str" >
</activity>
<activity
android:name=".About"
android:label="@string/pandroid_event_viewer_str"
android:configChanges="orientation|keyboardHidden"
android:theme="@android:style/Theme.Dialog"
>
android:label="@string/pandroid_event_viewer_str"
android:theme="@android:style/Theme.Dialog" >
</activity>
<activity
android:name=".PopupValidationEvent"
android:label="@string/validate_event_button_str"
android:theme="@android:style/Theme.Dialog"
android:configChanges="orientation|keyboardHidden"
>
android:label="@string/validate_event_button_str"
android:theme="@android:style/Theme.Dialog" >
</activity>
<activity
android:name=".Info"
android:label="@string/pandroid_event_viewer_str"
android:configChanges="orientation|keyboardHidden"
android:theme="@android:style/Theme.Dialog"
>
android:label="@string/pandroid_event_viewer_str"
android:theme="@android:style/Theme.Dialog" >
</activity>
<service android:name=".PandroidEventviewerService"></service>
<service android:name=".PandroidEventviewerService" >
</service>
<receiver android:process=":remote" android:name=".AlarmReceiver"></receiver>
<receiver
android:name=".AlarmReceiver"
android:process=":remote" >
</receiver>
</application>
</manifest>

View File

@ -1,3 +1,22 @@
2012-05-12 Santiago Munín <burning1@gmail.com>
* Licenses and javadoc comments added to all files, refactorized code.
* Main.java: fixed a bug which was making the app crash when "Reset" button was clicked.
* res/drawable-ldpi/help.png,
res/drawable-ldpi/cross.png,
res/drawable-ldpi/ok.png,
res/values/styles.xml: Added in order to build the new notification options' UI.
2012-05-08 Santiago Munín <burning1@gmail.com>
* Options.java: Fixed a null pointer bug which was making the
app crash when accessing the options.
* Main.java: Fixed a null pointer bug which crash at the beginning
of the app.
2012-12-27 Miguel de Dios <miguel.dedios@artica.es>
* AndroidManifest.xml,
@ -12,8 +31,6 @@
res/values-es/strings.xml,res/layout/info.xml: fixed some things and
added more stability and a pretty splashscreen.
MERGED FROM BRANCH 4.0.2
2012-04-25 Miguel de Dios <miguel.dedios@artica.es>
Apply patch from user Santiago Munín González <burning1@gmail.com>
@ -23,8 +40,6 @@
Fixes: #3495038
MERGED FROM BRANCH 4.0.2
2011-10-24 Miguel de Dios <miguel.dedios@artica.es>
* AndroidManifest.xml: update num version.

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -14,166 +14,142 @@
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ScrollView
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
android:orientation="vertical" >
<TextView
android:text="@string/agent_label_str"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
android:text="@string/agent_label_str" />
<EditText
android:id="@+id/agent_name"
android:layout_height="wrap_content"
android:singleLine="true"
android:editable="true"
android:layout_width="fill_parent"
/>
android:layout_height="wrap_content"
android:inputType="text"
android:singleLine="true" />
<TextView
android:text="@string/event_search_label_str"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
android:text="@string/event_search_label_str" />
<EditText
android:id="@+id/event_search_text"
android:layout_height="wrap_content"
android:singleLine="true"
android:editable="true"
android:layout_width="fill_parent"
/>
android:layout_height="wrap_content"
android:inputType="text"
android:singleLine="true" />
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TableRow
android:visibility="gone"
>
android:layout_height="wrap_content" >
<TableRow android:visibility="gone" >
<TextView
android:text="@string/group_label_str"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="5dip"
android:layout_weight="1"
/>
android:paddingRight="5dip"
android:text="@string/group_label_str" />
<Spinner
android:id="@+id/group_combo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
/>
android:visibility="gone" />
<ProgressBar
android:id="@+id/loading_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
/>
android:layout_gravity="right" />
</TableRow>
<TableRow>
<TextView
android:text="@string/severity_label_str"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="5dip"
android:layout_weight="1"
/>
android:paddingRight="5dip"
android:text="@string/severity_label_str" />
<Spinner
android:id="@+id/severity_combo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
android:layout_height="wrap_content" />
</TableRow>
<TableRow>
<TextView
android:text="@string/status_label_str"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="5dip"
android:layout_weight="1"
/>
android:paddingRight="5dip"
android:text="@string/status_label_str" />
<Spinner
android:id="@+id/status_combo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
android:layout_height="wrap_content"/>
</TableRow>
</TableLayout>
<!--
<TableRow>
<TextView
android:text="@string/date_label_str"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingRight="5dip"
/>
<TimePicker
android:textSize="10sp"
android:id="@+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<DatePicker
android:id="@+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
-->
<TextView
android:text="@string/max_time_old_event_str"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="5dip"
/>
android:text="@string/max_time_old_event_str"/>
<Spinner
android:id="@+id/max_time_old_event_combo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
/>
android:layout_height="wrap_content"/>
</TableRow>
</TableLayout>
<LinearLayout
android:layout_marginTop="10px"
android:layout_marginBottom="10px"
android:layout_height="2px"
android:layout_width="fill_parent"
android:background="#ffffff"
/>
android:layout_height="2dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:background="#ffffff" />
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
android:orientation="horizontal" >
<Button
android:text="@string/reset_button_str"
android:id="@+id/button_reset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
android:text="@string/reset_button_str" />
<Button
android:text="@string/search_button_str"
android:id="@+id/button_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
android:text="@string/search_button_str" />
</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"
/>
android:text="@string/set_as_filter_watcher_button_str" />
</LinearLayout>
</ScrollView>
</LinearLayout>

View File

@ -14,82 +14,191 @@
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ScrollView
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
android:orientation="vertical" >
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
android:orientation="vertical" >
<TextView
style="@style/options_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:text="@string/connection" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:orientation="vertical" >
<TextView
android:textColor="#ffffff"
android:text="@string/url_label_str"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="5dip"
/>
android:text="@string/url_label_str"
android:textColor="#ffffff" />
<EditText
android:id="@+id/url"
android:layout_height="wrap_content"
android:singleLine="true"
android:editable="true"
android:layout_width="fill_parent"
/>
android:layout_height="wrap_content"
android:inputType="textWebEditText"
android:singleLine="true" />
<TextView
android:textColor="#ffffff"
android:text="@string/user_label_str"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="5dip"
/>
android:text="@string/user_label_str"
android:textColor="#ffffff" />
<EditText
android:id="@+id/user"
android:layout_height="wrap_content"
android:singleLine="true"
android:editable="true"
android:layout_width="fill_parent"
/>
android:layout_height="wrap_content"
android:inputType="text"
android:singleLine="true" />
<TextView
android:textColor="#ffffff"
android:text="@string/password_label_str"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="5dip"
/>
android:text="@string/password_label_str"
android:textColor="#ffffff" />
<EditText
android:id="@+id/password"
android:layout_height="wrap_content"
android:singleLine="true"
android:editable="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
/>
<TextView
android:textColor="#ffffff"
android:text="@string/refresh_time_label_str"
android:singleLine="true" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="5dip"
/>
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/refresh_time_label_str"
android:textColor="#ffffff" />
<Spinner
android:id="@+id/refresh_combo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/update_options"
android:text="@string/update_button_str"
android:gravity="left" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:orientation="vertical" >
<TextView
android:id="@+id/check_connection_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableBottom="@drawable/help"
android:text="@string/check_connection"
android:textColor="#ffffff" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
android:layout_marginBottom="20dp"
android:orientation="vertical" >
<TextView
style="@style/options_header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:text="@string/notification" />
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:stretchColumns="0,1" >
<TableRow>
<TextView
style="@style/options_entry_text"
android:text="@string/vibration" />
<CheckBox
android:id="@+id/vibration_on"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableRow>
<TableRow>
<TextView
style="@style/options_entry_text"
android:text="@string/led_flash" />
<CheckBox
android:id="@+id/led_flash_on"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="63dp" />
</TableRow>
<TableRow>
<TextView
android:id="@+id/textView1"
style="@style/options_entry_text"
android:text="@string/sound" />
<Button
android:id="@+id/sound_button"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginRight="10dp" />
</TableRow>
</TableLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="2dp"
android:layout_marginBottom="10dp"
android:background="#ffffff" />
<Button
android:id="@+id/update_options"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/update_button_str"/>
</LinearLayout>
</ScrollView>
</LinearLayout>

View File

@ -52,7 +52,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="refresh_time_label_str">Refresh time</string>
<string name="set_as_filter_watcher_button_str">Filter by default</string>
<string name="validate_event_button_str">Validate Event</string>
@ -103,4 +103,13 @@
<string name="pandroid_info_txt"><b>Welcome to Pandora FMS Event viewer for Android</b></string>
<string name="pandroid_info_long_txt"><p>This app is used for to see confortable and standaralone the events status from the monitoring server of Pandora FMS. From this app you can see in realtime the events and validate or filter.</p>
<p>The configuration as default connecting with public demo of Pandora FMS in firefly.artica.es. Please change the configuration for to use your Pandora FMS server.</p></string>
<string name="check_connection">Connection status</string>
<string name="connection">Connection</string>
<string name="notification">Notification</string>
<string name="vibration">Vibration</string>
<string name="led_flash">Led flashes</string>
<string name="sound">Sound</string>
<string name="select_sound">Select notification sound</string>
<string name="silence">Silence</string>
</resources>

View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="options_header">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:background">#999999</item>
<item name="android:paddingTop">2dp</item>
<item name="android:paddingBottom">2dp</item>
<item name="android:paddingLeft">15dp</item>
<item name="android:layout_marginBottom">5dp</item>
<item name="android:textSize">20dp</item>
<item name="android:textColor">#FFFFFF</item>
</style>
<!--
<style name="options_section">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:orientation">vertical</item>
<item name="android:layout_margin">5dp</item>
</style>-->
<style name="options_entry_text">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textSize">20dp</item>
<item name="android:layout_margin">5dp</item>
<item name="android:textColor">#FFFFFF</item>
</style>
</resources>

View File

@ -1,3 +1,19 @@
/*
Pandora FMS - http://pandorafms.com
==================================================
Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
Please see http://pandorafms.org for full contribution list
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation; version 2
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
package pandroid_event_viewer.pandorafms;
import android.app.Activity;
@ -5,12 +21,18 @@ import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
import android.widget.TextView;
/**
* This class contains basic instructions to describe the About popup.
*
* @author Miguel de Dios Matías
*
*/
public class About extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -18,7 +40,8 @@ public class About extends Activity {
setContentView(R.layout.info);
TextView text = (TextView) findViewById(R.id.url_pandora);
text.setText(Html.fromHtml("<a href='http://pandorafms.org/'>PandoraFMS.org</a>"));
text.setText(Html
.fromHtml("<a href='http://pandorafms.org/'>PandoraFMS.org</a>"));
text.setMovementMethod(LinkMovementMethod.getInstance());
CheckBox check_show = (CheckBox) findViewById(R.id.dont_show_again_extended);
@ -31,15 +54,16 @@ public class About extends Activity {
SharedPreferences preferences = getSharedPreferences(
getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
SharedPreferences.Editor editorPreferences = preferences.edit();
SharedPreferences.Editor editorPreferences = preferences
.edit();
editorPreferences.putBoolean("show_popup_info", false);
editorPreferences.commit();
}
else {
} else {
SharedPreferences preferences = getSharedPreferences(
getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
SharedPreferences.Editor editorPreferences = preferences.edit();
SharedPreferences.Editor editorPreferences = preferences
.edit();
editorPreferences.putBoolean("show_popup_info", true);
editorPreferences.commit();
}

View File

@ -1,3 +1,19 @@
/*
Pandora FMS - http://pandorafms.com
==================================================
Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
Please see http://pandorafms.org for full contribution list
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation; version 2
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
package pandroid_event_viewer.pandorafms;
import java.util.ArrayList;
@ -20,9 +36,19 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.media.RingtoneManager;
import android.net.Uri;
import android.util.Log;
/**
* It will receive new events and launch notifications.
*
* @author Miguel de Dios Matías
*
*/
public class AlarmReceiver extends BroadcastReceiver {
private static String TAG = "ALARM RECEIVER";
private static final int NOTIFICATION_PANDROID_EVENT_VIEWER = 666;
public String url;
public String user;
public String password;
@ -32,10 +58,15 @@ public class AlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.e("AlarmReceiver", "onReceive");
Log.i(TAG, "onReceive");
checkNewEvents(context);
}
/**
* Checks if there are new events and, in that case, throw a notification.
*
* @param context
*/
public void checkNewEvents(Context context) {
if (this.url == null) {
SharedPreferences preferences = context.getSharedPreferences(
@ -47,7 +78,8 @@ public class AlarmReceiver extends BroadcastReceiver {
this.password = preferences.getString("password", "");
Calendar c = Calendar.getInstance();
long now = (c.getTimeInMillis() / 1000);
long old_previous_filterTimestamp = preferences.getLong("previous_filterTimestamp", now);
long old_previous_filterTimestamp = preferences.getLong(
"previous_filterTimestamp", now);
if ((user.length() == 0) && (password.length() == 0)
&& (url.length() == 0)) {
@ -73,88 +105,102 @@ public class AlarmReceiver extends BroadcastReceiver {
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("other_mode",
"url_encode_separator_|"));
parameters.add(new BasicNameValuePair("return_type", "csv"));
parameters.add(new BasicNameValuePair("other", parametersAPI + "|total"));
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());
return_api = Core.convertStreamToString(entityResponse
.getContent());
return_api = return_api.replace("\n", "");
Log.e("AlarmReceiver checkNewEvents", "" + return_api);
Log.i(TAG + " checkNewEvents", return_api);
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("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"));
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());
return_api = Core.convertStreamToString(entityResponse
.getContent());
return_api = return_api.replace("\n", "");
this.more_criticity = new Integer(return_api).intValue();
notificationEvent(context);
}
else {
} else {
this.more_criticity = -1;
// Restore timestamp
SharedPreferences.Editor editorPreferences = preferences.edit();
editorPreferences.putLong("previous_filterTimestamp", old_previous_filterTimestamp);
SharedPreferences.Editor editorPreferences = preferences
.edit();
editorPreferences.putLong("previous_filterTimestamp",
old_previous_filterTimestamp);
editorPreferences.commit();
}
}
catch (Exception e) {
Log.e("EXCEPTION checkNewEvents", e.getMessage());
} catch (Exception e) {
Log.e(TAG + " EXCEPTION checkNewEvents", e.getMessage());
return;
}
}
}
/**
* Builds an api call from all filter parameters
*
* @param context
* @return Api call.
*/
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);
// TODO no api parameter, waiting for it
// int filterIDGroup = preferences.getInt("filterIDGroup", 0);
int filterSeverity = preferences.getInt("filterSeverity", -1);
int filterStatus = preferences.getInt("filterStatus", 3);
String filterEventSearch = preferences.getString("filterEventSearch", "");
String filterEventSearch = preferences.getString("filterEventSearch",
"");
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.putLong("previous_filterTimestamp", filterTimestamp); //Save and the previous for the list.
// Save for the next execution
editorPreferences.putLong("filterTimestamp", now);
// Save the previous for the list.
editorPreferences.putLong("previous_filterTimestamp", filterTimestamp);
if (editorPreferences.commit()) {
Log.e("AlarmReceiver serializeParams2Api", "YES COMMIT");
Log.i(TAG + " (filter options)",
"Configuration changes commited (timestamp)");
} else {
Log.e(TAG + " (filter options)",
"Configuration changes not commited");
}
else {
Log.e("AlarmReceiver serializeParams2Api", "NOT COMMIT");
}
String return_var = "";
return_var += ';'; // Separator for the csv
return_var += "|";
return_var += Integer.toString(filterSeverity); // Criticity or severity
@ -173,90 +219,129 @@ public class AlarmReceiver extends BroadcastReceiver {
return_var += "|";
return_var += filterStatus; // The status
return_var += "|";
return_var += filterEventSearch; //The free search in the text event description.
return_var += filterEventSearch; // The free search in the text event
// description.
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("AlarmReceiver serializeParams2Api", return_var);
Log.i(TAG + " serializeParams2Api", return_var);
return return_var;
}
private static final int NOTIFICATION_PANDROID_EVENT_VIEWER = 666;
/**
* Launchs a notification
*
* @param context
*/
public void notificationEvent(Context context) {
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns);
NotificationManager mNotificationManager = (NotificationManager) context
.getSystemService(ns);
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());
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());
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());
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());
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());
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());
tickerText = context.getString(
R.string.notification_criticity_2_str).replace("%s",
new Long(this.count_events).toString());
break;
}
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
notification.defaults |= Notification.DEFAULT_ALL;
// notification.defaults |= Notification.DEFAULT_ALL;
notification.flags |= Notification.FLAG_AUTO_CANCEL;
// Notification options
SharedPreferences preferences = context.getSharedPreferences(
context.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
if (preferences.getBoolean("vibration", true)) {
Log.d(TAG, "Vibration");
notification.defaults |= Notification.DEFAULT_VIBRATE;
} else {
Log.d(TAG, "No vibration");
notification.vibrate = new long[] { 0, 0, 0, 0 };
}
if (preferences.getBoolean("led", false)) {
Log.d(TAG, "Led flash");
notification.defaults |= Notification.DEFAULT_LIGHTS;
/*
* notification.ledARGB = 0xff00ff00; notification.ledOnMS = 300;
* notification.ledOffMS = 1000; notification.flags |=
* Notification.FLAG_SHOW_LIGHTS;
*/
}
Uri notificationSoundUri = Uri.parse(preferences.getString(
"notification_sound_uri",
RingtoneManager
.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
.toString()));
if (notificationSoundUri != null) {
Log.i(TAG, "Setting sound: " + notificationSoundUri.toString());
notification.sound = notificationSoundUri;
} else {
Log.e(TAG, "Ringtone's uri problem (NULL)");
}
Intent notificationIntent = new Intent(context, PandroidEventviewerActivity.class);
Intent notificationIntent = new Intent(context,
PandroidEventviewerActivity.class);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
notificationIntent.putExtra("count_events", this.count_events);
notificationIntent.putExtra("more_criticity", this.more_criticity);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
notificationIntent, 0);
CharSequence title = context.getString(R.string.pandroid_event_viewer_str);
CharSequence title = context
.getString(R.string.pandroid_event_viewer_str);
notification.setLatestEventInfo(context, title, tickerText, contentIntent);
mNotificationManager.notify(NOTIFICATION_PANDROID_EVENT_VIEWER, notification);
notification.setLatestEventInfo(context, title, tickerText,
contentIntent);
Log.i(TAG, "Launching notification");
mNotificationManager.notify(NOTIFICATION_PANDROID_EVENT_VIEWER,
notification);
}
}

View File

@ -1,3 +1,19 @@
/*
Pandora FMS - http://pandorafms.com
==================================================
Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
Please see http://pandorafms.org for full contribution list
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation; version 2
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
package pandroid_event_viewer.pandorafms;
import java.io.BufferedReader;
@ -10,80 +26,61 @@ import java.util.Calendar;
import android.content.Context;
import android.content.Intent;
/**
* This class provides basic functions to manage services and some received
* data.
*
* @author Miguel de Dios Matías
*
*/
public class Core implements Serializable {
private static final long serialVersionUID = 7071445033114548174L;
private static final long serialVersionUID = 7071445033114548174L;
public Intent intent_service;
//public Context context; //Fucking marshall exception
public Core() {
intent_service = null;
//context = null; //Fucking marshall exception
}
/**
* Starts PandroidEventviewerService.
*
* @param context
*/
public void startServiceEventWatcher(Context context) {
if (intent_service == null) {
intent_service = new Intent(context, PandroidEventviewerService.class);
//this.context = context; //Fucking marshall exception
intent_service = new Intent(context,
PandroidEventviewerService.class);
}
context.startService(intent_service);
}
/**
* Stops PandroidEventviewerService.
*
* @param context
*/
public void stopServiceEventWatcher(Context context) {
if (intent_service == null) {
intent_service = new Intent(context, PandroidEventviewerService.class);
//this.context = context; //Fucking marshall exception
intent_service = new Intent(context,
PandroidEventviewerService.class);
}
context.stopService(this.intent_service);
}
///////////////////////
/*
public Core(Parcel in) {
intent_service = (Intent)in.readValue(null);
//context = (Context)in.readValue(null); //Fucking marshall exception
}
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
}
/**
* Reads from the input stream and returns a string.
*
* @param is
* @return A string with all data read.
*/
///////////
public static String convertStreamToString (InputStream is)
{
BufferedReader reader = new BufferedReader(new
InputStreamReader(is), 8*1024);
public static String convertStreamToString(InputStream is) {
BufferedReader reader = new BufferedReader(new InputStreamReader(is),
8 * 1024);
StringBuilder sb = new StringBuilder();
String line = null;
@ -104,8 +101,14 @@ public class Core implements Serializable {
return sb.toString();
}
public long convertMaxTimeOldEventValuesToTimestamp(long timestamp, int arrayKey) {
long time = timestamp;
/**
* Converts the maximum time setted to filter events to a timestamp.
*
* @param timestamp
* @param arrayKey
* @return Time in milliseconds.
*/
public long convertMaxTimeOldEventValuesToTimestamp(long time, int arrayKey) {
long return_var = 0;
if (time == 0) {

View File

@ -1,3 +1,19 @@
/*
Pandora FMS - http://pandorafms.com
==================================================
Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
Please see http://pandorafms.org for full contribution list
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation; version 2
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
package pandroid_event_viewer.pandorafms;
import java.io.IOException;
@ -37,32 +53,37 @@ import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
/**
* Activity where events are displayed.
*
* @author Miguel de Dios Matías
*
*/
public class EventList extends ListActivity {
private ListView lv;
private MyAdapter la;
public PandroidEventviewerActivity object;
public Core core;
private PandroidEventviewerActivity object;
private Core core;
public HashMap<Integer, Boolean> openedItem;
public HashMap<String, Bitmap> imgGroups;
public HashMap<String, Bitmap> imgSeverity;
public HashMap<String, Bitmap> imgType;
// private HashMap<Integer, Boolean> openedItem;
private HashMap<String, Bitmap> imgGroups;
private HashMap<String, Bitmap> imgSeverity;
private HashMap<String, Bitmap> imgType;
private BroadcastReceiver onBroadcast;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// this.openedItem = new HashMap<Integer, Boolean>();
this.imgGroups = new HashMap<String, Bitmap>();
this.imgSeverity = new HashMap<String, Bitmap>();
this.imgType = new HashMap<String, Bitmap>();
Intent i = getIntent();
this.object = (PandroidEventviewerActivity)i.getSerializableExtra("object");
this.object = (PandroidEventviewerActivity) i
.getSerializableExtra("object");
this.core = (Core) i.getSerializableExtra("core");
setContentView(R.layout.list_view_layout);
@ -85,11 +106,9 @@ public class EventList extends ListActivity {
if (object.eventList.size() == 0) {
button.setVisibility(Button.GONE);
}
else if (((long)object.eventList.size()) >= object.count_events) {
} else if (((long) object.eventList.size()) >= object.count_events) {
button.setVisibility(Button.GONE);
}
else {
} else {
button.setVisibility(Button.VISIBLE);
}
@ -97,8 +116,7 @@ public class EventList extends ListActivity {
LinearLayout layout = (LinearLayout) findViewById(R.id.loading_layout);
layout.setVisibility(LinearLayout.GONE);
la.showLoadingEvents = false;
}
else {
} else {
LinearLayout layout = (LinearLayout) findViewById(R.id.loading_layout);
layout.setVisibility(LinearLayout.GONE);
@ -160,13 +178,13 @@ public class EventList extends ListActivity {
inflater.inflate(R.menu.options_menu_list_events, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Intent i;
switch (item.getItemId()) {
case R.id.options_button_menu_options:
i = new Intent(this, Options.class);
//i.putExtra("object", object);
i.putExtra("core", this.core);
startActivity(i);
@ -187,7 +205,10 @@ public class EventList extends ListActivity {
return true;
}
public void toggleLoadingLayout() {
/**
* Shows loading information.
*/
private void toggleLoadingLayout() {
LinearLayout layout;
layout = (LinearLayout) findViewById(R.id.empty_list_layout);
@ -197,52 +218,55 @@ public class EventList extends ListActivity {
if (this.object.loadInProgress) {
layout.setVisibility(LinearLayout.VISIBLE);
}
else {
} else {
layout.setVisibility(LinearLayout.GONE);
}
}
public Bitmap downloadFile(String fileUrl) {
/**
* Downloads an image
*
* @param fileUrl
* @return A bitmap of that image
*/
private Bitmap downloadImage(String fileUrl) {
URL myFileUrl = null;
try {
myFileUrl = new URL(fileUrl);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
HttpURLConnection conn= (HttpURLConnection)myFileUrl.openConnection();
HttpURLConnection conn = (HttpURLConnection) myFileUrl
.openConnection();
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();
return BitmapFactory.decodeStream(is);
//imView.setImageBitmap(bmImg);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
public void setImageGroup(View view, String group_icon, int id) {
// TODO comment
private void setImageGroup(View view, String group_icon, int id) {
ImageView imgview = (ImageView) view.findViewById(id);
Bitmap img;
if (this.imgGroups.containsKey(group_icon)) {
img = this.imgGroups.get(group_icon);
}
else {
SharedPreferences preferences = getApplicationContext().getSharedPreferences(
getApplicationContext().getString(R.string.const_string_preferences),
} else {
SharedPreferences preferences = getApplicationContext()
.getSharedPreferences(
getApplicationContext().getString(
R.string.const_string_preferences),
Activity.MODE_PRIVATE);
String url = preferences.getString("url", "");
img = this.downloadFile(
url + "/images/groups_small/" + group_icon + ".png");
img = this.downloadImage(url + "/images/groups_small/" + group_icon
+ ".png");
if (img != null) {
this.imgGroups.put(group_icon, img);
@ -254,15 +278,15 @@ public class EventList extends ListActivity {
}
}
// TODO comment
public void setImageType(View view, String url, int id) {
ImageView imgview = (ImageView) view.findViewById(id);
Bitmap img = null;
if (this.imgType.containsKey(url)) {
img = this.imgType.get(url);
}
else {
img = this.downloadFile(url);
} else {
img = this.downloadImage(url);
if (img != null) {
this.imgType.put(url, img);
@ -274,15 +298,16 @@ public class EventList extends ListActivity {
}
}
// TODO comment
public void setImageSeverity(View view, String url, int id) {
ImageView imgview = (ImageView) view.findViewById(id);
Bitmap img = null;
if (this.imgSeverity.containsKey(url)) {
img = this.imgSeverity.get(url);
}
else {
img = this.downloadFile(url);
} else {
img = this.downloadImage(url);
if (img != null) {
this.imgSeverity.put(url, img);
@ -295,8 +320,7 @@ public class EventList extends ListActivity {
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id)
{
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
EventListItem item = this.object.eventList.get(position);
@ -306,23 +330,34 @@ public class EventList extends ListActivity {
la.notifyDataSetChanged();
}
public void loadMoreEvents(View v) {
// TODO removed a View v argument, check
/**
* Loads more events.
*
* @param v
*/
private void loadMoreEvents() {
la.showLoadingEvents = true;
la.notifyDataSetChanged();
object.executeBackgroundGetEvents();
}
public class MyAdapter extends BaseAdapter
{
/**
* Private adapter (event list).
*
* @author Miguel de Dios Matías
*
*/
private class MyAdapter extends BaseAdapter {
private Context mContext;
public PandroidEventviewerActivity object;
public Core core;
public boolean showLoadingEvents;
public MyAdapter(Context c, PandroidEventviewerActivity object, Core core)
{
public MyAdapter(Context c, PandroidEventviewerActivity object,
Core core) {
mContext = c;
this.object = object;
@ -338,13 +373,11 @@ public class EventList extends ListActivity {
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@ -352,43 +385,35 @@ public class EventList extends ListActivity {
public View getView(int position, View convertView, ViewGroup parent) {
View view;
//The comment lines don't run fine, opened wrong the rows.
//Optimization for not create convertView all times
//if (convertView == null)
//{
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LayoutInflater inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.item_list_event_layout, null);
/*}
else
{
view = convertView;
}*/
// If the end of the list.
if (this.object.eventList.size() == position) {
// Show button to get more events
if ((!object.loadInProgress) && (object.count_events != 0)) {
if (showLoadingEvents) {
LinearLayout layout = (LinearLayout) view.findViewById(R.id.loading_more_events);
LinearLayout layout = (LinearLayout) view
.findViewById(R.id.loading_more_events);
layout.setVisibility(LinearLayout.VISIBLE);
RelativeLayout layout2 = (RelativeLayout) view.findViewById(R.id.content_event_item);
RelativeLayout layout2 = (RelativeLayout) view
.findViewById(R.id.content_event_item);
layout2.setVisibility(RelativeLayout.GONE);
Button button = (Button)view.findViewById(R.id.button_load_more_events);
Button button = (Button) view
.findViewById(R.id.button_load_more_events);
button.setVisibility(Button.GONE);
}
else {
Button button = (Button)view.findViewById(R.id.button_load_more_events);
} else {
Button button = (Button) view
.findViewById(R.id.button_load_more_events);
if (object.eventList.size() == 0) {
button.setVisibility(Button.GONE);
}
else if (((long)object.eventList.size()) >= object.count_events) {
} else if (((long) object.eventList.size()) >= object.count_events) {
button.setVisibility(Button.GONE);
}
else {
} else {
button.setVisibility(Button.VISIBLE);
}
@ -396,16 +421,16 @@ public class EventList extends ListActivity {
@Override
public void onClick(View v) {
object.offset += object.pagination;
loadMoreEvents(v);
loadMoreEvents();
}
});
RelativeLayout content_event_item = (RelativeLayout)view.findViewById(R.id.content_event_item);
RelativeLayout content_event_item = (RelativeLayout) view
.findViewById(R.id.content_event_item);
content_event_item.setVisibility(RelativeLayout.GONE);
}
}
}
else {
} else {
EventListItem item = this.object.eventList.get(position);
switch (item.criticity) {
@ -434,113 +459,133 @@ public class EventList extends ListActivity {
if (item.event_type.equals("system")) {
titulo.setText(R.string.system_str);
}
else {
} else {
titulo.setText(item.agent_name);
}
TextView descripcion = (TextView)view.findViewById(R.id.event_name);
TextView descripcion = (TextView) view
.findViewById(R.id.event_name);
descripcion.setText(item.event);
TextView timestamp = (TextView)view.findViewById(R.id.timestamp);
TextView timestamp = (TextView) view
.findViewById(R.id.timestamp);
timestamp.setText(item.timestamp);
if (item.criticity_image.length() != 0)
setImageType(view, item.criticity_image, R.id.img_severity_colapse_item);
setImageType(view, item.criticity_image,
R.id.img_severity_colapse_item);
if (item.group_icon.length() != 0)
setImageGroup(view, item.group_icon, R.id.img_group_colapse_item);
setImageGroup(view, item.group_icon,
R.id.img_group_colapse_item);
ImageView imgValidate = (ImageView)view.findViewById(R.id.img_validate_colapse_item);
ImageView imgValidate = (ImageView) view
.findViewById(R.id.img_validate_colapse_item);
if (item.status == 1) {
imgValidate.setImageResource(R.drawable.tick);
}
else {
} else {
imgValidate.setImageResource(R.drawable.tick_off);
}
// Show extended info
if (item.opened) {
View viewEventExtended;
viewEventExtended = inflater.inflate(R.layout.item_list_event_extended, null);
viewEventExtended = inflater.inflate(
R.layout.item_list_event_extended, null);
TextView text;
if (item.tags.length() != 0) {
text = (TextView)viewEventExtended.findViewById(R.id.tags_text);
text = (TextView) viewEventExtended
.findViewById(R.id.tags_text);
text.setText(item.tags);
}
if (item.user_comment.length() != 0) {
text = (TextView)viewEventExtended.findViewById(R.id.comments_text);
text = (TextView) viewEventExtended
.findViewById(R.id.comments_text);
text.setText(item.user_comment);
}
if (item.group_name.length() != 0) {
text = (TextView)viewEventExtended.findViewById(R.id.group_text);
text = (TextView) viewEventExtended
.findViewById(R.id.group_text);
text.setText(item.group_name);
if (item.group_icon.length() != 0)
setImageGroup(viewEventExtended, item.group_icon, R.id.img_group);
}
else {
setImageGroup(viewEventExtended, item.group_icon,
R.id.img_group);
} else {
// ALL
setImageGroup(viewEventExtended, "world", R.id.img_group);
setImageGroup(viewEventExtended, "world",
R.id.img_group);
}
if (item.agent_name.length() != 0) {
View row = viewEventExtended.findViewById(R.id.row_agent);
View row = viewEventExtended
.findViewById(R.id.row_agent);
row.setVisibility(View.VISIBLE);
text = (TextView)viewEventExtended.findViewById(R.id.agent_text);
text.setText(Html.fromHtml(
"<a href='" + this.object.url +
"/index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente="
//"/mobile/index.php?page=agent&id=" //The link to Pandora Console Mobile
+ item.id_agent
+ "'>" + item.agent_name + "</a>"));
text = (TextView) viewEventExtended
.findViewById(R.id.agent_text);
text.setText(Html
.fromHtml("<a href='"
+ this.object.url
+ "/index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente="
// "/mobile/index.php?page=agent&id="
// //The link to Pandora Console Mobile
+ item.id_agent + "'>"
+ item.agent_name + "</a>"));
text.setMovementMethod(LinkMovementMethod.getInstance());
}
if (item.description_image.length() != 0)
setImageType(viewEventExtended, item.description_image, R.id.img_type);
text = (TextView)viewEventExtended.findViewById(R.id.type_text);
setImageType(viewEventExtended, item.description_image,
R.id.img_type);
text = (TextView) viewEventExtended
.findViewById(R.id.type_text);
text.setText(eventType2Text(item.event_type));
if (item.criticity_name.length() != 0) {
text = (TextView)viewEventExtended.findViewById(R.id.severity_text);
text = (TextView) viewEventExtended
.findViewById(R.id.severity_text);
text.setText(item.criticity_name);
if (item.criticity_image.length() != 0)
setImageType(viewEventExtended, item.criticity_image, R.id.img_severity);
setImageType(viewEventExtended,
item.criticity_image, R.id.img_severity);
}
//Set the open and close the extended info event row action.
view.setOnClickListener(new OnItemClickListener(position, this.object));
// Set the open and close the extended info event row
// action.
view.setOnClickListener(new OnItemClickListener(position,
this.object));
Button button;
button = (Button)viewEventExtended.findViewById(R.id.validate_button_extended);
button = (Button) viewEventExtended
.findViewById(R.id.validate_button_extended);
if (item.status == -1) {
// For unknow events
button.setVisibility(Button.GONE);
text = (TextView)viewEventExtended.findViewById(R.id.validate_event_label);
text = (TextView) viewEventExtended
.findViewById(R.id.validate_event_label);
text.setText("");
text.setVisibility(TextView.VISIBLE);
}
else if (item.status != 1) {
} else if (item.status != 1) {
OnClickListenerButtonValidate clickListener = new OnClickListenerButtonValidate();
clickListener.id_event = item.id_event;
clickListener.core = this.core;
button.setOnClickListener(clickListener);
text = (TextView)viewEventExtended.findViewById(R.id.validate_event_label);
text = (TextView) viewEventExtended
.findViewById(R.id.validate_event_label);
text.setVisibility(TextView.GONE);
}
else {
} else {
button.setVisibility(Button.GONE);
text = (TextView)viewEventExtended.findViewById(R.id.validate_event_label);
text = (TextView) viewEventExtended
.findViewById(R.id.validate_event_label);
text.setVisibility(TextView.VISIBLE);
}
LinearLayout itemLinearLayout = (LinearLayout)view.findViewById(R.id.item_linear_layout);
LinearLayout itemLinearLayout = (LinearLayout) view
.findViewById(R.id.item_linear_layout);
itemLinearLayout.addView(viewEventExtended);
}
}
@ -548,59 +593,75 @@ public class EventList extends ListActivity {
return view;
}
/**
* Returns the event type in the correct format (and system locale).
*
* @param type
* @return Localized type.
*/
private String eventType2Text(String type) {
String return_var;
if (type.equals("alert_recovered")) {
return_var = getApplicationContext().getString(R.string.alert_recovered_str);
}
else if (type.equals("alert_manual_validation")) {
return_var = getApplicationContext().getString(R.string.alert_manual_validation_str);
}
else if (type.equals("going_up_warning")) {
return_var = getApplicationContext().getString(R.string.going_up_warning_str);
}
else if (type.equals("going_down_critical")) {
return_var = getApplicationContext().getString(R.string.going_down_critical_str);
}
else if (type.equals("going_up_critical")) {
return_var = getApplicationContext().getString(R.string.going_down_critical_str);
}
else if (type.equals("going_up_normal")) {
return_var = getApplicationContext().getString(R.string.going_up_normal_str);
}
else if (type.equals("going_down_normal")) {
return_var = getApplicationContext().getString(R.string.going_up_normal_str);
}
else if (type.equals("going_down_warning")) {
return_var = getApplicationContext().getString(R.string.going_down_warning_str);
}
else if (type.equals("alert_fired")) {
return_var = getApplicationContext().getString(R.string.alert_fired_str);
}
else if (type.equals("system")) {
return_var = getApplicationContext().getString(R.string.system_str);
}
else if (type.equals("recon_host_detected")) {
return_var = getApplicationContext().getString(R.string.system_str);
}
else if (type.equals("new_agent")) {
return_var = getApplicationContext().getString(R.string.new_agent_str);
}
else {
return_var = getApplicationContext().getString(R.string.unknown_str) + " " + type;
return_var = getApplicationContext().getString(
R.string.alert_recovered_str);
} else if (type.equals("alert_manual_validation")) {
return_var = getApplicationContext().getString(
R.string.alert_manual_validation_str);
} else if (type.equals("going_up_warning")) {
return_var = getApplicationContext().getString(
R.string.going_up_warning_str);
} else if (type.equals("going_down_critical")) {
return_var = getApplicationContext().getString(
R.string.going_down_critical_str);
} else if (type.equals("going_up_critical")) {
return_var = getApplicationContext().getString(
R.string.going_down_critical_str);
} else if (type.equals("going_up_normal")) {
return_var = getApplicationContext().getString(
R.string.going_up_normal_str);
} else if (type.equals("going_down_normal")) {
return_var = getApplicationContext().getString(
R.string.going_up_normal_str);
} else if (type.equals("going_down_warning")) {
return_var = getApplicationContext().getString(
R.string.going_down_warning_str);
} else if (type.equals("alert_fired")) {
return_var = getApplicationContext().getString(
R.string.alert_fired_str);
} else if (type.equals("system")) {
return_var = getApplicationContext().getString(
R.string.system_str);
} else if (type.equals("recon_host_detected")) {
return_var = getApplicationContext().getString(
R.string.system_str);
} else if (type.equals("new_agent")) {
return_var = getApplicationContext().getString(
R.string.new_agent_str);
} else {
return_var = getApplicationContext().getString(
R.string.unknown_str)
+ " " + type;
}
return return_var;
}
/**
* Custom click listener (show more information).
*
* @author Miguel de Dios Matías
*
*/
private class OnItemClickListener implements OnClickListener {
private int mPosition;
private PandroidEventviewerActivity object;
OnItemClickListener(int position, PandroidEventviewerActivity object) {
mPosition = position;
this.object = object;
}
@Override
public void onClick(View arg0) {
EventListItem item = this.object.eventList.get(mPosition);
@ -610,24 +671,24 @@ public class EventList extends ListActivity {
}
}
public class OnClickListenerButtonValidate implements OnClickListener {
/**
* Custom click listener (event validation).
*
* @author Miguel de Dios Matías
*
*/
private class OnClickListenerButtonValidate implements OnClickListener {
public int id_event;
//public PandroidEventviewerActivity object;
public Core core;
@Override
public void onClick(View v) {
Intent i = new Intent(getApplicationContext(), PopupValidationEvent.class);
Intent i = new Intent(getApplicationContext(),
PopupValidationEvent.class);
i.putExtra("id_event", id_event);
//i.putExtra("object", this.object);
i.putExtra("core", this.core);
startActivity(i);
}
}
}
}

View File

@ -1,5 +1,27 @@
/*
Pandora FMS - http://pandorafms.com
==================================================
Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
Please see http://pandorafms.org for full contribution list
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation; version 2
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
package pandroid_event_viewer.pandorafms;
/**
* This class represents an event.
*
* @author Miguel de Dios Matías
*
*/
public class EventListItem {
public int id_event;
public int id_agent;

View File

@ -1,3 +1,19 @@
/*
Pandora FMS - http://pandorafms.com
==================================================
Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
Please see http://pandorafms.org for full contribution list
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation; version 2
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
package pandroid_event_viewer.pandorafms;
import android.app.Activity;
@ -6,15 +22,21 @@ import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.widget.TextView;
/**
* This class contains basic instructions to describe the Information popup.
*
* @author Miguel de Dios Matías
*
*/
public class Info extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.about);
TextView text = (TextView) findViewById(R.id.url_pandora);
text.setText(Html.fromHtml("<a href='http://pandorafms.org/'>PandoraFMS.org</a>"));
text.setText(Html
.fromHtml("<a href='http://pandorafms.org/'>PandoraFMS.org</a>"));
text.setMovementMethod(LinkMovementMethod.getInstance());
}
}

View File

@ -1,3 +1,19 @@
/*
Pandora FMS - http://pandorafms.com
==================================================
Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
Please see http://pandorafms.org for full contribution list
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation; version 2
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
package pandroid_event_viewer.pandorafms;
import java.util.ArrayList;
@ -5,6 +21,7 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
@ -32,19 +49,26 @@ import android.widget.ProgressBar;
import android.widget.Spinner;
import android.widget.Toast;
/**
* Activity with the filter options.
*
* @author Miguel de Dios Matías
*
*/
public class Main extends Activity {
public PandroidEventviewerActivity object;
public HashMap<Integer, String> pandoraGroups;
public Spinner comboSeverity;
public Core core;
private static String TAG = "MAIN";
private PandroidEventviewerActivity object;
private HashMap<Integer, String> pandoraGroups;
private Spinner comboSeverity;
private Core core;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent i = getIntent();
this.object = (PandroidEventviewerActivity)i.getSerializableExtra("object");
this.object = (PandroidEventviewerActivity) i
.getSerializableExtra("object");
this.core = (Core) i.getSerializableExtra("core");
this.pandoraGroups = new HashMap<Integer, String>();
@ -56,8 +80,8 @@ public class Main extends Activity {
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 ||
object.url.length() == 0) {
if (object.user.length() == 0 || object.password.length() == 0
|| object.url.length() == 0) {
Toast toast = Toast.makeText(this.getApplicationContext(),
this.getString(R.string.please_set_preferences_str),
Toast.LENGTH_SHORT);
@ -66,14 +90,12 @@ public class Main extends Activity {
buttonReset.setEnabled(false);
buttonSearch.setEnabled(false);
buttonbuttonSetAsFilterWatcher.setEnabled(false);
}
else if (object.user.equals("demo") || object.password.equals("demo")) {
} else if (object.user.equals("demo") || object.password.equals("demo")) {
Toast toast = Toast.makeText(this.getApplicationContext(),
this.getString(R.string.preferences_set_demo_pandora_str),
Toast.LENGTH_LONG);
toast.show();
}
else {
} else {
buttonSearch.setEnabled(false);
buttonReset.setEnabled(false);
buttonbuttonSetAsFilterWatcher.setEnabled(false);
@ -87,27 +109,28 @@ public class Main extends Activity {
comboSeverity = (Spinner) findViewById(R.id.severity_combo);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.severity_array_values, android.R.layout.simple_spinner_item);
this, R.array.severity_array_values,
android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
comboSeverity.setAdapter(adapter);
Spinner combo;
combo = (Spinner) findViewById(R.id.status_combo);
adapter = ArrayAdapter.createFromResource(
this, R.array.event_status_values, android.R.layout.simple_spinner_item);
adapter = ArrayAdapter.createFromResource(this,
R.array.event_status_values,
android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
combo.setAdapter(adapter);
combo.setSelection(3);
combo = (Spinner) findViewById(R.id.max_time_old_event_combo);
adapter = ArrayAdapter.createFromResource(
this, R.array.max_time_old_event_values, android.R.layout.simple_spinner_item);
adapter = ArrayAdapter.createFromResource(this,
R.array.max_time_old_event_values,
android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
combo.setAdapter(adapter);
combo.setSelection(preferences.getInt("filterLastTime", 6));
buttonReset.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -122,7 +145,8 @@ public class Main extends Activity {
}
});
buttonbuttonSetAsFilterWatcher.setOnClickListener(new View.OnClickListener() {
buttonbuttonSetAsFilterWatcher
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -141,12 +165,17 @@ public class Main extends Activity {
super.onRestart();
if (this.pandoraGroups.size() == 0) {
Log.e("Main onRestart", "Main onRestart");
Log.i(TAG, "onRestart: getting groups");
new GetGroupsAsyncTask().execute();
}
}
public ArrayList<String> getGroups() {
/**
* Get groups throught an api call.
*
* @return A list of groups.
*/
private List<String> getGroups() {
ArrayList<String> array = new ArrayList<String>();
SharedPreferences preferences = getSharedPreferences(
@ -167,7 +196,8 @@ public class Main extends Activity {
parameters.add(new BasicNameValuePair("pass", password));
parameters.add(new BasicNameValuePair("op", "get"));
parameters.add(new BasicNameValuePair("op2", "groups"));
parameters.add(new BasicNameValuePair("other_mode", "url_encode_separator_|"));
parameters.add(new BasicNameValuePair("other_mode",
"url_encode_separator_|"));
parameters.add(new BasicNameValuePair("return_type", "csv"));
parameters.add(new BasicNameValuePair("other", ";"));
@ -178,7 +208,8 @@ public class Main extends Activity {
HttpResponse response = httpClient.execute(httpPost);
HttpEntity entityResponse = response.getEntity();
String return_api = Core.convertStreamToString(entityResponse.getContent());
String return_api = Core.convertStreamToString(entityResponse
.getContent());
String[] lines = return_api.split("\n");
@ -189,32 +220,35 @@ public class Main extends Activity {
array.add(groups[1]);
}
}
catch (Exception e) {
Log.e("EXCEPTION ArrayList", e.getMessage());
} catch (Exception e) {
Log.e(TAG +": getting groups", e.getMessage());
}
return array;
}
public class GetGroupsAsyncTask extends AsyncTask<Void, Void, Void> {
public ArrayList<String> lista;
/**
* Async task which get groups.
*
* @author Miguel de Dios Matías
*
*/
private class GetGroupsAsyncTask extends AsyncTask<Void, Void, Void> {
private List<String> list;
@Override
protected Void doInBackground(Void... params) {
lista = getGroups();
list = getGroups();
return null;
}
@Override
protected void onPostExecute(Void unused)
{
protected void onPostExecute(Void unused) {
Spinner combo = (Spinner) findViewById(R.id.group_combo);
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(getApplicationContext(),
android.R.layout.simple_spinner_item,
lista);
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(
getApplicationContext(),
android.R.layout.simple_spinner_item, list);
combo.setAdapter(spinnerArrayAdapter);
combo.setSelection(0);
@ -240,13 +274,13 @@ public class Main extends Activity {
inflater.inflate(R.menu.options_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Intent i;
switch (item.getItemId()) {
case R.id.options_button_menu_options:
i = new Intent(this, Options.class);
//i.putExtra("object", object);
i.putExtra("core", new Core());
startActivity(i);
@ -260,33 +294,21 @@ public class Main extends Activity {
return true;
}
public void search_form() {
/**
* Performs the search choice
*/
private void search_form() {
// Clean the EventList
this.object.eventList = new ArrayList<EventListItem>();
this.object.loadInProgress = true;
//Get form data
/*
DatePicker datePicker = (DatePicker)findViewById(R.id.date);
TimePicker timePicker = (TimePicker)findViewById(R.id.time);
int day = datePicker.getDayOfMonth();
int month = datePicker.getMonth();
int year = datePicker.getYear();
int hour = timePicker.getCurrentHour();
int minute = timePicker.getCurrentMinute();
Calendar c = Calendar.getInstance();
c.set(year, month, day, hour, minute);
this.object.timestamp = c.getTimeInMillis() / 1000;
*/
int timeKey = 0;
Spinner combo = (Spinner) findViewById(R.id.max_time_old_event_combo);
timeKey = combo.getSelectedItemPosition();
this.object.timestamp = this.core.convertMaxTimeOldEventValuesToTimestamp(0, timeKey);
this.object.timestamp = this.core
.convertMaxTimeOldEventValuesToTimestamp(0, timeKey);
EditText text = (EditText) findViewById(R.id.agent_name);
this.object.agentNameStr = text.getText().toString();
@ -294,23 +316,25 @@ public class Main extends Activity {
this.object.id_group = 0;
combo = (Spinner) findViewById(R.id.group_combo);
if (combo.getSelectedItem() != null) {
String selectedGroup = combo.getSelectedItem().toString();
Iterator it = pandoraGroups.entrySet().iterator();
Iterator<Entry<Integer, String>> it = pandoraGroups.entrySet()
.iterator();
while (it.hasNext()) {
Map.Entry<Integer, String> e = (Map.Entry<Integer, String>)it.next();
Map.Entry<Integer, String> e = (Map.Entry<Integer, String>) it
.next();
if (e.getValue().equals(selectedGroup)) {
this.object.id_group = e.getKey();
}
}
}
combo = (Spinner) findViewById(R.id.severity_combo);
this.object.severity = combo.getSelectedItemPosition() - 1;
combo = (Spinner) findViewById(R.id.status_combo);
Log.e("Main search_form", "status_combo = " + combo.getSelectedItemPosition());
//this.object.status = combo.getSelectedItemPosition() - 1;//The next version re-add please
this.object.status = combo.getSelectedItemPosition() - 0;
text = (EditText) findViewById(R.id.event_search_text);
@ -323,7 +347,10 @@ public class Main extends Activity {
ta.getTabHost().setCurrentTab(1);
}
public void save_filter_watcher() {
/**
* Saves filter data
*/
private void save_filter_watcher() {
String filterAgentName = "";
int filterIDGroup = 0;
int filterSeverity = -1;
@ -331,7 +358,6 @@ public class Main extends Activity {
int filterLastTime = 0;
String filterEventSearch = "";
EditText text = (EditText) findViewById(R.id.agent_name);
filterAgentName = text.getText().toString();
@ -340,9 +366,10 @@ public class Main extends Activity {
if ((combo != null) && (combo.getSelectedItem() != null)) {
String selectedGroup = combo.getSelectedItem().toString();
Iterator it = pandoraGroups.entrySet().iterator();
Iterator<Entry<Integer, String>> it = pandoraGroups.entrySet()
.iterator();
while (it.hasNext()) {
Map.Entry<Integer, String> e = (Map.Entry<Integer, String>)it.next();
Map.Entry<Integer, String> e = it.next();
if (e.getValue().equals(selectedGroup)) {
filterIDGroup = e.getKey();
@ -354,7 +381,6 @@ public class Main extends Activity {
filterSeverity = combo.getSelectedItemPosition() - 1;
combo = (Spinner) findViewById(R.id.status_combo);
//filterStatus = combo.getSelectedItemPosition() - 1;//The next version re-add please
filterStatus = combo.getSelectedItemPosition() - 0;
combo = (Spinner) findViewById(R.id.max_time_old_event_combo);
@ -363,7 +389,6 @@ public class Main extends Activity {
text = (EditText) findViewById(R.id.event_search_text);
filterEventSearch = text.getText().toString();
SharedPreferences preferences = getSharedPreferences(
this.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
@ -381,17 +406,21 @@ public class Main extends Activity {
this.core.startServiceEventWatcher(getApplicationContext());
Toast toast = Toast.makeText(getApplicationContext(),
this.getString(R.string.filter_update_succesful_str), Toast.LENGTH_SHORT);
this.getString(R.string.filter_update_succesful_str),
Toast.LENGTH_SHORT);
toast.show();
}
else {
} else {
Toast toast = Toast.makeText(getApplicationContext(),
this.getString(R.string.filter_update_fail_str), Toast.LENGTH_SHORT);
this.getString(R.string.filter_update_fail_str),
Toast.LENGTH_SHORT);
toast.show();
}
}
public void reset_form() {
/**
* Resets the filter form.
*/
private void reset_form() {
EditText text = (EditText) findViewById(R.id.agent_name);
text.setText("");
@ -405,21 +434,10 @@ public class Main extends Activity {
combo.setSelection(6);
combo = (Spinner) findViewById(R.id.status_combo);
combo.setSelection(4);
combo.setSelection(3);
text = (EditText) findViewById(R.id.event_search_text);
text.setText("");
/*
Calendar c = Calendar.getInstance();
DatePicker datePicker = (DatePicker)findViewById(R.id.date);
datePicker.updateDate(c.get(Calendar.YEAR),
c.get(Calendar.MONTH),
c.get(Calendar.DAY_OF_MONTH));
TimePicker timePicker = (TimePicker)findViewById(R.id.time);
timePicker.setCurrentHour(c.get(Calendar.HOUR_OF_DAY));
timePicker.setCurrentMinute(c.get(Calendar.MINUTE));
*/
}
}

View File

@ -1,25 +1,58 @@
/*
Pandora FMS - http://pandorafms.com
==================================================
Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
Please see http://pandorafms.org for full contribution list
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation; version 2
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
package pandroid_event_viewer.pandorafms;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
/**
* Options activity.
*
* @author Miguel de Dios Matías
*
*/
public class Options extends Activity {
public String url;
public String user;
public String password;
public int refreshTimeKey;
private static String TAG = "Options";
private static int RINGTONE_PICK_CODE = 999;
private String url;
private String user;
private String password;
private int refreshTimeKey;
private TextView connectionStatus;
public Core core;
public PandroidEventviewerActivity object;
private Core core;
private PandroidEventviewerActivity object;
@Override
public void onCreate(Bundle savedInstanceState) {
@ -27,18 +60,17 @@ public class Options extends Activity {
Intent i = getIntent();
this.core = (Core) i.getSerializableExtra("core");
//this.object = (PandroidEventviewerActivity)i.getSerializableExtra("object");
//this.core = this.object.core;
setContentView(R.layout.options);
connectionStatus = (TextView) findViewById(R.id.check_connection_status);
new CheckConnectionAsyncTask().execute();
SharedPreferences preferences = getSharedPreferences(
this.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
url = preferences.getString("url", "http://firefly.artica.es/pandora_demo");
// Connection
url = preferences.getString("url",
"http://firefly.artica.es/pandora_demo");
user = preferences.getString("user", "demo");
password = preferences.getString("password", "demo");
refreshTimeKey = preferences.getInt("refreshTimeKey", 3);
@ -52,7 +84,8 @@ public class Options extends Activity {
Spinner combo = (Spinner) findViewById(R.id.refresh_combo);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.refresh_combo, android.R.layout.simple_spinner_item);
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);
@ -62,22 +95,75 @@ public class Options extends Activity {
@Override
public void onClick(View v) {
save_options();
new CheckConnectionAsyncTask().execute();
}
});
if (this.object.show_popup_info) {
if (this.object != null && this.object.show_popup_info) {
this.object.show_popup_info = false;
i = new Intent(this, About.class);
startActivity(i);
}
// Notification
boolean vibration = preferences.getBoolean("vibration", true);
CheckBox cb = (CheckBox) findViewById(R.id.vibration_on);
cb.setChecked(vibration);
boolean led = preferences.getBoolean("led", false);
cb = (CheckBox) findViewById(R.id.led_flash_on);
cb.setChecked(led);
Button notificationSound = (Button) findViewById(R.id.sound_button);
Uri defaultSoundUri = Uri.parse(preferences.getString(
"notification_sound_uri",
RingtoneManager
.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
.toString()));
this.setNewRingtone(notificationSound, defaultSoundUri);
notificationSound.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Log.i(TAG, "Selecting ringtone");
Intent intent = new Intent(
RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE,
getString(R.string.select_sound));
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT,
false);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT,
true);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE,
RingtoneManager.TYPE_NOTIFICATION);
startActivityForResult(intent, RINGTONE_PICK_CODE);
}
});
}
public void save_options() {
// Gets sound selected
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RINGTONE_PICK_CODE) {
if (data != null) {
Uri uri = data
.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
this.setNewRingtone(((Button) findViewById(R.id.sound_button)),
uri);
}
}
}
/**
* Saves all options
*/
private void save_options() {
SharedPreferences preferences = getSharedPreferences(
this.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
SharedPreferences.Editor editorPreferences = preferences.edit();
// Connection settings
EditText text = (EditText) findViewById(R.id.url);
String url = text.getText().toString();
if (url.charAt(url.length() - 1) == '/') {
@ -85,32 +171,112 @@ public class Options extends Activity {
}
editorPreferences.putString("url", url);
//this.object.url = url;
text = (EditText) findViewById(R.id.user);
editorPreferences.putString("user", text.getText().toString());
//this.object.user = text.getText().toString();
text = (EditText) findViewById(R.id.password);
editorPreferences.putString("password", text.getText().toString());
//this.object.password = text.getText().toString();
Spinner combo = (Spinner) findViewById(R.id.refresh_combo);
editorPreferences.putInt("refreshTimeKey", combo.getSelectedItemPosition());
editorPreferences.putInt("refreshTimeKey",
combo.getSelectedItemPosition());
// Notification settings
CheckBox cb = (CheckBox) findViewById(R.id.vibration_on);
editorPreferences.putBoolean("vibration", cb.isChecked());
cb = (CheckBox) findViewById(R.id.led_flash_on);
editorPreferences.putBoolean("led", cb.isChecked());
Context context = this.getApplicationContext();
int duration = Toast.LENGTH_SHORT;
if (editorPreferences.commit()) {
if (this.core != null) {
this.core.stopServiceEventWatcher(getApplicationContext());
this.core.startServiceEventWatcher(getApplicationContext());
}
Log.i(TAG, "Settings saved");
Toast toast = Toast.makeText(context,
this.getString(R.string.config_update_succesful_str),
Toast.LENGTH_SHORT);
toast.show();
} else {
Toast toast = Toast.makeText(context,
this.getString(R.string.config_update_fail_str),
Toast.LENGTH_LONG);
toast.show();
}
}
Toast toast = Toast.makeText(context, this.getString(R.string.config_update_succesful_str), duration);
toast.show();
/**
* Sets ringtone's title (shortens it if necessary) on the button and
* changes ringtone's uri in options. If there is a problem with the given
* Uri, just put "Silence".
*
* @param button
* Target button.
* @param uri
* Ringtone's uri.
*/
private void setNewRingtone(Button button, Uri uri) {
if (uri != null) {
Log.i(TAG, "New ringtone selected: " + uri.toString());
SharedPreferences preferences = getSharedPreferences(
this.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
SharedPreferences.Editor editorPreferences = preferences.edit();
editorPreferences.putString("notification_sound_uri",
uri.toString());
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(),
uri);
if (editorPreferences.commit()) {
Log.i(TAG, "New ringtone saved.");
} else {
Log.e(TAG, "Problem saving new ringtone preference.");
}
if (r != null) {
String text = r.getTitle(getApplicationContext());
if (text.length() > 15) {
button.setText(text.substring(0, 15) + "...");
} else {
button.setText(text);
}
} else {
Log.e(TAG, "Sound setting problem (null ringtone)");
button.setText(getString(R.string.silence));
}
} else {
Log.e(TAG, "Sound setting problem (null uri)");
button.setText(getString(R.string.silence));
}
}
/**
* Checks if connection parameters are ok.
*
* @author Santiago Munín González
*
*/
private class CheckConnectionAsyncTask extends AsyncTask<Void, Void, Void> {
private boolean connectionOk = false;
@Override
protected Void doInBackground(Void... arg0) {
// TODO implement check
this.connectionOk = false;
return null;
}
/**
* Choose an image (ok or wrong)
*/
protected void onPostExecute(Void v) {
if (this.connectionOk) {
connectionStatus.setCompoundDrawablesWithIntrinsicBounds(0, 0,
0, R.drawable.ok);
} else {
connectionStatus.setCompoundDrawablesWithIntrinsicBounds(0, 0,
0, R.drawable.cross);
}
else {
Toast toast = Toast.makeText(context, this.getString(R.string.config_update_fail_str), duration);
toast.show();
}
}
}

View File

@ -1,16 +1,19 @@
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
// Please see http://pandorafms.org for full contribution list
/*
Pandora FMS - http://pandorafms.com
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation; version 2
==================================================
Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
Please see http://pandorafms.org for full contribution list
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation; version 2
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
package pandroid_event_viewer.pandorafms;
@ -29,8 +32,6 @@ import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import pandroid_event_viewer.pandorafms.R;
import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
@ -42,7 +43,9 @@ import android.util.Log;
import android.widget.TabHost;
import android.widget.Toast;
public class PandroidEventviewerActivity extends TabActivity implements Serializable {
public class PandroidEventviewerActivity extends TabActivity implements
Serializable {
private static String TAG = "PandroidEventviewerActivity";
private static final long serialVersionUID = 1L;
// Data aplication
@ -70,14 +73,11 @@ public class PandroidEventviewerActivity extends TabActivity implements Serializ
public String eventSearch;
public int filterLastTime;
public Intent intent_service;
public Core core;
private Core core;
public boolean showOptionsFirstTime;
public boolean showTabListFirstTime;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -108,8 +108,7 @@ public class PandroidEventviewerActivity extends TabActivity implements Serializ
startActivity(i);
this.showOptionsFirstTime = true;
}
else {
} else {
this.loadInProgress = true;
this.showOptionsFirstTime = false;
@ -123,7 +122,8 @@ public class PandroidEventviewerActivity extends TabActivity implements Serializ
this.status = preferences.getInt("filterStatus", 3);
this.eventSearch = preferences.getString("filterEventSearch", "");
this.filterLastTime = preferences.getInt("filterLastTime", 6);
this.timestamp = this.core.convertMaxTimeOldEventValuesToTimestamp(0, this.filterLastTime);
this.timestamp = this.core.convertMaxTimeOldEventValuesToTimestamp(0,
this.filterLastTime);
this.eventList = new ArrayList<EventListItem>();
this.getNewListEvents = true;
@ -137,24 +137,24 @@ public class PandroidEventviewerActivity extends TabActivity implements Serializ
i_main.putExtra("object", this);
i_main.putExtra("core", this.core);
tabHost.addTab
(
tabHost.newTabSpec(getResources().getString(R.string.item_tab_main_text))
.setIndicator(getResources().getString(R.string.item_tab_main_text)
)
.setContent(i_main)
);
tabHost.addTab(tabHost
.newTabSpec(
getResources().getString(R.string.item_tab_main_text))
.setIndicator(
getResources().getString(R.string.item_tab_main_text))
.setContent(i_main));
Intent i_event_list = new Intent(this, EventList.class);
i_event_list.putExtra("object", this);
tabHost.addTab
(
tabHost.newTabSpec(getResources().getString(R.string.item_tab_event_list_text))
.setIndicator(getResources().getString(R.string.item_tab_event_list_text)
)
.setContent(i_event_list)
);
tabHost.addTab(tabHost
.newTabSpec(
getResources().getString(
R.string.item_tab_event_list_text))
.setIndicator(
getResources().getString(
R.string.item_tab_event_list_text))
.setContent(i_event_list));
tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = 45;
tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = 45;
@ -170,8 +170,7 @@ public class PandroidEventviewerActivity extends TabActivity implements Serializ
if (count_events > 0) {
process_notification(i);
}
else {
} else {
if (this.showTabListFirstTime) {
executeBackgroundGetEvents();
this.showTabListFirstTime = false;
@ -189,7 +188,12 @@ public class PandroidEventviewerActivity extends TabActivity implements Serializ
process_notification(intent);
}
public void process_notification(Intent intent) {
/**
* Processes status bar notifications' clicks.
*
* @param intent
*/
private void process_notification(Intent intent) {
long count_events = intent.getLongExtra("count_events", 0);
int more_criticity = intent.getIntExtra("more_criticity", -1);
@ -224,18 +228,20 @@ public class PandroidEventviewerActivity extends TabActivity implements Serializ
break;
}
Toast toast = Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT);
Toast toast = Toast.makeText(getApplicationContext(), text,
Toast.LENGTH_SHORT);
toast.show();
//Set the same parameters to extract the events of the notification.
// Set the same parameters to extract the events of the
// notification.
SharedPreferences preferences = getSharedPreferences(
getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
long timestamp_notification = preferences.getLong("previous_filterTimestamp", (new Date().getTime() / 1000));
Log.e("PandroidEventviewerActivity process_notification", "time_noti = " + timestamp_notification);
long timestamp_notification = preferences.getLong(
"previous_filterTimestamp", (new Date().getTime() / 1000));
Log.i(TAG + " process_notification_timestamp", ""
+ timestamp_notification);
this.timestamp = timestamp_notification;
Log.e("PandroidEventviewerActivity process_notification", "" +this.timestamp);
this.agentNameStr = preferences.getString("filterAgentName", "");
this.id_group = preferences.getInt("filterIDGroup", 0);
this.severity = preferences.getInt("filterSeverity", -1);
@ -251,7 +257,12 @@ public class PandroidEventviewerActivity extends TabActivity implements Serializ
}
}
public String serializeParams2Api() {
/**
* Serializes all params.
*
* @return All params in a string.
*/
private String serializeParams2Api() {
String return_var = "";
return_var += ';'; // Separator for the csv
@ -272,18 +283,25 @@ public class PandroidEventviewerActivity extends TabActivity implements Serializ
return_var += "|";
return_var += this.status; // The status
return_var += "|";
return_var += this.eventSearch; //The free search in the text event description.
return_var += this.eventSearch; // The free search in the text event
// description.
return_var += "|";
return_var += Integer.toString(this.pagination); //The pagination of list events
return_var += Integer.toString(this.pagination); // The pagination of
// list events
return_var += "|";
return_var += Long.toString(this.offset); // The offset of list events
Log.e("PandroidEventviewerActivity serializeParams2Api", return_var);
Log.i(TAG + " serializeParams2Api", return_var);
return return_var;
}
public void getEvents(boolean newEvents) {
/**
* Get events from pandora console.
*
* @param newEvents
*/
private void getEvents(boolean newEvents) {
SharedPreferences preferences = getSharedPreferences(
this.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
@ -309,18 +327,20 @@ public class PandroidEventviewerActivity extends TabActivity implements Serializ
parameters.add(new BasicNameValuePair("pass", 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("other_mode",
"url_encode_separator_|"));
parameters.add(new BasicNameValuePair("return_type", "csv"));
parameters.add(new BasicNameValuePair("other", serializeParams2Api() + "|total"));
parameters.add(new BasicNameValuePair("other",
serializeParams2Api() + "|total"));
entity = new UrlEncodedFormEntity(parameters);
httpPost.setEntity(entity);
response = httpClient.execute(httpPost);
entityResponse = response.getEntity();
return_api = Core.convertStreamToString(entityResponse.getContent());
return_api = Core
.convertStreamToString(entityResponse.getContent());
return_api = return_api.replace("\n", "");
Log.e("PandroidEventviewerActivity getEvents", return_api);
Log.i(TAG + " getEvents", return_api);
this.count_events = new Long(return_api).longValue();
Log.e("getEvents", return_api);
if (this.count_events == 0) {
return;
@ -332,40 +352,45 @@ public class PandroidEventviewerActivity extends TabActivity implements Serializ
parameters.add(new BasicNameValuePair("pass", 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("other_mode",
"url_encode_separator_|"));
parameters.add(new BasicNameValuePair("return_type", "csv"));
parameters.add(new BasicNameValuePair("other", serializeParams2Api()));
parameters.add(new BasicNameValuePair("other",
serializeParams2Api()));
entity = new UrlEncodedFormEntity(parameters);
httpPost.setEntity(entity);
response = httpClient.execute(httpPost);
entityResponse = response.getEntity();
return_api = Core.convertStreamToString(entityResponse.getContent());
return_api = return_api.replaceAll("\\<.*?\\>", ""); //Clean html tags.
return_api = Core
.convertStreamToString(entityResponse.getContent());
return_api = return_api.replaceAll("\\<.*?\\>", ""); // Clean html
// tags.
//Work around for the crap of \n in this event bad xml
//return_api = return_api.replaceAll("Unable to process XML data file [^\n]*\n[^\n]*line 187 thread .\n", "Bad XML");
Pattern pattern = Pattern.compile("Unable to process XML data file '(.*)'");
Pattern pattern = Pattern
.compile("Unable to process XML data file '(.*)'");
Matcher matcher;
String filename;
boolean endReplace = false; int i22 = 0;
while (!endReplace) { Log.e("loop", i22 + ""); i22++;
boolean endReplace = false;
int i22 = 0;
while (!endReplace) {
Log.i(TAG + " getEvents - loop", i22 + "");
i22++;
matcher = pattern.matcher(return_api);
if (matcher.find()) {
filename = matcher.group(1);
return_api = return_api.replaceFirst("Unable to process XML data file[^\n]*\n[^\n]*line 187 thread .*\n", "Bad XML: " + filename);
}
else {
return_api = return_api
.replaceFirst(
"Unable to process XML data file[^\n]*\n[^\n]*line 187 thread .*\n",
"Bad XML: " + filename);
} else {
endReplace = true;
}
}
Log.e("return_api", return_api);
Log.i(TAG + " getEvents - return_api", return_api);
String[] lines = return_api.split("\n");
@ -379,59 +404,51 @@ public class PandroidEventviewerActivity extends TabActivity implements Serializ
EventListItem event = new EventListItem();
if (items.length != 21) {
event.event = getApplication().getString(R.string.unknown_event_str);
}
else {
event.event = getApplication().getString(
R.string.unknown_event_str);
} else {
if (items[0].length() == 0) {
event.id_event = 0;
}
else {
} else {
event.id_event = Integer.parseInt(items[0]);
}
if (items[1].length() == 0) {
event.id_agent = 0;
}
else {
} else {
event.id_agent = Integer.parseInt(items[1]);
}
event.id_user = items[2];
if (items[3].length() == 0) {
event.id_group = 0;
}
else {
} else {
event.id_group = Integer.parseInt(items[3]);
}
if (items[4].length() == 0) {
event.status = 0;
}
else {
} else {
event.status = Integer.parseInt(items[4]);
}
event.timestamp = items[5];
event.event = items[6];
if (items[7].length() == 0) {
event.utimestamp = 0;
}
else {
} else {
event.utimestamp = Integer.parseInt(items[7]);
}
event.event_type = items[8];
if (items[9].length() == 0) {
event.id_agentmodule = 0;
}
else {
} else {
event.id_agentmodule = Integer.parseInt(items[9]);
}
if (items[10].length() == 0) {
event.id_alert_am = 0;
}
else {
} else {
event.id_alert_am = Integer.parseInt(items[10]);
}
if (items[11].length() == 0) {
event.criticity = 0;
}
else {
} else {
event.criticity = Integer.parseInt(items[11]);
}
event.user_comment = items[12];
@ -448,29 +465,34 @@ public class PandroidEventviewerActivity extends TabActivity implements Serializ
}
this.eventList.add(event);
}
//this.count_events = (long)this.eventList.size();
}
catch (Exception e) {
Log.e("EXCEPTION PandroidEventviewerActivity getEvents", e.getMessage());
} catch (Exception e) {
Log.e(TAG + " getEvents", e.getMessage());
return;
}
}
/**
* Executes the async task of getting events.
*/
public void executeBackgroundGetEvents() {
new GetEventsAsyncTask().execute();
}
/**
* Get events from pandora console (async task)
*
* @author Miguel de Dios Matías
*
*/
public class GetEventsAsyncTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
Log.e("GetEventsAsyncTask doInBackground", "doInBackground");
Log.i(TAG + " GetEventsAsyncTask", "doInBackground");
if (getNewListEvents) {
getEvents(true);
}
else {
} else {
getEvents(false);
}
@ -478,8 +500,7 @@ public class PandroidEventviewerActivity extends TabActivity implements Serializ
}
@Override
protected void onPostExecute(Void unused)
{
protected void onPostExecute(Void unused) {
Intent i = new Intent("eventlist.java");
if (getNewListEvents) {
@ -487,8 +508,7 @@ public class PandroidEventviewerActivity extends TabActivity implements Serializ
getNewListEvents = false;
i.putExtra("load_more", 0);
}
else {
} else {
i.putExtra("load_more", 1);
}

View File

@ -1,3 +1,19 @@
/*
Pandora FMS - http://pandorafms.com
==================================================
Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
Please see http://pandorafms.org for full contribution list
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation; version 2
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
package pandroid_event_viewer.pandorafms;
import android.app.Activity;
@ -9,8 +25,14 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.os.IBinder;
import android.util.Log;
/**
* This service will launch AlarmReceiver periodically.
*
* @author Miguel de Dios Matías
*
*/
public class PandroidEventviewerService extends Service {
private static String TAG = "PandroidEventviewerService";
public AlarmManager alarmM;
PendingIntent pendingI;
@ -28,12 +50,16 @@ public class PandroidEventviewerService extends Service {
int sleepTimeAlarm = convertRefreshTimeKeyToTime();
Log.e("PandroidEventviewerService", "sleepTimeAlarm = " + sleepTimeAlarm);
Log.i(TAG, "sleepTimeAlarm = " + sleepTimeAlarm);
alarmM.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), sleepTimeAlarm, this.pendingI);
alarmM.setRepeating(AlarmManager.RTC_WAKEUP,
System.currentTimeMillis(), sleepTimeAlarm, this.pendingI);
}
public int convertRefreshTimeKeyToTime() {
/**
* Converts chosen time from spinner to seconds (either are seconds or not)
* @return
*/
private int convertRefreshTimeKeyToTime() {
int returnvar = 60 * 10;
SharedPreferences preferences = getSharedPreferences(

View File

@ -1,3 +1,19 @@
/*
Pandora FMS - http://pandorafms.com
==================================================
Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
Please see http://pandorafms.org for full contribution list
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation; version 2
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
package pandroid_event_viewer.pandorafms;
import java.util.ArrayList;
@ -23,29 +39,28 @@ import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.Toast;
/**
* Provides the functionality necessary to validate an event.
*
* @author Miguel de Dios Matías
*
*/
public class PopupValidationEvent extends Activity {
public int id_event;
public String comment;
private int id_event;
private String comment;
private String url;
private String user;
private String password;
public PandroidEventviewerActivity object;
public Core core;
public String url;
public String user;
public String password;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent i = getIntent();
this.id_event = i.getIntExtra("id_event", -1);
//this.object = (PandroidEventviewerActivity)i.getSerializableExtra("object");
this.core = (Core)i.getSerializableExtra("core");
// this.core = (Core)i.getSerializableExtra("core");
setContentView(R.layout.popup_validation_event);
final Button button = (Button) findViewById(R.id.button_validate_event);
button.setOnClickListener(new View.OnClickListener() {
@ -56,7 +71,10 @@ public class PopupValidationEvent extends Activity {
});
}
public void validateEvent() {
/**
* Validates the event
*/
private void validateEvent() {
EditText textbox = (EditText) findViewById(R.id.comment);
String comment = textbox.getText().toString();
Button button = (Button) findViewById(R.id.button_validate_event);
@ -70,16 +88,26 @@ public class PopupValidationEvent extends Activity {
new SendValidationAsyncTask().execute();
}
public void destroyPopup() {
/**
* Finish the activity
*/
private void destroyPopup() {
finish();
}
public boolean sendValidation() {
/**
* Sends the validation to server.
*
* @return <b>true</b> if it was done.
*/
private boolean sendValidation() {
boolean return_var = false;
if (this.url == null) {
SharedPreferences preferences = getApplicationContext().getSharedPreferences(
getApplicationContext().getString(R.string.const_string_preferences),
SharedPreferences preferences = getApplicationContext()
.getSharedPreferences(
getApplicationContext().getString(
R.string.const_string_preferences),
Activity.MODE_PRIVATE);
this.url = preferences.getString("url", "");
@ -103,29 +131,36 @@ public class PopupValidationEvent extends Activity {
parameters.add(new BasicNameValuePair("pass", this.password));
parameters.add(new BasicNameValuePair("op", "set"));
parameters.add(new BasicNameValuePair("op2", "validate_events"));
parameters.add(new BasicNameValuePair("id", new Integer(this.id_event).toString()));
parameters.add(new BasicNameValuePair("id", new Integer(
this.id_event).toString()));
parameters.add(new BasicNameValuePair("other", this.comment));
entity = new UrlEncodedFormEntity(parameters);
httpPost.setEntity(entity);
response = httpClient.execute(httpPost);
entityResponse = response.getEntity();
return_api = Core.convertStreamToString(entityResponse.getContent());
return_api = Core
.convertStreamToString(entityResponse.getContent());
return_api = return_api.replace("\n", "");
if (return_api.startsWith("Correct validation")) {
return_var = true;
}
}
catch (Exception e) {
} catch (Exception e) {
Log.e("EXCEPTION sendValidation", e.getMessage());
}
return return_var;
}
public class SendValidationAsyncTask extends AsyncTask<Void, Void, Void> {
public ArrayList<String> lista;
public boolean result;
/**
* Sends a validation (async task)
*
* @author Miguel de Dios Matías
*
*/
private class SendValidationAsyncTask extends AsyncTask<Void, Void, Void> {
private boolean result;
@Override
protected Void doInBackground(Void... params) {
@ -135,18 +170,19 @@ public class PopupValidationEvent extends Activity {
}
@Override
protected void onPostExecute(Void unused)
{
protected void onPostExecute(Void unused) {
String text;
if (result) {
text = getApplicationContext().getString(R.string.successful_validate_event_str);
}
else {
text = getApplicationContext().getString(R.string.fail_validate_event_str);
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 toast = Toast.makeText(getApplicationContext(), text,
Toast.LENGTH_SHORT);
toast.show();
destroyPopup();