use of com.connectsdk.service.command.ServiceCommandError in project butter-android by butterproject.
the class NetcastTVService method sendPairingKey.
@Override
public void sendPairingKey(final String pairingKey) {
state = State.PAIRING;
if (!(serviceConfig instanceof NetcastTVServiceConfig)) {
serviceConfig = new NetcastTVServiceConfig(serviceConfig.getServiceUUID());
}
ResponseListener<Object> responseListener = new ResponseListener<Object>() {
@Override
public void onSuccess(Object response) {
state = State.PAIRED;
((NetcastTVServiceConfig) serviceConfig).setPairingKey(pairingKey);
hConnectSuccess();
}
@Override
public void onError(ServiceCommandError error) {
state = State.INITIAL;
if (listener != null)
listener.onConnectionFailure(NetcastTVService.this, error);
}
};
String requestURL = getUDAPRequestURL(UDAP_PATH_PAIRING);
Map<String, String> params = new HashMap<String, String>();
params.put("name", "hello");
params.put("value", pairingKey);
params.put("port", String.valueOf(serviceDescription.getPort()));
String httpMessage = getUDAPMessageBody(UDAP_API_PAIRING, params);
ServiceCommand<ResponseListener<Object>> command = new ServiceCommand<ResponseListener<Object>>(this, requestURL, httpMessage, responseListener);
command.send();
}
use of com.connectsdk.service.command.ServiceCommandError in project butter-android by butterproject.
the class WebOSTVService method getCurrentChannel.
private ServiceCommand<ResponseListener<Object>> getCurrentChannel(boolean isSubscription, final ChannelListener listener) {
ServiceCommand<ResponseListener<Object>> request;
ResponseListener<Object> responseListener = new ResponseListener<Object>() {
@Override
public void onSuccess(Object response) {
JSONObject jsonObj = (JSONObject) response;
ChannelInfo channel = parseRawChannelData(jsonObj);
Util.postSuccess(listener, channel);
}
@Override
public void onError(ServiceCommandError error) {
Util.postError(listener, error);
}
};
if (isSubscription) {
request = new URLServiceSubscription<ResponseListener<Object>>(this, CHANNEL, null, true, responseListener);
} else
request = new ServiceCommand<ResponseListener<Object>>(this, CHANNEL, null, true, responseListener);
request.send();
return request;
}
use of com.connectsdk.service.command.ServiceCommandError in project butter-android by butterproject.
the class WebOSTVService method launchYouTube.
@Override
public void launchYouTube(final String contentId, float startTime, final AppLaunchListener listener) {
JSONObject params = new JSONObject();
if (contentId != null && contentId.length() > 0) {
if (startTime < 0.0) {
Util.postError(listener, new ServiceCommandError(0, "Start time may not be negative", null));
return;
}
try {
params.put("contentId", String.format("%s&pairingCode=%s&t=%.1f", contentId, UUID.randomUUID().toString(), startTime));
} catch (JSONException e) {
e.printStackTrace();
}
}
AppInfo appInfo = new AppInfo() {
{
setId("youtube.leanback.v4");
setName("YouTube");
}
};
launchAppWithInfo(appInfo, params, listener);
}
use of com.connectsdk.service.command.ServiceCommandError in project butter-android by butterproject.
the class WebOSTVService method getRunningApp.
private ServiceCommand<AppInfoListener> getRunningApp(boolean isSubscription, final AppInfoListener listener) {
ServiceCommand<AppInfoListener> request;
ResponseListener<Object> responseListener = new ResponseListener<Object>() {
@Override
public void onSuccess(Object response) {
final JSONObject jsonObj = (JSONObject) response;
AppInfo app = new AppInfo() {
{
setId(jsonObj.optString("appId"));
setName(jsonObj.optString("appName"));
setRawData(jsonObj);
}
};
Util.postSuccess(listener, app);
}
@Override
public void onError(ServiceCommandError error) {
Util.postError(listener, error);
}
};
if (isSubscription)
request = new URLServiceSubscription<AppInfoListener>(this, FOREGROUND_APP, null, true, responseListener);
else
request = new ServiceCommand<AppInfoListener>(this, FOREGROUND_APP, null, true, responseListener);
request.send();
return request;
}
use of com.connectsdk.service.command.ServiceCommandError in project butter-android by butterproject.
the class WebOSTVService method getVolumeStatus.
private ServiceCommand<ResponseListener<Object>> getVolumeStatus(boolean isSubscription, final VolumeStatusListener listener) {
ServiceCommand<ResponseListener<Object>> request;
ResponseListener<Object> responseListener = new ResponseListener<Object>() {
@Override
public void onSuccess(Object response) {
try {
JSONObject jsonObj = (JSONObject) response;
boolean isMute = (Boolean) jsonObj.get("mute");
int iVolume = jsonObj.getInt("volume");
float fVolume = (float) (iVolume / 100.0);
Util.postSuccess(listener, new VolumeStatus(isMute, fVolume));
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onError(ServiceCommandError error) {
Util.postError(listener, error);
}
};
if (isSubscription)
request = new URLServiceSubscription<ResponseListener<Object>>(this, VOLUME_STATUS, null, true, responseListener);
else
request = new ServiceCommand<ResponseListener<Object>>(this, VOLUME_STATUS, null, true, responseListener);
request.send();
return request;
}
Aggregations