1 /******************************************************************
2 * Copyright 2015 Samsung Electronics All Rights Reserved.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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 ******************************************************************/
19 package org.iotivity.service.sample.client;
21 import android.os.Handler;
22 import android.util.Log;
24 import org.iotivity.service.RcsException;
25 import org.iotivity.service.RcsResourceAttributes;
26 import org.iotivity.service.client.RcsRemoteResourceObject;
28 public class ResourceListItem {
29 private final String LOG_TAG = "[RCSampleClient] "
30 + this.getClass().getSimpleName();
32 public String mResourceUri;
33 public RcsRemoteResourceObject mResource;
34 public RemoteResourceGetListener mGetListener;
35 public RemoteResourceCacheListener mCacheListener;
36 public boolean mCacheStarted;
38 private Handler mHandler;
40 public ResourceListItem(String resourceUri, RcsRemoteResourceObject resource, Handler handler)
42 mResourceUri = resourceUri;
45 mGetListener = new RemoteResourceGetListener();
46 mCacheListener = new RemoteResourceCacheListener();
47 mCacheStarted = false;
52 private class RemoteResourceGetListener implements RcsRemoteResourceObject.OnRemoteAttributesReceivedListener
56 public void onAttributesReceived(final RcsResourceAttributes rcsResourceAttributes, int eCode) {
57 Log.i(LOG_TAG, "onAttributesReceived -- " + mResourceUri);
59 new Thread(new Runnable() {
65 logMessage = "-- " + mResourceUri + "\n";
66 logMessage += Utils.resourceAttributes(rcsResourceAttributes);
68 mHandler.obtainMessage(ContainerClientActivity.MSG_ID_ATTRIBUTE_RECEIVED, logMessage).sendToTarget();
69 } catch (RcsException e) {
77 private class RemoteResourceCacheListener implements RcsRemoteResourceObject.OnCacheUpdatedListener
81 public void onCacheUpdated(final RcsResourceAttributes rcsResourceAttributes) {
82 Log.i(LOG_TAG, "onCacheUpdated -- " + mResourceUri);
84 new Thread(new Runnable() {
90 logMessage = "-- " + mResourceUri + "\n";
91 logMessage += Utils.resourceAttributes(rcsResourceAttributes);
93 mHandler.obtainMessage(ContainerClientActivity.MSG_ID_CACHEDATA_RECEIVED, logMessage).sendToTarget();
94 } catch (RcsException e) {