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 60410f8350
commit 6283e5052f
21 changed files with 2715 additions and 2088 deletions

View File

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

View File

@ -15,75 +15,78 @@
// GNU General Public License for more details. // GNU General Public License for more details.
--> -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="pandroid_event_viewer.pandorafms" package="pandroid_event_viewer.pandorafms"
android:versionCode="2" android:versionCode="2"
android:versionName="1.1"> android:versionName="1.1" >
<uses-sdk android:minSdkVersion="8" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.VIBRATE" />
<!-- <!--
android:configChanges="orientation|keyboardHidden" android:configChanges="orientation|keyboardHidden"
This is crazy, I want only block the screen rotation, but the android need This is crazy, I want only block the screen rotation, but the android need
two things. two things.
--> -->
<application android:icon="@drawable/pandorafms_logo" <application
android:label="Pandroid Event viewer" android:description="@string/pandroid_event_viewer_description_str"
android:description="@string/pandroid_event_viewer_description_str" android:icon="@drawable/pandorafms_logo"
> android:label="Pandroid Event viewer" >
<activity <activity
android:name=".PandroidEventviewerActivity" android:name=".PandroidEventviewerActivity"
android:label="Pandroid Event viewer" android:configChanges="orientation|keyboardHidden"
android:theme="@android:style/Theme.NoTitleBar" android:label="Pandroid Event viewer"
android:configChanges="orientation|keyboardHidden" android:theme="@android:style/Theme.NoTitleBar" >
> <intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity <activity
android:name=".Main" android:name=".Main"
android:configChanges="orientation|keyboardHidden" android:configChanges="orientation|keyboardHidden" >
>
</activity> </activity>
<activity <activity
android:name=".EventList" android:name=".EventList"
android:configChanges="orientation|keyboardHidden" android:configChanges="orientation|keyboardHidden" >
>
</activity> </activity>
<activity <activity
android:name=".Options" android:name=".Options"
android:label="@string/option_title_str" android:configChanges="orientation|keyboardHidden"
android:configChanges="orientation|keyboardHidden" android:label="@string/option_title_str" >
>
</activity>
<activity
android:name=".About"
android:label="@string/pandroid_event_viewer_str"
android:configChanges="orientation|keyboardHidden"
android:theme="@android:style/Theme.Dialog"
>
</activity> </activity>
<activity <activity
android:name=".PopupValidationEvent" android:name=".About"
android:label="@string/validate_event_button_str" android:configChanges="orientation|keyboardHidden"
android:theme="@android:style/Theme.Dialog" android:label="@string/pandroid_event_viewer_str"
android:configChanges="orientation|keyboardHidden" android:theme="@android:style/Theme.Dialog" >
>
</activity> </activity>
<activity <activity
android:name=".Info" android:name=".PopupValidationEvent"
android:label="@string/pandroid_event_viewer_str" android:configChanges="orientation|keyboardHidden"
android:configChanges="orientation|keyboardHidden" android:label="@string/validate_event_button_str"
android:theme="@android:style/Theme.Dialog" android:theme="@android:style/Theme.Dialog" >
> </activity>
<activity
android:name=".Info"
android:configChanges="orientation|keyboardHidden"
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" <TextView
android:layout_width="fill_parent" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
> android:text="@string/agent_label_str" />
<TextView
android:text="@string/agent_label_str" <EditText
android:layout_width="wrap_content" android:id="@+id/agent_name"
android:layout_height="wrap_content" android:layout_width="fill_parent"
/> android:layout_height="wrap_content"
<EditText android:inputType="text"
android:id="@+id/agent_name" android:singleLine="true" />
android:layout_height="wrap_content"
android:singleLine="true" <TextView
android:editable="true" android:layout_width="wrap_content"
android:layout_width="fill_parent" android:layout_height="wrap_content"
/> android:text="@string/event_search_label_str" />
<TextView
android:text="@string/event_search_label_str" <EditText
android:layout_width="wrap_content" android:id="@+id/event_search_text"
android:layout_height="wrap_content" android:layout_width="fill_parent"
/> android:layout_height="wrap_content"
<EditText android:inputType="text"
android:id="@+id/event_search_text" android:singleLine="true" />
android:layout_height="wrap_content"
android:singleLine="true" <TableLayout
android:editable="true" android:layout_width="fill_parent"
android:layout_width="fill_parent" android:layout_height="wrap_content" >
/>
<TableLayout <TableRow android:visibility="gone" >
android:layout_width="fill_parent"
android:layout_height="wrap_content" <TextView
> android:layout_width="wrap_content"
<TableRow android:layout_height="wrap_content"
android:visibility="gone" android:layout_weight="1"
> android:paddingRight="5dip"
<TextView android:text="@string/group_label_str" />
android:text="@string/group_label_str"
android:layout_width="wrap_content" <Spinner
android:layout_height="wrap_content" android:id="@+id/group_combo"
android:paddingRight="5dip" android:layout_width="wrap_content"
android:layout_weight="1" android:layout_height="wrap_content"
/> android:visibility="gone" />
<Spinner
android:id="@+id/group_combo" <ProgressBar
android:layout_width="wrap_content" android:id="@+id/loading_group"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:visibility="gone" android:layout_height="wrap_content"
/> android:layout_gravity="right" />
<ProgressBar </TableRow>
android:id="@+id/loading_group"
android:layout_width="wrap_content" <TableRow>
android:layout_height="wrap_content"
android:layout_gravity="right" <TextView
/> android:layout_width="wrap_content"
</TableRow> android:layout_height="wrap_content"
<TableRow> android:layout_weight="1"
<TextView android:paddingRight="5dip"
android:text="@string/severity_label_str" android:text="@string/severity_label_str" />
android:layout_width="wrap_content"
android:layout_height="wrap_content" <Spinner
android:paddingRight="5dip" android:id="@+id/severity_combo"
android:layout_weight="1" android:layout_width="wrap_content"
/> android:layout_height="wrap_content" />
<Spinner </TableRow>
android:id="@+id/severity_combo"
android:layout_width="wrap_content" <TableRow>
android:layout_height="wrap_content" <TextView
/> android:layout_width="wrap_content"
</TableRow> android:layout_height="wrap_content"
<TableRow> android:layout_weight="1"
<TextView android:paddingRight="5dip"
android:text="@string/status_label_str" android:text="@string/status_label_str" />
android:layout_width="wrap_content"
android:layout_height="wrap_content" <Spinner
android:paddingRight="5dip" android:id="@+id/status_combo"
android:layout_weight="1" android:layout_width="wrap_content"
/> android:layout_height="wrap_content"/>
<Spinner </TableRow>
android:id="@+id/status_combo"
android:layout_width="wrap_content" <TableRow>
android:layout_height="wrap_content" <TextView
/> android:layout_width="wrap_content"
</TableRow> android:layout_height="wrap_content"
</TableLayout> android:layout_weight="1"
<!-- android:paddingRight="5dip"
<TextView android:text="@string/max_time_old_event_str"/>
android:text="@string/date_label_str"
android:layout_width="wrap_content" <Spinner
android:layout_height="wrap_content" android:id="@+id/max_time_old_event_combo"
android:paddingRight="5dip" android:layout_width="wrap_content"
/> android:layout_height="wrap_content"/>
<TimePicker </TableRow>
android:textSize="10sp" </TableLayout>
android:id="@+id/time"
android:layout_width="wrap_content" <LinearLayout
android:layout_height="wrap_content" android:layout_width="fill_parent"
/> android:layout_height="2dp"
<DatePicker android:layout_marginBottom="10dp"
android:id="@+id/date" android:layout_marginTop="10dp"
android:layout_width="wrap_content" android:background="#ffffff" />
android:layout_height="wrap_content"
/> <LinearLayout
--> xmlns:android="http://schemas.android.com/apk/res/android"
<TextView android:layout_width="fill_parent"
android:text="@string/max_time_old_event_str" android:layout_height="fill_parent"
android:layout_width="wrap_content" android:orientation="horizontal" >
android:layout_height="wrap_content"
android:paddingRight="5dip" <Button
/> android:id="@+id/button_reset"
<Spinner android:layout_width="wrap_content"
android:id="@+id/max_time_old_event_combo" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:layout_weight="1"
android:layout_height="wrap_content" android:text="@string/reset_button_str" />
android:layout_gravity="right"
/> <Button
<LinearLayout android:id="@+id/button_send"
android:layout_marginTop="10px" android:layout_width="wrap_content"
android:layout_marginBottom="10px" android:layout_height="wrap_content"
android:layout_height="2px" android:layout_weight="1"
android:layout_width="fill_parent" android:text="@string/search_button_str" />
android:background="#ffffff" </LinearLayout>
/>
<LinearLayout <Button
xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/button_set_as_filter_watcher"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_height="fill_parent" android:text="@string/set_as_filter_watcher_button_str" />
> </LinearLayout>
<Button
android:text="@string/reset_button_str" </ScrollView>
android:id="@+id/button_reset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<Button
android:text="@string/search_button_str"
android:id="@+id/button_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
</LinearLayout>
<Button
android:text="@string/set_as_filter_watcher_button_str"
android:id="@+id/button_set_as_filter_watcher"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
</ScrollView>
</LinearLayout>

View File

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

View File

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

View File

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

View File

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

View File

@ -1,3 +1,19 @@
/*
Pandora FMS - http://pandorafms.com
==================================================
Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
Please see http://pandorafms.org for full contribution list
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation; version 2
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
package pandroid_event_viewer.pandorafms; package pandroid_event_viewer.pandorafms;
import java.util.ArrayList; import java.util.ArrayList;
@ -20,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,231 +58,290 @@ 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(
context.getString(R.string.const_string_preferences), context.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE); Activity.MODE_PRIVATE);
this.url = preferences.getString("url", ""); this.url = preferences.getString("url", "");
this.user = preferences.getString("user", ""); this.user = preferences.getString("user", "");
this.password = preferences.getString("password", ""); this.password = preferences.getString("password", "");
Calendar c = Calendar.getInstance(); Calendar c = Calendar.getInstance();
long now = (c.getTimeInMillis() / 1000); long now = (c.getTimeInMillis() / 1000);
long old_previous_filterTimestamp = preferences.getLong("previous_filterTimestamp", now); long old_previous_filterTimestamp = preferences.getLong(
"previous_filterTimestamp", now);
if ((user.length() == 0) && (password.length() == 0) if ((user.length() == 0) && (password.length() == 0)
&& (url.length() == 0)) { && (url.length() == 0)) {
return; return;
} }
try { try {
DefaultHttpClient httpClient = new DefaultHttpClient(); DefaultHttpClient httpClient = new DefaultHttpClient();
UrlEncodedFormEntity entity; UrlEncodedFormEntity entity;
HttpPost httpPost; HttpPost httpPost;
List<NameValuePair> parameters; List<NameValuePair> parameters;
HttpResponse response; HttpResponse response;
HttpEntity entityResponse; HttpEntity entityResponse;
String return_api; String return_api;
httpPost = new HttpPost(this.url + "/include/api.php"); httpPost = new HttpPost(this.url + "/include/api.php");
String parametersAPI = serializeParams2Api(context); String parametersAPI = serializeParams2Api(context);
//Get total count. // Get total count.
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 + "|total")); parameters.add(new BasicNameValuePair("return_type", "csv"));
entity = new UrlEncodedFormEntity(parameters); parameters.add(new BasicNameValuePair("other", parametersAPI
httpPost.setEntity(entity); + "|total"));
response = httpClient.execute(httpPost); entity = new UrlEncodedFormEntity(parameters);
entityResponse = response.getEntity(); httpPost.setEntity(entity);
return_api = Core.convertStreamToString(entityResponse.getContent()); response = httpClient.execute(httpPost);
entityResponse = response.getEntity();
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
parameters.add(new BasicNameValuePair("op", "get")); .add(new BasicNameValuePair("pass", this.password));
parameters.add(new BasicNameValuePair("op2", "events")); parameters.add(new BasicNameValuePair("op", "get"));
parameters.add(new BasicNameValuePair("other_mode", "url_encode_separator_|")); parameters.add(new BasicNameValuePair("op2", "events"));
parameters.add(new BasicNameValuePair("return_type", "csv")); parameters.add(new BasicNameValuePair("other_mode",
parameters.add(new BasicNameValuePair("other", parametersAPI + "|more_criticity")); "url_encode_separator_|"));
entity = new UrlEncodedFormEntity(parameters); parameters
httpPost.setEntity(entity); .add(new BasicNameValuePair("return_type", "csv"));
response = httpClient.execute(httpPost); parameters.add(new BasicNameValuePair("other",
entityResponse = response.getEntity(); parametersAPI + "|more_criticity"));
return_api = Core.convertStreamToString(entityResponse.getContent()); entity = new UrlEncodedFormEntity(parameters);
return_api = return_api.replace("\n", ""); httpPost.setEntity(entity);
this.more_criticity = new Integer(return_api).intValue(); response = httpClient.execute(httpPost);
entityResponse = response.getEntity();
return_api = Core.convertStreamToString(entityResponse
.getContent());
return_api = return_api.replace("\n", "");
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.commit(); editorPreferences.putLong("previous_filterTimestamp",
} old_previous_filterTimestamp);
editorPreferences.commit();
}
} } catch (Exception e) {
catch (Exception e) { Log.e(TAG + " EXCEPTION checkNewEvents", e.getMessage());
Log.e("EXCEPTION checkNewEvents", e.getMessage()); return;
}
return;
}
} }
} }
public String serializeParams2Api(Context context) { /**
SharedPreferences preferences = context.getSharedPreferences( * Builds an api call from all filter parameters
context.getString(R.string.const_string_preferences), *
Activity.MODE_PRIVATE); * @param context
* @return Api call.
*/
public String serializeParams2Api(Context context) {
SharedPreferences preferences = context.getSharedPreferences(
context.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
String filterAgentName = preferences.getString("filterAgentName", ""); String filterAgentName = preferences.getString("filterAgentName", "");
int filterIDGroup = preferences.getInt("filterIDGroup", 0); // TODO no api parameter, waiting for it
int filterSeverity = preferences.getInt("filterSeverity", -1); // int filterIDGroup = preferences.getInt("filterIDGroup", 0);
int filterStatus = preferences.getInt("filterStatus", 3); int filterSeverity = preferences.getInt("filterSeverity", -1);
String filterEventSearch = preferences.getString("filterEventSearch", ""); int filterStatus = preferences.getInt("filterStatus", 3);
String filterEventSearch = preferences.getString("filterEventSearch",
"");
Calendar c = Calendar.getInstance();
long now = (c.getTimeInMillis() / 1000);
long filterTimestamp = preferences.getLong("filterTimestamp", now);
SharedPreferences.Editor editorPreferences = preferences.edit();
// Save for the next execution
editorPreferences.putLong("filterTimestamp", now);
// Save the previous for the list.
editorPreferences.putLong("previous_filterTimestamp", filterTimestamp);
if (editorPreferences.commit()) {
Log.i(TAG + " (filter options)",
"Configuration changes commited (timestamp)");
} else {
Log.e(TAG + " (filter options)",
"Configuration changes not commited");
}
Calendar c = Calendar.getInstance(); String return_var = "";
long now = (c.getTimeInMillis() / 1000);
long filterTimestamp = preferences.getLong("filterTimestamp", now);
SharedPreferences.Editor editorPreferences = preferences.edit();
editorPreferences.putLong("filterTimestamp", now); //Save for the next execution.
editorPreferences.putLong("previous_filterTimestamp", filterTimestamp); //Save and the previous for the list.
if (editorPreferences.commit()) {
Log.e("AlarmReceiver serializeParams2Api", "YES COMMIT");
}
else {
Log.e("AlarmReceiver serializeParams2Api", "NOT COMMIT");
}
return_var += ';'; // Separator for the csv
return_var += "|";
return_var += Integer.toString(filterSeverity); // Criticity or severity
return_var += "|";
return_var += filterAgentName; // The agent name
return_var += "|";
return_var += ""; // Name of module
return_var += "|";
return_var += ""; // Name of alert template
return_var += "|";
return_var += ""; // Id user
return_var += "|";
return_var += Long.toString(filterTimestamp); // The minimun timestamp
return_var += "|";
return_var += ""; // The maximum timestamp
return_var += "|";
return_var += filterStatus; // The status
return_var += "|";
return_var += filterEventSearch; // The free search in the text event
// description.
return_var += "|";
return_var += Integer.toString(0); // The pagination of list events
return_var += "|";
return_var += Long.toString(0); // The offset of list events
String return_var = ""; Log.i(TAG + " serializeParams2Api", return_var);
return return_var;
}
/**
* Launchs a notification
*
* @param context
*/
public void notificationEvent(Context context) {
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) context
.getSystemService(ns);
return_var += ';'; //Separator for the csv mNotificationManager.cancel(NOTIFICATION_PANDROID_EVENT_VIEWER);
return_var += "|";
return_var += Integer.toString(filterSeverity); //Criticity or severity
return_var += "|";
return_var += filterAgentName; //The agent name
return_var += "|";
return_var += ""; //Name of module
return_var += "|";
return_var += ""; //Name of alert template
return_var += "|";
return_var += ""; //Id user
return_var += "|";
return_var += Long.toString(filterTimestamp); //The minimun timestamp
return_var += "|";
return_var += ""; //The maximum timestamp
return_var += "|";
return_var += filterStatus; //The status
return_var += "|";
return_var += filterEventSearch; //The free search in the text event description.
return_var += "|";
return_var += Integer.toString(0); //The pagination of list events
return_var += "|";
return_var += Long.toString(0); //The offset of list events
Log.e("AlarmReceiver serializeParams2Api", return_var); int icon;
CharSequence tickerText;
return return_var; switch (this.more_criticity) {
} case 0:
icon = R.drawable.criticity_0;
tickerText = context.getString(
R.string.notification_criticity_0_str).replace("%s",
new Long(this.count_events).toString());
break;
case 1:
icon = R.drawable.criticity_1;
tickerText = context.getString(
R.string.notification_criticity_1_str).replace("%s",
new Long(this.count_events).toString());
break;
case 2:
icon = R.drawable.criticity_2;
tickerText = context.getString(
R.string.notification_criticity_2_str).replace("%s",
new Long(this.count_events).toString());
break;
case 3:
icon = R.drawable.criticity_3;
tickerText = context.getString(
R.string.notification_criticity_3_str).replace("%s",
new Long(this.count_events).toString());
break;
case 4:
icon = R.drawable.criticity_4;
tickerText = context.getString(
R.string.notification_criticity_4_str).replace("%s",
new Long(this.count_events).toString());
break;
default:
icon = R.drawable.criticity_default;
tickerText = context.getString(
R.string.notification_criticity_2_str).replace("%s",
new Long(this.count_events).toString());
break;
}
private static final int NOTIFICATION_PANDROID_EVENT_VIEWER = 666; long when = System.currentTimeMillis();
public void notificationEvent(Context context) {
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns);
Notification notification = new Notification(icon, tickerText, when);
// notification.defaults |= Notification.DEFAULT_ALL;
mNotificationManager.cancel(NOTIFICATION_PANDROID_EVENT_VIEWER); 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)");
}
int icon; Intent notificationIntent = new Intent(context,
CharSequence tickerText; PandroidEventviewerActivity.class);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
notificationIntent.putExtra("count_events", this.count_events);
notificationIntent.putExtra("more_criticity", this.more_criticity);
switch (this.more_criticity) { PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
case 0: notificationIntent, 0);
icon = R.drawable.criticity_0;
tickerText = context.getString(R.string.notification_criticity_0_str)
.replace("%s", new Long(this.count_events).toString());
break;
case 1:
icon = R.drawable.criticity_1;
tickerText = context.getString(R.string.notification_criticity_1_str)
.replace("%s", new Long(this.count_events).toString());
break;
case 2:
icon = R.drawable.criticity_2;
tickerText = context.getString(R.string.notification_criticity_2_str)
.replace("%s", new Long(this.count_events).toString());
break;
case 3:
icon = R.drawable.criticity_3;
tickerText = context.getString(R.string.notification_criticity_3_str)
.replace("%s", new Long(this.count_events).toString());
break;
case 4:
icon = R.drawable.criticity_4;
tickerText = context.getString(R.string.notification_criticity_4_str)
.replace("%s", new Long(this.count_events).toString());
break;
default:
icon = R.drawable.criticity_default;
tickerText = context.getString(R.string.notification_criticity_2_str)
.replace("%s", new Long(this.count_events).toString());
break;
}
CharSequence title = context
.getString(R.string.pandroid_event_viewer_str);
long when = System.currentTimeMillis(); notification.setLatestEventInfo(context, title, tickerText,
contentIntent);
Notification notification = new Notification(icon, tickerText, when); Log.i(TAG, "Launching notification");
mNotificationManager.notify(NOTIFICATION_PANDROID_EVENT_VIEWER,
notification);
notification.defaults |= Notification.DEFAULT_ALL; }
notification.flags |= Notification.FLAG_AUTO_CANCEL;
Intent notificationIntent = new Intent(context, PandroidEventviewerActivity.class);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
notificationIntent.putExtra("count_events", this.count_events);
notificationIntent.putExtra("more_criticity", this.more_criticity);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
CharSequence title = context.getString(R.string.pandroid_event_viewer_str);
notification.setLatestEventInfo(context, title, tickerText, contentIntent);
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,102 +26,89 @@ 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 String convertStreamToString(InputStream is) {
BufferedReader reader = new BufferedReader(new InputStreamReader(is),
8 * 1024);
StringBuilder sb = new StringBuilder();
public static final Parcelable.Creator<Core> CREATOR String line = null;
= new Parcelable.Creator<Core>() { try {
while ((line = reader.readLine()) != null) {
@Override sb.append(line + "\n");
public Core createFromParcel(Parcel source) {
// TODO Auto-generated method stub
return new Core(source);
} }
} catch (IOException e) {
@Override e.printStackTrace();
public Core[] newArray(int size) { } finally {
// TODO Auto-generated method stub try {
return new Core[size]; is.close();
} catch (IOException e) {
e.printStackTrace();
} }
}; }
@Override return sb.toString();
public int describeContents() {
// TODO Auto-generated method stub
return 0;
} }
@Override /**
public void writeToParcel(Parcel dest, int flags) { * Converts the maximum time setted to filter events to a timestamp.
// TODO Auto-generated method stub *
dest.writeValue(this.intent_service); * @param timestamp
//dest.writeValue(this.context); //Fucking marshall exception * @param arrayKey
} * @return Time in milliseconds.
*/ */
/////////// public long convertMaxTimeOldEventValuesToTimestamp(long time, int arrayKey) {
public static String convertStreamToString (InputStream is)
{
BufferedReader reader = new BufferedReader(new
InputStreamReader(is), 8*1024);
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return sb.toString();
}
public long convertMaxTimeOldEventValuesToTimestamp(long timestamp, int arrayKey) {
long time = timestamp;
long return_var = 0; long return_var = 0;
if (time == 0) { if (time == 0) {
@ -114,57 +117,57 @@ public class Core implements Serializable {
} }
switch (arrayKey) { switch (arrayKey) {
case 0: case 0:
return_var = time - 30 * 60; return_var = time - 30 * 60;
break; break;
case 1: case 1:
return_var = time - 60 * 60; return_var = time - 60 * 60;
break; break;
case 2: case 2:
return_var = time - 2 * (60 * 60); return_var = time - 2 * (60 * 60);
break; break;
case 3: case 3:
return_var = time - 3 * (60 * 60); return_var = time - 3 * (60 * 60);
break; break;
case 4: case 4:
return_var = time - 4 * (60 * 60); return_var = time - 4 * (60 * 60);
break; break;
case 5: case 5:
return_var = time - 5 * (60 * 60); return_var = time - 5 * (60 * 60);
break; break;
case 6: case 6:
return_var = time - 8 * (60 * 60); return_var = time - 8 * (60 * 60);
break; break;
case 7: case 7:
return_var = time - 10 * (60 * 60); return_var = time - 10 * (60 * 60);
break; break;
case 8: case 8:
return_var = time - 12 * (60 * 60); return_var = time - 12 * (60 * 60);
break; break;
case 9: case 9:
return_var = time - 24 * (60 * 60); return_var = time - 24 * (60 * 60);
break; break;
case 10: case 10:
return_var = time - 2 * (24 * 60 * 60); return_var = time - 2 * (24 * 60 * 60);
break; break;
case 11: case 11:
return_var = time - 3 * (24 * 60 * 60); return_var = time - 3 * (24 * 60 * 60);
break; break;
case 12: case 12:
return_var = time - 4 * (24 * 60 * 60); return_var = time - 4 * (24 * 60 * 60);
break; break;
case 13: case 13:
return_var = time - 5 * (24 * 60 * 60); return_var = time - 5 * (24 * 60 * 60);
break; break;
case 14: case 14:
return_var = time - 7 * (24 * 60 * 60); return_var = time - 7 * (24 * 60 * 60);
break; break;
case 15: case 15:
return_var = time - 2 * (7 * 24 * 60 * 60); return_var = time - 2 * (7 * 24 * 60 * 60);
break; break;
case 16: case 16:
return_var = time - 30 * (24 * 60 * 60); return_var = time - 30 * (24 * 60 * 60);
break; break;
} }
return return_var; return return_var;

View File

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

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);
text.setText(Html
TextView text = (TextView) findViewById(R.id.url_pandora); .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,20 +49,27 @@ import android.widget.ProgressBar;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.Toast; import android.widget.Toast;
/**
* Activity with the filter options.
*
* @author Miguel de Dios Matías
*
*/
public class Main extends Activity { public class Main extends Activity {
public PandroidEventviewerActivity object; private static String TAG = "MAIN";
public HashMap<Integer, String> pandoraGroups; private PandroidEventviewerActivity object;
public Spinner comboSeverity; private HashMap<Integer, String> pandoraGroups;
public Core core; private Spinner comboSeverity;
private Core core;
/** Called when the activity is first created. */
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
Intent i = getIntent(); Intent i = getIntent();
this.object = (PandroidEventviewerActivity)i.getSerializableExtra("object"); this.object = (PandroidEventviewerActivity) i
this.core = (Core)i.getSerializableExtra("core"); .getSerializableExtra("object");
this.core = (Core) i.getSerializableExtra("core");
this.pandoraGroups = new HashMap<Integer, String>(); this.pandoraGroups = new HashMap<Integer, String>();
@ -55,25 +79,23 @@ public class Main extends Activity {
final Button buttonSearch = (Button) findViewById(R.id.button_send); final Button buttonSearch = (Button) findViewById(R.id.button_send);
final Button buttonbuttonSetAsFilterWatcher = (Button) findViewById(R.id.button_set_as_filter_watcher); final Button buttonbuttonSetAsFilterWatcher = (Button) findViewById(R.id.button_set_as_filter_watcher);
//Check if the user preferences it is set. // Check if the user preferences it is set.
if (object.user.length() == 0 || object.password.length() == 0 || if (object.user.length() == 0 || object.password.length() == 0
object.url.length() == 0) { || object.url.length() == 0) {
Toast toast = Toast.makeText(this.getApplicationContext(), Toast toast = Toast.makeText(this.getApplicationContext(),
this.getString(R.string.please_set_preferences_str), this.getString(R.string.please_set_preferences_str),
Toast.LENGTH_SHORT); Toast.LENGTH_SHORT);
toast.show(); toast.show();
buttonReset.setEnabled(false); buttonReset.setEnabled(false);
buttonSearch.setEnabled(false); buttonSearch.setEnabled(false);
buttonbuttonSetAsFilterWatcher.setEnabled(false); buttonbuttonSetAsFilterWatcher.setEnabled(false);
} } else if (object.user.equals("demo") || object.password.equals("demo")) {
else if (object.user.equals("demo") || object.password.equals("demo")) {
Toast toast = Toast.makeText(this.getApplicationContext(), Toast toast = Toast.makeText(this.getApplicationContext(),
this.getString(R.string.preferences_set_demo_pandora_str), this.getString(R.string.preferences_set_demo_pandora_str),
Toast.LENGTH_LONG); Toast.LENGTH_LONG);
toast.show(); toast.show();
} } else {
else {
buttonSearch.setEnabled(false); buttonSearch.setEnabled(false);
buttonReset.setEnabled(false); buttonReset.setEnabled(false);
buttonbuttonSetAsFilterWatcher.setEnabled(false); buttonbuttonSetAsFilterWatcher.setEnabled(false);
@ -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,36 +145,42 @@ 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) {
save_filter_watcher(); save_filter_watcher();
} }
}); });
if (this.object.show_popup_info) { if (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);
} }
} }
public void onRestart() { public void onRestart() {
super.onRestart(); super.onRestart();
if (this.pandoraGroups.size() == 0) { if (this.pandoraGroups.size() == 0) {
Log.e("Main onRestart", "Main onRestart"); Log.i(TAG, "onRestart: getting groups");
new GetGroupsAsyncTask().execute(); new GetGroupsAsyncTask().execute();
} }
} }
public ArrayList<String> getGroups() { /**
* Get groups throught an api call.
*
* @return A list of groups.
*/
private List<String> getGroups() {
ArrayList<String> array = new ArrayList<String>(); ArrayList<String> array = new ArrayList<String>();
SharedPreferences preferences = getSharedPreferences( SharedPreferences preferences = getSharedPreferences(
this.getString(R.string.const_string_preferences), this.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE); Activity.MODE_PRIVATE);
String url = preferences.getString("url", ""); String url = preferences.getString("url", "");
String user = preferences.getString("user", ""); String user = preferences.getString("user", "");
@ -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,43 +208,47 @@ 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");
for (int i= 0; i < lines.length; i++) { for (int i = 0; i < lines.length; i++) {
String[] groups = lines[i].split(";", 21); String[] groups = lines[i].split(";", 21);
this.pandoraGroups.put(new Integer(groups[0]), groups[1]); this.pandoraGroups.put(new Integer(groups[0]), groups[1]);
array.add(groups[1]); array.add(groups[1]);
} }
} } catch (Exception e) {
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);
@ -233,60 +267,48 @@ public class Main extends Activity {
} }
} }
//For options // For options
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater(); MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.options_menu, menu); inflater.inflate(R.menu.options_menu, menu);
return true; return true;
} }
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
Intent i; Intent i;
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.options_button_menu_options: case R.id.options_button_menu_options:
i = new Intent(this, Options.class); i = new Intent(this, Options.class);
//i.putExtra("object", object); i.putExtra("core", new Core());
i.putExtra("core", new Core());
startActivity(i); startActivity(i);
break; break;
case R.id.about_button_menu_options: case R.id.about_button_menu_options:
i = new Intent(this, About.class); i = new Intent(this, About.class);
startActivity(i); startActivity(i);
break; break;
} }
return true; return true;
} }
public void search_form() { /**
//Clean the EventList * Performs the search choice
*/
private void search_form() {
// Clean the EventList
this.object.eventList = new ArrayList<EventListItem>(); this.object.eventList = new ArrayList<EventListItem>();
this.object.loadInProgress = true; this.object.loadInProgress = true;
//Get form data
/*
DatePicker datePicker = (DatePicker)findViewById(R.id.date);
TimePicker timePicker = (TimePicker)findViewById(R.id.time);
int day = datePicker.getDayOfMonth();
int month = datePicker.getMonth();
int year = datePicker.getYear();
int hour = timePicker.getCurrentHour();
int minute = timePicker.getCurrentMinute();
Calendar c = Calendar.getInstance();
c.set(year, month, day, hour, minute);
this.object.timestamp = c.getTimeInMillis() / 1000;
*/
int timeKey = 0; int timeKey = 0;
Spinner combo = (Spinner)findViewById(R.id.max_time_old_event_combo); Spinner combo = (Spinner) findViewById(R.id.max_time_old_event_combo);
timeKey = combo.getSelectedItemPosition(); timeKey = combo.getSelectedItemPosition();
this.object.timestamp = this.core.convertMaxTimeOldEventValuesToTimestamp(0, timeKey); this.object.timestamp = this.core
.convertMaxTimeOldEventValuesToTimestamp(0, timeKey);
EditText text = (EditText) findViewById(R.id.agent_name); EditText text = (EditText) findViewById(R.id.agent_name);
this.object.agentNameStr = text.getText().toString(); this.object.agentNameStr = text.getText().toString();
@ -294,26 +316,28 @@ 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);
String selectedGroup = combo.getSelectedItem().toString(); if (combo.getSelectedItem() != null) {
String selectedGroup = combo.getSelectedItem().toString();
Iterator it = pandoraGroups.entrySet().iterator(); Iterator<Entry<Integer, String>> it = pandoraGroups.entrySet()
while (it.hasNext()) { .iterator();
Map.Entry<Integer, String> e = (Map.Entry<Integer, String>)it.next(); while (it.hasNext()) {
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);
this.object.eventSearch = text.getText().toString(); this.object.eventSearch = text.getText().toString();
this.object.getNewListEvents = true; this.object.getNewListEvents = true;
@ -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();
@ -353,20 +380,18 @@ public class Main extends Activity {
combo = (Spinner) findViewById(R.id.severity_combo); combo = (Spinner) findViewById(R.id.severity_combo);
filterSeverity = combo.getSelectedItemPosition() - 1; filterSeverity = combo.getSelectedItemPosition() - 1;
combo = (Spinner)findViewById(R.id.status_combo); combo = (Spinner) findViewById(R.id.status_combo);
//filterStatus = combo.getSelectedItemPosition() - 1;//The next version re-add please
filterStatus = combo.getSelectedItemPosition() - 0; filterStatus = combo.getSelectedItemPosition() - 0;
combo = (Spinner)findViewById(R.id.max_time_old_event_combo); combo = (Spinner) findViewById(R.id.max_time_old_event_combo);
filterLastTime = combo.getSelectedItemPosition(); filterLastTime = combo.getSelectedItemPosition();
text = (EditText)findViewById(R.id.event_search_text); text = (EditText) findViewById(R.id.event_search_text);
filterEventSearch = text.getText().toString(); filterEventSearch = text.getText().toString();
SharedPreferences preferences = getSharedPreferences( SharedPreferences preferences = getSharedPreferences(
this.getString(R.string.const_string_preferences), this.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE); Activity.MODE_PRIVATE);
SharedPreferences.Editor editorPreferences = preferences.edit(); SharedPreferences.Editor editorPreferences = preferences.edit();
editorPreferences.putString("filterAgentName", filterAgentName); editorPreferences.putString("filterAgentName", filterAgentName);
@ -381,18 +406,22 @@ 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() { /**
EditText text = (EditText)findViewById(R.id.agent_name); * Resets the filter form.
*/
private void reset_form() {
EditText text = (EditText) findViewById(R.id.agent_name);
text.setText(""); text.setText("");
Spinner combo = (Spinner) findViewById(R.id.group_combo); Spinner combo = (Spinner) findViewById(R.id.group_combo);
@ -401,25 +430,14 @@ public class Main extends Activity {
combo = (Spinner) findViewById(R.id.severity_combo); combo = (Spinner) findViewById(R.id.severity_combo);
combo.setSelection(0); combo.setSelection(0);
combo = (Spinner)findViewById(R.id.max_time_old_event_combo); combo = (Spinner) findViewById(R.id.max_time_old_event_combo);
combo.setSelection(6); combo.setSelection(6);
combo = (Spinner)findViewById(R.id.status_combo); combo = (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,116 +1,282 @@
/*
Pandora FMS - http://pandorafms.com
==================================================
Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
Please see http://pandorafms.org for full contribution list
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation; version 2
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
package pandroid_event_viewer.pandorafms; package pandroid_event_viewer.pandorafms;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText; import android.widget.EditText;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
/**
* Options activity.
*
* @author Miguel de Dios Matías
*
*/
public class Options extends Activity { public class Options extends Activity {
public String url; private static String TAG = "Options";
public String user; private static int RINGTONE_PICK_CODE = 999;
public String password; private String url;
public int refreshTimeKey; private String user;
private String password;
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) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
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);
connectionStatus = (TextView) findViewById(R.id.check_connection_status);
new CheckConnectionAsyncTask().execute();
SharedPreferences preferences = getSharedPreferences(
this.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
// Connection
url = preferences.getString("url",
"http://firefly.artica.es/pandora_demo");
user = preferences.getString("user", "demo");
password = preferences.getString("password", "demo");
refreshTimeKey = preferences.getInt("refreshTimeKey", 3);
setContentView(R.layout.options); EditText text = (EditText) findViewById(R.id.url);
text.setText(url);
text = (EditText) findViewById(R.id.user);
text.setText(user);
text = (EditText) findViewById(R.id.password);
text.setText(password);
SharedPreferences preferences = getSharedPreferences( Spinner combo = (Spinner) findViewById(R.id.refresh_combo);
this.getString(R.string.const_string_preferences), ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
Activity.MODE_PRIVATE); this, R.array.refresh_combo,
android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
combo.setAdapter(adapter);
combo.setSelection(refreshTimeKey);
url = preferences.getString("url", "http://firefly.artica.es/pandora_demo"); final Button buttonSearch = (Button) findViewById(R.id.update_options);
user = preferences.getString("user", "demo"); buttonSearch.setOnClickListener(new View.OnClickListener() {
password = preferences.getString("password", "demo");
refreshTimeKey = preferences.getInt("refreshTimeKey", 3);
EditText text = (EditText) findViewById(R.id.url);
text.setText(url);
text = (EditText) findViewById(R.id.user);
text.setText(user);
text = (EditText) findViewById(R.id.password);
text.setText(password);
Spinner combo = (Spinner) findViewById(R.id.refresh_combo);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.refresh_combo, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
combo.setAdapter(adapter);
combo.setSelection(refreshTimeKey);
final Button buttonSearch = (Button) findViewById(R.id.update_options);
buttonSearch.setOnClickListener(new View.OnClickListener() {
@Override @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);
} }
}
public void save_options() { // Notification
SharedPreferences preferences = getSharedPreferences( boolean vibration = preferences.getBoolean("vibration", true);
this.getString(R.string.const_string_preferences), CheckBox cb = (CheckBox) findViewById(R.id.vibration_on);
Activity.MODE_PRIVATE); cb.setChecked(vibration);
SharedPreferences.Editor editorPreferences = preferences.edit(); boolean led = preferences.getBoolean("led", false);
cb = (CheckBox) findViewById(R.id.led_flash_on);
cb.setChecked(led);
EditText text = (EditText) findViewById(R.id.url); Button notificationSound = (Button) findViewById(R.id.sound_button);
String url = text.getText().toString(); Uri defaultSoundUri = Uri.parse(preferences.getString(
if (url.charAt(url.length() - 1) == '/') { "notification_sound_uri",
url = url.substring(0, url.length() - 1); RingtoneManager
} .getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
.toString()));
this.setNewRingtone(notificationSound, defaultSoundUri);
editorPreferences.putString("url", url); notificationSound.setOnClickListener(new OnClickListener() {
//this.object.url = url; @Override
text = (EditText) findViewById(R.id.user); public void onClick(View v) {
editorPreferences.putString("user", text.getText().toString()); Log.i(TAG, "Selecting ringtone");
//this.object.user = text.getText().toString(); Intent intent = new Intent(
text = (EditText) findViewById(R.id.password); RingtoneManager.ACTION_RINGTONE_PICKER);
editorPreferences.putString("password", text.getText().toString()); intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE,
//this.object.password = text.getText().toString(); 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);
}
});
Spinner combo = (Spinner) findViewById(R.id.refresh_combo); }
editorPreferences.putInt("refreshTimeKey", combo.getSelectedItemPosition());
Context context = this.getApplicationContext(); // Gets sound selected
int duration = Toast.LENGTH_SHORT; @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);
}
}
}
if (editorPreferences.commit()) { /**
if (this.core != null) { * Saves all options
this.core.stopServiceEventWatcher(getApplicationContext()); */
this.core.startServiceEventWatcher(getApplicationContext()); private void save_options() {
} SharedPreferences preferences = getSharedPreferences(
this.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
SharedPreferences.Editor editorPreferences = preferences.edit();
// Connection settings
EditText text = (EditText) findViewById(R.id.url);
String url = text.getText().toString();
if (url.charAt(url.length() - 1) == '/') {
url = url.substring(0, url.length() - 1);
}
Toast toast = Toast.makeText(context, this.getString(R.string.config_update_succesful_str), duration); editorPreferences.putString("url", url);
toast.show(); text = (EditText) findViewById(R.id.user);
} editorPreferences.putString("user", text.getText().toString());
else { text = (EditText) findViewById(R.id.password);
Toast toast = Toast.makeText(context, this.getString(R.string.config_update_fail_str), duration); editorPreferences.putString("password", text.getText().toString());
toast.show();
} Spinner combo = (Spinner) findViewById(R.id.refresh_combo);
} editorPreferences.putInt("refreshTimeKey",
combo.getSelectedItemPosition());
// Notification settings
CheckBox cb = (CheckBox) findViewById(R.id.vibration_on);
editorPreferences.putBoolean("vibration", cb.isChecked());
cb = (CheckBox) findViewById(R.id.led_flash_on);
editorPreferences.putBoolean("led", cb.isChecked());
Context context = this.getApplicationContext();
if (editorPreferences.commit()) {
if (this.core != null) {
this.core.stopServiceEventWatcher(getApplicationContext());
this.core.startServiceEventWatcher(getApplicationContext());
}
Log.i(TAG, "Settings saved");
Toast toast = Toast.makeText(context,
this.getString(R.string.config_update_succesful_str),
Toast.LENGTH_SHORT);
toast.show();
} else {
Toast toast = Toast.makeText(context,
this.getString(R.string.config_update_fail_str),
Toast.LENGTH_LONG);
toast.show();
}
}
/**
* Sets ringtone's title (shortens it if necessary) on the button and
* changes ringtone's uri in options. If there is a problem with the given
* Uri, just put "Silence".
*
* @param button
* Target button.
* @param uri
* Ringtone's uri.
*/
private void setNewRingtone(Button button, Uri uri) {
if (uri != null) {
Log.i(TAG, "New ringtone selected: " + uri.toString());
SharedPreferences preferences = getSharedPreferences(
this.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE);
SharedPreferences.Editor editorPreferences = preferences.edit();
editorPreferences.putString("notification_sound_uri",
uri.toString());
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(),
uri);
if (editorPreferences.commit()) {
Log.i(TAG, "New ringtone saved.");
} else {
Log.e(TAG, "Problem saving new ringtone preference.");
}
if (r != null) {
String text = r.getTitle(getApplicationContext());
if (text.length() > 15) {
button.setText(text.substring(0, 15) + "...");
} else {
button.setText(text);
}
} else {
Log.e(TAG, "Sound setting problem (null ringtone)");
button.setText(getString(R.string.silence));
}
} else {
Log.e(TAG, "Sound setting problem (null uri)");
button.setText(getString(R.string.silence));
}
}
/**
* Checks if connection parameters are ok.
*
* @author Santiago Munín González
*
*/
private class CheckConnectionAsyncTask extends AsyncTask<Void, Void, Void> {
private boolean connectionOk = false;
@Override
protected Void doInBackground(Void... arg0) {
// TODO implement check
this.connectionOk = false;
return null;
}
/**
* Choose an image (ok or wrong)
*/
protected void onPostExecute(Void v) {
if (this.connectionOk) {
connectionStatus.setCompoundDrawablesWithIntrinsicBounds(0, 0,
0, R.drawable.ok);
} else {
connectionStatus.setCompoundDrawablesWithIntrinsicBounds(0, 0,
0, R.drawable.cross);
}
}
}
} }

View File

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

View File

@ -1,3 +1,19 @@
/*
Pandora FMS - http://pandorafms.com
==================================================
Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
Please see http://pandorafms.org for full contribution list
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation; version 2
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
package pandroid_event_viewer.pandorafms; package pandroid_event_viewer.pandorafms;
import android.app.Activity; import android.app.Activity;
@ -9,10 +25,16 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.IBinder; import android.os.IBinder;
import android.util.Log; import android.util.Log;
/**
* This service will launch AlarmReceiver periodically.
*
* @author Miguel de Dios Matías
*
*/
public class PandroidEventviewerService extends Service { public class PandroidEventviewerService extends Service {
private static String TAG = "PandroidEventviewerService";
public AlarmManager alarmM; public AlarmManager alarmM;
PendingIntent pendingI; PendingIntent pendingI;
@Override @Override
public IBinder onBind(Intent intent) { public IBinder onBind(Intent intent) {
@ -21,85 +43,89 @@ public class PandroidEventviewerService extends Service {
} }
public void onCreate() { public void onCreate() {
alarmM = (AlarmManager) getSystemService(Context.ALARM_SERVICE); alarmM = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent intentAlarm = new Intent(this, AlarmReceiver.class); Intent intentAlarm = new Intent(this, AlarmReceiver.class);
this.pendingI = PendingIntent.getBroadcast(this, 0, intentAlarm, 0); this.pendingI = PendingIntent.getBroadcast(this, 0, intentAlarm, 0);
int sleepTimeAlarm = convertRefreshTimeKeyToTime(); int sleepTimeAlarm = convertRefreshTimeKeyToTime();
Log.e("PandroidEventviewerService", "sleepTimeAlarm = " + sleepTimeAlarm); Log.i(TAG, "sleepTimeAlarm = " + sleepTimeAlarm);
alarmM.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), sleepTimeAlarm, this.pendingI); alarmM.setRepeating(AlarmManager.RTC_WAKEUP,
System.currentTimeMillis(), sleepTimeAlarm, this.pendingI);
} }
/**
public int convertRefreshTimeKeyToTime() { * Converts chosen time from spinner to seconds (either are seconds or not)
* @return
*/
private int convertRefreshTimeKeyToTime() {
int returnvar = 60 * 10; int returnvar = 60 * 10;
SharedPreferences preferences = getSharedPreferences( SharedPreferences preferences = getSharedPreferences(
this.getString(R.string.const_string_preferences), this.getString(R.string.const_string_preferences),
Activity.MODE_PRIVATE); Activity.MODE_PRIVATE);
int refreshTimeKey = preferences.getInt("refreshTimeKey", 3); int refreshTimeKey = preferences.getInt("refreshTimeKey", 3);
switch (refreshTimeKey) { switch (refreshTimeKey) {
case 0: case 0:
returnvar = 30; //30 seconds returnvar = 30; // 30 seconds
break; break;
case 1: case 1:
returnvar = 60; //1 minute returnvar = 60; // 1 minute
break; break;
case 2: case 2:
returnvar = 60 * 5; //5 minutes returnvar = 60 * 5; // 5 minutes
break; break;
case 3: case 3:
returnvar = 60 * 10; //10 minutes returnvar = 60 * 10; // 10 minutes
break; break;
case 4: case 4:
returnvar = 60 * 15; //15 minutes returnvar = 60 * 15; // 15 minutes
break; break;
case 5: case 5:
returnvar = 60 * 30; //30 minutes returnvar = 60 * 30; // 30 minutes
break; break;
case 6: case 6:
returnvar = 60 * 45; //45 minutes returnvar = 60 * 45; // 45 minutes
break; break;
case 7: case 7:
returnvar = 3600; //1 hour returnvar = 3600; // 1 hour
break; break;
case 8: case 8:
returnvar = 3600 + (60 * 30); //1 hour and 30 minutes returnvar = 3600 + (60 * 30); // 1 hour and 30 minutes
break; break;
case 9: case 9:
returnvar = 3600 * 2; //2 hours returnvar = 3600 * 2; // 2 hours
break; break;
case 10: case 10:
returnvar = 3600 * 3; //3 hours returnvar = 3600 * 3; // 3 hours
break; break;
case 11: case 11:
returnvar = 3600 * 4; //4 hours returnvar = 3600 * 4; // 4 hours
break; break;
case 12: case 12:
returnvar = 3600 * 6; //6 hours returnvar = 3600 * 6; // 6 hours
break; break;
case 13: case 13:
returnvar = 3600 * 8; //8 hours returnvar = 3600 * 8; // 8 hours
break; break;
case 14: case 14:
returnvar = 3600 * 10; //10 hours returnvar = 3600 * 10; // 10 hours
break; break;
case 15: case 15:
returnvar = 3600 * 12; //12 hours returnvar = 3600 * 12; // 12 hours
break; break;
case 16: case 16:
returnvar = 3600 * 24; //24 hours returnvar = 3600 * 24; // 24 hours
break; break;
case 17: case 17:
returnvar = 3600 * 36; //36 hours returnvar = 3600 * 36; // 36 hours
break; break;
case 18: case 18:
returnvar = 3600 * 48; //48 hours returnvar = 3600 * 48; // 48 hours
break; break;
} }
return returnvar * 1000; return returnvar * 1000;

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,109 +39,128 @@ 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; @Override
public Core core; public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
public String url; Intent i = getIntent();
public String user; this.id_event = i.getIntExtra("id_event", -1);
public String password; // this.core = (Core)i.getSerializableExtra("core");
/** Called when the activity is first created. */ setContentView(R.layout.popup_validation_event);
@Override final Button button = (Button) findViewById(R.id.button_validate_event);
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent i = getIntent(); button.setOnClickListener(new View.OnClickListener() {
this.id_event = i.getIntExtra("id_event", -1); @Override
//this.object = (PandroidEventviewerActivity)i.getSerializableExtra("object"); public void onClick(View v) {
this.core = (Core)i.getSerializableExtra("core"); validateEvent();
}
});
}
setContentView(R.layout.popup_validation_event); /**
* Validates the event
*/
private void validateEvent() {
EditText textbox = (EditText) findViewById(R.id.comment);
String comment = textbox.getText().toString();
Button button = (Button) findViewById(R.id.button_validate_event);
ProgressBar pb = (ProgressBar) findViewById(R.id.send_progress);
final Button button = (Button) findViewById(R.id.button_validate_event); button.setVisibility(Button.GONE);
pb.setVisibility(ProgressBar.VISIBLE);
button.setOnClickListener(new View.OnClickListener() { this.comment = "Validate from Pandroid Eventviewer Mobile: " + comment;
@Override
public void onClick(View v) {
validateEvent();
}
});
}
public void validateEvent() { new SendValidationAsyncTask().execute();
EditText textbox = (EditText) findViewById(R.id.comment); }
String comment = textbox.getText().toString();
Button button = (Button) findViewById(R.id.button_validate_event);
ProgressBar pb = (ProgressBar) findViewById(R.id.send_progress);
button.setVisibility(Button.GONE); /**
pb.setVisibility(ProgressBar.VISIBLE); * Finish the activity
*/
private void destroyPopup() {
finish();
}
this.comment = "Validate from Pandroid Eventviewer Mobile: " + comment; /**
* Sends the validation to server.
new SendValidationAsyncTask().execute(); *
} * @return <b>true</b> if it was done.
*/
public void destroyPopup() { private boolean sendValidation() {
finish(); boolean return_var = false;
}
public boolean sendValidation() {
boolean return_var = false;
if (this.url == null) { if (this.url == null) {
SharedPreferences preferences = getApplicationContext().getSharedPreferences( SharedPreferences preferences = getApplicationContext()
getApplicationContext().getString(R.string.const_string_preferences), .getSharedPreferences(
Activity.MODE_PRIVATE); getApplicationContext().getString(
R.string.const_string_preferences),
Activity.MODE_PRIVATE);
this.url = preferences.getString("url", ""); this.url = preferences.getString("url", "");
this.user = preferences.getString("user", ""); this.user = preferences.getString("user", "");
this.password = preferences.getString("password", ""); this.password = preferences.getString("password", "");
} }
try { try {
DefaultHttpClient httpClient = new DefaultHttpClient(); DefaultHttpClient httpClient = new DefaultHttpClient();
UrlEncodedFormEntity entity; UrlEncodedFormEntity entity;
HttpPost httpPost; HttpPost httpPost;
List<NameValuePair> parameters; List<NameValuePair> parameters;
HttpResponse response; HttpResponse response;
HttpEntity entityResponse; HttpEntity entityResponse;
String return_api; String return_api;
httpPost = new HttpPost(this.url + "/include/api.php"); httpPost = new HttpPost(this.url + "/include/api.php");
//Set event validation. // Set event validation.
parameters = new ArrayList<NameValuePair>(); parameters = new ArrayList<NameValuePair>();
parameters.add(new BasicNameValuePair("user", this.user)); parameters.add(new BasicNameValuePair("user", this.user));
parameters.add(new BasicNameValuePair("pass", this.password)); parameters.add(new BasicNameValuePair("pass", this.password));
parameters.add(new BasicNameValuePair("op", "set")); parameters.add(new BasicNameValuePair("op", "set"));
parameters.add(new BasicNameValuePair("op2", "validate_events")); parameters.add(new BasicNameValuePair("op2", "validate_events"));
parameters.add(new BasicNameValuePair("id", new Integer(this.id_event).toString())); parameters.add(new BasicNameValuePair("id", new Integer(
parameters.add(new BasicNameValuePair("other", this.comment)); this.id_event).toString()));
entity = new UrlEncodedFormEntity(parameters); parameters.add(new BasicNameValuePair("other", this.comment));
httpPost.setEntity(entity); entity = new UrlEncodedFormEntity(parameters);
response = httpClient.execute(httpPost); httpPost.setEntity(entity);
entityResponse = response.getEntity(); response = httpClient.execute(httpPost);
return_api = Core.convertStreamToString(entityResponse.getContent()); entityResponse = response.getEntity();
return_api = return_api.replace("\n", ""); return_api = Core
.convertStreamToString(entityResponse.getContent());
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,21 +170,22 @@ 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.show(); Toast.LENGTH_SHORT);
toast.show();
destroyPopup(); destroyPopup();
} }
} }
} }