use of com.connectsdk.service.command.ServiceCommand in project butter-android by butterproject.
the class WebOSWebAppSession method previous.
@Override
public void previous(final ResponseListener<Object> listener) {
int requestIdNumber = getNextId();
final String requestId = String.format(Locale.US, "req%d", requestIdNumber);
JSONObject message = null;
try {
message = new JSONObject() {
{
put("contentType", namespaceKey + "mediaCommand");
put("mediaCommand", new JSONObject() {
{
put("type", "playPrevious");
put("requestId", requestId);
}
});
}
};
} catch (JSONException e) {
Util.postError(listener, new ServiceCommandError(0, "JSON Parse error", null));
return;
}
ServiceCommand<ResponseListener<Object>> command = new ServiceCommand<ResponseListener<Object>>(null, null, null, listener);
mActiveCommands.put(requestId, command);
sendMessage(message, listener);
}
use of com.connectsdk.service.command.ServiceCommand in project butter-android by butterproject.
the class WebOSWebAppSession method jumpToTrack.
@Override
public void jumpToTrack(final long index, final ResponseListener<Object> listener) {
int requestIdNumber = getNextId();
final String requestId = String.format(Locale.US, "req%d", requestIdNumber);
JSONObject message = null;
try {
message = new JSONObject() {
{
put("contentType", namespaceKey + "mediaCommand");
put("mediaCommand", new JSONObject() {
{
put("type", "jumpToTrack");
put("requestId", requestId);
put("index", (int) index);
}
});
}
};
} catch (JSONException e) {
Util.postError(listener, new ServiceCommandError(0, "JSON Parse error", null));
return;
}
ServiceCommand<ResponseListener<Object>> command = new ServiceCommand<ResponseListener<Object>>(null, null, null, listener);
mActiveCommands.put(requestId, command);
sendMessage(message, listener);
}
use of com.connectsdk.service.command.ServiceCommand in project butter-android by butterproject.
the class WebOSWebAppSession method playMedia.
@Override
public void playMedia(final String url, final String mimeType, final String title, final String description, final String iconSrc, final boolean shouldLoop, final MediaPlayer.LaunchListener listener) {
int requestIdNumber = getNextId();
final String requestId = String.format(Locale.US, "req%d", requestIdNumber);
JSONObject message = null;
try {
message = new JSONObject() {
{
putOpt("contentType", namespaceKey + "mediaCommand");
putOpt("mediaCommand", new JSONObject() {
{
putOpt("type", "playMedia");
putOpt("mediaURL", url);
putOpt("iconURL", iconSrc);
putOpt("title", title);
putOpt("description", description);
putOpt("mimeType", mimeType);
putOpt("shouldLoop", shouldLoop);
putOpt("requestId", requestId);
}
});
}
};
} catch (JSONException e) {
Util.postError(listener, new ServiceCommandError(0, "JSON Parse error", null));
return;
}
ResponseListener<Object> response = new ResponseListener<Object>() {
@Override
public void onError(ServiceCommandError error) {
Util.postError(listener, error);
}
@Override
public void onSuccess(Object object) {
Util.postSuccess(listener, new MediaLaunchObject(launchSession, getMediaControl(), getPlaylistControl()));
}
};
ServiceCommand<ResponseListener<Object>> command = new ServiceCommand<ResponseListener<Object>>(null, null, null, response);
mActiveCommands.put(requestId, command);
sendMessage(message, new ResponseListener<Object>() {
@Override
public void onError(ServiceCommandError error) {
Util.postError(listener, error);
}
@Override
public void onSuccess(Object object) {
}
});
}
use of com.connectsdk.service.command.ServiceCommand in project butter-android by butterproject.
the class WebOSWebAppSession method displayImage.
@Override
public void displayImage(final String url, final String mimeType, final String title, final String description, final String iconSrc, final MediaPlayer.LaunchListener listener) {
int requestIdNumber = getNextId();
final String requestId = String.format(Locale.US, "req%d", requestIdNumber);
JSONObject message = null;
try {
message = new JSONObject() {
{
putOpt("contentType", namespaceKey + "mediaCommand");
putOpt("mediaCommand", new JSONObject() {
{
putOpt("type", "displayImage");
putOpt("mediaURL", url);
putOpt("iconURL", iconSrc);
putOpt("title", title);
putOpt("description", description);
putOpt("mimeType", mimeType);
putOpt("requestId", requestId);
}
});
}
};
} catch (JSONException e) {
Util.postError(listener, new ServiceCommandError(0, "JSON Parse error", null));
return;
}
ResponseListener<Object> response = new ResponseListener<Object>() {
@Override
public void onError(ServiceCommandError error) {
Util.postError(listener, error);
}
@Override
public void onSuccess(Object object) {
Util.postSuccess(listener, new MediaLaunchObject(launchSession, getMediaControl()));
}
};
ServiceCommand<ResponseListener<Object>> command = new ServiceCommand<ResponseListener<Object>>(socket, null, null, response);
mActiveCommands.put(requestId, command);
sendP2PMessage(message, new ResponseListener<Object>() {
@Override
public void onError(ServiceCommandError error) {
Util.postError(listener, error);
}
@Override
public void onSuccess(Object object) {
}
});
}
use of com.connectsdk.service.command.ServiceCommand in project butter-android by butterproject.
the class WebOSTVKeyboardInput method sendData.
private void sendData() {
waiting = true;
String uri;
String typeTest = toSend.get(0);
JSONObject payload = new JSONObject();
if (typeTest.equals(ENTER)) {
toSend.remove(0);
uri = "ssap://com.webos.service.ime/sendEnterKey";
} else if (typeTest.equals(DELETE)) {
uri = "ssap://com.webos.service.ime/deleteCharacters";
int count = 0;
while (toSend.size() > 0 && toSend.get(0).equals(DELETE)) {
toSend.remove(0);
count++;
}
try {
payload.put("count", count);
} catch (JSONException e) {
e.printStackTrace();
}
} else {
uri = "ssap://com.webos.service.ime/insertText";
StringBuilder sb = new StringBuilder();
while (toSend.size() > 0 && !(toSend.get(0).equals(DELETE) || toSend.get(0).equals(ENTER))) {
String text = toSend.get(0);
sb.append(text);
toSend.remove(0);
}
try {
payload.put("text", sb.toString());
payload.put("replace", 0);
} catch (JSONException e) {
e.printStackTrace();
}
}
ResponseListener<Object> responseListener = new ResponseListener<Object>() {
@Override
public void onSuccess(Object response) {
waiting = false;
if (toSend.size() > 0)
sendData();
}
@Override
public void onError(ServiceCommandError error) {
waiting = false;
if (toSend.size() > 0)
sendData();
}
};
ServiceCommand<ResponseListener<Object>> request = new ServiceCommand<ResponseListener<Object>>(service, uri, payload, true, responseListener);
request.send();
}
Aggregations