Android: Adding GroupServer/Client examples
authorTim Kourt <tim.a.kourt@intel.com>
Thu, 24 Sep 2015 19:24:02 +0000 (12:24 -0700)
committerPatrick Lankswert <patrick.lankswert@intel.com>
Fri, 25 Sep 2015 18:12:23 +0000 (18:12 +0000)
Change-Id: I2604a8dfccf6f55b37949e8ff0eda6b1b49d7713
Signed-off-by: Tim Kourt <tim.a.kourt@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/3053
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Patrick Lankswert <patrick.lankswert@intel.com>
(cherry picked from commit e685fddfe38624da5495400df2a1b76f95db6886)
Reviewed-on: https://gerrit.iotivity.org/gerrit/3121

36 files changed:
android/examples/groupclient/.gitignore [new file with mode: 0644]
android/examples/groupclient/build.gradle [new file with mode: 0644]
android/examples/groupclient/groupclient.iml [new file with mode: 0644]
android/examples/groupclient/proguard-rules.pro [new file with mode: 0644]
android/examples/groupclient/src/main/AndroidManifest.xml [new file with mode: 0644]
android/examples/groupclient/src/main/java/org/iotivity/base/examples/GroupClient.java [new file with mode: 0644]
android/examples/groupclient/src/main/res/drawable/iotivityicon.png [new file with mode: 0644]
android/examples/groupclient/src/main/res/drawable/iotivitylogo.png [new file with mode: 0644]
android/examples/groupclient/src/main/res/layout/activity_group_client.xml [new file with mode: 0644]
android/examples/groupclient/src/main/res/mipmap-hdpi/iotivityicon.png [new file with mode: 0644]
android/examples/groupclient/src/main/res/mipmap-mdpi/iotivityicon.png [new file with mode: 0644]
android/examples/groupclient/src/main/res/mipmap-xhdpi/iotivityicon.png [new file with mode: 0644]
android/examples/groupclient/src/main/res/mipmap-xxhdpi/iotivityicon.png [new file with mode: 0644]
android/examples/groupclient/src/main/res/values-v21/styles.xml [new file with mode: 0644]
android/examples/groupclient/src/main/res/values-w820dp/dimens.xml [new file with mode: 0644]
android/examples/groupclient/src/main/res/values/dimens.xml [new file with mode: 0644]
android/examples/groupclient/src/main/res/values/strings.xml [new file with mode: 0644]
android/examples/groupclient/src/main/res/values/styles.xml [new file with mode: 0644]
android/examples/groupserver/.gitignore [new file with mode: 0644]
android/examples/groupserver/build.gradle [new file with mode: 0644]
android/examples/groupserver/groupserver.iml [new file with mode: 0644]
android/examples/groupserver/proguard-rules.pro [new file with mode: 0644]
android/examples/groupserver/src/main/AndroidManifest.xml [new file with mode: 0644]
android/examples/groupserver/src/main/java/org/iotivity/base/examples/GroupServer.java [new file with mode: 0644]
android/examples/groupserver/src/main/res/drawable/iotivityicon.png [new file with mode: 0644]
android/examples/groupserver/src/main/res/drawable/iotivitylogo.png [new file with mode: 0644]
android/examples/groupserver/src/main/res/layout/activity_group_server.xml [new file with mode: 0644]
android/examples/groupserver/src/main/res/mipmap-hdpi/iotivityicon.png [new file with mode: 0644]
android/examples/groupserver/src/main/res/mipmap-mdpi/iotivityicon.png [new file with mode: 0644]
android/examples/groupserver/src/main/res/mipmap-xhdpi/iotivityicon.png [new file with mode: 0644]
android/examples/groupserver/src/main/res/mipmap-xxhdpi/iotivityicon.png [new file with mode: 0644]
android/examples/groupserver/src/main/res/values-v21/styles.xml [new file with mode: 0644]
android/examples/groupserver/src/main/res/values-w820dp/dimens.xml [new file with mode: 0644]
android/examples/groupserver/src/main/res/values/dimens.xml [new file with mode: 0644]
android/examples/groupserver/src/main/res/values/strings.xml [new file with mode: 0644]
android/examples/groupserver/src/main/res/values/styles.xml [new file with mode: 0644]

diff --git a/android/examples/groupclient/.gitignore b/android/examples/groupclient/.gitignore
new file mode 100644 (file)
index 0000000..796b96d
--- /dev/null
@@ -0,0 +1 @@
+/build
diff --git a/android/examples/groupclient/build.gradle b/android/examples/groupclient/build.gradle
new file mode 100644 (file)
index 0000000..b1653de
--- /dev/null
@@ -0,0 +1,24 @@
+apply plugin: 'com.android.application'
+
+android {
+    compileSdkVersion 22
+    buildToolsVersion "22.0.1"
+
+    defaultConfig {
+        applicationId "org.iotivity.base.examples.groupclient"
+        minSdkVersion 21
+        targetSdkVersion 22
+        versionCode 1
+        versionName "1.0"
+    }
+    buildTypes {
+        release {
+            minifyEnabled false
+            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
+        }
+    }
+}
+
+dependencies {
+    compile fileTree(dir: 'libs', include: ['*.jar'])
+}
diff --git a/android/examples/groupclient/groupclient.iml b/android/examples/groupclient/groupclient.iml
new file mode 100644 (file)
index 0000000..440b831
--- /dev/null
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module external.linked.project.id=":groupclient" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="examples" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
+  <component name="FacetManager">
+    <facet type="android-gradle" name="Android-Gradle">
+      <configuration>
+        <option name="GRADLE_PROJECT_PATH" value=":groupclient" />
+      </configuration>
+    </facet>
+    <facet type="android" name="Android">
+      <configuration>
+        <option name="SELECTED_BUILD_VARIANT" value="debug" />
+        <option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
+        <option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
+        <option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
+        <option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
+        <option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugTest" />
+        <option name="COMPILE_JAVA_TEST_TASK_NAME" value="compileDebugTestSources" />
+        <option name="TEST_SOURCE_GEN_TASK_NAME" value="generateDebugTestSources" />
+        <option name="ALLOW_USER_CONFIGURATION" value="false" />
+        <option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
+        <option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
+        <option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
+        <option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
+      </configuration>
+    </facet>
+  </component>
+  <component name="NewModuleRootManager" inherit-compiler-output="false">
+    <output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
+    <output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
+    <exclude-output />
+    <content url="file://$MODULE_DIR$">
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/debug" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/test/debug" isTestSource="true" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/test/debug" isTestSource="true" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/test/debug" isTestSource="true" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/test/debug" isTestSource="true" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/test/debug" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/test/debug" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
+      <excludeFolder url="file://$MODULE_DIR$/build/outputs" />
+      <excludeFolder url="file://$MODULE_DIR$/build/tmp" />
+    </content>
+    <orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
+    <orderEntry type="sourceFolder" forTests="false" />
+    <orderEntry type="library" exported="" name="iotivity-armeabi-base-debug-unspecified" level="project" />
+  </component>
+</module>
\ No newline at end of file
diff --git a/android/examples/groupclient/proguard-rules.pro b/android/examples/groupclient/proguard-rules.pro
new file mode 100644 (file)
index 0000000..d26150c
--- /dev/null
@@ -0,0 +1,17 @@
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in /home/rahul/sdk/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the proguardFiles
+# directive in build.gradle.
+#
+# For more details, see
+#   http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+#   public *;
+#}
diff --git a/android/examples/groupclient/src/main/AndroidManifest.xml b/android/examples/groupclient/src/main/AndroidManifest.xml
new file mode 100644 (file)
index 0000000..863e2ee
--- /dev/null
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="org.iotivity.base.examples" >
+
+    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
+    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+    <uses-permission android:name="android.permission.BLUETOOTH"/>
+    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
+    <uses-permission android:name="android.permission.INTERNET"/>
+    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
+    <uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/>
+    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
+    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
+    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
+
+    <application
+        android:allowBackup="true"
+        android:icon="@mipmap/iotivityicon"
+        android:label="@string/app_name"
+        android:theme="@style/AppTheme" >
+        <activity
+            android:name=".GroupClient"
+            android:label="@string/app_name" >
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+    </application>
+
+</manifest>
diff --git a/android/examples/groupclient/src/main/java/org/iotivity/base/examples/GroupClient.java b/android/examples/groupclient/src/main/java/org/iotivity/base/examples/GroupClient.java
new file mode 100644 (file)
index 0000000..4bfa9ee
--- /dev/null
@@ -0,0 +1,295 @@
+/*
+ * //******************************************************************
+ * //
+ * // Copyright 2015 Intel Corporation.
+ * //
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ * //
+ * // 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 org.iotivity.base.examples;
+
+import android.app.Activity;
+import android.content.Context;
+import android.os.Bundle;
+import android.text.method.ScrollingMovementMethod;
+import android.util.Log;
+import android.view.View;
+import android.widget.CompoundButton;
+import android.widget.ScrollView;
+import android.widget.TextView;
+import android.widget.ToggleButton;
+
+import org.iotivity.base.ErrorCode;
+import org.iotivity.base.ModeType;
+import org.iotivity.base.OcConnectivityType;
+import org.iotivity.base.OcException;
+import org.iotivity.base.OcHeaderOption;
+import org.iotivity.base.OcPlatform;
+import org.iotivity.base.OcRepresentation;
+import org.iotivity.base.OcResource;
+import org.iotivity.base.PlatformConfig;
+import org.iotivity.base.QualityOfService;
+import org.iotivity.base.ServiceType;
+
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * GroupClient
+ */
+public class GroupClient extends Activity implements
+        OcPlatform.OnResourceFoundListener,
+        OcResource.OnGetListener {
+
+    private OcResource mFoundCollectionResource;
+
+    /**
+     * A local method to configure and initialize platform and then search for the collection
+     * resources
+     */
+    private synchronized void startGroupClient() {
+        Context context = this;
+
+        PlatformConfig platformConfig = new PlatformConfig(
+                context,
+                ServiceType.IN_PROC,
+                ModeType.CLIENT,
+                "0.0.0.0", 0,
+                QualityOfService.LOW
+        );
+
+        msg("Configuring platform.");
+        OcPlatform.Configure(platformConfig);
+
+        msg("Find all resources of type \"a.collection\".");
+        try {
+            OcPlatform.findResource(
+                    "",
+                    OcPlatform.WELL_KNOWN_QUERY + "?rt=a.collection",
+                    EnumSet.of(OcConnectivityType.CT_DEFAULT),
+                    this
+            );
+        } catch (OcException e) {
+            Log.e(TAG, e.toString());
+            msg("Failed to invoke find resource API");
+        }
+
+        printLine();
+    }
+
+    /**
+     * An event handler to be executed whenever a "findResource" request completes successfully
+     *
+     * @param foundResource found resource
+     */
+    @Override
+    public synchronized void onResourceFound(OcResource foundResource) {
+        if (null == foundResource) {
+            msg("Found resource is invalid");
+            return;
+        }
+        if (null != mFoundCollectionResource) {
+            msg("Found another resource, ignoring");
+            return;
+        }
+
+        // Get the resource URI
+        String resourceUri = foundResource.getUri();
+        // Get the resource host address
+        String hostAddress = foundResource.getHost();
+        msg("\tURI of the resource: " + resourceUri);
+        msg("\tHost address of the resource: " + hostAddress);
+        // Get the resource types
+        msg("\tList of resource types: ");
+        for (String resourceType : foundResource.getResourceTypes()) {
+            msg("\t\t" + resourceType);
+        }
+        msg("\tList of resource interfaces:");
+        for (String resourceInterface : foundResource.getResourceInterfaces()) {
+            msg("\t\t" + resourceInterface);
+        }
+        msg("\tList of resource connectivity types:");
+        for (OcConnectivityType connectivityType : foundResource.getConnectivityTypeSet()) {
+            msg("\t\t" + connectivityType);
+        }
+
+        if (resourceUri.equals("/core/a/collection")) {
+            mFoundCollectionResource = foundResource;
+
+            msg("Getting representation of a collection resource...");
+
+            Map<String, String> queryParams = new HashMap<>();
+            try {
+                mFoundCollectionResource.get(
+                        "",
+                        OcPlatform.DEFAULT_INTERFACE,
+                        queryParams,
+                        this
+                );
+            } catch (OcException e) {
+                Log.e(TAG, e.toString());
+                msg("Error occurred while invoking \"get\" API");
+            }
+        }
+
+        printLine();
+        enableStartStopButton();
+    }
+
+    /**
+     * An event handler to be executed whenever a "get" request completes successfully
+     *
+     * @param list           list of the header options
+     * @param representation representation of a resource
+     */
+    @Override
+    public void onGetCompleted(List<OcHeaderOption> list, OcRepresentation representation) {
+        msg("Representation of a light collection resource:");
+        for (OcRepresentation childRepresentation : representation.getChildren()) {
+            msg("\t\tURI: " + childRepresentation.getUri());
+        }
+    }
+
+    /**
+     * An event handler to be executed whenever a "get" request fails
+     *
+     * @param throwable exception
+     */
+    @Override
+    public synchronized void onGetFailed(Throwable throwable) {
+        if (throwable instanceof OcException) {
+            OcException ocEx = (OcException) throwable;
+            Log.e(TAG, ocEx.toString());
+            ErrorCode errCode = ocEx.getErrorCode();
+            //do something based on errorCode
+            msg("Error code: " + errCode);
+        }
+        msg("Failed to get representation of a found collection resource");
+    }
+
+    /**
+     * A local method to reset group client
+     */
+    private synchronized void stopGroupClient() {
+        mFoundCollectionResource = null;
+
+        msg("Group Client is reset.");
+        printLine();
+
+        enableStartStopButton();
+    }
+
+    //******************************************************************************
+    // End of the OIC specific code
+    //******************************************************************************
+
+    private final static String TAG = GroupClient.class.getSimpleName();
+    private TextView mConsoleTextView;
+    private ScrollView mScrollView;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.activity_group_client);
+
+        mConsoleTextView = (TextView) findViewById(R.id.consoleTextView);
+        mConsoleTextView.setMovementMethod(new ScrollingMovementMethod());
+        mScrollView = (ScrollView) findViewById(R.id.scrollView);
+        mScrollView.fullScroll(View.FOCUS_DOWN);
+        final ToggleButton toggleButton = (ToggleButton) findViewById(R.id.toggleButton);
+
+        if (null == savedInstanceState) {
+            toggleButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+                    toggleButton.setEnabled(false);
+                    if (isChecked) {
+                        new Thread(new Runnable() {
+                            public void run() {
+                                startGroupClient();
+                            }
+                        }).start();
+                    } else {
+                        new Thread(new Runnable() {
+                            public void run() {
+                                stopGroupClient();
+                            }
+                        }).start();
+                    }
+                }
+            });
+        } else {
+            String consoleOutput = savedInstanceState.getString("consoleOutputString");
+            mConsoleTextView.setText(consoleOutput);
+            boolean buttonCheked = savedInstanceState.getBoolean("toggleButtonChecked");
+            toggleButton.setChecked(buttonCheked);
+        }
+    }
+
+    @Override
+    protected void onSaveInstanceState(Bundle outState) {
+        super.onSaveInstanceState(outState);
+        outState.putString("consoleOutputString", mConsoleTextView.getText().toString());
+        ToggleButton toggleButton = (ToggleButton) findViewById(R.id.toggleButton);
+        outState.putBoolean("toggleButtonChecked", toggleButton.isChecked());
+    }
+
+    @Override
+    protected void onRestoreInstanceState(Bundle savedInstanceState) {
+        super.onRestoreInstanceState(savedInstanceState);
+
+        String consoleOutput = savedInstanceState.getString("consoleOutputString");
+        mConsoleTextView.setText(consoleOutput);
+
+        final ToggleButton toggleButton = (ToggleButton) findViewById(R.id.toggleButton);
+        boolean buttonCheked = savedInstanceState.getBoolean("toggleButtonChecked");
+        toggleButton.setChecked(buttonCheked);
+    }
+
+    private void msg(final String text) {
+        runOnUiThread(new Runnable() {
+            public void run() {
+                mConsoleTextView.append("\n");
+                mConsoleTextView.append(text);
+                mScrollView.fullScroll(View.FOCUS_DOWN);
+            }
+        });
+        Log.i(TAG, text);
+    }
+
+    private void printLine() {
+        msg("------------------------------------------------------------------------");
+    }
+
+    private void sleep(int seconds) {
+        try {
+            Thread.sleep(seconds * 1000);
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+            Log.e(TAG, e.toString());
+        }
+    }
+
+    private void enableStartStopButton() {
+        runOnUiThread(new Runnable() {
+            public void run() {
+                ToggleButton toggleButton = (ToggleButton) findViewById(R.id.toggleButton);
+                toggleButton.setEnabled(true);
+            }
+        });
+    }
+}
diff --git a/android/examples/groupclient/src/main/res/drawable/iotivityicon.png b/android/examples/groupclient/src/main/res/drawable/iotivityicon.png
new file mode 100644 (file)
index 0000000..e1e4aa7
Binary files /dev/null and b/android/examples/groupclient/src/main/res/drawable/iotivityicon.png differ
diff --git a/android/examples/groupclient/src/main/res/drawable/iotivitylogo.png b/android/examples/groupclient/src/main/res/drawable/iotivitylogo.png
new file mode 100644 (file)
index 0000000..a7d3115
Binary files /dev/null and b/android/examples/groupclient/src/main/res/drawable/iotivitylogo.png differ
diff --git a/android/examples/groupclient/src/main/res/layout/activity_group_client.xml b/android/examples/groupclient/src/main/res/layout/activity_group_client.xml
new file mode 100644 (file)
index 0000000..cebb389
--- /dev/null
@@ -0,0 +1,36 @@
+<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" android:paddingLeft="@dimen/activity_horizontal_margin"
+    android:orientation="vertical"
+    android:paddingRight="@dimen/activity_horizontal_margin"
+    android:paddingTop="@dimen/activity_vertical_margin"
+    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".GroupClient">
+    <ToggleButton
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:id="@+id/toggleButton"
+        android:layout_centerHorizontal="true"
+        android:textOff="Start"
+        android:textOn="Stop"
+        android:layout_alignParentEnd="true"
+        android:layout_alignParentStart="true" />
+    <ScrollView
+        android:layout_below="@id/toggleButton"
+        android:layout_above="@+id/imageView"
+        android:layout_width="fill_parent"
+        android:layout_height="wrap_content"
+        android:fillViewport="true"
+        android:id="@+id/scrollView">
+        <TextView android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:id="@+id/consoleTextView" />
+    </ScrollView>
+    <ImageView
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:id="@+id/imageView"
+        android:layout_alignParentBottom="true"
+        android:layout_alignParentEnd="true"
+        android:layout_alignParentStart="true"
+        android:src="@drawable/iotivitylogo" />
+</RelativeLayout>
\ No newline at end of file
diff --git a/android/examples/groupclient/src/main/res/mipmap-hdpi/iotivityicon.png b/android/examples/groupclient/src/main/res/mipmap-hdpi/iotivityicon.png
new file mode 100644 (file)
index 0000000..e1e4aa7
Binary files /dev/null and b/android/examples/groupclient/src/main/res/mipmap-hdpi/iotivityicon.png differ
diff --git a/android/examples/groupclient/src/main/res/mipmap-mdpi/iotivityicon.png b/android/examples/groupclient/src/main/res/mipmap-mdpi/iotivityicon.png
new file mode 100644 (file)
index 0000000..2e7bce6
Binary files /dev/null and b/android/examples/groupclient/src/main/res/mipmap-mdpi/iotivityicon.png differ
diff --git a/android/examples/groupclient/src/main/res/mipmap-xhdpi/iotivityicon.png b/android/examples/groupclient/src/main/res/mipmap-xhdpi/iotivityicon.png
new file mode 100644 (file)
index 0000000..afa486b
Binary files /dev/null and b/android/examples/groupclient/src/main/res/mipmap-xhdpi/iotivityicon.png differ
diff --git a/android/examples/groupclient/src/main/res/mipmap-xxhdpi/iotivityicon.png b/android/examples/groupclient/src/main/res/mipmap-xxhdpi/iotivityicon.png
new file mode 100644 (file)
index 0000000..3e6bc6a
Binary files /dev/null and b/android/examples/groupclient/src/main/res/mipmap-xxhdpi/iotivityicon.png differ
diff --git a/android/examples/groupclient/src/main/res/values-v21/styles.xml b/android/examples/groupclient/src/main/res/values-v21/styles.xml
new file mode 100644 (file)
index 0000000..dba3c41
--- /dev/null
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <style name="AppTheme" parent="android:Theme.Material.Light">
+    </style>
+</resources>
diff --git a/android/examples/groupclient/src/main/res/values-w820dp/dimens.xml b/android/examples/groupclient/src/main/res/values-w820dp/dimens.xml
new file mode 100644 (file)
index 0000000..63fc816
--- /dev/null
@@ -0,0 +1,6 @@
+<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/android/examples/groupclient/src/main/res/values/dimens.xml b/android/examples/groupclient/src/main/res/values/dimens.xml
new file mode 100644 (file)
index 0000000..47c8224
--- /dev/null
@@ -0,0 +1,5 @@
+<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/android/examples/groupclient/src/main/res/values/strings.xml b/android/examples/groupclient/src/main/res/values/strings.xml
new file mode 100644 (file)
index 0000000..d8b8630
--- /dev/null
@@ -0,0 +1,3 @@
+<resources>
+    <string name="app_name">Group Client</string>
+</resources>
diff --git a/android/examples/groupclient/src/main/res/values/styles.xml b/android/examples/groupclient/src/main/res/values/styles.xml
new file mode 100644 (file)
index 0000000..ff6c9d2
--- /dev/null
@@ -0,0 +1,8 @@
+<resources>
+
+    <!-- Base application theme. -->
+    <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
+        <!-- Customize your theme here. -->
+    </style>
+
+</resources>
diff --git a/android/examples/groupserver/.gitignore b/android/examples/groupserver/.gitignore
new file mode 100644 (file)
index 0000000..796b96d
--- /dev/null
@@ -0,0 +1 @@
+/build
diff --git a/android/examples/groupserver/build.gradle b/android/examples/groupserver/build.gradle
new file mode 100644 (file)
index 0000000..209149f
--- /dev/null
@@ -0,0 +1,24 @@
+apply plugin: 'com.android.application'
+
+android {
+    compileSdkVersion 22
+    buildToolsVersion "22.0.1"
+
+    defaultConfig {
+        applicationId "org.iotivity.base.examples.groupserver"
+        minSdkVersion 21
+        targetSdkVersion 22
+        versionCode 1
+        versionName "1.0"
+    }
+    buildTypes {
+        release {
+            minifyEnabled false
+            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
+        }
+    }
+}
+
+dependencies {
+    compile fileTree(dir: 'libs', include: ['*.jar'])
+}
diff --git a/android/examples/groupserver/groupserver.iml b/android/examples/groupserver/groupserver.iml
new file mode 100644 (file)
index 0000000..b648b2f
--- /dev/null
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module external.linked.project.id=":groupserver" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="examples" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
+  <component name="FacetManager">
+    <facet type="android-gradle" name="Android-Gradle">
+      <configuration>
+        <option name="GRADLE_PROJECT_PATH" value=":groupserver" />
+      </configuration>
+    </facet>
+    <facet type="android" name="Android">
+      <configuration>
+        <option name="SELECTED_BUILD_VARIANT" value="debug" />
+        <option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
+        <option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
+        <option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
+        <option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
+        <option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugTest" />
+        <option name="COMPILE_JAVA_TEST_TASK_NAME" value="compileDebugTestSources" />
+        <option name="TEST_SOURCE_GEN_TASK_NAME" value="generateDebugTestSources" />
+        <option name="ALLOW_USER_CONFIGURATION" value="false" />
+        <option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
+        <option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
+        <option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
+        <option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
+      </configuration>
+    </facet>
+  </component>
+  <component name="NewModuleRootManager" inherit-compiler-output="false">
+    <output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
+    <output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
+    <exclude-output />
+    <content url="file://$MODULE_DIR$">
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/debug" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/test/debug" isTestSource="true" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/test/debug" isTestSource="true" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/test/debug" isTestSource="true" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/test/debug" isTestSource="true" generated="true" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/test/debug" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/test/debug" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
+      <sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
+      <excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
+      <excludeFolder url="file://$MODULE_DIR$/build/outputs" />
+      <excludeFolder url="file://$MODULE_DIR$/build/tmp" />
+    </content>
+    <orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
+    <orderEntry type="sourceFolder" forTests="false" />
+    <orderEntry type="library" exported="" name="iotivity-armeabi-base-debug-unspecified" level="project" />
+  </component>
+</module>
\ No newline at end of file
diff --git a/android/examples/groupserver/proguard-rules.pro b/android/examples/groupserver/proguard-rules.pro
new file mode 100644 (file)
index 0000000..d26150c
--- /dev/null
@@ -0,0 +1,17 @@
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in /home/rahul/sdk/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the proguardFiles
+# directive in build.gradle.
+#
+# For more details, see
+#   http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+#   public *;
+#}
diff --git a/android/examples/groupserver/src/main/AndroidManifest.xml b/android/examples/groupserver/src/main/AndroidManifest.xml
new file mode 100644 (file)
index 0000000..34a0806
--- /dev/null
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="org.iotivity.base.examples" >
+
+    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
+    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+    <uses-permission android:name="android.permission.BLUETOOTH"/>
+    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
+    <uses-permission android:name="android.permission.INTERNET"/>
+    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
+    <uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/>
+    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
+    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
+    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
+
+    <application
+        android:allowBackup="true"
+        android:icon="@mipmap/iotivityicon"
+        android:label="@string/app_name"
+        android:theme="@style/AppTheme" >
+        <activity
+            android:screenOrientation="portrait"
+            android:name=".GroupServer"
+            android:label="@string/app_name" >
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+    </application>
+
+</manifest>
diff --git a/android/examples/groupserver/src/main/java/org/iotivity/base/examples/GroupServer.java b/android/examples/groupserver/src/main/java/org/iotivity/base/examples/GroupServer.java
new file mode 100644 (file)
index 0000000..06089b0
--- /dev/null
@@ -0,0 +1,333 @@
+/*
+ * //******************************************************************
+ * //
+ * // Copyright 2015 Intel Corporation.
+ * //
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ * //
+ * // 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 org.iotivity.base.examples;
+
+import android.app.Activity;
+import android.content.Context;
+import android.os.Bundle;
+import android.text.method.ScrollingMovementMethod;
+import android.util.Log;
+import android.view.View;
+import android.widget.CompoundButton;
+import android.widget.ScrollView;
+import android.widget.TextView;
+import android.widget.ToggleButton;
+
+import org.iotivity.base.ModeType;
+import org.iotivity.base.OcConnectivityType;
+import org.iotivity.base.OcException;
+import org.iotivity.base.OcPlatform;
+import org.iotivity.base.OcResource;
+import org.iotivity.base.OcResourceHandle;
+import org.iotivity.base.PlatformConfig;
+import org.iotivity.base.QualityOfService;
+import org.iotivity.base.ResourceProperty;
+import org.iotivity.base.ServiceType;
+
+import java.util.EnumSet;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * GroupServer
+ */
+public class GroupServer extends Activity implements OcPlatform.OnResourceFoundListener {
+
+    private OcResourceHandle mCollectionResourceHandle;
+    private List<OcResourceHandle> mProxyResourceHandleList = new LinkedList<>();
+
+    /**
+     * A local method to configure and initialize platform, register a collection resource
+     * and then search for the light resources.In addition it creates a local light resource and
+     * adds it to the collection.
+     */
+    private synchronized void startGroupServer() {
+        Context context = this;
+
+        PlatformConfig platformConfig = new PlatformConfig(
+                context,
+                ServiceType.IN_PROC,
+                ModeType.CLIENT_SERVER,
+                "0.0.0.0", 0,
+                QualityOfService.LOW
+        );
+
+        msg("Configuring platform.");
+        OcPlatform.Configure(platformConfig);
+
+        String resourceUri = "/core/a/collection";
+        String resourceTypeName = "a.collection";
+        msg("Registering a collection resource.");
+        try {
+            mCollectionResourceHandle = OcPlatform.registerResource(
+                    resourceUri,                //resource URI
+                    resourceTypeName,           //resource type name
+                    OcPlatform.BATCH_INTERFACE, //using batch interface
+                    null,                       //use default entity handler
+                    EnumSet.of(ResourceProperty.DISCOVERABLE)
+            );
+        } catch (OcException e) {
+            Log.e(TAG, e.toString());
+            msg("Failed to register a collection resource");
+        }
+
+        if (null != mCollectionResourceHandle) {
+            try {
+                OcPlatform.bindInterfaceToResource(
+                        mCollectionResourceHandle,
+                        OcPlatform.GROUP_INTERFACE);
+
+                OcPlatform.bindInterfaceToResource(
+                        mCollectionResourceHandle,
+                        OcPlatform.DEFAULT_INTERFACE);
+            } catch (OcException e) {
+                e.printStackTrace();
+            }
+
+        }
+
+        msg("Sending request to find all resources with \"core.light\" type name");
+        try {
+            OcPlatform.findResource(
+                    "",
+                    OcPlatform.WELL_KNOWN_QUERY + "?rt=core.light",
+                    EnumSet.of(OcConnectivityType.CT_DEFAULT),
+                    this);
+
+        } catch (OcException e) {
+            Log.e(TAG, e.toString());
+            msg("Failed to invoke find resource API");
+        }
+
+        OcResourceHandle localLightResourceHandle = null;
+        msg("Registering a local light resource");
+        try {
+            localLightResourceHandle = OcPlatform.registerResource(
+                    "/a/light/local",               //resource URI
+                    "core.light",                   //resource type name
+                    OcPlatform.DEFAULT_INTERFACE,   //using default interface
+                    null,                           //use default entity handler
+                    EnumSet.of(ResourceProperty.DISCOVERABLE)
+            );
+        } catch (OcException e) {
+            Log.e(TAG, e.toString());
+            msg("Failed to register a local ligh resource");
+        }
+
+        if (null != localLightResourceHandle) {
+            msg("Binding a found resource proxy handle to the collection resource");
+            try {
+                OcPlatform.bindResource(mCollectionResourceHandle, localLightResourceHandle);
+            } catch (OcException e) {
+                Log.e(TAG, e.toString());
+                msg("Failed to bind found resource proxy handle to the collection resource");
+            }
+            mProxyResourceHandleList.add(localLightResourceHandle);
+        }
+
+        printLine();
+    }
+
+    /**
+     * An event handler to be executed whenever a "findResource" request completes successfully
+     *
+     * @param foundResource found resource
+     */
+    @Override
+    public synchronized void onResourceFound(OcResource foundResource) {
+        if (null == foundResource) {
+            msg("Found resource is invalid");
+            return;
+        }
+        msg("Found resource with \"core.light\" type name\".");
+        // Get the resource host address
+        String hostAddress = foundResource.getHost();
+        // Get the resource URI
+        String resourceUri = foundResource.getUri();
+        msg("\tHost address of the resource: " + hostAddress);
+        msg("\tURI of the resource: " + resourceUri);
+        // Get the resource types
+        msg("\tList of resource types: ");
+        for (String resourceType : foundResource.getResourceTypes()) {
+            msg("\t\t" + resourceType);
+        }
+        msg("\tList of resource interfaces:");
+        for (String resourceInterface : foundResource.getResourceInterfaces()) {
+            msg("\t\t" + resourceInterface);
+        }
+        msg("\tList of resource connectivity types:");
+        for (OcConnectivityType connectivityType : foundResource.getConnectivityTypeSet()) {
+            msg("\t\t" + connectivityType);
+        }
+
+        //In this example we are only interested in the light resources
+        if (resourceUri.equals("/a/light")) {
+            msg("Registering a found resource as a local proxy resource");
+            OcResourceHandle proxyResourceHandle = null;
+            try {
+                proxyResourceHandle = OcPlatform.registerResource(foundResource);
+            } catch (OcException e) {
+                Log.e(TAG, e.toString());
+                msg("Failed to register a found resource as a local proxy resource");
+            }
+
+            if (null != proxyResourceHandle) {
+                msg("Binding a found resource proxy handle to the collection resource");
+                try {
+                    OcPlatform.bindResource(mCollectionResourceHandle, proxyResourceHandle);
+                } catch (OcException e) {
+                    Log.e(TAG, e.toString());
+                    msg("Failed to bind found resource proxy handle to the collection resource");
+                }
+                mProxyResourceHandleList.add(proxyResourceHandle);
+            }
+        }
+
+        printLine();
+        enableStartStopButton();
+    }
+
+    /**
+     * A local method to reset group server
+     */
+    private synchronized void stopGroupServer() {
+        msg("Unregistering resources");
+        for (OcResourceHandle proxyResourceHandle : mProxyResourceHandleList) {
+            try {
+                OcPlatform.unbindResource(mCollectionResourceHandle, proxyResourceHandle);
+            } catch (OcException e) {
+                Log.e(TAG, e.toString());
+                msg("Failed to unbind a proxy resource");
+            }
+            try {
+                OcPlatform.unregisterResource(proxyResourceHandle);
+            } catch (OcException e) {
+                Log.e(TAG, e.toString());
+                msg("Failed to unregister a proxy resource");
+            }
+        }
+        mProxyResourceHandleList.clear();
+
+        if (null != mCollectionResourceHandle) {
+            try {
+                OcPlatform.unregisterResource(mCollectionResourceHandle);
+            } catch (OcException e) {
+                Log.e(TAG, e.toString());
+                msg("Failed to unregister a collection resource");
+            }
+        }
+        msg("Group Server is reset.");
+
+        printLine();
+        enableStartStopButton();
+    }
+
+    //******************************************************************************
+    // End of the OIC specific code
+    //******************************************************************************
+
+    private final static String TAG = GroupServer.class.getSimpleName();
+    private TextView mConsoleTextView;
+    private ScrollView mScrollView;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.activity_group_server);
+
+        mConsoleTextView = (TextView) findViewById(R.id.consoleTextView);
+        mConsoleTextView.setMovementMethod(new ScrollingMovementMethod());
+        mScrollView = (ScrollView) findViewById(R.id.scrollView);
+        mScrollView.fullScroll(View.FOCUS_DOWN);
+        final ToggleButton toggleButton = (ToggleButton) findViewById(R.id.toggleButton);
+
+        if (null == savedInstanceState) {
+            toggleButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+                    toggleButton.setEnabled(false);
+                    if (isChecked) {
+                        new Thread(new Runnable() {
+                            public void run() {
+                                startGroupServer();
+                            }
+                        }).start();
+                    } else {
+                        new Thread(new Runnable() {
+                            public void run() {
+                                stopGroupServer();
+                            }
+                        }).start();
+                    }
+                }
+            });
+        } else {
+            String consoleOutput = savedInstanceState.getString("consoleOutputString");
+            mConsoleTextView.setText(consoleOutput);
+            boolean buttonCheked = savedInstanceState.getBoolean("toggleButtonChecked");
+            toggleButton.setChecked(buttonCheked);
+        }
+    }
+
+    @Override
+    protected void onSaveInstanceState(Bundle outState) {
+        super.onSaveInstanceState(outState);
+        outState.putString("consoleOutputString", mConsoleTextView.getText().toString());
+        ToggleButton toggleButton = (ToggleButton) findViewById(R.id.toggleButton);
+        outState.putBoolean("toggleButtonChecked", toggleButton.isChecked());
+    }
+
+    @Override
+    protected void onRestoreInstanceState(Bundle savedInstanceState) {
+        super.onRestoreInstanceState(savedInstanceState);
+
+        String consoleOutput = savedInstanceState.getString("consoleOutputString");
+        mConsoleTextView.setText(consoleOutput);
+
+        final ToggleButton toggleButton = (ToggleButton) findViewById(R.id.toggleButton);
+        boolean buttonCheked = savedInstanceState.getBoolean("toggleButtonChecked");
+        toggleButton.setChecked(buttonCheked);
+    }
+
+    private void msg(final String text) {
+        runOnUiThread(new Runnable() {
+            public void run() {
+                mConsoleTextView.append("\n");
+                mConsoleTextView.append(text);
+                mScrollView.fullScroll(View.FOCUS_DOWN);
+            }
+        });
+        Log.i(TAG, text);
+    }
+
+    private void printLine() {
+        msg("------------------------------------------------------------------------");
+    }
+
+    private void enableStartStopButton() {
+        runOnUiThread(new Runnable() {
+            public void run() {
+                ToggleButton toggleButton = (ToggleButton) findViewById(R.id.toggleButton);
+                toggleButton.setEnabled(true);
+            }
+        });
+    }
+}
\ No newline at end of file
diff --git a/android/examples/groupserver/src/main/res/drawable/iotivityicon.png b/android/examples/groupserver/src/main/res/drawable/iotivityicon.png
new file mode 100644 (file)
index 0000000..e1e4aa7
Binary files /dev/null and b/android/examples/groupserver/src/main/res/drawable/iotivityicon.png differ
diff --git a/android/examples/groupserver/src/main/res/drawable/iotivitylogo.png b/android/examples/groupserver/src/main/res/drawable/iotivitylogo.png
new file mode 100644 (file)
index 0000000..a7d3115
Binary files /dev/null and b/android/examples/groupserver/src/main/res/drawable/iotivitylogo.png differ
diff --git a/android/examples/groupserver/src/main/res/layout/activity_group_server.xml b/android/examples/groupserver/src/main/res/layout/activity_group_server.xml
new file mode 100644 (file)
index 0000000..2befa76
--- /dev/null
@@ -0,0 +1,36 @@
+<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" android:paddingLeft="@dimen/activity_horizontal_margin"
+    android:orientation="vertical"
+    android:paddingRight="@dimen/activity_horizontal_margin"
+    android:paddingTop="@dimen/activity_vertical_margin"
+    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".GroupServer">
+    <ToggleButton
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:id="@+id/toggleButton"
+        android:layout_centerHorizontal="true"
+        android:textOff="Start"
+        android:textOn="Stop"
+        android:layout_alignParentEnd="true"
+        android:layout_alignParentStart="true" />
+    <ScrollView
+        android:layout_below="@id/toggleButton"
+        android:layout_above="@+id/imageView"
+        android:layout_width="fill_parent"
+        android:layout_height="wrap_content"
+        android:fillViewport="true"
+        android:id="@+id/scrollView">
+        <TextView android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:id="@+id/consoleTextView" />
+    </ScrollView>
+    <ImageView
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:id="@+id/imageView"
+        android:layout_alignParentBottom="true"
+        android:layout_alignParentEnd="true"
+        android:layout_alignParentStart="true"
+        android:src="@drawable/iotivitylogo" />
+</RelativeLayout>
\ No newline at end of file
diff --git a/android/examples/groupserver/src/main/res/mipmap-hdpi/iotivityicon.png b/android/examples/groupserver/src/main/res/mipmap-hdpi/iotivityicon.png
new file mode 100644 (file)
index 0000000..e1e4aa7
Binary files /dev/null and b/android/examples/groupserver/src/main/res/mipmap-hdpi/iotivityicon.png differ
diff --git a/android/examples/groupserver/src/main/res/mipmap-mdpi/iotivityicon.png b/android/examples/groupserver/src/main/res/mipmap-mdpi/iotivityicon.png
new file mode 100644 (file)
index 0000000..2e7bce6
Binary files /dev/null and b/android/examples/groupserver/src/main/res/mipmap-mdpi/iotivityicon.png differ
diff --git a/android/examples/groupserver/src/main/res/mipmap-xhdpi/iotivityicon.png b/android/examples/groupserver/src/main/res/mipmap-xhdpi/iotivityicon.png
new file mode 100644 (file)
index 0000000..afa486b
Binary files /dev/null and b/android/examples/groupserver/src/main/res/mipmap-xhdpi/iotivityicon.png differ
diff --git a/android/examples/groupserver/src/main/res/mipmap-xxhdpi/iotivityicon.png b/android/examples/groupserver/src/main/res/mipmap-xxhdpi/iotivityicon.png
new file mode 100644 (file)
index 0000000..3e6bc6a
Binary files /dev/null and b/android/examples/groupserver/src/main/res/mipmap-xxhdpi/iotivityicon.png differ
diff --git a/android/examples/groupserver/src/main/res/values-v21/styles.xml b/android/examples/groupserver/src/main/res/values-v21/styles.xml
new file mode 100644 (file)
index 0000000..dba3c41
--- /dev/null
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <style name="AppTheme" parent="android:Theme.Material.Light">
+    </style>
+</resources>
diff --git a/android/examples/groupserver/src/main/res/values-w820dp/dimens.xml b/android/examples/groupserver/src/main/res/values-w820dp/dimens.xml
new file mode 100644 (file)
index 0000000..63fc816
--- /dev/null
@@ -0,0 +1,6 @@
+<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/android/examples/groupserver/src/main/res/values/dimens.xml b/android/examples/groupserver/src/main/res/values/dimens.xml
new file mode 100644 (file)
index 0000000..47c8224
--- /dev/null
@@ -0,0 +1,5 @@
+<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/android/examples/groupserver/src/main/res/values/strings.xml b/android/examples/groupserver/src/main/res/values/strings.xml
new file mode 100644 (file)
index 0000000..7079346
--- /dev/null
@@ -0,0 +1,3 @@
+<resources>
+    <string name="app_name">Group Server</string>
+</resources>
diff --git a/android/examples/groupserver/src/main/res/values/styles.xml b/android/examples/groupserver/src/main/res/values/styles.xml
new file mode 100644 (file)
index 0000000..ff6c9d2
--- /dev/null
@@ -0,0 +1,8 @@
+<resources>
+
+    <!-- Base application theme. -->
+    <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
+        <!-- Customize your theme here. -->
+    </style>
+
+</resources>