use of com.connectsdk.service.capability.CapabilityMethods.CapabilityPriorityLevel 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;
}
Aggregations