use of com.connectsdk.service.command.ServiceCommand in project butter-android by butterproject.
the class WebOSTVService method getLaunchPoints.
public void getLaunchPoints(final LaunchPointsListener listener) {
String uri = "ssap://com.webos.applicationManager/listLaunchPoints";
ResponseListener<Object> responseListener = new ResponseListener<Object>() {
@Override
public void onSuccess(Object response) {
try {
JSONObject jsonObj = (JSONObject) response;
JSONArray launchPoints = (JSONArray) jsonObj.get("launchPoints");
Util.postSuccess(listener, launchPoints);
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onError(ServiceCommandError error) {
Util.postError(listener, error);
}
};
ServiceCommand<ResponseListener<Object>> request = new ServiceCommand<ResponseListener<Object>>(this, uri, null, true, responseListener);
request.send();
}
use of com.connectsdk.service.command.ServiceCommand in project butter-android by butterproject.
the class WebOSTVServiceSocketClient method sendPairingKey.
public void sendPairingKey(String pairingKey) {
ResponseListener<Object> listener = new ResponseListener<Object>() {
@Override
public void onError(ServiceCommandError error) {
state = State.INITIAL;
if (mListener != null)
mListener.onFailWithError(error);
}
@Override
public void onSuccess(Object object) {
}
};
String uri = "ssap://pairing/setPin";
int dataId = this.nextRequestId++;
ServiceCommand<ResponseListener<Object>> command = new ServiceCommand<ResponseListener<Object>>(this, null, null, listener);
command.setRequestId(dataId);
JSONObject headers = new JSONObject();
JSONObject payload = new JSONObject();
try {
headers.put("type", "request");
headers.put("id", dataId);
headers.put("uri", uri);
payload.put("pin", pairingKey);
} catch (JSONException e) {
e.printStackTrace();
}
requests.put(dataId, command);
sendMessage(headers, payload);
}
use of com.connectsdk.service.command.ServiceCommand in project butter-android by butterproject.
the class WebOSTVServiceSocketClient method helloTV.
private void helloTV() {
Context context = DiscoveryManager.getInstance().getContext();
PackageManager packageManager = context.getPackageManager();
// app Id
String packageName = context.getPackageName();
// SDK Version
String sdkVersion = DiscoveryManager.CONNECT_SDK_VERSION;
// Device Model
String deviceModel = Build.MODEL;
// OS Version
String OSVersion = String.valueOf(android.os.Build.VERSION.SDK_INT);
// resolution
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
@SuppressWarnings("deprecation") int // deprecated, but still needed for supporting API levels 10-12
width = display.getWidth();
@SuppressWarnings("deprecation") int // deprecated, but still needed for supporting API levels 10-12
height = display.getHeight();
String screenResolution = String.format("%dx%d", width, height);
// app Name
ApplicationInfo applicationInfo;
try {
applicationInfo = packageManager.getApplicationInfo(context.getPackageName(), 0);
} catch (final NameNotFoundException e) {
applicationInfo = null;
}
String applicationName = (String) (applicationInfo != null ? packageManager.getApplicationLabel(applicationInfo) : "(unknown)");
// app Region
Locale current = context.getResources().getConfiguration().locale;
String appRegion = current.getDisplayCountry();
JSONObject payload = new JSONObject();
try {
payload.put("sdkVersion", sdkVersion);
payload.put("deviceModel", deviceModel);
payload.put("OSVersion", OSVersion);
payload.put("resolution", screenResolution);
payload.put("appId", packageName);
payload.put("appName", applicationName);
payload.put("appRegion", appRegion);
} catch (JSONException e) {
e.printStackTrace();
}
int dataId = this.nextRequestId++;
JSONObject sendData = new JSONObject();
try {
sendData.put("id", dataId);
sendData.put("type", "hello");
sendData.put("payload", payload);
} catch (JSONException e) {
e.printStackTrace();
}
ServiceCommand<ResponseListener<Object>> request = new ServiceCommand<ResponseListener<Object>>(this, null, sendData, true, null);
this.sendCommandImmediately(request);
}
use of com.connectsdk.service.command.ServiceCommand in project butter-android by butterproject.
the class WebOSWebAppSession method connect.
private void connect(final Boolean joinOnly, final ResponseListener<Object> connectionListener) {
if (socket != null && socket.getState() == WebOSTVServiceSocketClient.State.CONNECTING) {
if (connectionListener != null) {
connectionListener.onError(new ServiceCommandError(0, "You have a connection request pending, please wait until it has finished", null));
}
return;
}
if (isConnected()) {
if (connectionListener != null)
connectionListener.onSuccess(null);
return;
}
mConnectionListener = new ResponseListener<ServiceCommand<ResponseListener<Object>>>() {
@Override
public void onError(ServiceCommandError error) {
if (socket != null)
disconnectFromWebApp();
if (connectionListener != null) {
if (error == null) {
error = new ServiceCommandError(0, "Unknown error connecting to web app", null);
}
connectionListener.onError(error);
}
}
@Override
public void onSuccess(ServiceCommand<ResponseListener<Object>> object) {
ResponseListener<Object> finalConnectionListener = new ResponseListener<Object>() {
@Override
public void onError(ServiceCommandError error) {
disconnectFromWebApp();
if (connectionListener != null)
connectionListener.onError(error);
}
@Override
public void onSuccess(Object object) {
connected = true;
if (connectionListener != null)
connectionListener.onSuccess(object);
}
};
service.connectToWebApp(WebOSWebAppSession.this, joinOnly, finalConnectionListener);
}
};
if (socket != null) {
if (socket.isConnected())
mConnectionListener.onSuccess(null);
else
socket.connect();
} else {
socket = new WebOSTVServiceSocketClient(service, WebOSTVServiceSocketClient.getURI(service));
socket.setListener(mSocketListener);
socket.connect();
}
}
use of com.connectsdk.service.command.ServiceCommand in project butter-android by butterproject.
the class WebOSWebAppSession method getPosition.
@Override
public void getPosition(final PositionListener 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", "getPosition");
put("requestId", requestId);
}
});
}
};
} catch (JSONException e) {
Util.postError(listener, new ServiceCommandError(0, "JSON Parse error", null));
}
ServiceCommand<ResponseListener<Object>> command = new ServiceCommand<ResponseListener<Object>>(null, null, null, new ResponseListener<Object>() {
@Override
public void onSuccess(Object response) {
try {
long position = ((JSONObject) response).getLong("position");
Util.postSuccess(listener, position * 1000);
} catch (JSONException e) {
this.onError(new ServiceCommandError(0, "JSON Parse error", null));
}
}
@Override
public void onError(ServiceCommandError error) {
Util.postError(listener, error);
}
});
mActiveCommands.put(requestId, command);
sendMessage(message, new ResponseListener<Object>() {
@Override
public void onSuccess(Object response) {
}
@Override
public void onError(ServiceCommandError error) {
Util.postError(listener, error);
}
});
}
Aggregations