Updated REServer Andriod application.
authorJay Sharma <jay.sharma@samsung.com>
Tue, 15 Sep 2015 11:39:59 +0000 (17:09 +0530)
committerMadan Lanka <lanka.madan@samsung.com>
Wed, 16 Sep 2015 00:35:31 +0000 (00:35 +0000)
- Updated REServer application for the new bundles : BMI and DI bundles.
- Updated the .xml file for the bundles.

Change-Id: I924f1a17bd2c3f5368e3275b5a019cc2759da7a2
Signed-off-by: Jay Sharma <jay.sharma@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2519
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
service/resource-encapsulation/examples/android/REServer/assets/lib/ResourceContainerConfig.xml
service/resource-encapsulation/examples/android/REServer/res/layout/list_group.xml [new file with mode: 0644]
service/resource-encapsulation/examples/android/REServer/res/layout/list_item.xml [new file with mode: 0644]
service/resource-encapsulation/examples/android/REServer/res/layout/resource_container.xml
service/resource-encapsulation/examples/android/REServer/res/layout/server_builder.xml
service/resource-encapsulation/examples/android/REServer/res/layout/userinputfortemperaturevalue.xml
service/resource-encapsulation/examples/android/REServer/src/com/example/sampleserver/ResourceContainer.java
service/resource-encapsulation/examples/android/REServer/src/com/example/sampleserver/ResourceContainerActivity.java
service/resource-encapsulation/examples/android/REServer/src/com/example/sampleserver/ServerBuilder.java
service/resource-encapsulation/examples/android/REServer/src/com/example/sampleserver/ServerBuilderAutoActivity.java

index df59562..3ba52a2 100644 (file)
@@ -1,28 +1,38 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<container>
+ <container>
     <bundle>
         <id>oic.bundle.discomfortIndexSensor</id>
-        <path>data/data/com.example.sampleresourceserver/files/libSoftSensorBundle.so</path>
+        <path>data/data/com.example.sampleresourceserver/files/libDISensorBundle.so</path>
         <version>1.0.0</version>
         <resources>
             <resourceInfo>
                 <name>DiscomfortIndexSensor1</name>
                 <resourceType>oic.softsensor</resourceType>
                 <outputs>
-                  <output>
-                    <name>discomfortIndex</name>
-                    <type>int</type>
-                  </output>
+                    <output>
+                        <name>discomfortIndex</name>
+                        <type>int</type>
+                    </output>
+                    <output>
+                        <name>humidity</name>
+                        <type>double</type>
+                    </output>
+                    <output>
+                        <name>temperature</name>
+                        <type>double</type>
+                    </output>
                 </outputs>
                 <inputs>
-                  <input>
-                    <name>humidity</name>
-                    <type>double</type>
-                  </input>
-                  <input>
-                    <name>temperature</name>
-                    <type>double</type>
-                  </input>
+                    <input>
+                        <name>humidity</name>
+                        <type>double</type>
+                        <resourceType>oic.sensor.humidity</resourceType>
+                    </input>
+                    <input>
+                        <name>temperature</name>
+                        <type>double</type>
+                        <resourceType>oic.sensor.temperature</resourceType>
+                    </input>
                 </inputs>
             </resourceInfo>
         </resources>
diff --git a/service/resource-encapsulation/examples/android/REServer/res/layout/list_group.xml b/service/resource-encapsulation/examples/android/REServer/res/layout/list_group.xml
new file mode 100644 (file)
index 0000000..4bb77b9
--- /dev/null
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="fill_parent"
+    android:layout_height="wrap_content"
+    android:orientation="vertical"
+    android:padding="8dp" >
+
+    <TextView
+        android:id="@+id/lblListHeader"
+        android:layout_width="fill_parent"
+        android:layout_height="wrap_content"
+        android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft"
+        android:textSize="20dp" />
+
+</LinearLayout>
\ No newline at end of file
diff --git a/service/resource-encapsulation/examples/android/REServer/res/layout/list_item.xml b/service/resource-encapsulation/examples/android/REServer/res/layout/list_item.xml
new file mode 100644 (file)
index 0000000..1241652
--- /dev/null
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="55dip"
+    android:orientation="vertical" >
+
+    <TextView
+        android:id="@+id/lblListItem"
+        android:layout_width="fill_parent"
+        android:layout_height="wrap_content"
+        android:paddingBottom="5dp"
+        android:paddingLeft="?android:attr/expandableListPreferredChildPaddingLeft"
+        android:paddingTop="5dp"
+        android:textSize="20dip" />
+
+</LinearLayout>
\ No newline at end of file
index 0fa92f4..50456c4 100644 (file)
@@ -3,7 +3,7 @@
     android:layout_width="match_parent"
     android:layout_height="match_parent" >
 
-       <Button
+    <Button
         android:id="@+id/startContainer"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_alignParentTop="true"
         android:text="Start Container" />
 
-        <ListView
-            android:id="@+id/containerApiList"
-            android:layout_width="match_parent"
-            android:layout_height="300dp"
-             android:layout_below="@id/startContainer">
-         </ListView>
+    <ExpandableListView
+        android:id="@+id/lvExp"
+        android:layout_width="match_parent"
+        android:layout_height="300dp"
+        android:layout_below="@id/startContainer" />
 
-         <EditText
+    <Button
+        android:id="@+id/listBundles"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignParentRight="true"
+        android:layout_alignParentTop="true"
+        android:text="List Bundles" />
+
+    <EditText
         android:id="@+id/log"
         android:layout_width="fill_parent"
-        android:layout_height="250dp"
+        android:layout_height="wrap_content"
+        android:layout_alignParentBottom="true"
         android:layout_alignParentLeft="true"
-        android:layout_below="@+id/containerApiList"
-        android:layout_marginTop="15dp"
-        android:ems="10"
-        android:editable="false" >
-
-        <requestFocus />
-    </EditText>
-
-         <Button
-             android:id="@+id/stopContainer"
-             android:layout_width="wrap_content"
-             android:layout_height="wrap_content"
-             android:layout_alignParentRight="true"
-             android:layout_alignParentTop="true"
-             android:text="Stop Container" />
+        android:layout_below="@id/lvExp"
+        android:editable="false"
+        android:ems="10" />
 
 </RelativeLayout>
index 1f87f2c..22fb8fc 100644 (file)
@@ -1,14 +1,13 @@
 <?xml version="1.0" encoding="utf-8"?>
-
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent">
 
-     <ListView
-              android:id="@+id/buildeList"
-              android:layout_height="wrap_content"
-              android:layout_width="match_parent">
-         </ListView>
+    <ListView
+        android:id="@+id/buildeList"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content" >
+    </ListView>
 
 </RelativeLayout>
\ No newline at end of file
index 50b5f08..65bbf6f 100644 (file)
@@ -4,32 +4,32 @@
     android:layout_height="match_parent"
     android:orientation="vertical" >
 
-      <EditText
-          android:id="@+id/attributeValue"
-          android:layout_width="wrap_content"
-          android:layout_height="wrap_content"
-          android:layout_alignParentTop="true"
-          android:layout_centerHorizontal="true"
-          android:layout_marginTop="28dp"
-          android:ems="10"
-          android:hint="Enter the Temperature" />
+    <EditText
+        android:id="@+id/attributeValue"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignParentTop="true"
+        android:layout_centerHorizontal="true"
+        android:layout_marginTop="28dp"
+        android:ems="10"
+        android:hint="Enter the Temperature" />
 
-      <Button
-          android:id="@+id/ok"
-          android:layout_width="150dp"
-          android:layout_height="wrap_content"
-          android:layout_alignParentLeft="true"
-          android:layout_below="@+id/region"
-          android:layout_marginTop="101dp"
-          android:text="OK" />
+    <Button
+        android:id="@+id/ok"
+        android:layout_width="150dp"
+        android:layout_height="wrap_content"
+        android:layout_alignParentLeft="true"
+        android:layout_below="@+id/region"
+        android:layout_marginTop="101dp"
+        android:text="OK" />
 
-       <Button
-           android:id="@+id/cancel"
-           android:layout_width="150dp"
-           android:layout_height="wrap_content"
-           android:layout_alignBaseline="@+id/ok"
-           android:layout_alignBottom="@+id/ok"
-           android:layout_alignParentRight="true"
-           android:text="Cancel" />
+    <Button
+        android:id="@+id/cancel"
+        android:layout_width="150dp"
+        android:layout_height="wrap_content"
+        android:layout_alignBaseline="@+id/ok"
+        android:layout_alignBottom="@+id/ok"
+        android:layout_alignParentRight="true"
+        android:text="Cancel" />
 
 </RelativeLayout>
index 70587d5..244d212 100644 (file)
@@ -28,7 +28,6 @@ import java.util.Map;
 import org.iotivity.ResourceEncapsulation.server.RCSBundleInfo;
 import org.iotivity.ResourceEncapsulation.server.RCSResourceContainer;
 
-import android.content.Context;
 import android.os.Message;
 
 /**
@@ -43,8 +42,9 @@ public class ResourceContainer {
     public static String                     logMessage;
     private static ResourceContainerActivity resourceContainerActivityInstance;
     private static Message                   msg;
-    private static boolean                   startBundleFlag;
-    private static boolean                   isStarted = false;
+    public static boolean                    startBundleFlag;
+    public static boolean                    isStarted     = false;
+    public static boolean                    isInitialized = false;
 
     // constructor
     public ResourceContainer() {
@@ -56,18 +56,21 @@ public class ResourceContainer {
     // Start Container
     public void startContainer(String sdCardPath) {
 
-        startBundleFlag = true;
         String configFile = sdCardPath + "/ResourceContainerConfig.xml";
-
-        if (!isStarted) {
+        if (!isStarted && !isInitialized) {
             for (int i = 0; i < 2; i++) {
                 containerInstance.startContainer(configFile);
-                isStarted = true;
             }
+            isStarted = true;
+            isInitialized = true;
         } else {
             containerInstance.startContainer(configFile);
         }
+
         logMessage = "Container Started";
+        logMessage += "with one Bundle" + "\n";
+        logMessage += "ID : oic.bundle.discomfortIndexSensor";
+
         ResourceContainerActivity.setMessageLog(logMessage);
         msg = Message.obtain();
         msg.what = 1;
@@ -81,28 +84,54 @@ public class ResourceContainer {
     // Stop Container
     public void stopContainer() {
 
-        containerInstance.stopContainer();
-        logMessage = "Container stopped";
+        if (isStarted) {
+            containerInstance.stopContainer();
+            logMessage = "Container stopped";
+            isStarted = false;
+            ResourceContainerActivity.setMessageLog(logMessage);
+            msg = Message.obtain();
+            msg.what = 1;
+            resourceContainerActivityInstance.getHandler().sendMessage(msg);
+        }
+    }
+
+    // List Bundle Resources DI
+    public void listBundleResourcesDI() {
+
+        List<String> bundleResources = containerInstance
+                .listBundleResources("oic.bundle.discomfortIndexSensor");
+
+        Iterator<String> it = bundleResources.iterator();
+        logMessage = "";
+
+        if (0 == bundleResources.size()) {
+            logMessage += "No resource found in the bundle" + "\n";
+        } else {
+            while (it.hasNext()) {
+                String element = (String) it.next();
+                logMessage += element + "\n";
+            }
+        }
         ResourceContainerActivity.setMessageLog(logMessage);
         msg = Message.obtain();
         msg.what = 1;
         resourceContainerActivityInstance.getHandler().sendMessage(msg);
     }
 
-    // List Bundle Resources
-    public void listBundleResources() {
+    // List Bundle Resources BMI
+    public void listBundleResourcesBMI() {
 
         List<String> bundleResources = containerInstance
-                .listBundleResources("oic.bundle.discomfortIndexSensor");
+                .listBundleResources("oic.bundle.BMISensor");
         Iterator<String> it = bundleResources.iterator();
         logMessage = "";
 
         if (0 == bundleResources.size()) {
-            logMessage = logMessage + "No resource found in the bundle" + "\n";
+            logMessage += "No resource found in the bundle" + "\n";
         } else {
             while (it.hasNext()) {
                 String element = (String) it.next();
-                logMessage = logMessage + element + "\n";
+                logMessage += element + "\n";
             }
         }
         ResourceContainerActivity.setMessageLog(logMessage);
@@ -116,16 +145,20 @@ public class ResourceContainer {
 
         List<RCSBundleInfo> bundleList = containerInstance.listBundles();
         Iterator<RCSBundleInfo> it = bundleList.iterator();
+        int i = 0;
         logMessage = "";
-        logMessage = logMessage + "size of bundleList : " + bundleList.size()
-                + "\n";
+        logMessage += "size of bundleList : " + bundleList.size() + "\n\n";
 
         while (it.hasNext()) {
-
+            i++;
             RCSBundleInfo object = (RCSBundleInfo) it.next();
-            logMessage = logMessage + "ID :" + object.getID() + "\n";
-            logMessage = logMessage + "Path: " + object.getPath() + "\n";
-            logMessage = logMessage + "version : " + object.getVersion() + "\n";
+            logMessage += "Bundle : " + i + " -: \n";
+            logMessage += "ID : " + object.getID() + "\n";
+            logMessage += "Lib Path: " + object.getPath() + "\n";
+            if (!(object.getVersion().equalsIgnoreCase("")))
+                logMessage += "version : " + object.getVersion() + "\n\n";
+            else
+                logMessage += "\n";
         }
         ResourceContainerActivity.setMessageLog(logMessage);
         msg = Message.obtain();
@@ -133,33 +166,30 @@ public class ResourceContainer {
         resourceContainerActivityInstance.getHandler().sendMessage(msg);
     }
 
-    // Add Bundles
-    public void addBundle() {
+    // Add Bundle BMI
+    public void addBundleBMI() {
 
         Map<String, String> bundleParams = null;
         List<RCSBundleInfo> bundleList = containerInstance.listBundles();
-        if (0 < bundleList.size()) {
+        if (1 < bundleList.size()) {
             logMessage = "Bundle already added" + "\n";
-
         } else {
             for (int i = 0; i < 2; i++) {
                 containerInstance
                         .addBundle(
-                                "oic.bundle.discomfortIndexSensor",
+                                "oic.bundle.BMISensor",
                                 "xyz",
-                                "data/data/com.example.sampleresourceserver/files/libSoftSensorBundle.so",
+                                "data/data/com.example.sampleresourceserver/files/libBMISensorBundle.so",
                                 bundleParams);
             }
 
             logMessage = "bundle to add : " + "\n";
-            logMessage = logMessage + "ID :"
-                    + "oic.bundle.discomfortIndexSensor" + "\n";
-            logMessage = logMessage + "Uri: " + "xyz" + "\n";
-            logMessage = logMessage
-                    + "Path : "
-                    + "data/data/com.re.sampleclient/files/libSoftSensorBundle.so"
+            logMessage += "ID :" + "oic.bundle.BMISensor" + "\n";
+            logMessage += "Uri: " + "xyz" + "\n";
+            logMessage += "Path : "
+                    + "data/data/com.re.sampleclient/files/libBMISensorBundle.so"
                     + "\n";
-            logMessage = logMessage + "bundle added successfully" + "\n";
+            logMessage += "bundle added successfully" + "\n";
         }
 
         ResourceContainerActivity.setMessageLog(logMessage);
@@ -168,24 +198,21 @@ public class ResourceContainer {
         resourceContainerActivityInstance.getHandler().sendMessage(msg);
     }
 
-    // Remove Bundle
-    public void removeBundle() {
+    // Remove Bundle BMI
+    public void removeBundleBMI() {
 
         List<RCSBundleInfo> bundleList = containerInstance.listBundles();
-        if (0 == bundleList.size()) {
-            logMessage = "No bundle to remove" + "\n";
-
+        if (1 == bundleList.size()) {
+            logMessage = "Bundle already removed" + "\n";
         } else {
 
             for (int i = 0; i < 2; i++) {
-                containerInstance
-                        .removeBundle("oic.bundle.discomfortIndexSensor");
+                containerInstance.removeBundle("oic.bundle.BMISensor");
             }
             startBundleFlag = false;
             logMessage = "bundle to remove : " + "\n";
-            logMessage = logMessage + "ID :"
-                    + "oic.bundle.discomfortIndexSensor" + "\n";
-            logMessage = logMessage + " bundle removed  successfully" + "\n";
+            logMessage += "ID :" + "oic.bundle.BMISensor" + "\n";
+            logMessage += " bundle removed  successfully" + "\n";
         }
         ResourceContainerActivity.setMessageLog(logMessage);
         msg = Message.obtain();
@@ -193,22 +220,21 @@ public class ResourceContainer {
         resourceContainerActivityInstance.getHandler().sendMessage(msg);
     }
 
-    // Start Bundle
-    public void startBundle() {
+    // Start Bundle BMI
+    public void startBundleBMI() {
 
         List<RCSBundleInfo> bundleList = containerInstance.listBundles();
-        if (0 == bundleList.size()) {
-            logMessage = "No bundle to Start" + "\n";
+        if (1 == bundleList.size()) {
+            logMessage = "BMI bundle not added" + "\n";
         } else if (true == startBundleFlag) {
             logMessage = "Bundle already started" + "\n";
         } else {
             startBundleFlag = true;
-            containerInstance.startBundle("oic.bundle.discomfortIndexSensor");
+            containerInstance.startBundle("oic.bundle.BMISensor");
 
             logMessage = " bundle to start" + "\n";
-            logMessage = logMessage + " ID : oic.bundle.discomfortIndexSensor"
-                    + "\n";
-            logMessage = logMessage + " bundle started successfully" + "\n";
+            logMessage += " ID : oic.bundle.BMISensor" + "\n";
+            logMessage += " bundle started successfully" + "\n";
         }
         ResourceContainerActivity.setMessageLog(logMessage);
         msg = Message.obtain();
@@ -216,25 +242,21 @@ public class ResourceContainer {
         resourceContainerActivityInstance.getHandler().sendMessage(msg);
     }
 
-    // Stop Bundle
-    public void stopBundle() {
+    // Stop Bundle BMI
+    public void stopBundleBMI() {
 
         if (false == startBundleFlag) {
-            logMessage = "Bundle already stopped" + "\n";
+            logMessage = "Bundle is not Started" + "\n";
         } else {
-
             List<RCSBundleInfo> bundleList = containerInstance.listBundles();
             if (0 == bundleList.size()) {
                 logMessage = "No bundle to Stop" + "\n";
-
             } else {
-                containerInstance
-                        .stopBundle("oic.bundle.discomfortIndexSensor");
+                containerInstance.stopBundle("oic.bundle.BMISensor");
                 startBundleFlag = false;
                 logMessage = " bundle to stop" + "\n";
-                logMessage = logMessage
-                        + " ID : oic.bundle.discomfortIndexSensor" + "\n";
-                logMessage = logMessage + " bundle stopped successfully" + "\n";
+                logMessage += " ID : oic.bundle.BMISensor" + "\n";
+                logMessage += " bundle stopped successfully" + "\n";
             }
         }
 
@@ -244,34 +266,54 @@ public class ResourceContainer {
         resourceContainerActivityInstance.getHandler().sendMessage(msg);
     }
 
-    // Add Resource Configuration
-    public void addResourceConfig() {
+    // Add Resource Configuration to DI bundle
+    public void addResourceConfigDI() {
 
-        if (false == startBundleFlag) {
-            logMessage = "Bundle is not started" + "\n";
+        List<RCSBundleInfo> bundleList = containerInstance.listBundles();
+        List<String> bundleResources = containerInstance
+                .listBundleResources("oic.bundle.discomfortIndexSensor");
 
+        if (0 == bundleList.size()) {
+            logMessage = "No bundle found" + "\n";
+        } else if ((0 == bundleList.size()) && (0 == bundleResources.size())) {
+            logMessage = "No bundle found" + "\n";
         } else {
+            Map<String, String> params = new HashMap<String, String>();
+            params.put("resourceType", "oic.softsensor");
+            params.put("address",
+                    "http://192.168.0.2/api/newdeveloper/sensor/22");
+            containerInstance.addResourceConfig(
+                    "oic.bundle.discomfortIndexSensor", "", params);
+            logMessage = "resource added successfully" + "\n";
+        }
+        ResourceContainerActivity.setMessageLog(logMessage);
+        msg = Message.obtain();
+        msg.what = 1;
+        resourceContainerActivityInstance.getHandler().sendMessage(msg);
+    }
 
+    // Add Resource Configuration to BMI bundle
+    public void addResourceConfigBMI() {
+
+        if (false == startBundleFlag) {
+            logMessage = "Bundle is not started" + "\n";
+        } else {
             List<RCSBundleInfo> bundleList = containerInstance.listBundles();
             List<String> bundleResources = containerInstance
-                    .listBundleResources("oic.bundle.discomfortIndexSensor");
+                    .listBundleResources("oic.bundle.BMISensor");
 
             if (0 == bundleList.size()) {
-
                 logMessage = "No bundle found" + "\n";
-
             } else if ((0 == bundleList.size())
                     && (0 == bundleResources.size())) {
-
                 logMessage = "No bundle found" + "\n";
             } else {
-
                 Map<String, String> params = new HashMap<String, String>();
                 params.put("resourceType", "oic.softsensor");
                 params.put("address",
                         "http://192.168.0.2/api/newdeveloper/sensor/22");
-                containerInstance.addResourceConfig(
-                        "oic.bundle.discomfortIndexSensor", "", params);
+                containerInstance.addResourceConfig("oic.bundle.BMISensor", "",
+                        params);
                 logMessage = "resource added successfully" + "\n";
             }
         }
@@ -281,8 +323,8 @@ public class ResourceContainer {
         resourceContainerActivityInstance.getHandler().sendMessage(msg);
     }
 
-    // Remove Resource Configuration
-    public void removeResourceConfig() {
+    // Remove Resource Configuration from DI Bundle
+    public void removeResourceConfigDI() {
 
         List<String> bundleResources = containerInstance
                 .listBundleResources("oic.bundle.discomfortIndexSensor");
@@ -304,4 +346,28 @@ public class ResourceContainer {
             resourceContainerActivityInstance.getHandler().sendMessage(msg);
         }
     }
+
+    // Remove Resource Configuration from BMI Bundle
+    public void removeResourceConfigBMI() {
+
+        List<String> bundleResources = containerInstance
+                .listBundleResources("oic.bundle.BMISensor");
+        if (bundleResources.size() >= 1) {
+            String element = bundleResources.get(0);
+            containerInstance.removeResourceConfig("oic.bundle.BMISensor",
+                    element);
+            Message msg;
+            logMessage = "resource removed successfully: \n" + element + "\n";
+            ResourceContainerActivity.setMessageLog(logMessage);
+            msg = Message.obtain();
+            msg.what = 1;
+            resourceContainerActivityInstance.getHandler().sendMessage(msg);
+        } else {
+            logMessage = "No resource to remove" + "\n";
+            ResourceContainerActivity.setMessageLog(logMessage);
+            msg = Message.obtain();
+            msg.what = 1;
+            resourceContainerActivityInstance.getHandler().sendMessage(msg);
+        }
+    }
 }
index df6d809..699f652 100644 (file)
 package com.example.sampleserver;
 
 import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
 
 import com.example.sampleresourceserver.*;
+
 import android.app.Activity;
+import android.content.Context;
+import android.graphics.Typeface;
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.Message;
 import android.util.Log;
+import android.view.LayoutInflater;
 import android.view.View;
+import android.view.ViewGroup;
 import android.view.View.OnClickListener;
-import android.widget.AdapterView;
-import android.widget.AdapterView.OnItemClickListener;
-import android.widget.ArrayAdapter;
+import android.widget.BaseExpandableListAdapter;
 import android.widget.Button;
 import android.widget.EditText;
-import android.widget.ListView;
+import android.widget.ExpandableListAdapter;
+import android.widget.ExpandableListView;
+import android.widget.ExpandableListView.OnChildClickListener;
+import android.widget.TextView;
 import android.widget.Toast;
 
 /**
@@ -51,12 +59,16 @@ public class ResourceContainerActivity extends Activity {
     private ResourceContainer                resourceContainerInstance;
     private static String                    logMessage;
 
-    private ArrayAdapter<String>             containerApis;
-    private ArrayList<String>                containerApiList;
+    public ExpandableListAdapter             listAdapter;
+    public ExpandableListView                expListView;
+    public List<String>                      sensors;
+    public List<String>                      diApiList;
+    public List<String>                      bmiApiList;
+    HashMap<String, List<String>>            listDataChild;
+
     private static Handler                   mHandler;
-    private ListView                         list;
     private Button                           startContainer;
-    private Button                           stopContainer;
+    private Button                           listBundles;
     private static EditText                  logs;
     private static String                    sdCardPath;
 
@@ -65,28 +77,44 @@ public class ResourceContainerActivity extends Activity {
 
         super.onCreate(savedInstanceState);
         setContentView(R.layout.resource_container);
-
         resourceContainerActivityInstance = this;
         resourceContainerInstance = new ResourceContainer();
 
-        containerApiList = new ArrayList<String>();
-
-        list = (ListView) findViewById(R.id.containerApiList);
+        expListView = (ExpandableListView) findViewById(R.id.lvExp);
         startContainer = (Button) findViewById(R.id.startContainer);
-        stopContainer = (Button) findViewById(R.id.stopContainer);
-        stopContainer.setEnabled(false);
+        listBundles = (Button) findViewById(R.id.listBundles);
+        listBundles.setEnabled(false);
         logs = (EditText) findViewById(R.id.log);
 
+        sensors = new ArrayList<String>();
+        diApiList = new ArrayList<String>();
+        bmiApiList = new ArrayList<String>();
+        listDataChild = new HashMap<String, List<String>>();
+
+        // Adding list items (header)
+        sensors.add("Discomfort Index Sensor");
+        sensors.add("BMI Sensor");
+
+        // Adding child data [discomfort Index sensor]
+        diApiList.add("1. List bundle resources");
+        diApiList.add("2. Add Resource");
+        diApiList.add("3. Remove Resource");
+
+        // Adding child data [BMI sensor]
+        bmiApiList.add("1. Add Bundle");
+        bmiApiList.add("2. Start Bundle");
+        bmiApiList.add("3. List bundle resources");
+        bmiApiList.add("4. Add Resource ");
+        bmiApiList.add("5. Remove Resource");
+        bmiApiList.add("6. Stop Bundle");
+        bmiApiList.add("7. Remove Bundle");
+
+        listDataChild.put(sensors.get(0), diApiList); // Header, Child data
+        listDataChild.put(sensors.get(1), bmiApiList);
+        listAdapter = new ExpandableList(this, sensors, listDataChild);
+
+        // getting the sd card path
         sdCardPath = this.getFilesDir().getPath();
-        // adding the item to list that will be displayed on the UI.
-        containerApiList.add("1. List Bundles");
-        containerApiList.add("2. List bundle resources");
-        containerApiList.add("3. Add Resource Config");
-        containerApiList.add("4. Remove Resource Config");
-        containerApiList.add("5. Remove Bundle");
-        containerApiList.add("6. Add Bundle");
-        containerApiList.add("7. Start Bundle");
-        containerApiList.add("8. Stop Bundle");
 
         // handler for updating the UI i.e. MessageLog (TextBox) & ListView
         mHandler = new Handler() {
@@ -94,12 +122,8 @@ public class ResourceContainerActivity extends Activity {
             public void handleMessage(Message msg) {
                 switch (msg.what) {
                     case 0:
-                        containerApis = new ArrayAdapter<String>(
-                                resourceContainerActivityInstance,
-                                android.R.layout.simple_list_item_1,
-                                containerApiList);
-                        list.setAdapter(containerApis);
-                        list.bringToFront();
+                        expListView.setAdapter(listAdapter);
+                        expListView.bringToFront();
                         break;
                     case 1:
                         logs.setText("");
@@ -107,70 +131,190 @@ public class ResourceContainerActivity extends Activity {
                         Log.i(LOG_TAG, logMessage);
                         break;
                     case 2:
-                        list.setAdapter(null);
+                        listAdapter = null;
+                        expListView.setAdapter(listAdapter);
                         break;
                 }
             }
         };
         setHandler(mHandler);
 
-        // StartContainer Button Listener
+        // StartContainer/stopContainer Button Listener
         startContainer.setOnClickListener(new OnClickListener() {
             @Override
             public void onClick(View v) {
 
-                resourceContainerInstance.startContainer(sdCardPath);
-                startContainer.setEnabled(false);
-                stopContainer.setEnabled(true);
-
+                String text = (String) startContainer.getText();
+                if (text.contains("Start")) {
+                    resourceContainerInstance.startContainer(sdCardPath);
+                    listAdapter = new ExpandableList(ResourceContainerActivity
+                            .getResourceContainerActivityObj(), sensors,
+                            listDataChild);
+                    listBundles.setEnabled(true);
+                    startContainer.setText("Stop Container");
+                } else {
+                    resourceContainerInstance.stopContainer();
+                    startContainer.setText("Start Container");
+                    listBundles.setEnabled(false);
+                    Message msg;
+                    msg = Message.obtain();
+                    msg.what = 2;
+                    resourceContainerActivityInstance.getHandler().sendMessage(
+                            msg);
+                }
             }
         });
 
-        // StopContainer Button Listener
-        stopContainer.setOnClickListener(new OnClickListener() {
+        // List Bundles Button Listener
+        listBundles.setOnClickListener(new OnClickListener() {
             @Override
             public void onClick(View v) {
-                resourceContainerInstance.stopContainer();
-                startContainer.setEnabled(true);
-                stopContainer.setEnabled(false);
-                Message msg;
-                msg = Message.obtain();
-                msg.what = 2;
-                resourceContainerActivityInstance.getHandler().sendMessage(msg);
+                resourceContainerInstance.listBundles();
             }
         });
 
-        // Listener for item clicked by the user on the UI
-        list.setOnItemClickListener(new OnItemClickListener() {
+        // Listener for the expandable list
+        expListView.setOnChildClickListener(new OnChildClickListener() {
+
             @Override
-            public void onItemClick(AdapterView<?> parent, View view,
-                    int position, long id) {
-                if (position == 0) {
-                    resourceContainerInstance.listBundles();
-                } else if (position == 1) {
-                    resourceContainerInstance.listBundleResources();
-                } else if (position == 2) {
-                    resourceContainerInstance.addResourceConfig();
-                } else if (position == 3) {
-                    resourceContainerInstance.removeResourceConfig();
-                } else if (position == 4) {
-                    resourceContainerInstance.removeBundle();
-                } else if (position == 5) {
-                    resourceContainerInstance.addBundle();
-                } else if (position == 6) {
-                    resourceContainerInstance.startBundle();
-                } else if (position == 7) {
-                    resourceContainerInstance.stopBundle();
+            public boolean onChildClick(ExpandableListView parent, View v,
+                    int groupPosition, int childPosition, long id) {
+
+                if (0 == groupPosition) {
+                    if (childPosition == 0) {
+                        resourceContainerInstance.listBundleResourcesDI();
+                    } else if (childPosition == 1) {
+                        resourceContainerInstance.addResourceConfigDI();
+                    } else if (childPosition == 2) {
+                        resourceContainerInstance.removeResourceConfigDI();
+                    }
+                } else {
+                    if (childPosition == 0) {
+                        resourceContainerInstance.addBundleBMI();
+                    } else if (childPosition == 1) {
+                        resourceContainerInstance.startBundleBMI();
+                    } else if (childPosition == 2) {
+                        resourceContainerInstance.listBundleResourcesBMI();
+                    } else if (childPosition == 3) {
+                        resourceContainerInstance.addResourceConfigBMI();
+                    } else if (childPosition == 4) {
+                        resourceContainerInstance.removeResourceConfigBMI();
+                    } else if (childPosition == 5) {
+                        resourceContainerInstance.stopBundleBMI();
+                    } else if (childPosition == 6) {
+                        resourceContainerInstance.removeBundleBMI();
+                    }
                 }
+                return false;
             }
         });
     }
 
     @Override
     public void onBackPressed() {
+        listAdapter = null;
+        expListView.setAdapter(listAdapter);
+        resourceContainerInstance.stopContainer();
+        ResourceContainer.startBundleFlag = false;
         super.onBackPressed();
     }
 
+    // class for handling expandable list items
+    public class ExpandableList extends BaseExpandableListAdapter {
+
+        private Context                       _context;
+        private List<String>                  _listDataHeader; // header titles
+        // child data in format of header title, child title
+        private HashMap<String, List<String>> _listDataChild;
+
+        public ExpandableList(Context context, List<String> listDataHeader,
+                HashMap<String, List<String>> listChildData) {
+            this._context = context;
+            this._listDataHeader = listDataHeader;
+            this._listDataChild = listChildData;
+        }
+
+        @Override
+        public Object getChild(int groupPosition, int childPosititon) {
+            return this._listDataChild.get(
+                    this._listDataHeader.get(groupPosition))
+                    .get(childPosititon);
+        }
+
+        @Override
+        public long getChildId(int groupPosition, int childPosition) {
+            return childPosition;
+        }
+
+        @Override
+        public View getChildView(int groupPosition, final int childPosition,
+                boolean isLastChild, View convertView, ViewGroup parent) {
+
+            final String childText = (String) getChild(groupPosition,
+                    childPosition);
+
+            if (convertView == null) {
+                LayoutInflater infalInflater = (LayoutInflater) this._context
+                        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+                convertView = infalInflater.inflate(R.layout.list_item, null);
+            }
+
+            TextView txtListChild = (TextView) convertView
+                    .findViewById(R.id.lblListItem);
+
+            txtListChild.setText(childText);
+            return convertView;
+        }
+
+        @Override
+        public int getChildrenCount(int groupPosition) {
+            return this._listDataChild.get(
+                    this._listDataHeader.get(groupPosition)).size();
+        }
+
+        @Override
+        public Object getGroup(int groupPosition) {
+            return this._listDataHeader.get(groupPosition);
+        }
+
+        @Override
+        public int getGroupCount() {
+            return this._listDataHeader.size();
+        }
+
+        @Override
+        public long getGroupId(int groupPosition) {
+            return groupPosition;
+        }
+
+        @Override
+        public View getGroupView(int groupPosition, boolean isExpanded,
+                View convertView, ViewGroup parent) {
+            String headerTitle = (String) getGroup(groupPosition);
+            if (convertView == null) {
+                LayoutInflater infalInflater = (LayoutInflater) this._context
+                        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+                convertView = infalInflater.inflate(R.layout.list_group, null);
+            }
+
+            TextView lblListHeader = (TextView) convertView
+                    .findViewById(R.id.lblListHeader);
+            lblListHeader.setTypeface(null, Typeface.BOLD);
+            lblListHeader.setText(headerTitle);
+            return convertView;
+        }
+
+        @Override
+        public boolean hasStableIds() {
+            return false;
+        }
+
+        @Override
+        public boolean isChildSelectable(int groupPosition, int childPosition) {
+            return true;
+        }
+    }
+
     // ****Utility Functions*****//
 
     public static void setMessageLog(String message) {
index 144e81b..f12ec69 100644 (file)
@@ -81,7 +81,7 @@ public class ServerBuilder {
 
         rcsResourceObject.setAttribute("Temperature", value);
         logMessage = "Attribute set successfully" + "\n";
-        logMessage = logMessage + "Temperature : " + value;
+        logMessage += "Temperature : " + value;
 
         serverBuilderDevActivityInstance.setMessageLog(logMessage);
         msg = Message.obtain();
@@ -189,8 +189,8 @@ public class ServerBuilder {
         public void onAttributeUpdate(String oldValue, String newValue) {
 
             logMessage = "attributed updated" + "\n";
-            logMessage = logMessage + "oldValue : " + oldValue + "\n";
-            logMessage = logMessage + "newValue : " + newValue + "\n";
+            logMessage += "oldValue : " + oldValue + "\n";
+            logMessage += "newValue : " + newValue + "\n";
             serverBuilderDevActivityInstance.setMessageLog(logMessage);
             msg = Message.obtain();
             msg.what = 0;
index 4cf4105..e95e470 100644 (file)
@@ -154,7 +154,7 @@ public class ServerBuilderAutoActivity extends Activity {
 
         ServerBuilder.rcsResourceObject.setAttribute("Temperature", value);
         logMessage = "Attribute set successfully" + "\n";
-        logMessage = logMessage + "Temperature : " + value;
+        logMessage += "Temperature : " + value;
         Message msg;
         ServerBuilderAutoActivity.setMessageLog(logMessage);
         msg = Message.obtain();