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="src"/>
<classpathentry kind="src" path="gen"/> <classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> <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> </classpath>

View File

@ -15,75 +15,78 @@
// GNU General Public License for more details. // GNU General Public License for more details.
--> -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="pandroid_event_viewer.pandorafms" package="pandroid_event_viewer.pandorafms"
android:versionCode="2" android:versionCode="2"
android:versionName="1.1"> 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.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.VIBRATE" />
<!-- <!--
android:configChanges="orientation|keyboardHidden" android:configChanges="orientation|keyboardHidden"
This is crazy, I want only block the screen rotation, but the android need This is crazy, I want only block the screen rotation, but the android need
two things. two things.
--> -->
<application android:icon="@drawable/pandorafms_logo" <application
android:label="Pandroid Event viewer" android:description="@string/pandroid_event_viewer_description_str"
android:description="@string/pandroid_event_viewer_description_str" android:icon="@drawable/pandorafms_logo"
> android:label="Pandroid Event viewer" >
<activity <activity
android:name=".PandroidEventviewerActivity" android:name=".PandroidEventviewerActivity"
android:label="Pandroid Event viewer" android:configChanges="orientation|keyboardHidden"
android:theme="@android:style/Theme.NoTitleBar" android:label="Pandroid Event viewer"
android:configChanges="orientation|keyboardHidden" android:theme="@android:style/Theme.NoTitleBar" >
> <intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity <activity
android:name=".Main" android:name=".Main"
android:configChanges="orientation|keyboardHidden" android:configChanges="orientation|keyboardHidden" >
>
</activity> </activity>
<activity <activity
android:name=".EventList" android:name=".EventList"
android:configChanges="orientation|keyboardHidden" android:configChanges="orientation|keyboardHidden" >
>
</activity> </activity>
<activity <activity
android:name=".Options" android:name=".Options"
android:label="@string/option_title_str" android:configChanges="orientation|keyboardHidden"
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"
>
</activity> </activity>
<activity <activity
android:name=".PopupValidationEvent" android:name=".About"
android:label="@string/validate_event_button_str" android:configChanges="orientation|keyboardHidden"
android:theme="@android:style/Theme.Dialog" android:label="@string/pandroid_event_viewer_str"
android:configChanges="orientation|keyboardHidden" android:theme="@android:style/Theme.Dialog" >
>
</activity> </activity>
<activity <activity
android:name=".Info" android:name=".PopupValidationEvent"
android:label="@string/pandroid_event_viewer_str" android:configChanges="orientation|keyboardHidden"
android:configChanges="orientation|keyboardHidden" android:label="@string/validate_event_button_str"
android:theme="@android:style/Theme.Dialog" android:theme="@android:style/Theme.Dialog" >
>
</activity> </activity>
<activity
<service android:name=".PandroidEventviewerService"></service> android:name=".Info"
android:configChanges="orientation|keyboardHidden"
<receiver android:process=":remote" android:name=".AlarmReceiver"></receiver> android:label="@string/pandroid_event_viewer_str"
android:theme="@android:style/Theme.Dialog" >
</activity>
<service android:name=".PandroidEventviewerService" >
</service>
<receiver
android:name=".AlarmReceiver"
android:process=":remote" >
</receiver>
</application> </application>
</manifest> </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> 2012-12-27 Miguel de Dios <miguel.dedios@artica.es>
* AndroidManifest.xml, * AndroidManifest.xml,
@ -11,8 +30,6 @@
res/values/strings.xml,res/values-en/strings.xml, res/values/strings.xml,res/values-en/strings.xml,
res/values-es/strings.xml,res/layout/info.xml: fixed some things and res/values-es/strings.xml,res/layout/info.xml: fixed some things and
added more stability and a pretty splashscreen. added more stability and a pretty splashscreen.
MERGED FROM BRANCH 4.0.2
2012-04-25 Miguel de Dios <miguel.dedios@artica.es> 2012-04-25 Miguel de Dios <miguel.dedios@artica.es>
@ -22,8 +39,6 @@
combo group because sometimes this is as null. combo group because sometimes this is as null.
Fixes: #3495038 Fixes: #3495038
MERGED FROM BRANCH 4.0.2
2011-10-24 Miguel de Dios <miguel.dedios@artica.es> 2011-10-24 Miguel de Dios <miguel.dedios@artica.es>

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

View File

@ -14,82 +14,191 @@
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
--> -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_width="fill_parent" android:layout_height="wrap_content" >
android:layout_height="fill_parent"
> <LinearLayout
<ScrollView android:layout_width="fill_parent"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:orientation="vertical" >
>
<LinearLayout <LinearLayout
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:orientation="vertical" >
>
<TextView <TextView
android:textColor="#ffffff" style="@style/options_header"
android:text="@string/url_label_str" android:layout_width="match_parent"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:orientation="vertical"
android:paddingRight="5dip" android:text="@string/connection" />
/>
<EditText <LinearLayout
android:id="@+id/url" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:singleLine="true" android:layout_margin="5dp"
android:editable="true" android:orientation="vertical" >
android:layout_width="fill_parent"
/> <TextView
<TextView android:layout_width="wrap_content"
android:textColor="#ffffff" android:layout_height="wrap_content"
android:text="@string/user_label_str" android:paddingRight="5dip"
android:layout_width="wrap_content" android:text="@string/url_label_str"
android:layout_height="wrap_content" android:textColor="#ffffff" />
android:paddingRight="5dip"
/> <EditText
<EditText android:id="@+id/url"
android:id="@+id/user" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:singleLine="true" android:inputType="textWebEditText"
android:editable="true" android:singleLine="true" />
android:layout_width="fill_parent"
/> <TextView
<TextView android:layout_width="wrap_content"
android:textColor="#ffffff" android:layout_height="wrap_content"
android:text="@string/password_label_str" android:paddingRight="5dip"
android:layout_width="wrap_content" android:text="@string/user_label_str"
android:layout_height="wrap_content" android:textColor="#ffffff" />
android:paddingRight="5dip"
/> <EditText
<EditText android:id="@+id/user"
android:id="@+id/password" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:singleLine="true" android:inputType="text"
android:editable="true" android:singleLine="true" />
android:layout_width="fill_parent"
android:inputType="textPassword" <TextView
/> android:layout_width="wrap_content"
<TextView android:layout_height="wrap_content"
android:textColor="#ffffff" android:paddingRight="5dip"
android:text="@string/refresh_time_label_str" android:text="@string/password_label_str"
android:layout_width="wrap_content" android:textColor="#ffffff" />
android:layout_height="wrap_content"
android:paddingRight="5dip" <EditText
/> android:id="@+id/password"
<Spinner android:layout_width="fill_parent"
android:id="@+id/refresh_combo" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:inputType="textPassword"
android:layout_height="wrap_content" android:singleLine="true" />
/>
<Button <RelativeLayout
android:id="@+id/update_options" android:layout_width="wrap_content"
android:text="@string/update_button_str" android:layout_height="wrap_content"
android:layout_width="fill_parent" android:layout_marginRight="5dp"
android:layout_height="wrap_content" android:layout_marginLeft="5dp"
/> android:orientation="horizontal" >
</LinearLayout>
</ScrollView> <LinearLayout
</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"
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>

View File

@ -52,7 +52,7 @@
<string name="option_title_str">Options</string> <string name="option_title_str">Options</string>
<string name="load_more_events_button_str">Load more events</string> <string name="load_more_events_button_str">Load more events</string>
<string name="empty_label_str">Empty list 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="set_as_filter_watcher_button_str">Filter by default</string>
<string name="validate_event_button_str">Validate Event</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_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> <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> <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> </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; package pandroid_event_viewer.pandorafms;
import android.app.Activity; import android.app.Activity;
@ -5,43 +21,51 @@ import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.text.Html; import android.text.Html;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.TextView; 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 { public class About extends Activity {
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.info); setContentView(R.layout.info);
TextView text = (TextView) findViewById(R.id.url_pandora); TextView text = (TextView) findViewById(R.id.url_pandora);
text.setText(Html.fromHtml("<a href='http://pandorafms.org/'>PandoraFMS.org</a>")); text.setText(Html
text.setMovementMethod(LinkMovementMethod.getInstance()); .fromHtml("<a href='http://pandorafms.org/'>PandoraFMS.org</a>"));
text.setMovementMethod(LinkMovementMethod.getInstance());
CheckBox check_show = (CheckBox)findViewById(R.id.dont_show_again_extended);
CheckBox check_show = (CheckBox) findViewById(R.id.dont_show_again_extended);
check_show.setOnClickListener(new View.OnClickListener() {
check_show.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
CheckBox check_show = (CheckBox)v; CheckBox check_show = (CheckBox) v;
if (check_show.isChecked()) { if (check_show.isChecked()) {
SharedPreferences preferences = getSharedPreferences( SharedPreferences preferences = getSharedPreferences(
getString(R.string.const_string_preferences), getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE); Activity.MODE_PRIVATE);
SharedPreferences.Editor editorPreferences = preferences.edit(); SharedPreferences.Editor editorPreferences = preferences
editorPreferences.putBoolean("show_popup_info", false); .edit();
editorPreferences.commit(); editorPreferences.putBoolean("show_popup_info", false);
} editorPreferences.commit();
else { } else {
SharedPreferences preferences = getSharedPreferences( SharedPreferences preferences = getSharedPreferences(
getString(R.string.const_string_preferences), getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE); Activity.MODE_PRIVATE);
SharedPreferences.Editor editorPreferences = preferences.edit(); SharedPreferences.Editor editorPreferences = preferences
editorPreferences.putBoolean("show_popup_info", true); .edit();
editorPreferences.commit(); 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; package pandroid_event_viewer.pandorafms;
import java.util.ArrayList; import java.util.ArrayList;
@ -20,243 +36,312 @@ import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.media.RingtoneManager;
import android.net.Uri;
import android.util.Log; import android.util.Log;
/**
* It will receive new events and launch notifications.
*
* @author Miguel de Dios Matías
*
*/
public class AlarmReceiver extends BroadcastReceiver { 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 url;
public String user; public String user;
public String password; public String password;
public long count_events; public long count_events;
public int more_criticity; public int more_criticity;
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
Log.e("AlarmReceiver", "onReceive"); Log.i(TAG, "onReceive");
checkNewEvents(context); checkNewEvents(context);
} }
/**
* Checks if there are new events and, in that case, throw a notification.
*
* @param context
*/
public void checkNewEvents(Context context) { public void checkNewEvents(Context context) {
if (this.url == null) { if (this.url == null) {
SharedPreferences preferences = context.getSharedPreferences( SharedPreferences preferences = context.getSharedPreferences(
context.getString(R.string.const_string_preferences), context.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE); Activity.MODE_PRIVATE);
this.url = preferences.getString("url", ""); this.url = preferences.getString("url", "");
this.user = preferences.getString("user", ""); this.user = preferences.getString("user", "");
this.password = preferences.getString("password", ""); this.password = preferences.getString("password", "");
Calendar c = Calendar.getInstance(); Calendar c = Calendar.getInstance();
long now = (c.getTimeInMillis() / 1000); 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)) { if ((user.length() == 0) && (password.length() == 0)
return; && (url.length() == 0)) {
} return;
}
try {
DefaultHttpClient httpClient = new DefaultHttpClient(); try {
UrlEncodedFormEntity entity; DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost; UrlEncodedFormEntity entity;
List<NameValuePair> parameters; HttpPost httpPost;
HttpResponse response; List<NameValuePair> parameters;
HttpEntity entityResponse; HttpResponse response;
String return_api; HttpEntity entityResponse;
String return_api;
httpPost = new HttpPost(this.url + "/include/api.php");
httpPost = new HttpPost(this.url + "/include/api.php");
String parametersAPI = serializeParams2Api(context);
String parametersAPI = serializeParams2Api(context);
//Get total count.
parameters = new ArrayList<NameValuePair>(); // Get total count.
parameters.add(new BasicNameValuePair("user", this.user)); parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair("pass", this.password)); parameters.add(new BasicNameValuePair("user", this.user));
parameters.add(new BasicNameValuePair("op", "get")); parameters.add(new BasicNameValuePair("pass", this.password));
parameters.add(new BasicNameValuePair("op2", "events")); parameters.add(new BasicNameValuePair("op", "get"));
parameters.add(new BasicNameValuePair("other_mode", "url_encode_separator_|")); parameters.add(new BasicNameValuePair("op2", "events"));
parameters.add(new BasicNameValuePair("return_type", "csv")); parameters.add(new BasicNameValuePair("other_mode",
parameters.add(new BasicNameValuePair("other", parametersAPI + "|total")); "url_encode_separator_|"));
entity = new UrlEncodedFormEntity(parameters); parameters.add(new BasicNameValuePair("return_type", "csv"));
httpPost.setEntity(entity); parameters.add(new BasicNameValuePair("other", parametersAPI
response = httpClient.execute(httpPost); + "|total"));
entityResponse = response.getEntity(); entity = new UrlEncodedFormEntity(parameters);
return_api = Core.convertStreamToString(entityResponse.getContent()); httpPost.setEntity(entity);
response = httpClient.execute(httpPost);
return_api = return_api.replace("\n", ""); entityResponse = response.getEntity();
Log.e("AlarmReceiver checkNewEvents", "" + return_api); return_api = Core.convertStreamToString(entityResponse
this.count_events = new Long(return_api).longValue(); .getContent());
//Check the event more critical return_api = return_api.replace("\n", "");
if (this.count_events != 0) { Log.i(TAG + " checkNewEvents", return_api);
parameters = new ArrayList<NameValuePair>(); this.count_events = new Long(return_api).longValue();
parameters.add(new BasicNameValuePair("user", this.user));
parameters.add(new BasicNameValuePair("pass", this.password)); // Check the event more critical
parameters.add(new BasicNameValuePair("op", "get")); if (this.count_events != 0) {
parameters.add(new BasicNameValuePair("op2", "events")); parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair("other_mode", "url_encode_separator_|")); parameters.add(new BasicNameValuePair("user", this.user));
parameters.add(new BasicNameValuePair("return_type", "csv")); parameters
parameters.add(new BasicNameValuePair("other", parametersAPI + "|more_criticity")); .add(new BasicNameValuePair("pass", this.password));
entity = new UrlEncodedFormEntity(parameters); parameters.add(new BasicNameValuePair("op", "get"));
httpPost.setEntity(entity); parameters.add(new BasicNameValuePair("op2", "events"));
response = httpClient.execute(httpPost); parameters.add(new BasicNameValuePair("other_mode",
entityResponse = response.getEntity(); "url_encode_separator_|"));
return_api = Core.convertStreamToString(entityResponse.getContent()); parameters
return_api = return_api.replace("\n", ""); .add(new BasicNameValuePair("return_type", "csv"));
this.more_criticity = new Integer(return_api).intValue(); parameters.add(new BasicNameValuePair("other",
parametersAPI + "|more_criticity"));
notificationEvent(context); entity = new UrlEncodedFormEntity(parameters);
} httpPost.setEntity(entity);
else { response = httpClient.execute(httpPost);
this.more_criticity = -1; entityResponse = response.getEntity();
return_api = Core.convertStreamToString(entityResponse
//Restore timestamp .getContent());
SharedPreferences.Editor editorPreferences = preferences.edit(); return_api = return_api.replace("\n", "");
editorPreferences.putLong("previous_filterTimestamp", old_previous_filterTimestamp); this.more_criticity = new Integer(return_api).intValue();
editorPreferences.commit();
} notificationEvent(context);
} else {
} this.more_criticity = -1;
catch (Exception e) {
Log.e("EXCEPTION checkNewEvents", e.getMessage()); // Restore timestamp
SharedPreferences.Editor editorPreferences = preferences
return; .edit();
} editorPreferences.putLong("previous_filterTimestamp",
old_previous_filterTimestamp);
editorPreferences.commit();
}
} catch (Exception e) {
Log.e(TAG + " EXCEPTION checkNewEvents", e.getMessage());
return;
}
} }
} }
public String serializeParams2Api(Context context) {
SharedPreferences preferences = context.getSharedPreferences(
context.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
String filterAgentName = preferences.getString("filterAgentName", "");
int filterIDGroup = preferences.getInt("filterIDGroup", 0);
int filterSeverity = preferences.getInt("filterSeverity", -1);
int filterStatus = preferences.getInt("filterStatus", 3);
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.
if (editorPreferences.commit()) {
Log.e("AlarmReceiver serializeParams2Api", "YES COMMIT");
}
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
return_var += "|";
return_var += filterAgentName; //The agent name
return_var += "|";
return_var += ""; //Name of module
return_var += "|";
return_var += ""; //Name of alert template
return_var += "|";
return_var += ""; //Id user
return_var += "|";
return_var += Long.toString(filterTimestamp); //The minimun timestamp
return_var += "|";
return_var += ""; //The maximum timestamp
return_var += "|";
return_var += filterStatus; //The status
return_var += "|";
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);
return return_var;
}
private static final int NOTIFICATION_PANDROID_EVENT_VIEWER = 666; /**
public void notificationEvent(Context context) { * Builds an api call from all filter parameters
String ns = Context.NOTIFICATION_SERVICE; *
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns); * @param context
* @return Api call.
*/
public String serializeParams2Api(Context context) {
mNotificationManager.cancel(NOTIFICATION_PANDROID_EVENT_VIEWER); SharedPreferences preferences = context.getSharedPreferences(
context.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
int icon;
CharSequence tickerText;
switch (this.more_criticity) {
case 0:
icon = R.drawable.criticity_0;
tickerText = context.getString(R.string.notification_criticity_0_str)
.replace("%s", new Long(this.count_events).toString());
break;
case 1:
icon = R.drawable.criticity_1;
tickerText = context.getString(R.string.notification_criticity_1_str)
.replace("%s", new Long(this.count_events).toString());
break;
case 2:
icon = R.drawable.criticity_2;
tickerText = context.getString(R.string.notification_criticity_2_str)
.replace("%s", new Long(this.count_events).toString());
break;
case 3:
icon = R.drawable.criticity_3;
tickerText = context.getString(R.string.notification_criticity_3_str)
.replace("%s", new Long(this.count_events).toString());
break;
case 4:
icon = R.drawable.criticity_4;
tickerText = context.getString(R.string.notification_criticity_4_str)
.replace("%s", new Long(this.count_events).toString());
break;
default:
icon = R.drawable.criticity_default;
tickerText = context.getString(R.string.notification_criticity_2_str)
.replace("%s", new Long(this.count_events).toString());
break;
}
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when); String filterAgentName = preferences.getString("filterAgentName", "");
// TODO no api parameter, waiting for it
// int filterIDGroup = preferences.getInt("filterIDGroup", 0);
notification.defaults |= Notification.DEFAULT_ALL; int filterSeverity = preferences.getInt("filterSeverity", -1);
int filterStatus = preferences.getInt("filterStatus", 3);
String filterEventSearch = preferences.getString("filterEventSearch",
notification.flags |= Notification.FLAG_AUTO_CANCEL; "");
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);
CharSequence title = context.getString(R.string.pandroid_event_viewer_str);
notification.setLatestEventInfo(context, title, tickerText, contentIntent); Calendar c = Calendar.getInstance();
long now = (c.getTimeInMillis() / 1000);
long filterTimestamp = preferences.getLong("filterTimestamp", now);
SharedPreferences.Editor editorPreferences = preferences.edit();
// Save for the next execution
mNotificationManager.notify(NOTIFICATION_PANDROID_EVENT_VIEWER, notification); editorPreferences.putLong("filterTimestamp", now);
} // Save the previous for the list.
editorPreferences.putLong("previous_filterTimestamp", filterTimestamp);
if (editorPreferences.commit()) {
Log.i(TAG + " (filter options)",
"Configuration changes commited (timestamp)");
} else {
Log.e(TAG + " (filter options)",
"Configuration changes not commited");
}
String return_var = "";
return_var += ';'; // Separator for the csv
return_var += "|";
return_var += Integer.toString(filterSeverity); // Criticity or severity
return_var += "|";
return_var += filterAgentName; // The agent name
return_var += "|";
return_var += ""; // Name of module
return_var += "|";
return_var += ""; // Name of alert template
return_var += "|";
return_var += ""; // Id user
return_var += "|";
return_var += Long.toString(filterTimestamp); // The minimun timestamp
return_var += "|";
return_var += ""; // The maximum timestamp
return_var += "|";
return_var += filterStatus; // The status
return_var += "|";
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.i(TAG + " serializeParams2Api", return_var);
return return_var;
}
/**
* Launchs a notification
*
* @param context
*/
public void notificationEvent(Context context) {
String ns = Context.NOTIFICATION_SERVICE;
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());
break;
case 1:
icon = R.drawable.criticity_1;
tickerText = context.getString(
R.string.notification_criticity_1_str).replace("%s",
new Long(this.count_events).toString());
break;
case 2:
icon = R.drawable.criticity_2;
tickerText = context.getString(
R.string.notification_criticity_2_str).replace("%s",
new Long(this.count_events).toString());
break;
case 3:
icon = R.drawable.criticity_3;
tickerText = context.getString(
R.string.notification_criticity_3_str).replace("%s",
new Long(this.count_events).toString());
break;
case 4:
icon = R.drawable.criticity_4;
tickerText = context.getString(
R.string.notification_criticity_4_str).replace("%s",
new Long(this.count_events).toString());
break;
default:
icon = R.drawable.criticity_default;
tickerText = context.getString(
R.string.notification_criticity_2_str).replace("%s",
new Long(this.count_events).toString());
break;
}
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
// 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);
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);
CharSequence title = context
.getString(R.string.pandroid_event_viewer_str);
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; package pandroid_event_viewer.pandorafms;
import java.io.BufferedReader; import java.io.BufferedReader;
@ -10,163 +26,150 @@ import java.util.Calendar;
import android.content.Context; import android.content.Context;
import android.content.Intent; 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 { public class Core implements Serializable {
private static final long serialVersionUID = 7071445033114548174L; private static final long serialVersionUID = 7071445033114548174L;
public Intent intent_service; public Intent intent_service;
//public Context context; //Fucking marshall exception
public Core() { public Core() {
intent_service = null; intent_service = null;
//context = null; //Fucking marshall exception
} }
/**
* Starts PandroidEventviewerService.
*
* @param context
*/
public void startServiceEventWatcher(Context context) { public void startServiceEventWatcher(Context context) {
if (intent_service == null) { if (intent_service == null) {
intent_service = new Intent(context, PandroidEventviewerService.class); intent_service = new Intent(context,
//this.context = context; //Fucking marshall exception PandroidEventviewerService.class);
} }
context.startService(intent_service); context.startService(intent_service);
} }
/**
* Stops PandroidEventviewerService.
*
* @param context
*/
public void stopServiceEventWatcher(Context context) { public void stopServiceEventWatcher(Context context) {
if (intent_service == null) { if (intent_service == null) {
intent_service = new Intent(context, PandroidEventviewerService.class); intent_service = new Intent(context,
//this.context = context; //Fucking marshall exception PandroidEventviewerService.class);
} }
context.stopService(this.intent_service); 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) { * Reads from the input stream and returns a string.
// TODO Auto-generated method stub *
return new Core(source); * @param is
* @return A string with all data read.
*/
public static String convertStreamToString(InputStream is) {
BufferedReader reader = new BufferedReader(new InputStreamReader(is),
8 * 1024);
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
} }
} catch (IOException e) {
@Override e.printStackTrace();
public Core[] newArray(int size) { } finally {
// TODO Auto-generated method stub try {
return new Core[size]; is.close();
} catch (IOException e) {
e.printStackTrace();
} }
}; }
@Override return sb.toString();
public int describeContents() {
// TODO Auto-generated method stub
return 0;
} }
@Override /**
public void writeToParcel(Parcel dest, int flags) { * Converts the maximum time setted to filter events to a timestamp.
// TODO Auto-generated method stub *
dest.writeValue(this.intent_service); * @param timestamp
//dest.writeValue(this.context); //Fucking marshall exception * @param arrayKey
} * @return Time in milliseconds.
*/ */
/////////// public long convertMaxTimeOldEventValuesToTimestamp(long time, int arrayKey) {
public static String convertStreamToString (InputStream is)
{
BufferedReader reader = new BufferedReader(new
InputStreamReader(is), 8*1024);
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return sb.toString();
}
public long convertMaxTimeOldEventValuesToTimestamp(long timestamp, int arrayKey) {
long time = timestamp;
long return_var = 0; long return_var = 0;
if (time == 0) { if (time == 0) {
Calendar c = Calendar.getInstance(); Calendar c = Calendar.getInstance();
time = c.getTimeInMillis() / 1000; time = c.getTimeInMillis() / 1000;
} }
switch (arrayKey) { switch (arrayKey) {
case 0: case 0:
return_var = time - 30 * 60; return_var = time - 30 * 60;
break; break;
case 1: case 1:
return_var = time - 60 * 60; return_var = time - 60 * 60;
break; break;
case 2: case 2:
return_var = time - 2 * (60 * 60); return_var = time - 2 * (60 * 60);
break; break;
case 3: case 3:
return_var = time - 3 * (60 * 60); return_var = time - 3 * (60 * 60);
break; break;
case 4: case 4:
return_var = time - 4 * (60 * 60); return_var = time - 4 * (60 * 60);
break; break;
case 5: case 5:
return_var = time - 5 * (60 * 60); return_var = time - 5 * (60 * 60);
break; break;
case 6: case 6:
return_var = time - 8 * (60 * 60); return_var = time - 8 * (60 * 60);
break; break;
case 7: case 7:
return_var = time - 10 * (60 * 60); return_var = time - 10 * (60 * 60);
break; break;
case 8: case 8:
return_var = time - 12 * (60 * 60); return_var = time - 12 * (60 * 60);
break; break;
case 9: case 9:
return_var = time - 24 * (60 * 60); return_var = time - 24 * (60 * 60);
break; break;
case 10: case 10:
return_var = time - 2 * (24 * 60 * 60); return_var = time - 2 * (24 * 60 * 60);
break; break;
case 11: case 11:
return_var = time - 3 * (24 * 60 * 60); return_var = time - 3 * (24 * 60 * 60);
break; break;
case 12: case 12:
return_var = time - 4 * (24 * 60 * 60); return_var = time - 4 * (24 * 60 * 60);
break; break;
case 13: case 13:
return_var = time - 5 * (24 * 60 * 60); return_var = time - 5 * (24 * 60 * 60);
break; break;
case 14: case 14:
return_var = time - 7 * (24 * 60 * 60); return_var = time - 7 * (24 * 60 * 60);
break; break;
case 15: case 15:
return_var = time - 2 * (7 * 24 * 60 * 60); return_var = time - 2 * (7 * 24 * 60 * 60);
break; break;
case 16: case 16:
return_var = time - 30 * (24 * 60 * 60); return_var = time - 30 * (24 * 60 * 60);
break; break;
} }
return return_var; return return_var;
} }
} }

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; package pandroid_event_viewer.pandorafms;
/**
* This class represents an event.
*
* @author Miguel de Dios Matías
*
*/
public class EventListItem { public class EventListItem {
public int id_event; public int id_event;
public int id_agent; public int id_agent;
@ -22,9 +44,9 @@ public class EventListItem {
public String description_image; public String description_image;
public String criticity_name; public String criticity_name;
public String criticity_image; public String criticity_image;
public boolean opened; public boolean opened;
public EventListItem() { public EventListItem() {
id_event = 0; id_event = 0;
id_agent = 0; id_agent = 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; package pandroid_event_viewer.pandorafms;
import android.app.Activity; import android.app.Activity;
@ -6,15 +22,21 @@ import android.text.Html;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;
import android.widget.TextView; 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 { public class Info extends Activity {
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.about);
setContentView(R.layout.about);
TextView text = (TextView) findViewById(R.id.url_pandora);
TextView text = (TextView) findViewById(R.id.url_pandora); text.setText(Html
text.setText(Html.fromHtml("<a href='http://pandorafms.org/'>PandoraFMS.org</a>")); .fromHtml("<a href='http://pandorafms.org/'>PandoraFMS.org</a>"));
text.setMovementMethod(LinkMovementMethod.getInstance()); 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; package pandroid_event_viewer.pandorafms;
import java.util.ArrayList; import java.util.ArrayList;
@ -5,6 +21,7 @@ import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
@ -32,394 +49,395 @@ import android.widget.ProgressBar;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.Toast; import android.widget.Toast;
/**
* Activity with the filter options.
*
* @author Miguel de Dios Matías
*
*/
public class Main extends Activity { public class Main extends Activity {
public PandroidEventviewerActivity object; private static String TAG = "MAIN";
public HashMap<Integer, String> pandoraGroups; private PandroidEventviewerActivity object;
public Spinner comboSeverity; private HashMap<Integer, String> pandoraGroups;
public Core core; private Spinner comboSeverity;
private Core core;
/** Called when the activity is first created. */
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
Intent i = getIntent(); Intent i = getIntent();
this.object = (PandroidEventviewerActivity)i.getSerializableExtra("object"); this.object = (PandroidEventviewerActivity) i
this.core = (Core)i.getSerializableExtra("core"); .getSerializableExtra("object");
this.core = (Core) i.getSerializableExtra("core");
this.pandoraGroups = new HashMap<Integer, String>(); this.pandoraGroups = new HashMap<Integer, String>();
setContentView(R.layout.main); setContentView(R.layout.main);
final Button buttonReset = (Button) findViewById(R.id.button_reset); final Button buttonReset = (Button) findViewById(R.id.button_reset);
final Button buttonSearch = (Button) findViewById(R.id.button_send); final Button buttonSearch = (Button) findViewById(R.id.button_send);
final Button buttonbuttonSetAsFilterWatcher = (Button) findViewById(R.id.button_set_as_filter_watcher); final Button buttonbuttonSetAsFilterWatcher = (Button) findViewById(R.id.button_set_as_filter_watcher);
//Check if the user preferences it is set. // Check if the user preferences it is set.
if (object.user.length() == 0 || object.password.length() == 0 || if (object.user.length() == 0 || object.password.length() == 0
object.url.length() == 0) { || object.url.length() == 0) {
Toast toast = Toast.makeText(this.getApplicationContext(), Toast toast = Toast.makeText(this.getApplicationContext(),
this.getString(R.string.please_set_preferences_str), this.getString(R.string.please_set_preferences_str),
Toast.LENGTH_SHORT); Toast.LENGTH_SHORT);
toast.show(); toast.show();
buttonReset.setEnabled(false); buttonReset.setEnabled(false);
buttonSearch.setEnabled(false); buttonSearch.setEnabled(false);
buttonbuttonSetAsFilterWatcher.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(), Toast toast = Toast.makeText(this.getApplicationContext(),
this.getString(R.string.preferences_set_demo_pandora_str), this.getString(R.string.preferences_set_demo_pandora_str),
Toast.LENGTH_LONG); Toast.LENGTH_LONG);
toast.show(); toast.show();
} } else {
else {
buttonSearch.setEnabled(false); buttonSearch.setEnabled(false);
buttonReset.setEnabled(false); buttonReset.setEnabled(false);
buttonbuttonSetAsFilterWatcher.setEnabled(false); buttonbuttonSetAsFilterWatcher.setEnabled(false);
new GetGroupsAsyncTask().execute(); new GetGroupsAsyncTask().execute();
} }
SharedPreferences preferences = getSharedPreferences( SharedPreferences preferences = getSharedPreferences(
this.getString(R.string.const_string_preferences), this.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE); Activity.MODE_PRIVATE);
comboSeverity = (Spinner) findViewById(R.id.severity_combo); comboSeverity = (Spinner) findViewById(R.id.severity_combo);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource( 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); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
comboSeverity.setAdapter(adapter); comboSeverity.setAdapter(adapter);
Spinner combo; Spinner combo;
combo = (Spinner) findViewById(R.id.status_combo); combo = (Spinner) findViewById(R.id.status_combo);
adapter = ArrayAdapter.createFromResource( adapter = ArrayAdapter.createFromResource(this,
this, R.array.event_status_values, android.R.layout.simple_spinner_item); R.array.event_status_values,
android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
combo.setAdapter(adapter); combo.setAdapter(adapter);
combo.setSelection(3); combo.setSelection(3);
combo = (Spinner) findViewById(R.id.max_time_old_event_combo); combo = (Spinner) findViewById(R.id.max_time_old_event_combo);
adapter = ArrayAdapter.createFromResource( adapter = ArrayAdapter.createFromResource(this,
this, R.array.max_time_old_event_values, android.R.layout.simple_spinner_item); R.array.max_time_old_event_values,
android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
combo.setAdapter(adapter); combo.setAdapter(adapter);
combo.setSelection(preferences.getInt("filterLastTime", 6)); combo.setSelection(preferences.getInt("filterLastTime", 6));
buttonReset.setOnClickListener(new View.OnClickListener() { buttonReset.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
reset_form(); reset_form();
} }
}); });
buttonSearch.setOnClickListener(new View.OnClickListener() { buttonSearch.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
search_form(); search_form();
} }
}); });
buttonbuttonSetAsFilterWatcher.setOnClickListener(new View.OnClickListener() { buttonbuttonSetAsFilterWatcher
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) { @Override
save_filter_watcher(); public void onClick(View v) {
} save_filter_watcher();
}); }
});
if (this.object.show_popup_info) {
this.object.show_popup_info = false; if (this.object.show_popup_info) {
i = new Intent(this, About.class); this.object.show_popup_info = false;
startActivity(i); i = new Intent(this, About.class);
} startActivity(i);
}
} }
public void onRestart() { public void onRestart() {
super.onRestart(); super.onRestart();
if (this.pandoraGroups.size() == 0) { if (this.pandoraGroups.size() == 0) {
Log.e("Main onRestart", "Main onRestart"); Log.i(TAG, "onRestart: getting groups");
new GetGroupsAsyncTask().execute(); 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>(); ArrayList<String> array = new ArrayList<String>();
SharedPreferences preferences = getSharedPreferences( SharedPreferences preferences = getSharedPreferences(
this.getString(R.string.const_string_preferences), this.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE); Activity.MODE_PRIVATE);
String url = preferences.getString("url", ""); String url = preferences.getString("url", "");
String user = preferences.getString("user", ""); String user = preferences.getString("user", "");
String password = preferences.getString("password", ""); String password = preferences.getString("password", "");
try { try {
DefaultHttpClient httpClient = new DefaultHttpClient(); DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url + "/include/api.php"); HttpPost httpPost = new HttpPost(url + "/include/api.php");
List<NameValuePair> parameters = new ArrayList<NameValuePair>(); List<NameValuePair> parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair("user", user)); parameters.add(new BasicNameValuePair("user", user));
parameters.add(new BasicNameValuePair("pass", password)); parameters.add(new BasicNameValuePair("pass", password));
parameters.add(new BasicNameValuePair("op", "get")); parameters.add(new BasicNameValuePair("op", "get"));
parameters.add(new BasicNameValuePair("op2", "groups")); 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("return_type", "csv"));
parameters.add(new BasicNameValuePair("other", ";")); parameters.add(new BasicNameValuePair("other", ";"));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(parameters); UrlEncodedFormEntity entity = new UrlEncodedFormEntity(parameters);
httpPost.setEntity(entity); httpPost.setEntity(entity);
HttpResponse response = httpClient.execute(httpPost); HttpResponse response = httpClient.execute(httpPost);
HttpEntity entityResponse = response.getEntity(); HttpEntity entityResponse = response.getEntity();
String return_api = Core.convertStreamToString(entityResponse.getContent()); String return_api = Core.convertStreamToString(entityResponse
.getContent());
String[] lines = return_api.split("\n"); String[] lines = return_api.split("\n");
for (int i= 0; i < lines.length; i++) { for (int i = 0; i < lines.length; i++) {
String[] groups = lines[i].split(";", 21); String[] groups = lines[i].split(";", 21);
this.pandoraGroups.put(new Integer(groups[0]), groups[1]); this.pandoraGroups.put(new Integer(groups[0]), groups[1]);
array.add(groups[1]); array.add(groups[1]);
} }
} catch (Exception e) {
Log.e(TAG +": getting groups", e.getMessage());
} }
catch (Exception e) {
Log.e("EXCEPTION ArrayList", e.getMessage());
}
return array; 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 @Override
protected Void doInBackground(Void... params) { protected Void doInBackground(Void... params) {
lista = getGroups(); list = getGroups();
return null; return null;
} }
@Override @Override
protected void onPostExecute(Void unused) protected void onPostExecute(Void unused) {
{ Spinner combo = (Spinner) findViewById(R.id.group_combo);
Spinner combo = (Spinner)findViewById(R.id.group_combo);
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(getApplicationContext(), getApplicationContext(),
android.R.layout.simple_spinner_item, android.R.layout.simple_spinner_item, list);
lista);
combo.setAdapter(spinnerArrayAdapter); combo.setAdapter(spinnerArrayAdapter);
combo.setSelection(0); combo.setSelection(0);
ProgressBar loadingGroup = (ProgressBar) findViewById(R.id.loading_group); ProgressBar loadingGroup = (ProgressBar) findViewById(R.id.loading_group);
loadingGroup.setVisibility(ProgressBar.GONE); loadingGroup.setVisibility(ProgressBar.GONE);
combo.setVisibility(Spinner.VISIBLE); combo.setVisibility(Spinner.VISIBLE);
Button buttonReset = (Button) findViewById(R.id.button_reset); Button buttonReset = (Button) findViewById(R.id.button_reset);
Button buttonSearch = (Button) findViewById(R.id.button_send); Button buttonSearch = (Button) findViewById(R.id.button_send);
Button buttonbuttonSetAsFilterWatcher = (Button) findViewById(R.id.button_set_as_filter_watcher); Button buttonbuttonSetAsFilterWatcher = (Button) findViewById(R.id.button_set_as_filter_watcher);
buttonReset.setEnabled(true); buttonReset.setEnabled(true);
buttonSearch.setEnabled(true); buttonSearch.setEnabled(true);
buttonbuttonSetAsFilterWatcher.setEnabled(true); buttonbuttonSetAsFilterWatcher.setEnabled(true);
} }
} }
//For options // For options
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater(); MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.options_menu, menu); inflater.inflate(R.menu.options_menu, menu);
return true; return true;
} }
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
Intent i; Intent i;
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.options_button_menu_options: case R.id.options_button_menu_options:
i = new Intent(this, Options.class); i = new Intent(this, Options.class);
//i.putExtra("object", object); i.putExtra("core", new Core());
i.putExtra("core", new Core());
startActivity(i);
startActivity(i); break;
break; case R.id.about_button_menu_options:
case R.id.about_button_menu_options: i = new Intent(this, About.class);
i = new Intent(this, About.class); startActivity(i);
startActivity(i); break;
break;
} }
return true; return true;
} }
public void search_form() { /**
//Clean the EventList * Performs the search choice
*/
private void search_form() {
// Clean the EventList
this.object.eventList = new ArrayList<EventListItem>(); this.object.eventList = new ArrayList<EventListItem>();
this.object.loadInProgress = true; 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; int timeKey = 0;
Spinner combo = (Spinner)findViewById(R.id.max_time_old_event_combo); Spinner combo = (Spinner) findViewById(R.id.max_time_old_event_combo);
timeKey = combo.getSelectedItemPosition(); 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); EditText text = (EditText) findViewById(R.id.agent_name);
this.object.agentNameStr = text.getText().toString(); this.object.agentNameStr = text.getText().toString();
this.object.id_group = 0; this.object.id_group = 0;
combo = (Spinner) findViewById(R.id.group_combo); combo = (Spinner) findViewById(R.id.group_combo);
String selectedGroup = combo.getSelectedItem().toString(); if (combo.getSelectedItem() != null) {
String selectedGroup = combo.getSelectedItem().toString();
Iterator it = pandoraGroups.entrySet().iterator();
while (it.hasNext()) { Iterator<Entry<Integer, String>> it = pandoraGroups.entrySet()
Map.Entry<Integer, String> e = (Map.Entry<Integer, String>)it.next(); .iterator();
while (it.hasNext()) {
if (e.getValue().equals(selectedGroup)) { Map.Entry<Integer, String> e = (Map.Entry<Integer, String>) it
this.object.id_group = e.getKey(); .next();
if (e.getValue().equals(selectedGroup)) {
this.object.id_group = e.getKey();
}
} }
} }
combo = (Spinner) findViewById(R.id.severity_combo); combo = (Spinner) findViewById(R.id.severity_combo);
this.object.severity = combo.getSelectedItemPosition() - 1; this.object.severity = combo.getSelectedItemPosition() - 1;
combo = (Spinner)findViewById(R.id.status_combo); 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; this.object.status = combo.getSelectedItemPosition() - 0;
text = (EditText)findViewById(R.id.event_search_text); text = (EditText) findViewById(R.id.event_search_text);
this.object.eventSearch = text.getText().toString(); this.object.eventSearch = text.getText().toString();
this.object.getNewListEvents = true; this.object.getNewListEvents = true;
this.object.executeBackgroundGetEvents(); this.object.executeBackgroundGetEvents();
TabActivity ta = (TabActivity) this.getParent(); TabActivity ta = (TabActivity) this.getParent();
ta.getTabHost().setCurrentTab(1); ta.getTabHost().setCurrentTab(1);
} }
public void save_filter_watcher() { /**
* Saves filter data
*/
private void save_filter_watcher() {
String filterAgentName = ""; String filterAgentName = "";
int filterIDGroup = 0; int filterIDGroup = 0;
int filterSeverity = -1; int filterSeverity = -1;
int filterStatus = -1; int filterStatus = -1;
int filterLastTime = 0; int filterLastTime = 0;
String filterEventSearch = ""; String filterEventSearch = "";
EditText text = (EditText) findViewById(R.id.agent_name); EditText text = (EditText) findViewById(R.id.agent_name);
filterAgentName = text.getText().toString(); filterAgentName = text.getText().toString();
Spinner combo; Spinner combo;
combo = (Spinner) findViewById(R.id.group_combo); combo = (Spinner) findViewById(R.id.group_combo);
if ((combo != null) && (combo.getSelectedItem() != null)) { if ((combo != null) && (combo.getSelectedItem() != null)) {
String selectedGroup = combo.getSelectedItem().toString(); String selectedGroup = combo.getSelectedItem().toString();
Iterator it = pandoraGroups.entrySet().iterator(); Iterator<Entry<Integer, String>> it = pandoraGroups.entrySet()
.iterator();
while (it.hasNext()) { 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)) { if (e.getValue().equals(selectedGroup)) {
filterIDGroup = e.getKey(); filterIDGroup = e.getKey();
} }
} }
} }
combo = (Spinner) findViewById(R.id.severity_combo); combo = (Spinner) findViewById(R.id.severity_combo);
filterSeverity = combo.getSelectedItemPosition() - 1; filterSeverity = combo.getSelectedItemPosition() - 1;
combo = (Spinner)findViewById(R.id.status_combo); combo = (Spinner) findViewById(R.id.status_combo);
//filterStatus = combo.getSelectedItemPosition() - 1;//The next version re-add please
filterStatus = combo.getSelectedItemPosition() - 0; filterStatus = combo.getSelectedItemPosition() - 0;
combo = (Spinner)findViewById(R.id.max_time_old_event_combo); combo = (Spinner) findViewById(R.id.max_time_old_event_combo);
filterLastTime = combo.getSelectedItemPosition(); filterLastTime = combo.getSelectedItemPosition();
text = (EditText)findViewById(R.id.event_search_text); text = (EditText) findViewById(R.id.event_search_text);
filterEventSearch = text.getText().toString(); filterEventSearch = text.getText().toString();
SharedPreferences preferences = getSharedPreferences( SharedPreferences preferences = getSharedPreferences(
this.getString(R.string.const_string_preferences), this.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE); Activity.MODE_PRIVATE);
SharedPreferences.Editor editorPreferences = preferences.edit(); SharedPreferences.Editor editorPreferences = preferences.edit();
editorPreferences.putString("filterAgentName", filterAgentName); editorPreferences.putString("filterAgentName", filterAgentName);
editorPreferences.putInt("filterIDGroup", filterIDGroup); editorPreferences.putInt("filterIDGroup", filterIDGroup);
editorPreferences.putInt("filterSeverity", filterSeverity); editorPreferences.putInt("filterSeverity", filterSeverity);
editorPreferences.putInt("filterStatus", filterStatus); editorPreferences.putInt("filterStatus", filterStatus);
editorPreferences.putString("filterEventSearch", filterEventSearch); editorPreferences.putString("filterEventSearch", filterEventSearch);
editorPreferences.putInt("filterLastTime", filterLastTime); editorPreferences.putInt("filterLastTime", filterLastTime);
if (editorPreferences.commit()) { if (editorPreferences.commit()) {
this.core.stopServiceEventWatcher(getApplicationContext()); this.core.stopServiceEventWatcher(getApplicationContext());
this.core.startServiceEventWatcher(getApplicationContext()); this.core.startServiceEventWatcher(getApplicationContext());
Toast toast = Toast.makeText(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(); toast.show();
} } else {
else {
Toast toast = Toast.makeText(getApplicationContext(), 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(); toast.show();
} }
} }
public void reset_form() { /**
EditText text = (EditText)findViewById(R.id.agent_name); * Resets the filter form.
*/
private void reset_form() {
EditText text = (EditText) findViewById(R.id.agent_name);
text.setText(""); text.setText("");
Spinner combo = (Spinner) findViewById(R.id.group_combo); Spinner combo = (Spinner) findViewById(R.id.group_combo);
combo.setSelection(0); combo.setSelection(0);
combo = (Spinner) findViewById(R.id.severity_combo); combo = (Spinner) findViewById(R.id.severity_combo);
combo.setSelection(0); combo.setSelection(0);
combo = (Spinner)findViewById(R.id.max_time_old_event_combo); combo = (Spinner) findViewById(R.id.max_time_old_event_combo);
combo.setSelection(6); combo.setSelection(6);
combo = (Spinner) findViewById(R.id.status_combo);
combo.setSelection(3);
combo = (Spinner)findViewById(R.id.status_combo); text = (EditText) findViewById(R.id.event_search_text);
combo.setSelection(4);
text = (EditText)findViewById(R.id.event_search_text);
text.setText(""); 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,116 +1,282 @@
/*
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; package pandroid_event_viewer.pandorafms;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; 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.os.Bundle;
import android.util.Log;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText; import android.widget.EditText;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
/**
* Options activity.
*
* @author Miguel de Dios Matías
*
*/
public class Options extends Activity { public class Options extends Activity {
public String url; private static String TAG = "Options";
public String user; private static int RINGTONE_PICK_CODE = 999;
public String password; private String url;
public int refreshTimeKey; private String user;
private String password;
public Core core; private int refreshTimeKey;
public PandroidEventviewerActivity object; private TextView connectionStatus;
@Override private Core core;
public void onCreate(Bundle savedInstanceState) { private PandroidEventviewerActivity object;
super.onCreate(savedInstanceState);
@Override
Intent i = getIntent(); public void onCreate(Bundle savedInstanceState) {
this.core = (Core)i.getSerializableExtra("core"); super.onCreate(savedInstanceState);
//this.object = (PandroidEventviewerActivity)i.getSerializableExtra("object");
//this.core = this.object.core; Intent i = getIntent();
this.core = (Core) i.getSerializableExtra("core");
setContentView(R.layout.options);
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), SharedPreferences preferences = getSharedPreferences(
Activity.MODE_PRIVATE); this.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
url = preferences.getString("url", "http://firefly.artica.es/pandora_demo"); // Connection
user = preferences.getString("user", "demo"); url = preferences.getString("url",
password = preferences.getString("password", "demo"); "http://firefly.artica.es/pandora_demo");
refreshTimeKey = preferences.getInt("refreshTimeKey", 3); user = preferences.getString("user", "demo");
password = preferences.getString("password", "demo");
EditText text = (EditText) findViewById(R.id.url); refreshTimeKey = preferences.getInt("refreshTimeKey", 3);
text.setText(url);
text = (EditText) findViewById(R.id.user); EditText text = (EditText) findViewById(R.id.url);
text.setText(user); text.setText(url);
text = (EditText) findViewById(R.id.password); text = (EditText) findViewById(R.id.user);
text.setText(password); text.setText(user);
text = (EditText) findViewById(R.id.password);
Spinner combo = (Spinner) findViewById(R.id.refresh_combo); text.setText(password);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.refresh_combo, android.R.layout.simple_spinner_item); Spinner combo = (Spinner) findViewById(R.id.refresh_combo);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
combo.setAdapter(adapter); this, R.array.refresh_combo,
combo.setSelection(refreshTimeKey); android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
final Button buttonSearch = (Button) findViewById(R.id.update_options); combo.setAdapter(adapter);
buttonSearch.setOnClickListener(new View.OnClickListener() { combo.setSelection(refreshTimeKey);
final Button buttonSearch = (Button) findViewById(R.id.update_options);
buttonSearch.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
save_options(); 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; this.object.show_popup_info = false;
i = new Intent(this, About.class); i = new Intent(this, About.class);
startActivity(i); startActivity(i);
} }
}
// Notification
public void save_options() { boolean vibration = preferences.getBoolean("vibration", true);
SharedPreferences preferences = getSharedPreferences( CheckBox cb = (CheckBox) findViewById(R.id.vibration_on);
this.getString(R.string.const_string_preferences), cb.setChecked(vibration);
Activity.MODE_PRIVATE); boolean led = preferences.getBoolean("led", false);
SharedPreferences.Editor editorPreferences = preferences.edit(); cb = (CheckBox) findViewById(R.id.led_flash_on);
cb.setChecked(led);
EditText text = (EditText) findViewById(R.id.url);
String url = text.getText().toString(); Button notificationSound = (Button) findViewById(R.id.sound_button);
if (url.charAt(url.length() - 1) == '/') { Uri defaultSoundUri = Uri.parse(preferences.getString(
url = url.substring(0, url.length() - 1); "notification_sound_uri",
} RingtoneManager
.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
editorPreferences.putString("url", url); .toString()));
//this.object.url = url; this.setNewRingtone(notificationSound, defaultSoundUri);
text = (EditText) findViewById(R.id.user);
editorPreferences.putString("user", text.getText().toString()); notificationSound.setOnClickListener(new OnClickListener() {
//this.object.user = text.getText().toString(); @Override
text = (EditText) findViewById(R.id.password); public void onClick(View v) {
editorPreferences.putString("password", text.getText().toString()); Log.i(TAG, "Selecting ringtone");
//this.object.password = text.getText().toString(); Intent intent = new Intent(
RingtoneManager.ACTION_RINGTONE_PICKER);
Spinner combo = (Spinner) findViewById(R.id.refresh_combo); intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE,
editorPreferences.putInt("refreshTimeKey", combo.getSelectedItemPosition()); getString(R.string.select_sound));
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT,
Context context = this.getApplicationContext(); false);
int duration = Toast.LENGTH_SHORT; intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT,
true);
if (editorPreferences.commit()) { intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE,
if (this.core != null) { RingtoneManager.TYPE_NOTIFICATION);
this.core.stopServiceEventWatcher(getApplicationContext()); startActivityForResult(intent, RINGTONE_PICK_CODE);
this.core.startServiceEventWatcher(getApplicationContext()); }
} });
Toast toast = Toast.makeText(context, this.getString(R.string.config_update_succesful_str), duration); }
toast.show();
} // Gets sound selected
else { @Override
Toast toast = Toast.makeText(context, this.getString(R.string.config_update_fail_str), duration); protected void onActivityResult(int requestCode, int resultCode, Intent data) {
toast.show(); 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) == '/') {
url = url.substring(0, url.length() - 1);
}
editorPreferences.putString("url", url);
text = (EditText) findViewById(R.id.user);
editorPreferences.putString("user", text.getText().toString());
text = (EditText) findViewById(R.id.password);
editorPreferences.putString("password", text.getText().toString());
Spinner combo = (Spinner) findViewById(R.id.refresh_combo);
editorPreferences.putInt("refreshTimeKey",
combo.getSelectedItemPosition());
// 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();
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();
}
}
/**
* 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);
}
}
}
} }

View File

@ -1,16 +1,19 @@
// Pandora FMS - http://pandorafms.com /*
// ================================================== 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 Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
// as published by the Free Software Foundation; version 2 Please see http://pandorafms.org for full contribution list
// This program is distributed in the hope that it will be useful, This program is free software; you can redistribute it and/or
// but WITHOUT ANY WARRANTY; without even the implied warranty of modify it under the terms of the GNU Lesser General Public License
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the as published by the Free Software Foundation; version 2
// GNU General Public License for more details.
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; 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.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair; import org.apache.http.message.BasicNameValuePair;
import pandroid_event_viewer.pandorafms.R;
import android.app.Activity; import android.app.Activity;
import android.app.TabActivity; import android.app.TabActivity;
import android.content.Intent; import android.content.Intent;
@ -42,457 +43,476 @@ import android.util.Log;
import android.widget.TabHost; import android.widget.TabHost;
import android.widget.Toast; 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; private static final long serialVersionUID = 1L;
//Data aplication // Data aplication
public ArrayList<EventListItem> eventList; public ArrayList<EventListItem> eventList;
public long count_events; public long count_events;
//Flags // Flags
public boolean loadInProgress; public boolean loadInProgress;
public boolean getNewListEvents; public boolean getNewListEvents;
//Configuration // Configuration
public boolean show_popup_info; public boolean show_popup_info;
public String url; public String url;
public String user; public String user;
public String password; public String password;
//Parameters to search in the API // Parameters to search in the API
public String agentNameStr; public String agentNameStr;
public int id_group; public int id_group;
public long timestamp; public long timestamp;
public int severity; public int severity;
public int pagination; public int pagination;
public long offset; public long offset;
public int status; public int status;
public String eventSearch; public String eventSearch;
public int filterLastTime; public int filterLastTime;
public Intent intent_service; private Core core;
public Core core; public boolean showOptionsFirstTime;
public boolean showTabListFirstTime;
public boolean showOptionsFirstTime;
public boolean showTabListFirstTime; @Override
public void onCreate(Bundle savedInstanceState) {
/** Called when the activity is first created. */ super.onCreate(savedInstanceState);
@Override
public void onCreate(Bundle savedInstanceState) { SharedPreferences preferences = getSharedPreferences(
super.onCreate(savedInstanceState); this.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
SharedPreferences preferences = getSharedPreferences(
this.getString(R.string.const_string_preferences), this.show_popup_info = preferences.getBoolean("show_popup_info", true);
Activity.MODE_PRIVATE); this.url = preferences.getString("url", "");
this.user = preferences.getString("user", "");
this.show_popup_info = preferences.getBoolean("show_popup_info", true); this.password = preferences.getString("password", "");
this.url = preferences.getString("url", "");
this.user = preferences.getString("user", ""); final TabHost tabHost = getTabHost();
this.password = preferences.getString("password", "");
this.loadInProgress = false;
final TabHost tabHost = getTabHost();
this.core = new Core();
this.loadInProgress = false;
// Check if the preferences is setted, if not show the option activity.
this.core = new Core(); if ((user.length() == 0) && (password.length() == 0)
&& (url.length() == 0)) {
//Check if the preferences is setted, if not show the option activity.
if ((user.length() == 0) && (password.length() == 0) Intent i = new Intent(this, Options.class);
&& (url.length() == 0)) { // i.putExtra("object", this);
i.putExtra("core", this.core);
Intent i = new Intent(this, Options.class);
//i.putExtra("object", this); startActivity(i);
i.putExtra("core", this.core);
this.showOptionsFirstTime = true;
startActivity(i); } else {
this.loadInProgress = true;
this.showOptionsFirstTime = true;
} this.showOptionsFirstTime = false;
else { this.showTabListFirstTime = true;
this.loadInProgress = true; }
this.showOptionsFirstTime = false; this.pagination = 20;
this.showTabListFirstTime = true; this.offset = 0;
} this.agentNameStr = preferences.getString("filterAgentName", "");
this.severity = preferences.getInt("filterSeverity", -1);
this.pagination = 20; this.status = preferences.getInt("filterStatus", 3);
this.offset = 0; this.eventSearch = preferences.getString("filterEventSearch", "");
this.agentNameStr = preferences.getString("filterAgentName", ""); this.filterLastTime = preferences.getInt("filterLastTime", 6);
this.severity = preferences.getInt("filterSeverity", -1); this.timestamp = this.core.convertMaxTimeOldEventValuesToTimestamp(0,
this.status = preferences.getInt("filterStatus", 3); this.filterLastTime);
this.eventSearch = preferences.getString("filterEventSearch", "");
this.filterLastTime = preferences.getInt("filterLastTime", 6); this.eventList = new ArrayList<EventListItem>();
this.timestamp = this.core.convertMaxTimeOldEventValuesToTimestamp(0, this.filterLastTime); this.getNewListEvents = true;
this.eventList = new ArrayList<EventListItem>(); if (!this.showOptionsFirstTime) {
this.getNewListEvents = true; // Start the background service for the notifications
this.core.startServiceEventWatcher(getApplicationContext());
if (!this.showOptionsFirstTime) { }
//Start the background service for the notifications
this.core.startServiceEventWatcher(getApplicationContext()); Intent i_main = new Intent(this, Main.class);
} i_main.putExtra("object", this);
i_main.putExtra("core", this.core);
Intent i_main = new Intent(this, Main.class);
i_main.putExtra("object", this); tabHost.addTab(tabHost
i_main.putExtra("core", this.core); .newTabSpec(
getResources().getString(R.string.item_tab_main_text))
tabHost.addTab .setIndicator(
( getResources().getString(R.string.item_tab_main_text))
tabHost.newTabSpec(getResources().getString(R.string.item_tab_main_text)) .setContent(i_main));
.setIndicator(getResources().getString(R.string.item_tab_main_text)
)
.setContent(i_main)
);
Intent i_event_list = new Intent(this, EventList.class); Intent i_event_list = new Intent(this, EventList.class);
i_event_list.putExtra("object", this); i_event_list.putExtra("object", this);
tabHost.addTab tabHost.addTab(tabHost
( .newTabSpec(
tabHost.newTabSpec(getResources().getString(R.string.item_tab_event_list_text)) getResources().getString(
.setIndicator(getResources().getString(R.string.item_tab_event_list_text) R.string.item_tab_event_list_text))
) .setIndicator(
.setContent(i_event_list) 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;
}
public void onResume() {
super.onResume();
this.getTabHost().setCurrentTab(1);
Intent i = getIntent();
long count_events = i.getLongExtra("count_events", 0);
if (count_events > 0) {
process_notification(i);
}
else {
if (this.showTabListFirstTime) {
executeBackgroundGetEvents();
this.showTabListFirstTime = false;
}
}
}
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
public void onNewIntent(Intent intent) {
super.onNewIntent(intent);
process_notification(intent);
}
public void process_notification(Intent intent) {
long count_events = intent.getLongExtra("count_events", 0);
int more_criticity = intent.getIntExtra("more_criticity", -1);
CharSequence text;
if (count_events > 0) {
//From the notificy
switch (more_criticity) {
case 0:
text = getString(R.string.loading_events_criticity_0_str)
.replace("%s", new Long(count_events).toString());
break;
case 1:
text = getString(R.string.loading_events_criticity_1_str)
.replace("%s", new Long(count_events).toString());
break;
case 2:
text = getString(R.string.loading_events_criticity_2_str)
.replace("%s", new Long(count_events).toString());
break;
case 3:
text = getString(R.string.loading_events_criticity_3_str)
.replace("%s", new Long(count_events).toString());
break;
case 4:
text = getString(R.string.loading_events_criticity_4_str)
.replace("%s", new Long(count_events).toString());
break;
default:
text = getString(R.string.loading_events_criticity_2_str)
.replace("%s", new Long(count_events).toString());
break;
}
Toast toast = Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT);
toast.show();
//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);
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);
this.status = preferences.getInt("filterStatus", 3);
this.eventSearch = preferences.getString("filterEventSearch", "");
this.getTabHost().setCurrentTab(1);
this.loadInProgress = true;
this.getNewListEvents = true;
this.eventList = new ArrayList<EventListItem>();
executeBackgroundGetEvents();
}
}
public String serializeParams2Api() {
String return_var = "";
return_var += ';'; //Separator for the csv
return_var += "|";
return_var += Integer.toString(this.severity); //Criticity or severity
return_var += "|";
return_var += this.agentNameStr; //The agent name
return_var += "|";
return_var += ""; //Name of module
return_var += "|";
return_var += ""; //Name of alert template
return_var += "|";
return_var += ""; //Id user
return_var += "|";
return_var += Long.toString(this.timestamp); //The minimun timestamp
return_var += "|";
return_var += ""; //The maximum timestamp
return_var += "|";
return_var += this.status; //The status
return_var += "|";
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 += "|";
return_var += Long.toString(this.offset); //The offset of list events
Log.e("PandroidEventviewerActivity serializeParams2Api", return_var);
return return_var;
}
public void getEvents(boolean newEvents) {
SharedPreferences preferences = getSharedPreferences(
this.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
String url = preferences.getString("url", "");
String user = preferences.getString("user", "");
String password = preferences.getString("password", "");
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
UrlEncodedFormEntity entity;
HttpPost httpPost;
List<NameValuePair> parameters;
HttpResponse response;
HttpEntity entityResponse;
String return_api;
httpPost = new HttpPost(url + "/include/api.php");
//Get total count.
parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair("user", user));
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("return_type", "csv"));
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 = return_api.replace("\n", "");
Log.e("PandroidEventviewerActivity getEvents", return_api);
this.count_events = new Long(return_api).longValue();
Log.e("getEvents", return_api);
if (this.count_events == 0) {
return;
}
//Get the list of events.
parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair("user", user));
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("return_type", "csv"));
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.
//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 '(.*)'");
Matcher matcher;
String filename;
boolean endReplace = false; int i22 = 0;
while (!endReplace) { Log.e("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 {
endReplace = true;
}
}
Log.e("return_api", return_api);
String[] lines = return_api.split("\n");
if (return_api.length() == 0) {
return;
}
for (int i= 0; i < lines.length; i++) {
String[] items = lines[i].split(";", 21);
EventListItem event = new EventListItem();
if (items.length != 21) {
event.event = getApplication().getString(R.string.unknown_event_str);
}
else {
if (items[0].length() == 0) {
event.id_event = 0;
}
else {
event.id_event = Integer.parseInt(items[0]);
}
if (items[1].length() == 0) {
event.id_agent = 0;
}
else {
event.id_agent = Integer.parseInt(items[1]);
}
event.id_user = items[2];
if (items[3].length() == 0) {
event.id_group = 0;
}
else {
event.id_group = Integer.parseInt(items[3]);
}
if (items[4].length() == 0) {
event.status = 0;
}
else {
event.status = Integer.parseInt(items[4]);
}
event.timestamp = items[5];
event.event = items[6];
if (items[7].length() == 0) {
event.utimestamp = 0;
}
else {
event.utimestamp = Integer.parseInt(items[7]);
}
event.event_type = items[8];
if (items[9].length() == 0) {
event.id_agentmodule = 0;
}
else {
event.id_agentmodule = Integer.parseInt(items[9]);
}
if (items[10].length() == 0) {
event.id_alert_am = 0;
}
else {
event.id_alert_am = Integer.parseInt(items[10]);
}
if (items[11].length() == 0) {
event.criticity = 0;
}
else {
event.criticity = Integer.parseInt(items[11]);
}
event.user_comment = items[12];
event.tags = items[13];
event.agent_name = items[14];
event.group_name = items[15];
event.group_icon = items[16];
event.description_event = items[17];
event.description_image = items[18];
event.criticity_name = items[19];
event.criticity_image = items[20];
event.opened = false;
}
this.eventList.add(event);
}
//this.count_events = (long)this.eventList.size();
}
catch (Exception e) {
Log.e("EXCEPTION PandroidEventviewerActivity getEvents", e.getMessage());
return;
}
}
public void executeBackgroundGetEvents() {
new GetEventsAsyncTask().execute();
}
tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = 45;
public class GetEventsAsyncTask extends AsyncTask<Void, Void, Void> { tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = 45;
}
public void onResume() {
super.onResume();
this.getTabHost().setCurrentTab(1);
Intent i = getIntent();
long count_events = i.getLongExtra("count_events", 0);
if (count_events > 0) {
process_notification(i);
} else {
if (this.showTabListFirstTime) {
executeBackgroundGetEvents();
this.showTabListFirstTime = false;
}
}
}
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
public void onNewIntent(Intent intent) {
super.onNewIntent(intent);
process_notification(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);
CharSequence text;
if (count_events > 0) {
// From the notificy
switch (more_criticity) {
case 0:
text = getString(R.string.loading_events_criticity_0_str)
.replace("%s", new Long(count_events).toString());
break;
case 1:
text = getString(R.string.loading_events_criticity_1_str)
.replace("%s", new Long(count_events).toString());
break;
case 2:
text = getString(R.string.loading_events_criticity_2_str)
.replace("%s", new Long(count_events).toString());
break;
case 3:
text = getString(R.string.loading_events_criticity_3_str)
.replace("%s", new Long(count_events).toString());
break;
case 4:
text = getString(R.string.loading_events_criticity_4_str)
.replace("%s", new Long(count_events).toString());
break;
default:
text = getString(R.string.loading_events_criticity_2_str)
.replace("%s", new Long(count_events).toString());
break;
}
Toast toast = Toast.makeText(getApplicationContext(), text,
Toast.LENGTH_SHORT);
toast.show();
// 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.i(TAG + " process_notification_timestamp", ""
+ timestamp_notification);
this.timestamp = timestamp_notification;
this.agentNameStr = preferences.getString("filterAgentName", "");
this.id_group = preferences.getInt("filterIDGroup", 0);
this.severity = preferences.getInt("filterSeverity", -1);
this.status = preferences.getInt("filterStatus", 3);
this.eventSearch = preferences.getString("filterEventSearch", "");
this.getTabHost().setCurrentTab(1);
this.loadInProgress = true;
this.getNewListEvents = true;
this.eventList = new ArrayList<EventListItem>();
executeBackgroundGetEvents();
}
}
/**
* Serializes all params.
*
* @return All params in a string.
*/
private String serializeParams2Api() {
String return_var = "";
return_var += ';'; // Separator for the csv
return_var += "|";
return_var += Integer.toString(this.severity); // Criticity or severity
return_var += "|";
return_var += this.agentNameStr; // The agent name
return_var += "|";
return_var += ""; // Name of module
return_var += "|";
return_var += ""; // Name of alert template
return_var += "|";
return_var += ""; // Id user
return_var += "|";
return_var += Long.toString(this.timestamp); // The minimun timestamp
return_var += "|";
return_var += ""; // The maximum timestamp
return_var += "|";
return_var += this.status; // The status
return_var += "|";
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 += "|";
return_var += Long.toString(this.offset); // The offset of list events
Log.i(TAG + " serializeParams2Api", return_var);
return return_var;
}
/**
* 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);
String url = preferences.getString("url", "");
String user = preferences.getString("user", "");
String password = preferences.getString("password", "");
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
UrlEncodedFormEntity entity;
HttpPost httpPost;
List<NameValuePair> parameters;
HttpResponse response;
HttpEntity entityResponse;
String return_api;
httpPost = new HttpPost(url + "/include/api.php");
// Get total count.
parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair("user", user));
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("return_type", "csv"));
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 = return_api.replace("\n", "");
Log.i(TAG + " getEvents", return_api);
this.count_events = new Long(return_api).longValue();
if (this.count_events == 0) {
return;
}
// Get the list of events.
parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair("user", user));
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("return_type", "csv"));
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.
Pattern pattern = Pattern
.compile("Unable to process XML data file '(.*)'");
Matcher matcher;
String filename;
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 {
endReplace = true;
}
}
Log.i(TAG + " getEvents - return_api", return_api);
String[] lines = return_api.split("\n");
if (return_api.length() == 0) {
return;
}
for (int i = 0; i < lines.length; i++) {
String[] items = lines[i].split(";", 21);
EventListItem event = new EventListItem();
if (items.length != 21) {
event.event = getApplication().getString(
R.string.unknown_event_str);
} else {
if (items[0].length() == 0) {
event.id_event = 0;
} else {
event.id_event = Integer.parseInt(items[0]);
}
if (items[1].length() == 0) {
event.id_agent = 0;
} else {
event.id_agent = Integer.parseInt(items[1]);
}
event.id_user = items[2];
if (items[3].length() == 0) {
event.id_group = 0;
} else {
event.id_group = Integer.parseInt(items[3]);
}
if (items[4].length() == 0) {
event.status = 0;
} else {
event.status = Integer.parseInt(items[4]);
}
event.timestamp = items[5];
event.event = items[6];
if (items[7].length() == 0) {
event.utimestamp = 0;
} else {
event.utimestamp = Integer.parseInt(items[7]);
}
event.event_type = items[8];
if (items[9].length() == 0) {
event.id_agentmodule = 0;
} else {
event.id_agentmodule = Integer.parseInt(items[9]);
}
if (items[10].length() == 0) {
event.id_alert_am = 0;
} else {
event.id_alert_am = Integer.parseInt(items[10]);
}
if (items[11].length() == 0) {
event.criticity = 0;
} else {
event.criticity = Integer.parseInt(items[11]);
}
event.user_comment = items[12];
event.tags = items[13];
event.agent_name = items[14];
event.group_name = items[15];
event.group_icon = items[16];
event.description_event = items[17];
event.description_image = items[18];
event.criticity_name = items[19];
event.criticity_image = items[20];
event.opened = false;
}
this.eventList.add(event);
}
} 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 @Override
protected Void doInBackground(Void... params) { protected Void doInBackground(Void... params) {
Log.e("GetEventsAsyncTask doInBackground", "doInBackground"); Log.i(TAG + " GetEventsAsyncTask", "doInBackground");
if (getNewListEvents) { if (getNewListEvents) {
getEvents(true); getEvents(true);
} } else {
else {
getEvents(false); getEvents(false);
} }
return null; return null;
} }
@Override @Override
protected void onPostExecute(Void unused) protected void onPostExecute(Void unused) {
{
Intent i = new Intent("eventlist.java"); Intent i = new Intent("eventlist.java");
if (getNewListEvents) { if (getNewListEvents) {
loadInProgress = false; loadInProgress = false;
getNewListEvents = false; getNewListEvents = false;
i.putExtra("load_more", 0); i.putExtra("load_more", 0);
} } else {
else {
i.putExtra("load_more", 1); i.putExtra("load_more", 1);
} }
getApplicationContext().sendBroadcast(i); getApplicationContext().sendBroadcast(i);
} }
} }
} }

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; package pandroid_event_viewer.pandorafms;
import android.app.Activity; import android.app.Activity;
@ -9,10 +25,16 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.IBinder; import android.os.IBinder;
import android.util.Log; import android.util.Log;
/**
* This service will launch AlarmReceiver periodically.
*
* @author Miguel de Dios Matías
*
*/
public class PandroidEventviewerService extends Service { public class PandroidEventviewerService extends Service {
private static String TAG = "PandroidEventviewerService";
public AlarmManager alarmM; public AlarmManager alarmM;
PendingIntent pendingI; PendingIntent pendingI;
@Override @Override
public IBinder onBind(Intent intent) { public IBinder onBind(Intent intent) {
@ -21,90 +43,94 @@ public class PandroidEventviewerService extends Service {
} }
public void onCreate() { public void onCreate() {
alarmM = (AlarmManager) getSystemService(Context.ALARM_SERVICE); alarmM = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent intentAlarm = new Intent(this, AlarmReceiver.class); Intent intentAlarm = new Intent(this, AlarmReceiver.class);
this.pendingI = PendingIntent.getBroadcast(this, 0, intentAlarm, 0); this.pendingI = PendingIntent.getBroadcast(this, 0, intentAlarm, 0);
int sleepTimeAlarm = convertRefreshTimeKeyToTime(); 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; int returnvar = 60 * 10;
SharedPreferences preferences = getSharedPreferences( SharedPreferences preferences = getSharedPreferences(
this.getString(R.string.const_string_preferences), this.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE); Activity.MODE_PRIVATE);
int refreshTimeKey = preferences.getInt("refreshTimeKey", 3); int refreshTimeKey = preferences.getInt("refreshTimeKey", 3);
switch (refreshTimeKey) { switch (refreshTimeKey) {
case 0: case 0:
returnvar = 30; //30 seconds returnvar = 30; // 30 seconds
break; break;
case 1: case 1:
returnvar = 60; //1 minute returnvar = 60; // 1 minute
break; break;
case 2: case 2:
returnvar = 60 * 5; //5 minutes returnvar = 60 * 5; // 5 minutes
break; break;
case 3: case 3:
returnvar = 60 * 10; //10 minutes returnvar = 60 * 10; // 10 minutes
break; break;
case 4: case 4:
returnvar = 60 * 15; //15 minutes returnvar = 60 * 15; // 15 minutes
break; break;
case 5: case 5:
returnvar = 60 * 30; //30 minutes returnvar = 60 * 30; // 30 minutes
break; break;
case 6: case 6:
returnvar = 60 * 45; //45 minutes returnvar = 60 * 45; // 45 minutes
break; break;
case 7: case 7:
returnvar = 3600; //1 hour returnvar = 3600; // 1 hour
break; break;
case 8: case 8:
returnvar = 3600 + (60 * 30); //1 hour and 30 minutes returnvar = 3600 + (60 * 30); // 1 hour and 30 minutes
break; break;
case 9: case 9:
returnvar = 3600 * 2; //2 hours returnvar = 3600 * 2; // 2 hours
break; break;
case 10: case 10:
returnvar = 3600 * 3; //3 hours returnvar = 3600 * 3; // 3 hours
break; break;
case 11: case 11:
returnvar = 3600 * 4; //4 hours returnvar = 3600 * 4; // 4 hours
break; break;
case 12: case 12:
returnvar = 3600 * 6; //6 hours returnvar = 3600 * 6; // 6 hours
break; break;
case 13: case 13:
returnvar = 3600 * 8; //8 hours returnvar = 3600 * 8; // 8 hours
break; break;
case 14: case 14:
returnvar = 3600 * 10; //10 hours returnvar = 3600 * 10; // 10 hours
break; break;
case 15: case 15:
returnvar = 3600 * 12; //12 hours returnvar = 3600 * 12; // 12 hours
break; break;
case 16: case 16:
returnvar = 3600 * 24; //24 hours returnvar = 3600 * 24; // 24 hours
break; break;
case 17: case 17:
returnvar = 3600 * 36; //36 hours returnvar = 3600 * 36; // 36 hours
break; break;
case 18: case 18:
returnvar = 3600 * 48; //48 hours returnvar = 3600 * 48; // 48 hours
break; break;
} }
return returnvar * 1000; return returnvar * 1000;
} }
public void onDestroy() { public void onDestroy() {
alarmM.cancel(this.pendingI); alarmM.cancel(this.pendingI);
} }

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; package pandroid_event_viewer.pandorafms;
import java.util.ArrayList; import java.util.ArrayList;
@ -23,133 +39,153 @@ import android.widget.EditText;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.Toast; import android.widget.Toast;
/**
* Provides the functionality necessary to validate an event.
*
* @author Miguel de Dios Matías
*
*/
public class PopupValidationEvent extends Activity { public class PopupValidationEvent extends Activity {
public int id_event; private int id_event;
public String comment; private String comment;
private String url;
public PandroidEventviewerActivity object; private String user;
public Core core; private String password;
public String url; @Override
public String user; public void onCreate(Bundle savedInstanceState) {
public String password; super.onCreate(savedInstanceState);
/** Called when the activity is first created. */ Intent i = getIntent();
@Override this.id_event = i.getIntExtra("id_event", -1);
public void onCreate(Bundle savedInstanceState) { // this.core = (Core)i.getSerializableExtra("core");
super.onCreate(savedInstanceState);
setContentView(R.layout.popup_validation_event);
Intent i = getIntent(); final Button button = (Button) findViewById(R.id.button_validate_event);
this.id_event = i.getIntExtra("id_event", -1);
//this.object = (PandroidEventviewerActivity)i.getSerializableExtra("object"); button.setOnClickListener(new View.OnClickListener() {
this.core = (Core)i.getSerializableExtra("core"); @Override
public void onClick(View v) {
setContentView(R.layout.popup_validation_event); validateEvent();
}
final Button button = (Button) findViewById(R.id.button_validate_event); });
}
button.setOnClickListener(new View.OnClickListener() {
@Override /**
public void onClick(View v) { * Validates the event
validateEvent(); */
} private void validateEvent() {
}); EditText textbox = (EditText) findViewById(R.id.comment);
} String comment = textbox.getText().toString();
Button button = (Button) findViewById(R.id.button_validate_event);
public void validateEvent() { ProgressBar pb = (ProgressBar) findViewById(R.id.send_progress);
EditText textbox = (EditText) findViewById(R.id.comment);
String comment = textbox.getText().toString(); button.setVisibility(Button.GONE);
Button button = (Button) findViewById(R.id.button_validate_event); pb.setVisibility(ProgressBar.VISIBLE);
ProgressBar pb = (ProgressBar) findViewById(R.id.send_progress);
this.comment = "Validate from Pandroid Eventviewer Mobile: " + comment;
button.setVisibility(Button.GONE);
pb.setVisibility(ProgressBar.VISIBLE); new SendValidationAsyncTask().execute();
}
this.comment = "Validate from Pandroid Eventviewer Mobile: " + comment;
/**
new SendValidationAsyncTask().execute(); * Finish the activity
} */
private void destroyPopup() {
public void destroyPopup() { finish();
finish(); }
}
/**
public boolean sendValidation() { * Sends the validation to server.
boolean return_var = false; *
* @return <b>true</b> if it was done.
*/
private boolean sendValidation() {
boolean return_var = false;
if (this.url == null) { if (this.url == null) {
SharedPreferences preferences = getApplicationContext().getSharedPreferences( SharedPreferences preferences = getApplicationContext()
getApplicationContext().getString(R.string.const_string_preferences), .getSharedPreferences(
Activity.MODE_PRIVATE); getApplicationContext().getString(
R.string.const_string_preferences),
this.url = preferences.getString("url", ""); Activity.MODE_PRIVATE);
this.user = preferences.getString("user", "");
this.password = preferences.getString("password", ""); this.url = preferences.getString("url", "");
this.user = preferences.getString("user", "");
this.password = preferences.getString("password", "");
} }
try { try {
DefaultHttpClient httpClient = new DefaultHttpClient(); DefaultHttpClient httpClient = new DefaultHttpClient();
UrlEncodedFormEntity entity; UrlEncodedFormEntity entity;
HttpPost httpPost; HttpPost httpPost;
List<NameValuePair> parameters; List<NameValuePair> parameters;
HttpResponse response; HttpResponse response;
HttpEntity entityResponse; HttpEntity entityResponse;
String return_api; String return_api;
httpPost = new HttpPost(this.url + "/include/api.php"); httpPost = new HttpPost(this.url + "/include/api.php");
//Set event validation. // Set event validation.
parameters = new ArrayList<NameValuePair>(); parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair("user", this.user)); 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", "set")); parameters.add(new BasicNameValuePair("op", "set"));
parameters.add(new BasicNameValuePair("op2", "validate_events")); 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(
parameters.add(new BasicNameValuePair("other", this.comment)); this.id_event).toString()));
entity = new UrlEncodedFormEntity(parameters); parameters.add(new BasicNameValuePair("other", this.comment));
httpPost.setEntity(entity); entity = new UrlEncodedFormEntity(parameters);
response = httpClient.execute(httpPost); httpPost.setEntity(entity);
entityResponse = response.getEntity(); response = httpClient.execute(httpPost);
return_api = Core.convertStreamToString(entityResponse.getContent()); entityResponse = response.getEntity();
return_api = return_api.replace("\n", ""); return_api = Core
.convertStreamToString(entityResponse.getContent());
if (return_api.startsWith("Correct validation")) { return_api = return_api.replace("\n", "");
return_var = true;
} if (return_api.startsWith("Correct validation")) {
} return_var = true;
catch (Exception e) { }
Log.e("EXCEPTION sendValidation", e.getMessage()); } catch (Exception e) {
} Log.e("EXCEPTION sendValidation", e.getMessage());
}
return return_var; return return_var;
} }
public class SendValidationAsyncTask extends AsyncTask<Void, Void, Void> { /**
public ArrayList<String> lista; * Sends a validation (async task)
public boolean result; *
* @author Miguel de Dios Matías
*
*/
private class SendValidationAsyncTask extends AsyncTask<Void, Void, Void> {
private boolean result;
@Override @Override
protected Void doInBackground(Void... params) { protected Void doInBackground(Void... params) {
result = sendValidation(); result = sendValidation();
return null; return null;
} }
@Override @Override
protected void onPostExecute(Void unused) protected void onPostExecute(Void unused) {
{
String text; String text;
if (result) { if (result) {
text = getApplicationContext().getString(R.string.successful_validate_event_str); text = getApplicationContext().getString(
R.string.successful_validate_event_str);
} else {
text = getApplicationContext().getString(
R.string.fail_validate_event_str);
} }
else {
text = getApplicationContext().getString(R.string.fail_validate_event_str); Toast toast = Toast.makeText(getApplicationContext(), text,
} Toast.LENGTH_SHORT);
toast.show();
Toast toast = Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT);
toast.show(); destroyPopup();
destroyPopup();
} }
} }
} }