Search in sources :

Example 6 with DeviceService

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;
}
Also used : DeviceService(com.connectsdk.service.DeviceService) CapabilityPriorityLevel(com.connectsdk.service.capability.CapabilityMethods.CapabilityPriorityLevel)

Example 7 with DeviceService

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();
}
Also used : DeviceService(com.connectsdk.service.DeviceService)

Example 8 with DeviceService

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;
}
Also used : JSONObject(org.json.JSONObject) DeviceService(com.connectsdk.service.DeviceService) JSONException(org.json.JSONException)

Example 9 with DeviceService

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);
        }
    });
}
Also used : DeviceService(com.connectsdk.service.DeviceService)

Example 10 with DeviceService

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();
// //
}
Also used : DeviceService(com.connectsdk.service.DeviceService)

Aggregations

DeviceService (com.connectsdk.service.DeviceService)11 NetcastTVService (com.connectsdk.service.NetcastTVService)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 AlertDialog (android.app.AlertDialog)1 DialogInterface (android.content.DialogInterface)1 EditText (android.widget.EditText)1 TextView (android.widget.TextView)1 ConnectableDevice (com.connectsdk.device.ConnectableDevice)1 AirPlayService (com.connectsdk.service.AirPlayService)1 CastService (com.connectsdk.service.CastService)1 DLNAService (com.connectsdk.service.DLNAService)1 RokuService (com.connectsdk.service.RokuService)1 WebOSTVService (com.connectsdk.service.WebOSTVService)1 CapabilityPriorityLevel (com.connectsdk.service.capability.CapabilityMethods.CapabilityPriorityLevel)1 ServiceConfig (com.connectsdk.service.config.ServiceConfig)1 ArrayList (java.util.ArrayList)1