initial version of android client
authorVictor Kirhenshtein <victor@netxms.org>
Fri, 14 Jan 2011 19:54:31 +0000 (19:54 +0000)
committerVictor Kirhenshtein <victor@netxms.org>
Fri, 14 Jan 2011 19:54:31 +0000 (19:54 +0000)
18 files changed:
.gitattributes
android/src/console/.classpath [new file with mode: 0644]
android/src/console/.project [new file with mode: 0644]
android/src/console/AndroidManifest.xml [new file with mode: 0644]
android/src/console/default.properties [new file with mode: 0644]
android/src/console/res/drawable-hdpi/ic_menu_preferences.png [new file with mode: 0644]
android/src/console/res/drawable-hdpi/icon.png [new file with mode: 0644]
android/src/console/res/drawable-ldpi/icon.png [new file with mode: 0644]
android/src/console/res/drawable-mdpi/ic_menu_preferences.png [new file with mode: 0644]
android/src/console/res/drawable-mdpi/icon.png [new file with mode: 0644]
android/src/console/res/layout/homescreen.xml [new file with mode: 0644]
android/src/console/res/menu/main_menu.xml [new file with mode: 0644]
android/src/console/res/values/strings.xml [new file with mode: 0644]
android/src/console/res/xml/preferences.xml [new file with mode: 0644]
android/src/console/src/org/netxms/ui/android/main/ConsolePreferences.java [new file with mode: 0644]
android/src/console/src/org/netxms/ui/android/main/HomeScreen.java [new file with mode: 0644]
android/src/console/src/org/netxms/ui/android/service/ClientConnectorService.java [new file with mode: 0644]
android/src/console/src/org/netxms/ui/android/service/tasks/ConnectTask.java [new file with mode: 0644]

index 63ae5bb..1ba4f81 100644 (file)
@@ -1,4 +1,19 @@
 * text=auto !eol
+android/src/console/AndroidManifest.xml -text
+android/src/console/default.properties -text
+android/src/console/res/drawable-hdpi/ic_menu_preferences.png -text
+android/src/console/res/drawable-hdpi/icon.png -text
+android/src/console/res/drawable-ldpi/icon.png -text
+android/src/console/res/drawable-mdpi/ic_menu_preferences.png -text
+android/src/console/res/drawable-mdpi/icon.png -text
+android/src/console/res/layout/homescreen.xml -text
+android/src/console/res/menu/main_menu.xml -text
+android/src/console/res/values/strings.xml -text
+android/src/console/res/xml/preferences.xml -text
+android/src/console/src/org/netxms/ui/android/main/ConsolePreferences.java -text
+android/src/console/src/org/netxms/ui/android/main/HomeScreen.java -text
+android/src/console/src/org/netxms/ui/android/service/ClientConnectorService.java -text
+android/src/console/src/org/netxms/ui/android/service/tasks/ConnectTask.java -text
 contrib/backgrounds/.keep -text
 contrib/logo.jpg -text
 contrib/mibs/BAY-STACK-MIB.txt -text
diff --git a/android/src/console/.classpath b/android/src/console/.classpath
new file mode 100644 (file)
index 0000000..0e01999
--- /dev/null
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+       <classpathentry kind="src" path="src"/>
+       <classpathentry kind="src" path="gen"/>
+       <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
+       <classpathentry kind="lib" path="jar/netxms-base-1.1.0.jar"/>
+       <classpathentry kind="lib" path="jar/netxms-client-1.1.0.jar"/>
+       <classpathentry kind="lib" path="jar/netxms-client-api-1.1.0.jar"/>
+       <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/android/src/console/.project b/android/src/console/.project
new file mode 100644 (file)
index 0000000..659be1b
--- /dev/null
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+       <name>android-console</name>
+       <comment></comment>
+       <projects>
+       </projects>
+       <buildSpec>
+               <buildCommand>
+                       <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>org.eclipse.jdt.core.javabuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>com.android.ide.eclipse.adt.ApkBuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+       </buildSpec>
+       <natures>
+               <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
+               <nature>org.eclipse.jdt.core.javanature</nature>
+       </natures>
+</projectDescription>
diff --git a/android/src/console/AndroidManifest.xml b/android/src/console/AndroidManifest.xml
new file mode 100644 (file)
index 0000000..83146c2
--- /dev/null
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+      android:versionCode="1" android:versionName="1.1.0" package="org.netxms.ui.android">
+    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
+    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
+    <uses-permission android:name="android.permission.INTERNET" />
+    <uses-permission android:name="android.permission.VIBRATE" />
+    <application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar" android:enabled="true">
+       <service android:name="org.netxms.ui.android.service.ClientConnectorService"
+                android:label="@string/app_name">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+       </service>
+        <activity android:name="org.netxms.ui.android.main.HomeScreen"
+                  android:label="@string/app_name">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+        <activity android:name="org.netxms.ui.android.main.ConsolePreferences"
+                  android:label="@string/settings">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+    </application>
+<uses-sdk android:minSdkVersion="7"></uses-sdk>
+</manifest> 
\ No newline at end of file
diff --git a/android/src/console/default.properties b/android/src/console/default.properties
new file mode 100644 (file)
index 0000000..9d135cb
--- /dev/null
@@ -0,0 +1,11 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+# 
+# This file must be checked in Version Control Systems.
+# 
+# To customize properties used by the Ant build system use,
+# "build.properties", and override values to adapt the script to your
+# project structure.
+
+# Project target.
+target=android-7
diff --git a/android/src/console/res/drawable-hdpi/ic_menu_preferences.png b/android/src/console/res/drawable-hdpi/ic_menu_preferences.png
new file mode 100644 (file)
index 0000000..81bca4a
Binary files /dev/null and b/android/src/console/res/drawable-hdpi/ic_menu_preferences.png differ
diff --git a/android/src/console/res/drawable-hdpi/icon.png b/android/src/console/res/drawable-hdpi/icon.png
new file mode 100644 (file)
index 0000000..8074c4c
Binary files /dev/null and b/android/src/console/res/drawable-hdpi/icon.png differ
diff --git a/android/src/console/res/drawable-ldpi/icon.png b/android/src/console/res/drawable-ldpi/icon.png
new file mode 100644 (file)
index 0000000..1095584
Binary files /dev/null and b/android/src/console/res/drawable-ldpi/icon.png differ
diff --git a/android/src/console/res/drawable-mdpi/ic_menu_preferences.png b/android/src/console/res/drawable-mdpi/ic_menu_preferences.png
new file mode 100644 (file)
index 0000000..60dbff6
Binary files /dev/null and b/android/src/console/res/drawable-mdpi/ic_menu_preferences.png differ
diff --git a/android/src/console/res/drawable-mdpi/icon.png b/android/src/console/res/drawable-mdpi/icon.png
new file mode 100644 (file)
index 0000000..a07c69f
Binary files /dev/null and b/android/src/console/res/drawable-mdpi/icon.png differ
diff --git a/android/src/console/res/layout/homescreen.xml b/android/src/console/res/layout/homescreen.xml
new file mode 100644 (file)
index 0000000..04e2e1c
--- /dev/null
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout android:id="@+id/MainScreenLayout" 
+               android:orientation="vertical" 
+               android:gravity="fill_horizontal" 
+               android:layout_width="fill_parent" 
+               android:layout_height="fill_parent" 
+               xmlns:android="http://schemas.android.com/apk/res/android">
+       <TextView android:id="@+id/MainScreenTitle" 
+                       android:text="@string/main_title" 
+                       android:textSize="16sp" 
+                       android:textColor="#ffffff" 
+                       android:background="#2b3c8e" 
+                       android:paddingTop="2sp" 
+                       android:paddingBottom="2sp" 
+                       android:paddingLeft="5sp" 
+                       android:paddingRight="5sp" 
+                       android:layout_width="fill_parent" 
+                       android:layout_height="wrap_content">
+       </TextView>
+       <GridView android:id="@+id/ActivityList" 
+                       android:background="#ffffff" 
+                       android:layout_width="fill_parent" 
+                       android:layout_height="fill_parent">
+       </GridView>
+</LinearLayout>
diff --git a/android/src/console/res/menu/main_menu.xml b/android/src/console/res/menu/main_menu.xml
new file mode 100644 (file)
index 0000000..3e9efd2
--- /dev/null
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<menu
+  xmlns:android="http://schemas.android.com/apk/res/android">
+<item android:enabled="true" android:id="@+id/settings" android:title="@string/settings" android:visible="true" android:checkable="false" android:checked="false" android:icon="@drawable/ic_menu_preferences"></item>
+</menu>
diff --git a/android/src/console/res/values/strings.xml b/android/src/console/res/values/strings.xml
new file mode 100644 (file)
index 0000000..7e2e330
--- /dev/null
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <string name="pref_encrypt_summary_disabled">Do not use encryption</string>
+    <string name="pref_encrypt_summary_enabled">Use encryption</string>
+    
+    <string name="pref_encrypt">Encrypt connection</string>
+    <string name="pref_password_summary">NetXMS password</string>
+    <string name="pref_password">Password</string>
+    <string name="pref_login_summary">NetXMS login name</string>
+    <string name="pref_login">User name</string>
+    <string name="pref_server_summary">Name or address of NetXMS server</string>
+    <string name="pref_server">Server</string>
+    <string name="pref_connection">Connection</string>
+    <string name="settings">Settings</string>
+    
+    <string name="app_name">NetXMS Client</string>
+<string name="main_title">NetXMS Management Console</string>
+<string name="notification_title">NetXMS</string>
+
+</resources>
diff --git a/android/src/console/res/xml/preferences.xml b/android/src/console/res/xml/preferences.xml
new file mode 100644 (file)
index 0000000..b105b89
--- /dev/null
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<PreferenceScreen
+  xmlns:android="http://schemas.android.com/apk/res/android">
+<PreferenceCategory android:title="@string/pref_connection"><EditTextPreference android:title="@string/pref_server" android:summary="@string/pref_server_summary" android:enabled="true" android:key="connection.server"></EditTextPreference>
+<EditTextPreference android:title="@string/pref_login" android:summary="@string/pref_login_summary" android:enabled="true" android:defaultValue="admin" android:key="connection.login"></EditTextPreference>
+<EditTextPreference android:enabled="true" android:key="connection.password" android:title="@string/pref_password" android:summary="@string/pref_password_summary"></EditTextPreference>
+<CheckBoxPreference android:title="@string/pref_encrypt" android:key="connection.encrypt" android:enabled="true" android:summaryOn="@string/pref_encrypt_summary_enabled" android:summaryOff="@string/pref_encrypt_summary_disabled" android:defaultValue="false"></CheckBoxPreference>
+</PreferenceCategory>
+</PreferenceScreen>
diff --git a/android/src/console/src/org/netxms/ui/android/main/ConsolePreferences.java b/android/src/console/src/org/netxms/ui/android/main/ConsolePreferences.java
new file mode 100644 (file)
index 0000000..c3724a0
--- /dev/null
@@ -0,0 +1,35 @@
+/**\r
+ * \r
+ */\r
+package org.netxms.ui.android.main;\r
+\r
+import org.netxms.ui.android.R;\r
+import android.os.Bundle;\r
+import android.preference.PreferenceActivity;\r
+\r
+/**\r
+ * Console preferences\r
+ *\r
+ */\r
+public class ConsolePreferences extends PreferenceActivity\r
+{\r
+       /* (non-Javadoc)\r
+        * @see android.preference.PreferenceActivity#onCreate(android.os.Bundle)\r
+        */\r
+       @Override\r
+       protected void onCreate(Bundle savedInstanceState)\r
+       {\r
+               super.onCreate(savedInstanceState);\r
+               addPreferencesFromResource(R.xml.preferences);\r
+       }\r
+\r
+       /* (non-Javadoc)\r
+        * @see android.app.Activity#onPause()\r
+        */\r
+       @Override\r
+       protected void onPause()\r
+       {\r
+               super.onPause();\r
+               \r
+       }\r
+}\r
diff --git a/android/src/console/src/org/netxms/ui/android/main/HomeScreen.java b/android/src/console/src/org/netxms/ui/android/main/HomeScreen.java
new file mode 100644 (file)
index 0000000..4e5cac9
--- /dev/null
@@ -0,0 +1,59 @@
+package org.netxms.ui.android.main;
+
+import org.netxms.ui.android.R;
+import org.netxms.ui.android.service.ClientConnectorService;
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+
+public class HomeScreen extends Activity
+{
+       private ClientConnectorService service;
+       
+       /* (non-Javadoc)
+        * @see android.app.Activity#onCreate(android.os.Bundle)
+        */
+       @Override
+       public void onCreate(Bundle savedInstanceState)
+       {
+               super.onCreate(savedInstanceState);
+               setContentView(R.layout.homescreen);
+
+               startService(new Intent(this, ClientConnectorService.class));
+               
+               /*
+               bindService(new Intent(), new ServiceConnection() {
+                       
+               }, flags);*/
+       }
+
+       /* (non-Javadoc)
+        * @see android.app.Activity#onCreateOptionsMenu(android.view.Menu)
+        */
+       @Override
+       public boolean onCreateOptionsMenu(Menu menu)
+       {
+           MenuInflater inflater = getMenuInflater();
+           inflater.inflate(R.menu.main_menu, menu);
+           return true;
+       }
+
+       /* (non-Javadoc)
+        * @see android.app.Activity#onOptionsItemSelected(android.view.MenuItem)
+        */
+       @Override
+       public boolean onOptionsItemSelected(MenuItem item)
+       {
+               switch(item.getItemId())
+               {
+                       case R.id.settings:
+                               startActivity(new Intent(this, ConsolePreferences.class));
+                               return true;
+                       default:
+                               return super.onOptionsItemSelected(item);
+               }
+       }
+}
diff --git a/android/src/console/src/org/netxms/ui/android/service/ClientConnectorService.java b/android/src/console/src/org/netxms/ui/android/service/ClientConnectorService.java
new file mode 100644 (file)
index 0000000..21e9106
--- /dev/null
@@ -0,0 +1,95 @@
+/**\r
+ * \r
+ */\r
+package org.netxms.ui.android.service;\r
+\r
+import org.netxms.ui.android.R;\r
+import org.netxms.ui.android.main.HomeScreen;\r
+import org.netxms.ui.android.service.tasks.ConnectTask;\r
+import android.app.Notification;\r
+import android.app.NotificationManager;\r
+import android.app.PendingIntent;\r
+import android.app.Service;\r
+import android.content.Intent;\r
+import android.content.SharedPreferences;\r
+import android.os.Binder;\r
+import android.os.IBinder;\r
+import android.preference.PreferenceManager;\r
+\r
+/**\r
+ * Background communication service for NetXMS client.\r
+ *\r
+ */\r
+public class ClientConnectorService extends Service\r
+{\r
+       private Binder binder = new ClientConnectorBinder();\r
+       private NotificationManager notificationManager;\r
+       \r
+   /**\r
+    * Class for clients to access.  Because we know this service always\r
+    * runs in the same process as its clients, we don't need to deal with\r
+    * IPC.\r
+    */\r
+   public class ClientConnectorBinder extends Binder \r
+   {\r
+       ClientConnectorService getService() \r
+      {\r
+               return ClientConnectorService.this;\r
+      }\r
+   }\r
+\r
+   /* (non-Javadoc)\r
+        * @see android.app.Service#onCreate()\r
+        */\r
+       @Override\r
+       public void onCreate()\r
+       {\r
+               super.onCreate();\r
+               \r
+               notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);\r
+               showNotification(1, "NetXMS service started");\r
+               \r
+               reconnect();\r
+       }\r
+\r
+       /* (non-Javadoc)\r
+        * @see android.app.Service#onBind(android.content.Intent)\r
+        */\r
+       @Override\r
+       public IBinder onBind(Intent intent)\r
+       {\r
+               return binder;\r
+       }\r
+\r
+       /* (non-Javadoc)\r
+        * @see android.app.Service#onDestroy()\r
+        */\r
+       @Override\r
+       public void onDestroy()\r
+       {\r
+               super.onDestroy();\r
+       }\r
+       \r
+       /**\r
+        * Show notification\r
+        * \r
+        * @param text\r
+        */\r
+       public void showNotification(int id, String text)\r
+       {\r
+               Notification n = new Notification(android.R.drawable.stat_notify_sdcard, text, System.currentTimeMillis());\r
+               n.defaults = Notification.DEFAULT_ALL;\r
+               \r
+               Intent notifyIntent = new Intent(getApplicationContext(), HomeScreen.class);\r
+               PendingIntent intent = PendingIntent.getActivity(getApplicationContext(), 0, notifyIntent, Intent.FLAG_ACTIVITY_NEW_TASK);\r
+               n.setLatestEventInfo(getApplicationContext(), getString(R.string.notification_title), text, intent);\r
+               \r
+               notificationManager.notify(id, n);\r
+       }\r
+       \r
+       private void reconnect()\r
+       {\r
+               SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);\r
+               new ConnectTask(this).execute(sp.getString("connection.server", ""), sp.getString("connection.login", ""), sp.getString("connection.password", ""));\r
+       }\r
+}\r
diff --git a/android/src/console/src/org/netxms/ui/android/service/tasks/ConnectTask.java b/android/src/console/src/org/netxms/ui/android/service/tasks/ConnectTask.java
new file mode 100644 (file)
index 0000000..35f4ae1
--- /dev/null
@@ -0,0 +1,59 @@
+/**\r
+ * \r
+ */\r
+package org.netxms.ui.android.service.tasks;\r
+\r
+import org.netxms.client.NXCSession;\r
+import org.netxms.ui.android.service.ClientConnectorService;\r
+import android.os.AsyncTask;\r
+\r
+/**\r
+ * @author Victor\r
+ *\r
+ */\r
+public class ConnectTask extends AsyncTask<String, String, NXCSession>\r
+{\r
+       private ClientConnectorService service;\r
+       private Exception exception;\r
+       \r
+       /**\r
+        * Create connect task.\r
+        * \r
+        * @param service\r
+        */\r
+       public ConnectTask(ClientConnectorService service)\r
+       {\r
+               this.service = service;\r
+       }\r
+       \r
+       /* (non-Javadoc)\r
+        * @see android.os.AsyncTask#doInBackground(Params[])\r
+        */\r
+       @Override\r
+       protected NXCSession doInBackground(String... params)\r
+       {\r
+               NXCSession session = new NXCSession(params[0], params[1], params[2]);\r
+               try\r
+               {\r
+                       session.connect();\r
+               }\r
+               catch(Exception e)\r
+               {\r
+                       session = null;\r
+                       exception = e;\r
+               }\r
+               return session;\r
+       }\r
+\r
+       /* (non-Javadoc)\r
+        * @see android.os.AsyncTask#onPostExecute(java.lang.Object)\r
+        */\r
+       @Override\r
+       protected void onPostExecute(NXCSession result)\r
+       {\r
+               if (result != null)\r
+                       service.showNotification(1, "Connected to server " + result.getServerAddress());\r
+               else\r
+                       service.showNotification(1, exception.toString());\r
+       }\r
+}\r