Skip to content

Commit

Permalink
Merge pull request #864 from smartdevicelink/feature/issue_229
Browse files Browse the repository at this point in the history
Add PLAY_PAUSE enum value
  • Loading branch information
BrettyWhite authored Sep 26, 2018
2 parents cdabc5f + 906a671 commit daaac59
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

/**
* 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 {

Expand Down Expand Up @@ -199,6 +199,7 @@ public void testListEnum() {
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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public RPCRequest(Hashtable<String, Object> hash) {
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)){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
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;
Expand Down Expand Up @@ -46,6 +48,7 @@
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;
Expand Down Expand Up @@ -3354,36 +3357,51 @@ public void run() {

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() {
@Override
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() {
@Override
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
Expand Down Expand Up @@ -3637,6 +3655,58 @@ public void run() {
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>
Expand Down Expand Up @@ -3793,8 +3863,7 @@ public void sendRPCRequest(RPCRequest request) throws SdlException {
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);
Expand All @@ -3810,6 +3879,28 @@ public void sendRPCRequest(RPCRequest request) throws SdlException {
", 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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;
Expand Down Expand Up @@ -85,6 +86,22 @@ public void format(com.smartdevicelink.util.Version rpcVersion, boolean formatPa
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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,21 @@
*/
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,
/**
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit daaac59

Please sign in to comment.