Additionally source is modified to align with new version of apis.
Project names are changed as well to align with tizen samples.
ResourceContainer examples are removed because it will be excluded from service api.
JIRA issue : https://jira.iotivity.org/i#browse/IOT-744
Change-Id: Ie26dcef2ba373cde796099c4f6e5c32fbcf8aa03
Signed-off-by: coderhyme <jhyo.kim@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2999
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
+++ /dev/null
-<?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 combineaccessrules="false" exported="true" kind="src" path="/java"/>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="src" path="gen"/>
- <classpathentry kind="output" path="bin/classes"/>
-</classpath>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>REClient</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>
+++ /dev/null
-<?xml version="1.0" encoding="utf-8"?>
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.re.sampleclient"
- 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/iot"
- android:label="@string/app_name"
- android:theme="@style/AppTheme" >
- <activity
- android:name="com.re.sampleclient.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.re.sampleclient.ResourceClientActivity"
- android:label="@string/app_name" >
- </activity>
- <activity
- android:name="com.re.sampleclient.ContainerClientActivity"
- android:label="@string/app_name" >
- </activity>
- </application>
-
-</manifest>
+++ /dev/null
-# 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
+++ /dev/null
-<?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>
+++ /dev/null
-<?xml version="1.0" encoding="utf-8"?>
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent" >
-
- <Button
- android:id="@+id/discoverResource"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentLeft="true"
- android:layout_alignParentRight="true"
- android:layout_alignParentTop="true"
- android:text="Discover Resource" />
-
- <EditText
- android:id="@+id/log"
- android:layout_width="fill_parent"
- android:layout_height="250dp"
- android:layout_alignParentLeft="true"
- android:layout_below="@+id/discoverResource"
- android:editable="false"
- android:ems="10" />
-
-</RelativeLayout>
+++ /dev/null
-<?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/button1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentLeft="true"
- android:layout_alignParentTop="true"
- android:text="Discover Resource" />
-
- <ListView
- android:id="@+id/groupaApiList"
- android:layout_width="match_parent"
- android:layout_height="300dp"
- android:layout_below="@id/button1">
- </ListView>
-
- <EditText
- android:id="@+id/EditText"
- android:layout_width="fill_parent"
- android:layout_height="250dp"
- android:layout_alignParentLeft="true"
- android:layout_below="@+id/groupaApiList"
- android:layout_marginTop="15dp"
- android:ems="10"
- android:editable="false" >
-
- <requestFocus />
- </EditText>
-
-</RelativeLayout>
+++ /dev/null
-<?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>
+++ /dev/null
-<menu xmlns:android="http://schemas.android.com/apk/res/android" >
- <item
- android:id="@+id/re_client"
- android:orderInCategory="100"
- android:showAsAction="never"
- android:title="@string/re_client"/>
-</menu>
+++ /dev/null
-<resources>
-
- <style name="AppBaseTheme" parent="android:Theme.Holo.Light">
- </style>
-
-</resources>
+++ /dev/null
- <resources>
-
- <style name="AppBaseTheme" parent="android:Theme.Light">
- </style>
-
- <style name="AppTheme" parent="AppBaseTheme">
- </style>
-
-</resources>
+++ /dev/null
-<resources>
- <dimen name="activity_horizontal_margin">64dp</dimen>
-</resources>
+++ /dev/null
-<resources>
- <dimen name="activity_horizontal_margin">16dp</dimen>
- <dimen name="activity_vertical_margin">16dp</dimen>
-</resources>
+++ /dev/null
-<?xml version="1.0" encoding="utf-8"?>
-<resources>
- <string name="app_name">REClient</string>
- <string name="re_client">RE Client!</string>
-</resources>
+++ /dev/null
-<resources>
-
- <style name="AppBaseTheme" parent="android:Theme.Light">
-
- </style>
-
- <!-- Application theme. -->
- <style name="AppTheme" parent="AppBaseTheme">
-
- </style>
-
-</resources>
+++ /dev/null
-/******************************************************************
- *
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- *
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************/
-
-package com.re.sampleclient;
-
-import java.util.Vector;
-
-import org.iotivity.ResourceEncapsulation.client.RCSAddress;
-import org.iotivity.ResourceEncapsulation.client.RCSDiscoveryManager;
-import org.iotivity.ResourceEncapsulation.client.RCSDiscoveryManager.IDiscoverResourceListener;
-import org.iotivity.ResourceEncapsulation.client.RCSRemoteResourceObject;
-import org.iotivity.ResourceEncapsulation.common.RCSException;
-
-import android.app.Activity;
-import android.os.Bundle;
-import android.util.Log;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.Button;
-import android.widget.EditText;
-
-/**
- * It contains the discover resource API for Discovering Container Resource
- */
-public class ContainerClientActivity extends Activity {
-
- private final RCSDiscoveryManager discoveyManagerObj = RCSDiscoveryManager
- .getInstance();
- private final String LOG_TAG = "[ReSample] "
- + this.getClass()
- .getSimpleName();
- private Button discoverResourceButton;
- private EditText logs;
- public static String logMessage;
- private DiscoverResourceListener discoverResourceListener;
- public static ContainerClientActivity containerClientActivityObj;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.resource_container);
-
- containerClientActivityObj = this;
- discoverResourceButton = (Button) findViewById(R.id.discoverResource);
- logs = (EditText) findViewById(R.id.log);
-
- discoverResourceListener = new DiscoverResourceListener();
- discoveyManagerObj
- .setDiscoverResourceListener(discoverResourceListener);
-
- discoverResourceButton.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- RCSAddress address = RCSAddress.multicast();
- try {
- discoveyManagerObj.discoverResourceByType(address,
- "oic.softsensor");
- logMessage = "";
- logs.setText(logMessage);
- } catch (RCSException e) {
- e.printStackTrace();
- }
- }
- });
- }
-
- /**
- * Listener for receiving Resource discovered in the network.
- */
- private class DiscoverResourceListener implements IDiscoverResourceListener {
-
- @Override
- public void onResourceDiscovered(RCSRemoteResourceObject foundResource) {
- Log.i(LOG_TAG, "onResourceDiscovered invoked");
-
- String resourceURI = foundResource.getUri();
- String hostAddress = foundResource.getAddress();
- boolean isObservableflag = foundResource.isObservable();
-
- Vector<String> resourceTypes = foundResource.getTypes();
- Vector<String> resourceInterfaces = foundResource.getInterFaces();
-
- logMessage = "URI : " + resourceURI + "\n";
- logMessage += "Host : " + hostAddress + "\n";
- for (int i = 0; i < resourceTypes.size(); i++) {
- logMessage += "resourceType : " + resourceTypes.get(i) + "\n";
- }
-
- for (int i = 0; i < resourceInterfaces.size(); i++) {
- logMessage += "resourceInterfaces : "
- + resourceInterfaces.get(i) + "\n";
- }
- logMessage += "isObservable : " + isObservableflag + "\n";
-
- ContainerClientActivity.this.runOnUiThread(new Runnable() {
- public void run() {
- logs.setText(logMessage);
- }
- });
- }
- };
-}
+++ /dev/null
-/******************************************************************
- *
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- *
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************/
-package com.re.sampleclient;
-
-import java.util.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 android.app.Activity;
-import android.app.AlertDialog;
-import android.content.DialogInterface;
-import android.content.DialogInterface.OnClickListener;
-import android.content.Intent;
-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.AdapterView.OnItemClickListener;
-import android.widget.ArrayAdapter;
-import android.widget.ListView;
-
-/**
- * Starting Activity of the application responsible for configuring the
- * OcPlatform and redirecting to ResourceClient activity or Container 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 = "[ReSample] "
- + 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("Resource Client");
- apisList.add("Discover Container 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,
- ResourceClientActivity.class);
- startActivity(intent);
- }
- if (position == 1) {
-
- Intent intent = new Intent(activityObj,
- ContainerClientActivity.class);
- startActivity(intent);
- }
- }
- });
-
- // calling the method to check the Wi-fi connectivity and configuring
- // the OcPlatform
- configurePlatform();
- }
-
- @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");
- }
-}
+++ /dev/null
-/******************************************************************
- *
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- *
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************/
-package com.re.sampleclient;
-
-import java.util.Vector;
-
-import org.iotivity.ResourceEncapsulation.client.RCSAddress;
-import org.iotivity.ResourceEncapsulation.client.RCSDiscoveryManager;
-import org.iotivity.ResourceEncapsulation.client.RCSDiscoveryManager.IDiscoverResourceListener;
-import org.iotivity.ResourceEncapsulation.client.RCSRemoteResourceObject.IGetRemoteAttributeListener;
-import org.iotivity.ResourceEncapsulation.client.RCSRemoteResourceObject.ISetRemoteAttributeListener;
-import org.iotivity.ResourceEncapsulation.client.RCSRemoteResourceObject.IStateChangedCallbackListener;
-import org.iotivity.ResourceEncapsulation.client.RCSRemoteResourceObject.ICacheUpdateListener;
-import org.iotivity.ResourceEncapsulation.client.RCSRemoteResourceObject.CacheState;
-import org.iotivity.ResourceEncapsulation.client.RCSRemoteResourceObject.ResourceState;
-import org.iotivity.ResourceEncapsulation.client.RCSRemoteResourceObject;
-import org.iotivity.ResourceEncapsulation.common.AttriubtesGetValueTypes;
-import org.iotivity.ResourceEncapsulation.common.RCSException;
-import org.iotivity.ResourceEncapsulation.common.RCSResourceAttributes;
-
-import android.os.Message;
-import android.util.Log;
-
-/**
- * For calling the Resource Client APIs as per user selection on UI and for
- * updating the UI
- *
- * It contains all the Resource Client APIs.
- */
-public class ResourceClient {
-
- private static final String LOG_TAG = "[RESample] Client";
- private static Message msg;
- public String logMessage;
-
- private final RCSDiscoveryManager discoveyManagerObj;
- public RCSRemoteResourceObject remoteResourceObj;
-
- private static ResourceClientActivity resourcClientActivityObj = null;
- private final DiscoverResourceListener discoverResourceListener;
- private final StateChangedListener stateChangedListener;
- private final CacheUpdateListener cacheUpdateListener;
- private final RemoteAttributeGetListener remoteAttributeGetListener;
- private final RemoteAttributeSetListener remoteAttributeSetListener;
- static boolean monitoringState = false;
- static boolean cachingState = false;
-
- // constructor
- public ResourceClient() {
- discoveyManagerObj = RCSDiscoveryManager.getInstance();
- discoverResourceListener = new DiscoverResourceListener();
- stateChangedListener = new StateChangedListener();
- cacheUpdateListener = new CacheUpdateListener();
- remoteAttributeGetListener = new RemoteAttributeGetListener();
- remoteAttributeSetListener = new RemoteAttributeSetListener();
-
- discoveyManagerObj
- .setDiscoverResourceListener(discoverResourceListener);
-
- resourcClientActivityObj = ResourceClientActivity
- .getResourceClientActivityObj();
- }
-
- /**
- * Listener for receiving Resource discovered in network.
- */
- private class DiscoverResourceListener implements IDiscoverResourceListener {
-
- @Override
- public void onResourceDiscovered(RCSRemoteResourceObject foundResource) {
- Log.i(LOG_TAG, "onResourceDiscovered invoked");
-
- String resourceURI = foundResource.getUri();
- String hostAddress = foundResource.getAddress();
- boolean isObservableflag = foundResource.isObservable();
-
- Vector<String> resourceTypes = foundResource.getTypes();
- Vector<String> resourceInterfaces = foundResource.getInterFaces();
- remoteResourceObj = foundResource;
- cachingState = false;
- monitoringState = false;
-
- msg = Message.obtain();
- msg.what = 0;
- resourcClientActivityObj.getHandler().sendMessage(msg);
-
- logMessage = "URI : " + resourceURI + "\n";
- logMessage += "Host : " + hostAddress + "\n";
- for (int i = 0; i < resourceTypes.size(); i++) {
- logMessage += "resourceType : " + resourceTypes.get(i) + "\n";
- }
-
- for (int i = 0; i < resourceInterfaces.size(); i++) {
- logMessage += "resourceInterfaces : "
- + resourceInterfaces.get(i) + "\n";
- }
- logMessage += "isObservable : " + isObservableflag + "\n";
-
- ResourceClientActivity.setMessageLog(logMessage);
- msg = Message.obtain();
- msg.what = 1;
- resourcClientActivityObj.getHandler().sendMessage(msg);
- }
- };
-
- /**
- * Listener for receiving Changed resource state as a result of
- * startMonitoring API
- */
- private class StateChangedListener implements IStateChangedCallbackListener {
-
- @Override
- public void onStateChanged(ResourceState resourceState) {
- Log.i(LOG_TAG, "onStateChangedCallback invoked");
-
- switch (resourceState) {
- case NONE:
- Log.i(LOG_TAG, "Current Resource State : NOT_MONITORING");
- logMessage = "Current Resource State : NOT_MONITORING\n";
- break;
-
- case ALIVE:
- Log.i(LOG_TAG, "Current Resource State : ALIVE");
- logMessage = "Current Resource State : ALIVE\n";
- break;
-
- case REQUESTED:
- Log.i(LOG_TAG, "Current Resource State : REQUESTED");
- logMessage = "Current Resource State : REQUESTED\n";
- break;
-
- case LOST_SIGNAL:
- Log.i(LOG_TAG, "Current Resource State : LOST_SIGNAL");
- logMessage = "Current Resource State : LOST_SIGNAL\n";
- logMessage += "Start the server and press discover resource button"
- + "\n";
- break;
-
- case DESTROYED:
- Log.i(LOG_TAG, "Current Resource State : DESTROYED");
- logMessage = "Current Resource State : DESTROYED\n";
- break;
- }
-
- ResourceClientActivity.setMessageLog(logMessage);
- msg = Message.obtain();
- msg.what = 1;
- resourcClientActivityObj.getHandler().sendMessage(msg);
- }
- }
-
- /**
- * Listener for receiving updated resource attributes as a result of
- * startCaching() API with callback
- */
- private class CacheUpdateListener implements ICacheUpdateListener {
- @Override
- public void onCacheUpdatedCallback(RCSResourceAttributes attributes) {
- Log.i(LOG_TAG, "onCacheUpdatedCallback invoked");
-
- printAttributes(attributes);
- }
- };
-
- /**
- * Listener for receiving the resource attributes as a result of
- * getRemoteAttributes() API
- */
- private class RemoteAttributeGetListener implements
- IGetRemoteAttributeListener {
- @Override
- public void onRemoteAttributesGetCallback(
- RCSResourceAttributes attributes) {
-
- Log.i(LOG_TAG, "onRemoteAttributesGetCallback invoked");
- printAttributes(attributes);
- }
- };
-
- /**
- * Listener for receiving the resource attributes as a result of
- * setRemoteAttributes() API
- */
- private class RemoteAttributeSetListener implements
- ISetRemoteAttributeListener {
- @Override
- public void onRemoteAttributesSetCallback(
- RCSResourceAttributes attributes) {
-
- Log.i(LOG_TAG, "onRemoteAttributesSetCallback invoked");
- printAttributes(attributes);
- }
- };
-
- // Discover Resource
- public void disocverResources() {
- Log.d(LOG_TAG, "discover resources entry");
- RCSAddress address = RCSAddress.multicast();
- try {
- discoveyManagerObj.discoverResource(address);
- } catch (RCSException e) {
- e.printStackTrace();
- }
- Log.d(LOG_TAG, "discover resources exit");
- }
-
- // Start Monitoring
- public void startMonitoring() {
- Log.d(LOG_TAG, "startMonitoring entry");
-
- if (null == remoteResourceObj) {
- Log.e(LOG_TAG, "Remote Resource object NULL");
- return;
- }
-
- if (true == monitoringState) {
- logMessage = "Monitoring already started\n";
- Log.e(LOG_TAG, "Monitoring already started");
- ResourceClientActivity.setMessageLog(logMessage);
- msg = Message.obtain();
- msg.what = 1;
- resourcClientActivityObj.getHandler().sendMessage(msg);
- return;
- }
-
- remoteResourceObj.setStateChangedListener(stateChangedListener);
-
- if (null != stateChangedListener) {
- try {
- remoteResourceObj.startMonitoring();
- monitoringState = true;
- } catch (RCSException e) {
- e.printStackTrace();
- return;
- }
- }
- Log.d(LOG_TAG, "startMonitoring exit");
- }
-
- // Stop Monitoring
- public void stopMonitoring() {
- Log.d(LOG_TAG, "stopMonitoring entry");
-
- if (monitoringState) {
- if (null == remoteResourceObj) {
- Log.e(LOG_TAG, "Remote Resource object NULL");
- return;
- }
-
- remoteResourceObj.stopMonitoring();
- monitoringState = false;
- logMessage = "Stopped Resource Monitoring\n";
- } else {
- Log.i(LOG_TAG, "Monitoring not started");
- logMessage = "Monitoring not started\n";
- }
-
- Log.d(LOG_TAG, "stopMonitoring exit");
-
- ResourceClientActivity.setMessageLog(logMessage);
- msg = Message.obtain();
- msg.what = 1;
- resourcClientActivityObj.getHandler().sendMessage(msg);
- }
-
- // Get Attributes
- public void getRemoteAttributes() {
- Log.d(LOG_TAG, "getRemoteAttributes entry");
-
- if (null == remoteResourceObj) {
- Log.e(LOG_TAG, "Remote Resource object NULL");
- return;
- }
-
- try {
- remoteResourceObj
- .setGetRemoteAttributesListener(remoteAttributeGetListener);
-
- if (null != remoteAttributeGetListener) {
- remoteResourceObj.getRemoteAttributes();
- }
- } catch (Exception e) {
- e.printStackTrace();
- return;
- }
-
- Log.d(LOG_TAG, "getRemoteAttributes exit");
- }
-
- // Set Attributes
- public void setRemoteAttributes(int value) {
- Log.d(LOG_TAG, "setRemoteAttributes entry");
-
- if (null == remoteResourceObj) {
- Log.e(LOG_TAG, "Remote Resource object NULL");
- return;
- }
-
- try {
- remoteResourceObj
- .setSetRemoteAttributesListener(remoteAttributeSetListener);
-
- if (null != remoteAttributeSetListener) {
- RCSResourceAttributes attr = new RCSResourceAttributes();
- attr.setValueInt("Temperature", value);
- remoteResourceObj.setRemoteAttributes(attr);
- }
- } catch (Exception e) {
- e.printStackTrace();
- return;
- }
-
- Log.d(LOG_TAG, "setRemoteAttributes exit");
- }
-
- // Start Caching
- public void startCaching(int cachingType) {
- Log.d(LOG_TAG, "startCaching entry");
-
- if (null == remoteResourceObj) {
- Log.e(LOG_TAG, "Remote Resource object NULL");
- return;
- }
-
- if (true == cachingState) {
- Log.d(LOG_TAG, "Caching already started");
- logMessage = "Caching already started\n";
- ResourceClientActivity.setMessageLog(logMessage);
- msg = Message.obtain();
- msg.what = 1;
- resourcClientActivityObj.getHandler().sendMessage(msg);
- return;
- }
-
- if (0 == cachingType) {
- Log.d(LOG_TAG, "startCaching without callback");
- remoteResourceObj.setCacheUpdateListener(null);
- logMessage = "Caching started without callback\n";
- ResourceClientActivity.setMessageLog(logMessage);
- msg = Message.obtain();
- msg.what = 1;
- resourcClientActivityObj.getHandler().sendMessage(msg);
- } else {
- Log.d(LOG_TAG, "startCaching with callback");
- remoteResourceObj.setCacheUpdateListener(cacheUpdateListener);
- logMessage = "Caching started\n";
- ResourceClientActivity.setMessageLog(logMessage);
- msg = Message.obtain();
- msg.what = 1;
- resourcClientActivityObj.getHandler().sendMessage(msg);
- }
-
- try {
- remoteResourceObj.startCaching();
- cachingState = true;
- } catch (RCSException e) {
- e.printStackTrace();
- return;
- }
-
- Log.d(LOG_TAG, "startCaching exit");
- }
-
- // Get Cache State
- public void getCacheState() {
- Log.d(LOG_TAG, "getCacheState entry");
-
- if (null == remoteResourceObj) {
- Log.e(LOG_TAG, "Remote Resource object NULL");
- return;
- }
-
- CacheState cState = remoteResourceObj.getCacheState();
- Log.i(LOG_TAG, "Cache State : " + cState.name());
-
- logMessage = "Cache State : " + cState.toString() + "\n";
- ResourceClientActivity.setMessageLog(logMessage);
- msg = Message.obtain();
- msg.what = 1;
- resourcClientActivityObj.getHandler().sendMessage(msg);
-
- Log.d(LOG_TAG, "getCacheState exit");
- }
-
- // Get Cached Attributes
- public void getCachedAttributes() {
- Log.d(LOG_TAG, "getCachedAttributes entry");
-
- if (null == remoteResourceObj) {
- Log.e(LOG_TAG, "Remote Resource object NULL");
- return;
- }
- if (true == cachingState) {
- RCSResourceAttributes attributes = null;
- try {
- attributes = remoteResourceObj.getCachedAttributes();
- } catch (RCSException e) {
- e.printStackTrace();
- return;
- }
- printAttributes(attributes);
- } else {
- logMessage = "Caching not started" + "\n";
- ResourceClientActivity.setMessageLog(logMessage);
- msg = Message.obtain();
- msg.what = 1;
- resourcClientActivityObj.getHandler().sendMessage(msg);
- }
- Log.d(LOG_TAG, "getCachedAttributes exit");
- }
-
- // Get Cached Attribute
- public void getCachedAttribute() {
- Log.d(LOG_TAG, "getCachedAttribute entry");
-
- if (null == remoteResourceObj) {
- Log.e(LOG_TAG, "Remote Resource object NULL");
- return;
- }
-
- if (true == cachingState) {
- String key = "Temperature";
- String attribute;
- try {
- attribute = remoteResourceObj.getCachedAttribute(key);
- } catch (RCSException e) {
- e.printStackTrace();
- return;
- }
- logMessage = "Key : " + key + "\n";
- logMessage += "Value : " + attribute + "\n";
- ResourceClientActivity.setMessageLog(logMessage);
- msg = Message.obtain();
- msg.what = 1;
- resourcClientActivityObj.getHandler().sendMessage(msg);
- } else {
- logMessage = "Caching not started" + "\n";
- ResourceClientActivity.setMessageLog(logMessage);
- msg = Message.obtain();
- msg.what = 1;
- resourcClientActivityObj.getHandler().sendMessage(msg);
- }
- Log.d(LOG_TAG, "getCachedAttribute exit");
- }
-
- // Stop Caching
- public void stopCaching() {
- Log.d(LOG_TAG, "stopCaching entry");
-
- if (null == remoteResourceObj) {
- Log.e(LOG_TAG, "Remote Resource object NULL");
- return;
- }
-
- if (false == cachingState) {
- Log.e(LOG_TAG, "Caching not started");
- logMessage = "Caching not started\n";
- } else {
- remoteResourceObj.stopCaching();
- cachingState = false;
- logMessage = "Stopped Caching\n";
- }
-
- ResourceClientActivity.setMessageLog(logMessage);
- msg = Message.obtain();
- msg.what = 1;
- resourcClientActivityObj.getHandler().sendMessage(msg);
- Log.d(LOG_TAG, "stopCaching exit");
- }
-
- // For Printing the Attributes on the UI
- private void printAttributes(RCSResourceAttributes attributes) {
- Log.d(LOG_TAG, "Printing Attributes");
-
- try {
- int temperature = attributes.getValue("Temperature", AttriubtesGetValueTypes.Integer);
- Log.i(LOG_TAG, "Temperature : " + temperature);
- logMessage = "Attributes : \n\nTemperature : " + temperature + "\n";
- } catch (Exception e) {
- Log.i(LOG_TAG, "Temperature attribute not found");
- logMessage = "Attributes Temperature not found \n";
- e.printStackTrace();
- return;
- }
- ResourceClientActivity.setMessageLog(logMessage);
- msg = Message.obtain();
- msg.what = 1;
- resourcClientActivityObj.getHandler().sendMessage(msg);
- }
-}
\ No newline at end of file
+++ /dev/null
-/******************************************************************
- *
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- *
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************/
-package com.re.sampleclient;
-
-import java.util.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.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 Client APIs.
- * & for updating UI.
- */
-public class ResourceClientActivity extends Activity {
-
- private ListView list;
- private Button discoverResourceButton;
- private ArrayAdapter<String> groupApis;
- private ArrayList<String> clientApisList;
- private static ResourceClientActivity clientApiActivityObj;
- private static Handler mHandler;
- private ResourceClient resourceClientObj;
- public static Context mcontext;
-
- private static EditText logs;
- private static String logMessage;
-
- private final String LOG_TAG = "[ReSample] "
- + this.getClass()
- .getSimpleName();
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.resourceclientapis);
-
- clientApiActivityObj = this;
- mcontext = this;
-
- resourceClientObj = new ResourceClient();
- clientApisList = new ArrayList<String>();
- list = (ListView) findViewById(R.id.groupaApiList);
- discoverResourceButton = (Button) findViewById(R.id.button1);
- logs = (EditText) findViewById(R.id.EditText);
-
- // adding the item to list that will be displayed on the UI.
- clientApisList.add("1. Start Monitoring");
- clientApisList.add("2. Stop Monitoring");
-
- clientApisList.add("3. Get Remote Attributes");
- clientApisList.add("4. Set Remote Attributes");
-
- clientApisList.add("5. Start Caching without callback");
- clientApisList.add("6. Start Caching with callback");
-
- clientApisList.add("7. Get Cache State");
- clientApisList.add("8. Get All Cached Attributes");
- clientApisList.add("9. Get Cached Attribute");
-
- clientApisList.add("10. Stop Caching");
-
- // handler for updating the UI i.e. MessageLog (TextBox) & ListView
- mHandler = new Handler() {
- @Override
- public void handleMessage(Message msg) {
- switch (msg.what) {
- case 0:
- groupApis = new ArrayAdapter<String>(
- clientApiActivityObj,
- android.R.layout.simple_list_item_1,
- clientApisList);
- list.setAdapter(groupApis);
- list.bringToFront();
- break;
- case 1:
- logs.setText("");
- logs.setText(logMessage);
- Log.i(LOG_TAG, logMessage);
- }
- }
- };
- setHandler(mHandler);
-
- // Discover ResourceButton Listener
- discoverResourceButton.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- resourceClientObj.disocverResources();
- }
- });
-
- // 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) {
- resourceClientObj.startMonitoring();
- } else if (position == 1) {
- resourceClientObj.stopMonitoring();
- } else if (position == 2) {
- resourceClientObj.getRemoteAttributes();
- } else if (position == 3) {
- userInputDialog();
- } else if (position == 4) {
- resourceClientObj.startCaching(0);
- } else if (position == 5) {
- resourceClientObj.startCaching(1);
- } else if (position == 6) {
- resourceClientObj.getCacheState();
- } else if (position == 7) {
- resourceClientObj.getCachedAttributes();
- } else if (position == 8) {
- resourceClientObj.getCachedAttribute();
- } else if (position == 9) {
- resourceClientObj.stopCaching();
- }
- }
- });
- }
-
- // Dialog for taking user input for setting the attribute [Temperature]
- // value
- private void userInputDialog() {
-
- if (null == resourceClientObj) {
- displayToastMessage("Resource Object is NULL");
- } else {
- final Dialog dialog = new Dialog(mcontext);
- dialog.setContentView(R.layout.userinputforattributevalue);
- 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();
-
- try {
- int intValue = Integer.parseInt(value);
- resourceClientObj.setRemoteAttributes(intValue);
- dialog.dismiss();
-
- } catch (NumberFormatException e) {
- String toastmessage = "Please enter the Integer Value";
- displayToastMessage(toastmessage);
- }
- }
- });
- cancel.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- dialog.dismiss();
- }
- });
- }
- }
-
- public static void setMessageLog(String message) {
- logMessage = message;
- }
-
- @Override
- public void onBackPressed() {
- super.onBackPressed();
- }
-
- public static ResourceClientActivity getResourceClientActivityObj() {
- return clientApiActivityObj;
- }
-
- public Handler getHandler() {
- return mHandler;
- }
-
- public void setHandler(Handler mHandler) {
- ResourceClientActivity.mHandler = mHandler;
- }
-
- public void displayToastMessage(String message) {
- Toast toast = Toast.makeText(this, message, Toast.LENGTH_SHORT);
- toast.show();
- Log.i(LOG_TAG, message);
- }
-}
--- /dev/null
+.gradle
+/local.properties
+/.idea
+.DS_Store
+/build
+/captures
+/gradle
--- /dev/null
+To build the app
+
+1. build Iotivity with TARGET_OS=android
+
+2. Copy aar files into app/libs folder
+ - {Iotivity_root}/android/android_api/base/build/outputs/aar/iotivity-{TARGET_ARCH}-base-{MODE}.aar
+ - {Iotivity_root}/service/resource-encapsulation/android/service/build/outputs/aar/iotivity-{TARGET_ARCH}-service-{MODE}.aar
+
+3. Configure dependencies for libs in app/build.gradle
+ - default TARGET_ARCH is armeabi
+ - default MODE is release
+
+ for example, if you build Iotivity as follows,
+
+ $scons TARGET_OS=android TARGET_ARCH=x86 RELEASE=0
+
+ then, dependencies should be modified like below
+
+ dependencies {
+ compile(name:'iotivity-x86-service-debug', ext:'aar')
+ compile(name:'iotivity-x86-base-debug', ext:'aar')
+ }
+
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<module external.linked.project.id="RESampleClientApp" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
+ <component name="FacetManager">
+ <facet type="java-gradle" name="Java-Gradle">
+ <configuration>
+ <option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
+ <option name="BUILDABLE" value="false" />
+ </configuration>
+ </facet>
+ </component>
+ <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="true">
+ <exclude-output />
+ <content url="file://$MODULE_DIR$">
+ <excludeFolder url="file://$MODULE_DIR$/.gradle" />
+ </content>
+ <orderEntry type="inheritedJdk" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ </component>
+</module>
\ No newline at end of file
--- /dev/null
+/build
+/libs/*
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="RESampleClientApp" 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=":app" />
+ </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="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugAndroidTest" />
+ <option name="COMPILE_JAVA_TEST_TASK_NAME" value="compileDebugAndroidTestSources" />
+ <afterSyncTasks>
+ <task>generateDebugAndroidTestSources</task>
+ <task>generateDebugSources</task>
+ </afterSyncTasks>
+ <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" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
+ <output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
+ <output-test url="file://$MODULE_DIR$/build/intermediates/classes/androidTest/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/resValues/debug" type="java-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/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/exploded-aar/iotivity-armeabi-base-release/jars" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/iotivity-armeabi-service-release/jars" />
+ <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 21 Platform" jdkType="Android SDK" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ <orderEntry type="library" exported="" name="iotivity-armeabi-base-release-" level="project" />
+ <orderEntry type="library" exported="" name="iotivity-armeabi-service-release-" level="project" />
+ </component>
+</module>
\ No newline at end of file
--- /dev/null
+apply plugin: 'com.android.application'
+
+android {
+ compileSdkVersion 21
+ buildToolsVersion "21.1.2"
+
+ defaultConfig {
+ applicationId "org.iotivity.service.sample.client"
+ minSdkVersion 21
+ targetSdkVersion 21
+ versionCode 1
+ versionName "1.0"
+ }
+ buildTypes {
+ release {
+ minifyEnabled false
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
+ }
+ }
+}
+
+dependencies {
+ compile fileTree(dir: 'libs', include: ['*.jar'])
+
+ compile(name:'iotivity-armeabi-service-release', ext:'aar')
+ compile(name:'iotivity-armeabi-base-release', ext:'aar')
+}
--- /dev/null
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="org.iotivity.service.sample.client">
+
+ <uses-permission android:name="android.permission.INTERNET" />
+ <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
+
+ <application android:allowBackup="true" android:label="@string/app_name"
+ android:icon="@mipmap/ic_launcher" android:theme="@style/AppTheme">
+ <activity
+ android:name=".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=".ResourceClientActivity" />
+ </application>
+
+</manifest>
--- /dev/null
+/******************************************************************
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ * <p>
+ * <p>
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.service.sample.client;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.DialogInterface;
+import android.content.DialogInterface.OnClickListener;
+import android.content.Intent;
+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.AdapterView.OnItemClickListener;
+import android.widget.ArrayAdapter;
+import android.widget.ListView;
+
+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 java.util.ArrayList;
+
+
+/**
+ * Starting Activity of the application responsible for configuring the
+ * OcPlatform and redirecting to ResourceClient activity.
+ */
+public class MainActivity extends Activity {
+
+ private static final String LOG_TAG = MainActivity.class.getSimpleName();
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_main);
+
+ if (!isWifiConnected()) {
+ showWifiUnavailableDialog();
+ return;
+ }
+
+ configurePlatform();
+ }
+
+ public void onResourceClientClick(View v) {
+ startActivity(new Intent(this, ResourceClientActivity.class));
+ }
+
+ private boolean isWifiConnected() {
+ ConnectivityManager connManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
+ return connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected();
+ }
+
+ private void showWifiUnavailableDialog() {
+ new AlertDialog.Builder(this).setTitle("Error")
+ .setMessage("WiFi is not enabled/connected! Please connect the WiFi and start application again...")
+ .setCancelable(false)
+ .setPositiveButton("OK", new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ finish();
+ }
+ }).create().show();
+ }
+
+ private void configurePlatform() {
+ OcPlatform.Configure(new PlatformConfig(getApplicationContext(),
+ ServiceType.IN_PROC, ModeType.CLIENT_SERVER, "0.0.0.0", 0,
+ QualityOfService.LOW));
+
+ Log.i(LOG_TAG, "Configuration done Successfully");
+ }
+}
--- /dev/null
+/******************************************************************
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ * <p>
+ * <p>
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.service.sample.client;
+
+import static org.iotivity.service.client.RcsRemoteResourceObject.OnCacheUpdatedListener;
+import static org.iotivity.service.client.RcsRemoteResourceObject.OnStateChangedListener;
+import static org.iotivity.service.client.RcsRemoteResourceObject.ResourceState;
+
+import java.lang.ref.WeakReference;
+
+import org.iotivity.service.RcsException;
+import org.iotivity.service.RcsResourceAttributes;
+import org.iotivity.service.RcsValue;
+import org.iotivity.service.client.RcsAddress;
+import org.iotivity.service.client.RcsDiscoveryManager;
+import org.iotivity.service.client.RcsDiscoveryManager.OnResourceDiscoveredListener;
+import org.iotivity.service.client.RcsRemoteResourceObject;
+import org.iotivity.service.client.RcsRemoteResourceObject.OnRemoteAttributesReceivedListener;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.DialogInterface;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.util.Log;
+import android.view.View;
+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.TextView;
+import android.widget.Toast;
+
+/*
+ * Activity for handling user's selection on UI for Resource Client APIs.
+ * & for updating UI.
+ */
+public class ResourceClientActivity extends Activity
+ implements OnItemClickListener {
+
+ private static final String LOG_TAG = ResourceClientActivity.class
+ .getSimpleName();
+
+ private static final int MSG_ID_RESOURCE_DISCOVERED = 0;
+ private static final int MSG_ID_ATTRIBUTE_RECEIVED = 1;
+ private static final int MSG_ID_PRINT_LOG = 2;
+
+ private static final String ATTR_KEY_TEMPERATURE = "Temperature";
+
+ private TextView mLogView;
+ private ListView mListView;
+ private Button mDiscoveryBtn;
+
+ private Handler mHandler;
+ private ArrayAdapter<Item> mItemAdapter;
+
+ private RcsDiscoveryManager.DiscoveryTask mDiscoveryTask;
+ private RcsRemoteResourceObject mResourceObj;
+
+ private OnResourceDiscoveredListener mOnResourceDiscoveredListener = new OnResourceDiscoveredListener() {
+
+ @Override
+ public void onResourceDiscovered(
+ RcsRemoteResourceObject foundResource) {
+ Log.i(LOG_TAG, "onResourceDiscovered");
+
+ mHandler.obtainMessage(MSG_ID_RESOURCE_DISCOVERED, foundResource)
+ .sendToTarget();
+ }
+ };
+
+ private OnStateChangedListener mOnStateChangedListener = new OnStateChangedListener() {
+
+ @Override
+ public void onStateChanged(ResourceState resourceState) {
+ Log.i(LOG_TAG, "onStateChanged");
+
+ mHandler.obtainMessage(MSG_ID_PRINT_LOG,
+ "Current Resource State : " + resourceState);
+ }
+ };
+
+ private OnRemoteAttributesReceivedListener mOnRemoteAttributesReceivedListener = new OnRemoteAttributesReceivedListener() {
+ @Override
+ public void onAttributesReceived(RcsResourceAttributes attrs,
+ int eCode) {
+ Log.i(LOG_TAG, "onAttributesReceived");
+
+ mHandler.obtainMessage(MSG_ID_ATTRIBUTE_RECEIVED, attrs)
+ .sendToTarget();
+ }
+ };
+
+ private OnCacheUpdatedListener mOnCacheUpdatedListener = new OnCacheUpdatedListener() {
+ @Override
+ public void onCacheUpdated(RcsResourceAttributes attrs) {
+ Log.i(LOG_TAG, "onCacheUpdated");
+
+ mHandler.obtainMessage(MSG_ID_ATTRIBUTE_RECEIVED, attrs)
+ .sendToTarget();
+ }
+ };
+
+ private Item mStartMonitoring = new Item("1. Start Monitoring") {
+ @Override
+ public void execute() throws RcsException {
+ if (mResourceObj.isMonitoring()) {
+ printLog("Monitoring already started");
+ return;
+ }
+
+ mResourceObj.startMonitoring(mOnStateChangedListener);
+ }
+ };
+
+ private Item mStopMonitoring = new Item("2. Stop Monitoring") {
+ @Override
+ public void execute() throws RcsException {
+ if (mResourceObj.isMonitoring()) {
+ mResourceObj.stopMonitoring();
+ printLog("Stopped Resource Monitoring");
+ } else {
+ printLog("Monitoring not started");
+ }
+ }
+ };
+
+ private Item mGetRemoteAttributes = new Item("3. Get Remote Attributes") {
+ @Override
+ public void execute() throws RcsException {
+ mResourceObj
+ .getRemoteAttributes(mOnRemoteAttributesReceivedListener);
+ }
+ };
+
+ private Item mSetRemoteAttributes = new Item("4. Set Remote Attributes") {
+
+ @Override
+ public void execute() throws RcsException {
+ showInputValueDialog();
+ }
+ };
+
+ private Item mStartCaching = new Item("5. Start Caching") {
+ @Override
+ public void execute() throws RcsException {
+ if (mResourceObj.isCaching()) {
+ printLog("Caching already started");
+ return;
+ }
+
+ mResourceObj.startCaching(mOnCacheUpdatedListener);
+ }
+ };
+
+ private Item mGetCacheState = new Item("6. Get Cache State") {
+ @Override
+ public void execute() throws RcsException {
+ printLog("Cache State : " + mResourceObj.getCacheState());
+ }
+ };
+
+ private Item mGetCachedAttributes = new Item(
+ "7. Get All Cached Attributes") {
+ @Override
+ public void execute() throws RcsException {
+ printAttributes(mResourceObj.getCachedAttributes());
+ }
+ };
+
+ private Item mGetCachedAttribute = new Item("8. Get Cached Attribute") {
+ @Override
+ public void execute() throws RcsException {
+ printLog(ATTR_KEY_TEMPERATURE + " : " + mResourceObj
+ .getCachedAttribute(ATTR_KEY_TEMPERATURE).asInt());
+ }
+ };
+
+ private Item mStopCaching = new Item("9. Stop Caching") {
+ @Override
+ public void execute() throws RcsException {
+ mResourceObj.stopCaching();
+ }
+ };
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_resource_client);
+
+ mListView = (ListView) findViewById(R.id.list_menu);
+ mLogView = (TextView) findViewById(R.id.text_log);
+ mDiscoveryBtn = (Button) findViewById(R.id.btn_discovery);
+
+ mHandler = new ClientHandler(this);
+
+ initMenuList();
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+
+ if (mDiscoveryTask != null)
+ mDiscoveryTask.cancel();
+ if (mResourceObj != null)
+ mResourceObj.destroy();
+ }
+
+ private void initMenuList() {
+ Item[] items = new Item[] { mStartMonitoring, mStopMonitoring,
+ mGetRemoteAttributes, mSetRemoteAttributes, mStartCaching,
+ mGetCacheState, mGetCachedAttributes, mGetCachedAttribute,
+ mStopCaching };
+
+ mItemAdapter = new ArrayAdapter<>(this,
+ android.R.layout.simple_list_item_1, items);
+
+ mListView.setAdapter(mItemAdapter);
+
+ mListView.setOnItemClickListener(this);
+ }
+
+ @Override
+ public void onItemClick(AdapterView<?> parent, View view, int position,
+ long id) {
+ if (mResourceObj == null) {
+ showError("no discovered RemoteResourceObject");
+ return;
+ }
+
+ try {
+ mItemAdapter.getItem(position).execute();
+ } catch (RcsException e) {
+ showError(e);
+ }
+ }
+
+ public void onDiscoverResourceClick(View v) {
+ toggleDiscovery();
+ }
+
+ private void toggleDiscovery() {
+ if (mDiscoveryTask == null) {
+ try {
+ mDiscoveryTask = RcsDiscoveryManager.getInstance()
+ .discoverResource(RcsAddress.multicast(),
+ mOnResourceDiscoveredListener);
+ mDiscoveryBtn.setText(R.string.cancel_discovery);
+
+ mListView.setVisibility(View.INVISIBLE);
+
+ if (mResourceObj != null) {
+ mResourceObj.destroy();
+ mResourceObj = null;
+ }
+ } catch (RcsException e) {
+ showError(e);
+ }
+ } else {
+ mDiscoveryTask.cancel();
+ mDiscoveryTask = null;
+
+ mDiscoveryBtn.setText(R.string.discover_resource);
+ }
+ }
+
+ private void printAttributes(RcsResourceAttributes attributes) {
+ try {
+ StringBuilder sb = new StringBuilder();
+ for (String key : attributes.keySet()) {
+ sb.append(key + " : " + attributes.get(key));
+ }
+ printLog(sb.toString());
+ } catch (Exception e) {
+ printLog(e);
+ }
+ }
+
+ private void setRemoteResourceObject(
+ RcsRemoteResourceObject foundResource) {
+ if (mResourceObj != null) {
+ Log.w(LOG_TAG, "Another remote resource found...");
+ return;
+ }
+
+ mResourceObj = foundResource;
+
+ mListView.setVisibility(View.VISIBLE);
+ toggleDiscovery();
+
+ try {
+ printLog(resourceInfo(mResourceObj));
+ } catch (RcsException e) {
+ showError(e);
+ }
+ }
+
+ private void showInputValueDialog() {
+ final AlertDialog dialog = new AlertDialog.Builder(this)
+ .setTitle("Enter the Temperature Value")
+ .setView(R.layout.dialog_content_edit_text)
+ .setNegativeButton("Cancel", null).create();
+
+ dialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK",
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialogInterface,
+ int which) {
+
+ EditText temperatureValue = (EditText) dialog
+ .findViewById(R.id.attributeValue);
+
+ try {
+ RcsValue value = new RcsValue(Integer.parseInt(
+ temperatureValue.getText().toString()));
+
+ RcsResourceAttributes attrs = new RcsResourceAttributes();
+ attrs.put(ATTR_KEY_TEMPERATURE, value);
+
+ mResourceObj.setRemoteAttributes(attrs,
+ mOnRemoteAttributesReceivedListener);
+ } catch (NumberFormatException e) {
+ showError("Please enter the Integer Value");
+ } catch (RcsException e) {
+ showError(e);
+ }
+ }
+ });
+ dialog.show();
+ }
+
+ private void showError(String msg) {
+ Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
+ Log.e(LOG_TAG, msg);
+ }
+
+ private void showError(Exception e) {
+ Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
+ Log.e(LOG_TAG, e.getMessage(), e);
+ }
+
+ private void printLog(String message) {
+ Log.i(LOG_TAG, message);
+ mLogView.setText(message);
+ }
+
+ private void printLog(Exception e) {
+ Log.i(LOG_TAG, e.getMessage(), e);
+ mLogView.setText(e.getMessage());
+ }
+
+ private String resourceInfo(RcsRemoteResourceObject resourceObject)
+ throws RcsException {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append("URI : " + resourceObject.getUri() + "\n");
+ sb.append("Host : " + resourceObject.getAddress() + "\n");
+ for (String type : resourceObject.getTypes()) {
+ sb.append("resourceType : " + type + "\n");
+ }
+
+ for (String itf : resourceObject.getInterfaces()) {
+ sb.append("resourceInterfaces : " + itf + "\n");
+ }
+
+ sb.append("isObservable : " + resourceObject.isObservable() + "\n");
+
+ return sb.toString();
+ }
+
+ private static abstract class Item {
+ private final String mTitle;
+
+ protected Item(String title) {
+ mTitle = title;
+ }
+
+ @Override
+ public String toString() {
+ return mTitle;
+ }
+
+ public abstract void execute() throws RcsException;
+ }
+
+ private static class ClientHandler extends Handler {
+ private WeakReference<ResourceClientActivity> mActivityRef;
+
+ private ClientHandler(ResourceClientActivity activity) {
+ mActivityRef = new WeakReference<>(activity);
+ }
+
+ @Override
+ public void handleMessage(Message msg) {
+ super.handleMessage(msg);
+
+ ResourceClientActivity activity = mActivityRef.get();
+ if (activity == null)
+ return;
+
+ switch (msg.what) {
+ case MSG_ID_RESOURCE_DISCOVERED:
+ activity.setRemoteResourceObject(
+ (RcsRemoteResourceObject) msg.obj);
+ break;
+
+ case MSG_ID_ATTRIBUTE_RECEIVED:
+ activity.printAttributes((RcsResourceAttributes) msg.obj);
+ break;
+
+ case MSG_ID_PRINT_LOG:
+ activity.printLog(msg.obj.toString());
+ break;
+ }
+ }
+ }
+}
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+
+ <Button
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:onClick="onResourceClientClick"
+ android:text="@string/resource_client" />
+
+</LinearLayout>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+
+ <Button
+ android:id="@+id/btn_discovery"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_alignParentTop="true"
+ android:onClick="onDiscoverResourceClick"
+ android:text="@string/discover_resource" />
+
+ <ListView
+ android:id="@+id/list_menu"
+ android:layout_width="match_parent"
+ android:layout_height="0dp"
+ android:layout_weight="1"
+ android:visibility="invisible" />
+
+ <TextView
+ android:id="@+id/text_log"
+ android:layout_width="fill_parent"
+ android:layout_height="150dp"
+ android:layout_marginLeft="10dp"
+ android:layout_marginTop="10dp"
+ android:ems="10" />
+</LinearLayout>
--- /dev/null
+<?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"
+ android:inputType="numberDecimal" />
+
+</RelativeLayout>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <style name="AppTheme" parent="android:Theme.Material.Light">
+ </style>
+</resources>
--- /dev/null
+<resources>
+ <string name="app_name">RESampleClientApp</string>
+
+ <string name="resource_client">Resource Client</string>
+ <string name="container_resource">Discover Container Resource</string>
+
+ <string name="discover_resource">Discover Resource</string>
+ <string name="cancel_discovery">Cancel Discovery</string>
+
+</resources>
--- /dev/null
+<resources>
+
+ <!-- Base application theme. -->
+ <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
+ <!-- Customize your theme here. -->
+ </style>
+
+</resources>
--- /dev/null
+// Top-level build file where you can add configuration options common to all sub-projects/modules.
+
+buildscript {
+ repositories {
+ jcenter()
+ }
+ dependencies {
+ classpath 'com.android.tools.build:gradle:1.3.0'
+
+ // NOTE: Do not place your application dependencies here; they belong
+ // in the individual module build.gradle files
+ }
+}
+
+allprojects {
+ repositories {
+ jcenter()
+
+ flatDir {
+ dirs 'libs'
+ }
+ }
+}
--- /dev/null
+include ':app'
--- /dev/null
+.gradle
+/local.properties
+/.idea
+.DS_Store
+/build
+/captures
+/gradle
--- /dev/null
+To build the app
+
+1. build Iotivity with TARGET_OS=android
+
+2. Copy aar files into app/libs folder
+ - {Iotivity_root}/android/android_api/base/build/outputs/aar/iotivity-{TARGET_ARCH}-base-{MODE}.aar
+ - {Iotivity_root}/service/resource-encapsulation/android/service/build/outputs/aar/iotivity-{TARGET_ARCH}-service-{MODE}.aar
+
+3. Configure dependencies for libs in app/build.gradle
+ - default TARGET_ARCH is armeabi
+ - default MODE is release
+
+ for example, if you build Iotivity as follows,
+
+ $scons TARGET_OS=android TARGET_ARCH=x86 RELEASE=0
+
+ then, dependencies should be modified like below
+
+ dependencies {
+ compile(name:'iotivity-x86-service-debug', ext:'aar')
+ compile(name:'iotivity-x86-base-debug', ext:'aar')
+ }
+
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<module external.linked.project.id="RESampleServerApp" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
+ <component name="FacetManager">
+ <facet type="java-gradle" name="Java-Gradle">
+ <configuration>
+ <option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
+ <option name="BUILDABLE" value="false" />
+ </configuration>
+ </facet>
+ </component>
+ <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="true">
+ <exclude-output />
+ <content url="file://$MODULE_DIR$">
+ <excludeFolder url="file://$MODULE_DIR$/.gradle" />
+ </content>
+ <orderEntry type="inheritedJdk" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ </component>
+</module>
\ No newline at end of file
--- /dev/null
+/build
+/libs/*
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="RESampleServerApp" 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=":app" />
+ </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="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugAndroidTest" />
+ <option name="COMPILE_JAVA_TEST_TASK_NAME" value="compileDebugAndroidTestSources" />
+ <afterSyncTasks>
+ <task>generateDebugAndroidTestSources</task>
+ <task>generateDebugSources</task>
+ </afterSyncTasks>
+ <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" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
+ <output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
+ <output-test url="file://$MODULE_DIR$/build/intermediates/classes/androidTest/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/resValues/debug" type="java-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/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/exploded-aar/iotivity-armeabi-base-release/jars" />
+ <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/iotivity-armeabi-service-release/jars" />
+ <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 21 Platform" jdkType="Android SDK" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ <orderEntry type="library" exported="" name="iotivity-armeabi-base-release-" level="project" />
+ <orderEntry type="library" exported="" name="iotivity-armeabi-service-release-" level="project" />
+ </component>
+</module>
\ No newline at end of file
--- /dev/null
+apply plugin: 'com.android.application'
+
+android {
+ compileSdkVersion 21
+ buildToolsVersion "21.1.2"
+
+ defaultConfig {
+ applicationId "org.iotivity.service.sample.server"
+ minSdkVersion 21
+ targetSdkVersion 21
+ versionCode 1
+ versionName "1.0"
+ }
+ buildTypes {
+ release {
+ minifyEnabled false
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
+ }
+ }
+}
+
+dependencies {
+ compile fileTree(dir: 'libs', include: ['*.jar'])
+
+ compile(name:'iotivity-armeabi-service-release', ext:'aar')
+ compile(name:'iotivity-armeabi-base-release', ext:'aar')
+}
--- /dev/null
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in C:\Android/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 *;
+#}
--- /dev/null
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="org.iotivity.service.sample.server">
+
+ <uses-permission android:name="android.permission.INTERNET" />
+ <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
+
+ <application android:allowBackup="true" android:label="@string/app_name"
+ android:icon="@mipmap/ic_launcher" android:theme="@style/AppTheme">
+
+ <activity
+ android:name=".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=".SimpleServerActivity" />
+ <activity android:name=".CustomServerActivity" />
+ </application>
+
+</manifest>
--- /dev/null
+/******************************************************************
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ * <p>
+ * <p>
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.service.sample.server;
+
+import java.lang.ref.WeakReference;
+
+import org.iotivity.service.RcsException;
+import org.iotivity.service.RcsResourceAttributes;
+import org.iotivity.service.RcsValue;
+import org.iotivity.service.server.RcsGetResponse;
+import org.iotivity.service.server.RcsRequest;
+import org.iotivity.service.server.RcsResourceObject;
+import org.iotivity.service.server.RcsResourceObject.GetRequestHandler;
+import org.iotivity.service.server.RcsResourceObject.OnAttributeUpdatedListener;
+import org.iotivity.service.server.RcsResourceObject.SetRequestHandler;
+import org.iotivity.service.server.RcsSetResponse;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.DialogInterface;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.util.Log;
+import android.view.View;
+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.TextView;
+import android.widget.Toast;
+
+public class CustomServerActivity extends Activity
+ implements OnItemClickListener {
+ private static final String LOG_TAG = CustomServerActivity.class
+ .getSimpleName();
+
+ private static final int MSG_ID_PRINT_LOG = 0;
+
+ private Handler mHandler;
+
+ private ListView mListView;
+ private TextView mLogView;
+ private ArrayAdapter<Item> mItemAdapter;
+
+ private RcsResourceObject mResourceObject;
+
+ private GetRequestHandler mGetRequestHandler = new GetRequestHandler() {
+ @Override
+ public RcsGetResponse onGetRequested(RcsRequest request,
+ RcsResourceAttributes attrs) {
+ mHandler.obtainMessage(MSG_ID_PRINT_LOG,
+ "Got a Get request from client, send default response \n"
+ + "URI : " + request.getResourceUri() + "\n")
+ .sendToTarget();
+
+ return RcsGetResponse.defaultAction();
+ }
+ };
+
+ private Item mGetRequestHandlerItem = new ToggleItem(
+ R.string.register_get_request_handler,
+ R.string.unregister_get_request_handler) {
+
+ @Override
+ public void execute() throws RcsException {
+ if (isChecked()) {
+ mResourceObject.setGetRequestHandler(null);
+ } else {
+ mResourceObject.setGetRequestHandler(mGetRequestHandler);
+ }
+ toggle();
+ }
+ };
+
+ private SetRequestHandler mSetRequestHandler = new SetRequestHandler() {
+ @Override
+ public RcsSetResponse onSetRequested(RcsRequest request,
+ RcsResourceAttributes attrs) {
+ mHandler.obtainMessage(MSG_ID_PRINT_LOG,
+ "Got a Set request from client, send default response\n"
+ + "URI : " + request.getResourceUri() + "\n")
+ .sendToTarget();
+
+ return RcsSetResponse.defaultAction();
+ }
+ };
+
+ private Item mSetRequestHandlerItem = new ToggleItem(
+ R.string.register_set_request_handler,
+ R.string.unregister_set_request_handler) {
+
+ @Override
+ public void execute() throws RcsException {
+ if (isChecked()) {
+ mResourceObject.setSetRequestHandler(null);
+ } else {
+ mResourceObject.setSetRequestHandler(mSetRequestHandler);
+ }
+ toggle();
+ }
+ };
+
+ private OnAttributeUpdatedListener mOnAttributeUpdatedListener = new OnAttributeUpdatedListener() {
+ @Override
+ public void onAttributeUpdated(RcsValue oldValue, RcsValue newValue) {
+ mHandler.obtainMessage(MSG_ID_PRINT_LOG,
+ "attributes updated\n" + "oldValue : " + oldValue
+ + ", newValue : " + newValue + "\n")
+ .sendToTarget();
+ }
+ };
+
+ private Item mAttributeUpdatedListenerItem = new ToggleItem(
+ R.string.register_attribute_updated_listener,
+ R.string.unregister_attribute_updated_listener) {
+
+ @Override
+ public void execute() throws RcsException {
+ if (isChecked()) {
+ mResourceObject.removeAttributeUpdatedListener(
+ ResourceProperties.ATTR_KEY_TEMPERATURE);
+ } else {
+ mResourceObject.addAttributeUpdatedListener(
+ ResourceProperties.ATTR_KEY_TEMPERATURE,
+ mOnAttributeUpdatedListener);
+ }
+ toggle();
+ }
+ };
+ private Item mSetTempItem = new Item() {
+
+ @Override
+ public String toString() {
+ return getString(R.string.set_temp);
+ }
+
+ @Override
+ public void execute() throws RcsException {
+ showInputValueDialog();
+ }
+ };
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_custom_server);
+
+ mHandler = new LocalHandler(this);
+
+ mLogView = (TextView) findViewById(R.id.text_log);
+ mListView = (ListView) findViewById(R.id.list_menu);
+
+ initMenuList();
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+
+ if (mResourceObject != null)
+ mResourceObject.destroy();
+ }
+
+ private void initMenuList() {
+ // the items that will be displayed on the UI.
+ Item[] items = new Item[] { mSetTempItem, mGetRequestHandlerItem,
+ mSetRequestHandlerItem, mAttributeUpdatedListenerItem };
+
+ mItemAdapter = new ArrayAdapter<>(this,
+ android.R.layout.simple_list_item_1, items);
+ mListView.setAdapter(mItemAdapter);
+
+ mListView.setOnItemClickListener(this);
+ }
+
+ @Override
+ public void onItemClick(AdapterView<?> parent, View view, int position,
+ long id) {
+ try {
+ mItemAdapter.getItem(position).execute();
+ mItemAdapter.notifyDataSetChanged();
+ } catch (RcsException e) {
+ showError(e.getMessage());
+ }
+ }
+
+ public void onStartServerClick(View v) {
+ Button btn = (Button) v;
+ if (mResourceObject == null) {
+ RcsResourceAttributes attrs = new RcsResourceAttributes();
+ attrs.put(ResourceProperties.ATTR_KEY_TEMPERATURE, 10);
+
+ mResourceObject = new RcsResourceObject.Builder(
+ ResourceProperties.URI, ResourceProperties.TYPE,
+ ResourceProperties.INTERFACE).setAttributes(attrs).build();
+
+ btn.setText(R.string.stop_server);
+ mListView.setVisibility(View.VISIBLE);
+ mLogView.setText("Resource created successfully");
+ } else {
+ mResourceObject.destroy();
+ mResourceObject = null;
+
+ btn.setText(R.string.start_server);
+ mListView.setVisibility(View.INVISIBLE);
+ mLogView.setText("Resource stopped successfully");
+ }
+ }
+
+ private void showInputValueDialog() {
+ final AlertDialog dialog = new AlertDialog.Builder(this)
+ .setTitle("Enter the Temperature Value")
+ .setView(R.layout.dialog_content_edit_text)
+ .setNegativeButton("Cancel", null).create();
+
+ dialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK",
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialogInterface,
+ int which) {
+
+ EditText editText = (EditText) dialog
+ .findViewById(R.id.edit_text);
+
+ try {
+ RcsValue value = new RcsValue(Integer
+ .parseInt(editText.getText().toString()));
+
+ mResourceObject.setAttribute(
+ ResourceProperties.ATTR_KEY_TEMPERATURE,
+ value);
+ printLog(
+ "Attribute set successfully\nTemperature : "
+ + value);
+ } catch (NumberFormatException e) {
+ showError("Please enter the Integer Value");
+ } catch (RcsException e) {
+ printLog(e);
+ }
+ }
+ });
+ dialog.show();
+ }
+
+ private void showError(String message) {
+ Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
+ Log.i(LOG_TAG, message);
+ }
+
+ private void printLog(String msg) {
+ mLogView.setText(msg);
+ Log.i(LOG_TAG, msg);
+ }
+
+ private void printLog(Exception e) {
+ mLogView.setText(e.getMessage());
+ Log.i(LOG_TAG, e.getMessage(), e);
+ }
+
+ private interface Item {
+ void execute() throws RcsException;
+ }
+
+ private static class LocalHandler extends Handler {
+ private WeakReference<CustomServerActivity> mActivityRef;
+
+ private LocalHandler(CustomServerActivity activity) {
+ mActivityRef = new WeakReference<>(activity);
+ }
+
+ @Override
+ public void handleMessage(Message msg) {
+ super.handleMessage(msg);
+
+ CustomServerActivity activity = mActivityRef.get();
+ if (activity == null)
+ return;
+
+ switch (msg.what) {
+ case MSG_ID_PRINT_LOG:
+ activity.printLog(msg.obj.toString());
+ break;
+ }
+ }
+ }
+
+ private abstract class ToggleItem implements Item {
+ private int mUncheckedStrId;
+ private int mCheckedStrId;
+
+ private boolean mIsChecked;
+
+ public ToggleItem(int uncheckedStrId, int checkedStrId) {
+ mUncheckedStrId = uncheckedStrId;
+ mCheckedStrId = checkedStrId;
+ }
+
+ @Override
+ public String toString() {
+ return getString(mIsChecked ? mCheckedStrId : mUncheckedStrId);
+ }
+
+ protected final boolean isChecked() {
+ return mIsChecked;
+ }
+
+ public final void toggle() {
+ mIsChecked = !mIsChecked;
+ }
+ }
+}
--- /dev/null
+/******************************************************************
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ * <p>
+ * <p>
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.service.sample.server;
+
+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 android.app.Activity;
+import android.app.AlertDialog;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.net.ConnectivityManager;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.View;
+
+/**
+ * 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 final String LOG_TAG = MainActivity.class.getSimpleName();
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_main);
+
+ if (!isWifiConnected()) {
+ showWifiUnavailableDialog();
+ return;
+ }
+
+ configurePlatform();
+ }
+
+ public void onSimpleServerBtnClick(View v) {
+ startActivity(new Intent(this, SimpleServerActivity.class));
+ }
+
+ public void onCustomServerBtnClick(View v) {
+ startActivity(new Intent(this, CustomServerActivity.class));
+ }
+
+ private void showWifiUnavailableDialog() {
+ new AlertDialog.Builder(this).setTitle("Error")
+ .setMessage(
+ "WiFi is not enabled/connected! Please connect the WiFi and start application again...")
+ .setCancelable(false)
+ .setPositiveButton("OK", new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ finish();
+ }
+ }).create().show();
+ }
+
+ private boolean isWifiConnected() {
+ ConnectivityManager connManager = (ConnectivityManager) getSystemService(
+ CONNECTIVITY_SERVICE);
+ return connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
+ .isConnected();
+ }
+
+ private void configurePlatform() {
+ OcPlatform.Configure(new PlatformConfig(getApplicationContext(),
+ ServiceType.IN_PROC, ModeType.CLIENT_SERVER, "0.0.0.0", 0,
+ QualityOfService.LOW));
+ Log.i(LOG_TAG, "Configuration done successfully");
+ }
+}
\ No newline at end of file
--- /dev/null
+/******************************************************************
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ * <p>
+ * <p>
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.service.sample.server;
+
+public class ResourceProperties {
+ public static final String URI = "/a/TempSensor";
+ public static final String TYPE = "oic.r.temperature.sensor";
+ public static final String INTERFACE = "oic.if.";
+
+ public static final String ATTR_KEY_TEMPERATURE = "Temperature";
+}
--- /dev/null
+/******************************************************************
+ * Copyright 2015 Samsung Electronics All Rights Reserved.
+ * <p/>
+ * <p/>
+ * <p/>
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.service.sample.server;
+
+import org.iotivity.service.RcsException;
+import org.iotivity.service.RcsResourceAttributes;
+import org.iotivity.service.RcsValue;
+import org.iotivity.service.server.RcsResourceObject;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.DialogInterface;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.View;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.TextView;
+import android.widget.Toast;
+
+/**
+ * Activity for handling user's selection on UI for changing temperature. & for
+ * updating UI.
+ */
+public class SimpleServerActivity extends Activity {
+
+ private static final String LOG_TAG = SimpleServerActivity.class
+ .getSimpleName();
+
+ private TextView mLogView;
+ private RcsResourceObject mResourceObject;
+ private View mSetTempBtn;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_simple_server);
+
+ mLogView = (TextView) findViewById(R.id.text_log);
+ mSetTempBtn = findViewById(R.id.btn_set_temp);
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+
+ if (mResourceObject != null)
+ mResourceObject.destroy();
+ }
+
+ public void onStartServerClick(View v) {
+ Button btn = (Button) v;
+ if (mResourceObject == null) {
+ RcsResourceAttributes attrs = new RcsResourceAttributes();
+ attrs.put(ResourceProperties.ATTR_KEY_TEMPERATURE, 10);
+
+ mResourceObject = new RcsResourceObject.Builder(
+ ResourceProperties.URI, ResourceProperties.TYPE,
+ ResourceProperties.INTERFACE).setAttributes(attrs).build();
+
+ btn.setText(R.string.stop_server);
+ mSetTempBtn.setEnabled(true);
+ } else {
+ mResourceObject.destroy();
+ mResourceObject = null;
+
+ btn.setText(R.string.start_server);
+ mSetTempBtn.setEnabled(false);
+ }
+ }
+
+ public void onSetTempClick(View v) {
+ showInputValueDialog();
+ }
+
+ private void showInputValueDialog() {
+ final AlertDialog dialog = new AlertDialog.Builder(this)
+ .setTitle("Enter the Temperature Value")
+ .setView(R.layout.dialog_content_edit_text)
+ .setNegativeButton("Cancel", null).create();
+
+ dialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK",
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialogInterface,
+ int which) {
+
+ EditText editText = (EditText) dialog
+ .findViewById(R.id.edit_text);
+
+ try {
+ RcsValue value = new RcsValue(Integer
+ .parseInt(editText.getText().toString()));
+
+ mResourceObject.setAttribute(
+ ResourceProperties.ATTR_KEY_TEMPERATURE,
+ value);
+ printLog(
+ "Attribute set successfully\nTemperature : "
+ + value);
+ } catch (NumberFormatException e) {
+ showError("Please enter the Integer Value");
+ } catch (RcsException e) {
+ printLog(e);
+ }
+ }
+ });
+ dialog.show();
+ }
+
+ private void showError(String message) {
+ Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
+ Log.i(LOG_TAG, message);
+ }
+
+ private void printLog(String msg) {
+ Log.e(LOG_TAG, msg);
+ mLogView.setText(msg);
+ }
+
+ private void printLog(Exception e) {
+ Log.e(LOG_TAG, e.getMessage(), e);
+ mLogView.setText(e.getMessage());
+ }
+}
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+
+ <Button
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:onClick="onStartServerClick"
+ android:text="@string/start_server" />
+
+ <ListView
+ android:id="@+id/list_menu"
+ android:layout_width="match_parent"
+ android:layout_height="0dp"
+ android:layout_weight="1"
+ android:visibility="invisible" />
+
+ <TextView
+ android:id="@+id/text_log"
+ android:layout_width="fill_parent"
+ android:layout_height="250dp"
+ android:layout_marginTop="15dp"
+ android:ems="10" />
+
+</LinearLayout>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+
+ <Button
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/simple_sever"
+ android:onClick="onSimpleServerBtnClick" />
+
+ <Button
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/custom_sever"
+ android:onClick="onCustomServerBtnClick" />
+
+</LinearLayout>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+
+ <Button
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:onClick="onStartServerClick"
+ android:text="@string/start_server" />
+
+ <Button
+ android:id="@+id/btn_set_temp"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:enabled="false"
+ android:onClick="onSetTempClick"
+ android:text="@string/set_temp" />
+
+ <TextView
+ android:id="@+id/text_log"
+ android:layout_width="fill_parent"
+ android:layout_height="250dp"
+ android:layout_marginTop="15dp"
+ android:ems="10" />
+
+</LinearLayout>
\ No newline at end of file
--- /dev/null
+<?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/edit_text"
+ 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"
+ android:inputType="numberDecimal" />
+
+</RelativeLayout>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <style name="AppTheme" parent="android:Theme.Material.Light">
+ </style>
+</resources>
--- /dev/null
+<resources>
+ <string name="app_name">RESampleServerApp</string>
+
+ <string name="start_server">Start</string>
+ <string name="stop_server">Stop Server</string>
+
+ <string name="set_temp">Set Temperature</string>
+
+ <string name="simple_sever">Simple Server</string>
+ <string name="custom_sever">Custom Server</string>
+
+ <string name="register_get_request_handler">Register GetRequestHandler</string>
+ <string name="unregister_get_request_handler">Unregister GetRequestHandler</string>
+
+ <string name="register_set_request_handler">Register SetRequestHandler</string>
+ <string name="unregister_set_request_handler">Unregister SetRequestHandler</string>
+
+ <string name="register_attribute_updated_listener">Register AttributeUpdatedListener</string>
+ <string name="unregister_attribute_updated_listener">Unregister AttributeUpdatedListener</string>
+</resources>
--- /dev/null
+<resources>
+
+ <!-- Base application theme. -->
+ <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
+ <!-- Customize your theme here. -->
+ </style>
+
+</resources>
--- /dev/null
+// Top-level build file where you can add configuration options common to all sub-projects/modules.
+
+buildscript {
+ repositories {
+ jcenter()
+ }
+ dependencies {
+ classpath 'com.android.tools.build:gradle:1.3.0'
+
+ // NOTE: Do not place your application dependencies here; they belong
+ // in the individual module build.gradle files
+ }
+}
+
+allprojects {
+ repositories {
+ jcenter()
+
+ flatDir {
+ dirs 'libs'
+ }
+ }
+}
--- /dev/null
+include ':app'
+++ /dev/null
-<?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 kind="src" path="src"/>
- <classpathentry kind="src" path="gen"/>
- <classpathentry kind="output" path="bin/classes"/>
-</classpath>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>REServer</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>
+++ /dev/null
-<?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" />
- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
-
- <application
- android:allowBackup="true"
- android:icon="@drawable/iot"
- 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
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
- <container>
- <bundle>
- <id>oic.bundle.discomfortIndexSensor</id>
- <path>data/data/com.example.sampleresourceserver/files/libDISensorBundle.so</path>
- <version>1.0.0</version>
- <resources>
- <resourceInfo>
- <name>DiscomfortIndexSensor1</name>
- <resourceType>oic.softsensor</resourceType>
- <outputs>
- <output>
- <name>discomfortIndex</name>
- <type>int</type>
- </output>
- <output>
- <name>humidity</name>
- <type>double</type>
- </output>
- <output>
- <name>temperature</name>
- <type>double</type>
- </output>
- </outputs>
- <inputs>
- <input>
- <name>humidity</name>
- <type>double</type>
- <resourceType>oic.sensor.humidity</resourceType>
- </input>
- <input>
- <name>temperature</name>
- <type>double</type>
- <resourceType>oic.sensor.temperature</resourceType>
- </input>
- </inputs>
- </resourceInfo>
- </resources>
- </bundle>
-</container>
+++ /dev/null
-# 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
+++ /dev/null
-<?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
+++ /dev/null
-<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical"
- android:padding="8dp" >
-
- <TextView
- android:id="@+id/ListHead"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft"
- android:textSize="20dp" />
-
-</LinearLayout>
\ No newline at end of file
+++ /dev/null
-<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="55dip"
- android:orientation="vertical" >
-
- <TextView
- android:id="@+id/listItem"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:paddingBottom="5dp"
- android:paddingLeft="?android:attr/expandableListPreferredChildPaddingLeft"
- android:paddingTop="5dp"
- android:textSize="20dip" />
-
-</LinearLayout>
\ No newline at end of file
+++ /dev/null
-<?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" />
-
- <ExpandableListView
- android:id="@+id/lvExp"
- android:layout_width="match_parent"
- android:layout_height="300dp"
- android:layout_below="@id/startContainer" />
-
- <Button
- android:id="@+id/listBundles"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentRight="true"
- android:layout_alignParentTop="true"
- android:text="List Bundles" />
-
- <EditText
- android:id="@+id/log"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_alignParentBottom="true"
- android:layout_alignParentLeft="true"
- android:layout_below="@id/lvExp"
- android:editable="false"
- android:ems="10" />
-
-</RelativeLayout>
+++ /dev/null
-<?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_width="match_parent"
- android:layout_height="wrap_content" >
- </ListView>
-
-</RelativeLayout>
\ No newline at end of file
+++ /dev/null
-<?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
+++ /dev/null
-<?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
+++ /dev/null
-<?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>
+++ /dev/null
-<menu xmlns:android="http://schemas.android.com/apk/res/android" >
- <item
- android:id="@+id/re_server"
- android:orderInCategory="100"
- android:showAsAction="never"
- android:title="@string/re_server"/>
-</menu>
\ No newline at end of file
+++ /dev/null
-<resources>
-
- <style name="AppBaseTheme" parent="android:Theme.Holo.Light">
- </style>
-
-</resources>
+++ /dev/null
- <resources>
-
- <style name="AppBaseTheme" parent="android:Theme.Light">
- </style>
-
- <style name="AppTheme" parent="AppBaseTheme">
- </style>
-
-</resources>
+++ /dev/null
-<resources>
- <dimen name="activity_horizontal_margin">64dp</dimen>
-</resources>
+++ /dev/null
-<resources>
- <dimen name="activity_horizontal_margin">16dp</dimen>
- <dimen name="activity_vertical_margin">16dp</dimen>
-</resources>
+++ /dev/null
-<?xml version="1.0" encoding="utf-8"?>
-<resources>
- <string name="app_name">REServer</string>
- <string name="hello_world">RE Server!</string>
- <string name="re_server">RE_SERVER</string>
-</resources>
+++ /dev/null
-<resources>
-
- <style name="AppBaseTheme" parent="android:Theme.Light">
-
- </style>
-
- <!-- Application theme. -->
- <style name="AppTheme" parent="AppBaseTheme">
-
- </style>
-
-</resources>
+++ /dev/null
-/******************************************************************
- *
- * 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.FileOutputStream;
-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 Context context;
- 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;
- context = 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");
- apisList.add("Resource Container");
- 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 all the files from assets folder to SDcard
- CopyAssetsToSDCard();
- }
-
- private void CopyAssetsToSDCard() {
- AssetManager assetManager = getAssets();
- String[] files = null;
- try {
- files = assetManager.list("lib");
- } catch (IOException e) {
- Log.e(LOG_TAG, e.getMessage());
- }
-
- for (String filename : files) {
- InputStream in = null;
- OutputStream out = null;
- try {
- in = assetManager.open("lib/" + filename);
- out = new FileOutputStream(context.getFilesDir().getParent()
- + "/files/" + filename);
- copyIndividualFile(in, out);
- in.close();
- in = null;
- out.flush();
- out.close();
- out = null;
- } catch (Exception e) {
- Log.e(LOG_TAG, e.getMessage());
- }
- }
- }
-
- private void copyIndividualFile(InputStream in, OutputStream out)
- throws IOException {
-
- Log.i(LOG_TAG, "copyIndividualFile");
- byte[] buffer = new byte[2048];
- int read;
- while ((read = in.read(buffer)) != -1) {
- out.write(buffer, 0, read);
- }
- }
-
- @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
+++ /dev/null
-/******************************************************************
- *
- * 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;
- public static boolean startBundleFlag;
- public static boolean isStarted = false;
- public static boolean isInitialized = false;
-
- // constructor
- public ResourceContainer() {
- resourceContainerActivityInstance = ResourceContainerActivity
- .getResourceContainerActivityObj();
- containerInstance = RCSResourceContainer.getInstance();
- }
-
- // Start Container
- public void startContainer(String sdCardPath) {
-
- String configFile = sdCardPath + "/ResourceContainerConfig.xml";
- if (!isStarted && !isInitialized) {
- for (int i = 0; i < 2; i++) {
- containerInstance.startContainer(configFile);
- }
- isStarted = true;
- isInitialized = true;
- } else {
- containerInstance.startContainer(configFile);
- isStarted = true;
- }
-
- logMessage = "Container Started";
- logMessage += "with one Bundle" + "\n";
- logMessage += "ID : oic.bundle.discomfortIndexSensor";
-
- 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() {
-
- if (isStarted) {
- containerInstance.stopContainer();
- logMessage = "Container stopped";
- isStarted = false;
- ResourceContainerActivity.setMessageLog(logMessage);
- msg = Message.obtain();
- msg.what = 1;
- resourceContainerActivityInstance.getHandler().sendMessage(msg);
- }
- }
-
- // List Bundle Resources DI
- public void listBundleResourcesDI() {
-
- List<String> bundleResources = containerInstance
- .listBundleResources("oic.bundle.discomfortIndexSensor");
-
- Iterator<String> it = bundleResources.iterator();
- logMessage = "";
-
- if (0 == bundleResources.size()) {
- logMessage += "No resource found in the bundle" + "\n";
- } else {
- while (it.hasNext()) {
- String element = (String) it.next();
- logMessage += element + "\n";
- }
- }
- ResourceContainerActivity.setMessageLog(logMessage);
- msg = Message.obtain();
- msg.what = 1;
- resourceContainerActivityInstance.getHandler().sendMessage(msg);
- }
-
- // List Bundle Resources BMI
- public void listBundleResourcesBMI() {
-
- List<String> bundleResources = containerInstance
- .listBundleResources("oic.bundle.BMISensor");
- Iterator<String> it = bundleResources.iterator();
- logMessage = "";
-
- if (0 == bundleResources.size()) {
- logMessage += "No resource found in the bundle" + "\n";
- } else {
- while (it.hasNext()) {
- String element = (String) it.next();
- logMessage += element + "\n";
- }
- }
- ResourceContainerActivity.setMessageLog(logMessage);
- msg = Message.obtain();
- msg.what = 1;
- resourceContainerActivityInstance.getHandler().sendMessage(msg);
- }
-
- // List Bundles
- public void listBundles() {
-
- List<RCSBundleInfo> bundleList = containerInstance.listBundles();
- Iterator<RCSBundleInfo> it = bundleList.iterator();
- int i = 0;
- logMessage = "";
- logMessage += "size of bundleList : " + bundleList.size() + "\n\n";
-
- while (it.hasNext()) {
- i++;
- RCSBundleInfo object = (RCSBundleInfo) it.next();
- logMessage += "Bundle : " + i + " -: \n";
- logMessage += "ID : " + object.getID() + "\n";
- logMessage += "Lib Path: " + object.getPath() + "\n";
- if (!(object.getVersion().equalsIgnoreCase("")))
- logMessage += "version : " + object.getVersion() + "\n\n";
- else
- logMessage += "\n";
- }
- ResourceContainerActivity.setMessageLog(logMessage);
- msg = Message.obtain();
- msg.what = 1;
- resourceContainerActivityInstance.getHandler().sendMessage(msg);
- }
-
- // Add Bundle BMI
- public void addBundleBMI() {
-
- Map<String, String> bundleParams = null;
- List<RCSBundleInfo> bundleList = containerInstance.listBundles();
- if (1 < bundleList.size()) {
- logMessage = "Bundle already added" + "\n";
- } else {
- for (int i = 0; i < 2; i++) {
- containerInstance
- .addBundle(
- "oic.bundle.BMISensor",
- "xyz",
- "data/data/com.example.sampleresourceserver/files/libBMISensorBundle.so",
- bundleParams);
- }
-
- logMessage = "bundle to add : " + "\n";
- logMessage += "ID :" + "oic.bundle.BMISensor" + "\n";
- logMessage += "Uri: " + "xyz" + "\n";
- logMessage += "Path : "
- + "data/data/com.re.sampleclient/files/libBMISensorBundle.so"
- + "\n";
- logMessage += "bundle added successfully" + "\n";
- }
-
- ResourceContainerActivity.setMessageLog(logMessage);
- msg = Message.obtain();
- msg.what = 1;
- resourceContainerActivityInstance.getHandler().sendMessage(msg);
- }
-
- // Remove Bundle BMI
- public void removeBundleBMI() {
-
- List<RCSBundleInfo> bundleList = containerInstance.listBundles();
- if (1 == bundleList.size()) {
- logMessage = "Bundle already removed" + "\n";
- } else {
-
- for (int i = 0; i < 2; i++) {
- containerInstance.removeBundle("oic.bundle.BMISensor");
- }
- startBundleFlag = false;
- logMessage = "bundle to remove : " + "\n";
- logMessage += "ID :" + "oic.bundle.BMISensor" + "\n";
- logMessage += " bundle removed successfully" + "\n";
- }
- ResourceContainerActivity.setMessageLog(logMessage);
- msg = Message.obtain();
- msg.what = 1;
- resourceContainerActivityInstance.getHandler().sendMessage(msg);
- }
-
- // Start Bundle BMI
- public void startBundleBMI() {
-
- List<RCSBundleInfo> bundleList = containerInstance.listBundles();
- if (1 == bundleList.size()) {
- logMessage = "BMI bundle not added" + "\n";
- } else if (true == startBundleFlag) {
- logMessage = "Bundle already started" + "\n";
- } else {
- startBundleFlag = true;
- containerInstance.startBundle("oic.bundle.BMISensor");
-
- logMessage = " bundle to start" + "\n";
- logMessage += " ID : oic.bundle.BMISensor" + "\n";
- logMessage += " bundle started successfully" + "\n";
- }
- ResourceContainerActivity.setMessageLog(logMessage);
- msg = Message.obtain();
- msg.what = 1;
- resourceContainerActivityInstance.getHandler().sendMessage(msg);
- }
-
- // Stop Bundle BMI
- public void stopBundleBMI() {
-
- if (false == startBundleFlag) {
- logMessage = "Bundle is not Started" + "\n";
- } else {
- List<RCSBundleInfo> bundleList = containerInstance.listBundles();
- if (0 == bundleList.size()) {
- logMessage = "No bundle to Stop" + "\n";
- } else {
- containerInstance.stopBundle("oic.bundle.BMISensor");
- startBundleFlag = false;
- logMessage = " bundle to stop" + "\n";
- logMessage += " ID : oic.bundle.BMISensor" + "\n";
- logMessage += " bundle stopped successfully" + "\n";
- }
- }
-
- ResourceContainerActivity.setMessageLog(logMessage);
- msg = Message.obtain();
- msg.what = 1;
- resourceContainerActivityInstance.getHandler().sendMessage(msg);
- }
-
- // Add Resource Configuration to DI bundle
- public void addResourceConfigDI() {
-
- List<RCSBundleInfo> bundleList = containerInstance.listBundles();
- List<String> bundleResources = containerInstance
- .listBundleResources("oic.bundle.discomfortIndexSensor");
-
- if (0 == bundleList.size()) {
- logMessage = "No bundle found" + "\n";
- } else if ((0 == bundleList.size()) && (0 == bundleResources.size())) {
- logMessage = "No bundle found" + "\n";
- } else {
- Map<String, String> params = new HashMap<String, String>();
- params.put("resourceType", "oic.softsensor");
- params.put("address",
- "http://192.168.0.2/api/newdeveloper/sensor/22");
- containerInstance.addResourceConfig(
- "oic.bundle.discomfortIndexSensor", "", params);
- logMessage = "resource added successfully" + "\n";
- }
- ResourceContainerActivity.setMessageLog(logMessage);
- msg = Message.obtain();
- msg.what = 1;
- resourceContainerActivityInstance.getHandler().sendMessage(msg);
- }
-
- // Add Resource Configuration to BMI bundle
- public void addResourceConfigBMI() {
-
- if (false == startBundleFlag) {
- logMessage = "Bundle is not started" + "\n";
- } else {
- List<RCSBundleInfo> bundleList = containerInstance.listBundles();
- List<String> bundleResources = containerInstance
- .listBundleResources("oic.bundle.BMISensor");
-
- if (0 == bundleList.size()) {
- logMessage = "No bundle found" + "\n";
- } else if ((0 == bundleList.size())
- && (0 == bundleResources.size())) {
- logMessage = "No bundle found" + "\n";
- } else {
- Map<String, String> params = new HashMap<String, String>();
- params.put("resourceType", "oic.softsensor");
- params.put("address",
- "http://192.168.0.2/api/newdeveloper/sensor/22");
- containerInstance.addResourceConfig("oic.bundle.BMISensor", "",
- params);
- logMessage = "resource added successfully" + "\n";
- }
- }
- ResourceContainerActivity.setMessageLog(logMessage);
- msg = Message.obtain();
- msg.what = 1;
- resourceContainerActivityInstance.getHandler().sendMessage(msg);
- }
-
- // Remove Resource Configuration from DI Bundle
- public void removeResourceConfigDI() {
-
- 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);
- }
- }
-
- // Remove Resource Configuration from BMI Bundle
- public void removeResourceConfigBMI() {
-
- List<String> bundleResources = containerInstance
- .listBundleResources("oic.bundle.BMISensor");
- if (bundleResources.size() >= 1) {
- String element = bundleResources.get(0);
- containerInstance.removeResourceConfig("oic.bundle.BMISensor",
- element);
- Message msg;
- logMessage = "resource removed successfully: \n" + element + "\n";
- ResourceContainerActivity.setMessageLog(logMessage);
- msg = Message.obtain();
- msg.what = 1;
- resourceContainerActivityInstance.getHandler().sendMessage(msg);
- } else {
- logMessage = "No resource to remove" + "\n";
- ResourceContainerActivity.setMessageLog(logMessage);
- msg = Message.obtain();
- msg.what = 1;
- resourceContainerActivityInstance.getHandler().sendMessage(msg);
- }
- }
-}
+++ /dev/null
-/******************************************************************
- *
- * 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 java.util.HashMap;
-import java.util.List;
-
-import com.example.sampleresourceserver.*;
-
-import android.app.Activity;
-import android.content.Context;
-import android.graphics.Typeface;
-import android.os.Bundle;
-import android.os.Handler;
-import android.os.Message;
-import android.util.Log;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.view.View.OnClickListener;
-import android.widget.BaseExpandableListAdapter;
-import android.widget.Button;
-import android.widget.EditText;
-import android.widget.ExpandableListAdapter;
-import android.widget.ExpandableListView;
-import android.widget.ExpandableListView.OnChildClickListener;
-import android.widget.TextView;
-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;
-
- public ExpandableListAdapter listAdapter;
- public ExpandableListView expListView;
- public List<String> sensors;
- public List<String> diApiList;
- public List<String> bmiApiList;
- HashMap<String, List<String>> listChild;
-
- private static Handler mHandler;
- private Button startContainer;
- private Button listBundles;
- private static EditText logs;
- private static String sdCardPath;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
-
- super.onCreate(savedInstanceState);
- setContentView(R.layout.resource_container);
- resourceContainerActivityInstance = this;
- resourceContainerInstance = new ResourceContainer();
-
- expListView = (ExpandableListView) findViewById(R.id.lvExp);
- startContainer = (Button) findViewById(R.id.startContainer);
- listBundles = (Button) findViewById(R.id.listBundles);
- listBundles.setEnabled(false);
- logs = (EditText) findViewById(R.id.log);
-
- sensors = new ArrayList<String>();
- diApiList = new ArrayList<String>();
- bmiApiList = new ArrayList<String>();
- listChild = new HashMap<String, List<String>>();
-
- // Adding list items (header)
- sensors.add("Discomfort Index Sensor");
- sensors.add("BMI Sensor");
-
- // Adding child data [discomfort Index sensor]
- diApiList.add("1. List bundle resources");
- diApiList.add("2. Add Resource");
- diApiList.add("3. Remove Resource");
-
- // Adding child data [BMI sensor]
- bmiApiList.add("1. Add Bundle");
- bmiApiList.add("2. Start Bundle");
- bmiApiList.add("3. List bundle resources");
- bmiApiList.add("4. Add Resource ");
- bmiApiList.add("5. Remove Resource");
- bmiApiList.add("6. Stop Bundle");
- bmiApiList.add("7. Remove Bundle");
-
- listChild.put(sensors.get(0), diApiList);
- listChild.put(sensors.get(1), bmiApiList);
- listAdapter = new ExpandableList(this, sensors, listChild);
-
- // getting the sd card path
- sdCardPath = this.getFilesDir().getPath();
-
- // handler for updating the UI i.e. MessageLog (TextBox) & ListView
- mHandler = new Handler() {
- @Override
- public void handleMessage(Message msg) {
- switch (msg.what) {
- case 0:
- expListView.setAdapter(listAdapter);
- expListView.bringToFront();
- break;
- case 1:
- logs.setText("");
- logs.setText(logMessage);
- Log.i(LOG_TAG, logMessage);
- break;
- case 2:
- listAdapter = null;
- expListView.setAdapter(listAdapter);
- break;
- }
- }
- };
- setHandler(mHandler);
-
- // StartContainer/stopContainer Button Listener
- startContainer.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
-
- String text = (String) startContainer.getText();
- if (text.contains("Start")) {
- resourceContainerInstance.startContainer(sdCardPath);
- listAdapter = new ExpandableList(ResourceContainerActivity
- .getResourceContainerActivityObj(), sensors,
- listChild);
- listBundles.setEnabled(true);
- startContainer.setText("Stop Container");
- } else {
- resourceContainerInstance.stopContainer();
- startContainer.setText("Start Container");
- listBundles.setEnabled(false);
- Message msg;
- msg = Message.obtain();
- msg.what = 2;
- resourceContainerActivityInstance.getHandler().sendMessage(
- msg);
- }
- }
- });
-
- // List Bundles Button Listener
- listBundles.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- resourceContainerInstance.listBundles();
- }
- });
-
- // Listener for the expandable list
- expListView.setOnChildClickListener(new OnChildClickListener() {
-
- @Override
- public boolean onChildClick(ExpandableListView parent, View v,
- int groupPosition, int childPosition, long id) {
-
- if (0 == groupPosition) {
- if (childPosition == 0) {
- resourceContainerInstance.listBundleResourcesDI();
- } else if (childPosition == 1) {
- resourceContainerInstance.addResourceConfigDI();
- } else if (childPosition == 2) {
- resourceContainerInstance.removeResourceConfigDI();
- }
- } else {
- if (childPosition == 0) {
- resourceContainerInstance.addBundleBMI();
- } else if (childPosition == 1) {
- resourceContainerInstance.startBundleBMI();
- } else if (childPosition == 2) {
- resourceContainerInstance.listBundleResourcesBMI();
- } else if (childPosition == 3) {
- resourceContainerInstance.addResourceConfigBMI();
- } else if (childPosition == 4) {
- resourceContainerInstance.removeResourceConfigBMI();
- } else if (childPosition == 5) {
- resourceContainerInstance.stopBundleBMI();
- } else if (childPosition == 6) {
- resourceContainerInstance.removeBundleBMI();
- }
- }
- return false;
- }
- });
- }
-
- @Override
- public void onBackPressed() {
- listAdapter = null;
- expListView.setAdapter(listAdapter);
- resourceContainerInstance.stopContainer();
- ResourceContainer.startBundleFlag = false;
- super.onBackPressed();
- }
-
- // class for handling expandable list items
- public class ExpandableList extends BaseExpandableListAdapter {
-
- private Context mContext;
- private HashMap<String, List<String>> mListDataChild;
- private List<String> mListDataHeader;
-
- // constructor
- public ExpandableList(Context context, List<String> dataHeader,
- HashMap<String, List<String>> childData) {
- this.mContext = context;
- this.mListDataHeader = dataHeader;
- this.mListDataChild = childData;
- }
-
- // get the child ID
- @Override
- public long getChildId(int grpPosition, int childPosition) {
- return childPosition;
- }
-
- // get the child
- @Override
- public Object getChild(int grpPosition, int childPosititon) {
- return this.mListDataChild.get(
- this.mListDataHeader.get(grpPosition)).get(childPosititon);
- }
-
- // get Group View
- @Override
- public View getGroupView(int grpPosition, boolean isExpandable,
- View changeView, ViewGroup head) {
- String mainHeading = (String) getGroup(grpPosition);
- if (changeView == null) {
- LayoutInflater flater;
- flater = (LayoutInflater) this.mContext
- .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- changeView = flater.inflate(R.layout.group, null);
- }
-
- TextView listHeader = (TextView) changeView
- .findViewById(R.id.ListHead);
- listHeader.setTypeface(null, Typeface.BOLD);
- listHeader.setText(mainHeading);
- return changeView;
- }
-
- // get Children count
- @Override
- public int getChildrenCount(int grpPosition) {
- int count = this.mListDataChild.get(
- this.mListDataHeader.get(grpPosition)).size();
- return count;
- }
-
- // Get Group
- @Override
- public Object getGroup(int grpPosition) {
- return this.mListDataHeader.get(grpPosition);
- }
-
- // get Group size
- @Override
- public int getGroupCount() {
- int size = this.mListDataHeader.size();
- return size;
- }
-
- // get Group ID
- @Override
- public long getGroupId(int grpPosition) {
- return grpPosition;
- }
-
- // get Group View
- @Override
- public View getChildView(int grpPosition, final int childPosition,
- boolean isLastItem, View changeView, ViewGroup head) {
-
- final String innerText = (String) getChild(grpPosition,
- childPosition);
-
- if (changeView == null) {
- LayoutInflater flater = (LayoutInflater) this.mContext
- .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- changeView = flater.inflate(R.layout.list_item, null);
- }
-
- TextView textListChild = (TextView) changeView
- .findViewById(R.id.listItem);
-
- textListChild.setText(innerText);
- return changeView;
- }
-
- // To check whether child is selectable or not
- @Override
- public boolean isChildSelectable(int grpPosition, int childPosition) {
- return true;
- }
-
- // To check the stable IDs
- @Override
- public boolean hasStableIds() {
- return false;
- }
- }
-
- // ****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);
- }
-}
+++ /dev/null
-/******************************************************************
- *
- * 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();
- rcsResourceObject
- .setSetRequestHandlerPolicy(SetRequestHandlerPolicy.ACCEPTANCE);
- } catch (RCSException e) {
- e.printStackTrace();
- }
- }
-
- // Set Attribute
- public void setAttribute(int value) {
-
- rcsResourceObject.setAttribute("Temperature", value);
- logMessage = "Attribute set successfully" + "\n";
- 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 += "oldValue : " + oldValue + "\n";
- logMessage += "newValue : " + newValue + "\n";
- serverBuilderDevActivityInstance.setMessageLog(logMessage);
- msg = Message.obtain();
- msg.what = 0;
- serverBuilderDevActivityInstance.getHandler().sendMessage(msg);
- }
- };
-}
+++ /dev/null
-/******************************************************************
- *
- * 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();
- }
-}
+++ /dev/null
-/******************************************************************
- *
- * 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 += "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);
- }
-}
+++ /dev/null
-/******************************************************************
- *
- * 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);
- }
-}