Imported Upstream version 0.9.1
[platform/upstream/iotivity.git] / service / protocol-plugin / plugin-manager / src / Android / src / org / iotivity / service / ppm / OnPutHuebulb.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 OnPutHuebulb.java
22
23 /// @brief This class is OnPutListener for Huebulb.
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 OnPutHuebulb implements OcResource.OnPutListener {
38     final private static String TAG = "OnPutHuebulb";
39
40     @Override
41     public void onPutCompleted(List<OcHeaderOption> options,
42             OcRepresentation rep) {
43         Log.i(TAG, "PUT request was successful");
44
45         try{
46             MainActivity.hueplug.m_name = rep.getValue("name");
47             MainActivity.hueplug.m_power = rep.getValue("power");
48             MainActivity.hueplug.m_bright = rep.getValue("brightness");
49             MainActivity.hueplug.m_color = rep.getValue("color");
50             MainActivity.hueplug.m_uri = rep.getValue("uri");
51         } catch (OcException e) {
52             Log.e(TAG, e.getMessage());
53         }
54
55         Log.i(TAG, "name : " + MainActivity.hueplug.m_name);
56         Log.i(TAG, "power : " + MainActivity.hueplug.m_power);
57         Log.i(TAG, "brightness : " + MainActivity.hueplug.m_bright);
58         Log.i(TAG, "color : " + MainActivity.hueplug.m_color);
59         Log.i(TAG, "uri : " + MainActivity.hueplug.m_uri);
60     }
61
62     @Override
63     public void onPutFailed(Throwable ex) {
64         if (ex instanceof OcException) {
65             OcException ocEx = (OcException) ex;
66             ErrorCode errCode = ocEx.getErrorCode();
67         }
68         Log.e(TAG, ex.toString());
69     }
70 }