Change UI of android server application
authorMinji Park <minjii.park@samsung.com>
Mon, 18 Jan 2016 05:30:54 +0000 (14:30 +0900)
committerUze Choi <uzchoi@samsung.com>
Wed, 20 Jan 2016 04:49:29 +0000 (04:49 +0000)
Change UI of android server application to make android sample bundle possible to be tested seperatly for each api

Change-Id: I3a9a82ce68a305d7cc70c3b51580bb89d27cab35
Signed-off-by: Minji Park <minjii.park@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/4827
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/resource-container/examples/android/RCSampleServerApp/app/src/main/java/org/iotivity/service/sample/container/ResourceContainer.java
service/resource-container/examples/android/RCSampleServerApp/app/src/main/java/org/iotivity/service/sample/container/ResourceContainerActivity.java
service/resource-container/examples/android/RCSampleServerApp/app/src/main/res/layout/resource_container.xml

index 8a3c6e3..55223fb 100755 (executable)
@@ -49,7 +49,6 @@ public class ResourceContainer {
     private static Message                   msg;
     public static boolean                    startBundleFlag;
     private static boolean                   isStarted     = false;
-    public static boolean                    isInitialized = false;
     PowerManager pm = null;
     PowerManager.WakeLock wl = null;
 
@@ -85,6 +84,22 @@ public class ResourceContainer {
             msg = Message.obtain();
             msg.what = 0;
             resourceContainerActivityInstance.getHandler().sendMessage(msg);
+
+            // initialize the information of the bundles
+            // which registered at the starting time of the container
+            List<RcsBundleInfo> bundleList = containerInstance.listBundles();
+            Iterator<RcsBundleInfo> it = bundleList.iterator();
+
+            while (it.hasNext())
+            {
+                String id = ((RcsBundleInfo) it.next()).getID();
+                if (id.equals(ExampleBundleDescription.DIBundle.mBundleId)) {
+                    ExampleBundleDescription.DIBundle.isStarted = true;
+                }
+                else if (id.equals(ExampleBundleDescription.DIAndroidBundle.mBundleId)) {
+                    ExampleBundleDescription.DIAndroidBundle.isStarted = true;
+                }
+            }
         }
     }
 
@@ -169,30 +184,25 @@ public class ResourceContainer {
         return false;
     }
 
-    // Add BMI Bundles
-    public void addBMIBundle() {
-        Map<String, String> bundleParams = new HashMap<String, String>();
-
-        if (bundleExists("oic.bundle.BMISensor"))
-            logMessage = "Bundle already added" + "\n";
+    // add Bundles
+    public void addBundle(BundleInformation bundle) {
+        if (bundleExists(bundle.mBundleId))
+            logMessage = "Bundle \'" + bundle.mBundleId + "\' already added" + "\n";
 
         else {
             containerInstance
-                    .addBundle(
-                            "oic.bundle.BMISensor",
-                            "",
-                            "/data/data/org.iotivity.service.sample.resourcecontainer/files/libBMISensorBundle.so",
-                            "bmisensor", bundleParams);
+                    .addBundle(bundle.mBundleId, bundle.mBundleUri,
+                            bundle.mBundlePath, bundle.mActivator, bundle.mBundleParams);
 
             logMessage = "bundle to add : " + "\n";
-            logMessage = logMessage + "ID :" + "oic.bundle.BMISensor" + "\n";
-            logMessage = logMessage + "Uri: " + "xyz" + "\n";
+            logMessage = logMessage + "ID : " + bundle.mBundleId + "\n";
+            logMessage = logMessage + "Uri: " + bundle.mBundleUri + "\n";
             logMessage = logMessage
                     + "Path : "
-                    + "/data/data/org.iotivity.service.sample.server/files/libBMISensorBundle.so"
+                    + bundle.mBundlePath
                     + "\n\n";
             logMessage = logMessage + "bundle added successfully" + "\n";
-            }
+        }
 
         ResourceContainerActivity.setMessageLog(logMessage);
         msg = Message.obtain();
@@ -200,18 +210,18 @@ public class ResourceContainer {
         resourceContainerActivityInstance.getHandler().sendMessage(msg);
     }
 
-    // Remove Bundle BMI
-    public void removeBMIBundle() {
+    // remove Bundles
+    public void removeBundle(BundleInformation bundle) {
 
-        if (!bundleExists("oic.bundle.BMISensor"))
-            logMessage = "BMI Bundle not added" + "\n";
+        if (!bundleExists(bundle.mBundleId))
+            logMessage = "Bundle \'" + bundle.mBundleId + "\' not added" + "\n";
 
         else {
-            containerInstance.removeBundle("oic.bundle.BMISensor");
+            containerInstance.removeBundle(bundle.mBundleId);
 
-            startBundleFlag = false;
+            bundle.isStarted = false;
             logMessage = "bundle to remove : " + "\n";
-            logMessage = logMessage + "ID :" + "oic.bundle.BMISensor" + "\n\n";
+            logMessage = logMessage + "ID : " + bundle.mBundleId + "\n\n";
             logMessage = logMessage + " bundle removed  successfully" + "\n";
         }
 
@@ -221,19 +231,19 @@ public class ResourceContainer {
         resourceContainerActivityInstance.getHandler().sendMessage(msg);
     }
 
-    // Start Bundle BMI
-    public void startBMIBundle() {
+    // start Bundles
+    public void startBundle(BundleInformation bundle) {
 
-        if (!bundleExists("oic.bundle.BMISensor")) {
-            logMessage = "BMI bundle not added" + "\n";
-        } else if (true == startBundleFlag) {
-            logMessage = "Bundle already started" + "\n";
+        if (!bundleExists(bundle.mBundleId)) {
+            logMessage = "Bundle \'" + bundle.mBundleId + "\' not added" + "\n";
+        } else if (bundle.isStarted) {
+            logMessage = "Bundle \'" + bundle.mBundleId + "\' already started" + "\n";
         } else {
-            startBundleFlag = true;
-            containerInstance.startBundle("oic.bundle.BMISensor");
+            bundle.isStarted = true;
+            containerInstance.startBundle(bundle.mBundleId);
 
             logMessage = " bundle to start" + "\n";
-            logMessage += " ID : oic.bundle.BMISensor" + "\n\n";
+            logMessage += " ID : " + bundle.mBundleId + "\n\n";
             logMessage += " bundle started successfully" + "\n";
         }
 
@@ -243,20 +253,20 @@ public class ResourceContainer {
         resourceContainerActivityInstance.getHandler().sendMessage(msg);
     }
 
-    // Stop Bundle BMI
-    public void stopBMIBundle() {
+    // Stop Bundles
+    public void stopBundle(BundleInformation bundle) {
 
-        if (!bundleExists("oic.bundle.BMISensor")) {
-            logMessage = "BMI Bundle not added" + "\n";
+        if (!bundleExists(bundle.mBundleId)) {
+            logMessage = "Bundle \'" + bundle.mBundleId + "\' not added" + "\n";
         }
-        else if (false == startBundleFlag) {
-            logMessage = "Bundle is not Started" + "\n";
+        else if (!bundle.isStarted) {
+            logMessage = "Bundle \'" + bundle.mBundleId + "\' is not Started" + "\n";
         } else {
-                containerInstance.stopBundle("oic.bundle.BMISensor");
-                startBundleFlag = false;
-                logMessage = " bundle to stop" + "\n";
-                logMessage = logMessage + " ID : oic.bundle.BMISensor" + "\n\n";
-                logMessage = logMessage + " bundle stopped successfully" + "\n";
+            containerInstance.stopBundle(bundle.mBundleId);
+            bundle.isStarted = false;
+            logMessage = " bundle to stop" + "\n";
+            logMessage = logMessage + " ID : " + bundle.mBundleId  + "\n\n";
+            logMessage = logMessage + " bundle stopped successfully" + "\n";
         }
 
         ResourceContainerActivity.setMessageLog(logMessage);
@@ -264,12 +274,46 @@ public class ResourceContainer {
         msg.what = 1;
         resourceContainerActivityInstance.getHandler().sendMessage(msg);
     }
+}
 
-    public void addAndroidResource(){
-        logMessage = "Add android resource " + "\n";
-        ResourceContainerActivity.setMessageLog(logMessage);
-        msg = Message.obtain();
-        msg.what = 1;
-        resourceContainerActivityInstance.getHandler().sendMessage(msg);
-    }
+class ExampleBundleDescription
+{
+    static final BundleInformation BMIBundle =
+            new BundleInformation ("oic.bundle.BMISensor", "",
+                    "/data/data/org.iotivity.service.sample.resourcecontainer/files/" +
+                            "libBMISensorBundle.so",
+                    "bmisensor", new HashMap<String, String>());
+
+    static final BundleInformation DIBundle =
+            new BundleInformation ("oic.bundle.discomfortIndexSensor", "",
+                    "/data/data/org.iotivity.service.sample.resourcecontainer/files/" +
+                            "libDISensorBundle.so",
+                    "disensor", new HashMap<String, String>());
+
+    static final BundleInformation DIAndroidBundle =
+            new BundleInformation ("oic.android.sample", "",
+                    "org.iotivity.service.sample.androidbundle.apk",
+                    "org.iotivity.service.sample.androidbundle.SampleActivator",
+                    new HashMap<String, String>());
 }
+
+class BundleInformation
+{
+    String mBundleId;
+    String mBundleUri;
+    String mBundlePath;
+    String mActivator;
+    Map<String, String> mBundleParams;
+
+    Boolean isStarted;
+
+    public BundleInformation(String id, String uri, String path, String activator, Map<String, String> params)
+    {
+        mBundleId = id;
+        mBundleUri = uri;
+        mBundlePath = path;
+        mActivator = activator;
+        mBundleParams = params;
+        isStarted = false;
+    }
+}
\ No newline at end of file
index 3f688f0..51e78fe 100755 (executable)
@@ -60,8 +60,6 @@ import java.util.List;
  * for updating UI.
  */
 public class ResourceContainerActivity extends Activity {
-    // private static final String LOG_TAG =
-    // ResourceContainerActivity.class.getSimpleName();
 
     private final String                     LOG_TAG = "[RCSampleServerApp] "
             + this.getClass()
@@ -73,6 +71,8 @@ public class ResourceContainerActivity extends Activity {
     private Context                          context;
     public ExpandableListAdapter             listAdapter;
     public ExpandableListView                expListView;
+    private int lastExpandedPosition = -1;
+
     public List<String>                      sensors;
     public List<String>                      diApiList;
     public List<String>                      bmiApiList;
@@ -137,10 +137,18 @@ public class ResourceContainerActivity extends Activity {
         bmiApiList.add("5. Remove BMI sensor bundle");
 
         // Adding child data [discomfort Index sensor]
-        diApiList.add("1. List bundle resources");
+        diApiList.add("1. Add DI sensor bundle");
+        diApiList.add("2. Start DI sensor bundle");
+        diApiList.add("3. List bundle resources");
+        diApiList.add("4. Stop DI sensor bundle");
+        diApiList.add("5. Remove DI sensor bundle");
 
         // Adding child data [discomfort Index sensor - android]
-        diAndroidApiList.add("1. List bundle resources");
+        diAndroidApiList.add("1. Add Android DI sensor bundle");
+        diAndroidApiList.add("2. Start Android DI sensor bundle");
+        diAndroidApiList.add("3. List bundle resources");
+        diAndroidApiList.add("4. Stop Android DI sensor bundle");
+        diAndroidApiList.add("5. Remove Android DI sensor bundle");
 
         listChild.put(sensors.get(0), bmiApiList);
         listChild.put(sensors.get(1), diApiList);
@@ -207,7 +215,18 @@ public class ResourceContainerActivity extends Activity {
             }
         });
 
-        // Listener for the expandable list
+
+        expListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
+            @Override
+            public void onGroupExpand(int groupPosition) {
+                if (lastExpandedPosition != -1
+                        && groupPosition != lastExpandedPosition) {
+                    expListView.collapseGroup(lastExpandedPosition);
+                }
+                lastExpandedPosition = groupPosition;
+            }
+        });
+
         expListView
                 .setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
 
@@ -215,33 +234,51 @@ public class ResourceContainerActivity extends Activity {
                     public boolean onChildClick(ExpandableListView parent,
                                                 View v, int groupPosition, int childPosition,
                                                 long id) {
-                        if (0 == groupPosition) {
-                            if (childPosition == 0) {
-                                resourceContainerInstance.addBMIBundle();
-                            } else if (childPosition == 1) {
-                                resourceContainerInstance.startBMIBundle();
-                            } else if (childPosition == 2) {
-                                resourceContainerInstance
-                                        .listBundleResources("oic.bundle.BMISensor");
-                            } else if (childPosition == 3) {
-                                resourceContainerInstance.stopBMIBundle();
-                            } else if (childPosition == 4) {
-                                resourceContainerInstance.removeBMIBundle();
-                            }
+                        BundleInformation bundleToTest;
+
+                        switch (groupPosition) {
+                            case 0:
+                                bundleToTest = ExampleBundleDescription.BMIBundle;
+                                break;
+
+                            case 1:
+                                bundleToTest = ExampleBundleDescription.DIBundle;
+                                break;
+
+                            case 2:
+                                bundleToTest = ExampleBundleDescription.DIAndroidBundle;
+                                break;
+
+                            default:
+                                return false;
                         }
-                        else if (1 == groupPosition) {
-                            if (childPosition == 0) {
-                                resourceContainerInstance
-                                        .listBundleResources("oic.bundle.discomfortIndexSensor");
 
-                            }
-                        } else if (2 == groupPosition) {
-                            if (childPosition == 0) {
+                        switch (childPosition) {
+                            case 0:
+                                resourceContainerInstance.addBundle(bundleToTest);
+                                break;
+
+                            case 1:
+                                resourceContainerInstance.startBundle(bundleToTest);
+                                break;
+
+                            case 2:
                                 resourceContainerInstance
-                                        .listBundleResources("oic.android.sample");
-                            }
+                                        .listBundleResources(bundleToTest.mBundleId);
+                                break;
+
+                            case 3:
+                                resourceContainerInstance.stopBundle(bundleToTest);
+                                break;
+
+                            case 4:
+                                resourceContainerInstance.removeBundle(bundleToTest);
+                                break;
+
+                            default:
+                                return false;
                         }
-                        return false;
+                        return true;
                     }
                 });
     }
index 50456c4..423709a 100755 (executable)
@@ -1,7 +1,8 @@
 <?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
-    android:layout_height="match_parent" >
+    android:layout_height="match_parent"
+    android:padding="5dp">
 
     <Button
         android:id="@+id/startContainer"
@@ -33,6 +34,8 @@
         android:layout_alignParentLeft="true"
         android:layout_below="@id/lvExp"
         android:editable="false"
-        android:ems="10" />
+        android:ems="10"
+        android:background="#32437200"
+        android:padding="10dp" />
 
 </RelativeLayout>