summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Henigan <robert.henigan@livio.io>2021-03-12 11:07:31 -0500
committerGitHub <noreply@github.com>2021-03-12 11:07:31 -0500
commit82c75e74b95486c4cc6a10acc83bfefc6192d85e (patch)
tree2a315c2c5b87c42caa185c64b55ec7ed9a26ea00
parent6ace4918e482fc1661c0ec578a83c0dc93e95112 (diff)
downloadsdl_android-82c75e74b95486c4cc6a10acc83bfefc6192d85e.tar.gz
Fix Main Menu UI updates do not take text field name into account (#1629)
* Check for textFieldNames * Review Feedback * Remove empty line seperating doc from method * Update MenuCell Constructors * Update JavaSE MenuCell Constructors Co-authored-by: Henigan <rheniga1@MGC12Z921DLVCG.fbpld77.ford.com>
-rwxr-xr-xandroid/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlService.java14
-rw-r--r--base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseMenuManager.java104
-rw-r--r--javaSE/hello_sdl_java/src/main/java/com/smartdevicelink/java/SdlService.java14
3 files changed, 108 insertions, 24 deletions
diff --git a/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlService.java b/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlService.java
index e4119d16c..c6e9ce3ef 100755
--- a/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlService.java
+++ b/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlService.java
@@ -298,7 +298,7 @@ public class SdlService extends Service {
// some voice commands
List<String> voice2 = Collections.singletonList("Cell two");
- MenuCell mainCell1 = new MenuCell("Test Cell 1 (speak)", livio, null, new MenuSelectionListener() {
+ MenuCell mainCell1 = new MenuCell("Test Cell 1 (speak)", "Secondary Text", "Tertiary Text", livio, livio, null, new MenuSelectionListener() {
@Override
public void onTriggered(TriggerSource trigger) {
Log.i(TAG, "Test cell 1 triggered. Source: " + trigger.toString());
@@ -306,7 +306,7 @@ public class SdlService extends Service {
}
});
- MenuCell mainCell2 = new MenuCell("Test Cell 2", null, voice2, new MenuSelectionListener() {
+ MenuCell mainCell2 = new MenuCell("Test Cell 2", "Secondary Text", null, null, null, voice2, new MenuSelectionListener() {
@Override
public void onTriggered(TriggerSource trigger) {
Log.i(TAG, "Test cell 2 triggered. Source: " + trigger.toString());
@@ -315,14 +315,14 @@ public class SdlService extends Service {
// SUB MENU
- MenuCell subCell1 = new MenuCell("SubCell 1", null, null, new MenuSelectionListener() {
+ MenuCell subCell1 = new MenuCell("SubCell 1", null, null, null, null, null, new MenuSelectionListener() {
@Override
public void onTriggered(TriggerSource trigger) {
Log.i(TAG, "Sub cell 1 triggered. Source: " + trigger.toString());
}
});
- MenuCell subCell2 = new MenuCell("SubCell 2", null, null, new MenuSelectionListener() {
+ MenuCell subCell2 = new MenuCell("SubCell 2", null, null, null, null, null, new MenuSelectionListener() {
@Override
public void onTriggered(TriggerSource trigger) {
Log.i(TAG, "Sub cell 2 triggered. Source: " + trigger.toString());
@@ -330,16 +330,16 @@ public class SdlService extends Service {
});
// sub menu parent cell
- MenuCell mainCell3 = new MenuCell("Test Cell 3 (sub menu)", MenuLayout.LIST, null, Arrays.asList(subCell1, subCell2));
+ MenuCell mainCell3 = new MenuCell("Test Cell 3 (sub menu)", null, null, MenuLayout.LIST, null, null, Arrays.asList(subCell1, subCell2));
- MenuCell mainCell4 = new MenuCell("Show Perform Interaction", null, null, new MenuSelectionListener() {
+ MenuCell mainCell4 = new MenuCell("Show Perform Interaction", null, null, null, null, null, new MenuSelectionListener() {
@Override
public void onTriggered(TriggerSource trigger) {
showPerformInteraction();
}
});
- MenuCell mainCell5 = new MenuCell("Clear the menu", null, null, new MenuSelectionListener() {
+ MenuCell mainCell5 = new MenuCell("Clear the menu", null, null, null,null, null, new MenuSelectionListener() {
@Override
public void onTriggered(TriggerSource trigger) {
Log.i(TAG, "Clearing Menu. Source: " + trigger.toString());
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 86760c889..f39423b1a 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
@@ -65,6 +65,7 @@ import com.smartdevicelink.proxy.rpc.enums.ImageFieldName;
import com.smartdevicelink.proxy.rpc.enums.PredefinedWindows;
import com.smartdevicelink.proxy.rpc.enums.SystemCapabilityType;
import com.smartdevicelink.proxy.rpc.enums.SystemContext;
+import com.smartdevicelink.proxy.rpc.enums.TextFieldName;
import com.smartdevicelink.proxy.rpc.listeners.OnMultipleRequestListener;
import com.smartdevicelink.proxy.rpc.listeners.OnRPCNotificationListener;
import com.smartdevicelink.proxy.rpc.listeners.OnRPCResponseListener;
@@ -740,6 +741,12 @@ abstract class BaseMenuManager extends BaseSubManager {
// ARTWORKS
+ /**
+ * Get an array of artwork that needs to be uploaded from a list of menu cells
+ *
+ * @param cells List of MenuCell's to check
+ * @return List of artwork that needs to be uploaded
+ */
private List<SdlArtwork> findAllArtworksToBeUploadedFromCells(List<MenuCell> cells) {
// Make sure we can use images in the menus
if (!hasImageFieldOfName(ImageFieldName.cmdIcon)) {
@@ -770,6 +777,18 @@ abstract class BaseMenuManager extends BaseSubManager {
return artworks;
}
+ /**
+ * Determine if cells should or should not be uploaded to the head unit with artworks.
+ *
+ * No artworks will be uploaded if:
+ *
+ * 1. If any cell has a dynamic artwork that is not uploaded
+ * 2. If any cell contains a secondary artwork may be used on the head unit, and the cell has a dynamic secondary artwork that is not uploaded
+ * 3. If any cell's subcells fail check (1) or (2)
+ *
+ * @param cells List of MenuCell's to check
+ * @return True if the cells should be uploaded with artwork, false if they should not
+ */
private boolean shouldRPCsIncludeImages(List<MenuCell> cells) {
for (MenuCell cell : cells) {
SdlArtwork artwork = cell.getIcon();
@@ -784,8 +803,8 @@ abstract class BaseMenuManager extends BaseSubManager {
if (secondaryArtwork != null && !secondaryArtwork.isStaticIcon() && fileManager.get() != null && !fileManager.get().hasUploadedFile(secondaryArtwork)) {
return false;
}
- } else if (cell.getSubCells() != null && cell.getSubCells().size() > 0) {
- return shouldRPCsIncludeImages(cell.getSubCells());
+ } else if (cell.getSubCells() != null && cell.getSubCells().size() > 0 && !shouldRPCsIncludeImages(cell.getSubCells())) {
+ return false;
}
}
return true;
@@ -795,6 +814,10 @@ abstract class BaseMenuManager extends BaseSubManager {
return defaultMainWindowCapability == null || ManagerUtility.WindowCapabilityUtility.hasImageFieldOfName(defaultMainWindowCapability, imageFieldName);
}
+ private boolean hasTextFieldOfName(TextFieldName textFieldName) {
+ return defaultMainWindowCapability == null || ManagerUtility.WindowCapabilityUtility.hasTextFieldOfName(defaultMainWindowCapability, textFieldName);
+ }
+
// IDs
private void updateIdsOnDynamicCells(List<MenuCell> dynamicCells) {
@@ -841,6 +864,13 @@ abstract class BaseMenuManager extends BaseSubManager {
return null;
}
+
+ /**
+ * Assign cell ids on an array of menu cells given a parent id (or no parent id)
+ *
+ * @param cells List of menu cells to update
+ * @param parentId The parent id to assign if needed
+ */
private void updateIdsOnMenuCells(List<MenuCell> cells, int parentId) {
for (MenuCell cell : cells) {
int newId = ++lastMenuId;
@@ -880,6 +910,12 @@ abstract class BaseMenuManager extends BaseSubManager {
// DELETES
+ /**
+ * Create an array of DeleteCommand and DeleteSubMenu RPCs from an ArrayList of menu cells
+ *
+ * @param cells List of menu cells to use
+ * @return List of DeleteCommand and DeletedSubmenu RPCs
+ */
private List<RPCRequest> createDeleteRPCsForCells(List<MenuCell> cells) {
List<RPCRequest> deletes = new ArrayList<>();
for (MenuCell cell : cells) {
@@ -896,6 +932,14 @@ abstract class BaseMenuManager extends BaseSubManager {
// COMMANDS / SUBMENU RPCs
+ /**
+ * This method will receive the cells to be added. It will then build an array of add commands using the correct index to position the new items in the correct location.
+ * e.g. If the new menu array is [A, B, C, D] but only [C, D] are new we need to pass [A, B , C , D] so C and D can be added to index 2 and 3 respectively.
+ *
+ * @param cellsToAdd List of MenuCell's that will be added to the menu, this array must contain only cells that are not already in the menu.
+ * @param shouldHaveArtwork Boolean that indicates whether artwork should be applied to the RPC or not
+ * @return List of RPCRequest addCommands
+ */
private List<RPCRequest> mainMenuCommandsForCells(List<MenuCell> cellsToAdd, boolean shouldHaveArtwork) {
List<RPCRequest> builtCommands = new ArrayList<>();
@@ -917,6 +961,13 @@ abstract class BaseMenuManager extends BaseSubManager {
return builtCommands;
}
+ /**
+ * Creates AddSubMenu RPCs for the passed array of menu cells, AND all of those cells' subcell RPCs, both AddCommands and AddSubMenus
+ *
+ * @param cells List of MenuCell's to create RPCs for
+ * @param shouldHaveArtwork Boolean that indicates whether artwork should be applied to the RPC or not
+ * @return An List of RPCs of AddSubMenus and their associated subcell RPCs
+ */
private List<RPCRequest> subMenuCommandsForCells(List<MenuCell> cells, boolean shouldHaveArtwork) {
List<RPCRequest> builtCommands = new ArrayList<>();
for (MenuCell cell : cells) {
@@ -927,6 +978,13 @@ abstract class BaseMenuManager extends BaseSubManager {
return builtCommands;
}
+ /**
+ * Creates AddCommand and AddSubMenu RPCs for a passed array of cells, AND all of those cells' subcell RPCs, both AddCommands and AddSubmenus
+ *
+ * @param cells List of MenuCell's to create RPCs for
+ * @param shouldHaveArtwork Boolean that indicates whether artwork should be applied to the RPC or not
+ * @return An List of RPCs of AddCommand and AddSubMenus for the array of menu cells and their subcells, recursively
+ */
List<RPCRequest> allCommandsForCells(List<MenuCell> cells, boolean shouldHaveArtwork) {
List<RPCRequest> builtCommands = new ArrayList<>();
@@ -959,11 +1017,19 @@ abstract class BaseMenuManager extends BaseSubManager {
return builtCommands;
}
+ /**
+ * An individual AddCommand RPC for a given MenuCell
+ *
+ * @param cell MenuCell to create RPCs for
+ * @param shouldHaveArtwork Boolean that indicates whether artwork should be applied to the RPC or not
+ * @param position The position the AddCommand RPC should be given
+ * @return The AddCommand RPC
+ */
private AddCommand commandForMenuCell(MenuCell cell, boolean shouldHaveArtwork, int position) {
MenuParams params = new MenuParams(cell.getUniqueTitle());
- params.setSecondaryText((cell.getSecondaryText() != null && cell.getSecondaryText().length() == 0) ? null : cell.getSecondaryText());
- params.setTertiaryText((cell.getTertiaryText() != null && cell.getTertiaryText().length() == 0) ? null : cell.getTertiaryText());
+ params.setSecondaryText((cell.getSecondaryText() != null && cell.getSecondaryText().length() > 0 && hasTextFieldOfName(TextFieldName.menuCommandSecondaryText)) ? cell.getSecondaryText() : null);
+ params.setTertiaryText((cell.getTertiaryText() != null && cell.getTertiaryText().length() > 0 && hasTextFieldOfName(TextFieldName.menuCommandTertiaryText)) ? cell.getTertiaryText() : null);
params.setParentID(cell.getParentCellId() != MAX_ID ? cell.getParentCellId() : null);
params.setPosition(position);
@@ -980,10 +1046,18 @@ abstract class BaseMenuManager extends BaseSubManager {
return command;
}
+ /**
+ * An individual AddSubMenu RPC for a given MenuCell
+ *
+ * @param cell The cell to create the RPC for
+ * @param shouldHaveArtwork Whether artwork should be applied to the RPC
+ * @param position The position the AddSubMenu RPC should be given
+ * @return The AddSubMenu RPC
+ */
private AddSubMenu subMenuCommandForMenuCell(MenuCell cell, boolean shouldHaveArtwork, int position) {
AddSubMenu subMenu = new AddSubMenu(cell.getCellId(), cell.getUniqueTitle());
- subMenu.setSecondaryText((cell.getSecondaryText() != null && cell.getSecondaryText().length() == 0) ? null : cell.getSecondaryText());
- subMenu.setTertiaryText((cell.getTertiaryText() != null && cell.getTertiaryText().length() == 0) ? null : cell.getTertiaryText());
+ subMenu.setSecondaryText((cell.getSecondaryText() != null && cell.getSecondaryText().length() > 0 && hasTextFieldOfName(TextFieldName.menuSubMenuSecondaryText)) ? cell.getSecondaryText() : null);
+ subMenu.setTertiaryText((cell.getTertiaryText() != null && cell.getTertiaryText().length() > 0 && hasTextFieldOfName(TextFieldName.menuSubMenuTertiaryText)) ? cell.getTertiaryText() : null);
subMenu.setPosition(position);
if (cell.getSubMenuLayout() != null) {
subMenu.setMenuLayout(cell.getSubMenuLayout());
@@ -997,6 +1071,14 @@ abstract class BaseMenuManager extends BaseSubManager {
// CELL COMMAND HANDLING
+
+ /**
+ * Call a listener for a currently displayed MenuCell based on the incoming OnCommand notification
+ *
+ * @param cells List of MenuCell's to check (including their subcells)
+ * @param command OnCommand notification retrieved
+ * @return True if the handler was found, false if it was not found
+ */
private boolean callListenerForCells(List<MenuCell> cells, OnCommand command) {
if (cells != null && cells.size() > 0 && command != null) {
for (MenuCell cell : cells) {
@@ -1379,11 +1461,13 @@ abstract class BaseMenuManager extends BaseSubManager {
}
}
- /**
- Check for cell lists with completely duplicate information, or any duplicate voiceCommands
- @param cells The cells you will be adding
- @return Boolean that indicates whether menuCells are unique or not
+ /**
+ * Check for cell lists with completely duplicate information, or any duplicate voiceCommands
+ *
+ * @param cells List of MenuCell's you will be adding
+ * @param allVoiceCommands List of String's for VoiceCommands (Used for recursive calls to check voiceCommands of the cells)
+ * @return Boolean that indicates whether menuCells are unique or not
*/
private boolean menuCellsAreUnique(List<MenuCell> cells, ArrayList<String> allVoiceCommands) {
//Check all voice commands for identical items and check each list of cells for identical cells
diff --git a/javaSE/hello_sdl_java/src/main/java/com/smartdevicelink/java/SdlService.java b/javaSE/hello_sdl_java/src/main/java/com/smartdevicelink/java/SdlService.java
index 8b15abaf4..c106b03fa 100644
--- a/javaSE/hello_sdl_java/src/main/java/com/smartdevicelink/java/SdlService.java
+++ b/javaSE/hello_sdl_java/src/main/java/com/smartdevicelink/java/SdlService.java
@@ -247,7 +247,7 @@ public class SdlService {
// some voice commands
List<String> voice2 = Collections.singletonList("Cell two");
- MenuCell mainCell1 = new MenuCell("Test Cell 1 (speak)", livio, null, new MenuSelectionListener() {
+ MenuCell mainCell1 = new MenuCell("Test Cell 1 (speak)", "Secondary Text", "Tertiary Text", livio, livio, null, new MenuSelectionListener() {
@Override
public void onTriggered(TriggerSource trigger) {
DebugTool.logInfo(TAG, "Test cell 1 triggered. Source: " + trigger.toString());
@@ -255,7 +255,7 @@ public class SdlService {
}
});
- MenuCell mainCell2 = new MenuCell("Test Cell 2", null, voice2, new MenuSelectionListener() {
+ MenuCell mainCell2 = new MenuCell("Test Cell 2", "Secondary Text", null, null, null, voice2, new MenuSelectionListener() {
@Override
public void onTriggered(TriggerSource trigger) {
DebugTool.logInfo(TAG, "Test cell 2 triggered. Source: " + trigger.toString());
@@ -264,14 +264,14 @@ public class SdlService {
// SUB MENU
- MenuCell subCell1 = new MenuCell("SubCell 1", null, null, new MenuSelectionListener() {
+ MenuCell subCell1 = new MenuCell("SubCell 1", null, null, null, null, null, new MenuSelectionListener() {
@Override
public void onTriggered(TriggerSource trigger) {
DebugTool.logInfo(TAG, "Sub cell 1 triggered. Source: " + trigger.toString());
}
});
- MenuCell subCell2 = new MenuCell("SubCell 2", null, null, new MenuSelectionListener() {
+ MenuCell subCell2 = new MenuCell("SubCell 2", null, null, null, null, null, new MenuSelectionListener() {
@Override
public void onTriggered(TriggerSource trigger) {
DebugTool.logInfo(TAG, "Sub cell 2 triggered. Source: " + trigger.toString());
@@ -279,16 +279,16 @@ public class SdlService {
});
// sub menu parent cell
- MenuCell mainCell3 = new MenuCell("Test Cell 3 (sub menu)", MenuLayout.LIST, null, Arrays.asList(subCell1, subCell2));
+ MenuCell mainCell3 = new MenuCell("Test Cell 3 (sub menu)", null, null, MenuLayout.LIST, null, null, Arrays.asList(subCell1, subCell2));
- MenuCell mainCell4 = new MenuCell("Show Perform Interaction", null, null, new MenuSelectionListener() {
+ MenuCell mainCell4 = new MenuCell("Show Perform Interaction", null, null, null, null, null, new MenuSelectionListener() {
@Override
public void onTriggered(TriggerSource trigger) {
showPerformInteraction();
}
});
- MenuCell mainCell5 = new MenuCell("Clear the menu", null, null, new MenuSelectionListener() {
+ MenuCell mainCell5 = new MenuCell("Clear the menu", null, null, null,null, null, new MenuSelectionListener() {
@Override
public void onTriggered(TriggerSource trigger) {
DebugTool.logInfo(TAG, "Clearing Menu. Source: " + trigger.toString());