Imported Upstream version 0.9.2
[platform/upstream/iotivity.git] / android / examples / fridgeclient / src / main / java / org / iotivity / base / examples / fridgeclient / FridgeClient.java
index a004c87..b2109e8 100644 (file)
-/*\r
- * //******************************************************************\r
- * //\r
- * // Copyright 2015 Intel Corporation.\r
- * //\r
- * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
- * //\r
- * // Licensed under the Apache License, Version 2.0 (the "License");\r
- * // you may not use this file except in compliance with the License.\r
- * // You may obtain a copy of the License at\r
- * //\r
- * //      http://www.apache.org/licenses/LICENSE-2.0\r
- * //\r
- * // Unless required by applicable law or agreed to in writing, software\r
- * // distributed under the License is distributed on an "AS IS" BASIS,\r
- * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * // See the License for the specific language governing permissions and\r
- * // limitations under the License.\r
- * //\r
- * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
- */\r
-\r
-package org.iotivity.base.examples.fridgeclient;\r
-\r
-import android.app.Activity;\r
-import android.content.BroadcastReceiver;\r
-import android.content.Context;\r
-import android.content.Intent;\r
-import android.content.IntentFilter;\r
-import android.os.Bundle;\r
-import android.os.Message;\r
-import android.support.v4.content.LocalBroadcastManager;\r
-import android.text.method.ScrollingMovementMethod;\r
-import android.util.Log;\r
-import android.view.Menu;\r
-import android.view.MenuItem;\r
-import android.widget.LinearLayout;\r
-import android.widget.TextView;\r
-\r
-import org.iotivity.base.ErrorCode;\r
-import org.iotivity.base.ModeType;\r
-import org.iotivity.base.OcConnectivityType;\r
-import org.iotivity.base.OcException;\r
-import org.iotivity.base.OcHeaderOption;\r
-import org.iotivity.base.OcPlatform;\r
-import org.iotivity.base.OcRepresentation;\r
-import org.iotivity.base.OcResource;\r
-import org.iotivity.base.PlatformConfig;\r
-import org.iotivity.base.QualityOfService;\r
-import org.iotivity.base.ServiceType;\r
-\r
-import java.util.HashMap;\r
-import java.util.LinkedList;\r
-import java.util.List;\r
-\r
-import base.iotivity.org.examples.message.IMessageLogger;\r
-\r
-/**\r
- * FridgeClient\r
- * <p/>\r
- * FridgeClient is a sample client app which should be started after the fridgeServer is started.\r
- * It creates DeviceResource, DoorResource, LightResource and performs a get operation on them.\r
- * This implements IMessageLogger to display messages on the screen\r
- */\r
-public class FridgeClient extends Activity implements\r
-        OcPlatform.OnResourceFoundListener, IMessageLogger {\r
-    private static String TAG = "FridgeClient: ";\r
-\r
-    private MessageReceiver mMessageReceiver = new MessageReceiver();\r
-    private TextView mEventsTextView;\r
-    private String mDeviceName;\r
-    private int mDeviceCode;\r
-    private List<String> ifaces;\r
-    private final List<OcResource> resourceList = new LinkedList<OcResource>();\r
-\r
-    /**\r
-     * configure OIC platform and call findResource\r
-     */\r
-    private void initOICStack() {\r
-        PlatformConfig cfg = new PlatformConfig(\r
-                this,\r
-                ServiceType.IN_PROC,\r
-                ModeType.CLIENT,\r
-                "0.0.0.0", // bind to all available interfaces\r
-                0,\r
-                QualityOfService.LOW);\r
-\r
-        OcPlatform.Configure(cfg);\r
-        try {\r
-            OcPlatform.findResource("", OcPlatform.WELL_KNOWN_QUERY + "?rt=" + "intel.fridge",\r
-                    OcConnectivityType.WIFI, this);\r
-        } catch (OcException e) {\r
-            logMessage(TAG + " init Error. " + e.getMessage());\r
-            Log.e(TAG, e.getMessage());\r
-        }\r
-    }\r
-\r
-    /**\r
-     * prints out the appropriate messages depending on the device code\r
-     *\r
-     * @param representation representation of the OcResource\r
-     * @param value          clientDeviceCode\r
-     */\r
-    private void getResponse(OcRepresentation representation, int value) {\r
-        switch (value) {\r
-            case 0:\r
-                // Get on device\r
-                try {\r
-                    logMessage(TAG + "Name of device: " +\r
-                            representation.getValue(StringConstants.DEVICE_NAME));\r
-                } catch (OcException e) {\r
-                    Log.e(TAG, e.getMessage());\r
-                }\r
-                break;\r
-            case 1:\r
-                // get on fridge light\r
-                try {\r
-                    boolean lightOn = representation.getValue(StringConstants.ON);\r
-                    logMessage(TAG + "The fridge light is " +\r
-                            (lightOn ? "" : "not " + "on"));\r
-                } catch (OcException e) {\r
-                    Log.e(TAG, e.getMessage());\r
-                }\r
-                break;\r
-            case 2:\r
-            case 3:\r
-                // get on fridge door(s)\r
-                try {\r
-                    boolean doorOpen = representation.getValue(StringConstants.OPEN);\r
-                    logMessage(TAG + "Door is " + (doorOpen ?\r
-                            "open" : "not open") + " and is on the " +\r
-                            representation.getValue(StringConstants.SIDE) + " side");\r
-                } catch (OcException e) {\r
-                    Log.e(TAG, e.getMessage());\r
-                }\r
-                break;\r
-            case 4:\r
-                // get on fridge random door\r
-                try {\r
-                    logMessage("Name of fridge: " +\r
-                            representation.getValue(StringConstants.DEVICE_NAME));\r
-                } catch (OcException e) {\r
-                    Log.e(TAG, e.getMessage());\r
-                }\r
-                break;\r
-            default:\r
-                logMessage("Unexpected State");\r
-                break;\r
-        }\r
-    }\r
-\r
-    /**\r
-     * this method is used to wait for 1 second between calls to different resources.\r
-     * It is added for better readability\r
-     */\r
-    private void doWait() {\r
-        try {\r
-            Thread.sleep(StringConstants.WAIT_TIME);\r
-        } catch (InterruptedException e) {\r
-            logMessage(TAG + "doWait exception: " + e.getMessage());\r
-            Log.e(TAG, e.getMessage());\r
-        }\r
-    }\r
-\r
-    @Override\r
-    /**\r
-     *  callback when a resource is found. This method calls getResponse with the correct code\r
-     */\r
-    synchronized public void onResourceFound(OcResource ocResource) {\r
-        // eventHandler for onGetListener\r
-        resourceList.add(ocResource);\r
-        OcResource.OnGetListener onGetListener = new OcResource.OnGetListener() {\r
-            @Override\r
-            public void onGetCompleted(List<OcHeaderOption> headerOptionList, OcRepresentation rep) {\r
-                logMessage(TAG + " Got a response from " + getClientDeviceName());\r
-                getResponse(rep, getClientDeviceCode());\r
-            }\r
-\r
-            @Override\r
-            public void onGetFailed(Throwable throwable) {\r
-                if (throwable instanceof OcException) {\r
-                    OcException ocEx = (OcException) throwable;\r
-                    ErrorCode errCode = ocEx.getErrorCode();\r
-                    //do something based on errorCode\r
-                }\r
-                Log.e(TAG, throwable.toString());\r
-            }\r
-        };\r
-\r
-        if (ocResource.getUri().equals(StringConstants.RESOURCE_URI)) {\r
-            logMessage(TAG + "Discovered a device with \nHost: " + ocResource.getHost() +\r
-                    ", Uri: " + ocResource.getUri());\r
-        }\r
-        List<String> lightTypes = new LinkedList<>();\r
-        lightTypes.add("intel.fridge.light");\r
-        try {\r
-            OcResource light = OcPlatform.constructResourceObject(ocResource.getHost(),\r
-                    StringConstants.LIGHT, OcConnectivityType.WIFI, false, lightTypes, ifaces);\r
-\r
-            List<String> doorTypes = new LinkedList<>();\r
-            doorTypes.add("intel.fridge.door");\r
-            OcResource leftDoor = OcPlatform.constructResourceObject(ocResource.getHost(),\r
-                    StringConstants.LEFT_DOOR, OcConnectivityType.WIFI, false, doorTypes, ifaces);\r
-\r
-            OcResource rightDoor = OcPlatform.constructResourceObject(ocResource.getHost(),\r
-                    StringConstants.RIGHT_DOOR, OcConnectivityType.WIFI, false, doorTypes, ifaces);\r
-\r
-            OcResource randomDoor = OcPlatform.constructResourceObject(ocResource.getHost(),\r
-                    StringConstants.RANDOM_DOOR, OcConnectivityType.WIFI, false, doorTypes, ifaces);\r
-\r
-            List<OcHeaderOption> headerOptions = new LinkedList<>();\r
-            OcHeaderOption apiVersion = new OcHeaderOption(StringConstants.API_VERSION_KEY,\r
-                    StringConstants.API_VERSION);\r
-            OcHeaderOption clientToken = new OcHeaderOption(StringConstants.CLIENT_VERSION_KEY,\r
-                    StringConstants.CLIENT_TOKEN);\r
-            headerOptions.add(apiVersion);\r
-            headerOptions.add(clientToken);\r
-            ocResource.setHeaderOptions(headerOptions);\r
-            /**\r
-             *  wait for 1 second before calling get on different resources.\r
-             *  It is done for better readability.\r
-             *  doWait() is called before each call to get\r
-             */\r
-            doWait();\r
-\r
-            setupClientOptions("Device", 0);\r
-            ocResource.get(new HashMap<String, String>(), onGetListener);\r
-            doWait();\r
-\r
-            setupClientOptions("Fridge Light", 1);\r
-            light.get(new HashMap<String, String>(), onGetListener);\r
-            doWait();\r
-\r
-            setupClientOptions("Left Door", 2);\r
-            leftDoor.get(new HashMap<String, String>(), onGetListener);\r
-            doWait();\r
-\r
-            setupClientOptions("Right Door", 3);\r
-            rightDoor.get(new HashMap<String, String>(), onGetListener);\r
-            doWait();\r
-\r
-            setupClientOptions("Random Door", 4);\r
-            randomDoor.get(new HashMap<String, String>(), onGetListener);\r
-            doWait();\r
-\r
-            resourceList.add(leftDoor);\r
-            leftDoor.deleteResource(new OcResource.OnDeleteListener() {\r
-                @Override\r
-                public void onDeleteCompleted(List<OcHeaderOption> ocHeaderOptions) {\r
-                    logMessage(TAG + "Delete resource successful");\r
-                }\r
-\r
-                @Override\r
-                public void onDeleteFailed(Throwable throwable) {\r
-                    if (throwable instanceof OcException) {\r
-                        OcException ocEx = (OcException) throwable;\r
-                        ErrorCode errCode = ocEx.getErrorCode();\r
-                        //do something based on errorCode\r
-                    }\r
-                    Log.e(TAG, throwable.toString());\r
-                }\r
-            });\r
-        } catch (OcException e) {\r
-            logMessage(TAG + "onResourceFound Error. " + e.getMessage());\r
-            Log.e(TAG, e.getMessage());\r
-        }\r
-    }\r
-\r
-    @Override\r
-    protected void onCreate(Bundle savedInstanceState) {\r
-        super.onCreate(savedInstanceState);\r
-        setContentView(R.layout.activity_fridge_client);\r
-        registerReceiver(mMessageReceiver, new IntentFilter(StringConstants.INTENT));\r
-\r
-        mEventsTextView = new TextView(this);\r
-        mEventsTextView.setMovementMethod(new ScrollingMovementMethod());\r
-        LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout);\r
-        layout.addView(mEventsTextView, new LinearLayout.LayoutParams\r
-                (LinearLayout.LayoutParams.MATCH_PARENT, 0, 1f));\r
-        ifaces = new LinkedList<>();\r
-        ifaces.add(StringConstants.RESOURCE_INTERFACE);\r
-        mDeviceCode = -1;\r
-        mDeviceName = "";\r
-\r
-        initOICStack();\r
-    }\r
-\r
-    public class MessageReceiver extends BroadcastReceiver {\r
-        @Override\r
-        public void onReceive(Context context, Intent intent) {\r
-            final String message = intent.getStringExtra(StringConstants.MESSAGE);\r
-            logMessage(message);\r
-        }\r
-    }\r
-\r
-    @Override\r
-    public void logMessage(final String text) {\r
-        if (StringConstants.ENABLE_PRINTING) {\r
-            runOnUiThread(new Runnable() {\r
-                public void run() {\r
-                    final Message msg = new Message();\r
-                    msg.obj = text;\r
-                    mEventsTextView.append("\n");\r
-                    mEventsTextView.append(text);\r
-                }\r
-            });\r
-            Log.i(TAG, text);\r
-        }\r
-    }\r
-\r
-\r
-    private void setupClientOptions(String name, int value) {\r
-        mDeviceName = name;\r
-        mDeviceCode = value;\r
-    }\r
-\r
-    private String getClientDeviceName() {\r
-        return mDeviceName;\r
-    }\r
-\r
-    private int getClientDeviceCode() {\r
-        return mDeviceCode;\r
-    }\r
-\r
-\r
-    //method to print the headerOptions received from the server\r
-    void printHeaderOptions(List<OcHeaderOption> headerOptions) {\r
-        for (OcHeaderOption headerOption : headerOptions) {\r
-            if (StringConstants.API_VERSION_KEY == headerOption.getOptionId()) {\r
-                logMessage(TAG + "Server API version in GET response: " +\r
-                        headerOption.getOptionData());\r
-            }\r
-        }\r
-    }\r
-\r
-    @Override\r
-    public boolean onCreateOptionsMenu(Menu menu) {\r
-        getMenuInflater().inflate(R.menu.menu_fridge_client, menu);\r
-        return true;\r
-    }\r
-\r
-    @Override\r
-    public boolean onOptionsItemSelected(MenuItem item) {\r
-        int id = item.getItemId();\r
-        if (id == R.id.action_settings) {\r
-            return true;\r
-        }\r
-        return super.onOptionsItemSelected(item);\r
-    }\r
-\r
-    @Override\r
-    public void onDestroy() {\r
-        super.onDestroy();\r
-        onStop();\r
-    }\r
-\r
-    @Override\r
-    protected void onStop() {\r
-        LocalBroadcastManager.getInstance(this).unregisterReceiver(mMessageReceiver);\r
-        super.onStop();\r
-    }\r
-}\r
+/*
+ * //******************************************************************
+ * //
+ * // Copyright 2015 Intel Corporation.
+ * //
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ * //
+ * // Licensed under the Apache License, Version 2.0 (the "License");
+ * // you may not use this file except in compliance with the License.
+ * // You may obtain a copy of the License at
+ * //
+ * //      http://www.apache.org/licenses/LICENSE-2.0
+ * //
+ * // Unless required by applicable law or agreed to in writing, software
+ * // distributed under the License is distributed on an "AS IS" BASIS,
+ * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * // See the License for the specific language governing permissions and
+ * // limitations under the License.
+ * //
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ */
+
+package org.iotivity.base.examples.fridgeclient;
+
+import android.app.Activity;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.os.Bundle;
+import android.os.Message;
+import android.support.v4.content.LocalBroadcastManager;
+import android.text.method.ScrollingMovementMethod;
+import android.util.Log;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import org.iotivity.base.ErrorCode;
+import org.iotivity.base.ModeType;
+import org.iotivity.base.OcConnectivityType;
+import org.iotivity.base.OcException;
+import org.iotivity.base.OcHeaderOption;
+import org.iotivity.base.OcPlatform;
+import org.iotivity.base.OcRepresentation;
+import org.iotivity.base.OcResource;
+import org.iotivity.base.PlatformConfig;
+import org.iotivity.base.QualityOfService;
+import org.iotivity.base.ServiceType;
+
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+
+import base.iotivity.org.examples.message.IMessageLogger;
+
+/**
+ * FridgeClient
+ * <p/>
+ * FridgeClient is a sample client app which should be started after the fridgeServer is started.
+ * It creates DeviceResource, DoorResource, LightResource and performs a get operation on them.
+ * This implements IMessageLogger to display messages on the screen
+ */
+public class FridgeClient extends Activity implements
+        OcPlatform.OnResourceFoundListener, IMessageLogger {
+    private static String TAG = "FridgeClient: ";
+
+    private MessageReceiver mMessageReceiver = new MessageReceiver();
+    private TextView mEventsTextView;
+    private String mDeviceName;
+    private int mDeviceCode;
+    private List<String> ifaces;
+    private final List<OcResource> resourceList = new LinkedList<OcResource>();
+
+    /**
+     * configure OIC platform and call findResource
+     */
+    private void initOICStack() {
+        PlatformConfig cfg = new PlatformConfig(
+                this,
+                ServiceType.IN_PROC,
+                ModeType.CLIENT,
+                "0.0.0.0", // bind to all available interfaces
+                0,
+                QualityOfService.LOW);
+
+        OcPlatform.Configure(cfg);
+        try {
+            OcPlatform.findResource("", OcPlatform.WELL_KNOWN_QUERY + "?rt=" + "intel.fridge",
+                    EnumSet.of(OcConnectivityType.CT_DEFAULT), this);
+        } catch (OcException e) {
+            logMessage(TAG + " init Error. " + e.getMessage());
+            Log.e(TAG, e.getMessage());
+        }
+    }
+
+    /**
+     * prints out the appropriate messages depending on the device code
+     *
+     * @param representation representation of the OcResource
+     * @param value          clientDeviceCode
+     */
+    private void getResponse(OcRepresentation representation, int value) {
+        switch (value) {
+            case 0:
+                // Get on device
+                try {
+                    logMessage(TAG + "Name of device: " +
+                            representation.getValue(StringConstants.DEVICE_NAME));
+                } catch (OcException e) {
+                    Log.e(TAG, e.getMessage());
+                }
+                break;
+            case 1:
+                // get on fridge light
+                try {
+                    boolean lightOn = representation.getValue(StringConstants.ON);
+                    logMessage(TAG + "The fridge light is " +
+                            (lightOn ? "" : "not " + "on"));
+                } catch (OcException e) {
+                    Log.e(TAG, e.getMessage());
+                }
+                break;
+            case 2:
+            case 3:
+                // get on fridge door(s)
+                try {
+                    boolean doorOpen = representation.getValue(StringConstants.OPEN);
+                    logMessage(TAG + "Door is " + (doorOpen ?
+                            "open" : "not open") + " and is on the " +
+                            representation.getValue(StringConstants.SIDE) + " side");
+                } catch (OcException e) {
+                    Log.e(TAG, e.getMessage());
+                }
+                break;
+            case 4:
+                // get on fridge random door
+                try {
+                    logMessage("Name of fridge: " +
+                            representation.getValue(StringConstants.DEVICE_NAME));
+                } catch (OcException e) {
+                    Log.e(TAG, e.getMessage());
+                }
+                break;
+            default:
+                logMessage("Unexpected State");
+                break;
+        }
+    }
+
+    /**
+     * this method is used to wait for 1 second between calls to different resources.
+     * It is added for better readability
+     */
+    private void doWait() {
+        try {
+            Thread.sleep(StringConstants.WAIT_TIME);
+        } catch (InterruptedException e) {
+            logMessage(TAG + "doWait exception: " + e.getMessage());
+            Log.e(TAG, e.getMessage());
+        }
+    }
+
+    @Override
+    /**
+     *  callback when a resource is found. This method calls getResponse with the correct code
+     */
+    synchronized public void onResourceFound(OcResource ocResource) {
+        // eventHandler for onGetListener
+        resourceList.add(ocResource);
+        OcResource.OnGetListener onGetListener = new OcResource.OnGetListener() {
+            @Override
+            public void onGetCompleted(List<OcHeaderOption> headerOptionList, OcRepresentation rep) {
+                logMessage(TAG + " Got a response from " + getClientDeviceName());
+                getResponse(rep, getClientDeviceCode());
+            }
+
+            @Override
+            public void onGetFailed(Throwable throwable) {
+                if (throwable instanceof OcException) {
+                    OcException ocEx = (OcException) throwable;
+                    ErrorCode errCode = ocEx.getErrorCode();
+                    //do something based on errorCode
+                }
+                Log.e(TAG, throwable.toString());
+            }
+        };
+
+        if (ocResource.getUri().equals(StringConstants.RESOURCE_URI)) {
+            logMessage(TAG + "Discovered a device with \nHost: " + ocResource.getHost() +
+                    ", Uri: " + ocResource.getUri());
+        }
+        List<String> lightTypes = new LinkedList<>();
+        lightTypes.add("intel.fridge.light");
+        try {
+            OcResource light = OcPlatform.constructResourceObject(ocResource.getHost(),
+                    StringConstants.LIGHT, EnumSet.of(OcConnectivityType.CT_DEFAULT), false, lightTypes, ifaces);
+
+            List<String> doorTypes = new LinkedList<>();
+            doorTypes.add("intel.fridge.door");
+            OcResource leftDoor = OcPlatform.constructResourceObject(ocResource.getHost(),
+                    StringConstants.LEFT_DOOR, EnumSet.of(OcConnectivityType.CT_DEFAULT), false, doorTypes, ifaces);
+
+            OcResource rightDoor = OcPlatform.constructResourceObject(ocResource.getHost(),
+                    StringConstants.RIGHT_DOOR, EnumSet.of(OcConnectivityType.CT_DEFAULT), false, doorTypes, ifaces);
+
+            OcResource randomDoor = OcPlatform.constructResourceObject(ocResource.getHost(),
+                    StringConstants.RANDOM_DOOR, EnumSet.of(OcConnectivityType.CT_DEFAULT), false, doorTypes, ifaces);
+
+            List<OcHeaderOption> headerOptions = new LinkedList<>();
+            OcHeaderOption apiVersion = new OcHeaderOption(StringConstants.API_VERSION_KEY,
+                    StringConstants.API_VERSION);
+            OcHeaderOption clientToken = new OcHeaderOption(StringConstants.CLIENT_TOKEN_KEY,
+                    StringConstants.CLIENT_TOKEN);
+            headerOptions.add(apiVersion);
+            headerOptions.add(clientToken);
+            ocResource.setHeaderOptions(headerOptions);
+            /**
+             *  wait for 1 second before calling get on different resources.
+             *  It is done for better readability.
+             *  doWait() is called before each call to get
+             */
+            doWait();
+
+            setupClientOptions("Device", 0);
+            ocResource.get(new HashMap<String, String>(), onGetListener);
+            doWait();
+
+            setupClientOptions("Fridge Light", 1);
+            light.get(new HashMap<String, String>(), onGetListener);
+            doWait();
+
+            setupClientOptions("Left Door", 2);
+            leftDoor.get(new HashMap<String, String>(), onGetListener);
+            doWait();
+
+            setupClientOptions("Right Door", 3);
+            rightDoor.get(new HashMap<String, String>(), onGetListener);
+            doWait();
+
+            setupClientOptions("Random Door", 4);
+            randomDoor.get(new HashMap<String, String>(), onGetListener);
+            doWait();
+
+            resourceList.add(leftDoor);
+            leftDoor.deleteResource(new OcResource.OnDeleteListener() {
+                @Override
+                public void onDeleteCompleted(List<OcHeaderOption> ocHeaderOptions) {
+                    logMessage(TAG + "Delete resource successful");
+                }
+
+                @Override
+                public void onDeleteFailed(Throwable throwable) {
+                    if (throwable instanceof OcException) {
+                        OcException ocEx = (OcException) throwable;
+                        ErrorCode errCode = ocEx.getErrorCode();
+                        //do something based on errorCode
+                    }
+                    Log.e(TAG, throwable.toString());
+                }
+            });
+        } catch (OcException e) {
+            logMessage(TAG + "onResourceFound Error. " + e.getMessage());
+            Log.e(TAG, e.getMessage());
+        }
+    }
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.activity_fridge_client);
+        registerReceiver(mMessageReceiver, new IntentFilter(StringConstants.INTENT));
+
+        mEventsTextView = new TextView(this);
+        mEventsTextView.setMovementMethod(new ScrollingMovementMethod());
+        LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout);
+        layout.addView(mEventsTextView, new LinearLayout.LayoutParams
+                (LinearLayout.LayoutParams.MATCH_PARENT, 0, 1f));
+        ifaces = new LinkedList<>();
+        ifaces.add(StringConstants.RESOURCE_INTERFACE);
+        mDeviceCode = -1;
+        mDeviceName = "";
+
+        initOICStack();
+    }
+
+    public class MessageReceiver extends BroadcastReceiver {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            final String message = intent.getStringExtra(StringConstants.MESSAGE);
+            logMessage(message);
+        }
+    }
+
+    @Override
+    public void logMessage(final String text) {
+        if (StringConstants.ENABLE_PRINTING) {
+            runOnUiThread(new Runnable() {
+                public void run() {
+                    final Message msg = new Message();
+                    msg.obj = text;
+                    mEventsTextView.append("\n");
+                    mEventsTextView.append(text);
+                }
+            });
+            Log.i(TAG, text);
+        }
+    }
+
+
+    private void setupClientOptions(String name, int value) {
+        mDeviceName = name;
+        mDeviceCode = value;
+    }
+
+    private String getClientDeviceName() {
+        return mDeviceName;
+    }
+
+    private int getClientDeviceCode() {
+        return mDeviceCode;
+    }
+
+
+    //method to print the headerOptions received from the server
+    void printHeaderOptions(List<OcHeaderOption> headerOptions) {
+        for (OcHeaderOption headerOption : headerOptions) {
+            if (StringConstants.API_VERSION_KEY == headerOption.getOptionId()) {
+                logMessage(TAG + "Server API version in GET response: " +
+                        headerOption.getOptionData());
+            }
+        }
+    }
+
+    @Override
+    public boolean onCreateOptionsMenu(Menu menu) {
+        getMenuInflater().inflate(R.menu.menu_fridge_client, menu);
+        return true;
+    }
+
+    @Override
+    public boolean onOptionsItemSelected(MenuItem item) {
+        int id = item.getItemId();
+        if (id == R.id.action_settings) {
+            return true;
+        }
+        return super.onOptionsItemSelected(item);
+    }
+
+    @Override
+    public void onDestroy() {
+        super.onDestroy();
+        onStop();
+    }
+
+    @Override
+    protected void onStop() {
+        LocalBroadcastManager.getInstance(this).unregisterReceiver(mMessageReceiver);
+        super.onStop();
+    }
+}