summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrett <3911458+BrettyWhite@users.noreply.github.com>2018-09-26 14:40:00 -0400
committerGitHub <noreply@github.com>2018-09-26 14:40:00 -0400
commitdaaac59ff5b1952df771c62e1675cadc2211bbf0 (patch)
tree506ad6487d3bd3d36a7548bee595514fe9ffdb4d
parentcdabc5f4f67aeb081d598a87fc9d19d204205430 (diff)
parent906a6719bb65236546bb90d38173ef93452c1ee3 (diff)
downloadsdl_android-daaac59ff5b1952df771c62e1675cadc2211bbf0.tar.gz
Merge pull request #864 from smartdevicelink/feature/issue_229
Add PLAY_PAUSE enum value
-rw-r--r--sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/ButtonNameTests.java3
-rw-r--r--sdl_android/src/main/java/com/smartdevicelink/proxy/RPCRequest.java4
-rw-r--r--sdl_android/src/main/java/com/smartdevicelink/proxy/SdlProxyBase.java95
-rw-r--r--sdl_android/src/main/java/com/smartdevicelink/proxy/rpc/RegisterAppInterfaceResponse.java17
-rw-r--r--sdl_android/src/main/java/com/smartdevicelink/proxy/rpc/enums/ButtonName.java26
5 files changed, 140 insertions, 5 deletions
diff --git a/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/ButtonNameTests.java b/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/ButtonNameTests.java
index e37eb2fd1..e823e7593 100644
--- a/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/ButtonNameTests.java
+++ b/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/enums/ButtonNameTests.java
@@ -10,7 +10,7 @@ import com.smartdevicelink.proxy.rpc.enums.ButtonName;
/**
* This is a unit test class for the SmartDeviceLink library project class :
- * {@link com.smartdevicelink.rpc.enums.ButtonName}
+ * {@link com.smartdevicelink.proxy.rpc.enums.ButtonName}
*/
public class ButtonNameTests extends TestCase {
@@ -199,6 +199,7 @@ public class ButtonNameTests extends TestCase {
enumTestList.add(ButtonName.SOURCE);
enumTestList.add(ButtonName.SHUFFLE);
enumTestList.add(ButtonName.REPEAT);
+ enumTestList.add(ButtonName.PLAY_PAUSE);
assertTrue("Enum value list does not match enum class list",
enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList));
diff --git a/sdl_android/src/main/java/com/smartdevicelink/proxy/RPCRequest.java b/sdl_android/src/main/java/com/smartdevicelink/proxy/RPCRequest.java
index 370ffe1ec..db493fecf 100644
--- a/sdl_android/src/main/java/com/smartdevicelink/proxy/RPCRequest.java
+++ b/sdl_android/src/main/java/com/smartdevicelink/proxy/RPCRequest.java
@@ -21,6 +21,10 @@ public class RPCRequest extends RPCMessage {
super(hash);
}
+ public RPCRequest(RPCRequest request){
+ super(request);
+ setCorrelationID(CorrelationIdGenerator.generateId());
+ }
public Integer getCorrelationID() {
//First we check to see if a correlation ID is set. If not, create one.
if(!function.containsKey(RPCMessage.KEY_CORRELATION_ID)){
diff --git a/sdl_android/src/main/java/com/smartdevicelink/proxy/SdlProxyBase.java b/sdl_android/src/main/java/com/smartdevicelink/proxy/SdlProxyBase.java
index 3a6ee954c..50713f013 100644
--- a/sdl_android/src/main/java/com/smartdevicelink/proxy/SdlProxyBase.java
+++ b/sdl_android/src/main/java/com/smartdevicelink/proxy/SdlProxyBase.java
@@ -13,6 +13,8 @@ import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.Hashtable;
import java.util.List;
import java.util.Vector;
@@ -46,6 +48,7 @@ import android.view.Display;
import android.view.InputDevice;
import android.view.MotionEvent;
import android.view.Surface;
+import android.widget.Button;
import com.smartdevicelink.Dispatcher.IDispatchingStrategy;
import com.smartdevicelink.Dispatcher.ProxyMessageDispatcher;
@@ -3354,6 +3357,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
final OnButtonPress msg = new OnButtonPress(hash);
msg.format(rpcSpecVersion, true);
+ final OnButtonPress onButtonPressCompat = (OnButtonPress)handleButtonNotificationFormatting(msg);
if (_callbackToUIThread) {
// Run in UI thread
_mainUIHandler.post(new Runnable() {
@@ -3361,17 +3365,25 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
public void run() {
_proxyListener.onOnButtonPress(msg);
onRPCNotificationReceived(msg);
+ if(onButtonPressCompat != null){
+ _proxyListener.onOnButtonPress(onButtonPressCompat);
+ }
}
});
} else {
_proxyListener.onOnButtonPress(msg);
onRPCNotificationReceived(msg);
+ if(onButtonPressCompat != null){
+ _proxyListener.onOnButtonPress(onButtonPressCompat);
+ }
}
} else if (functionName.equals(FunctionID.ON_BUTTON_EVENT.toString())) {
// OnButtonEvent
final OnButtonEvent msg = new OnButtonEvent(hash);
msg.format(rpcSpecVersion, true);
+ final OnButtonEvent onButtonEventCompat = (OnButtonEvent)handleButtonNotificationFormatting(msg);
+
if (_callbackToUIThread) {
// Run in UI thread
_mainUIHandler.post(new Runnable() {
@@ -3379,11 +3391,17 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
public void run() {
_proxyListener.onOnButtonEvent(msg);
onRPCNotificationReceived(msg);
+ if(onButtonEventCompat != null){
+ _proxyListener.onOnButtonEvent(onButtonEventCompat);
+ }
}
});
} else {
_proxyListener.onOnButtonEvent(msg);
onRPCNotificationReceived(msg);
+ if(onButtonEventCompat != null){
+ _proxyListener.onOnButtonEvent(onButtonEventCompat);
+ }
}
} else if (functionName.equals(FunctionID.ON_LANGUAGE_CHANGE.toString())) {
// OnLanguageChange
@@ -3637,6 +3655,58 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
SdlTrace.logProxyEvent("Proxy received RPC Message: " + functionName, SDL_LIB_TRACE_KEY);
}
+ //FIXME
+ /**
+ * Temporary method to bridge the new PLAY_PAUSE and OKAY button functionality with the old
+ * OK button name. This should be removed during the next major release
+ * @param notification
+ */
+ private RPCNotification handleButtonNotificationFormatting(RPCNotification notification){
+ if(FunctionID.ON_BUTTON_EVENT.toString().equals(notification.getFunctionName())
+ || FunctionID.ON_BUTTON_PRESS.toString().equals(notification.getFunctionName())){
+
+ ButtonName buttonName = (ButtonName)notification.getObject(ButtonName.class, OnButtonEvent.KEY_BUTTON_NAME);
+ ButtonName compatBtnName = null;
+
+ if(rpcSpecVersion != null && rpcSpecVersion.getMajor() >= 5){
+ if(ButtonName.PLAY_PAUSE.equals(buttonName)){
+ compatBtnName = ButtonName.OK;
+ }
+ }else{ // rpc spec version is either null or less than 5
+ if(ButtonName.OK.equals(buttonName)){
+ compatBtnName = ButtonName.PLAY_PAUSE;
+ }
+ }
+
+ try {
+ if (compatBtnName != null) { //There is a button name that needs to be swapped out
+ RPCNotification notification2;
+ //The following is done because there is currently no way to make a deep copy
+ //of an RPC. Since this code will be removed, it's ugliness is borderline acceptable.
+ if (notification instanceof OnButtonEvent) {
+ OnButtonEvent onButtonEvent = new OnButtonEvent();
+ onButtonEvent.setButtonEventMode(((OnButtonEvent) notification).getButtonEventMode());
+ onButtonEvent.setCustomButtonID(((OnButtonEvent) notification).getCustomButtonID());
+ notification2 = onButtonEvent;
+ } else if (notification instanceof OnButtonPress) {
+ OnButtonPress onButtonPress = new OnButtonPress();
+ onButtonPress.setButtonPressMode(((OnButtonPress) notification).getButtonPressMode());
+ onButtonPress.setCustomButtonName(((OnButtonPress) notification).getCustomButtonName());
+ notification2 = onButtonPress;
+ } else {
+ return null;
+ }
+
+ notification2.setParameters(OnButtonEvent.KEY_BUTTON_NAME, compatBtnName);
+ return notification2;
+ }
+ }catch (Exception e){
+ //Should never get here
+ }
+ }
+ return null;
+ }
+
/**
* Takes a list of RPCRequests and sends it to SDL in a synchronous fashion. Responses are captured through callback on OnMultipleRequestListener.
* For sending requests asynchronously, use sendRequests <br>
@@ -3793,8 +3863,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
throw new SdlException("Invalid correlation ID. The correlation ID, " + request.getCorrelationID()
+ " , is a reserved correlation ID.", SdlExceptionCause.RESERVED_CORRELATION_ID);
}
-
- // Throw exception if RPCRequest is sent when SDL is unavailable
+ // Throw exception if RPCRequest is sent when SDL is unavailable
if (!_appInterfaceRegisterd && !request.getFunctionName().equals(FunctionID.REGISTER_APP_INTERFACE.toString())) {
SdlTrace.logProxyEvent("Application attempted to send an RPCRequest (non-registerAppInterface), before the interface was registerd.", SDL_LIB_TRACE_KEY);
@@ -3810,6 +3879,28 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase>
", is un-allowed using the Advanced Lifecycle Management Model.", SdlExceptionCause.INCORRECT_LIFECYCLE_MODEL);
}
}
+
+ //FIXME this is temporary until the next major release of the library where OK is removed
+
+ if(FunctionID.SUBSCRIBE_BUTTON.toString().equals(request.getFunctionName())
+ || FunctionID.UNSUBSCRIBE_BUTTON.toString().equals(request.getFunctionName())
+ || FunctionID.BUTTON_PRESS.toString().equals(request.getFunctionName())){
+
+ ButtonName buttonName = (ButtonName)request.getObject(ButtonName.class, SubscribeButton.KEY_BUTTON_NAME);
+
+ if(rpcSpecVersion != null && rpcSpecVersion.getMajor() < 5) {
+
+ if (ButtonName.PLAY_PAUSE.equals(buttonName)) {
+ request.setParameters(SubscribeButton.KEY_BUTTON_NAME, ButtonName.OK);
+ }
+ } else { //Newer than version 5.0.0
+ if(ButtonName.OK.equals(buttonName)){
+ RPCRequest request2 = new RPCRequest(request);
+ request2.setParameters(SubscribeButton.KEY_BUTTON_NAME, ButtonName.PLAY_PAUSE);
+ sendRPCRequestPrivate(request2);
+ }
+ }
+ }
sendRPCRequestPrivate(request);
} // end-method
diff --git a/sdl_android/src/main/java/com/smartdevicelink/proxy/rpc/RegisterAppInterfaceResponse.java b/sdl_android/src/main/java/com/smartdevicelink/proxy/rpc/RegisterAppInterfaceResponse.java
index 13ecd9c75..746129a85 100644
--- a/sdl_android/src/main/java/com/smartdevicelink/proxy/rpc/RegisterAppInterfaceResponse.java
+++ b/sdl_android/src/main/java/com/smartdevicelink/proxy/rpc/RegisterAppInterfaceResponse.java
@@ -5,6 +5,7 @@ import android.support.annotation.NonNull;
import com.smartdevicelink.protocol.enums.FunctionID;
import com.smartdevicelink.proxy.RPCResponse;
import com.smartdevicelink.proxy.Version;
+import com.smartdevicelink.proxy.rpc.enums.ButtonName;
import com.smartdevicelink.proxy.rpc.enums.HmiZoneCapabilities;
import com.smartdevicelink.proxy.rpc.enums.Language;
import com.smartdevicelink.proxy.rpc.enums.PrerecordedSpeech;
@@ -85,6 +86,22 @@ public class RegisterAppInterfaceResponse extends RPCResponse {
setIconResumed(Boolean.FALSE);
}
+ List<ButtonCapabilities> capabilities = getButtonCapabilities();
+ if(capabilities != null){
+ List<ButtonCapabilities> additions = new ArrayList<>();
+ for(ButtonCapabilities capability : capabilities){
+ if(ButtonName.OK.equals(capability.getName())){
+ if(rpcVersion == null || rpcVersion.getMajor() < 5){
+ //If version is < 5, the play pause button must also be added
+ additions.add(new ButtonCapabilities(ButtonName.PLAY_PAUSE, capability.getShortPressAvailable(), capability.getLongPressAvailable(), capability.getUpDownAvailable()));
+ }
+ }
+ }
+ capabilities.addAll(additions);
+ setButtonCapabilities(capabilities);
+ }
+
+
super.format(rpcVersion,formatParams);
}
diff --git a/sdl_android/src/main/java/com/smartdevicelink/proxy/rpc/enums/ButtonName.java b/sdl_android/src/main/java/com/smartdevicelink/proxy/rpc/enums/ButtonName.java
index f478a78ee..6d4cecffc 100644
--- a/sdl_android/src/main/java/com/smartdevicelink/proxy/rpc/enums/ButtonName.java
+++ b/sdl_android/src/main/java/com/smartdevicelink/proxy/rpc/enums/ButtonName.java
@@ -23,10 +23,21 @@ package com.smartdevicelink.proxy.rpc.enums;
*/
public enum ButtonName{
/**
+ * <br><b>THIS ENUM VALUE WILL CHANGE IN FUNCITONALITY DURING THE NEXT MAJOR RELEASE!</b>
+ * <br><br>
+ * This ButtonName value originally was used for both the OK button and PLAY_PAUSE button. As of
+ * SmartDeviceLink 5.0.0, the functionality was broken out into the OK and PLAY_PAUSE buttons.
+ * <br><br> For this version of the library OK will be received for both OK and PLAY_PAUSE to
+ * mitigate a potential break in functionliaty. If the desire is only for the OK functionality,
+ * this button should still be used. If the desired functionality was actually for the play/pause
+ * toggle, then the new PLAY_PAUSE should be used.
+ * <br><br>
* Represents the button usually labeled "OK". A typical use of this button
- * is for the user to press it to make a selection.
- *
+ * is for the user to press it to make a selection (and until a major library version release,
+ * play pause toggle).
+ *
* @since SmartDeviceLink 1.0
+ * @see #PLAY_PAUSE
*/
OK,
/**
@@ -136,6 +147,17 @@ public enum ButtonName{
SOURCE,
SHUFFLE,
REPEAT,
+ /**
+ * Represents the play/pause button. A typical use of this button
+ * is for the user to press it to toggle between media playing and pausing.
+ *
+ * <br><br><b>NOTE:</b> This functionality used to be represented by the OK button.
+ *
+ * @since SmartDeviceLink 5.0
+ * @see #OK
+ */
+ PLAY_PAUSE,
+
;
public static ButtonName valueForString(String value) {