fixed non-working predefind charts on Android 2.2
authorVictor Kirhenshtein <victor@netxms.org>
Fri, 8 Jun 2012 11:24:50 +0000 (11:24 +0000)
committerVictor Kirhenshtein <victor@netxms.org>
Fri, 8 Jun 2012 11:24:50 +0000 (11:24 +0000)
.gitattributes
android/src/console/.classpath
android/src/console/libs/simple-xml-2.4.1.jar [deleted file]
android/src/console/libs/simple-xml-2.6.4.jar [new file with mode: 0644]
android/src/console/src/org/netxms/ui/android/main/activities/GraphBrowser.java
android/src/console/src/org/netxms/ui/android/main/activities/helpers/ChartConfig.java
android/src/console/src/org/netxms/ui/android/main/activities/helpers/XmlDateConverter.java [new file with mode: 0644]

index d14ed98..391cb39 100644 (file)
@@ -6,7 +6,7 @@ android/src/console/.externalToolBuilders/generate_build_number.xml -text
 android/src/console/.externalToolBuilders/run.exe -text
 android/src/console/AndroidManifest.xml -text
 android/src/console/default.properties -text
-android/src/console/libs/simple-xml-2.4.1.jar -text
+android/src/console/libs/simple-xml-2.6.4.jar -text
 android/src/console/lint.xml -text
 android/src/console/project.properties -text
 android/src/console/res/drawable-hdpi-v11/ic_stat_connected.png -text
@@ -120,6 +120,7 @@ android/src/console/src/org/netxms/ui/android/main/activities/HomeScreen.java -t
 android/src/console/src/org/netxms/ui/android/main/activities/LastValues.java -text
 android/src/console/src/org/netxms/ui/android/main/activities/NodeBrowser.java -text
 android/src/console/src/org/netxms/ui/android/main/activities/NodeInfo.java -text
+android/src/console/src/org/netxms/ui/android/main/activities/helpers/XmlDateConverter.java -text
 android/src/console/src/org/netxms/ui/android/main/adapters/ActivityListAdapter.java -text
 android/src/console/src/org/netxms/ui/android/main/adapters/AlarmListAdapter.java -text
 android/src/console/src/org/netxms/ui/android/main/adapters/ConnectionPointListAdapter.java -text
index d43e33a..d012aa7 100644 (file)
@@ -7,6 +7,6 @@
        <classpathentry exported="true" kind="lib" path="libs/netxms-base-1.2.1.jar"/>
        <classpathentry exported="true" kind="lib" path="libs/netxms-client-api-1.2.1.jar"/>
        <classpathentry exported="true" kind="lib" path="libs/netxms-client-1.2.1.jar"/>
-       <classpathentry exported="true" kind="lib" path="libs/simple-xml-2.4.1.jar"/>
+       <classpathentry exported="true" kind="lib" path="libs/simple-xml-2.6.4.jar"/>
        <classpathentry kind="output" path="bin/classes"/>
 </classpath>
diff --git a/android/src/console/libs/simple-xml-2.4.1.jar b/android/src/console/libs/simple-xml-2.4.1.jar
deleted file mode 100644 (file)
index d6fe351..0000000
Binary files a/android/src/console/libs/simple-xml-2.4.1.jar and /dev/null differ
diff --git a/android/src/console/libs/simple-xml-2.6.4.jar b/android/src/console/libs/simple-xml-2.6.4.jar
new file mode 100644 (file)
index 0000000..be60eae
Binary files /dev/null and b/android/src/console/libs/simple-xml-2.6.4.jar differ
index cc34f09..c99729e 100644 (file)
@@ -29,6 +29,8 @@ import android.widget.TextView;
  */\r
 public class GraphBrowser extends AbstractClientActivity\r
 {\r
+       private static final String LOG_TAG = "org.netxms.ui.android.main.activities.GraphBrowser";\r
+       \r
        private ExpandableListView listView;\r
        private GraphAdapter adapter;\r
        ProgressDialog dialog;\r
@@ -111,7 +113,7 @@ public class GraphBrowser extends AbstractClientActivity
                        }\r
                        catch(Exception e)\r
                        {\r
-                               // TODO: notify user about error??\r
+                               Log.w(LOG_TAG, "ChartConfig.createFromXml", e);\r
                                config = new ChartConfig();\r
                        }\r
                        \r
index e0dff4f..1b44b95 100644 (file)
@@ -27,6 +27,8 @@ import org.simpleframework.xml.Element;
 import org.simpleframework.xml.ElementArray;
 import org.simpleframework.xml.Root;
 import org.simpleframework.xml.Serializer;
+import org.simpleframework.xml.convert.AnnotationStrategy;
+import org.simpleframework.xml.convert.Convert;
 import org.simpleframework.xml.core.Persister;
 
 /**
@@ -75,9 +77,11 @@ public class ChartConfig
        private int timeFrameType = GraphSettings.TIME_FRAME_BACK_FROM_NOW;
        
        @Element(required=false)
+       @Convert(XmlDateConverter.class)
        private Date timeFrom;
        
        @Element(required=false)
+       @Convert(XmlDateConverter.class)
        private Date timeTo;
        
        /**
@@ -101,7 +105,7 @@ public class ChartConfig
                        return config;
                }
                
-               Serializer serializer = new Persister();
+               Serializer serializer = new Persister(new AnnotationStrategy());
                return serializer.read(ChartConfig.class, xml);
        }
 
@@ -349,7 +353,7 @@ public class ChartConfig
         */
        public String createXml() throws Exception
        {
-               Serializer serializer = new Persister();
+               Serializer serializer = new Persister(new AnnotationStrategy());
                Writer writer = new StringWriter();
                serializer.write(this, writer);
                return writer.toString();
diff --git a/android/src/console/src/org/netxms/ui/android/main/activities/helpers/XmlDateConverter.java b/android/src/console/src/org/netxms/ui/android/main/activities/helpers/XmlDateConverter.java
new file mode 100644 (file)
index 0000000..eba7b4e
--- /dev/null
@@ -0,0 +1,57 @@
+/**\r
+ * NetXMS - open source network management system\r
+ * Copyright (C) 2003-2012 Victor Kirhenshtein\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
+ */\r
+package org.netxms.ui.android.main.activities.helpers;\r
+\r
+import java.util.Date;\r
+import org.simpleframework.xml.convert.Converter;\r
+import org.simpleframework.xml.stream.InputNode;\r
+import org.simpleframework.xml.stream.OutputNode;\r
+\r
+/**\r
+ * Converter for date serialization/deserialization\r
+ */\r
+public class XmlDateConverter implements Converter<Date>\r
+{\r
+       /* (non-Javadoc)\r
+        * @see org.simpleframework.xml.convert.Converter#read(org.simpleframework.xml.stream.InputNode)\r
+        */\r
+       @Override\r
+       public Date read(InputNode node) throws Exception\r
+       {\r
+               long n;\r
+               try\r
+               {\r
+                       n = Long.parseLong(node.getValue());\r
+               }\r
+               catch(NumberFormatException e)\r
+               {\r
+                       n = System.currentTimeMillis();\r
+               }\r
+               return new Date(n);\r
+       }\r
+\r
+       /* (non-Javadoc)\r
+        * @see org.simpleframework.xml.convert.Converter#write(org.simpleframework.xml.stream.OutputNode, java.lang.Object)\r
+        */\r
+       @Override\r
+       public void write(OutputNode node, Date object) throws Exception\r
+       {\r
+               node.setValue(Long.toString(object.getTime()));\r
+       }\r
+}\r