use of com.connectsdk.service.DeviceService in project butter-android by butterproject.
the class ConnectableDevice method getCapability.
/**
* Get a capability with the highest priority from a device. If device doesn't have such
* capability then returns null.
* @param controllerClass type of capability
* @return capability implementation
*/
public <T extends CapabilityMethods> T getCapability(Class<T> controllerClass) {
T foundController = null;
CapabilityPriorityLevel foundControllerPriority = CapabilityPriorityLevel.NOT_SUPPORTED;
for (DeviceService service : services.values()) {
if (service.getAPI(controllerClass) == null)
continue;
T controller = service.getAPI(controllerClass);
CapabilityPriorityLevel controllerPriority = service.getPriorityLevel(controllerClass);
if (foundController == null) {
foundController = controller;
if (controllerPriority == null || controllerPriority == CapabilityPriorityLevel.NOT_SUPPORTED) {
Log.w(Util.T, "We found a mathcing capability class, but no priority level for the class. Please check \"getPriorityLevel()\" in your class");
}
foundControllerPriority = controllerPriority;
} else if (controllerPriority != null && foundControllerPriority != null) {
if (controllerPriority.getValue() > foundControllerPriority.getValue()) {
foundController = controller;
foundControllerPriority = controllerPriority;
}
}
}
return foundController;
}
use of com.connectsdk.service.DeviceService in project butter-android by butterproject.
the class ConnectableDevice method isConnected.
// @cond INTERNAL
public boolean isConnected() {
int connectedCount = 0;
Iterator<DeviceService> iterator = services.values().iterator();
while (iterator.hasNext()) {
DeviceService service = iterator.next();
if (!service.isConnectable()) {
connectedCount++;
} else {
if (service.isConnected())
connectedCount++;
}
}
return connectedCount >= services.size();
}
use of com.connectsdk.service.DeviceService in project butter-android by butterproject.
the class ConnectableDevice method toJSONObject.
public JSONObject toJSONObject() {
JSONObject deviceObject = new JSONObject();
try {
deviceObject.put(KEY_ID, getId());
deviceObject.put(KEY_LAST_IP, getIpAddress());
deviceObject.put(KEY_FRIENDLY, getFriendlyName());
deviceObject.put(KEY_MODEL_NAME, getModelName());
deviceObject.put(KEY_MODEL_NUMBER, getModelNumber());
deviceObject.put(KEY_LAST_SEEN, getLastSeenOnWifi());
deviceObject.put(KEY_LAST_CONNECTED, getLastConnected());
deviceObject.put(KEY_LAST_DETECTED, getLastDetection());
JSONObject jsonServices = new JSONObject();
for (DeviceService service : services.values()) {
JSONObject serviceObject = service.toJSONObject();
jsonServices.put(service.getServiceConfig().getServiceUUID(), serviceObject);
}
deviceObject.put(KEY_SERVICES, jsonServices);
} catch (JSONException e) {
e.printStackTrace();
}
return deviceObject;
}
use of com.connectsdk.service.DeviceService in project butter-android by butterproject.
the class ConnectableDevice method removeServiceWithId.
/**
* Removes a DeviceService from the ConnectableDevice instance.
*
* @param serviceId ID of the DeviceService to be removed (DLNA, webOS TV, etc)
*/
public void removeServiceWithId(String serviceId) {
DeviceService service = services.get(serviceId);
if (service == null)
return;
service.disconnect();
services.remove(serviceId);
final List<String> removed = getMismatchCapabilities(service.getCapabilities(), getCapabilities());
Util.runOnUI(new Runnable() {
@Override
public void run() {
for (ConnectableDeviceListener listener : listeners) listener.onCapabilityUpdated(ConnectableDevice.this, new ArrayList<String>(), removed);
}
});
}
use of com.connectsdk.service.DeviceService in project butter-android by butterproject.
the class ConnectableDevice method getConnectedServiceNames.
// @cond INTERNAL
public String getConnectedServiceNames() {
int serviceCount = getServices().size();
if (serviceCount <= 0)
return null;
String[] serviceNames = new String[serviceCount];
int serviceIndex = 0;
for (DeviceService service : getServices()) {
serviceNames[serviceIndex] = service.getServiceName();
serviceIndex++;
}
// credit: http://stackoverflow.com/a/6623121/2715
StringBuilder sb = new StringBuilder();
for (String serviceName : serviceNames) {
if (sb.length() > 0)
sb.append(", ");
sb.append(serviceName);
}
return sb.toString();
// //
}
Aggregations