--- /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 exported="true" kind="lib" path="E:/Projects/Mixed_backup/master_22_aug/android/android_api/base/build/intermediates/bundles/release/classes.jar"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" path="gen"/>
+ <classpathentry kind="output" path="bin/classes"/>
+</classpath>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>SampleResourceClientApp</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.ConfigurationApiActivity"
+ 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/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/action_settings"
+ android:orderInCategory="100"
+ android:showAsAction="never"
+ android:title="@string/action_settings"/>
+
+</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>
+
+ <!--
+ Example customization of dimensions originally defined in res/values/dimens.xml
+ (such as screen margins) for screens with more than 820dp of available width. This
+ would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively).
+ -->
+ <dimen name="activity_horizontal_margin">64dp</dimen>
+
+</resources>
--- /dev/null
+<resources>
+
+ <!-- Default screen margins, per the Android Design guidelines. -->
+ <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">RESampleClient</string>
+ <string name="hello_world">Hello world!</string>
+ <string name="action_settings">Settings</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.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
+ */
+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 API's");
+ 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);
+ }
+ }
+ });
+
+ // 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.ICacheUpdateListener;
+import org.iotivity.ResourceEncapsulation.client.IDiscoverResourceListener;
+import org.iotivity.ResourceEncapsulation.client.IRemoteAttributeListener;
+import org.iotivity.ResourceEncapsulation.client.IStateChangedCallbackListener;
+import org.iotivity.ResourceEncapsulation.client.RCSAddress;
+import org.iotivity.ResourceEncapsulation.client.RCSDiscoveryManager;
+import org.iotivity.ResourceEncapsulation.client.RCSRemoteResourceObject;
+
+import org.iotivity.ResourceEncapsulation.utils.CacheState;
+import org.iotivity.ResourceEncapsulation.common.RCSException;
+import org.iotivity.ResourceEncapsulation.common.RCSResourceAttributes;
+import org.iotivity.ResourceEncapsulation.utils.ResourceState;
+
+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 RemoteAttributeListener remoteAttributeListener;
+ static boolean monitoringState = false;
+ static boolean cachingState = false;
+
+ // constructor
+ public ResourceClient() {
+ discoveyManagerObj = new RCSDiscoveryManager();
+ discoverResourceListener = new DiscoverResourceListener();
+ stateChangedListener = new StateChangedListener();
+ cacheUpdateListener = new CacheUpdateListener();
+ remoteAttributeListener = new RemoteAttributeListener();
+
+ 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;
+
+ msg = Message.obtain();
+ msg.what = 0;
+ resourcClientActivityObj.getHandler().sendMessage(msg);
+
+ logMessage = "URI : " + resourceURI + "\n";
+ logMessage = logMessage + "Host : " + hostAddress + "\n";
+ for (int i = 0; i < resourceTypes.size(); i++) {
+ logMessage = logMessage + "resourceType : "
+ + resourceTypes.get(i) + "\n";
+ }
+
+ for (int i = 0; i < resourceInterfaces.size(); i++) {
+ logMessage = logMessage + "resourceInterfaces : "
+ + resourceInterfaces.get(i) + "\n";
+ }
+ logMessage = logMessage + "isObservable : " + isObservableflag
+ + "\n";
+
+ resourcClientActivityObj.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 onStateChangedCallback(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 = 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() and setRemoteAttributes() API
+ */
+ private class RemoteAttributeListener implements IRemoteAttributeListener {
+ @Override
+ public void onRemoteAttributesGetCallback(
+ RCSResourceAttributes attributes) {
+
+ Log.i(LOG_TAG, "onRemoteAttributesGetCallback invoked");
+ printAttributes(attributes);
+ }
+ };
+
+ public void disocverResources() {
+ Log.d(LOG_TAG, "discover resources entry");
+ RCSAddress address = RCSAddress.multicast();
+ discoveyManagerObj.discoverResource(address);
+ Log.d(LOG_TAG, "discover resources exit");
+ }
+
+ 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");
+ }
+
+ 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);
+ }
+
+ public void getRemoteAttributes() {
+ Log.d(LOG_TAG, "getRemoteAttributes entry");
+
+ if (null == remoteResourceObj) {
+ Log.e(LOG_TAG, "Remote Resource object NULL");
+ return;
+ }
+
+ try {
+ remoteResourceObj
+ .setRemoteAttributesListener(remoteAttributeListener);
+
+ if (null != remoteAttributeListener) {
+ remoteResourceObj.getRemoteAttributes();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ return;
+ }
+
+ Log.d(LOG_TAG, "getRemoteAttributes exit");
+ }
+
+ 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
+ .setRemoteAttributesListener(remoteAttributeListener);
+
+ if (null != remoteAttributeListener) {
+ RCSResourceAttributes attr = new RCSResourceAttributes();
+ attr.setValueInt("Temperature", value);
+ remoteResourceObj.setRemoteAttributes(attr);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ return;
+ }
+
+ Log.d(LOG_TAG, "setRemoteAttributes exit");
+ }
+
+ 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");
+ }
+
+ 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");
+ }
+
+ 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");
+ }
+
+ 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 = 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");
+ }
+
+ 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");
+ }
+
+ private void printAttributes(RCSResourceAttributes attributes) {
+ Log.d(LOG_TAG, "Printing Attributes");
+
+ try {
+ int temperature = attributes.getValueInt("Temperature");
+ 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 java.util.Calendar;
+
+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 ResourceClient resourceClientObj;
+ private static Handler mHandler;
+
+ private static EditText logs;
+ private static String logMessage;
+
+ public static Context mcontext;
+ public static Calendar scheduleTime;
+
+ private final String LOG_TAG = "[ReSample] "
+ + this.getClass()
+ .getSimpleName(); ;
+
+ @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"); // 0
+ clientApisList.add("2. Stop Monitoring"); // 1
+
+ clientApisList.add("3. Get Remote Attributes"); // 2
+ clientApisList.add("4. Set Remote Attributes"); // 3
+
+ clientApisList.add("5. Start Caching without callback"); // 4
+ clientApisList.add("6. Start Caching with callback"); // 5
+
+ clientApisList.add("7. Get Cache State"); // 6
+ clientApisList.add("8. Get All Cached Attributes"); // 7
+ clientApisList.add("9. Get Cached Attribute"); // 8
+
+ clientApisList.add("10. Stop Caching"); // 9
+
+ // 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 regionValue = (EditText) dialog
+ .findViewById(R.id.attributeValue);
+ String value = regionValue.getText().toString();
+ if (value.equalsIgnoreCase("")) {
+ String toastmessage = "Please enter the Temperature Value";
+ displayToastMessage(toastmessage);
+ } else {
+ dialog.dismiss();
+ int val = Integer.parseInt(value);
+ resourceClientObj.setRemoteAttributes(val);
+ }
+ }
+ });
+ 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);
+ }
+}