[Resource-Encapsulation] Android Sample Application for Server side
authorJay Sharma <jay.sharma@samsung.com>
Wed, 2 Sep 2015 05:13:38 +0000 (10:43 +0530)
committerMadan Lanka <lanka.madan@samsung.com>
Fri, 4 Sep 2015 05:34:48 +0000 (05:34 +0000)
- For Server Builder APIs
- For Resource Container APIs

Change-Id: Ia15bbfdadddc82ca45ebee8e58e579b5db399e0d
Signed-off-by: Jay Sharma <jay.sharma@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2342
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
30 files changed:
service/resource-encapsulation/examples/android/SampleServer/.classpath [new file with mode: 0644]
service/resource-encapsulation/examples/android/SampleServer/.project [new file with mode: 0644]
service/resource-encapsulation/examples/android/SampleServer/AndroidManifest.xml [new file with mode: 0644]
service/resource-encapsulation/examples/android/SampleServer/assets/lib/ResourceContainerConfig.xml [new file with mode: 0644]
service/resource-encapsulation/examples/android/SampleServer/ic_launcher-web.png [new file with mode: 0644]
service/resource-encapsulation/examples/android/SampleServer/project.properties [new file with mode: 0644]
service/resource-encapsulation/examples/android/SampleServer/res/drawable-hdpi/ic_launcher.png [new file with mode: 0644]
service/resource-encapsulation/examples/android/SampleServer/res/drawable-mdpi/ic_launcher.png [new file with mode: 0644]
service/resource-encapsulation/examples/android/SampleServer/res/drawable-xhdpi/ic_launcher.png [new file with mode: 0644]
service/resource-encapsulation/examples/android/SampleServer/res/drawable-xxhdpi/ic_launcher.png [new file with mode: 0644]
service/resource-encapsulation/examples/android/SampleServer/res/layout/activity_main.xml [new file with mode: 0644]
service/resource-encapsulation/examples/android/SampleServer/res/layout/resource_container.xml [new file with mode: 0644]
service/resource-encapsulation/examples/android/SampleServer/res/layout/server_builder.xml [new file with mode: 0644]
service/resource-encapsulation/examples/android/SampleServer/res/layout/server_builder_auto.xml [new file with mode: 0644]
service/resource-encapsulation/examples/android/SampleServer/res/layout/server_builder_dev.xml [new file with mode: 0644]
service/resource-encapsulation/examples/android/SampleServer/res/layout/userinputfortemperaturevalue.xml [new file with mode: 0644]
service/resource-encapsulation/examples/android/SampleServer/res/menu/main.xml [new file with mode: 0644]
service/resource-encapsulation/examples/android/SampleServer/res/values-v11/styles.xml [new file with mode: 0644]
service/resource-encapsulation/examples/android/SampleServer/res/values-v14/styles.xml [new file with mode: 0644]
service/resource-encapsulation/examples/android/SampleServer/res/values-w820dp/dimens.xml [new file with mode: 0644]
service/resource-encapsulation/examples/android/SampleServer/res/values/dimens.xml [new file with mode: 0644]
service/resource-encapsulation/examples/android/SampleServer/res/values/strings.xml [new file with mode: 0644]
service/resource-encapsulation/examples/android/SampleServer/res/values/styles.xml [new file with mode: 0644]
service/resource-encapsulation/examples/android/SampleServer/src/com/example/sampleserver/MainActivity.java [new file with mode: 0644]
service/resource-encapsulation/examples/android/SampleServer/src/com/example/sampleserver/ResourceContainer.java [new file with mode: 0644]
service/resource-encapsulation/examples/android/SampleServer/src/com/example/sampleserver/ResourceContainerActivity.java [new file with mode: 0644]
service/resource-encapsulation/examples/android/SampleServer/src/com/example/sampleserver/ServerBuilder.java [new file with mode: 0644]
service/resource-encapsulation/examples/android/SampleServer/src/com/example/sampleserver/ServerBuilderActivity.java [new file with mode: 0644]
service/resource-encapsulation/examples/android/SampleServer/src/com/example/sampleserver/ServerBuilderAutoActivity.java [new file with mode: 0644]
service/resource-encapsulation/examples/android/SampleServer/src/com/example/sampleserver/ServerBuilderDevActivity.java [new file with mode: 0644]

diff --git a/service/resource-encapsulation/examples/android/SampleServer/.classpath b/service/resource-encapsulation/examples/android/SampleServer/.classpath
new file mode 100644 (file)
index 0000000..d6e5878
--- /dev/null
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+       <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
+       <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
+       <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
+       <classpathentry exported="true" kind="lib" path="E:/Projects/Mixed_backup/master_22_aug/android/android_api/base/build/intermediates/bundles/release/classes.jar"/>
+       <classpathentry kind="src" path="src"/>
+       <classpathentry kind="src" path="gen"/>
+       <classpathentry kind="output" path="bin/classes"/>
+</classpath>
diff --git a/service/resource-encapsulation/examples/android/SampleServer/.project b/service/resource-encapsulation/examples/android/SampleServer/.project
new file mode 100644 (file)
index 0000000..f5fee67
--- /dev/null
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+       <name>SampleServer</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/service/resource-encapsulation/examples/android/SampleServer/AndroidManifest.xml b/service/resource-encapsulation/examples/android/SampleServer/AndroidManifest.xml
new file mode 100644 (file)
index 0000000..74373bc
--- /dev/null
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="com.example.sampleresourceserver"
+    android:versionCode="1"
+    android:versionName="1.0" >
+
+    <uses-sdk
+        android:minSdkVersion="8"
+        android:targetSdkVersion="21" />
+
+    <uses-permission android:name="android.permission.INTERNET" />
+    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
+
+    <application
+        android:allowBackup="true"
+        android:icon="@drawable/ic_launcher"
+        android:label="@string/app_name"
+        android:theme="@style/AppTheme" >
+        <activity
+            android:name="com.example.sampleserver.MainActivity"
+            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="com.example.sampleserver.ServerBuilderActivity"
+            android:label="@string/app_name" >
+        </activity>
+        <activity
+            android:name="com.example.sampleserver.ResourceContainerActivity"
+            android:label="@string/app_name" >
+        </activity>
+        <activity
+            android:name="com.example.sampleserver.ServerBuilderAutoActivity"
+            android:label="@string/app_name" >
+        </activity>
+        <activity
+            android:name="com.example.sampleserver.ServerBuilderDevActivity"
+            android:label="@string/app_name" >
+        </activity>
+    </application>
+
+</manifest>
\ No newline at end of file
diff --git a/service/resource-encapsulation/examples/android/SampleServer/assets/lib/ResourceContainerConfig.xml b/service/resource-encapsulation/examples/android/SampleServer/assets/lib/ResourceContainerConfig.xml
new file mode 100644 (file)
index 0000000..44b4089
--- /dev/null
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<container>      
+    <bundle>
+        <id>oic.bundle.discomfortIndexSensor</id>
+        <path>data/data/com.example.sampleresourceserver/files/libSoftSensorBundle.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>
+                </outputs>
+                <inputs>
+                  <input>
+                    <name>humidity</name>
+                    <type>double</type>
+                  </input>
+                                 <input>
+                    <name>temperature</name>
+                    <type>double</type>
+                  </input>
+                </inputs>
+            </resourceInfo>       
+        </resources>
+    </bundle>
+</container>
diff --git a/service/resource-encapsulation/examples/android/SampleServer/ic_launcher-web.png b/service/resource-encapsulation/examples/android/SampleServer/ic_launcher-web.png
new file mode 100644 (file)
index 0000000..a18cbb4
Binary files /dev/null and b/service/resource-encapsulation/examples/android/SampleServer/ic_launcher-web.png differ
diff --git a/service/resource-encapsulation/examples/android/SampleServer/project.properties b/service/resource-encapsulation/examples/android/SampleServer/project.properties
new file mode 100644 (file)
index 0000000..6ab28b0
--- /dev/null
@@ -0,0 +1,15 @@
+# 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 edit
+# "ant.properties", and override values to adapt the script to your
+# project structure.
+#
+# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
+#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
+
+# Project target.
+target=android-21
+android.library.reference.1=../../../sdk/java
diff --git a/service/resource-encapsulation/examples/android/SampleServer/res/drawable-hdpi/ic_launcher.png b/service/resource-encapsulation/examples/android/SampleServer/res/drawable-hdpi/ic_launcher.png
new file mode 100644 (file)
index 0000000..288b665
Binary files /dev/null and b/service/resource-encapsulation/examples/android/SampleServer/res/drawable-hdpi/ic_launcher.png differ
diff --git a/service/resource-encapsulation/examples/android/SampleServer/res/drawable-mdpi/ic_launcher.png b/service/resource-encapsulation/examples/android/SampleServer/res/drawable-mdpi/ic_launcher.png
new file mode 100644 (file)
index 0000000..6ae570b
Binary files /dev/null and b/service/resource-encapsulation/examples/android/SampleServer/res/drawable-mdpi/ic_launcher.png differ
diff --git a/service/resource-encapsulation/examples/android/SampleServer/res/drawable-xhdpi/ic_launcher.png b/service/resource-encapsulation/examples/android/SampleServer/res/drawable-xhdpi/ic_launcher.png
new file mode 100644 (file)
index 0000000..d4fb7cd
Binary files /dev/null and b/service/resource-encapsulation/examples/android/SampleServer/res/drawable-xhdpi/ic_launcher.png differ
diff --git a/service/resource-encapsulation/examples/android/SampleServer/res/drawable-xxhdpi/ic_launcher.png b/service/resource-encapsulation/examples/android/SampleServer/res/drawable-xxhdpi/ic_launcher.png
new file mode 100644 (file)
index 0000000..85a6081
Binary files /dev/null and b/service/resource-encapsulation/examples/android/SampleServer/res/drawable-xxhdpi/ic_launcher.png differ
diff --git a/service/resource-encapsulation/examples/android/SampleServer/res/layout/activity_main.xml b/service/resource-encapsulation/examples/android/SampleServer/res/layout/activity_main.xml
new file mode 100644 (file)
index 0000000..901e033
--- /dev/null
@@ -0,0 +1,14 @@
+<?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/list"
+              android:layout_height="wrap_content"
+              android:layout_width="match_parent">
+         </ListView>
+
+</RelativeLayout>
\ No newline at end of file
diff --git a/service/resource-encapsulation/examples/android/SampleServer/res/layout/resource_container.xml b/service/resource-encapsulation/examples/android/SampleServer/res/layout/resource_container.xml
new file mode 100644 (file)
index 0000000..36519bd
--- /dev/null
@@ -0,0 +1,43 @@
+<?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/startContainer"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignParentLeft="true"
+        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>
+         
+         <EditText
+        android:id="@+id/log"
+        android:layout_width="fill_parent"
+        android:layout_height="250dp"
+        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" />
+        
+</RelativeLayout>
diff --git a/service/resource-encapsulation/examples/android/SampleServer/res/layout/server_builder.xml b/service/resource-encapsulation/examples/android/SampleServer/res/layout/server_builder.xml
new file mode 100644 (file)
index 0000000..1f87f2c
--- /dev/null
@@ -0,0 +1,14 @@
+<?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>
+
+</RelativeLayout>
\ No newline at end of file
diff --git a/service/resource-encapsulation/examples/android/SampleServer/res/layout/server_builder_auto.xml b/service/resource-encapsulation/examples/android/SampleServer/res/layout/server_builder_auto.xml
new file mode 100644 (file)
index 0000000..1d38175
--- /dev/null
@@ -0,0 +1,25 @@
+<?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" >
+
+    <ListView
+        android:id="@+id/serverBuilderAutoList"
+        android:layout_width="match_parent"
+        android:layout_height="300dp" >
+    </ListView>
+
+    <EditText
+        android:id="@+id/Autolog"
+        android:layout_width="fill_parent"
+        android:layout_height="250dp"
+        android:layout_alignParentLeft="true"
+        android:layout_below="@+id/serverBuilderAutoList"
+        android:layout_marginTop="15dp"
+        android:editable="false"
+        android:ems="10" >
+
+        <requestFocus />
+    </EditText>
+
+</RelativeLayout>
\ No newline at end of file
diff --git a/service/resource-encapsulation/examples/android/SampleServer/res/layout/server_builder_dev.xml b/service/resource-encapsulation/examples/android/SampleServer/res/layout/server_builder_dev.xml
new file mode 100644 (file)
index 0000000..510c912
--- /dev/null
@@ -0,0 +1,25 @@
+<?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" >
+
+    <ListView
+        android:id="@+id/serverBuilderDevList"
+        android:layout_width="match_parent"
+        android:layout_height="300dp" >
+    </ListView>
+
+    <EditText
+        android:id="@+id/devLog"
+        android:layout_width="fill_parent"
+        android:layout_height="250dp"
+        android:layout_alignParentLeft="true"
+        android:layout_below="@+id/serverBuilderDevList"
+        android:layout_marginTop="15dp"
+        android:editable="false"
+        android:ems="10" >
+
+        <requestFocus />
+    </EditText>
+
+</RelativeLayout>
\ No newline at end of file
diff --git a/service/resource-encapsulation/examples/android/SampleServer/res/layout/userinputfortemperaturevalue.xml b/service/resource-encapsulation/examples/android/SampleServer/res/layout/userinputfortemperaturevalue.xml
new file mode 100644 (file)
index 0000000..50b5f08
--- /dev/null
@@ -0,0 +1,35 @@
+<?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: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" />
+
+      <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" />
+
+</RelativeLayout>
diff --git a/service/resource-encapsulation/examples/android/SampleServer/res/menu/main.xml b/service/resource-encapsulation/examples/android/SampleServer/res/menu/main.xml
new file mode 100644 (file)
index 0000000..d227c49
--- /dev/null
@@ -0,0 +1,9 @@
+<menu xmlns:android="http://schemas.android.com/apk/res/android" >
+
+    <item
+        android:id="@+id/action_settings"
+        android:orderInCategory="100"
+        android:showAsAction="never"
+        android:title="@string/action_settings"/>
+
+</menu>
\ No newline at end of file
diff --git a/service/resource-encapsulation/examples/android/SampleServer/res/values-v11/styles.xml b/service/resource-encapsulation/examples/android/SampleServer/res/values-v11/styles.xml
new file mode 100644 (file)
index 0000000..1074513
--- /dev/null
@@ -0,0 +1,6 @@
+<resources>
+
+    <style name="AppBaseTheme" parent="android:Theme.Holo.Light">
+    </style>
+
+</resources>
diff --git a/service/resource-encapsulation/examples/android/SampleServer/res/values-v14/styles.xml b/service/resource-encapsulation/examples/android/SampleServer/res/values-v14/styles.xml
new file mode 100644 (file)
index 0000000..2d1ebfe
--- /dev/null
@@ -0,0 +1,9 @@
+  <resources>
+
+    <style name="AppBaseTheme" parent="android:Theme.Light">
+    </style>
+
+    <style name="AppTheme" parent="AppBaseTheme">
+    </style>
+
+</resources>
diff --git a/service/resource-encapsulation/examples/android/SampleServer/res/values-w820dp/dimens.xml b/service/resource-encapsulation/examples/android/SampleServer/res/values-w820dp/dimens.xml
new file mode 100644 (file)
index 0000000..f3e7020
--- /dev/null
@@ -0,0 +1,10 @@
+<resources>
+
+    <!--
+         Example customization of dimensions originally defined in res/values/dimens.xml
+         (such as screen margins) for screens with more than 820dp of available width. This
+         would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively).
+    -->
+    <dimen name="activity_horizontal_margin">64dp</dimen>
+
+</resources>
diff --git a/service/resource-encapsulation/examples/android/SampleServer/res/values/dimens.xml b/service/resource-encapsulation/examples/android/SampleServer/res/values/dimens.xml
new file mode 100644 (file)
index 0000000..55c1e59
--- /dev/null
@@ -0,0 +1,7 @@
+<resources>
+
+    <!-- Default screen margins, per the Android Design guidelines. -->
+    <dimen name="activity_horizontal_margin">16dp</dimen>
+    <dimen name="activity_vertical_margin">16dp</dimen>
+
+</resources>
diff --git a/service/resource-encapsulation/examples/android/SampleServer/res/values/strings.xml b/service/resource-encapsulation/examples/android/SampleServer/res/values/strings.xml
new file mode 100644 (file)
index 0000000..7a6b96d
--- /dev/null
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+    <string name="app_name">SampleResourceServer</string>
+    <string name="hello_world">Hello world!</string>
+    <string name="action_settings">Settings</string>
+
+</resources>
diff --git a/service/resource-encapsulation/examples/android/SampleServer/res/values/styles.xml b/service/resource-encapsulation/examples/android/SampleServer/res/values/styles.xml
new file mode 100644 (file)
index 0000000..3ccf2b0
--- /dev/null
@@ -0,0 +1,12 @@
+<resources>
+
+    <style name="AppBaseTheme" parent="android:Theme.Light">
+
+    </style>
+
+    <!-- Application theme. -->
+    <style name="AppTheme" parent="AppBaseTheme">
+
+    </style>
+
+</resources>
diff --git a/service/resource-encapsulation/examples/android/SampleServer/src/com/example/sampleserver/MainActivity.java b/service/resource-encapsulation/examples/android/SampleServer/src/com/example/sampleserver/MainActivity.java
new file mode 100644 (file)
index 0000000..24b760d
--- /dev/null
@@ -0,0 +1,213 @@
+/******************************************************************
+ *
+ * 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.example.sampleserver;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+
+import org.iotivity.base.ModeType;
+import org.iotivity.base.OcPlatform;
+import org.iotivity.base.PlatformConfig;
+import org.iotivity.base.QualityOfService;
+import org.iotivity.base.ServiceType;
+
+import com.example.sampleresourceserver.R;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.DialogInterface.OnClickListener;
+import android.content.res.AssetManager;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.ListView;
+import android.widget.AdapterView.OnItemClickListener;
+
+/**
+ * Starting Activity of the application responsible for configuring the
+ * OcPlatform and redirecting to ServerBuilder or ResourceContainer activity as
+ * per user's selection
+ */
+public class MainActivity extends Activity {
+
+    private static MainActivity  activityObj;
+    private ArrayAdapter<String> apis;
+    private ArrayList<String>    apisList;
+    private ListView             list;
+    private final String         LOG_TAG = "[ReSampleServer]"
+                                                 + this.getClass()
+                                                         .getSimpleName();
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.activity_main);
+        activityObj = this;
+
+        list = (ListView) findViewById(R.id.list);
+        apisList = new ArrayList<String>();
+
+        // adding the item to list that will be displayed on the UI.
+        apisList.add("Server Builder APIs");
+        apisList.add("Resource Container APIs");
+        apis = new ArrayAdapter<String>(activityObj,
+                android.R.layout.simple_list_item_1, apisList);
+        list.setAdapter(apis);
+
+        // handling user's selection on the UI
+        list.setOnItemClickListener(new OnItemClickListener() {
+            @Override
+            public void onItemClick(AdapterView<?> parent, View view,
+                    int position, long id) {
+
+                if (position == 0) {
+
+                    ServerBuilder builderObject = new ServerBuilder();
+                    builderObject.createResource();
+
+                    Intent intent = new Intent(activityObj,
+                            ServerBuilderActivity.class);
+                    startActivity(intent);
+                }
+                if (position == 1) {
+                    Intent intent = new Intent(activityObj,
+                            ResourceContainerActivity.class);
+                    startActivity(intent);
+                }
+            }
+        });
+
+        // calling the method to check the Wi-fi connectivity and configuring
+        // the OcPlatform
+        configurePlatform();
+
+        // copy assets folder file to SDcard
+        copyFiles("lib");
+    }
+
+    private void copyFiles(String path) {
+        AssetManager assetManager = getAssets();
+        String assets[] = null;
+
+        try {
+            assets = assetManager.list(path);
+
+            if (assets.length == 0) {
+                copyFile(path);
+            } else {
+                String fullPath = "/data/data/"
+                        + this.getClass().getPackage().toString() + "/" + path;
+                File dir = new File(fullPath);
+
+                if (!dir.exists())
+                    dir.mkdir();
+                for (int i = 0; i < assets.length; ++i) {
+                    copyFiles(path + "/" + assets[i]);
+                }
+            }
+        } catch (IOException ex) {
+            Log.e("tag", "I/O Exception", ex);
+        }
+    }
+
+    private void copyFile(String filename) {
+        AssetManager assetManager = getAssets();
+        InputStream in = null;
+        OutputStream out = null;
+
+        try {
+            in = assetManager.open(filename);
+            out = openFileOutput(filename.split("/")[1], Context.MODE_PRIVATE);
+
+            byte[] buffer = new byte[1024];
+            int read;
+
+            while ((read = in.read(buffer)) != -1) {
+                out.write(buffer, 0, read);
+            }
+
+            in.close();
+            in = null;
+            out.flush();
+            out.close();
+            out = null;
+        } catch (Exception e) {
+            Log.e("tag", e.getMessage());
+        }
+    }
+
+    @Override
+    public void onBackPressed() {
+        apisList.clear();
+        super.onBackPressed();
+    }
+
+    private void configurePlatform() {
+        // local Variables
+        ConnectivityManager connManager;
+        NetworkInfo wifi;
+        AlertDialog dialog;
+        PlatformConfig platformConfigObj;
+
+        // Check the wifi connectivity
+        connManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
+        wifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
+        if (false == wifi.isConnected()) {
+            // WiFi is not connected close the application
+            AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
+            dialogBuilder.setTitle("Error");
+            dialogBuilder
+                    .setMessage("WiFi is not enabled/connected! Please connect the WiFi and start application again...");
+            dialogBuilder.setCancelable(false);
+            dialogBuilder.setPositiveButton("OK", new OnClickListener() {
+                @Override
+                public void onClick(DialogInterface dialog, int which) {
+                    // Closing the application
+                    activityObj.finish();
+                }
+            });
+
+            dialog = dialogBuilder.create();
+            dialog.show();
+            Log.i(LOG_TAG,
+                    "WiFi is not enabled/connected! Please connect the WiFi and start application again...");
+            return;
+        }
+        // If wifi is connected calling the configure method for configuring the
+        // OcPlatform
+        platformConfigObj = new PlatformConfig(getApplicationContext(),
+                ServiceType.IN_PROC, ModeType.CLIENT_SERVER, "0.0.0.0", 0,
+                QualityOfService.LOW);
+
+        OcPlatform.Configure(platformConfigObj);
+        Log.i(LOG_TAG, "Configuration done Successfully");
+    }
+}
\ No newline at end of file
diff --git a/service/resource-encapsulation/examples/android/SampleServer/src/com/example/sampleserver/ResourceContainer.java b/service/resource-encapsulation/examples/android/SampleServer/src/com/example/sampleserver/ResourceContainer.java
new file mode 100644 (file)
index 0000000..4184178
--- /dev/null
@@ -0,0 +1,307 @@
+/******************************************************************
+ *
+ * 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.example.sampleserver;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.iotivity.ResourceEncapsulation.server.RCSBundleInfo;
+import org.iotivity.ResourceEncapsulation.server.RCSResourceContainer;
+
+import android.os.Message;
+
+/**
+ * For calling the Resource Container APIs as per user selection on UI and for
+ * updating the UI
+ *
+ * It contains all the Resource Container APIs.
+ */
+public class ResourceContainer {
+
+    private RCSResourceContainer             containerInstance;
+    public static String                     logMessage;
+    private static ResourceContainerActivity resourceContainerActivityInstance;
+    private static Message                   msg;
+    private static boolean                   startBundleFlag;
+    private static boolean                   isStarted = false;
+
+    // constructor
+    public ResourceContainer() {
+        resourceContainerActivityInstance = ResourceContainerActivity
+                .getResourceContainerActivityObj();
+        containerInstance = RCSResourceContainer.getInstance();
+    }
+
+    // Start Container
+    public void startContainer() {
+
+        startBundleFlag = true;
+        String configFile = "/data/data/"
+                + resourceContainerActivityInstance.getPackageName()
+                + "/files/ResourceContainerConfig.xml";
+        if (!isStarted) {
+            for (int i = 0; i < 2; i++) {
+                containerInstance.startContainer(configFile);
+                isStarted = true;
+            }
+        } else {
+            containerInstance.startContainer(configFile);
+        }
+        logMessage = "Container Started";
+        ResourceContainerActivity.setMessageLog(logMessage);
+        msg = Message.obtain();
+        msg.what = 1;
+        resourceContainerActivityInstance.getHandler().sendMessage(msg);
+
+        msg = Message.obtain();
+        msg.what = 0;
+        resourceContainerActivityInstance.getHandler().sendMessage(msg);
+    }
+
+    // Stop Container
+    public void stopContainer() {
+
+        containerInstance.stopContainer();
+        logMessage = "Container stopped";
+        ResourceContainerActivity.setMessageLog(logMessage);
+        msg = Message.obtain();
+        msg.what = 1;
+        resourceContainerActivityInstance.getHandler().sendMessage(msg);
+    }
+
+    // List Bundle Resources
+    public void listBundleResources() {
+
+        List<String> bundleResources = containerInstance
+                .listBundleResources("oic.bundle.discomfortIndexSensor");
+        Iterator it = bundleResources.iterator();
+        logMessage = "";
+
+        if (0 == bundleResources.size()) {
+            logMessage = logMessage + "No resource found in the bundle" + "\n";
+        } else {
+            while (it.hasNext()) {
+                String element = (String) it.next();
+                logMessage = logMessage + element + "\n";
+            }
+        }
+        ResourceContainerActivity.setMessageLog(logMessage);
+        msg = Message.obtain();
+        msg.what = 1;
+        resourceContainerActivityInstance.getHandler().sendMessage(msg);
+    }
+
+    // List Bundles
+    public void listBundles() {
+
+        List<RCSBundleInfo> bundleList = containerInstance.listBundles();
+        Iterator it = bundleList.iterator();
+        logMessage = "";
+        logMessage = logMessage + "size of bundleList : " + bundleList.size()
+                + "\n";
+
+        while (it.hasNext()) {
+
+            RCSBundleInfo object = (RCSBundleInfo) it.next();
+            logMessage = logMessage + "ID :" + object.getID() + "\n";
+            logMessage = logMessage + "Path: " + object.getPath() + "\n";
+            logMessage = logMessage + "version : " + object.getVersion() + "\n";
+        }
+        ResourceContainerActivity.setMessageLog(logMessage);
+        msg = Message.obtain();
+        msg.what = 1;
+        resourceContainerActivityInstance.getHandler().sendMessage(msg);
+    }
+
+    // Add Bundles
+    public void addBundle() {
+
+        Map<String, String> bundleParams = null;
+        List<RCSBundleInfo> bundleList = containerInstance.listBundles();
+        if (0 < bundleList.size()) {
+            logMessage = "Bundle already added" + "\n";
+
+        } else {
+            for (int i = 0; i < 2; i++) {
+                containerInstance
+                        .addBundle(
+                                "oic.bundle.discomfortIndexSensor",
+                                "xyz",
+                                "data/data/com.example.sampleresourceserver/files/libSoftSensorBundle.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"
+                    + "\n";
+            logMessage = logMessage + "bundle added successfully" + "\n";
+        }
+
+        ResourceContainerActivity.setMessageLog(logMessage);
+        msg = Message.obtain();
+        msg.what = 1;
+        resourceContainerActivityInstance.getHandler().sendMessage(msg);
+    }
+
+    // Remove Bundle
+    public void removeBundle() {
+
+        List<RCSBundleInfo> bundleList = containerInstance.listBundles();
+        if (0 == bundleList.size()) {
+            logMessage = "No bundle to remove" + "\n";
+
+        } else {
+
+            for (int i = 0; i < 2; i++) {
+                containerInstance
+                        .removeBundle("oic.bundle.discomfortIndexSensor");
+            }
+            startBundleFlag = false;
+            logMessage = "bundle to remove : " + "\n";
+            logMessage = logMessage + "ID :"
+                    + "oic.bundle.discomfortIndexSensor" + "\n";
+            logMessage = logMessage + " bundle removed  successfully" + "\n";
+        }
+        ResourceContainerActivity.setMessageLog(logMessage);
+        msg = Message.obtain();
+        msg.what = 1;
+        resourceContainerActivityInstance.getHandler().sendMessage(msg);
+    }
+
+    // Start Bundle
+    public void startBundle() {
+
+        List<RCSBundleInfo> bundleList = containerInstance.listBundles();
+        if (0 == bundleList.size()) {
+            logMessage = "No bundle to Start" + "\n";
+        } else if (true == startBundleFlag) {
+            logMessage = "Bundle already started" + "\n";
+        } else {
+            startBundleFlag = true;
+            containerInstance.startBundle("oic.bundle.discomfortIndexSensor");
+
+            logMessage = " bundle to start" + "\n";
+            logMessage = logMessage + " ID : oic.bundle.discomfortIndexSensor"
+                    + "\n";
+            logMessage = logMessage + " bundle started successfully" + "\n";
+        }
+        ResourceContainerActivity.setMessageLog(logMessage);
+        msg = Message.obtain();
+        msg.what = 1;
+        resourceContainerActivityInstance.getHandler().sendMessage(msg);
+    }
+
+    // Stop Bundle
+    public void stopBundle() {
+
+        if (false == startBundleFlag) {
+            logMessage = "Bundle already stopped" + "\n";
+        } else {
+
+            List<RCSBundleInfo> bundleList = containerInstance.listBundles();
+            if (0 == bundleList.size()) {
+                logMessage = "No bundle to Stop" + "\n";
+
+            } else {
+                containerInstance
+                        .stopBundle("oic.bundle.discomfortIndexSensor");
+                startBundleFlag = false;
+                logMessage = " bundle to stop" + "\n";
+                logMessage = logMessage
+                        + " ID : oic.bundle.discomfortIndexSensor" + "\n";
+                logMessage = logMessage + " bundle stopped successfully" + "\n";
+            }
+        }
+
+        ResourceContainerActivity.setMessageLog(logMessage);
+        msg = Message.obtain();
+        msg.what = 1;
+        resourceContainerActivityInstance.getHandler().sendMessage(msg);
+    }
+
+    // Add Resource Configuration
+    public void addResourceConfig() {
+
+        if (false == startBundleFlag) {
+            logMessage = "Bundle is not started" + "\n";
+
+        } else {
+
+            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);
+    }
+
+    // Remove Resource Configuration
+    public void removeResourceConfig() {
+
+        List<String> bundleResources = containerInstance
+                .listBundleResources("oic.bundle.discomfortIndexSensor");
+        if (bundleResources.size() >= 1) {
+            String element = bundleResources.get(0);
+            containerInstance.removeResourceConfig(
+                    "oic.bundle.discomfortIndexSensor", 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);
+        }
+    }
+}
diff --git a/service/resource-encapsulation/examples/android/SampleServer/src/com/example/sampleserver/ResourceContainerActivity.java b/service/resource-encapsulation/examples/android/SampleServer/src/com/example/sampleserver/ResourceContainerActivity.java
new file mode 100644 (file)
index 0000000..3deedf3
--- /dev/null
@@ -0,0 +1,195 @@
+/******************************************************************
+ *
+ * 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.example.sampleserver;
+
+import java.util.ArrayList;
+
+import com.example.sampleresourceserver.*;
+import android.app.Activity;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemClickListener;
+import android.widget.ArrayAdapter;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.ListView;
+import android.widget.Toast;
+
+/**
+ * Activity for handling user's selection on UI for Resource container APIs. &
+ * for updating UI.
+ */
+public class ResourceContainerActivity extends Activity {
+
+    private final String                     LOG_TAG = "[ReSample] "
+                                                             + this.getClass()
+                                                                     .getSimpleName();
+    private static ResourceContainerActivity resourceContainerActivityInstance;
+    private ResourceContainer                resourceContainerInstance;
+    private static String                    logMessage;
+
+    private ArrayAdapter<String>             containerApis;
+    private ArrayList<String>                containerApiList;
+    private static Handler                   mHandler;
+    private ListView                         list;
+    private Button                           startContainer;
+    private Button                           stopContainer;
+    private static EditText                  logs;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.resource_container);
+
+        resourceContainerActivityInstance = this;
+        resourceContainerInstance = new ResourceContainer();
+
+        containerApiList = new ArrayList<String>();
+
+        list = (ListView) findViewById(R.id.containerApiList);
+        startContainer = (Button) findViewById(R.id.startContainer);
+        stopContainer = (Button) findViewById(R.id.stopContainer);
+        stopContainer.setEnabled(false);
+        logs = (EditText) findViewById(R.id.log);
+
+        // 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() {
+            @Override
+            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();
+                        break;
+                    case 1:
+                        logs.setText("");
+                        logs.setText(logMessage);
+                        Log.i(LOG_TAG, logMessage);
+                        break;
+                    case 2:
+                        list.setAdapter(null);
+                        break;
+                }
+            }
+        };
+        setHandler(mHandler);
+
+        // StartContainer Button Listener
+        startContainer.setOnClickListener(new OnClickListener() {
+            @Override
+            public void onClick(View v) {
+
+                resourceContainerInstance.startContainer();
+                startContainer.setEnabled(false);
+                stopContainer.setEnabled(true);
+
+            }
+        });
+
+        // StopContainer Button Listener
+        stopContainer.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);
+            }
+        });
+
+        // Listener for item clicked by the user on the UI
+        list.setOnItemClickListener(new OnItemClickListener() {
+            @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();
+                }
+            }
+        });
+    }
+
+    @Override
+    public void onBackPressed() {
+        super.onBackPressed();
+    }
+
+    // ****Utility Functions*****//
+
+    public static void setMessageLog(String message) {
+        logMessage = message;
+    }
+
+    public static ResourceContainerActivity getResourceContainerActivityObj() {
+        return resourceContainerActivityInstance;
+    }
+
+    public Handler getHandler() {
+        return mHandler;
+    }
+
+    public void setHandler(Handler mHandler) {
+        ResourceContainerActivity.mHandler = mHandler;
+    }
+
+    public void displayToastMessage(String message) {
+        Toast toast = Toast.makeText(this, message, Toast.LENGTH_SHORT);
+        toast.show();
+        Log.i(LOG_TAG, message);
+    }
+}
diff --git a/service/resource-encapsulation/examples/android/SampleServer/src/com/example/sampleserver/ServerBuilder.java b/service/resource-encapsulation/examples/android/SampleServer/src/com/example/sampleserver/ServerBuilder.java
new file mode 100644 (file)
index 0000000..94ec164
--- /dev/null
@@ -0,0 +1,198 @@
+/******************************************************************
+ *
+ * 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.example.sampleserver;
+
+import org.iotivity.ResourceEncapsulation.common.RCSException;
+import org.iotivity.ResourceEncapsulation.common.RCSResourceAttributes;
+import org.iotivity.ResourceEncapsulation.server.Builder;
+import org.iotivity.ResourceEncapsulation.server.RCSResourceObject.*;
+import org.iotivity.ResourceEncapsulation.server.RCSGetResponse;
+import org.iotivity.ResourceEncapsulation.server.RCSRequest;
+import org.iotivity.ResourceEncapsulation.server.RCSResourceObject;
+import org.iotivity.ResourceEncapsulation.server.RCSSetResponse;
+
+import android.os.Message;
+
+public class ServerBuilder {
+
+    public static RCSResourceObject           rcsResourceObject;
+    private static ServerBuilderDevActivity   serverBuilderDevActivityInstance;
+    private static String                     logMessage;
+    private static Message                    msg;
+
+    private final GetRequestHandler           getRequestListener;
+    private final SetRequestHandler           setRequestListener;
+    private final AddAttributeUpdatedListener attributeUpdatedListener;
+
+    // constructor
+    public ServerBuilder() {
+        serverBuilderDevActivityInstance = ServerBuilderDevActivity
+                .getServerBuilderDevActivity();
+        getRequestListener = new GetRequestHandler();
+        setRequestListener = new SetRequestHandler();
+        attributeUpdatedListener = new AddAttributeUpdatedListener();
+    }
+
+    // Create Resource
+    public void createResource() {
+
+        Builder builderObject = new Builder("/a/TempSensor",
+                "core.TemperatureSensor", "oic.if.");
+        builderObject.setDiscoverable(true);
+        builderObject.setObservable(true);
+
+        RCSResourceAttributes attr = new RCSResourceAttributes();
+        try {
+            attr.setValueInt("Temperature", 10);
+        } catch (RCSException e) {
+            e.printStackTrace();
+        }
+        builderObject.setAttributes(attr);
+
+        try {
+            rcsResourceObject = builderObject.build();
+        } catch (RCSException e) {
+            e.printStackTrace();
+        }
+    }
+
+    // Set Attribute
+    public void setAttribute(int value) {
+
+        rcsResourceObject.setAttribute("Temperature", value);
+        logMessage = "Attribute set successfully" + "\n";
+        logMessage = logMessage + "Temperature : " + value;
+
+        serverBuilderDevActivityInstance.setMessageLog(logMessage);
+        msg = Message.obtain();
+        msg.what = 0;
+        serverBuilderDevActivityInstance.getHandler().sendMessage(msg);
+    }
+
+    // Set Get Request Listener
+    public void setGetRequestListener() {
+        rcsResourceObject.setGetRequestListener(getRequestListener);
+        rcsResourceObject.setGetRequestHandler();
+        logMessage = "Get Handler set successfully." + "\n";
+
+        serverBuilderDevActivityInstance.setMessageLog(logMessage);
+        msg = Message.obtain();
+        msg.what = 0;
+        serverBuilderDevActivityInstance.getHandler().sendMessage(msg);
+    }
+
+    // Set Set Request Listener
+    public void setSetRequestListener() {
+        rcsResourceObject.setSetRequestListener(setRequestListener);
+        rcsResourceObject.setSetRequestHandler();
+        logMessage = "Set Handler set successfully." + "\n";
+
+        serverBuilderDevActivityInstance.setMessageLog(logMessage);
+        msg = Message.obtain();
+        msg.what = 0;
+        serverBuilderDevActivityInstance.getHandler().sendMessage(msg);
+    }
+
+    // Set Attribute Updated Listener
+    public void setAttributeUpdatedListener() {
+
+        rcsResourceObject.setAttributeUpdatedListener(attributeUpdatedListener);
+        rcsResourceObject.addAttributeUpdatedListener("Temperature");
+        logMessage = "Attribte updated listener set successfully." + "\n";
+
+        serverBuilderDevActivityInstance.setMessageLog(logMessage);
+        msg = Message.obtain();
+        msg.what = 0;
+        serverBuilderDevActivityInstance.getHandler().sendMessage(msg);
+    }
+
+    // Remove Attribute Updated Listener
+    public void removeAttributeUpdatedListener() {
+
+        rcsResourceObject.removeAttributeUpdatedListener("Temperature");
+        logMessage = "Attribte updated listener removed successfully." + "\n";
+
+        serverBuilderDevActivityInstance.setMessageLog(logMessage);
+        msg = Message.obtain();
+        msg.what = 0;
+        serverBuilderDevActivityInstance.getHandler().sendMessage(msg);
+    }
+
+    /**
+     * Listener for receiving Get Request and for Sending Response
+     */
+    private class GetRequestHandler implements IGetRequestHandler {
+
+        @Override
+        public RCSGetResponse onGetRequest(RCSRequest request,
+                RCSResourceAttributes attributes) {
+
+            logMessage = "Got a Get request from client sending dafault response \n"
+                    + "URI : " + request.getResourceUri() + "\n";
+            serverBuilderDevActivityInstance.setMessageLog(logMessage);
+            msg = Message.obtain();
+            msg.what = 0;
+            serverBuilderDevActivityInstance.getHandler().sendMessage(msg);
+
+            RCSGetResponse object = RCSGetResponse.defaultAction();
+
+            return object;
+        }
+    };
+
+    /**
+     * Listener for receiving Set Request and for Sending Response
+     */
+    private class SetRequestHandler implements ISetRequestHandler {
+
+        @Override
+        public RCSSetResponse onSetRequest(RCSRequest request,
+                RCSResourceAttributes attributes) {
+
+            logMessage = "Got a Set request from client sending dafault response"
+                    + "\n" + "URI : " + request.getResourceUri() + "\n";
+            serverBuilderDevActivityInstance.setMessageLog(logMessage);
+            msg = Message.obtain();
+            msg.what = 0;
+            serverBuilderDevActivityInstance.getHandler().sendMessage(msg);
+            RCSSetResponse object = RCSSetResponse.defaultAction();
+            return object;
+        }
+    };
+
+    /**
+     * Listener for receiving Updated Attribute
+     */
+    private class AddAttributeUpdatedListener implements
+            IAttributeUpdatedListener {
+        @Override
+        public void onAttributeUpdate(String oldValue, String newValue) {
+
+            logMessage = "attributed updated" + "\n";
+            logMessage = logMessage + "oldValue : " + oldValue + "\n";
+            logMessage = logMessage + "newValue : " + newValue + "\n";
+            serverBuilderDevActivityInstance.setMessageLog(logMessage);
+            msg = Message.obtain();
+            msg.what = 0;
+            serverBuilderDevActivityInstance.getHandler().sendMessage(msg);
+        }
+    };
+}
diff --git a/service/resource-encapsulation/examples/android/SampleServer/src/com/example/sampleserver/ServerBuilderActivity.java b/service/resource-encapsulation/examples/android/SampleServer/src/com/example/sampleserver/ServerBuilderActivity.java
new file mode 100644 (file)
index 0000000..77d1107
--- /dev/null
@@ -0,0 +1,89 @@
+/******************************************************************
+ *
+ * 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.example.sampleserver;
+
+import java.util.ArrayList;
+
+import com.example.sampleresourceserver.R;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.ListView;
+import android.widget.AdapterView.OnItemClickListener;
+
+/**
+ * Starting Activity for ServerBuilder and redirect to ServerBuilderAutoActivity
+ * or ServerBuilderDevActivity as per user's selection
+ */
+public class ServerBuilderActivity extends Activity {
+
+    private static ServerBuilderActivity activityObj;
+    private ArrayAdapter<String>         apis;
+    private ArrayList<String>            apisList;
+    private ListView                     list;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.server_builder);
+        activityObj = this;
+        list = (ListView) findViewById(R.id.buildeList);
+        apisList = new ArrayList<String>();
+
+        // adding the item to list that will be displayed on the UI.
+        apisList.add("Auto Control for created Resource");
+        apisList.add("Developer Control for created Resource");
+        apis = new ArrayAdapter<String>(activityObj,
+                android.R.layout.simple_list_item_1, apisList);
+        list.setAdapter(apis);
+
+        // handling user's selection on the UI
+        list.setOnItemClickListener(new OnItemClickListener() {
+            @Override
+            public void onItemClick(AdapterView<?> parent, View view,
+                    int position, long id) {
+
+                if (position == 0) {
+
+                    Intent intent = new Intent(activityObj,
+                            ServerBuilderAutoActivity.class);
+                    startActivity(intent);
+                }
+                if (position == 1) {
+
+                    Intent intent = new Intent(activityObj,
+                            ServerBuilderDevActivity.class);
+                    startActivity(intent);
+                }
+            }
+        });
+    }
+
+    @Override
+    public void onBackPressed() {
+        super.onBackPressed();
+    }
+}
diff --git a/service/resource-encapsulation/examples/android/SampleServer/src/com/example/sampleserver/ServerBuilderAutoActivity.java b/service/resource-encapsulation/examples/android/SampleServer/src/com/example/sampleserver/ServerBuilderAutoActivity.java
new file mode 100644 (file)
index 0000000..4cf4105
--- /dev/null
@@ -0,0 +1,193 @@
+/******************************************************************
+ *
+ * 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.example.sampleserver;
+
+import java.util.ArrayList;
+
+import android.app.Activity;
+import android.app.Dialog;
+import android.content.Context;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.ListView;
+import android.widget.Toast;
+import android.widget.AdapterView.OnItemClickListener;
+import com.example.sampleresourceserver.R;
+
+/**
+ * Activity for handling user's selection on UI for changing temperature. & for
+ * updating UI.
+ */
+public class ServerBuilderAutoActivity extends Activity {
+
+    private static ServerBuilderAutoActivity activityObj;
+    private ArrayAdapter<String>             apis;
+    private ArrayList<String>                apisList;
+    private final String                     LOG_TAG = "[ReSample] "
+                                                             + this.getClass()
+                                                                     .getSimpleName();
+    private ListView                         list;
+    private EditText                         logs;
+    private static Handler                   mHandler;
+    public static Context                    mcontext;
+    private static String                    logMessage;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.server_builder_auto);
+
+        logs = (EditText) findViewById(R.id.Autolog);
+        activityObj = this;
+        mcontext = this;
+
+        list = (ListView) findViewById(R.id.serverBuilderAutoList);
+        apisList = new ArrayList<String>();
+
+        // adding the item to list that will be displayed on the UI.
+        apisList.add("Set Temperature");
+
+        apis = new ArrayAdapter<String>(activityObj,
+                android.R.layout.simple_list_item_1, apisList);
+        list.setAdapter(apis);
+
+        // handling user's selection on the UI
+        list.setOnItemClickListener(new OnItemClickListener() {
+            @Override
+            public void onItemClick(AdapterView<?> parent, View view,
+                    int position, long id) {
+
+                if (position == 0) {
+                    userInputDialog();
+                }
+            }
+        });
+
+        // handler for updating the UI i.e. MessageLog (TextBox) & ListView
+        mHandler = new Handler() {
+            @Override
+            public void handleMessage(Message msg) {
+                switch (msg.what) {
+                    case 0:
+                        logs.setText("");
+                        logs.setText(logMessage);
+                        Log.i(LOG_TAG, logMessage);
+                        break;
+                }
+            }
+        };
+        setHandler(mHandler);
+    }
+
+    // Dialog for taking user input for setting the attribute [Temperature]
+    // value
+    private void userInputDialog() {
+
+        if (null == ServerBuilder.rcsResourceObject) {
+            displayToastMessage("Resource Object is NULL");
+        } else {
+            final Dialog dialog = new Dialog(mcontext);
+            dialog.setContentView(R.layout.userinputfortemperaturevalue);
+            dialog.setTitle("Enter the Temperature Value");
+
+            dialog.setCancelable(false);
+            dialog.show();
+            Button ok = (Button) dialog.findViewById(R.id.ok);
+            Button cancel = (Button) dialog.findViewById(R.id.cancel);
+
+            ok.setOnClickListener(new OnClickListener() {
+                @Override
+                public void onClick(View v) {
+
+                    EditText temperatureValue = (EditText) dialog
+                            .findViewById(R.id.attributeValue);
+                    String value = temperatureValue.getText().toString();
+                    if (value.equalsIgnoreCase("")) {
+                        String toastmessage = "Please enter the Temperature Value";
+                        displayToastMessage(toastmessage);
+                    } else {
+                        dialog.dismiss();
+                        int val = Integer.parseInt(value);
+
+                        setAttribute(val);
+                    }
+                }
+            });
+            cancel.setOnClickListener(new OnClickListener() {
+                @Override
+                public void onClick(View v) {
+                    dialog.dismiss();
+                }
+            });
+        }
+    }
+
+    // Set the attribute value as per user's selection on the UI
+    public void setAttribute(int value) {
+
+        ServerBuilder.rcsResourceObject.setAttribute("Temperature", value);
+        logMessage = "Attribute set successfully" + "\n";
+        logMessage = logMessage + "Temperature : " + value;
+        Message msg;
+        ServerBuilderAutoActivity.setMessageLog(logMessage);
+        msg = Message.obtain();
+        msg.what = 0;
+        this.getHandler().sendMessage(msg);
+    }
+
+    @Override
+    public void onBackPressed() {
+        super.onBackPressed();
+    }
+
+    // ****Utility Functions*****//
+
+    public static ServerBuilderAutoActivity getServerBuilderAutoActivity() {
+        return activityObj;
+    }
+
+    public static void setMessageLog(String message) {
+        logMessage = message;
+    }
+
+    public Handler getHandler() {
+        return mHandler;
+    }
+
+    public void setHandler(Handler mHandler) {
+        ServerBuilderAutoActivity.mHandler = mHandler;
+    }
+
+    public void displayToastMessage(String message) {
+        Toast toast = Toast.makeText(this, message, Toast.LENGTH_SHORT);
+        toast.show();
+        Log.i(LOG_TAG, message);
+    }
+}
diff --git a/service/resource-encapsulation/examples/android/SampleServer/src/com/example/sampleserver/ServerBuilderDevActivity.java b/service/resource-encapsulation/examples/android/SampleServer/src/com/example/sampleserver/ServerBuilderDevActivity.java
new file mode 100644 (file)
index 0000000..f552791
--- /dev/null
@@ -0,0 +1,224 @@
+/******************************************************************
+ *
+ * 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.example.sampleserver;
+
+import java.util.ArrayList;
+
+import android.app.Activity;
+import android.app.Dialog;
+import android.content.Context;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.ListView;
+import android.widget.Toast;
+import android.widget.AdapterView.OnItemClickListener;
+
+import com.example.sampleresourceserver.R;
+
+/**
+ * Activity for handling user's selection on UI & for updating UI.
+ */
+public class ServerBuilderDevActivity extends Activity {
+
+    private static ServerBuilderDevActivity activityObj;
+    private ArrayAdapter<String>            apis;
+    private ArrayList<String>               apisList;
+    private final String                    LOG_TAG                         = "[ReSample] "
+                                                                                    + this.getClass()
+                                                                                            .getSimpleName();
+    private ListView                        list;
+    private EditText                        logs;
+    private static Handler                  mHandler;
+    public static Context                   mcontext;
+    private static String                   logMessage;
+    private ServerBuilder                   builderObj;
+
+    public static boolean                   getHandlerFlag                  = false;
+    public static boolean                   setHandlerFlag                  = false;
+    public static boolean                   setAttributeUpdatedListenerFlag = false;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.server_builder_dev);
+
+        logs = (EditText) findViewById(R.id.devLog);
+        logs.setText("Resource Created Successfully");
+
+        activityObj = this;
+        mcontext = this;
+        builderObj = new ServerBuilder();
+
+        list = (ListView) findViewById(R.id.serverBuilderDevList);
+        apisList = new ArrayList<String>();
+
+        // adding the item to list that will be displayed on the UI.
+        apisList.add("Set Temperature");
+        apisList.add("Set Get Request Handler");
+        apisList.add("Set Set Request Handler");
+        apisList.add("Set Attribute Updated Listener");
+        apisList.add("Remove Attribute Updated Listener");
+
+        apis = new ArrayAdapter<String>(activityObj,
+                android.R.layout.simple_list_item_1, apisList);
+        list.setAdapter(apis);
+
+        // handling user's selection on the UI
+        list.setOnItemClickListener(new OnItemClickListener() {
+            @Override
+            public void onItemClick(AdapterView<?> parent, View view,
+                    int position, long id) {
+
+                if (position == 0) {
+                    userInputDialog();
+                }
+                if (position == 1) {
+                    if (getHandlerFlag == true) {
+                        displayToastMessage("GetRequest Handle already set");
+                    } else {
+                        builderObj.setGetRequestListener();
+                        getHandlerFlag = true;
+                    }
+                }
+                if (position == 2) {
+                    if (setHandlerFlag == true) {
+                        displayToastMessage("GetRequest Handle already set");
+                    } else {
+                        builderObj.setSetRequestListener();
+                        setHandlerFlag = true;
+                    }
+                }
+                if (position == 3) {
+                    if (setAttributeUpdatedListenerFlag == true) {
+                        displayToastMessage("Attribute Updated Listener already set");
+                    } else {
+                        builderObj.setAttributeUpdatedListener();
+                        setAttributeUpdatedListenerFlag = true;
+                    }
+                }
+                if (position == 4) {
+                    if (setAttributeUpdatedListenerFlag == false) {
+                        displayToastMessage("Attribute Updated Listener is not set");
+                    } else {
+                        builderObj.removeAttributeUpdatedListener();
+                        setAttributeUpdatedListenerFlag = false;
+                    }
+                }
+            }
+        });
+
+        // handler for updating the UI i.e. MessageLog (TextBox) & ListView
+        mHandler = new Handler() {
+            @Override
+            public void handleMessage(Message msg) {
+                switch (msg.what) {
+                    case 0:
+                        logs.setText("");
+                        logs.setText(logMessage);
+                        Log.i(LOG_TAG, logMessage);
+                        break;
+                }
+            }
+        };
+        setHandler(mHandler);
+    }
+
+    // Dialog for taking user input for setting the attribute [Temperature]
+    // value
+    private void userInputDialog() {
+
+        if (null == builderObj) {
+            displayToastMessage("Resource Object is NULL");
+        } else {
+            final Dialog dialog = new Dialog(mcontext);
+            dialog.setContentView(R.layout.userinputfortemperaturevalue);
+            dialog.setTitle("Enter the Temperature Value");
+
+            dialog.setCancelable(false);
+            dialog.show();
+            Button ok = (Button) dialog.findViewById(R.id.ok);
+            Button cancel = (Button) dialog.findViewById(R.id.cancel);
+
+            ok.setOnClickListener(new OnClickListener() {
+                @Override
+                public void onClick(View v) {
+
+                    EditText temperatureValue = (EditText) dialog
+                            .findViewById(R.id.attributeValue);
+                    String value = temperatureValue.getText().toString();
+                    if (value.equalsIgnoreCase("")) {
+                        String toastmessage = "Please enter the Temperature Value";
+                        displayToastMessage(toastmessage);
+                    } else {
+                        dialog.dismiss();
+                        int val = Integer.parseInt(value);
+
+                        builderObj.setAttribute(val);
+                    }
+                }
+            });
+            cancel.setOnClickListener(new OnClickListener() {
+                @Override
+                public void onClick(View v) {
+                    dialog.dismiss();
+                }
+            });
+        }
+    }
+
+    @Override
+    public void onBackPressed() {
+        super.onBackPressed();
+    }
+
+    // ****Utility Functions*****//
+
+    public void setMessageLog(String message) {
+        logMessage = message;
+    }
+
+    public static ServerBuilderDevActivity getServerBuilderDevActivity() {
+        return activityObj;
+    }
+
+    public Handler getHandler() {
+        return mHandler;
+    }
+
+    public void setHandler(Handler mHandler) {
+        ServerBuilderDevActivity.mHandler = mHandler;
+    }
+
+    public void displayToastMessage(String message) {
+        Toast toast = Toast.makeText(this, message, Toast.LENGTH_SHORT);
+        toast.show();
+        Log.i(LOG_TAG, message);
+    }
+}