319d5e1097ff26c34658c29de3bcc02ad737cb87
[platform/upstream/iotivity.git] / service / resource-container / examples / android / RCSampleClientApp / app / src / main / java / org / iotivity / service / sample / client / ContainerClientActivity.java
1 /******************************************************************
2  * Copyright 2015 Samsung Electronics All Rights Reserved.
3  * <p>
4  * <p>
5  * <p>
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  * <p>
10  * http://www.apache.org/licenses/LICENSE-2.0
11  * <p>
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  ******************************************************************/
18
19 package org.iotivity.service.sample.client;
20
21 import android.app.Activity;
22 import android.os.Bundle;
23 import android.util.Log;
24 import android.view.View;
25 import android.widget.TextView;
26
27 import org.iotivity.service.RcsException;
28 import org.iotivity.service.client.RcsAddress;
29 import org.iotivity.service.client.RcsDiscoveryManager;
30 import org.iotivity.service.client.RcsRemoteResourceObject;
31
32 /**
33  * It contains the discover resource API for Discovering Container Resource
34  */
35 public class ContainerClientActivity extends Activity implements
36         RcsDiscoveryManager.OnResourceDiscoveredListener {
37     private final String LOG_TAG = "[SampleClient] "
38                                          + this.getClass().getSimpleName();
39
40     private TextView     mLogView;
41
42     @Override
43     protected void onCreate(Bundle savedInstanceState) {
44         super.onCreate(savedInstanceState);
45         setContentView(R.layout.activity_container_client);
46         mLogView = (TextView) findViewById(R.id.log);
47     }
48
49     public void onDiscoverResourceClick(View v) {
50         try {
51             RcsDiscoveryManager.getInstance().discoverResourceByType(
52                     RcsAddress.multicast(), "oic.r.sensor",
53                     ContainerClientActivity.this);
54             mLogView.setText("");
55         } catch (RcsException e) {
56             e.printStackTrace();
57         }
58     }
59
60     @Override
61     public void onResourceDiscovered(
62             final RcsRemoteResourceObject discoveredResource) {
63         Log.i(LOG_TAG, "onResourceDiscovered");
64
65         runOnUiThread(new Runnable() {
66             public void run() {
67                 try {
68                     mLogView.setText(Utils.resourceInfo(discoveredResource));
69                 } catch (RcsException e) {
70                     Utils.showError(ContainerClientActivity.this, LOG_TAG, e);
71                 }
72             }
73         });
74     }
75 }