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

@ -18,7 +18,11 @@
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" />
@ -29,61 +33,60 @@
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:theme="@android:style/Theme.NoTitleBar"
android:configChanges="orientation|keyboardHidden" android:configChanges="orientation|keyboardHidden"
> android:label="Pandroid Event viewer"
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>
<activity <activity
android:name=".About" android:name=".About"
android:label="@string/pandroid_event_viewer_str"
android:configChanges="orientation|keyboardHidden" android:configChanges="orientation|keyboardHidden"
android:theme="@android:style/Theme.Dialog" android:label="@string/pandroid_event_viewer_str"
> android:theme="@android:style/Theme.Dialog" >
</activity> </activity>
<activity <activity
android:name=".PopupValidationEvent" android:name=".PopupValidationEvent"
android:label="@string/validate_event_button_str"
android:theme="@android:style/Theme.Dialog"
android:configChanges="orientation|keyboardHidden" android:configChanges="orientation|keyboardHidden"
> android:label="@string/validate_event_button_str"
android:theme="@android:style/Theme.Dialog" >
</activity> </activity>
<activity <activity
android:name=".Info" android:name=".Info"
android:label="@string/pandroid_event_viewer_str"
android:configChanges="orientation|keyboardHidden" android:configChanges="orientation|keyboardHidden"
android:theme="@android:style/Theme.Dialog" android:label="@string/pandroid_event_viewer_str"
> android:theme="@android:style/Theme.Dialog" >
</activity> </activity>
<service android:name=".PandroidEventviewerService"></service> <service android:name=".PandroidEventviewerService" >
</service>
<receiver android:process=":remote" android:name=".AlarmReceiver"></receiver> <receiver
android:name=".AlarmReceiver"
android:process=":remote" >
</receiver>
</application> </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,
@ -12,8 +31,6 @@
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>
Apply patch from user Santiago Munín González <burning1@gmail.com> Apply patch from user Santiago Munín González <burning1@gmail.com>
@ -23,8 +40,6 @@
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>
* AndroidManifest.xml: update num version. * AndroidManifest.xml: update num version.

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -14,166 +14,142 @@
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 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"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView <TextView
android:text="@string/agent_label_str"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
/> android:text="@string/agent_label_str" />
<EditText <EditText
android:id="@+id/agent_name" android:id="@+id/agent_name"
android:layout_height="wrap_content"
android:singleLine="true"
android:editable="true"
android:layout_width="fill_parent" android:layout_width="fill_parent"
/> android:layout_height="wrap_content"
android:inputType="text"
android:singleLine="true" />
<TextView <TextView
android:text="@string/event_search_label_str"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
/> android:text="@string/event_search_label_str" />
<EditText <EditText
android:id="@+id/event_search_text" android:id="@+id/event_search_text"
android:layout_height="wrap_content"
android:singleLine="true"
android:editable="true"
android:layout_width="fill_parent" android:layout_width="fill_parent"
/> android:layout_height="wrap_content"
android:inputType="text"
android:singleLine="true" />
<TableLayout <TableLayout
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content" >
>
<TableRow <TableRow android:visibility="gone" >
android:visibility="gone"
>
<TextView <TextView
android:text="@string/group_label_str"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingRight="5dip"
android:layout_weight="1" android:layout_weight="1"
/> android:paddingRight="5dip"
android:text="@string/group_label_str" />
<Spinner <Spinner
android:id="@+id/group_combo" android:id="@+id/group_combo"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:visibility="gone" android:visibility="gone" />
/>
<ProgressBar <ProgressBar
android:id="@+id/loading_group" android:id="@+id/loading_group"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="right" android:layout_gravity="right" />
/>
</TableRow> </TableRow>
<TableRow> <TableRow>
<TextView <TextView
android:text="@string/severity_label_str"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingRight="5dip"
android:layout_weight="1" android:layout_weight="1"
/> android:paddingRight="5dip"
android:text="@string/severity_label_str" />
<Spinner <Spinner
android:id="@+id/severity_combo" android:id="@+id/severity_combo"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content" />
/>
</TableRow> </TableRow>
<TableRow> <TableRow>
<TextView <TextView
android:text="@string/status_label_str"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingRight="5dip"
android:layout_weight="1" android:layout_weight="1"
/> android:paddingRight="5dip"
android:text="@string/status_label_str" />
<Spinner <Spinner
android:id="@+id/status_combo" android:id="@+id/status_combo"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"/>
/>
</TableRow> </TableRow>
</TableLayout>
<!-- <TableRow>
<TextView <TextView
android:text="@string/date_label_str"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingRight="5dip" android:paddingRight="5dip"
/> android:text="@string/max_time_old_event_str"/>
<TimePicker
android:textSize="10sp"
android:id="@+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<DatePicker
android:id="@+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
-->
<TextView
android:text="@string/max_time_old_event_str"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="5dip"
/>
<Spinner <Spinner
android:id="@+id/max_time_old_event_combo" android:id="@+id/max_time_old_event_combo"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"/>
android:layout_gravity="right" </TableRow>
/> </TableLayout>
<LinearLayout <LinearLayout
android:layout_marginTop="10px"
android:layout_marginBottom="10px"
android:layout_height="2px"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:background="#ffffff" android:layout_height="2dp"
/> android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:background="#ffffff" />
<LinearLayout <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
> android:orientation="horizontal" >
<Button <Button
android:text="@string/reset_button_str"
android:id="@+id/button_reset" android:id="@+id/button_reset"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
/> android:text="@string/reset_button_str" />
<Button <Button
android:text="@string/search_button_str"
android:id="@+id/button_send" android:id="@+id/button_send"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
/> android:text="@string/search_button_str" />
</LinearLayout> </LinearLayout>
<Button <Button
android:text="@string/set_as_filter_watcher_button_str"
android:id="@+id/button_set_as_filter_watcher" android:id="@+id/button_set_as_filter_watcher"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
/> android:text="@string/set_as_filter_watcher_button_str" />
</LinearLayout> </LinearLayout>
</ScrollView> </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="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 <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
style="@style/options_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:text="@string/connection" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:orientation="vertical" >
<TextView <TextView
android:textColor="#ffffff"
android:text="@string/url_label_str"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingRight="5dip" android:paddingRight="5dip"
/> android:text="@string/url_label_str"
android:textColor="#ffffff" />
<EditText <EditText
android:id="@+id/url" android:id="@+id/url"
android:layout_height="wrap_content"
android:singleLine="true"
android:editable="true"
android:layout_width="fill_parent" android:layout_width="fill_parent"
/> android:layout_height="wrap_content"
android:inputType="textWebEditText"
android:singleLine="true" />
<TextView <TextView
android:textColor="#ffffff"
android:text="@string/user_label_str"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingRight="5dip" android:paddingRight="5dip"
/> android:text="@string/user_label_str"
android:textColor="#ffffff" />
<EditText <EditText
android:id="@+id/user" android:id="@+id/user"
android:layout_height="wrap_content"
android:singleLine="true"
android:editable="true"
android:layout_width="fill_parent" android:layout_width="fill_parent"
/> android:layout_height="wrap_content"
android:inputType="text"
android:singleLine="true" />
<TextView <TextView
android:textColor="#ffffff"
android:text="@string/password_label_str"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingRight="5dip" android:paddingRight="5dip"
/> android:text="@string/password_label_str"
android:textColor="#ffffff" />
<EditText <EditText
android:id="@+id/password" android:id="@+id/password"
android:layout_height="wrap_content"
android:singleLine="true"
android:editable="true"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPassword" android:inputType="textPassword"
/> android:singleLine="true" />
<TextView
android:textColor="#ffffff" <RelativeLayout
android:text="@string/refresh_time_label_str"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingRight="5dip" android:layout_marginRight="5dp"
/> android:layout_marginLeft="5dp"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/refresh_time_label_str"
android:textColor="#ffffff" />
<Spinner <Spinner
android:id="@+id/refresh_combo" android:id="@+id/refresh_combo"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
/> android:gravity="left" />
<Button </LinearLayout>
android:id="@+id/update_options"
android:text="@string/update_button_str" <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_width="fill_parent"
android:layout_height="wrap_content" 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>
<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> </ScrollView>
</LinearLayout>

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,12 +21,18 @@ 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);
@ -18,7 +40,8 @@ public class About extends Activity {
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
.fromHtml("<a href='http://pandorafms.org/'>PandoraFMS.org</a>"));
text.setMovementMethod(LinkMovementMethod.getInstance()); 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);
@ -31,15 +54,16 @@ public class About extends Activity {
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
.edit();
editorPreferences.putBoolean("show_popup_info", false); editorPreferences.putBoolean("show_popup_info", false);
editorPreferences.commit(); 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
.edit();
editorPreferences.putBoolean("show_popup_info", true); editorPreferences.putBoolean("show_popup_info", true);
editorPreferences.commit(); 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,9 +36,19 @@ 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;
@ -32,10 +58,15 @@ public class AlarmReceiver extends BroadcastReceiver {
@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(
@ -47,7 +78,8 @@ public class AlarmReceiver extends BroadcastReceiver {
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) if ((user.length() == 0) && (password.length() == 0)
&& (url.length() == 0)) { && (url.length() == 0)) {
@ -73,88 +105,102 @@ public class AlarmReceiver extends BroadcastReceiver {
parameters.add(new BasicNameValuePair("pass", this.password)); parameters.add(new BasicNameValuePair("pass", this.password));
parameters.add(new BasicNameValuePair("op", "get")); parameters.add(new BasicNameValuePair("op", "get"));
parameters.add(new BasicNameValuePair("op2", "events")); parameters.add(new BasicNameValuePair("op2", "events"));
parameters.add(new BasicNameValuePair("other_mode", "url_encode_separator_|")); parameters.add(new BasicNameValuePair("other_mode",
"url_encode_separator_|"));
parameters.add(new BasicNameValuePair("return_type", "csv")); parameters.add(new BasicNameValuePair("return_type", "csv"));
parameters.add(new BasicNameValuePair("other", parametersAPI + "|total")); parameters.add(new BasicNameValuePair("other", parametersAPI
+ "|total"));
entity = new UrlEncodedFormEntity(parameters); entity = new UrlEncodedFormEntity(parameters);
httpPost.setEntity(entity); httpPost.setEntity(entity);
response = httpClient.execute(httpPost); response = httpClient.execute(httpPost);
entityResponse = response.getEntity(); entityResponse = response.getEntity();
return_api = Core.convertStreamToString(entityResponse.getContent()); return_api = Core.convertStreamToString(entityResponse
.getContent());
return_api = return_api.replace("\n", ""); return_api = return_api.replace("\n", "");
Log.e("AlarmReceiver checkNewEvents", "" + return_api); Log.i(TAG + " checkNewEvents", return_api);
this.count_events = new Long(return_api).longValue(); this.count_events = new Long(return_api).longValue();
// Check the event more critical // Check the event more critical
if (this.count_events != 0) { if (this.count_events != 0) {
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", "get")); parameters.add(new BasicNameValuePair("op", "get"));
parameters.add(new BasicNameValuePair("op2", "events")); parameters.add(new BasicNameValuePair("op2", "events"));
parameters.add(new BasicNameValuePair("other_mode", "url_encode_separator_|")); parameters.add(new BasicNameValuePair("other_mode",
parameters.add(new BasicNameValuePair("return_type", "csv")); "url_encode_separator_|"));
parameters.add(new BasicNameValuePair("other", parametersAPI + "|more_criticity")); parameters
.add(new BasicNameValuePair("return_type", "csv"));
parameters.add(new BasicNameValuePair("other",
parametersAPI + "|more_criticity"));
entity = new UrlEncodedFormEntity(parameters); entity = new UrlEncodedFormEntity(parameters);
httpPost.setEntity(entity); httpPost.setEntity(entity);
response = httpClient.execute(httpPost); response = httpClient.execute(httpPost);
entityResponse = response.getEntity(); entityResponse = response.getEntity();
return_api = Core.convertStreamToString(entityResponse.getContent()); return_api = Core.convertStreamToString(entityResponse
.getContent());
return_api = return_api.replace("\n", ""); return_api = return_api.replace("\n", "");
this.more_criticity = new Integer(return_api).intValue(); this.more_criticity = new Integer(return_api).intValue();
notificationEvent(context); notificationEvent(context);
} } else {
else {
this.more_criticity = -1; this.more_criticity = -1;
// Restore timestamp // Restore timestamp
SharedPreferences.Editor editorPreferences = preferences.edit(); SharedPreferences.Editor editorPreferences = preferences
editorPreferences.putLong("previous_filterTimestamp", old_previous_filterTimestamp); .edit();
editorPreferences.putLong("previous_filterTimestamp",
old_previous_filterTimestamp);
editorPreferences.commit(); editorPreferences.commit();
} }
} } catch (Exception e) {
catch (Exception e) { Log.e(TAG + " EXCEPTION checkNewEvents", e.getMessage());
Log.e("EXCEPTION checkNewEvents", e.getMessage());
return; return;
} }
} }
} }
/**
* Builds an api call from all filter parameters
*
* @param context
* @return Api call.
*/
public String serializeParams2Api(Context context) { public String serializeParams2Api(Context context) {
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);
String filterAgentName = preferences.getString("filterAgentName", ""); String filterAgentName = preferences.getString("filterAgentName", "");
int filterIDGroup = preferences.getInt("filterIDGroup", 0); // TODO no api parameter, waiting for it
// int filterIDGroup = preferences.getInt("filterIDGroup", 0);
int filterSeverity = preferences.getInt("filterSeverity", -1); int filterSeverity = preferences.getInt("filterSeverity", -1);
int filterStatus = preferences.getInt("filterStatus", 3); int filterStatus = preferences.getInt("filterStatus", 3);
String filterEventSearch = preferences.getString("filterEventSearch", ""); String filterEventSearch = preferences.getString("filterEventSearch",
"");
Calendar c = Calendar.getInstance(); Calendar c = Calendar.getInstance();
long now = (c.getTimeInMillis() / 1000); long now = (c.getTimeInMillis() / 1000);
long filterTimestamp = preferences.getLong("filterTimestamp", now); long filterTimestamp = preferences.getLong("filterTimestamp", now);
SharedPreferences.Editor editorPreferences = preferences.edit(); SharedPreferences.Editor editorPreferences = preferences.edit();
editorPreferences.putLong("filterTimestamp", now); //Save for the next execution. // Save for the next execution
editorPreferences.putLong("previous_filterTimestamp", filterTimestamp); //Save and the previous for the list. editorPreferences.putLong("filterTimestamp", now);
// Save the previous for the list.
editorPreferences.putLong("previous_filterTimestamp", filterTimestamp);
if (editorPreferences.commit()) { if (editorPreferences.commit()) {
Log.e("AlarmReceiver serializeParams2Api", "YES COMMIT"); Log.i(TAG + " (filter options)",
"Configuration changes commited (timestamp)");
} else {
Log.e(TAG + " (filter options)",
"Configuration changes not commited");
} }
else {
Log.e("AlarmReceiver serializeParams2Api", "NOT COMMIT");
}
String return_var = ""; String return_var = "";
return_var += ';'; // Separator for the csv return_var += ';'; // Separator for the csv
return_var += "|"; return_var += "|";
return_var += Integer.toString(filterSeverity); // Criticity or severity return_var += Integer.toString(filterSeverity); // Criticity or severity
@ -173,90 +219,129 @@ public class AlarmReceiver extends BroadcastReceiver {
return_var += "|"; return_var += "|";
return_var += filterStatus; // The status return_var += filterStatus; // The status
return_var += "|"; return_var += "|";
return_var += filterEventSearch; //The free search in the text event description. return_var += filterEventSearch; // The free search in the text event
// description.
return_var += "|"; return_var += "|";
return_var += Integer.toString(0); // The pagination of list events return_var += Integer.toString(0); // The pagination of list events
return_var += "|"; return_var += "|";
return_var += Long.toString(0); // The offset of list events return_var += Long.toString(0); // The offset of list events
Log.e("AlarmReceiver serializeParams2Api", return_var); Log.i(TAG + " serializeParams2Api", return_var);
return return_var; return return_var;
} }
private static final int NOTIFICATION_PANDROID_EVENT_VIEWER = 666; /**
* Launchs a notification
*
* @param context
*/
public void notificationEvent(Context context) { public void notificationEvent(Context context) {
String ns = Context.NOTIFICATION_SERVICE; String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns); NotificationManager mNotificationManager = (NotificationManager) context
.getSystemService(ns);
mNotificationManager.cancel(NOTIFICATION_PANDROID_EVENT_VIEWER); mNotificationManager.cancel(NOTIFICATION_PANDROID_EVENT_VIEWER);
int icon; int icon;
CharSequence tickerText; CharSequence tickerText;
switch (this.more_criticity) { switch (this.more_criticity) {
case 0: case 0:
icon = R.drawable.criticity_0; icon = R.drawable.criticity_0;
tickerText = context.getString(R.string.notification_criticity_0_str) tickerText = context.getString(
.replace("%s", new Long(this.count_events).toString()); R.string.notification_criticity_0_str).replace("%s",
new Long(this.count_events).toString());
break; break;
case 1: case 1:
icon = R.drawable.criticity_1; icon = R.drawable.criticity_1;
tickerText = context.getString(R.string.notification_criticity_1_str) tickerText = context.getString(
.replace("%s", new Long(this.count_events).toString()); R.string.notification_criticity_1_str).replace("%s",
new Long(this.count_events).toString());
break; break;
case 2: case 2:
icon = R.drawable.criticity_2; icon = R.drawable.criticity_2;
tickerText = context.getString(R.string.notification_criticity_2_str) tickerText = context.getString(
.replace("%s", new Long(this.count_events).toString()); R.string.notification_criticity_2_str).replace("%s",
new Long(this.count_events).toString());
break; break;
case 3: case 3:
icon = R.drawable.criticity_3; icon = R.drawable.criticity_3;
tickerText = context.getString(R.string.notification_criticity_3_str) tickerText = context.getString(
.replace("%s", new Long(this.count_events).toString()); R.string.notification_criticity_3_str).replace("%s",
new Long(this.count_events).toString());
break; break;
case 4: case 4:
icon = R.drawable.criticity_4; icon = R.drawable.criticity_4;
tickerText = context.getString(R.string.notification_criticity_4_str) tickerText = context.getString(
.replace("%s", new Long(this.count_events).toString()); R.string.notification_criticity_4_str).replace("%s",
new Long(this.count_events).toString());
break; break;
default: default:
icon = R.drawable.criticity_default; icon = R.drawable.criticity_default;
tickerText = context.getString(R.string.notification_criticity_2_str) tickerText = context.getString(
.replace("%s", new Long(this.count_events).toString()); R.string.notification_criticity_2_str).replace("%s",
new Long(this.count_events).toString());
break; break;
} }
long when = System.currentTimeMillis(); long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when); Notification notification = new Notification(icon, tickerText, when);
// notification.defaults |= Notification.DEFAULT_ALL;
notification.defaults |= Notification.DEFAULT_ALL;
notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.flags |= Notification.FLAG_AUTO_CANCEL;
// Notification options
SharedPreferences preferences = context.getSharedPreferences(
context.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
if (preferences.getBoolean("vibration", true)) {
Log.d(TAG, "Vibration");
notification.defaults |= Notification.DEFAULT_VIBRATE;
} else {
Log.d(TAG, "No vibration");
notification.vibrate = new long[] { 0, 0, 0, 0 };
}
if (preferences.getBoolean("led", false)) {
Log.d(TAG, "Led flash");
notification.defaults |= Notification.DEFAULT_LIGHTS;
/*
* notification.ledARGB = 0xff00ff00; notification.ledOnMS = 300;
* notification.ledOffMS = 1000; notification.flags |=
* Notification.FLAG_SHOW_LIGHTS;
*/
}
Uri notificationSoundUri = Uri.parse(preferences.getString(
"notification_sound_uri",
RingtoneManager
.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
.toString()));
if (notificationSoundUri != null) {
Log.i(TAG, "Setting sound: " + notificationSoundUri.toString());
notification.sound = notificationSoundUri;
} else {
Log.e(TAG, "Ringtone's uri problem (NULL)");
}
Intent notificationIntent = new Intent(context, PandroidEventviewerActivity.class); Intent notificationIntent = new Intent(context,
PandroidEventviewerActivity.class);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
notificationIntent.putExtra("count_events", this.count_events); notificationIntent.putExtra("count_events", this.count_events);
notificationIntent.putExtra("more_criticity", this.more_criticity); notificationIntent.putExtra("more_criticity", this.more_criticity);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
notificationIntent, 0);
CharSequence title = context.getString(R.string.pandroid_event_viewer_str); CharSequence title = context
.getString(R.string.pandroid_event_viewer_str);
notification.setLatestEventInfo(context, title, tickerText, contentIntent); notification.setLatestEventInfo(context, title, tickerText,
contentIntent);
Log.i(TAG, "Launching notification");
mNotificationManager.notify(NOTIFICATION_PANDROID_EVENT_VIEWER,
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,80 +26,61 @@ 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);
} }
/////////////////////// /**
/* * Reads from the input stream and returns a string.
public Core(Parcel in) { *
intent_service = (Intent)in.readValue(null); * @param is
//context = (Context)in.readValue(null); //Fucking marshall exception * @return A string with all data read.
}
public static final Parcelable.Creator<Core> CREATOR
= new Parcelable.Creator<Core>() {
@Override
public Core createFromParcel(Parcel source) {
// TODO Auto-generated method stub
return new Core(source);
}
@Override
public Core[] newArray(int size) {
// TODO Auto-generated method stub
return new Core[size];
}
};
@Override
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
// TODO Auto-generated method stub
dest.writeValue(this.intent_service);
//dest.writeValue(this.context); //Fucking marshall exception
}
*/ */
/////////// public static String convertStreamToString(InputStream is) {
BufferedReader reader = new BufferedReader(new InputStreamReader(is),
8 * 1024);
public static String convertStreamToString (InputStream is)
{
BufferedReader reader = new BufferedReader(new
InputStreamReader(is), 8*1024);
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
String line = null; String line = null;
@ -104,8 +101,14 @@ public class Core implements Serializable {
return sb.toString(); return sb.toString();
} }
public long convertMaxTimeOldEventValuesToTimestamp(long timestamp, int arrayKey) { /**
long time = timestamp; * Converts the maximum time setted to filter events to a timestamp.
*
* @param timestamp
* @param arrayKey
* @return Time in milliseconds.
*/
public long convertMaxTimeOldEventValuesToTimestamp(long time, int arrayKey) {
long return_var = 0; long return_var = 0;
if (time == 0) { if (time == 0) {

View File

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

View File

@ -1,5 +1,27 @@
/*
Pandora FMS - http://pandorafms.com
==================================================
Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
Please see http://pandorafms.org for full contribution list
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation; version 2
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
package pandroid_event_viewer.pandorafms; 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;

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.fromHtml("<a href='http://pandorafms.org/'>PandoraFMS.org</a>")); text.setText(Html
.fromHtml("<a href='http://pandorafms.org/'>PandoraFMS.org</a>"));
text.setMovementMethod(LinkMovementMethod.getInstance()); 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,19 +49,26 @@ 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
.getSerializableExtra("object");
this.core = (Core) i.getSerializableExtra("core"); this.core = (Core) i.getSerializableExtra("core");
this.pandoraGroups = new HashMap<Integer, String>(); this.pandoraGroups = new HashMap<Integer, String>();
@ -56,8 +80,8 @@ public class Main extends Activity {
final Button buttonbuttonSetAsFilterWatcher = (Button) findViewById(R.id.button_set_as_filter_watcher); 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);
@ -66,14 +90,12 @@ public class Main extends Activity {
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);
@ -87,27 +109,28 @@ public class Main extends Activity {
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) {
@ -122,7 +145,8 @@ public class Main extends Activity {
} }
}); });
buttonbuttonSetAsFilterWatcher.setOnClickListener(new View.OnClickListener() { buttonbuttonSetAsFilterWatcher
.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -141,12 +165,17 @@ public class Main extends Activity {
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(
@ -167,7 +196,8 @@ public class Main extends Activity {
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", ";"));
@ -178,7 +208,8 @@ public class Main extends Activity {
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");
@ -189,32 +220,35 @@ public class Main extends Activity {
array.add(groups[1]); array.add(groups[1]);
} }
} } catch (Exception e) {
catch (Exception e) { Log.e(TAG +": getting groups", e.getMessage());
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>(getApplicationContext(), ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(
android.R.layout.simple_spinner_item, getApplicationContext(),
lista); android.R.layout.simple_spinner_item, list);
combo.setAdapter(spinnerArrayAdapter); combo.setAdapter(spinnerArrayAdapter);
combo.setSelection(0); combo.setSelection(0);
@ -240,13 +274,13 @@ public class Main extends Activity {
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);
@ -260,33 +294,21 @@ public class Main extends Activity {
return true; return true;
} }
public void search_form() { /**
* Performs the search choice
*/
private void search_form() {
// Clean the EventList // 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();
@ -294,23 +316,25 @@ public class Main extends Activity {
this.object.id_group = 0; this.object.id_group = 0;
combo = (Spinner) findViewById(R.id.group_combo); combo = (Spinner) findViewById(R.id.group_combo);
if (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 = (Map.Entry<Integer, String>) it
.next();
if (e.getValue().equals(selectedGroup)) { if (e.getValue().equals(selectedGroup)) {
this.object.id_group = e.getKey(); 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);
@ -323,7 +347,10 @@ public class Main extends Activity {
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;
@ -331,7 +358,6 @@ public class Main extends Activity {
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();
@ -340,9 +366,10 @@ public class Main extends Activity {
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();
@ -354,7 +381,6 @@ public class Main extends Activity {
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);
@ -363,7 +389,6 @@ public class Main extends Activity {
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);
@ -381,17 +406,21 @@ public class Main extends Activity {
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() { /**
* Resets the filter form.
*/
private void reset_form() {
EditText text = (EditText) findViewById(R.id.agent_name); EditText text = (EditText) findViewById(R.id.agent_name);
text.setText(""); text.setText("");
@ -405,21 +434,10 @@ public class Main extends Activity {
combo.setSelection(6); combo.setSelection(6);
combo = (Spinner) findViewById(R.id.status_combo); combo = (Spinner) findViewById(R.id.status_combo);
combo.setSelection(4); combo.setSelection(3);
text = (EditText) findViewById(R.id.event_search_text); 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,25 +1,58 @@
/*
Pandora FMS - http://pandorafms.com
==================================================
Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
Please see http://pandorafms.org for full contribution list
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation; version 2
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
package pandroid_event_viewer.pandorafms; 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;
private int refreshTimeKey;
private TextView connectionStatus;
public Core core; private Core core;
public PandroidEventviewerActivity object; private PandroidEventviewerActivity object;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
@ -27,18 +60,17 @@ public class Options extends Activity {
Intent i = getIntent(); Intent i = getIntent();
this.core = (Core) i.getSerializableExtra("core"); this.core = (Core) i.getSerializableExtra("core");
//this.object = (PandroidEventviewerActivity)i.getSerializableExtra("object");
//this.core = this.object.core;
setContentView(R.layout.options); setContentView(R.layout.options);
connectionStatus = (TextView) findViewById(R.id.check_connection_status);
new CheckConnectionAsyncTask().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);
// Connection
url = preferences.getString("url", "http://firefly.artica.es/pandora_demo"); url = preferences.getString("url",
"http://firefly.artica.es/pandora_demo");
user = preferences.getString("user", "demo"); user = preferences.getString("user", "demo");
password = preferences.getString("password", "demo"); password = preferences.getString("password", "demo");
refreshTimeKey = preferences.getInt("refreshTimeKey", 3); refreshTimeKey = preferences.getInt("refreshTimeKey", 3);
@ -52,7 +84,8 @@ public class Options extends Activity {
Spinner combo = (Spinner) findViewById(R.id.refresh_combo); Spinner combo = (Spinner) findViewById(R.id.refresh_combo);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource( ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.refresh_combo, android.R.layout.simple_spinner_item); this, R.array.refresh_combo,
android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
combo.setAdapter(adapter); combo.setAdapter(adapter);
combo.setSelection(refreshTimeKey); combo.setSelection(refreshTimeKey);
@ -62,22 +95,75 @@ public class Options extends Activity {
@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
boolean vibration = preferences.getBoolean("vibration", true);
CheckBox cb = (CheckBox) findViewById(R.id.vibration_on);
cb.setChecked(vibration);
boolean led = preferences.getBoolean("led", false);
cb = (CheckBox) findViewById(R.id.led_flash_on);
cb.setChecked(led);
Button notificationSound = (Button) findViewById(R.id.sound_button);
Uri defaultSoundUri = Uri.parse(preferences.getString(
"notification_sound_uri",
RingtoneManager
.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
.toString()));
this.setNewRingtone(notificationSound, defaultSoundUri);
notificationSound.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Log.i(TAG, "Selecting ringtone");
Intent intent = new Intent(
RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE,
getString(R.string.select_sound));
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT,
false);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT,
true);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE,
RingtoneManager.TYPE_NOTIFICATION);
startActivityForResult(intent, RINGTONE_PICK_CODE);
}
});
} }
public void save_options() { // Gets sound selected
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RINGTONE_PICK_CODE) {
if (data != null) {
Uri uri = data
.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
this.setNewRingtone(((Button) findViewById(R.id.sound_button)),
uri);
}
}
}
/**
* Saves all options
*/
private void save_options() {
SharedPreferences preferences = getSharedPreferences( 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();
// Connection settings
EditText text = (EditText) findViewById(R.id.url); EditText text = (EditText) findViewById(R.id.url);
String url = text.getText().toString(); String url = text.getText().toString();
if (url.charAt(url.length() - 1) == '/') { if (url.charAt(url.length() - 1) == '/') {
@ -85,32 +171,112 @@ public class Options extends Activity {
} }
editorPreferences.putString("url", url); editorPreferences.putString("url", url);
//this.object.url = url;
text = (EditText) findViewById(R.id.user); text = (EditText) findViewById(R.id.user);
editorPreferences.putString("user", text.getText().toString()); editorPreferences.putString("user", text.getText().toString());
//this.object.user = text.getText().toString();
text = (EditText) findViewById(R.id.password); text = (EditText) findViewById(R.id.password);
editorPreferences.putString("password", text.getText().toString()); editorPreferences.putString("password", text.getText().toString());
//this.object.password = text.getText().toString();
Spinner combo = (Spinner) findViewById(R.id.refresh_combo); Spinner combo = (Spinner) findViewById(R.id.refresh_combo);
editorPreferences.putInt("refreshTimeKey", combo.getSelectedItemPosition()); editorPreferences.putInt("refreshTimeKey",
combo.getSelectedItemPosition());
// Notification settings
CheckBox cb = (CheckBox) findViewById(R.id.vibration_on);
editorPreferences.putBoolean("vibration", cb.isChecked());
cb = (CheckBox) findViewById(R.id.led_flash_on);
editorPreferences.putBoolean("led", cb.isChecked());
Context context = this.getApplicationContext(); Context context = this.getApplicationContext();
int duration = Toast.LENGTH_SHORT;
if (editorPreferences.commit()) { if (editorPreferences.commit()) {
if (this.core != null) { if (this.core != null) {
this.core.stopServiceEventWatcher(getApplicationContext()); this.core.stopServiceEventWatcher(getApplicationContext());
this.core.startServiceEventWatcher(getApplicationContext()); this.core.startServiceEventWatcher(getApplicationContext());
} }
Log.i(TAG, "Settings saved");
Toast toast = Toast.makeText(context,
this.getString(R.string.config_update_succesful_str),
Toast.LENGTH_SHORT);
toast.show();
} else {
Toast toast = Toast.makeText(context,
this.getString(R.string.config_update_fail_str),
Toast.LENGTH_LONG);
toast.show();
}
}
Toast toast = Toast.makeText(context, this.getString(R.string.config_update_succesful_str), duration); /**
toast.show(); * Sets ringtone's title (shortens it if necessary) on the button and
* changes ringtone's uri in options. If there is a problem with the given
* Uri, just put "Silence".
*
* @param button
* Target button.
* @param uri
* Ringtone's uri.
*/
private void setNewRingtone(Button button, Uri uri) {
if (uri != null) {
Log.i(TAG, "New ringtone selected: " + uri.toString());
SharedPreferences preferences = getSharedPreferences(
this.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
SharedPreferences.Editor editorPreferences = preferences.edit();
editorPreferences.putString("notification_sound_uri",
uri.toString());
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(),
uri);
if (editorPreferences.commit()) {
Log.i(TAG, "New ringtone saved.");
} else {
Log.e(TAG, "Problem saving new ringtone preference.");
}
if (r != null) {
String text = r.getTitle(getApplicationContext());
if (text.length() > 15) {
button.setText(text.substring(0, 15) + "...");
} else {
button.setText(text);
}
} else {
Log.e(TAG, "Sound setting problem (null ringtone)");
button.setText(getString(R.string.silence));
}
} else {
Log.e(TAG, "Sound setting problem (null uri)");
button.setText(getString(R.string.silence));
}
}
/**
* Checks if connection parameters are ok.
*
* @author Santiago Munín González
*
*/
private class CheckConnectionAsyncTask extends AsyncTask<Void, Void, Void> {
private boolean connectionOk = false;
@Override
protected Void doInBackground(Void... arg0) {
// TODO implement check
this.connectionOk = false;
return null;
}
/**
* Choose an image (ok or wrong)
*/
protected void onPostExecute(Void v) {
if (this.connectionOk) {
connectionStatus.setCompoundDrawablesWithIntrinsicBounds(0, 0,
0, R.drawable.ok);
} else {
connectionStatus.setCompoundDrawablesWithIntrinsicBounds(0, 0,
0, R.drawable.cross);
} }
else {
Toast toast = Toast.makeText(context, this.getString(R.string.config_update_fail_str), duration);
toast.show();
} }
} }
} }

View File

@ -1,16 +1,19 @@
// Pandora FMS - http://pandorafms.com /*
// ================================================== 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,7 +43,9 @@ 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
@ -70,14 +73,11 @@ public class PandroidEventviewerActivity extends TabActivity implements Serializ
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 showOptionsFirstTime;
public boolean showTabListFirstTime; public boolean showTabListFirstTime;
/** 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);
@ -108,8 +108,7 @@ public class PandroidEventviewerActivity extends TabActivity implements Serializ
startActivity(i); startActivity(i);
this.showOptionsFirstTime = true; this.showOptionsFirstTime = true;
} } else {
else {
this.loadInProgress = true; this.loadInProgress = true;
this.showOptionsFirstTime = false; this.showOptionsFirstTime = false;
@ -123,7 +122,8 @@ public class PandroidEventviewerActivity extends TabActivity implements Serializ
this.status = preferences.getInt("filterStatus", 3); this.status = preferences.getInt("filterStatus", 3);
this.eventSearch = preferences.getString("filterEventSearch", ""); this.eventSearch = preferences.getString("filterEventSearch", "");
this.filterLastTime = preferences.getInt("filterLastTime", 6); this.filterLastTime = preferences.getInt("filterLastTime", 6);
this.timestamp = this.core.convertMaxTimeOldEventValuesToTimestamp(0, this.filterLastTime); this.timestamp = this.core.convertMaxTimeOldEventValuesToTimestamp(0,
this.filterLastTime);
this.eventList = new ArrayList<EventListItem>(); this.eventList = new ArrayList<EventListItem>();
this.getNewListEvents = true; this.getNewListEvents = true;
@ -137,24 +137,24 @@ public class PandroidEventviewerActivity extends TabActivity implements Serializ
i_main.putExtra("object", this); i_main.putExtra("object", this);
i_main.putExtra("core", this.core); i_main.putExtra("core", this.core);
tabHost.addTab tabHost.addTab(tabHost
( .newTabSpec(
tabHost.newTabSpec(getResources().getString(R.string.item_tab_main_text)) getResources().getString(R.string.item_tab_main_text))
.setIndicator(getResources().getString(R.string.item_tab_main_text) .setIndicator(
) getResources().getString(R.string.item_tab_main_text))
.setContent(i_main) .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(0).getLayoutParams().height = 45;
tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = 45; tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = 45;
@ -170,8 +170,7 @@ public class PandroidEventviewerActivity extends TabActivity implements Serializ
if (count_events > 0) { if (count_events > 0) {
process_notification(i); process_notification(i);
} } else {
else {
if (this.showTabListFirstTime) { if (this.showTabListFirstTime) {
executeBackgroundGetEvents(); executeBackgroundGetEvents();
this.showTabListFirstTime = false; this.showTabListFirstTime = false;
@ -189,7 +188,12 @@ public class PandroidEventviewerActivity extends TabActivity implements Serializ
process_notification(intent); process_notification(intent);
} }
public void process_notification(Intent intent) { /**
* Processes status bar notifications' clicks.
*
* @param intent
*/
private void process_notification(Intent intent) {
long count_events = intent.getLongExtra("count_events", 0); long count_events = intent.getLongExtra("count_events", 0);
int more_criticity = intent.getIntExtra("more_criticity", -1); int more_criticity = intent.getIntExtra("more_criticity", -1);
@ -224,18 +228,20 @@ public class PandroidEventviewerActivity extends TabActivity implements Serializ
break; break;
} }
Toast toast = Toast.makeText(getApplicationContext(), text,
Toast toast = Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT); Toast.LENGTH_SHORT);
toast.show(); toast.show();
//Set the same parameters to extract the events of the notification. // Set the same parameters to extract the events of the
// notification.
SharedPreferences preferences = getSharedPreferences( SharedPreferences preferences = getSharedPreferences(
getString(R.string.const_string_preferences), getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE); Activity.MODE_PRIVATE);
long timestamp_notification = preferences.getLong("previous_filterTimestamp", (new Date().getTime() / 1000)); long timestamp_notification = preferences.getLong(
Log.e("PandroidEventviewerActivity process_notification", "time_noti = " + timestamp_notification); "previous_filterTimestamp", (new Date().getTime() / 1000));
Log.i(TAG + " process_notification_timestamp", ""
+ timestamp_notification);
this.timestamp = timestamp_notification; this.timestamp = timestamp_notification;
Log.e("PandroidEventviewerActivity process_notification", "" +this.timestamp);
this.agentNameStr = preferences.getString("filterAgentName", ""); this.agentNameStr = preferences.getString("filterAgentName", "");
this.id_group = preferences.getInt("filterIDGroup", 0); this.id_group = preferences.getInt("filterIDGroup", 0);
this.severity = preferences.getInt("filterSeverity", -1); this.severity = preferences.getInt("filterSeverity", -1);
@ -251,7 +257,12 @@ public class PandroidEventviewerActivity extends TabActivity implements Serializ
} }
} }
public String serializeParams2Api() { /**
* Serializes all params.
*
* @return All params in a string.
*/
private String serializeParams2Api() {
String return_var = ""; String return_var = "";
return_var += ';'; // Separator for the csv return_var += ';'; // Separator for the csv
@ -272,18 +283,25 @@ public class PandroidEventviewerActivity extends TabActivity implements Serializ
return_var += "|"; return_var += "|";
return_var += this.status; // The status return_var += this.status; // The status
return_var += "|"; return_var += "|";
return_var += this.eventSearch; //The free search in the text event description. return_var += this.eventSearch; // The free search in the text event
// description.
return_var += "|"; return_var += "|";
return_var += Integer.toString(this.pagination); //The pagination of list events return_var += Integer.toString(this.pagination); // The pagination of
// list events
return_var += "|"; return_var += "|";
return_var += Long.toString(this.offset); // The offset of list events return_var += Long.toString(this.offset); // The offset of list events
Log.e("PandroidEventviewerActivity serializeParams2Api", return_var); Log.i(TAG + " serializeParams2Api", return_var);
return return_var; return return_var;
} }
public void getEvents(boolean newEvents) { /**
* Get events from pandora console.
*
* @param newEvents
*/
private void getEvents(boolean newEvents) {
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);
@ -309,18 +327,20 @@ public class PandroidEventviewerActivity extends TabActivity implements Serializ
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", "events")); parameters.add(new BasicNameValuePair("op2", "events"));
parameters.add(new BasicNameValuePair("other_mode", "url_encode_separator_|")); parameters.add(new BasicNameValuePair("other_mode",
"url_encode_separator_|"));
parameters.add(new BasicNameValuePair("return_type", "csv")); parameters.add(new BasicNameValuePair("return_type", "csv"));
parameters.add(new BasicNameValuePair("other", serializeParams2Api() + "|total")); parameters.add(new BasicNameValuePair("other",
serializeParams2Api() + "|total"));
entity = new UrlEncodedFormEntity(parameters); entity = new UrlEncodedFormEntity(parameters);
httpPost.setEntity(entity); httpPost.setEntity(entity);
response = httpClient.execute(httpPost); response = httpClient.execute(httpPost);
entityResponse = response.getEntity(); entityResponse = response.getEntity();
return_api = Core.convertStreamToString(entityResponse.getContent()); return_api = Core
.convertStreamToString(entityResponse.getContent());
return_api = return_api.replace("\n", ""); return_api = return_api.replace("\n", "");
Log.e("PandroidEventviewerActivity getEvents", return_api); Log.i(TAG + " getEvents", return_api);
this.count_events = new Long(return_api).longValue(); this.count_events = new Long(return_api).longValue();
Log.e("getEvents", return_api);
if (this.count_events == 0) { if (this.count_events == 0) {
return; return;
@ -332,40 +352,45 @@ public class PandroidEventviewerActivity extends TabActivity implements Serializ
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", "events")); parameters.add(new BasicNameValuePair("op2", "events"));
parameters.add(new BasicNameValuePair("other_mode", "url_encode_separator_|")); parameters.add(new BasicNameValuePair("other_mode",
"url_encode_separator_|"));
parameters.add(new BasicNameValuePair("return_type", "csv")); parameters.add(new BasicNameValuePair("return_type", "csv"));
parameters.add(new BasicNameValuePair("other", serializeParams2Api())); parameters.add(new BasicNameValuePair("other",
serializeParams2Api()));
entity = new UrlEncodedFormEntity(parameters); entity = new UrlEncodedFormEntity(parameters);
httpPost.setEntity(entity); httpPost.setEntity(entity);
response = httpClient.execute(httpPost); response = httpClient.execute(httpPost);
entityResponse = response.getEntity(); entityResponse = response.getEntity();
return_api = Core.convertStreamToString(entityResponse.getContent()); return_api = Core
return_api = return_api.replaceAll("\\<.*?\\>", ""); //Clean html tags. .convertStreamToString(entityResponse.getContent());
return_api = return_api.replaceAll("\\<.*?\\>", ""); // Clean html
// tags.
//Work around for the crap of \n in this event bad xml Pattern pattern = Pattern
//return_api = return_api.replaceAll("Unable to process XML data file [^\n]*\n[^\n]*line 187 thread .\n", "Bad XML"); .compile("Unable to process XML data file '(.*)'");
Pattern pattern = Pattern.compile("Unable to process XML data file '(.*)'");
Matcher matcher; Matcher matcher;
String filename; String filename;
boolean endReplace = false; int i22 = 0; boolean endReplace = false;
while (!endReplace) { Log.e("loop", i22 + ""); i22++; int i22 = 0;
while (!endReplace) {
Log.i(TAG + " getEvents - loop", i22 + "");
i22++;
matcher = pattern.matcher(return_api); matcher = pattern.matcher(return_api);
if (matcher.find()) { if (matcher.find()) {
filename = matcher.group(1); 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); return_api = return_api
} .replaceFirst(
else { "Unable to process XML data file[^\n]*\n[^\n]*line 187 thread .*\n",
"Bad XML: " + filename);
} else {
endReplace = true; endReplace = true;
} }
} }
Log.e("return_api", return_api); Log.i(TAG + " getEvents - return_api", return_api);
String[] lines = return_api.split("\n"); String[] lines = return_api.split("\n");
@ -379,59 +404,51 @@ public class PandroidEventviewerActivity extends TabActivity implements Serializ
EventListItem event = new EventListItem(); EventListItem event = new EventListItem();
if (items.length != 21) { if (items.length != 21) {
event.event = getApplication().getString(R.string.unknown_event_str); event.event = getApplication().getString(
} R.string.unknown_event_str);
else { } else {
if (items[0].length() == 0) { if (items[0].length() == 0) {
event.id_event = 0; event.id_event = 0;
} } else {
else {
event.id_event = Integer.parseInt(items[0]); event.id_event = Integer.parseInt(items[0]);
} }
if (items[1].length() == 0) { if (items[1].length() == 0) {
event.id_agent = 0; event.id_agent = 0;
} } else {
else {
event.id_agent = Integer.parseInt(items[1]); event.id_agent = Integer.parseInt(items[1]);
} }
event.id_user = items[2]; event.id_user = items[2];
if (items[3].length() == 0) { if (items[3].length() == 0) {
event.id_group = 0; event.id_group = 0;
} } else {
else {
event.id_group = Integer.parseInt(items[3]); event.id_group = Integer.parseInt(items[3]);
} }
if (items[4].length() == 0) { if (items[4].length() == 0) {
event.status = 0; event.status = 0;
} } else {
else {
event.status = Integer.parseInt(items[4]); event.status = Integer.parseInt(items[4]);
} }
event.timestamp = items[5]; event.timestamp = items[5];
event.event = items[6]; event.event = items[6];
if (items[7].length() == 0) { if (items[7].length() == 0) {
event.utimestamp = 0; event.utimestamp = 0;
} } else {
else {
event.utimestamp = Integer.parseInt(items[7]); event.utimestamp = Integer.parseInt(items[7]);
} }
event.event_type = items[8]; event.event_type = items[8];
if (items[9].length() == 0) { if (items[9].length() == 0) {
event.id_agentmodule = 0; event.id_agentmodule = 0;
} } else {
else {
event.id_agentmodule = Integer.parseInt(items[9]); event.id_agentmodule = Integer.parseInt(items[9]);
} }
if (items[10].length() == 0) { if (items[10].length() == 0) {
event.id_alert_am = 0; event.id_alert_am = 0;
} } else {
else {
event.id_alert_am = Integer.parseInt(items[10]); event.id_alert_am = Integer.parseInt(items[10]);
} }
if (items[11].length() == 0) { if (items[11].length() == 0) {
event.criticity = 0; event.criticity = 0;
} } else {
else {
event.criticity = Integer.parseInt(items[11]); event.criticity = Integer.parseInt(items[11]);
} }
event.user_comment = items[12]; event.user_comment = items[12];
@ -448,29 +465,34 @@ public class PandroidEventviewerActivity extends TabActivity implements Serializ
} }
this.eventList.add(event); this.eventList.add(event);
} }
//this.count_events = (long)this.eventList.size(); } catch (Exception e) {
} Log.e(TAG + " getEvents", e.getMessage());
catch (Exception e) {
Log.e("EXCEPTION PandroidEventviewerActivity getEvents", e.getMessage());
return; return;
} }
} }
/**
* Executes the async task of getting events.
*/
public void executeBackgroundGetEvents() { public void executeBackgroundGetEvents() {
new GetEventsAsyncTask().execute(); new GetEventsAsyncTask().execute();
} }
/**
* Get events from pandora console (async task)
*
* @author Miguel de Dios Matías
*
*/
public class GetEventsAsyncTask extends AsyncTask<Void, Void, Void> { 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);
} }
@ -478,8 +500,7 @@ public class PandroidEventviewerActivity extends TabActivity implements Serializ
} }
@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) {
@ -487,8 +508,7 @@ public class PandroidEventviewerActivity extends TabActivity implements Serializ
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);
} }

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,8 +25,14 @@ 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;
@ -28,12 +50,16 @@ public class PandroidEventviewerService extends Service {
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(

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,29 +39,28 @@ 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;
private String user;
private String password;
public PandroidEventviewerActivity object;
public Core core;
public String url;
public String user;
public String password;
/** Called when the activity is first created. */
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
Intent i = getIntent(); Intent i = getIntent();
this.id_event = i.getIntExtra("id_event", -1); this.id_event = i.getIntExtra("id_event", -1);
//this.object = (PandroidEventviewerActivity)i.getSerializableExtra("object"); // this.core = (Core)i.getSerializableExtra("core");
this.core = (Core)i.getSerializableExtra("core");
setContentView(R.layout.popup_validation_event); setContentView(R.layout.popup_validation_event);
final Button button = (Button) findViewById(R.id.button_validate_event); final Button button = (Button) findViewById(R.id.button_validate_event);
button.setOnClickListener(new View.OnClickListener() { button.setOnClickListener(new View.OnClickListener() {
@ -56,7 +71,10 @@ public class PopupValidationEvent extends Activity {
}); });
} }
public void validateEvent() { /**
* Validates the event
*/
private void validateEvent() {
EditText textbox = (EditText) findViewById(R.id.comment); EditText textbox = (EditText) findViewById(R.id.comment);
String comment = textbox.getText().toString(); String comment = textbox.getText().toString();
Button button = (Button) findViewById(R.id.button_validate_event); Button button = (Button) findViewById(R.id.button_validate_event);
@ -70,16 +88,26 @@ public class PopupValidationEvent extends Activity {
new SendValidationAsyncTask().execute(); new SendValidationAsyncTask().execute();
} }
public void destroyPopup() { /**
* Finish the activity
*/
private void destroyPopup() {
finish(); finish();
} }
public boolean sendValidation() { /**
* Sends the validation to server.
*
* @return <b>true</b> if it was done.
*/
private boolean sendValidation() {
boolean return_var = false; 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(
getApplicationContext().getString(
R.string.const_string_preferences),
Activity.MODE_PRIVATE); Activity.MODE_PRIVATE);
this.url = preferences.getString("url", ""); this.url = preferences.getString("url", "");
@ -103,29 +131,36 @@ public class PopupValidationEvent extends Activity {
parameters.add(new BasicNameValuePair("pass", this.password)); parameters.add(new BasicNameValuePair("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(
this.id_event).toString()));
parameters.add(new BasicNameValuePair("other", this.comment)); parameters.add(new BasicNameValuePair("other", this.comment));
entity = new UrlEncodedFormEntity(parameters); entity = new UrlEncodedFormEntity(parameters);
httpPost.setEntity(entity); httpPost.setEntity(entity);
response = httpClient.execute(httpPost); response = httpClient.execute(httpPost);
entityResponse = response.getEntity(); entityResponse = response.getEntity();
return_api = Core.convertStreamToString(entityResponse.getContent()); return_api = Core
.convertStreamToString(entityResponse.getContent());
return_api = return_api.replace("\n", ""); return_api = return_api.replace("\n", "");
if (return_api.startsWith("Correct validation")) { if (return_api.startsWith("Correct validation")) {
return_var = true; return_var = true;
} }
} } catch (Exception e) {
catch (Exception e) {
Log.e("EXCEPTION sendValidation", e.getMessage()); 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) {
@ -135,18 +170,19 @@ public class PopupValidationEvent extends Activity {
} }
@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 { } else {
text = getApplicationContext().getString(R.string.fail_validate_event_str); text = getApplicationContext().getString(
R.string.fail_validate_event_str);
} }
Toast toast = Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT); Toast toast = Toast.makeText(getApplicationContext(), text,
Toast.LENGTH_SHORT);
toast.show(); toast.show();
destroyPopup(); destroyPopup();