[Resource-Encapsulation] Updated Android SampleResorceClient App 71/2371/2
authorJay Sharma <jay.sharma@samsung.com>
Fri, 4 Sep 2015 04:45:06 +0000 (10:15 +0530)
committerMadan Lanka <lanka.madan@samsung.com>
Fri, 4 Sep 2015 05:37:07 +0000 (05:37 +0000)
- Added Resource Container part.
- updated comments

Change-Id: If6821f26cd9d39dd13f0ff8e13e1ab050b7e993b
Signed-off-by: Jay Sharma <jay.sharma@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2371
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Rami Jung <rami.jung@samsung.com>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
service/resource-encapsulation/examples/android/SampleResourceClientApp/AndroidManifest.xml
service/resource-encapsulation/examples/android/SampleResourceClientApp/res/layout/resource_container.xml [new file with mode: 0644]
service/resource-encapsulation/examples/android/SampleResourceClientApp/src/com/re/sampleclient/ContainerClientActivity.java [new file with mode: 0644]
service/resource-encapsulation/examples/android/SampleResourceClientApp/src/com/re/sampleclient/MainActivity.java
service/resource-encapsulation/examples/android/SampleResourceClientApp/src/com/re/sampleclient/ResourceClient.java
service/resource-encapsulation/examples/android/SampleResourceClientApp/src/com/re/sampleclient/ResourceClientActivity.java

index 63c3ff9..5b7914d 100644 (file)
@@ -30,8 +30,8 @@
             android:label="@string/app_name" >
         </activity>
         <activity
-            android:name="com.re.sampleclient.ConfigurationApiActivity"
-            android:label="@string/app_name" >  
+            android:name="com.re.sampleclient.ContainerClientActivity"
+            android:label="@string/app_name" >
         </activity>
     </application>
 
diff --git a/service/resource-encapsulation/examples/android/SampleResourceClientApp/res/layout/resource_container.xml b/service/resource-encapsulation/examples/android/SampleResourceClientApp/res/layout/resource_container.xml
new file mode 100644 (file)
index 0000000..0ffb052
--- /dev/null
@@ -0,0 +1,24 @@
+<?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" >
+
+       <Button
+           android:id="@+id/discoverResource"
+           android:layout_width="wrap_content"
+           android:layout_height="wrap_content"
+           android:layout_alignParentLeft="true"
+           android:layout_alignParentRight="true"
+           android:layout_alignParentTop="true"
+           android:text="Discover Resource" />
+
+         <EditText
+             android:id="@+id/log"
+             android:layout_width="fill_parent"
+             android:layout_height="250dp"
+             android:layout_alignParentLeft="true"
+             android:layout_below="@+id/discoverResource"
+             android:editable="false"
+             android:ems="10" />
+
+</RelativeLayout>
diff --git a/service/resource-encapsulation/examples/android/SampleResourceClientApp/src/com/re/sampleclient/ContainerClientActivity.java b/service/resource-encapsulation/examples/android/SampleResourceClientApp/src/com/re/sampleclient/ContainerClientActivity.java
new file mode 100644 (file)
index 0000000..fa55d36
--- /dev/null
@@ -0,0 +1,121 @@
+/******************************************************************
+ *
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************/
+
+package com.re.sampleclient;
+
+import java.util.Vector;
+
+import org.iotivity.ResourceEncapsulation.client.RCSAddress;
+import org.iotivity.ResourceEncapsulation.client.RCSDiscoveryManager;
+import org.iotivity.ResourceEncapsulation.client.RCSDiscoveryManager.IDiscoverResourceListener;
+import org.iotivity.ResourceEncapsulation.client.RCSRemoteResourceObject;
+import org.iotivity.ResourceEncapsulation.common.RCSException;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.widget.EditText;
+
+/**
+ * It contains the discover resource API for Discovering Container Resource
+ */
+public class ContainerClientActivity extends Activity {
+
+    private final RCSDiscoveryManager     discoveyManagerObj = RCSDiscoveryManager
+                                                                     .getInstance();
+    private final String                  LOG_TAG            = "[ReSample] "
+                                                                     + this.getClass()
+                                                                             .getSimpleName();
+    private Button                        discoverResourceButton;
+    private EditText                      logs;
+    public static String                  logMessage;
+    private DiscoverResourceListener      discoverResourceListener;
+    public static ContainerClientActivity containerClientActivityObj;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.resource_container);
+
+        containerClientActivityObj = this;
+        discoverResourceButton = (Button) findViewById(R.id.discoverResource);
+        logs = (EditText) findViewById(R.id.log);
+
+        discoverResourceListener = new DiscoverResourceListener();
+        discoveyManagerObj
+                .setDiscoverResourceListener(discoverResourceListener);
+
+        discoverResourceButton.setOnClickListener(new OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                RCSAddress address = RCSAddress.multicast();
+                try {
+                    discoveyManagerObj.discoverResourceByType(address,
+                            "oic.softsensor");
+                    logMessage = "";
+                    logs.setText(logMessage);
+                } catch (RCSException e) {
+                    e.printStackTrace();
+                }
+            }
+        });
+    }
+
+    /**
+     * Listener for receiving Resource discovered in the network.
+     */
+    private class DiscoverResourceListener implements IDiscoverResourceListener {
+
+        @Override
+        public void onResourceDiscovered(RCSRemoteResourceObject foundResource) {
+            Log.i(LOG_TAG, "onResourceDiscovered invoked");
+
+            String resourceURI = foundResource.getUri();
+            String hostAddress = foundResource.getAddress();
+            boolean isObservableflag = foundResource.isObservable();
+
+            Vector<String> resourceTypes = foundResource.getTypes();
+            Vector<String> resourceInterfaces = foundResource.getInterFaces();
+
+            logMessage = "URI : " + resourceURI + "\n";
+            logMessage = logMessage + "Host : " + hostAddress + "\n";
+            for (int i = 0; i < resourceTypes.size(); i++) {
+                logMessage = logMessage + "resourceType : "
+                        + resourceTypes.get(i) + "\n";
+            }
+
+            for (int i = 0; i < resourceInterfaces.size(); i++) {
+                logMessage = logMessage + "resourceInterfaces : "
+                        + resourceInterfaces.get(i) + "\n";
+            }
+            logMessage = logMessage + "isObservable : " + isObservableflag
+                    + "\n";
+
+            ContainerClientActivity.this.runOnUiThread(new Runnable() {
+                public void run() {
+                    logs.setText(logMessage);
+                }
+            });
+        }
+    };
+}
index 36fde7c..8bd6726 100644 (file)
@@ -44,7 +44,8 @@ import android.widget.ListView;
 
 /**
  * Starting Activity of the application responsible for configuring the
- * OcPlatform and redirecting to ResourceClient activity
+ * OcPlatform and redirecting to ResourceClient activity or Container Activity
+ * as per user's selection.
  */
 public class MainActivity extends Activity {
 
@@ -67,6 +68,7 @@ public class MainActivity extends Activity {
 
         // adding the item to list that will be displayed on the UI.
         apisList.add("Resource Client API's");
+        apisList.add("Discover Container Resource");
         apis = new ArrayAdapter<String>(activityObj,
                 android.R.layout.simple_list_item_1, apisList);
         list.setAdapter(apis);
@@ -82,6 +84,12 @@ public class MainActivity extends Activity {
                             ResourceClientActivity.class);
                     startActivity(intent);
                 }
+                if (position == 1) {
+
+                    Intent intent = new Intent(activityObj,
+                            ContainerClientActivity.class);
+                    startActivity(intent);
+                }
             }
         });
 
index 0e018a7..e82eb7c 100644 (file)
@@ -23,9 +23,13 @@ import java.util.Vector;
 
 import org.iotivity.ResourceEncapsulation.client.RCSAddress;
 import org.iotivity.ResourceEncapsulation.client.RCSDiscoveryManager;
-import org.iotivity.ResourceEncapsulation.client.RCSDiscoveryManager.*;
+import org.iotivity.ResourceEncapsulation.client.RCSDiscoveryManager.IDiscoverResourceListener;
+import org.iotivity.ResourceEncapsulation.client.RCSRemoteResourceObject.IStateChangedCallbackListener;
+import org.iotivity.ResourceEncapsulation.client.RCSRemoteResourceObject.ICacheUpdateListener;
+import org.iotivity.ResourceEncapsulation.client.RCSRemoteResourceObject.IRemoteAttributeListener;
+import org.iotivity.ResourceEncapsulation.client.RCSRemoteResourceObject.CacheState;
+import org.iotivity.ResourceEncapsulation.client.RCSRemoteResourceObject.ResourceState;
 import org.iotivity.ResourceEncapsulation.client.RCSRemoteResourceObject;
-import org.iotivity.ResourceEncapsulation.client.RCSRemoteResourceObject.*;
 import org.iotivity.ResourceEncapsulation.common.RCSException;
 import org.iotivity.ResourceEncapsulation.common.RCSResourceAttributes;
 
@@ -73,7 +77,7 @@ public class ResourceClient {
     /**
      * Listener for receiving Resource discovered in network.
      */
-    private class DiscoverResourceListener implements IDiscoverResourceListener{
+    private class DiscoverResourceListener implements IDiscoverResourceListener {
 
         @Override
         public void onResourceDiscovered(RCSRemoteResourceObject foundResource) {
@@ -105,7 +109,7 @@ public class ResourceClient {
             logMessage = logMessage + "isObservable : " + isObservableflag
                     + "\n";
 
-            resourcClientActivityObj.setMessageLog(logMessage);
+            ResourceClientActivity.setMessageLog(logMessage);
             msg = Message.obtain();
             msg.what = 1;
             resourcClientActivityObj.getHandler().sendMessage(msg);
@@ -187,18 +191,19 @@ public class ResourceClient {
         }
     };
 
+    // Discover Resource
     public void disocverResources() {
         Log.d(LOG_TAG, "discover resources entry");
         RCSAddress address = RCSAddress.multicast();
         try {
             discoveyManagerObj.discoverResource(address);
-        } catch (Exception e) {
-            // TODO Auto-generated catch block
+        } catch (RCSException e) {
             e.printStackTrace();
         }
         Log.d(LOG_TAG, "discover resources exit");
     }
 
+    // Start Monitoring
     public void startMonitoring() {
         Log.d(LOG_TAG, "startMonitoring entry");
 
@@ -231,6 +236,7 @@ public class ResourceClient {
         Log.d(LOG_TAG, "startMonitoring exit");
     }
 
+    // Stop Monitoring
     public void stopMonitoring() {
         Log.d(LOG_TAG, "stopMonitoring entry");
 
@@ -256,6 +262,7 @@ public class ResourceClient {
         resourcClientActivityObj.getHandler().sendMessage(msg);
     }
 
+    // Get Attributes
     public void getRemoteAttributes() {
         Log.d(LOG_TAG, "getRemoteAttributes entry");
 
@@ -279,6 +286,7 @@ public class ResourceClient {
         Log.d(LOG_TAG, "getRemoteAttributes exit");
     }
 
+    // Set Attributes
     public void setRemoteAttributes(int value) {
         Log.d(LOG_TAG, "setRemoteAttributes entry");
 
@@ -304,6 +312,7 @@ public class ResourceClient {
         Log.d(LOG_TAG, "setRemoteAttributes exit");
     }
 
+    // Start Caching
     public void startCaching(int cachingType) {
         Log.d(LOG_TAG, "startCaching entry");
 
@@ -351,6 +360,7 @@ public class ResourceClient {
         Log.d(LOG_TAG, "startCaching exit");
     }
 
+    // Get Cache State
     public void getCacheState() {
         Log.d(LOG_TAG, "getCacheState entry");
 
@@ -371,6 +381,7 @@ public class ResourceClient {
         Log.d(LOG_TAG, "getCacheState exit");
     }
 
+    // Get Cached Attributes
     public void getCachedAttributes() {
         Log.d(LOG_TAG, "getCachedAttributes entry");
 
@@ -397,6 +408,7 @@ public class ResourceClient {
         Log.d(LOG_TAG, "getCachedAttributes exit");
     }
 
+    // Get Cached Attribute
     public void getCachedAttribute() {
         Log.d(LOG_TAG, "getCachedAttribute entry");
 
@@ -430,6 +442,7 @@ public class ResourceClient {
         Log.d(LOG_TAG, "getCachedAttribute exit");
     }
 
+    // Stop Caching
     public void stopCaching() {
         Log.d(LOG_TAG, "stopCaching entry");
 
@@ -454,6 +467,7 @@ public class ResourceClient {
         Log.d(LOG_TAG, "stopCaching exit");
     }
 
+    // For Printing the Attributes on the UI
     private void printAttributes(RCSResourceAttributes attributes) {
         Log.d(LOG_TAG, "Printing Attributes");
 
@@ -467,7 +481,6 @@ public class ResourceClient {
             e.printStackTrace();
             return;
         }
-
         ResourceClientActivity.setMessageLog(logMessage);
         msg = Message.obtain();
         msg.what = 1;
index 6107664..53a1d7c 100644 (file)
@@ -20,7 +20,6 @@
 package com.re.sampleclient;
 
 import java.util.ArrayList;
-import java.util.Calendar;
 
 import android.app.Activity;
 import android.app.Dialog;
@@ -50,18 +49,16 @@ public class ResourceClientActivity extends Activity {
     private ArrayAdapter<String>          groupApis;
     private ArrayList<String>             clientApisList;
     private static ResourceClientActivity clientApiActivityObj;
-    private ResourceClient                resourceClientObj;
     private static Handler                mHandler;
+    private ResourceClient                resourceClientObj;
+    public static Context                 mcontext;
 
     private static EditText               logs;
     private static String                 logMessage;
 
-    public static Context                 mcontext;
-    public static Calendar                scheduleTime;
-
     private final String                  LOG_TAG = "[ReSample] "
                                                           + this.getClass()
-                                                                  .getSimpleName(); ;
+                                                                  .getSimpleName();
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -78,20 +75,20 @@ public class ResourceClientActivity extends Activity {
         logs = (EditText) findViewById(R.id.EditText);
 
         // adding the item to list that will be displayed on the UI.
-        clientApisList.add("1. Start Monitoring"); // 0
-        clientApisList.add("2. Stop Monitoring"); // 1
+        clientApisList.add("1. Start Monitoring");
+        clientApisList.add("2. Stop Monitoring");
 
-        clientApisList.add("3. Get Remote Attributes"); // 2
-        clientApisList.add("4. Set Remote Attributes"); // 3
+        clientApisList.add("3. Get Remote Attributes");
+        clientApisList.add("4. Set Remote Attributes");
 
-        clientApisList.add("5. Start Caching without callback"); // 4
-        clientApisList.add("6. Start Caching with callback"); // 5
+        clientApisList.add("5. Start Caching without callback");
+        clientApisList.add("6. Start Caching with callback");
 
-        clientApisList.add("7. Get Cache State"); // 6
-        clientApisList.add("8. Get All Cached Attributes"); // 7
-        clientApisList.add("9. Get Cached Attribute"); // 8
+        clientApisList.add("7. Get Cache State");
+        clientApisList.add("8. Get All Cached Attributes");
+        clientApisList.add("9. Get Cached Attribute");
 
-        clientApisList.add("10. Stop Caching"); // 9
+        clientApisList.add("10. Stop Caching");
 
         // handler for updating the UI i.e. MessageLog (TextBox) & ListView
         mHandler = new Handler() {
@@ -173,9 +170,9 @@ public class ResourceClientActivity extends Activity {
                 @Override
                 public void onClick(View v) {
 
-                    EditText regionValue = (EditText) dialog
+                    EditText temperatureValue = (EditText) dialog
                             .findViewById(R.id.attributeValue);
-                    String value = regionValue.getText().toString();
+                    String value = temperatureValue.getText().toString();
                     if (value.equalsIgnoreCase("")) {
                         String toastmessage = "Please enter the Temperature Value";
                         displayToastMessage(toastmessage);