summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrettyWhite <geekman3454@protonmail.com>2019-07-29 11:26:09 -0400
committerBrettyWhite <geekman3454@protonmail.com>2019-07-29 11:26:09 -0400
commitaaa0e7eb3b5e44f7c9089aa729d6245679849c01 (patch)
tree7bddab33b0cbbfaeb75c2bf1c7cefe491de299d6
parent29f28b0cf84f39e2fdde3c62311cb6dbc30db970 (diff)
downloadsdl_android-aaa0e7eb3b5e44f7c9089aa729d6245679849c01.tar.gz
tests for openMenu APIs
-rw-r--r--android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/MenuManagerTests.java28
-rw-r--r--base/src/main/java/com/smartdevicelink/managers/screen/BaseScreenManager.java19
-rw-r--r--base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseMenuManager.java71
-rw-r--r--base/src/main/java/com/smartdevicelink/proxy/rpc/ShowAppMenu.java4
4 files changed, 120 insertions, 2 deletions
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/MenuManagerTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/MenuManagerTests.java
index 73581cab4..675cc6721 100644
--- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/MenuManagerTests.java
+++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/MenuManagerTests.java
@@ -39,15 +39,19 @@ import com.smartdevicelink.managers.CompletionListener;
import com.smartdevicelink.managers.file.FileManager;
import com.smartdevicelink.managers.file.filetypes.SdlArtwork;
import com.smartdevicelink.protocol.enums.FunctionID;
+import com.smartdevicelink.proxy.RPCRequest;
+import com.smartdevicelink.proxy.RPCResponse;
import com.smartdevicelink.proxy.interfaces.ISdl;
import com.smartdevicelink.proxy.rpc.OnCommand;
import com.smartdevicelink.proxy.rpc.OnHMIStatus;
+import com.smartdevicelink.proxy.rpc.ShowAppMenu;
import com.smartdevicelink.proxy.rpc.enums.FileType;
import com.smartdevicelink.proxy.rpc.enums.HMILevel;
import com.smartdevicelink.proxy.rpc.enums.SystemContext;
import com.smartdevicelink.proxy.rpc.enums.TriggerSource;
import com.smartdevicelink.proxy.rpc.listeners.OnRPCNotificationListener;
+import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
@@ -425,6 +429,29 @@ public class MenuManagerTests extends AndroidTestCase2 {
assertEquals(menuManager.menuCells.size(), 0);
}
+ public void testOpeningMainMenu(){
+ // call open Menu
+ MenuManager mockMenuManager = mock(MenuManager.class);
+ mockMenuManager.openMenu();
+ verify(mockMenuManager, Mockito.times(1)).openMenu();
+ }
+
+ public void testOpeningSubMenuNullCells(){
+ // call open Menu
+ MenuManager mockMenuManager = mock(MenuManager.class);
+ MenuCell cell = mock(MenuCell.class);
+ mockMenuManager.menuCells = null;
+ assertFalse(mockMenuManager.openSubMenu(cell));
+ }
+
+ public void testOpeningSubMenu(){
+ // call open Menu
+ List<MenuCell> testCells = createTestCells();
+ menuManager.menuCells = testCells;
+ // has to get success response to be true
+ assertTrue(menuManager.openSubMenu(testCells.get(3)));
+ }
+
// HELPERS
// Emulate what happens when Core sends OnHMIStatus notification
@@ -460,6 +487,7 @@ public class MenuManagerTests extends AndroidTestCase2 {
MenuCell subCell2 = new MenuCell("SubCell 2",null, null, menuSelectionListenerSub2);
mainCell4 = new MenuCell("Test Cell 4", livio, Arrays.asList(subCell1,subCell2)); // sub menu parent cell
+ mainCell4.setCellId(4);
return Arrays.asList(mainCell1, mainCell2, mainCell3, mainCell4);
}
diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/BaseScreenManager.java b/base/src/main/java/com/smartdevicelink/managers/screen/BaseScreenManager.java
index cc33bae86..012a62d98 100644
--- a/base/src/main/java/com/smartdevicelink/managers/screen/BaseScreenManager.java
+++ b/base/src/main/java/com/smartdevicelink/managers/screen/BaseScreenManager.java
@@ -392,6 +392,8 @@ abstract class BaseScreenManager extends BaseSubManager {
this.voiceCommandManager.setVoiceCommands(voiceCommands);
}
+ // MENUS
+
/**
* The list of currently set menu cells
* @return a List of the currently set menu cells
@@ -425,6 +427,23 @@ abstract class BaseScreenManager extends BaseSubManager {
return this.menuManager.getDynamicMenuUpdatesMode();
}
+ /**
+ * Requires SDL RPC Version 6.0.0 or greater
+ * Opens the Main Menu
+ */
+ public void openMenu(){
+ this.menuManager.openMenu();
+ }
+
+ /**
+ * Requires SDL RPC Version 6.0.0 or greater
+ * Opens a subMenu. The cell you pass in must be constructed with {@link MenuCell(String,SdlArtwork,List)}
+ * @param cell - A <Strong>SubMenu</Strong> cell whose sub menu you wish to open
+ */
+ public void openSubMenu(@NonNull MenuCell cell){
+ this.menuManager.openSubMenu(cell);
+ }
+
// CHOICE SETS
/**
diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseMenuManager.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseMenuManager.java
index 140e4cacc..b0a7b3e1e 100644
--- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseMenuManager.java
+++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseMenuManager.java
@@ -54,6 +54,7 @@ import com.smartdevicelink.proxy.rpc.ImageField;
import com.smartdevicelink.proxy.rpc.MenuParams;
import com.smartdevicelink.proxy.rpc.OnCommand;
import com.smartdevicelink.proxy.rpc.OnHMIStatus;
+import com.smartdevicelink.proxy.rpc.ShowAppMenu;
import com.smartdevicelink.proxy.rpc.enums.DisplayType;
import com.smartdevicelink.proxy.rpc.enums.HMILevel;
import com.smartdevicelink.proxy.rpc.enums.ImageFieldName;
@@ -62,6 +63,7 @@ import com.smartdevicelink.proxy.rpc.enums.SystemCapabilityType;
import com.smartdevicelink.proxy.rpc.enums.SystemContext;
import com.smartdevicelink.proxy.rpc.listeners.OnMultipleRequestListener;
import com.smartdevicelink.proxy.rpc.listeners.OnRPCNotificationListener;
+import com.smartdevicelink.proxy.rpc.listeners.OnRPCResponseListener;
import com.smartdevicelink.util.DebugTool;
import org.json.JSONException;
@@ -245,6 +247,75 @@ abstract class BaseMenuManager extends BaseSubManager {
return this.dynamicMenuUpdatesMode;
}
+ // OPEN MENU RPCs
+
+ /**
+ * Opens the Main Menu
+ */
+ public void openMenu(){
+ ShowAppMenu showAppMenu = new ShowAppMenu();
+ showAppMenu.setOnRPCResponseListener(new OnRPCResponseListener() {
+ @Override
+ public void onResponse(int correlationId, RPCResponse response) {
+ if (response.getSuccess()){
+ DebugTool.logInfo("Open Main Menu Request Successful");
+ } else {
+ DebugTool.logError("Open Main Menu Request Failed");
+ }
+ }
+
+ @Override
+ public void onError(int correlationId, Result resultCode, String info){
+ DebugTool.logError("Open Main Menu onError: "+ resultCode+ " | Info: "+ info);
+ }
+ });
+ internalInterface.sendRPC(showAppMenu);
+ }
+
+ /**
+ * Opens a subMenu. The cell you pass in must be constructed with {@link MenuCell(String,SdlArtwork,List)}
+ * @param cell - A <Strong>SubMenu</Strong> cell whose sub menu you wish to open
+ */
+ public boolean openSubMenu(@NonNull MenuCell cell){
+
+ if (menuCells == null){
+ return false;
+ }
+ // We must see if we have a copy of this cell, since we clone the objects
+ for (MenuCell clonedCell : menuCells){
+ if (clonedCell.equals(cell)){
+ // We've found the correct sub menu cell
+ if (cell.getCellId() != MAX_ID) {
+ sendOpenSubMenu(cell.getCellId());
+ }
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private void sendOpenSubMenu(Integer id){
+
+ ShowAppMenu showAppMenu = new ShowAppMenu();
+ showAppMenu.setMenuID(id);
+ showAppMenu.setOnRPCResponseListener(new OnRPCResponseListener() {
+ @Override
+ public void onResponse(int correlationId, RPCResponse response) {
+ if (response.getSuccess()){
+ DebugTool.logInfo("Open Sub Menu Request Successful");
+ } else {
+ DebugTool.logError("Open Sub Menu Request Failed");
+ }
+ }
+
+ @Override
+ public void onError(int correlationId, Result resultCode, String info){
+ DebugTool.logError("Open Sub Menu onError: "+ resultCode+ " | Info: "+ info);
+ }
+ });
+ internalInterface.sendRPC(showAppMenu);
+ }
+
// UPDATING SYSTEM
// ROOT MENU
diff --git a/base/src/main/java/com/smartdevicelink/proxy/rpc/ShowAppMenu.java b/base/src/main/java/com/smartdevicelink/proxy/rpc/ShowAppMenu.java
index d95a07831..6c6c2e7c9 100644
--- a/base/src/main/java/com/smartdevicelink/proxy/rpc/ShowAppMenu.java
+++ b/base/src/main/java/com/smartdevicelink/proxy/rpc/ShowAppMenu.java
@@ -66,7 +66,7 @@ public class ShowAppMenu extends RPCRequest {
* If omitted the HMI opens the apps menu.
* If set to a sub-menu ID the HMI opens the corresponding sub-menu
* previously added using `AddSubMenu`.
- * @param menuID -
+ * @param menuID - The SubMenu ID to open
*/
public void setMenuID(Integer menuID){
setParameters(KEY_MENU_ID, menuID);
@@ -76,7 +76,7 @@ public class ShowAppMenu extends RPCRequest {
* If omitted the HMI opens the apps menu.
* If set to a sub-menu ID the HMI opens the corresponding sub-menu
* previously added using `AddSubMenu`.
- * @return -
+ * @return - MenuID int
*/
public Integer getMenuID(){
return getInteger(KEY_MENU_ID);