Imported Upstream version 0.9.2
[platform/upstream/iotivity.git] / service / protocol-plugin / plugin-manager / src / Android / src / org / iotivity / service / ppm / OnGetGear.java
1 //******************************************************************
2 //
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
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
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
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.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 /// @file OnGetGear.java
22
23 /// @brief This class is OnGetListener for Gear.
24
25 package org.iotivity.service.ppm;
26
27 import java.util.List;
28
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;
34
35 import android.util.Log;
36
37 public class OnGetGear implements OcResource.OnGetListener {
38     final private static String TAG = "PPMSampleApp : OnGetGear";
39
40     @Override
41     public void onGetCompleted(List<OcHeaderOption> headerOptions,
42             OcRepresentation rep) {
43         Log.i(TAG, "GET request Gear was successful");
44
45         try{
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());
53         }
54
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);
60
61         Log.e(TAG, "updating display from thread");
62
63         MainActivity.mActivity.runOnUiThread(new Runnable() {
64             @Override
65             public void run() {
66                 MainActivity.updateGearStatus();
67             }
68         });
69     }
70
71     @Override
72     public void onGetFailed(Throwable ex) {
73         if (ex instanceof OcException) {
74             OcException ocEx = (OcException) ex;
75             ErrorCode errCode = ocEx.getErrorCode();
76         }
77         Log.e(TAG, ex.toString());
78     }
79 }