Imported Upstream version 1.0.0
[platform/upstream/iotivity.git] / service / resource-container / examples / android / RCSampleClientApp / app / src / main / java / org / iotivity / service / sample / client / Utils.java
1 package org.iotivity.service.sample.client;
2
3 import android.content.Context;
4 import android.util.Log;
5 import android.widget.Toast;
6
7 import org.iotivity.service.RcsException;
8 import org.iotivity.service.client.RcsRemoteResourceObject;
9
10 public class Utils {
11     public static String resourceInfo(RcsRemoteResourceObject resourceObject)
12             throws RcsException {
13         StringBuilder sb = new StringBuilder();
14
15         sb.append("URI : " + resourceObject.getUri() + "\n");
16         sb.append("Host : " + resourceObject.getAddress() + "\n");
17         for (String type : resourceObject.getTypes()) {
18             sb.append("resourceType : " + type + "\n");
19         }
20
21         for (String itf : resourceObject.getInterfaces()) {
22             sb.append("resourceInterfaces : " + itf + "\n");
23         }
24
25         sb.append("isObservable : " + resourceObject.isObservable() + "\n");
26
27         return sb.toString();
28     }
29
30     public static void showError(Context ctx, String tag, String msg) {
31         Toast.makeText(ctx, msg, Toast.LENGTH_SHORT).show();
32         Log.e(tag, msg);
33     }
34
35     public static void showError(Context ctx, String tag, Exception e) {
36         Toast.makeText(ctx, e.getMessage(), Toast.LENGTH_SHORT).show();
37         Log.e(tag, e.getMessage(), e);
38     }
39 }