Properly defined URI & Resource Type values for Presence Advertisement.
[contrib/iotivity.git] / android / SimpleClient / app / src / main / java / org / iotivity / simpleclient / FoundResource.java
1 //******************************************************************
2 //
3 // Copyright 2014 MediaTek 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 package org.iotivity.simpleclient;
22
23 import android.util.Log;
24
25 import org.iotivity.base.AbstractFindCallback;
26 import org.iotivity.base.OCResource;
27
28 public class FoundResource extends AbstractFindCallback {
29     final private static String TAG = "FoundResource";
30
31
32     public void Callback(OCResource resource) {
33
34         if(SimpleClient.curResource != null) {
35             Log.e(TAG, "Found another resource, ignoring");
36         }
37
38         String resourceURI;
39         String hostAddress;
40
41         if(resource != null) {
42             Log.i(TAG, "DISCOVERED Resource");
43
44             resourceURI = resource.uri();
45             Log.i(TAG, "URI of the resource: " + resourceURI);
46
47             hostAddress = resource.host();
48             Log.i(TAG, "Host address of the resource: " + hostAddress);
49
50             new SimpleToast().execute("URI of the resource: " + resourceURI + "\nHost address of the resource: " + hostAddress);
51
52             String[] resourceTypes = resource.getResourceTypes();
53             for(int i=0; i<resourceTypes.length; i++) {
54                 Log.i(TAG, "[" + i + "] : " + resourceTypes[i]);
55             }
56
57             String[] resourceInterfaces = resource.getResourceInterfaces();
58             for(int i=0; i<resourceInterfaces.length; i++) {
59                 Log.i(TAG, "[" + i + "] : " + resourceInterfaces[i]);
60             }
61
62             if(resourceURI.equals("/a/light")) {
63                 SimpleClient.curResource = resource;
64                 SimpleClient.getLightRepresentation(resource);
65             }
66         }
67         else {
68             Log.e(TAG, "Resource is invalid");
69         }
70     }
71
72 }