1 //******************************************************************
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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 /// @file OnGetGear.java
23 /// @brief This class is OnGetListener for Gear.
25 package org.iotivity.service.ppm;
27 import java.util.List;
29 import org.iotivity.base.ErrorCode;
30 import org.iotivity.base.OcException;
31 import org.iotivity.base.OcHeaderOption;
32 import org.iotivity.base.OcRepresentation;
33 import org.iotivity.base.OcResource;
35 import android.util.Log;
37 public class OnGetGear implements OcResource.OnGetListener {
38 final private static String TAG = "PPMSampleApp : OnGetGear";
41 public void onGetCompleted(List<OcHeaderOption> headerOptions,
42 OcRepresentation rep) {
43 Log.i(TAG, "GET request Gear was successful");
46 MainActivity.gearplug.m_name = rep.getValue("name");
47 MainActivity.gearplug.m_power = rep.getValue("power");
48 MainActivity.gearplug.m_bright = rep.getValue("brightness");
49 MainActivity.gearplug.m_color = rep.getValue("color");
50 MainActivity.gearplug.m_uri = rep.getValue("uri");
51 } catch (OcException e) {
52 Log.e(TAG, e.getMessage());
55 Log.i(TAG, "name : " + MainActivity.gearplug.m_name);
56 Log.i(TAG, "power : " + MainActivity.gearplug.m_power);
57 Log.i(TAG, "brightness : " + MainActivity.gearplug.m_bright);
58 Log.i(TAG, "color : " + MainActivity.gearplug.m_color);
59 Log.i(TAG, "uri : " + MainActivity.gearplug.m_uri);
61 Log.e(TAG, "updating display from thread");
63 MainActivity.mActivity.runOnUiThread(new Runnable() {
66 MainActivity.updateGearStatus();
72 public void onGetFailed(Throwable ex) {
73 if (ex instanceof OcException) {
74 OcException ocEx = (OcException) ex;
75 ErrorCode errCode = ocEx.getErrorCode();
77 Log.e(TAG, ex.toString());