1 /******************************************************************
3 * Copyright 2015 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 ******************************************************************/
21 package com.tm.sample;
23 import java.util.Vector;
25 import org.iotivity.base.OcHeaderOption;
26 import org.iotivity.base.OcRepresentation;
27 import org.iotivity.service.tm.Action;
28 import org.iotivity.service.tm.ActionSet;
29 import org.iotivity.service.tm.Capability;
30 import org.iotivity.service.tm.GroupManager.*;
32 import android.os.Message;
33 import android.util.Log;
36 * For getting the put,get,observe and post Callback and updating
37 * the UI i.e. logMessage(TextBox) of GroupApiActivity.
39 public class ActionListener implements IActionListener {
41 private final String LOG_TAG = "[TMSample] "
44 private static Message msg;
45 private String logMessage;
46 private GroupApiActivity groupApiActivityObj = null;
49 public void onPostResponseCallback(Vector<OcHeaderOption> headerOptions,
50 OcRepresentation rep, int errorValue) {
51 Log.i(LOG_TAG, "Got Callback : onPostResponseCallback");
53 groupApiActivityObj = GroupApiActivity.getGroupApiActivityObj();
54 logMessage = "API Result : SUCCESS" + "\n";
55 logMessage += "Recieved Callback for called API (OnPostCallback)"
58 // sending message to handler of GroupApiActivity to Update the UI
59 GroupApiActivity.setMessageLog(logMessage);
60 msg = Message.obtain();
62 groupApiActivityObj.getHandler().sendMessage(msg);
66 public void onGetResponseCallback(Vector<OcHeaderOption> headerOptions,
67 OcRepresentation rep, int errorValue) {
68 Log.i(LOG_TAG, "Got Callback : onGetResponseCallback");
70 String actionSetStr = rep.getValueString("ActionSet");
71 groupApiActivityObj = GroupApiActivity.getGroupApiActivityObj();
72 logMessage = "Recieved Callback for called API (onGetResponseCallback)"
73 + "\n" + "ActionSet:" + actionSetStr;
75 GroupApiActivity.setMessageLog(logMessage);
76 // sending message to handler of GroupApiActivity to Update the UI
77 msg = Message.obtain();
79 groupApiActivityObj.getHandler().sendMessage(msg);
81 if (actionSetStr != null) {
82 ActionSet actionSet = ActionSet.toActionSet(actionSetStr);
83 if (actionSet != null) {
84 System.out.println("ActionSet Name : "
85 + actionSet.actionsetName);
86 for (int i = 0; i < actionSet.listOfAction.size(); i++) {
87 Action action = actionSet.listOfAction.get(i);
88 System.out.println("Target : " + action.target);
90 Vector<Capability> listOfCapability = action.listOfCapability;
91 for (int j = 0; j < listOfCapability.size(); j++) {
92 Capability capability = listOfCapability.get(j);
93 System.out.println("Capability : "
94 + capability.capability);
95 System.out.println("Status : " + capability.status);
101 groupApiActivityObj = GroupApiActivity.getGroupApiActivityObj();
102 GroupApiActivity.setMessageLog(logMessage);
103 msg = Message.obtain();
105 groupApiActivityObj.getHandler().sendMessage(msg);
109 public void onPutResponseCallback(Vector<OcHeaderOption> headerOptions,
110 OcRepresentation rep, int errorValue) {
111 Log.i(LOG_TAG, "Got Callback : onPutResponseCallback");
113 groupApiActivityObj = GroupApiActivity.getGroupApiActivityObj();
114 logMessage = "API Result : SUCCESS" + "\n";
115 logMessage += "Recieved Callback for called API (onPutResponseCallback)"
117 GroupApiActivity.setMessageLog(logMessage);
118 // sending message to handler of GroupApiActivity to Update the UI
119 msg = Message.obtain();
121 groupApiActivityObj.getHandler().sendMessage(msg);