From e9469c8bc3d2fd5a0a4f27c2538a913e3ea1c3eb Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Wed, 24 Apr 2019 09:30:03 -0400 Subject: start of menu manager, getting some files made --- .../managers/screen/menu/BaseMenuManager.java | 48 ++++++++++++++++++++++ .../screen/menu/BaseVoiceCommandManager.java | 46 +++++++++++++++++++++ .../managers/screen/menu/cells/MenuCell.java | 36 ++++++++++++++++ .../managers/screen/menu/cells/VoiceCommand.java | 36 ++++++++++++++++ .../managers/screen/menu/MenuManager.java | 44 ++++++++++++++++++++ .../managers/screen/menu/VoiceCommandManager.java | 44 ++++++++++++++++++++ 6 files changed, 254 insertions(+) create mode 100644 base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseMenuManager.java create mode 100644 base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java create mode 100644 base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java create mode 100644 base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/VoiceCommand.java create mode 100644 javaSE/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManager.java create mode 100644 javaSE/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManager.java 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 new file mode 100644 index 000000000..b0b0698c1 --- /dev/null +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseMenuManager.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +package com.smartdevicelink.managers.screen.menu; + +import android.support.annotation.NonNull; + +import com.smartdevicelink.managers.BaseSubManager; +import com.smartdevicelink.proxy.interfaces.ISdl; + +abstract class BaseMenuManager extends BaseSubManager { + + + public BaseMenuManager(@NonNull ISdl internalInterface) { + super(internalInterface); + } + + +} diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java new file mode 100644 index 000000000..6ce102d16 --- /dev/null +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +package com.smartdevicelink.managers.screen.menu; + +import android.support.annotation.NonNull; + +import com.smartdevicelink.managers.BaseSubManager; +import com.smartdevicelink.proxy.interfaces.ISdl; + +abstract class BaseVoiceCommandManager extends BaseSubManager { + + + public BaseVoiceCommandManager(@NonNull ISdl internalInterface) { + super(internalInterface); + } +} diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java new file mode 100644 index 000000000..45c7030e7 --- /dev/null +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +package com.smartdevicelink.managers.screen.menu.cells; + +public class MenuCell { +} diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/VoiceCommand.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/VoiceCommand.java new file mode 100644 index 000000000..bcc65e0b4 --- /dev/null +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/VoiceCommand.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +package com.smartdevicelink.managers.screen.menu.cells; + +public class VoiceCommand { +} diff --git a/javaSE/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManager.java b/javaSE/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManager.java new file mode 100644 index 000000000..8819d2386 --- /dev/null +++ b/javaSE/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManager.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +package com.smartdevicelink.managers.screen.menu; + +import com.smartdevicelink.proxy.interfaces.ISdl; + +public class MenuManager extends BaseMenuManager { + + public MenuManager(ISdl internalInterface) { + // setup + super(internalInterface); + } + +} diff --git a/javaSE/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManager.java b/javaSE/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManager.java new file mode 100644 index 000000000..2d48875a5 --- /dev/null +++ b/javaSE/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManager.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +package com.smartdevicelink.managers.screen.menu; + +import com.smartdevicelink.proxy.interfaces.ISdl; + +public class VoiceCommandManager extends BaseVoiceCommandManager { + + public VoiceCommandManager(ISdl internalInterface) { + // setup + super(internalInterface); + } + +} -- cgit v1.2.1 From 12a3a1734f100d41072868b6f0f2f1e64e8058e2 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Wed, 24 Apr 2019 11:51:40 -0400 Subject: setters/getters done for menucell, need constructors --- .../screen/menu/MenuSelectionListener.java | 41 ++++++ .../managers/screen/menu/cells/MenuCell.java | 157 +++++++++++++++++++++ .../managers/screen/menu/cells/VoiceCommand.java | 3 + 3 files changed, 201 insertions(+) create mode 100644 base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuSelectionListener.java diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuSelectionListener.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuSelectionListener.java new file mode 100644 index 000000000..5c9ed5ce4 --- /dev/null +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuSelectionListener.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +package com.smartdevicelink.managers.screen.menu; + +import com.smartdevicelink.proxy.rpc.enums.TriggerSource; + +public interface MenuSelectionListener { + + void onTriggered(TriggerSource trigger); + +} diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java index 45c7030e7..9f5d3e6fb 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java @@ -32,5 +32,162 @@ package com.smartdevicelink.managers.screen.menu.cells; +import android.support.annotation.NonNull; + +import com.smartdevicelink.managers.file.filetypes.SdlArtwork; +import com.smartdevicelink.managers.screen.menu.MenuSelectionListener; + +import java.util.List; + public class MenuCell { + + /** + * The cell's text to be displayed + */ + private String title; + + /** + * The cell's icon to be displayed + */ + private SdlArtwork icon; + + /** + * The strings the user can say to activate this voice command + */ + private List voiceCommands; + + /** + * If this is not null, this cell will be a sub-menu button, displaying the sub-cells in a menu when pressed. + */ + private List subCells; + + /** + * The listener that will be called when the command is activated + */ + private MenuSelectionListener menuSelectionListener; + + private int parentCellId; + private int cellId; + + + // CONSTRUCTORS + + public MenuCell() { + + } + + + // SETTERS / GETTERS + + /** + * Sets the title of the menu cell + * @param title - the title of the cell. Required + */ + public void setTitle(@NonNull String title){ + this.title = title; + } + + /** + * Gets the title of the menu cell + * @return The title of the cell object + */ + public String getTitle(){ + return title; + } + + /** + * Sets the icon of the menu cell + * @param icon - the icon being set, of type {@link SdlArtwork} + */ + public void setIcon(SdlArtwork icon){ + this.icon = icon; + } + + /** + * Gets the icon for the cell + * @return the {@link SdlArtwork} icon for the cell + */ + public SdlArtwork getIcon() { + return icon; + } + + /** + * A list of Strings that will be used for voice commands + * @param voiceCommands - the string list used by the IVI system for voice commands + */ + public void setVoiceCommands(List voiceCommands) { + this.voiceCommands = voiceCommands; + } + + /** + * the string list used by the IVI system for voice commands + * @return The String List used by the menu cell object for voice commands + */ + public List getVoiceCommands() { + return voiceCommands; + } + + /** + * The list of MenuCells that can be set as subCells + * @param subCells - the list of subCells for this menu item + */ + public void setSubCells(List subCells) { + this.subCells = subCells; + } + + /** + * The list of subCells for this menu item + * @return a list of MenuCells that are the subCells for this menu item + */ + public List getSubCells() { + return subCells; + } + + /** + * The listener for when a menu item is selected + * @param menuSelectionListener the listener for this menuCell object + */ + public void setMenuSelectionListener(MenuSelectionListener menuSelectionListener) { + this.menuSelectionListener = menuSelectionListener; + } + + /** + * The listener that gets triggered when the menuCell object is selected + * @return the MenuSelectionListener for the cell + */ + public MenuSelectionListener getMenuSelectionListener() { + return menuSelectionListener; + } + + /** + * Set the cell Id + * @param cellId - the cell Id + */ + private void setCellId(int cellId) { + this.cellId = cellId; + } + + /** + * Get the cellId + * @return the cellId for this menuCell + */ + private int getCellId() { + return cellId; + } + + /** + * Sets the ParentCellId + * @param parentCellId the parent cell's Id + */ + private void setParentCellId(int parentCellId) { + this.parentCellId = parentCellId; + } + + /** + * Get the parent cell's Id + * @return the parent cell's Id + */ + private int getParentCellId() { + return parentCellId; + } } diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/VoiceCommand.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/VoiceCommand.java index bcc65e0b4..7450995dc 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/VoiceCommand.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/VoiceCommand.java @@ -33,4 +33,7 @@ package com.smartdevicelink.managers.screen.menu.cells; public class VoiceCommand { + + + } -- cgit v1.2.1 From f67a27d2f17771a50fb7eab136f04088ef793f6b Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Wed, 24 Apr 2019 13:25:33 -0400 Subject: menuCell class done, needs tests --- .../managers/screen/menu/cells/MenuCell.java | 40 +++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java index 9f5d3e6fb..6226f8b58 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java @@ -72,8 +72,34 @@ public class MenuCell { // CONSTRUCTORS - public MenuCell() { + public MenuCell(@NonNull String title) { + setTitle(title); // title is the only required param + setCellId(Integer.MAX_VALUE); + setParentCellId(Integer.MAX_VALUE); + } + + public MenuCell(@NonNull String title, List subCells) { + setTitle(title); // title is the only required param + setSubCells(subCells); + setCellId(Integer.MAX_VALUE); + setParentCellId(Integer.MAX_VALUE); + } + + public MenuCell(@NonNull String title, SdlArtwork icon, List subCells) { + setTitle(title); // title is the only required param + setIcon(icon); + setSubCells(subCells); + setCellId(Integer.MAX_VALUE); + setParentCellId(Integer.MAX_VALUE); + } + public MenuCell(@NonNull String title, SdlArtwork icon, List voiceCommands, MenuSelectionListener listener) { + setTitle(title); // title is the only required param + setIcon(icon); + setVoiceCommands(voiceCommands); + setMenuSelectionListener(listener); + setCellId(Integer.MAX_VALUE); + setParentCellId(Integer.MAX_VALUE); } @@ -190,4 +216,16 @@ public class MenuCell { private int getParentCellId() { return parentCellId; } + + // HELPER + + /** + * Get the description of the cell + * @return a String description of the cell object + */ + public String getDescription(){ + return "MenuCell: ID: "+cellId+ " title: "+ title + " ArtworkName: "+ + icon.getName() + " VoiceCommands: "+ voiceCommands.size() + " isSubCell: " + (parentCellId != Integer.MAX_VALUE ? "YES":"NO")+ + " hasSubCells: "+ (subCells.size() > 0 ? "YES":"NO"); + } } -- cgit v1.2.1 From 84ab204eaa6fbabb0d09937a558a09ceb0bfdc8d Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Wed, 24 Apr 2019 13:55:09 -0400 Subject: add extended objects to android project --- .../managers/screen/menu/MenuManager.java | 45 ++++++++++++++++++++++ .../managers/screen/menu/VoiceCommandManager.java | 44 +++++++++++++++++++++ .../managers/screen/menu/BaseMenuManager.java | 3 +- .../managers/screen/menu/MenuManager.java | 5 ++- 4 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManager.java create mode 100644 android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManager.java diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManager.java b/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManager.java new file mode 100644 index 000000000..b68f55c03 --- /dev/null +++ b/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManager.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +package com.smartdevicelink.managers.screen.menu; + +import com.smartdevicelink.managers.file.FileManager; +import com.smartdevicelink.proxy.interfaces.ISdl; + +public class MenuManager extends BaseMenuManager { + + public MenuManager(ISdl internalInterface, FileManager fileManager) { + // setup + super(internalInterface, fileManager); + } + +} diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManager.java b/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManager.java new file mode 100644 index 000000000..2d48875a5 --- /dev/null +++ b/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManager.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +package com.smartdevicelink.managers.screen.menu; + +import com.smartdevicelink.proxy.interfaces.ISdl; + +public class VoiceCommandManager extends BaseVoiceCommandManager { + + public VoiceCommandManager(ISdl internalInterface) { + // setup + super(internalInterface); + } + +} 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 b0b0698c1..c26193051 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 @@ -35,12 +35,13 @@ package com.smartdevicelink.managers.screen.menu; import android.support.annotation.NonNull; import com.smartdevicelink.managers.BaseSubManager; +import com.smartdevicelink.managers.file.FileManager; import com.smartdevicelink.proxy.interfaces.ISdl; abstract class BaseMenuManager extends BaseSubManager { - public BaseMenuManager(@NonNull ISdl internalInterface) { + public BaseMenuManager(@NonNull ISdl internalInterface, @NonNull FileManager fileManager) { super(internalInterface); } diff --git a/javaSE/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManager.java b/javaSE/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManager.java index 8819d2386..b68f55c03 100644 --- a/javaSE/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManager.java +++ b/javaSE/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManager.java @@ -32,13 +32,14 @@ package com.smartdevicelink.managers.screen.menu; +import com.smartdevicelink.managers.file.FileManager; import com.smartdevicelink.proxy.interfaces.ISdl; public class MenuManager extends BaseMenuManager { - public MenuManager(ISdl internalInterface) { + public MenuManager(ISdl internalInterface, FileManager fileManager) { // setup - super(internalInterface); + super(internalInterface, fileManager); } } -- cgit v1.2.1 From 202d984e1ff8c6d6261b5d831ab524066efcb5c3 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Wed, 24 Apr 2019 14:05:40 -0400 Subject: adding empty test classes --- .../managers/screen/menu/MenuManagerTests.java | 40 +++++++++++++++++++++ .../screen/menu/VoiceCommandManagerTests.java | 40 +++++++++++++++++++++ .../managers/screen/menu/cells/MenuCellTests.java | 42 ++++++++++++++++++++++ .../screen/menu/cells/VoiceCommandTests.java | 40 +++++++++++++++++++++ 4 files changed, 162 insertions(+) create mode 100644 android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/MenuManagerTests.java create mode 100644 android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManagerTests.java create mode 100644 android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/cells/MenuCellTests.java create mode 100644 android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/cells/VoiceCommandTests.java 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 new file mode 100644 index 000000000..e766ed62a --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/MenuManagerTests.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +package com.smartdevicelink.managers.screen.menu; + +import com.smartdevicelink.AndroidTestCase2; + +public class MenuManagerTests extends AndroidTestCase2 { + + +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManagerTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManagerTests.java new file mode 100644 index 000000000..49c77b116 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManagerTests.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +package com.smartdevicelink.managers.screen.menu; + +import com.smartdevicelink.AndroidTestCase2; + +public class VoiceCommandManagerTests extends AndroidTestCase2 { + + +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/cells/MenuCellTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/cells/MenuCellTests.java new file mode 100644 index 000000000..75a44aa6b --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/cells/MenuCellTests.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +package com.smartdevicelink.managers.screen.menu.cells; + +import com.smartdevicelink.AndroidTestCase2; + + +public class MenuCellTests extends AndroidTestCase2 { + + + +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/cells/VoiceCommandTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/cells/VoiceCommandTests.java new file mode 100644 index 000000000..b6824fe15 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/cells/VoiceCommandTests.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +package com.smartdevicelink.managers.screen.menu.cells; + +import com.smartdevicelink.AndroidTestCase2; + +public class VoiceCommandTests extends AndroidTestCase2 { + + +} -- cgit v1.2.1 From f78441c1e787ec6a1bca49f57697e94fdbd7f749 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Wed, 24 Apr 2019 14:12:59 -0400 Subject: javadocs for the constructors --- .../managers/screen/menu/cells/MenuCell.java | 25 +++++++++++++++------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java index 6226f8b58..2e3c717a6 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java @@ -69,22 +69,24 @@ public class MenuCell { private int parentCellId; private int cellId; - // CONSTRUCTORS + /** + * Creates a new MenuCell Object with just the title set. + * @param title The cell's primary text + */ public MenuCell(@NonNull String title) { setTitle(title); // title is the only required param setCellId(Integer.MAX_VALUE); setParentCellId(Integer.MAX_VALUE); } - public MenuCell(@NonNull String title, List subCells) { - setTitle(title); // title is the only required param - setSubCells(subCells); - setCellId(Integer.MAX_VALUE); - setParentCellId(Integer.MAX_VALUE); - } - + /** + * Creates a new MenuCell Object with multiple parameters set + * @param title The cell's primary text + * @param icon The cell's image + * @param subCells The sub-cells that will appear when the cell is selected + */ public MenuCell(@NonNull String title, SdlArtwork icon, List subCells) { setTitle(title); // title is the only required param setIcon(icon); @@ -93,6 +95,13 @@ public class MenuCell { setParentCellId(Integer.MAX_VALUE); } + /** + * Creates a new MenuCell Object with multiple parameters set + * @param title The cell's primary text + * @param icon The cell's image + * @param voiceCommands Voice commands that will activate the menu cell + * @param listener Calls the code that will be run when the menu cell is selected + */ public MenuCell(@NonNull String title, SdlArtwork icon, List voiceCommands, MenuSelectionListener listener) { setTitle(title); // title is the only required param setIcon(icon); -- cgit v1.2.1 From fdd0019e5b92dc9a9cbcdee7020f62b9e2f230c5 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Wed, 24 Apr 2019 14:27:36 -0400 Subject: start of menu cell tests --- .../managers/screen/menu/cells/MenuCellTests.java | 20 ++++++++++++++++++++ .../managers/screen/menu/cells/MenuCell.java | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/cells/MenuCellTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/cells/MenuCellTests.java index 75a44aa6b..086530676 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/cells/MenuCellTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/cells/MenuCellTests.java @@ -32,11 +32,31 @@ package com.smartdevicelink.managers.screen.menu.cells; +import android.content.Context; + import com.smartdevicelink.AndroidTestCase2; +import com.smartdevicelink.proxy.interfaces.ISdl; + +import static org.mockito.Mockito.mock; public class MenuCellTests extends AndroidTestCase2 { + private MenuCell MenuCell; + + @Override + public void setUp() throws Exception{ + super.setUp(); + + ISdl internalInterface = mock(ISdl.class); + + Context context = getContext(); + + } + @Override + public void tearDown() throws Exception { + super.tearDown(); + } } diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java index 2e3c717a6..333168c85 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java @@ -233,7 +233,7 @@ public class MenuCell { * @return a String description of the cell object */ public String getDescription(){ - return "MenuCell: ID: "+cellId+ " title: "+ title + " ArtworkName: "+ + return "MenuCell - ID: "+cellId+ " title: "+ title + " ArtworkName: "+ icon.getName() + " VoiceCommands: "+ voiceCommands.size() + " isSubCell: " + (parentCellId != Integer.MAX_VALUE ? "YES":"NO")+ " hasSubCells: "+ (subCells.size() > 0 ? "YES":"NO"); } -- cgit v1.2.1 From 0a8ceb4ada774313be6e5fb81bdbec7a124b4233 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Wed, 24 Apr 2019 16:14:23 -0400 Subject: menu cell tests --- .../managers/screen/menu/cells/MenuCellTests.java | 53 +++++++++++++++++----- .../java/com/smartdevicelink/test/Test.java | 5 ++ 2 files changed, 47 insertions(+), 11 deletions(-) diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/cells/MenuCellTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/cells/MenuCellTests.java index 086530676..da53bce3a 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/cells/MenuCellTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/cells/MenuCellTests.java @@ -32,26 +32,24 @@ package com.smartdevicelink.managers.screen.menu.cells; -import android.content.Context; - import com.smartdevicelink.AndroidTestCase2; -import com.smartdevicelink.proxy.interfaces.ISdl; - -import static org.mockito.Mockito.mock; +import com.smartdevicelink.managers.screen.menu.MenuSelectionListener; +import com.smartdevicelink.proxy.rpc.enums.TriggerSource; +import com.smartdevicelink.test.Test; public class MenuCellTests extends AndroidTestCase2 { - private MenuCell MenuCell; + private MenuSelectionListener menuSelectionListener = new MenuSelectionListener() { + @Override + public void onTriggered(TriggerSource trigger) { + // stuff + } + }; @Override public void setUp() throws Exception{ super.setUp(); - - ISdl internalInterface = mock(ISdl.class); - - Context context = getContext(); - } @Override @@ -59,4 +57,37 @@ public class MenuCellTests extends AndroidTestCase2 { super.tearDown(); } + public void testSettersAndGetters(){ + + // set everything + MenuCell menuCell = new MenuCell(Test.GENERAL_STRING); + menuCell.setIcon(Test.GENERAL_ARTWORK); + menuCell.setVoiceCommands(Test.GENERAL_STRING_LIST); + menuCell.setSubCells(Test.GENERAL_MENUCELL_LIST); + menuCell.setMenuSelectionListener(menuSelectionListener); + + // use getters and assert equality + assertEquals(menuCell.getTitle(), Test.GENERAL_STRING); + assertEquals(menuCell.getIcon(), Test.GENERAL_ARTWORK); + assertEquals(menuCell.getVoiceCommands(), Test.GENERAL_STRING_LIST); + assertEquals(menuCell.getSubCells(), Test.GENERAL_MENUCELL_LIST); + assertEquals(menuCell.getMenuSelectionListener(), menuSelectionListener); + } + + public void testConstructors(){ + + // first constructor was tested in previous method, use the last two here + + MenuCell menuCell2 =new MenuCell(Test.GENERAL_STRING, Test.GENERAL_ARTWORK, Test.GENERAL_MENUCELL_LIST); + assertEquals(menuCell2.getTitle(), Test.GENERAL_STRING); + assertEquals(menuCell2.getIcon(), Test.GENERAL_ARTWORK); + assertEquals(menuCell2.getSubCells(), Test.GENERAL_MENUCELL_LIST); + + MenuCell menuCell3 =new MenuCell(Test.GENERAL_STRING, Test.GENERAL_ARTWORK, Test.GENERAL_STRING_LIST, menuSelectionListener); + assertEquals(menuCell3.getTitle(), Test.GENERAL_STRING); + assertEquals(menuCell3.getIcon(), Test.GENERAL_ARTWORK); + assertEquals(menuCell3.getVoiceCommands(), Test.GENERAL_STRING_LIST); + assertEquals(menuCell3.getMenuSelectionListener(), menuSelectionListener); + } + } diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java index 62176744f..aaa1f51a3 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java @@ -5,7 +5,9 @@ import android.util.Log; import com.smartdevicelink.R; import com.smartdevicelink.SdlConnection.SdlSession2; +import com.smartdevicelink.managers.file.filetypes.SdlArtwork; import com.smartdevicelink.managers.lockscreen.LockScreenConfig; +import com.smartdevicelink.managers.screen.menu.cells.MenuCell; import com.smartdevicelink.protocol.SdlProtocol; import com.smartdevicelink.protocol.enums.FunctionID; import com.smartdevicelink.proxy.SdlProxyBase; @@ -393,6 +395,8 @@ public class Test { public static final AudioControlData GENERAL_AUDIOCONTROLDATA = new AudioControlData(); public static final LightControlData GENERAL_LIGHTCONTROLDATA = new LightControlData(); public static final HMISettingsControlData GENERAL_HMISETTINGSCONTROLDATA = new HMISettingsControlData(); + public static final SdlArtwork GENERAL_ARTWORK = new SdlArtwork(); + public static final MenuCell GENERAL_MENUCELL = new MenuCell(GENERAL_STRING); public static final HMICapabilities GENERAL_HMICAPABILITIES = new HMICapabilities(); @@ -449,6 +453,7 @@ public class Test { public static final List GENERAL_WEATHERDATA_LIST = Arrays.asList(GENERAL_WEATHERDATA); public static final List GENERAL_WEATHERALERT_LIST = Arrays.asList(GENERAL_WEATHERALERT); public static final List GENERAL_NAVIGATION_INSTRUCTION_LIST = Arrays.asList(GENERAL_NAVIGATION_INSTRUCTION); + public static final List GENERAL_MENUCELL_LIST = Arrays.asList(GENERAL_MENUCELL); public static final JSONArray JSON_TURNS = new JSONArray(); -- cgit v1.2.1 From b33d613861ac4346f382a9ae3ac04a9db9e7c895 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Thu, 25 Apr 2019 10:37:07 -0400 Subject: voice command class - needs tests --- .../screen/menu/VoiceCommandSelectionListener.java | 39 ++++++++++++++++ .../managers/screen/menu/cells/VoiceCommand.java | 52 ++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 base/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommandSelectionListener.java diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommandSelectionListener.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommandSelectionListener.java new file mode 100644 index 000000000..1af92d3f4 --- /dev/null +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommandSelectionListener.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +package com.smartdevicelink.managers.screen.menu; + +public interface VoiceCommandSelectionListener { + + void onVoiceCommandSelected(); + +} diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/VoiceCommand.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/VoiceCommand.java index 7450995dc..f9e52f0b5 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/VoiceCommand.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/VoiceCommand.java @@ -32,8 +32,60 @@ package com.smartdevicelink.managers.screen.menu.cells; +import com.smartdevicelink.managers.screen.menu.VoiceCommandSelectionListener; + +import java.util.List; + public class VoiceCommand { + /** + * The strings the user can say to activate this voice command + */ + private List voiceCommands; + + /** + * The listener that will be called when the command is activated + */ + private VoiceCommandSelectionListener voiceCommandSelectionListener; + + // CONSTRUCTOR(S) + + public VoiceCommand(List voiceCommands, VoiceCommandSelectionListener voiceCommandSelectionListener){ + setVoiceCommands(voiceCommands); + setVoiceCommandSelectionListener(voiceCommandSelectionListener); + } + + // SETTERS / GETTERS + + /** + * The strings the user can say to activate this voice command + * @param voiceCommands - the list of commands to send to the head unit + */ + public void setVoiceCommands(List voiceCommands) { + this.voiceCommands = voiceCommands; + } + + /** + * The strings the user can say to activate this voice command + * @return the List of voice commands + */ + public List getVoiceCommands() { + return voiceCommands; + } + /** + * The listener that will be called when the command is activated + * @param voiceCommandSelectionListener - the listener for this object + */ + public void setVoiceCommandSelectionListener(VoiceCommandSelectionListener voiceCommandSelectionListener) { + this.voiceCommandSelectionListener = voiceCommandSelectionListener; + } + /** + * The listener that will be called when the command is activated + * @return voiceCommandSelectionListener - the listener for this object + */ + public VoiceCommandSelectionListener getVoiceCommandSelectionListener() { + return voiceCommandSelectionListener; + } } -- cgit v1.2.1 From b2307153a57acad4b9628a9f2b73a9cd47c081c8 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Thu, 25 Apr 2019 10:57:41 -0400 Subject: add tests for voicecommand class --- .../screen/menu/cells/VoiceCommandTests.java | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/cells/VoiceCommandTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/cells/VoiceCommandTests.java index b6824fe15..906727e89 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/cells/VoiceCommandTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/cells/VoiceCommandTests.java @@ -33,8 +33,33 @@ package com.smartdevicelink.managers.screen.menu.cells; import com.smartdevicelink.AndroidTestCase2; +import com.smartdevicelink.managers.screen.menu.VoiceCommandSelectionListener; +import com.smartdevicelink.test.Test; public class VoiceCommandTests extends AndroidTestCase2 { + private VoiceCommandSelectionListener voiceCommandSelectionListener = new VoiceCommandSelectionListener() { + @Override + public void onVoiceCommandSelected() { + // Stuffs + } + }; + + @Override + public void setUp() throws Exception{ + super.setUp(); + } + + @Override + public void tearDown() throws Exception { + super.tearDown(); + } + + public void testSettersAndGetters(){ + VoiceCommand voiceCommand = new VoiceCommand(Test.GENERAL_STRING_LIST, voiceCommandSelectionListener); + + assertEquals(voiceCommand.getVoiceCommands(), Test.GENERAL_STRING_LIST); + assertEquals(voiceCommand.getVoiceCommandSelectionListener(), voiceCommandSelectionListener); + } } -- cgit v1.2.1 From 2e581deb01bbf500d3bacb10c5767978ef4ff8d2 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Thu, 25 Apr 2019 11:38:24 -0400 Subject: start of voicecommandmanager --- .../screen/menu/BaseVoiceCommandManager.java | 85 ++++++++++++++++++++++ .../managers/screen/menu/cells/VoiceCommand.java | 5 ++ 2 files changed, 90 insertions(+) diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java index 6ce102d16..aa169ef5b 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java @@ -35,12 +35,97 @@ package com.smartdevicelink.managers.screen.menu; import android.support.annotation.NonNull; import com.smartdevicelink.managers.BaseSubManager; +import com.smartdevicelink.managers.screen.menu.cells.VoiceCommand; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCNotification; +import com.smartdevicelink.proxy.RPCRequest; import com.smartdevicelink.proxy.interfaces.ISdl; +import com.smartdevicelink.proxy.rpc.OnCommand; +import com.smartdevicelink.proxy.rpc.OnHMIStatus; +import com.smartdevicelink.proxy.rpc.enums.HMILevel; +import com.smartdevicelink.proxy.rpc.listeners.OnRPCNotificationListener; +import com.smartdevicelink.util.DebugTool; + +import java.util.ArrayList; +import java.util.List; abstract class BaseVoiceCommandManager extends BaseSubManager { + private List voiceCommands; + private List oldVoiceCommands; + + private List inProgressUpdate; + + private int commandId; + private int lastVoiceCommandId; + private static final int voiceCommandIdMin = 1900000000; + + private boolean waitingOnHMIUpdate; + private boolean hasQueuedUpdate; + + private HMILevel currentHMILevel; + private OnRPCNotificationListener hmiListener; + private OnRPCNotificationListener commandListener; + + // CONSTRUCTORS public BaseVoiceCommandManager(@NonNull ISdl internalInterface) { super(internalInterface); + addListeners(); + + lastVoiceCommandId = voiceCommandIdMin; + voiceCommands = new ArrayList<>(); + oldVoiceCommands = new ArrayList<>(); + } + + + // HELPERS + + public void stop(){ + + lastVoiceCommandId = voiceCommandIdMin; + voiceCommands = null; + oldVoiceCommands = null; + + waitingOnHMIUpdate = false; + currentHMILevel = null; + inProgressUpdate = null; + hasQueuedUpdate = false; + + // remove listeners + internalInterface.removeOnRPCNotificationListener(FunctionID.ON_HMI_STATUS, hmiListener); + internalInterface.removeOnRPCNotificationListener(FunctionID.ON_COMMAND, commandListener); + + super.dispose(); + } + + // LISTENERS + + private void addListeners(){ + // HMI UPDATES + hmiListener = new OnRPCNotificationListener() { + @Override + public void onNotified(RPCNotification notification) { + currentHMILevel = ((OnHMIStatus) notification).getHmiLevel(); + if (currentHMILevel == HMILevel.HMI_FULL){ + if (waitingOnHMIUpdate){ + DebugTool.logInfo( "Acquired HMI_FULL with pending update. Sending now"); + waitingOnHMIUpdate = false; + // TODO: DO THINGS HERE + } + } + } + }; + internalInterface.addOnRPCNotificationListener(FunctionID.ON_HMI_STATUS, hmiListener); + + // COMMANDS + commandListener = new OnRPCNotificationListener() { + @Override + public void onNotified(RPCNotification notification) { + OnCommand command = (OnCommand) notification; + // TODO: STUFF HERE + } + }; + internalInterface.addOnRPCNotificationListener(FunctionID.ON_COMMAND, commandListener); } } diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/VoiceCommand.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/VoiceCommand.java index f9e52f0b5..28b02b3a1 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/VoiceCommand.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/VoiceCommand.java @@ -50,6 +50,11 @@ public class VoiceCommand { // CONSTRUCTOR(S) + /** + * Constructor that sets all parameters for this class + * @param voiceCommands The strings the user can say to activate this voice command + * @param voiceCommandSelectionListener The listener that will be called when the command is activated + */ public VoiceCommand(List voiceCommands, VoiceCommandSelectionListener voiceCommandSelectionListener){ setVoiceCommands(voiceCommands); setVoiceCommandSelectionListener(voiceCommandSelectionListener); -- cgit v1.2.1 From c4d9f6e137364c93dfec168c2dc238796fc670b7 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Thu, 25 Apr 2019 11:45:54 -0400 Subject: add in comments for methods still needed --- .../screen/menu/BaseVoiceCommandManager.java | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java index aa169ef5b..4b88b70dc 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java @@ -78,9 +78,36 @@ abstract class BaseVoiceCommandManager extends BaseSubManager { oldVoiceCommands = new ArrayList<>(); } + // SETTERS + + public void setVoiceCommands(List voiceCommands){ + + } + + // UPDATING SYSTEM + + // update w/ listener + + // DELETING OLD MENU ITEMS + + // deleteCurrentVoiceCommands w/ listener + + // SEND NEW MENU ITEMS + + // send current voice commands w/ listener + + // DELETES + + // deleteCommandsForVoiceCommands + + // COMMANDS + + // addCommandsForVoiceCommands // HELPERS + // updateIdsOnVoiceCommands + public void stop(){ lastVoiceCommandId = voiceCommandIdMin; @@ -102,6 +129,7 @@ abstract class BaseVoiceCommandManager extends BaseSubManager { // LISTENERS private void addListeners(){ + // HMI UPDATES hmiListener = new OnRPCNotificationListener() { @Override -- cgit v1.2.1 From d8db1016737583e765f59cea04f4db2a4d479ab6 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Thu, 25 Apr 2019 14:18:15 -0400 Subject: still working on voicemanager. incremental commit --- .../screen/menu/BaseVoiceCommandManager.java | 67 +++++++++++++++++++--- .../managers/screen/menu/cells/VoiceCommand.java | 29 ++++++++++ 2 files changed, 89 insertions(+), 7 deletions(-) diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java index 4b88b70dc..9ff30f565 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java @@ -35,11 +35,14 @@ package com.smartdevicelink.managers.screen.menu; import android.support.annotation.NonNull; import com.smartdevicelink.managers.BaseSubManager; +import com.smartdevicelink.managers.CompletionListener; import com.smartdevicelink.managers.screen.menu.cells.VoiceCommand; import com.smartdevicelink.protocol.enums.FunctionID; import com.smartdevicelink.proxy.RPCNotification; import com.smartdevicelink.proxy.RPCRequest; import com.smartdevicelink.proxy.interfaces.ISdl; +import com.smartdevicelink.proxy.rpc.AddCommand; +import com.smartdevicelink.proxy.rpc.DeleteCommand; import com.smartdevicelink.proxy.rpc.OnCommand; import com.smartdevicelink.proxy.rpc.OnHMIStatus; import com.smartdevicelink.proxy.rpc.enums.HMILevel; @@ -82,31 +85,81 @@ abstract class BaseVoiceCommandManager extends BaseSubManager { public void setVoiceCommands(List voiceCommands){ + // make sure hmi is not none + if (currentHMILevel == null || currentHMILevel == HMILevel.HMI_NONE){ + // Trying to send on HMI_NONE, waiting for full + waitingOnHMIUpdate = true; + return; + } + + waitingOnHMIUpdate = false; + lastVoiceCommandId = voiceCommandIdMin; + updateIdsOnVoiceCommands(voiceCommands); + oldVoiceCommands = voiceCommands; + this.voiceCommands = voiceCommands; + + updateWithListener(null); } // UPDATING SYSTEM - // update w/ listener + private void updateWithListener(CompletionListener listener){ + + + + } // DELETING OLD MENU ITEMS - // deleteCurrentVoiceCommands w/ listener + private void sendDeleteCurrentVoiceCommands(CompletionListener listener){ + + + + } // SEND NEW MENU ITEMS - // send current voice commands w/ listener + private void sendCurrentVoiceCommands(CompletionListener listener){ + + + + } // DELETES - // deleteCommandsForVoiceCommands + private List deleteCommandsForVoiceCommands(List voiceCommands){ + List deleteCommandList = new ArrayList<>(); + for (VoiceCommand command : voiceCommands){ + DeleteCommand delete = new DeleteCommand(command.getCommandId()); + deleteCommandList.add(delete); + } + return deleteCommandList; + } // COMMANDS - // addCommandsForVoiceCommands + private List addCommandsForVoiceCommands(List voiceCommands){ + List addCommandList = new ArrayList<>(); + for (VoiceCommand command : voiceCommands){ + addCommandList.add(commandForVoiceCommand(command)); + } + return addCommandList; + } + + private AddCommand commandForVoiceCommand(VoiceCommand voiceCommand){ + AddCommand command = new AddCommand(); + command.setVrCommands(voiceCommand.getVoiceCommands()); + command.setCmdID(voiceCommand.getCommandId()); + return command; + } // HELPERS - // updateIdsOnVoiceCommands + private void updateIdsOnVoiceCommands(List voiceCommands){ + for (VoiceCommand command : voiceCommands){ + command.setCommandId(++lastVoiceCommandId); + } + } public void stop(){ @@ -129,7 +182,7 @@ abstract class BaseVoiceCommandManager extends BaseSubManager { // LISTENERS private void addListeners(){ - + // HMI UPDATES hmiListener = new OnRPCNotificationListener() { @Override diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/VoiceCommand.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/VoiceCommand.java index 28b02b3a1..4f6f51d56 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/VoiceCommand.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/VoiceCommand.java @@ -48,6 +48,9 @@ public class VoiceCommand { */ private VoiceCommandSelectionListener voiceCommandSelectionListener; + + private int commandId; + // CONSTRUCTOR(S) /** @@ -93,4 +96,30 @@ public class VoiceCommand { public VoiceCommandSelectionListener getVoiceCommandSelectionListener() { return voiceCommandSelectionListener; } + + /** + * set the command ID + * @param commandId the id to identify the command + */ + public void setCommandId(int commandId) { + this.commandId = commandId; + } + + /** + * the id used to identify the command + * @return the id + */ + public int getCommandId() { + return commandId; + } + + // HELPER + + /** + * Get the description of the cell + * @return a String description of the cell object + */ + public String getDescription(){ + return "VOICE COMMAND - ID: "+commandId+ " First Object: "+ voiceCommands.get(0)+ " Voice Commands: "+ voiceCommands.size(); + } } -- cgit v1.2.1 From 4d1f51f3eaf9e98b66fcd308f66a145f377238f4 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Thu, 25 Apr 2019 15:34:21 -0400 Subject: base voice manager build complete, needs testing --- .../screen/menu/BaseVoiceCommandManager.java | 140 +++++++++++++++++++-- 1 file changed, 128 insertions(+), 12 deletions(-) diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java index 9ff30f565..fcb1c8b50 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java @@ -39,13 +39,15 @@ import com.smartdevicelink.managers.CompletionListener; import com.smartdevicelink.managers.screen.menu.cells.VoiceCommand; import com.smartdevicelink.protocol.enums.FunctionID; import com.smartdevicelink.proxy.RPCNotification; -import com.smartdevicelink.proxy.RPCRequest; +import com.smartdevicelink.proxy.RPCResponse; import com.smartdevicelink.proxy.interfaces.ISdl; import com.smartdevicelink.proxy.rpc.AddCommand; import com.smartdevicelink.proxy.rpc.DeleteCommand; import com.smartdevicelink.proxy.rpc.OnCommand; import com.smartdevicelink.proxy.rpc.OnHMIStatus; import com.smartdevicelink.proxy.rpc.enums.HMILevel; +import com.smartdevicelink.proxy.rpc.enums.Result; +import com.smartdevicelink.proxy.rpc.listeners.OnMultipleRequestListener; import com.smartdevicelink.proxy.rpc.listeners.OnRPCNotificationListener; import com.smartdevicelink.util.DebugTool; @@ -57,9 +59,8 @@ abstract class BaseVoiceCommandManager extends BaseSubManager { private List voiceCommands; private List oldVoiceCommands; - private List inProgressUpdate; + private List inProgressUpdate; - private int commandId; private int lastVoiceCommandId; private static final int voiceCommandIdMin = 1900000000; @@ -103,26 +104,130 @@ abstract class BaseVoiceCommandManager extends BaseSubManager { // UPDATING SYSTEM - private void updateWithListener(CompletionListener listener){ + private void updateWithListener(final CompletionListener listener){ + if (currentHMILevel == null || currentHMILevel.equals(HMILevel.HMI_NONE)){ + waitingOnHMIUpdate = true; + return; + } + if (inProgressUpdate != null){ + // There's an in-progress update, put this on hold + hasQueuedUpdate = true; + return; + } + + sendDeleteCurrentVoiceCommands(new CompletionListener() { + @Override + public void onComplete(boolean success) { + // we don't care about errors from deleting, send new add commands + sendCurrentVoiceCommands(new CompletionListener() { + @Override + public void onComplete(boolean success2) { + inProgressUpdate = null; + + if (hasQueuedUpdate){ + updateWithListener(null); + hasQueuedUpdate = false; + } + + if (listener != null){ + listener.onComplete(success2); + } + + if (!success2){ + DebugTool.logError("Error sending voice commands"); + } + } + }); + } + }); } // DELETING OLD MENU ITEMS - private void sendDeleteCurrentVoiceCommands(CompletionListener listener){ + private void sendDeleteCurrentVoiceCommands(final CompletionListener listener){ + if (oldVoiceCommands == null || oldVoiceCommands.size() == 0){ + if (listener != null){ + listener.onComplete(false); + } + return; + } + + List deleteVoiceCommands = deleteCommandsForVoiceCommands(oldVoiceCommands); + oldVoiceCommands.clear(); + internalInterface.sendRequests(deleteVoiceCommands, new OnMultipleRequestListener() { + @Override + public void onUpdate(int remainingRequests) {} + + @Override + public void onFinished() { + DebugTool.logInfo("Successfully deleted old voice commands"); + if (listener != null){ + listener.onComplete(true); + } + } + + @Override + public void onError(int correlationId, Result resultCode, String info) { + DebugTool.logError("Error deleting old voice commands"); + if (listener != null){ + listener.onComplete(false); + } + } + @Override + public void onResponse(int correlationId, RPCResponse response) {} + }); } // SEND NEW MENU ITEMS - private void sendCurrentVoiceCommands(CompletionListener listener){ + private void sendCurrentVoiceCommands(final CompletionListener listener){ + if (voiceCommands == null || voiceCommands.size() == 0){ + DebugTool.logInfo("No Voice Commands to Send"); + if (listener != null){ + listener.onComplete(false); + } + return; + } + inProgressUpdate = addCommandsForVoiceCommands(voiceCommands); + internalInterface.sendRequests(inProgressUpdate, new OnMultipleRequestListener() { + @Override + public void onUpdate(int remainingRequests) { + DebugTool.logInfo("Remaining Voice Commands: "+ remainingRequests); + } + + @Override + public void onFinished() { + DebugTool.logInfo("Sending Voice Commands Complete"); + if (listener != null){ + listener.onComplete(true); + } + oldVoiceCommands = voiceCommands; + } + + @Override + public void onError(int correlationId, Result resultCode, String info) { + DebugTool.logError("Add Commands Failed: "+info); + if (listener != null){ + listener.onComplete(false); + } + } + + @Override + public void onResponse(int correlationId, RPCResponse response) { + if (response != null && !response.getSuccess()){ + DebugTool.logError("Error sending voice commands: "+ response.getInfo()); + } + } + }); } // DELETES @@ -187,12 +292,14 @@ abstract class BaseVoiceCommandManager extends BaseSubManager { hmiListener = new OnRPCNotificationListener() { @Override public void onNotified(RPCNotification notification) { + HMILevel oldHMILevel = currentHMILevel; currentHMILevel = ((OnHMIStatus) notification).getHmiLevel(); - if (currentHMILevel == HMILevel.HMI_FULL){ + // Auto-send an update if we were in NONE and now we are not + if (oldHMILevel.equals(HMILevel.HMI_NONE) && !currentHMILevel.equals(HMILevel.HMI_NONE)){ if (waitingOnHMIUpdate){ - DebugTool.logInfo( "Acquired HMI_FULL with pending update. Sending now"); - waitingOnHMIUpdate = false; - // TODO: DO THINGS HERE + setVoiceCommands(voiceCommands); + }else{ + updateWithListener(null); } } } @@ -203,8 +310,17 @@ abstract class BaseVoiceCommandManager extends BaseSubManager { commandListener = new OnRPCNotificationListener() { @Override public void onNotified(RPCNotification notification) { - OnCommand command = (OnCommand) notification; - // TODO: STUFF HERE + OnCommand onCommand = (OnCommand) notification; + if (voiceCommands != null && voiceCommands.size() > 0){ + for (VoiceCommand command : voiceCommands){ + if (onCommand.getCmdID() == command.getCommandId()){ + if (command.getVoiceCommandSelectionListener() != null) { + command.getVoiceCommandSelectionListener().onVoiceCommandSelected(); + break; + } + } + } + } } }; internalInterface.addOnRPCNotificationListener(FunctionID.ON_COMMAND, commandListener); -- cgit v1.2.1 From 37bbfbea9382a8887cffd121ad1afd89d317628e Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Thu, 25 Apr 2019 16:01:29 -0400 Subject: fix some stuff, add VCM to basescreenmanager --- .../managers/screen/BaseScreenManager.java | 22 ++++++++++++++++++---- .../screen/menu/BaseVoiceCommandManager.java | 19 ++++++++++++++++++- 2 files changed, 36 insertions(+), 5 deletions(-) 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 74ba6fc58..4074ad120 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/BaseScreenManager.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/BaseScreenManager.java @@ -38,6 +38,8 @@ import com.smartdevicelink.managers.BaseSubManager; import com.smartdevicelink.managers.CompletionListener; import com.smartdevicelink.managers.file.FileManager; import com.smartdevicelink.managers.file.filetypes.SdlArtwork; +import com.smartdevicelink.managers.screen.menu.VoiceCommandManager; +import com.smartdevicelink.managers.screen.menu.cells.VoiceCommand; import com.smartdevicelink.proxy.interfaces.ISdl; import com.smartdevicelink.proxy.rpc.enums.MetadataType; import com.smartdevicelink.proxy.rpc.enums.TextAlignment; @@ -57,19 +59,20 @@ abstract class BaseScreenManager extends BaseSubManager { private final WeakReference fileManager; private SoftButtonManager softButtonManager; private TextAndGraphicManager textAndGraphicManager; + private VoiceCommandManager voiceCommandManager; // Sub manager listener private final CompletionListener subManagerListener = new CompletionListener() { @Override public synchronized void onComplete(boolean success) { - if (softButtonManager != null && textAndGraphicManager != null) { - if (softButtonManager.getState() == BaseSubManager.READY && textAndGraphicManager.getState() == BaseSubManager.READY) { + if (softButtonManager != null && textAndGraphicManager != null && voiceCommandManager != null) { + if (softButtonManager.getState() == BaseSubManager.READY && textAndGraphicManager.getState() == BaseSubManager.READY && voiceCommandManager.getState() == BaseSubManager.READY) { DebugTool.logInfo("Starting screen manager, all sub managers are in ready state"); transitionToState(READY); - } else if (softButtonManager.getState() == BaseSubManager.ERROR && textAndGraphicManager.getState() == BaseSubManager.ERROR) { + } else if (softButtonManager.getState() == BaseSubManager.ERROR && textAndGraphicManager.getState() == BaseSubManager.ERROR && voiceCommandManager.getState() == BaseSubManager.ERROR) { Log.e(TAG, "ERROR starting screen manager, both sub managers in error state"); transitionToState(ERROR); - } else if (textAndGraphicManager.getState() == BaseSubManager.SETTING_UP || softButtonManager.getState() == BaseSubManager.SETTING_UP) { + } else if (textAndGraphicManager.getState() == BaseSubManager.SETTING_UP || softButtonManager.getState() == BaseSubManager.SETTING_UP || voiceCommandManager.getState() == BaseSubManager.SETTING_UP) { DebugTool.logInfo("SETTING UP screen manager, one sub manager is still setting up"); transitionToState(SETTING_UP); } else { @@ -95,12 +98,14 @@ abstract class BaseScreenManager extends BaseSubManager { super.start(listener); this.softButtonManager.start(subManagerListener); this.textAndGraphicManager.start(subManagerListener); + this.voiceCommandManager.start(subManagerListener); } private void initialize(){ if (fileManager.get() != null) { this.softButtonManager = new SoftButtonManager(internalInterface, fileManager.get()); this.textAndGraphicManager = new TextAndGraphicManager(internalInterface, fileManager.get(), softButtonManager); + this.voiceCommandManager = new VoiceCommandManager(internalInterface); } } @@ -111,6 +116,7 @@ abstract class BaseScreenManager extends BaseSubManager { public void dispose() { softButtonManager.dispose(); textAndGraphicManager.dispose(); + voiceCommandManager.dispose(); super.dispose(); } @@ -351,6 +357,14 @@ abstract class BaseScreenManager extends BaseSubManager { return softButtonManager.getSoftButtonObjectById(buttonId); } + public List getVoiceCommands(){ + return voiceCommandManager.getVoiceCommands(); + } + + public void setVoiceCommands(List voiceCommands){ + this.voiceCommandManager.setVoiceCommands(voiceCommands); + } + /** * Begin a multiple updates transaction. The updates will be applied when commit() is called
* Note: if we don't use beginTransaction & commit, every update will be sent individually. diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java index fcb1c8b50..93c2fcad1 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java @@ -82,10 +82,22 @@ abstract class BaseVoiceCommandManager extends BaseSubManager { oldVoiceCommands = new ArrayList<>(); } + @Override + public void start(CompletionListener listener) { + transitionToState(READY); + super.start(listener); + } + // SETTERS public void setVoiceCommands(List voiceCommands){ + // we actually need voice commands to set. + if (voiceCommands == null || voiceCommands.size() == 0){ + DebugTool.logInfo("Trying to set empty list of voice commands, returning"); + return; + } + // make sure hmi is not none if (currentHMILevel == null || currentHMILevel == HMILevel.HMI_NONE){ // Trying to send on HMI_NONE, waiting for full @@ -102,6 +114,10 @@ abstract class BaseVoiceCommandManager extends BaseSubManager { updateWithListener(null); } + public List getVoiceCommands(){ + return voiceCommands; + } + // UPDATING SYSTEM private void updateWithListener(final CompletionListener listener){ @@ -266,7 +282,8 @@ abstract class BaseVoiceCommandManager extends BaseSubManager { } } - public void stop(){ + @Override + public void dispose(){ lastVoiceCommandId = voiceCommandIdMin; voiceCommands = null; -- cgit v1.2.1 From 7b1de23e01b77b067cc1cb8c6946a2e76950c426 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Fri, 26 Apr 2019 14:00:35 -0400 Subject: start of menu manager --- .../managers/screen/BaseScreenManager.java | 10 ++- .../managers/screen/menu/BaseMenuManager.java | 100 +++++++++++++++++++++ .../screen/menu/BaseVoiceCommandManager.java | 43 +++++---- 3 files changed, 133 insertions(+), 20 deletions(-) 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 4074ad120..ac1f81c0a 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/BaseScreenManager.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/BaseScreenManager.java @@ -105,8 +105,8 @@ abstract class BaseScreenManager extends BaseSubManager { if (fileManager.get() != null) { this.softButtonManager = new SoftButtonManager(internalInterface, fileManager.get()); this.textAndGraphicManager = new TextAndGraphicManager(internalInterface, fileManager.get(), softButtonManager); - this.voiceCommandManager = new VoiceCommandManager(internalInterface); } + this.voiceCommandManager = new VoiceCommandManager(internalInterface); } /** @@ -357,10 +357,18 @@ abstract class BaseScreenManager extends BaseSubManager { return softButtonManager.getSoftButtonObjectById(buttonId); } + /** + * Get the currently set voice commands + * @return a List of Voice Command objects + */ public List getVoiceCommands(){ return voiceCommandManager.getVoiceCommands(); } + /** + * Set voice commands + * @param voiceCommands the voice commands to be sent to the head unit + */ public void setVoiceCommands(List voiceCommands){ this.voiceCommandManager.setVoiceCommands(voiceCommands); } 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 c26193051..935a77d4b 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 @@ -35,15 +35,115 @@ package com.smartdevicelink.managers.screen.menu; import android.support.annotation.NonNull; import com.smartdevicelink.managers.BaseSubManager; +import com.smartdevicelink.managers.CompletionListener; import com.smartdevicelink.managers.file.FileManager; +import com.smartdevicelink.managers.screen.menu.cells.MenuCell; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.RPCMessage; +import com.smartdevicelink.proxy.RPCNotification; import com.smartdevicelink.proxy.interfaces.ISdl; +import com.smartdevicelink.proxy.rpc.DisplayCapabilities; +import com.smartdevicelink.proxy.rpc.OnCommand; +import com.smartdevicelink.proxy.rpc.OnHMIStatus; +import com.smartdevicelink.proxy.rpc.enums.HMILevel; +import com.smartdevicelink.proxy.rpc.enums.SystemContext; +import com.smartdevicelink.proxy.rpc.listeners.OnRPCNotificationListener; + +import java.lang.ref.WeakReference; +import java.util.ArrayList; +import java.util.List; abstract class BaseMenuManager extends BaseSubManager { + private final WeakReference fileManager; + + private List menuCells; + private List waitingUpdateMenuCells; + private List oldMenuCells; + private List inProgressUpdate; + + private boolean waitingOnHMIUpdate; + private boolean hasQueuedUpdate; + private HMILevel currentHMILevel; + + private OnRPCNotificationListener hmiListener; + private OnRPCNotificationListener commandListener; + + private static final int parentIdNotFound = Integer.MAX_VALUE; + private static final int menuCellIdMin = 1; + private int lastMenuId; + + private SystemContext currentSystemContext; + + private DisplayCapabilities displayCapabilities; public BaseMenuManager(@NonNull ISdl internalInterface, @NonNull FileManager fileManager) { + super(internalInterface); + + // Set up some Vars + this.fileManager = new WeakReference<>(fileManager); + menuCells = new ArrayList<>(); + oldMenuCells = new ArrayList<>(); + waitingUpdateMenuCells = new ArrayList<>(); + inProgressUpdate = new ArrayList<>(); + + lastMenuId = menuCellIdMin; + addListeners(); } + @Override + public void start(CompletionListener listener) { + transitionToState(READY); + super.start(listener); + } + @Override + public void dispose(){ + + lastMenuId = menuCellIdMin; + menuCells = null; + oldMenuCells = null; + currentHMILevel = null; + currentSystemContext = SystemContext.SYSCTXT_MAIN; + displayCapabilities = null; + inProgressUpdate = null; + hasQueuedUpdate = false; + waitingOnHMIUpdate = false; + waitingUpdateMenuCells = null; + + // remove listeners + internalInterface.removeOnRPCNotificationListener(FunctionID.ON_HMI_STATUS, hmiListener); + internalInterface.removeOnRPCNotificationListener(FunctionID.ON_COMMAND, commandListener); + + super.dispose(); + } + + // LISTENERS + + private void addListeners(){ + + // HMI UPDATES + hmiListener = new OnRPCNotificationListener() { + @Override + public void onNotified(RPCNotification notification) { + HMILevel oldHMILevel = currentHMILevel; + currentHMILevel = ((OnHMIStatus) notification).getHmiLevel(); + // Auto-send an update if we were in NONE and now we are not + if (oldHMILevel.equals(HMILevel.HMI_NONE) && !currentHMILevel.equals(HMILevel.HMI_NONE)){ + + } + } + }; + internalInterface.addOnRPCNotificationListener(FunctionID.ON_HMI_STATUS, hmiListener); + + // COMMANDS + commandListener = new OnRPCNotificationListener() { + @Override + public void onNotified(RPCNotification notification) { + OnCommand onCommand = (OnCommand) notification; + } + }; + internalInterface.addOnRPCNotificationListener(FunctionID.ON_COMMAND, commandListener); + } } diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java index 93c2fcad1..fd2ee7709 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java @@ -45,8 +45,11 @@ import com.smartdevicelink.proxy.rpc.AddCommand; import com.smartdevicelink.proxy.rpc.DeleteCommand; import com.smartdevicelink.proxy.rpc.OnCommand; import com.smartdevicelink.proxy.rpc.OnHMIStatus; +import com.smartdevicelink.proxy.rpc.SetMediaClockTimer; +import com.smartdevicelink.proxy.rpc.StartTime; import com.smartdevicelink.proxy.rpc.enums.HMILevel; import com.smartdevicelink.proxy.rpc.enums.Result; +import com.smartdevicelink.proxy.rpc.enums.UpdateMode; import com.smartdevicelink.proxy.rpc.listeners.OnMultipleRequestListener; import com.smartdevicelink.proxy.rpc.listeners.OnRPCNotificationListener; import com.smartdevicelink.util.DebugTool; @@ -54,6 +57,8 @@ import com.smartdevicelink.util.DebugTool; import java.util.ArrayList; import java.util.List; +import static com.smartdevicelink.proxy.rpc.SetMediaClockTimer.countUpFromStartTime; + abstract class BaseVoiceCommandManager extends BaseSubManager { private List voiceCommands; @@ -88,6 +93,25 @@ abstract class BaseVoiceCommandManager extends BaseSubManager { super.start(listener); } + @Override + public void dispose(){ + + lastVoiceCommandId = voiceCommandIdMin; + voiceCommands = null; + oldVoiceCommands = null; + + waitingOnHMIUpdate = false; + currentHMILevel = null; + inProgressUpdate = null; + hasQueuedUpdate = false; + + // remove listeners + internalInterface.removeOnRPCNotificationListener(FunctionID.ON_HMI_STATUS, hmiListener); + internalInterface.removeOnRPCNotificationListener(FunctionID.ON_COMMAND, commandListener); + + super.dispose(); + } + // SETTERS public void setVoiceCommands(List voiceCommands){ @@ -282,25 +306,6 @@ abstract class BaseVoiceCommandManager extends BaseSubManager { } } - @Override - public void dispose(){ - - lastVoiceCommandId = voiceCommandIdMin; - voiceCommands = null; - oldVoiceCommands = null; - - waitingOnHMIUpdate = false; - currentHMILevel = null; - inProgressUpdate = null; - hasQueuedUpdate = false; - - // remove listeners - internalInterface.removeOnRPCNotificationListener(FunctionID.ON_HMI_STATUS, hmiListener); - internalInterface.removeOnRPCNotificationListener(FunctionID.ON_COMMAND, commandListener); - - super.dispose(); - } - // LISTENERS private void addListeners(){ -- cgit v1.2.1 From 389c485c380f39340b46c8fc3d2ab517164693d4 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Mon, 29 Apr 2019 10:20:47 -0400 Subject: checkpoint - in middle of code --- .../managers/screen/menu/BaseMenuManager.java | 71 ++++++++++++++++++++-- .../managers/screen/menu/cells/MenuCell.java | 6 +- 2 files changed, 68 insertions(+), 9 deletions(-) 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 935a77d4b..3150d6b5b 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 @@ -41,13 +41,22 @@ import com.smartdevicelink.managers.screen.menu.cells.MenuCell; import com.smartdevicelink.protocol.enums.FunctionID; import com.smartdevicelink.proxy.RPCMessage; import com.smartdevicelink.proxy.RPCNotification; +import com.smartdevicelink.proxy.SystemCapabilityManager; import com.smartdevicelink.proxy.interfaces.ISdl; +import com.smartdevicelink.proxy.interfaces.OnSystemCapabilityListener; +import com.smartdevicelink.proxy.rpc.AddCommand; +import com.smartdevicelink.proxy.rpc.AddSubMenu; import com.smartdevicelink.proxy.rpc.DisplayCapabilities; +import com.smartdevicelink.proxy.rpc.Image; +import com.smartdevicelink.proxy.rpc.MenuParams; import com.smartdevicelink.proxy.rpc.OnCommand; import com.smartdevicelink.proxy.rpc.OnHMIStatus; +import com.smartdevicelink.proxy.rpc.RegisterAppInterfaceResponse; import com.smartdevicelink.proxy.rpc.enums.HMILevel; +import com.smartdevicelink.proxy.rpc.enums.SystemCapabilityType; import com.smartdevicelink.proxy.rpc.enums.SystemContext; import com.smartdevicelink.proxy.rpc.listeners.OnRPCNotificationListener; +import com.smartdevicelink.util.DebugTool; import java.lang.ref.WeakReference; import java.util.ArrayList; @@ -68,6 +77,7 @@ abstract class BaseMenuManager extends BaseSubManager { private OnRPCNotificationListener hmiListener; private OnRPCNotificationListener commandListener; + private DisplayCapabilities displayCapabilities; private static final int parentIdNotFound = Integer.MAX_VALUE; private static final int menuCellIdMin = 1; @@ -75,8 +85,6 @@ abstract class BaseMenuManager extends BaseSubManager { private SystemContext currentSystemContext; - private DisplayCapabilities displayCapabilities; - public BaseMenuManager(@NonNull ISdl internalInterface, @NonNull FileManager fileManager) { super(internalInterface); @@ -119,20 +127,70 @@ abstract class BaseMenuManager extends BaseSubManager { super.dispose(); } + private AddCommand commandForMenuCell(MenuCell cell, boolean shouldHaveArtwork, int position){ + + MenuParams params = new MenuParams(cell.getTitle()); + params.setParentID(cell.getCellId() != Integer.MAX_VALUE ? cell.getParentCellId() : null); + params.setPosition(position); + + AddCommand command = new AddCommand(cell.getCellId()); + command.setMenuParams(params); + command.setVrCommands(cell.getVoiceCommands()); + command.setCmdIcon((cell.getIcon() != null && shouldHaveArtwork) ? cell.getIcon().getImageRPC() : null); + + return command; + } + + private AddSubMenu subMenuCommandForMenuCell(MenuCell cell, boolean shouldHaveArtwork, int position){ + AddSubMenu subMenu = new AddSubMenu(cell.getCellId(), cell.getTitle()); + subMenu.setPosition(position); + subMenu.setMenuIcon((shouldHaveArtwork && (cell.getIcon().getName() != null)) ? cell.getIcon().getImageRPC() : null); + return subMenu; + } + + // CELL COMMAND HANDLING + + private boolean callListenerForCells(List cells, OnCommand command){ + for (MenuCell cell : cells){ + if (cell.getCellId() == command.getCmdID() && cell.getMenuSelectionListener() != null){ + cell.getMenuSelectionListener().onTriggered(command.getTriggerSource()); + return true; + } + + if (cell.getSubCells().size() > 0){ + // for each cell, if it has sub cells, recursively loop through those as well + if (callListenerForCells(cell.getSubCells(), command)) { + return true; + } + } + } + return false; + } + // LISTENERS private void addListeners(){ + // DISPLAY CAPABILITIES - via SCM + internalInterface.getCapability(SystemCapabilityType.DISPLAY, new OnSystemCapabilityListener() { + @Override + public void onCapabilityRetrieved(Object capability) { + displayCapabilities = (DisplayCapabilities) capability; + } + + @Override + public void onError(String info) { + DebugTool.logError("Unable to retrieve display capabilities: "+ info); + } + }); + // HMI UPDATES hmiListener = new OnRPCNotificationListener() { @Override public void onNotified(RPCNotification notification) { HMILevel oldHMILevel = currentHMILevel; currentHMILevel = ((OnHMIStatus) notification).getHmiLevel(); - // Auto-send an update if we were in NONE and now we are not - if (oldHMILevel.equals(HMILevel.HMI_NONE) && !currentHMILevel.equals(HMILevel.HMI_NONE)){ - - } + // TODO } }; internalInterface.addOnRPCNotificationListener(FunctionID.ON_HMI_STATUS, hmiListener); @@ -142,6 +200,7 @@ abstract class BaseMenuManager extends BaseSubManager { @Override public void onNotified(RPCNotification notification) { OnCommand onCommand = (OnCommand) notification; + callListenerForCells(menuCells, onCommand); } }; internalInterface.addOnRPCNotificationListener(FunctionID.ON_COMMAND, commandListener); diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java index 333168c85..a22a3ae9b 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java @@ -206,7 +206,7 @@ public class MenuCell { * Get the cellId * @return the cellId for this menuCell */ - private int getCellId() { + public int getCellId() { return cellId; } @@ -214,7 +214,7 @@ public class MenuCell { * Sets the ParentCellId * @param parentCellId the parent cell's Id */ - private void setParentCellId(int parentCellId) { + public void setParentCellId(int parentCellId) { this.parentCellId = parentCellId; } @@ -222,7 +222,7 @@ public class MenuCell { * Get the parent cell's Id * @return the parent cell's Id */ - private int getParentCellId() { + public int getParentCellId() { return parentCellId; } -- cgit v1.2.1 From b653625e8f751a295c69ab6a4630b4816389978c Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Mon, 29 Apr 2019 10:57:42 -0400 Subject: COMMANDS / SUBMENU RPCs --- .../managers/screen/menu/BaseMenuManager.java | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) 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 3150d6b5b..2afc7ab45 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 @@ -41,6 +41,7 @@ import com.smartdevicelink.managers.screen.menu.cells.MenuCell; import com.smartdevicelink.protocol.enums.FunctionID; import com.smartdevicelink.proxy.RPCMessage; import com.smartdevicelink.proxy.RPCNotification; +import com.smartdevicelink.proxy.RPCRequest; import com.smartdevicelink.proxy.SystemCapabilityManager; import com.smartdevicelink.proxy.interfaces.ISdl; import com.smartdevicelink.proxy.interfaces.OnSystemCapabilityListener; @@ -127,6 +128,51 @@ abstract class BaseMenuManager extends BaseSubManager { super.dispose(); } + // COMMANDS / SUBMENU RPCs + + private List mainMenuCommandsForCells(List cells, boolean shouldHaveArtwork) { + List builtCommands = new ArrayList<>(); + + // We need the index so we will use this type of loop + for (int i = 0; i < cells.size(); i++) { + MenuCell cell = cells.get(i); + if (cell.getSubCells().size() > 0){ + builtCommands.add(subMenuCommandForMenuCell(cell, shouldHaveArtwork, i)); + }else{ + builtCommands.add(commandForMenuCell(cell, shouldHaveArtwork, i)); + } + } + return builtCommands; + } + + private List subMenuCommandsForCells(List cells, boolean shouldHaveArtwork){ + List builtCommands = new ArrayList<>(); + for (MenuCell cell : cells){ + if (cell.getSubCells().size() > 0){ + builtCommands.addAll(allCommandsForCells(cell.getSubCells(), shouldHaveArtwork)); + } + } + return builtCommands; + } + + private List allCommandsForCells(List cells, boolean shouldHaveArtwork){ + List builtCommands = new ArrayList<>(); + + // We need the index so we will use this type of loop + for (int i = 0; i < cells.size(); i++) { + MenuCell cell = cells.get(i); + if (cell.getSubCells().size() > 0){ + builtCommands.add(subMenuCommandForMenuCell(cell, shouldHaveArtwork, i)); + // recursively grab the commands for all the sub cells + builtCommands.addAll(allCommandsForCells(cell.getSubCells(), shouldHaveArtwork)); + }else{ + builtCommands.add(commandForMenuCell(cell, shouldHaveArtwork, i)); + } + } + + return builtCommands; + } + private AddCommand commandForMenuCell(MenuCell cell, boolean shouldHaveArtwork, int position){ MenuParams params = new MenuParams(cell.getTitle()); -- cgit v1.2.1 From 245c078bc4ce1100ef591c58f9ed3593b3f8cfbf Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Mon, 29 Apr 2019 14:45:28 -0400 Subject: finishing initial menu manager code --- .../managers/screen/menu/BaseMenuManager.java | 365 ++++++++++++++++++++- .../managers/screen/menu/cells/MenuCell.java | 6 +- 2 files changed, 362 insertions(+), 9 deletions(-) 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 2afc7ab45..61a182c65 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 @@ -37,31 +37,40 @@ import android.support.annotation.NonNull; import com.smartdevicelink.managers.BaseSubManager; import com.smartdevicelink.managers.CompletionListener; import com.smartdevicelink.managers.file.FileManager; +import com.smartdevicelink.managers.file.MultipleFileCompletionListener; +import com.smartdevicelink.managers.file.filetypes.SdlArtwork; import com.smartdevicelink.managers.screen.menu.cells.MenuCell; import com.smartdevicelink.protocol.enums.FunctionID; -import com.smartdevicelink.proxy.RPCMessage; import com.smartdevicelink.proxy.RPCNotification; import com.smartdevicelink.proxy.RPCRequest; -import com.smartdevicelink.proxy.SystemCapabilityManager; +import com.smartdevicelink.proxy.RPCResponse; import com.smartdevicelink.proxy.interfaces.ISdl; import com.smartdevicelink.proxy.interfaces.OnSystemCapabilityListener; import com.smartdevicelink.proxy.rpc.AddCommand; import com.smartdevicelink.proxy.rpc.AddSubMenu; +import com.smartdevicelink.proxy.rpc.DeleteCommand; +import com.smartdevicelink.proxy.rpc.DeleteSubMenu; import com.smartdevicelink.proxy.rpc.DisplayCapabilities; -import com.smartdevicelink.proxy.rpc.Image; +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.RegisterAppInterfaceResponse; import com.smartdevicelink.proxy.rpc.enums.HMILevel; +import com.smartdevicelink.proxy.rpc.enums.ImageFieldName; +import com.smartdevicelink.proxy.rpc.enums.Result; 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.util.DebugTool; +import org.json.JSONException; + import java.lang.ref.WeakReference; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Map; abstract class BaseMenuManager extends BaseSubManager { @@ -70,7 +79,7 @@ abstract class BaseMenuManager extends BaseSubManager { private List menuCells; private List waitingUpdateMenuCells; private List oldMenuCells; - private List inProgressUpdate; + private List inProgressUpdate; private boolean waitingOnHMIUpdate; private boolean hasQueuedUpdate; @@ -128,6 +137,326 @@ abstract class BaseMenuManager extends BaseSubManager { super.dispose(); } + // SETTERS + + /** + * Creates and sends all associated Menu RPCs + * @param cells - the menu cells that are to be sent to the head unit, including their sub-cells. + */ + public void setMenuCells(List cells){ + + if (currentHMILevel == null || currentHMILevel.equals(HMILevel.HMI_NONE) || currentSystemContext.equals(SystemContext.SYSCTXT_MENU)){ + // We are in NONE or the menu is in use, bail out of here + waitingOnHMIUpdate = true; + waitingUpdateMenuCells = cells; + return; + } + + waitingOnHMIUpdate = false; + + // HashSet order doesnt matter / does not allow duplicates + HashSet titleCheckSet = new HashSet<>(); + HashSet allMenuVoiceCommands = new HashSet<>(); + int voiceCommandCount = 0; + + for (MenuCell cell : cells){ + titleCheckSet.add(cell.getTitle()); + if (cell.getVoiceCommands() != null){ + allMenuVoiceCommands.addAll(cell.getVoiceCommands()); + voiceCommandCount += cell.getVoiceCommands().size(); + } + } + + // Check for duplicate titles + if (titleCheckSet.size() != menuCells.size()){ + DebugTool.logError("Not all cell titles are unique. The menu will not be set"); + return; + } + + // Check for duplicate voice commands + if (allMenuVoiceCommands.size() != voiceCommandCount){ + DebugTool.logError("Attempted to create a menu with duplicate voice commands. Voice commands must be unique. The menu will not be set"); + return; + } + + // Set the IDs + lastMenuId = menuCellIdMin; + updateIdsOnMenuCells(cells, parentIdNotFound); + + // Update our Lists + oldMenuCells = menuCells; + menuCells = cells; + + // Upload the Artworks + List artworksToBeUploaded = findAllArtworksToBeUploadedFromCells(menuCells); + + if (artworksToBeUploaded.size() > 0 && fileManager.get() != null){ + fileManager.get().uploadArtworks(artworksToBeUploaded, new MultipleFileCompletionListener() { + @Override + public void onComplete(Map errors) { + if (errors != null && errors.size() > 0){ + DebugTool.logError("Error uploading Menu Artworks: "+ errors.toString()); + } + + DebugTool.logInfo("Menu Artworks Uploaded"); + // Now that Artworks are on the head unit, proceed + updateMenuWithListener(null); + } + }); + }else{ + // No Artworks to be uploaded, send off + updateMenuWithListener(null); + } + } + + // UPDATING SYSTEM + + private void updateMenuWithListener(final CompletionListener listener){ + + if (currentHMILevel == null || currentHMILevel.equals(HMILevel.HMI_NONE) || currentSystemContext.equals(SystemContext.SYSCTXT_MENU)){ + // We are in NONE or the menu is in use, bail out of here + waitingOnHMIUpdate = true; + waitingUpdateMenuCells = menuCells; + return; + } + + if (inProgressUpdate != null && inProgressUpdate.size() > 0){ + // there's an in-progress update so this needs to wait + hasQueuedUpdate = true; + return; + } + + sendCurrentMenu(new CompletionListener() { + @Override + public void onComplete(boolean success) { + inProgressUpdate = null; + + if (!success){ + DebugTool.logError("Error Sending Current Menu"); + if (listener != null){ + listener.onComplete(false); + } + } + + if (hasQueuedUpdate){ + updateMenuWithListener(null); + hasQueuedUpdate = false; + } + } + }); + + } + + // DELETE OLD MENU ITEMS + + private void deleteCurrentMenu(final CompletionListener listener){ + + if (oldMenuCells.size() == 0) { + if (listener != null){ + // technically this method is successful if there's nothing to delete + listener.onComplete(true); + } + return; + } + + List deleteCommands = deleteCommandsForCells(oldMenuCells); + oldMenuCells.clear(); + internalInterface.sendRequests(deleteCommands, new OnMultipleRequestListener() { + @Override + public void onUpdate(int remainingRequests) { + + } + + @Override + public void onFinished() { + DebugTool.logInfo("Successfully deleted all old menu commands"); + if (listener != null){ + listener.onComplete(true); + } + } + + @Override + public void onError(int correlationId, Result resultCode, String info) { + DebugTool.logError("Failed to delete all old menu commands"); + if (listener != null){ + listener.onComplete(false); + } + } + + @Override + public void onResponse(int correlationId, RPCResponse response) { + + } + }); + } + + // SEND NEW MENU ITEMS + + private void sendCurrentMenu(final CompletionListener listener){ + + if (menuCells.size() == 0){ + DebugTool.logInfo("No main menu to send, returning"); + if (listener != null){ + listener.onComplete(false); + } + return; + } + + List mainMenuCommands; + final List subMenuCommands; + + if (findAllArtworksToBeUploadedFromCells(menuCells).size() > 0 || !checkImageFields()){ + // Send artwork-less menu + mainMenuCommands = mainMenuCommandsForCells(menuCells, false); + subMenuCommands = subMenuCommandsForCells(menuCells, false); + } else { + mainMenuCommands = mainMenuCommandsForCells(menuCells, true); + subMenuCommands = subMenuCommandsForCells(menuCells, true); + } + + + // add all built commands to inProgressUpdate + inProgressUpdate = mainMenuCommands; + inProgressUpdate.addAll(subMenuCommands); + + internalInterface.sendRequests(mainMenuCommands, new OnMultipleRequestListener() { + @Override + public void onUpdate(int remainingRequests) { + // nothing here + } + + @Override + public void onFinished() { + + oldMenuCells = menuCells; + sendSubMenuCommands(subMenuCommands, listener); + + DebugTool.logInfo("Finished sending main menu commands. Sending sub menu commands."); + + } + + @Override + public void onError(int correlationId, Result resultCode, String info) { + DebugTool.logError("Failed to send main menu commands: "+ info); + if (listener != null){ + listener.onComplete(false); + } + } + + @Override + public void onResponse(int correlationId, RPCResponse response) { + try { + DebugTool.logInfo("Main Menu response: "+ response.serializeJSON().toString()); + } catch (JSONException e) { + e.printStackTrace(); + } + } + }); + + } + + private void sendSubMenuCommands(List commands, final CompletionListener listener){ + internalInterface.sendRequests(commands, new OnMultipleRequestListener() { + @Override + public void onUpdate(int remainingRequests) { + + } + + @Override + public void onFinished() { + DebugTool.logInfo("Finished Updating Menu"); + if (listener != null){ + listener.onComplete(true); + } + } + + @Override + public void onError(int correlationId, Result resultCode, String info) { + DebugTool.logError("Failed to send sub menu commands: "+ info); + if (listener != null){ + listener.onComplete(false); + } + } + + @Override + public void onResponse(int correlationId, RPCResponse response) { + try { + DebugTool.logInfo("Sub Menu response: "+ response.serializeJSON().toString()); + } catch (JSONException e) { + e.printStackTrace(); + } + } + }); + } + + // OTHER HELPER METHODS: + + // ARTWORKS + + private List findAllArtworksToBeUploadedFromCells(List cells){ + // Make sure we can use images in the menus + if (!checkImageFields()){ + return new ArrayList<>(); + } + + List artworks = new ArrayList<>(); + for (MenuCell cell : cells){ + if (artworkNeedsUpload(cell.getIcon())){ + artworks.add(cell.getIcon()); + } + if (cell.getSubCells().size() > 0){ + artworks.addAll(findAllArtworksToBeUploadedFromCells(cell.getSubCells())); + } + } + + return artworks; + } + + private boolean checkImageFields(){ + List imageFields = displayCapabilities.getImageFields(); + for (ImageField field: imageFields){ + if (field.getName().equals(ImageFieldName.cmdIcon)){ + return true; + } + } + return false; + } + + private boolean artworkNeedsUpload(SdlArtwork artwork){ + if (fileManager.get() != null){ + return (artwork != null && !fileManager.get().hasUploadedFile(artwork) && !artwork.isStaticIcon()); + } + return false; + } + + // IDs + + private void updateIdsOnMenuCells(List cells, int parentId){ + for (MenuCell cell : cells){ + cell.setCellId(++lastMenuId); + cell.setParentCellId(parentId); + if (cell.getSubCells().size() > 0){ + updateIdsOnMenuCells(cell.getSubCells(), cell.getCellId()); + } + } + } + + // DELETES + + private List deleteCommandsForCells(List cells){ + List deletes = new ArrayList<>(); + for (MenuCell cell : cells){ + if (cell.getSubCells() == null){ + DeleteCommand delete = new DeleteCommand(cell.getCellId()); + deletes.add(delete); + }else{ + DeleteSubMenu delete = new DeleteSubMenu(cell.getCellId()); + deletes.add(delete); + } + } + return deletes; + } + // COMMANDS / SUBMENU RPCs private List mainMenuCommandsForCells(List cells, boolean shouldHaveArtwork) { @@ -234,9 +563,31 @@ abstract class BaseMenuManager extends BaseSubManager { hmiListener = new OnRPCNotificationListener() { @Override public void onNotified(RPCNotification notification) { + OnHMIStatus hmiStatus = (OnHMIStatus) notification; HMILevel oldHMILevel = currentHMILevel; - currentHMILevel = ((OnHMIStatus) notification).getHmiLevel(); - // TODO + currentHMILevel = hmiStatus.getHmiLevel(); + + // Auto-send an updated menu if we were in NONE and now we are not, and we need an update + if (oldHMILevel.equals(HMILevel.HMI_NONE) && !currentHMILevel.equals(HMILevel.HMI_NONE) && !currentSystemContext.equals(SystemContext.SYSCTXT_MENU)){ + if (waitingOnHMIUpdate){ + setMenuCells(waitingUpdateMenuCells); + waitingUpdateMenuCells.clear(); + return; + } + } + + // If we don't check for this and only update when not in the menu, there can be IN_USE errors, especially with submenus. + // We also don't want to encourage changing out the menu while the user is using it for usability reasons. + SystemContext oldContext = currentSystemContext; + currentSystemContext = hmiStatus.getSystemContext(); + + if (oldContext.equals(SystemContext.SYSCTXT_MENU) && !currentSystemContext.equals(SystemContext.SYSCTXT_MENU) && !currentHMILevel.equals(HMILevel.HMI_NONE)){ + if (waitingOnHMIUpdate){ + setMenuCells(waitingUpdateMenuCells); + waitingUpdateMenuCells.clear(); + return; + } + } } }; internalInterface.addOnRPCNotificationListener(FunctionID.ON_HMI_STATUS, hmiListener); diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java index a22a3ae9b..130f40d10 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java @@ -195,10 +195,11 @@ public class MenuCell { } /** - * Set the cell Id + * Set the cell Id. + * NOTE: THIS IS USED INTERNALLY ONLY, PLEASE DO NOT SET * @param cellId - the cell Id */ - private void setCellId(int cellId) { + public void setCellId(int cellId) { this.cellId = cellId; } @@ -212,6 +213,7 @@ public class MenuCell { /** * Sets the ParentCellId + * NOTE: THIS IS USED INTERNALLY ONLY, PLEASE DO NOT SET * @param parentCellId the parent cell's Id */ public void setParentCellId(int parentCellId) { -- cgit v1.2.1 From d4c9dde5c146a0b80580a5c749c162bb6d68a073 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Mon, 29 Apr 2019 15:01:16 -0400 Subject: set up menu manager in basesdlmanager --- .../managers/screen/BaseScreenManager.java | 30 +++++++++++++++++++--- .../managers/screen/menu/BaseMenuManager.java | 15 +++++++++-- 2 files changed, 39 insertions(+), 6 deletions(-) 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 ac1f81c0a..a0aa19580 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/BaseScreenManager.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/BaseScreenManager.java @@ -38,7 +38,9 @@ import com.smartdevicelink.managers.BaseSubManager; import com.smartdevicelink.managers.CompletionListener; import com.smartdevicelink.managers.file.FileManager; import com.smartdevicelink.managers.file.filetypes.SdlArtwork; +import com.smartdevicelink.managers.screen.menu.MenuManager; import com.smartdevicelink.managers.screen.menu.VoiceCommandManager; +import com.smartdevicelink.managers.screen.menu.cells.MenuCell; import com.smartdevicelink.managers.screen.menu.cells.VoiceCommand; import com.smartdevicelink.proxy.interfaces.ISdl; import com.smartdevicelink.proxy.rpc.enums.MetadataType; @@ -60,19 +62,20 @@ abstract class BaseScreenManager extends BaseSubManager { private SoftButtonManager softButtonManager; private TextAndGraphicManager textAndGraphicManager; private VoiceCommandManager voiceCommandManager; + private MenuManager menuManager; // Sub manager listener private final CompletionListener subManagerListener = new CompletionListener() { @Override public synchronized void onComplete(boolean success) { - if (softButtonManager != null && textAndGraphicManager != null && voiceCommandManager != null) { - if (softButtonManager.getState() == BaseSubManager.READY && textAndGraphicManager.getState() == BaseSubManager.READY && voiceCommandManager.getState() == BaseSubManager.READY) { + if (softButtonManager != null && textAndGraphicManager != null && voiceCommandManager != null && menuManager != null) { + if (softButtonManager.getState() == BaseSubManager.READY && textAndGraphicManager.getState() == BaseSubManager.READY && voiceCommandManager.getState() == BaseSubManager.READY && menuManager.getState() == BaseSubManager.READY) { DebugTool.logInfo("Starting screen manager, all sub managers are in ready state"); transitionToState(READY); - } else if (softButtonManager.getState() == BaseSubManager.ERROR && textAndGraphicManager.getState() == BaseSubManager.ERROR && voiceCommandManager.getState() == BaseSubManager.ERROR) { + } else if (softButtonManager.getState() == BaseSubManager.ERROR && textAndGraphicManager.getState() == BaseSubManager.ERROR && voiceCommandManager.getState() == BaseSubManager.ERROR && menuManager.getState() == BaseSubManager.ERROR) { Log.e(TAG, "ERROR starting screen manager, both sub managers in error state"); transitionToState(ERROR); - } else if (textAndGraphicManager.getState() == BaseSubManager.SETTING_UP || softButtonManager.getState() == BaseSubManager.SETTING_UP || voiceCommandManager.getState() == BaseSubManager.SETTING_UP) { + } else if (textAndGraphicManager.getState() == BaseSubManager.SETTING_UP || softButtonManager.getState() == BaseSubManager.SETTING_UP || voiceCommandManager.getState() == BaseSubManager.SETTING_UP || menuManager.getState() == BaseSubManager.SETTING_UP) { DebugTool.logInfo("SETTING UP screen manager, one sub manager is still setting up"); transitionToState(SETTING_UP); } else { @@ -99,12 +102,14 @@ abstract class BaseScreenManager extends BaseSubManager { this.softButtonManager.start(subManagerListener); this.textAndGraphicManager.start(subManagerListener); this.voiceCommandManager.start(subManagerListener); + this.menuManager.start(subManagerListener); } private void initialize(){ if (fileManager.get() != null) { this.softButtonManager = new SoftButtonManager(internalInterface, fileManager.get()); this.textAndGraphicManager = new TextAndGraphicManager(internalInterface, fileManager.get(), softButtonManager); + this.menuManager = new MenuManager(internalInterface, fileManager.get()); } this.voiceCommandManager = new VoiceCommandManager(internalInterface); } @@ -117,6 +122,7 @@ abstract class BaseScreenManager extends BaseSubManager { softButtonManager.dispose(); textAndGraphicManager.dispose(); voiceCommandManager.dispose(); + menuManager.dispose(); super.dispose(); } @@ -373,6 +379,22 @@ abstract class BaseScreenManager extends BaseSubManager { this.voiceCommandManager.setVoiceCommands(voiceCommands); } + /** + * The list of currently set menu cells + * @return a List of the currently set menu cells + */ + public List getMenu(){ + return this.menuManager.getMenuCells(); + } + + /** + * Creates and sends all associated Menu RPCs + * @param menuCells - the menu cells that are to be sent to the head unit, including their sub-cells. + */ + public void setMenu(List menuCells){ + this.menuManager.setMenuCells(menuCells); + } + /** * Begin a multiple updates transaction. The updates will be applied when commit() is called
* Note: if we don't use beginTransaction & commit, every update will be sent individually. 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 61a182c65..f58999c47 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 @@ -87,6 +87,7 @@ abstract class BaseMenuManager extends BaseSubManager { private OnRPCNotificationListener hmiListener; private OnRPCNotificationListener commandListener; + private OnSystemCapabilityListener displayListener; private DisplayCapabilities displayCapabilities; private static final int parentIdNotFound = Integer.MAX_VALUE; @@ -133,6 +134,7 @@ abstract class BaseMenuManager extends BaseSubManager { // remove listeners internalInterface.removeOnRPCNotificationListener(FunctionID.ON_HMI_STATUS, hmiListener); internalInterface.removeOnRPCNotificationListener(FunctionID.ON_COMMAND, commandListener); + internalInterface.removeOnSystemCapabilityListener(SystemCapabilityType.DISPLAY, displayListener); super.dispose(); } @@ -209,6 +211,14 @@ abstract class BaseMenuManager extends BaseSubManager { } } + /** + * Returns current list of menu cells + * @return a List of Currently set menu cells + */ + public List getMenuCells(){ + return menuCells; + } + // UPDATING SYSTEM private void updateMenuWithListener(final CompletionListener listener){ @@ -547,7 +557,7 @@ abstract class BaseMenuManager extends BaseSubManager { private void addListeners(){ // DISPLAY CAPABILITIES - via SCM - internalInterface.getCapability(SystemCapabilityType.DISPLAY, new OnSystemCapabilityListener() { + displayListener = new OnSystemCapabilityListener() { @Override public void onCapabilityRetrieved(Object capability) { displayCapabilities = (DisplayCapabilities) capability; @@ -557,7 +567,8 @@ abstract class BaseMenuManager extends BaseSubManager { public void onError(String info) { DebugTool.logError("Unable to retrieve display capabilities: "+ info); } - }); + }; + internalInterface.getCapability(SystemCapabilityType.DISPLAY, displayListener); // HMI UPDATES hmiListener = new OnRPCNotificationListener() { -- cgit v1.2.1 From 1c295a6528abcacc6ee4605d0c1b9df564ae5576 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Mon, 29 Apr 2019 15:10:08 -0400 Subject: add some extra javadocs to classes extending new managers --- .../java/com/smartdevicelink/managers/screen/menu/MenuManager.java | 7 +++++++ .../smartdevicelink/managers/screen/menu/VoiceCommandManager.java | 7 +++++++ .../com/smartdevicelink/managers/screen/menu/BaseMenuManager.java | 1 - .../java/com/smartdevicelink/managers/screen/menu/MenuManager.java | 7 +++++++ .../smartdevicelink/managers/screen/menu/VoiceCommandManager.java | 7 +++++++ 5 files changed, 28 insertions(+), 1 deletion(-) diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManager.java b/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManager.java index b68f55c03..4a28a2792 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManager.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManager.java @@ -35,6 +35,13 @@ package com.smartdevicelink.managers.screen.menu; import com.smartdevicelink.managers.file.FileManager; import com.smartdevicelink.proxy.interfaces.ISdl; +/** + * MenuManager
+ * + * Note: This class must be accessed through the ScreenManager via the SdlManager. Do not instantiate it by itself.
+ * + * The MenuManager takes MenuCell objects and creates and sends all necessary RPCs to build out a menu + */ public class MenuManager extends BaseMenuManager { public MenuManager(ISdl internalInterface, FileManager fileManager) { diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManager.java b/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManager.java index 2d48875a5..a892d3a2c 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManager.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManager.java @@ -34,6 +34,13 @@ package com.smartdevicelink.managers.screen.menu; import com.smartdevicelink.proxy.interfaces.ISdl; +/** + * VoiceCommandManager
+ * + * Note: This class must be accessed through the ScreenManager via the SdlManager. Do not instantiate it by itself.
+ * + * The VoiceCommandManager takes a List of VoiceCommand objects and sets them on the Head unit for you. + */ public class VoiceCommandManager extends BaseVoiceCommandManager { public VoiceCommandManager(ISdl internalInterface) { 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 f58999c47..501f112e7 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 @@ -596,7 +596,6 @@ abstract class BaseMenuManager extends BaseSubManager { if (waitingOnHMIUpdate){ setMenuCells(waitingUpdateMenuCells); waitingUpdateMenuCells.clear(); - return; } } } diff --git a/javaSE/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManager.java b/javaSE/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManager.java index b68f55c03..4a28a2792 100644 --- a/javaSE/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManager.java +++ b/javaSE/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManager.java @@ -35,6 +35,13 @@ package com.smartdevicelink.managers.screen.menu; import com.smartdevicelink.managers.file.FileManager; import com.smartdevicelink.proxy.interfaces.ISdl; +/** + * MenuManager
+ * + * Note: This class must be accessed through the ScreenManager via the SdlManager. Do not instantiate it by itself.
+ * + * The MenuManager takes MenuCell objects and creates and sends all necessary RPCs to build out a menu + */ public class MenuManager extends BaseMenuManager { public MenuManager(ISdl internalInterface, FileManager fileManager) { diff --git a/javaSE/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManager.java b/javaSE/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManager.java index 2d48875a5..a892d3a2c 100644 --- a/javaSE/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManager.java +++ b/javaSE/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManager.java @@ -34,6 +34,13 @@ package com.smartdevicelink.managers.screen.menu; import com.smartdevicelink.proxy.interfaces.ISdl; +/** + * VoiceCommandManager
+ * + * Note: This class must be accessed through the ScreenManager via the SdlManager. Do not instantiate it by itself.
+ * + * The VoiceCommandManager takes a List of VoiceCommand objects and sets them on the Head unit for you. + */ public class VoiceCommandManager extends BaseVoiceCommandManager { public VoiceCommandManager(ISdl internalInterface) { -- cgit v1.2.1 From 5276306957fc821d99f020065ffe51e2209fb068 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Mon, 29 Apr 2019 16:52:41 -0400 Subject: some debugging --- .../java/com/sdl/hellosdlandroid/SdlService.java | 77 +++++++++++------- .../managers/screen/menu/BaseMenuManager.java | 94 ++++++++++++---------- .../screen/menu/BaseVoiceCommandManager.java | 5 +- .../managers/screen/menu/cells/MenuCell.java | 14 ++-- 4 files changed, 114 insertions(+), 76 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 b180c851b..47f45a5d4 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 @@ -15,6 +15,8 @@ import com.smartdevicelink.managers.CompletionListener; import com.smartdevicelink.managers.SdlManager; import com.smartdevicelink.managers.SdlManagerListener; import com.smartdevicelink.managers.file.filetypes.SdlArtwork; +import com.smartdevicelink.managers.screen.menu.MenuSelectionListener; +import com.smartdevicelink.managers.screen.menu.cells.MenuCell; import com.smartdevicelink.protocol.enums.FunctionID; import com.smartdevicelink.proxy.RPCNotification; import com.smartdevicelink.proxy.TTSChunkFactory; @@ -26,12 +28,14 @@ import com.smartdevicelink.proxy.rpc.Speak; import com.smartdevicelink.proxy.rpc.enums.AppHMIType; import com.smartdevicelink.proxy.rpc.enums.FileType; import com.smartdevicelink.proxy.rpc.enums.HMILevel; +import com.smartdevicelink.proxy.rpc.enums.TriggerSource; import com.smartdevicelink.proxy.rpc.listeners.OnRPCNotificationListener; import com.smartdevicelink.transport.BaseTransportConfig; import com.smartdevicelink.transport.MultiplexTransportConfig; import com.smartdevicelink.transport.TCPTransportConfig; import com.smartdevicelink.util.DebugTool; +import java.util.Arrays; import java.util.Collections; import java.util.Vector; @@ -56,8 +60,8 @@ public class SdlService extends Service { // TCP/IP transport config // The default port is 12345 // The IP is of the machine that is running SDL Core - private static final int TCP_PORT = 12345; - private static final String DEV_MACHINE_IP_ADDRESS = "192.168.1.78"; + private static final int TCP_PORT = 16865; + private static final String DEV_MACHINE_IP_ADDRESS = "m.sdl.tools"; // variable to create and call functions of the SyncProxy private SdlManager sdlManager = null; @@ -159,28 +163,13 @@ public class SdlService extends Service { public void onNotified(RPCNotification notification) { OnHMIStatus status = (OnHMIStatus) notification; if (status.getHmiLevel() == HMILevel.HMI_FULL && ((OnHMIStatus) notification).getFirstRun()) { - sendCommands(); + sendMenu(); performWelcomeSpeak(); performWelcomeShow(); } } }); - // Menu Selected Listener - sdlManager.addOnRPCNotificationListener(FunctionID.ON_COMMAND, new OnRPCNotificationListener() { - @Override - public void onNotified(RPCNotification notification) { - OnCommand command = (OnCommand) notification; - Integer id = command.getCmdID(); - if(id != null){ - switch(id){ - case TEST_COMMAND_ID: - showTest(); - break; - } - } - } - }); } @Override @@ -207,16 +196,50 @@ public class SdlService extends Service { } /** - * Add commands for the app on SDL. + * Setup Menu */ - private void sendCommands(){ - AddCommand command = new AddCommand(); - MenuParams params = new MenuParams(); - params.setMenuName(TEST_COMMAND_NAME); - command.setCmdID(TEST_COMMAND_ID); - command.setMenuParams(params); - command.setVrCommands(Collections.singletonList(TEST_COMMAND_NAME)); - sdlManager.sendRPC(command); + private void sendMenu(){ + + // First Menu Item + MenuCell mainCell1 = new MenuCell("Test Cell 1"); + mainCell1.setMenuSelectionListener(new MenuSelectionListener() { + @Override + public void onTriggered(TriggerSource trigger) { + Log.i("MENU", "Test cell 1 triggered"); + } + }); + + sdlManager.getScreenManager().setMenu(Arrays.asList(mainCell1)); + + // Second Menu Item w/ 2 sub cells + MenuCell subCell1 = new MenuCell("Sub 1"); + subCell1.setMenuSelectionListener(new MenuSelectionListener() { + @Override + public void onTriggered(TriggerSource trigger) { + Log.i("MENU", "Sub cell 1 triggered"); + } + }); + MenuCell subCell2 = new MenuCell("Sub 2"); + subCell2.setMenuSelectionListener(new MenuSelectionListener() { + @Override + public void onTriggered(TriggerSource trigger) { + Log.i("MENU", "Sub cell 2 triggered"); + } + }); + // This goes to sub menu, no listener on it + MenuCell mainCell2 = new MenuCell("Test Cell 2", null, Arrays.asList(subCell1, subCell2)); + + // Third Menu Item + MenuCell mainCell3 = new MenuCell("Test Cell 3"); + mainCell3.setMenuSelectionListener(new MenuSelectionListener() { + @Override + public void onTriggered(TriggerSource trigger) { + Log.i("MENU", "Main cell 3 triggered"); + } + }); + + // create cell list and create menu + sdlManager.getScreenManager().setMenu(Arrays.asList(mainCell1, mainCell2, mainCell3)); } /** 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 501f112e7..1eb293778 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 @@ -33,6 +33,7 @@ package com.smartdevicelink.managers.screen.menu; import android.support.annotation.NonNull; +import android.util.Log; import com.smartdevicelink.managers.BaseSubManager; import com.smartdevicelink.managers.CompletionListener; @@ -90,7 +91,8 @@ abstract class BaseMenuManager extends BaseSubManager { private OnSystemCapabilityListener displayListener; private DisplayCapabilities displayCapabilities; - private static final int parentIdNotFound = Integer.MAX_VALUE; + private static final int MAX_ID = 2000000000; + private static final int parentIdNotFound = MAX_ID; private static final int menuCellIdMin = 1; private int lastMenuId; @@ -102,6 +104,8 @@ abstract class BaseMenuManager extends BaseSubManager { // Set up some Vars this.fileManager = new WeakReference<>(fileManager); + currentSystemContext = SystemContext.SYSCTXT_MAIN; + currentHMILevel = HMILevel.HMI_NONE; menuCells = new ArrayList<>(); oldMenuCells = new ArrayList<>(); waitingUpdateMenuCells = new ArrayList<>(); @@ -155,13 +159,14 @@ abstract class BaseMenuManager extends BaseSubManager { } waitingOnHMIUpdate = false; + this.menuCells = new ArrayList<>(cells); // HashSet order doesnt matter / does not allow duplicates HashSet titleCheckSet = new HashSet<>(); HashSet allMenuVoiceCommands = new HashSet<>(); int voiceCommandCount = 0; - for (MenuCell cell : cells){ + for (MenuCell cell : this.menuCells){ titleCheckSet.add(cell.getTitle()); if (cell.getVoiceCommands() != null){ allMenuVoiceCommands.addAll(cell.getVoiceCommands()); @@ -170,7 +175,7 @@ abstract class BaseMenuManager extends BaseSubManager { } // Check for duplicate titles - if (titleCheckSet.size() != menuCells.size()){ + if (titleCheckSet.size() != this.menuCells.size()){ DebugTool.logError("Not all cell titles are unique. The menu will not be set"); return; } @@ -183,14 +188,13 @@ abstract class BaseMenuManager extends BaseSubManager { // Set the IDs lastMenuId = menuCellIdMin; - updateIdsOnMenuCells(cells, parentIdNotFound); + updateIdsOnMenuCells(this.menuCells, parentIdNotFound); // Update our Lists - oldMenuCells = menuCells; - menuCells = cells; + this.oldMenuCells = new ArrayList<>(menuCells); // Upload the Artworks - List artworksToBeUploaded = findAllArtworksToBeUploadedFromCells(menuCells); + List artworksToBeUploaded = findAllArtworksToBeUploadedFromCells(this.menuCells); if (artworksToBeUploaded.size() > 0 && fileManager.get() != null){ fileManager.get().uploadArtworks(artworksToBeUploaded, new MultipleFileCompletionListener() { @@ -236,25 +240,29 @@ abstract class BaseMenuManager extends BaseSubManager { return; } - sendCurrentMenu(new CompletionListener() { + deleteCurrentMenu(new CompletionListener() { @Override public void onComplete(boolean success) { - inProgressUpdate = null; - - if (!success){ - DebugTool.logError("Error Sending Current Menu"); - if (listener != null){ - listener.onComplete(false); + sendCurrentMenu(new CompletionListener() { + @Override + public void onComplete(boolean success) { + inProgressUpdate = null; + + if (!success){ + DebugTool.logError("Error Sending Current Menu"); + if (listener != null){ + listener.onComplete(false); + } + } + + if (hasQueuedUpdate){ + updateMenuWithListener(null); + hasQueuedUpdate = false; + } } - } - - if (hasQueuedUpdate){ - updateMenuWithListener(null); - hasQueuedUpdate = false; - } + }); } }); - } // DELETE OLD MENU ITEMS @@ -270,7 +278,9 @@ abstract class BaseMenuManager extends BaseSubManager { } List deleteCommands = deleteCommandsForCells(oldMenuCells); - oldMenuCells.clear(); + if (oldMenuCells != null && oldMenuCells.size() > 0) { + oldMenuCells.clear(); + } internalInterface.sendRequests(deleteCommands, new OnMultipleRequestListener() { @Override public void onUpdate(int remainingRequests) { @@ -287,10 +297,7 @@ abstract class BaseMenuManager extends BaseSubManager { @Override public void onError(int correlationId, Result resultCode, String info) { - DebugTool.logError("Failed to delete all old menu commands"); - if (listener != null){ - listener.onComplete(false); - } + } @Override @@ -347,10 +354,7 @@ abstract class BaseMenuManager extends BaseSubManager { @Override public void onError(int correlationId, Result resultCode, String info) { - DebugTool.logError("Failed to send main menu commands: "+ info); - if (listener != null){ - listener.onComplete(false); - } + } @Override @@ -414,7 +418,7 @@ abstract class BaseMenuManager extends BaseSubManager { if (artworkNeedsUpload(cell.getIcon())){ artworks.add(cell.getIcon()); } - if (cell.getSubCells().size() > 0){ + if (cell.getSubCells() != null && cell.getSubCells().size() > 0){ artworks.addAll(findAllArtworksToBeUploadedFromCells(cell.getSubCells())); } } @@ -423,10 +427,12 @@ abstract class BaseMenuManager extends BaseSubManager { } private boolean checkImageFields(){ - List imageFields = displayCapabilities.getImageFields(); - for (ImageField field: imageFields){ - if (field.getName().equals(ImageFieldName.cmdIcon)){ - return true; + if (displayCapabilities != null && displayCapabilities.getImageFields() != null) { + List imageFields = displayCapabilities.getImageFields(); + for (ImageField field : imageFields) { + if (field.getName().equals(ImageFieldName.cmdIcon)) { + return true; + } } } return false; @@ -445,7 +451,7 @@ abstract class BaseMenuManager extends BaseSubManager { for (MenuCell cell : cells){ cell.setCellId(++lastMenuId); cell.setParentCellId(parentId); - if (cell.getSubCells().size() > 0){ + if (cell.getSubCells() != null && cell.getSubCells().size() > 0){ updateIdsOnMenuCells(cell.getSubCells(), cell.getCellId()); } } @@ -475,7 +481,7 @@ abstract class BaseMenuManager extends BaseSubManager { // We need the index so we will use this type of loop for (int i = 0; i < cells.size(); i++) { MenuCell cell = cells.get(i); - if (cell.getSubCells().size() > 0){ + if (cell.getSubCells() != null && cell.getSubCells().size() > 0){ builtCommands.add(subMenuCommandForMenuCell(cell, shouldHaveArtwork, i)); }else{ builtCommands.add(commandForMenuCell(cell, shouldHaveArtwork, i)); @@ -487,7 +493,7 @@ abstract class BaseMenuManager extends BaseSubManager { private List subMenuCommandsForCells(List cells, boolean shouldHaveArtwork){ List builtCommands = new ArrayList<>(); for (MenuCell cell : cells){ - if (cell.getSubCells().size() > 0){ + if (cell.getSubCells() != null && cell.getSubCells().size() > 0){ builtCommands.addAll(allCommandsForCells(cell.getSubCells(), shouldHaveArtwork)); } } @@ -500,7 +506,7 @@ abstract class BaseMenuManager extends BaseSubManager { // We need the index so we will use this type of loop for (int i = 0; i < cells.size(); i++) { MenuCell cell = cells.get(i); - if (cell.getSubCells().size() > 0){ + if (cell.getSubCells() != null && cell.getSubCells().size() > 0){ builtCommands.add(subMenuCommandForMenuCell(cell, shouldHaveArtwork, i)); // recursively grab the commands for all the sub cells builtCommands.addAll(allCommandsForCells(cell.getSubCells(), shouldHaveArtwork)); @@ -515,7 +521,7 @@ abstract class BaseMenuManager extends BaseSubManager { private AddCommand commandForMenuCell(MenuCell cell, boolean shouldHaveArtwork, int position){ MenuParams params = new MenuParams(cell.getTitle()); - params.setParentID(cell.getCellId() != Integer.MAX_VALUE ? cell.getParentCellId() : null); + params.setParentID(cell.getParentCellId() != MAX_ID ? cell.getParentCellId() : 0); params.setPosition(position); AddCommand command = new AddCommand(cell.getCellId()); @@ -542,7 +548,7 @@ abstract class BaseMenuManager extends BaseSubManager { return true; } - if (cell.getSubCells().size() > 0){ + if (cell.getSubCells() != null && cell.getSubCells().size() > 0){ // for each cell, if it has sub cells, recursively loop through those as well if (callListenerForCells(cell.getSubCells(), command)) { return true; @@ -561,6 +567,12 @@ abstract class BaseMenuManager extends BaseSubManager { @Override public void onCapabilityRetrieved(Object capability) { displayCapabilities = (DisplayCapabilities) capability; + try { + // TODO REMOVE + Log.i("MENU CAPS", "DISP CAP: "+ displayCapabilities.serializeJSON().toString()); + } catch (JSONException e) { + e.printStackTrace(); + } } @Override diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java index fd2ee7709..3a334daa8 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java @@ -80,8 +80,9 @@ abstract class BaseVoiceCommandManager extends BaseSubManager { public BaseVoiceCommandManager(@NonNull ISdl internalInterface) { super(internalInterface); - addListeners(); + currentHMILevel = HMILevel.HMI_NONE; + addListeners(); lastVoiceCommandId = voiceCommandIdMin; voiceCommands = new ArrayList<>(); oldVoiceCommands = new ArrayList<>(); @@ -229,10 +230,10 @@ abstract class BaseVoiceCommandManager extends BaseSubManager { private void sendCurrentVoiceCommands(final CompletionListener listener){ if (voiceCommands == null || voiceCommands.size() == 0){ - DebugTool.logInfo("No Voice Commands to Send"); if (listener != null){ listener.onComplete(false); } + DebugTool.logInfo("No Voice Commands to Send"); return; } diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java index 130f40d10..5c643acb7 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java @@ -69,6 +69,8 @@ public class MenuCell { private int parentCellId; private int cellId; + private static final int MAX_ID = 2000000000; + // CONSTRUCTORS /** @@ -77,8 +79,8 @@ public class MenuCell { */ public MenuCell(@NonNull String title) { setTitle(title); // title is the only required param - setCellId(Integer.MAX_VALUE); - setParentCellId(Integer.MAX_VALUE); + setCellId(MAX_ID); + setParentCellId(MAX_ID); } /** @@ -91,8 +93,8 @@ public class MenuCell { setTitle(title); // title is the only required param setIcon(icon); setSubCells(subCells); - setCellId(Integer.MAX_VALUE); - setParentCellId(Integer.MAX_VALUE); + setCellId(MAX_ID); + setParentCellId(MAX_ID); } /** @@ -107,8 +109,8 @@ public class MenuCell { setIcon(icon); setVoiceCommands(voiceCommands); setMenuSelectionListener(listener); - setCellId(Integer.MAX_VALUE); - setParentCellId(Integer.MAX_VALUE); + setCellId(MAX_ID); + setParentCellId(MAX_ID); } -- cgit v1.2.1 From 2c686127eaaae58a39a7db3961ffd43ba5717ce5 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Mon, 29 Apr 2019 16:55:39 -0400 Subject: revert sdl service for now --- .../java/com/sdl/hellosdlandroid/SdlService.java | 77 ++++++++-------------- 1 file changed, 27 insertions(+), 50 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 47f45a5d4..b180c851b 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 @@ -15,8 +15,6 @@ import com.smartdevicelink.managers.CompletionListener; import com.smartdevicelink.managers.SdlManager; import com.smartdevicelink.managers.SdlManagerListener; import com.smartdevicelink.managers.file.filetypes.SdlArtwork; -import com.smartdevicelink.managers.screen.menu.MenuSelectionListener; -import com.smartdevicelink.managers.screen.menu.cells.MenuCell; import com.smartdevicelink.protocol.enums.FunctionID; import com.smartdevicelink.proxy.RPCNotification; import com.smartdevicelink.proxy.TTSChunkFactory; @@ -28,14 +26,12 @@ import com.smartdevicelink.proxy.rpc.Speak; import com.smartdevicelink.proxy.rpc.enums.AppHMIType; import com.smartdevicelink.proxy.rpc.enums.FileType; import com.smartdevicelink.proxy.rpc.enums.HMILevel; -import com.smartdevicelink.proxy.rpc.enums.TriggerSource; import com.smartdevicelink.proxy.rpc.listeners.OnRPCNotificationListener; import com.smartdevicelink.transport.BaseTransportConfig; import com.smartdevicelink.transport.MultiplexTransportConfig; import com.smartdevicelink.transport.TCPTransportConfig; import com.smartdevicelink.util.DebugTool; -import java.util.Arrays; import java.util.Collections; import java.util.Vector; @@ -60,8 +56,8 @@ public class SdlService extends Service { // TCP/IP transport config // The default port is 12345 // The IP is of the machine that is running SDL Core - private static final int TCP_PORT = 16865; - private static final String DEV_MACHINE_IP_ADDRESS = "m.sdl.tools"; + private static final int TCP_PORT = 12345; + private static final String DEV_MACHINE_IP_ADDRESS = "192.168.1.78"; // variable to create and call functions of the SyncProxy private SdlManager sdlManager = null; @@ -163,13 +159,28 @@ public class SdlService extends Service { public void onNotified(RPCNotification notification) { OnHMIStatus status = (OnHMIStatus) notification; if (status.getHmiLevel() == HMILevel.HMI_FULL && ((OnHMIStatus) notification).getFirstRun()) { - sendMenu(); + sendCommands(); performWelcomeSpeak(); performWelcomeShow(); } } }); + // Menu Selected Listener + sdlManager.addOnRPCNotificationListener(FunctionID.ON_COMMAND, new OnRPCNotificationListener() { + @Override + public void onNotified(RPCNotification notification) { + OnCommand command = (OnCommand) notification; + Integer id = command.getCmdID(); + if(id != null){ + switch(id){ + case TEST_COMMAND_ID: + showTest(); + break; + } + } + } + }); } @Override @@ -196,50 +207,16 @@ public class SdlService extends Service { } /** - * Setup Menu + * Add commands for the app on SDL. */ - private void sendMenu(){ - - // First Menu Item - MenuCell mainCell1 = new MenuCell("Test Cell 1"); - mainCell1.setMenuSelectionListener(new MenuSelectionListener() { - @Override - public void onTriggered(TriggerSource trigger) { - Log.i("MENU", "Test cell 1 triggered"); - } - }); - - sdlManager.getScreenManager().setMenu(Arrays.asList(mainCell1)); - - // Second Menu Item w/ 2 sub cells - MenuCell subCell1 = new MenuCell("Sub 1"); - subCell1.setMenuSelectionListener(new MenuSelectionListener() { - @Override - public void onTriggered(TriggerSource trigger) { - Log.i("MENU", "Sub cell 1 triggered"); - } - }); - MenuCell subCell2 = new MenuCell("Sub 2"); - subCell2.setMenuSelectionListener(new MenuSelectionListener() { - @Override - public void onTriggered(TriggerSource trigger) { - Log.i("MENU", "Sub cell 2 triggered"); - } - }); - // This goes to sub menu, no listener on it - MenuCell mainCell2 = new MenuCell("Test Cell 2", null, Arrays.asList(subCell1, subCell2)); - - // Third Menu Item - MenuCell mainCell3 = new MenuCell("Test Cell 3"); - mainCell3.setMenuSelectionListener(new MenuSelectionListener() { - @Override - public void onTriggered(TriggerSource trigger) { - Log.i("MENU", "Main cell 3 triggered"); - } - }); - - // create cell list and create menu - sdlManager.getScreenManager().setMenu(Arrays.asList(mainCell1, mainCell2, mainCell3)); + private void sendCommands(){ + AddCommand command = new AddCommand(); + MenuParams params = new MenuParams(); + params.setMenuName(TEST_COMMAND_NAME); + command.setCmdID(TEST_COMMAND_ID); + command.setMenuParams(params); + command.setVrCommands(Collections.singletonList(TEST_COMMAND_NAME)); + sdlManager.sendRPC(command); } /** -- cgit v1.2.1 From 355f56a47fd4db06e47e5b47e171e046d64c28c3 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Tue, 30 Apr 2019 09:38:58 -0400 Subject: restructure some of the menucell class --- .../managers/screen/menu/cells/MenuCell.java | 34 +++++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java index 5c643acb7..bfdaba8b9 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java @@ -33,6 +33,7 @@ package com.smartdevicelink.managers.screen.menu.cells; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import com.smartdevicelink.managers.file.filetypes.SdlArtwork; import com.smartdevicelink.managers.screen.menu.MenuSelectionListener; @@ -69,12 +70,15 @@ public class MenuCell { private int parentCellId; private int cellId; - private static final int MAX_ID = 2000000000; + private static final int MAX_ID = 2000000000; // Cannot use Integer.MAX_INT as the value is too high. // CONSTRUCTORS + // SINGLE MENU ITEM CONSTRUCTORS + /** * Creates a new MenuCell Object with just the title set. + * NOTE: We recommend adding a {@link MenuSelectionListener} to notify you when the cell is clicked * @param title The cell's primary text */ public MenuCell(@NonNull String title) { @@ -84,15 +88,13 @@ public class MenuCell { } /** - * Creates a new MenuCell Object with multiple parameters set + * Creates a new MenuCell Object with just the title set. * @param title The cell's primary text - * @param icon The cell's image - * @param subCells The sub-cells that will appear when the cell is selected + * @param listener a listener that notifies you when the cell was selected and lets you know its trigger source */ - public MenuCell(@NonNull String title, SdlArtwork icon, List subCells) { + public MenuCell(@NonNull String title, @Nullable MenuSelectionListener listener) { setTitle(title); // title is the only required param - setIcon(icon); - setSubCells(subCells); + setMenuSelectionListener(listener); setCellId(MAX_ID); setParentCellId(MAX_ID); } @@ -104,7 +106,7 @@ public class MenuCell { * @param voiceCommands Voice commands that will activate the menu cell * @param listener Calls the code that will be run when the menu cell is selected */ - public MenuCell(@NonNull String title, SdlArtwork icon, List voiceCommands, MenuSelectionListener listener) { + public MenuCell(@NonNull String title, @Nullable MenuSelectionListener listener, @Nullable SdlArtwork icon, @Nullable List voiceCommands) { setTitle(title); // title is the only required param setIcon(icon); setVoiceCommands(voiceCommands); @@ -113,6 +115,22 @@ public class MenuCell { setParentCellId(MAX_ID); } + // CELL THAT WILL LINK TO SUB MENU CONSTRUCTOR + + /** + * Creates a new MenuCell Object with multiple parameters set + * NOTE: because this has sub-cells, there does not need to be a listener + * @param title The cell's primary text + * @param icon The cell's image + * @param subCells The sub-cells that will appear when the cell is selected + */ + public MenuCell(@NonNull String title, @Nullable SdlArtwork icon, @Nullable List subCells) { + setTitle(title); // title is the only required param + setIcon(icon); + setSubCells(subCells); + setCellId(MAX_ID); + setParentCellId(MAX_ID); + } // SETTERS / GETTERS -- cgit v1.2.1 From 044bd293888d163108eb60840005d5c970fb44ce Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Tue, 30 Apr 2019 09:40:29 -0400 Subject: re-worded some javadocs --- .../java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java index bfdaba8b9..bdfca3e80 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java @@ -115,14 +115,14 @@ public class MenuCell { setParentCellId(MAX_ID); } - // CELL THAT WILL LINK TO SUB MENU CONSTRUCTOR + // CONSTRUCTOR FOR CELL THAT WILL LINK TO SUB MENU /** * Creates a new MenuCell Object with multiple parameters set * NOTE: because this has sub-cells, there does not need to be a listener * @param title The cell's primary text * @param icon The cell's image - * @param subCells The sub-cells that will appear when the cell is selected + * @param subCells The sub-cells for the sub menu that will appear when the cell is selected */ public MenuCell(@NonNull String title, @Nullable SdlArtwork icon, @Nullable List subCells) { setTitle(title); // title is the only required param -- cgit v1.2.1 From b88c7936c841d2ed9e2ce6d2d8cfd5a7f9e52099 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Tue, 30 Apr 2019 10:15:46 -0400 Subject: test fixes, and updates --- .../managers/screen/menu/cells/MenuCellTests.java | 8 +++++++- .../java/com/smartdevicelink/test/Test.java | 1 + .../managers/screen/menu/BaseMenuManager.java | 6 ------ .../managers/screen/menu/cells/MenuCell.java | 18 ++++++++++++++---- .../managers/screen/menu/cells/VoiceCommand.java | 15 +++++++++++---- 5 files changed, 33 insertions(+), 15 deletions(-) diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/cells/MenuCellTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/cells/MenuCellTests.java index da53bce3a..b8d8eda13 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/cells/MenuCellTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/cells/MenuCellTests.java @@ -72,6 +72,8 @@ public class MenuCellTests extends AndroidTestCase2 { assertEquals(menuCell.getVoiceCommands(), Test.GENERAL_STRING_LIST); assertEquals(menuCell.getSubCells(), Test.GENERAL_MENUCELL_LIST); assertEquals(menuCell.getMenuSelectionListener(), menuSelectionListener); + assertEquals(menuCell.getCellId(), Test.GENERAL_MENU_MAX_ID); + assertEquals(menuCell.getParentCellId(), Test.GENERAL_MENU_MAX_ID); } public void testConstructors(){ @@ -83,11 +85,15 @@ public class MenuCellTests extends AndroidTestCase2 { assertEquals(menuCell2.getIcon(), Test.GENERAL_ARTWORK); assertEquals(menuCell2.getSubCells(), Test.GENERAL_MENUCELL_LIST); - MenuCell menuCell3 =new MenuCell(Test.GENERAL_STRING, Test.GENERAL_ARTWORK, Test.GENERAL_STRING_LIST, menuSelectionListener); + MenuCell menuCell3 =new MenuCell(Test.GENERAL_STRING, menuSelectionListener, Test.GENERAL_ARTWORK, Test.GENERAL_STRING_LIST); assertEquals(menuCell3.getTitle(), Test.GENERAL_STRING); assertEquals(menuCell3.getIcon(), Test.GENERAL_ARTWORK); assertEquals(menuCell3.getVoiceCommands(), Test.GENERAL_STRING_LIST); assertEquals(menuCell3.getMenuSelectionListener(), menuSelectionListener); + + MenuCell menuCell4 =new MenuCell(Test.GENERAL_STRING, menuSelectionListener); + assertEquals(menuCell4.getTitle(), Test.GENERAL_STRING); + assertEquals(menuCell4.getMenuSelectionListener(), menuSelectionListener); } } diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java index aaa1f51a3..da44aea12 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java @@ -397,6 +397,7 @@ public class Test { public static final HMISettingsControlData GENERAL_HMISETTINGSCONTROLDATA = new HMISettingsControlData(); public static final SdlArtwork GENERAL_ARTWORK = new SdlArtwork(); public static final MenuCell GENERAL_MENUCELL = new MenuCell(GENERAL_STRING); + public static final int GENERAL_MENU_MAX_ID = 2000000000; public static final HMICapabilities GENERAL_HMICAPABILITIES = new HMICapabilities(); 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 1eb293778..b7621c2df 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 @@ -567,12 +567,6 @@ abstract class BaseMenuManager extends BaseSubManager { @Override public void onCapabilityRetrieved(Object capability) { displayCapabilities = (DisplayCapabilities) capability; - try { - // TODO REMOVE - Log.i("MENU CAPS", "DISP CAP: "+ displayCapabilities.serializeJSON().toString()); - } catch (JSONException e) { - e.printStackTrace(); - } } @Override diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java index bdfca3e80..c9c9a85b7 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java @@ -67,10 +67,20 @@ public class MenuCell { */ private MenuSelectionListener menuSelectionListener; + /** + * Used internally for cell ordering + */ private int parentCellId; + + /** + * Used internally for cell ordering + */ private int cellId; - private static final int MAX_ID = 2000000000; // Cannot use Integer.MAX_INT as the value is too high. + /** + * MAX ID for cells - Cannot use Integer.MAX_INT as the value is too high. + */ + private static final int MAX_ID = 2000000000; // CONSTRUCTORS @@ -216,7 +226,7 @@ public class MenuCell { /** * Set the cell Id. - * NOTE: THIS IS USED INTERNALLY ONLY, PLEASE DO NOT SET + * * NOTE: THIS IS USED INTERNALLY ONLY, PLEASE DO NOT SET * @param cellId - the cell Id */ public void setCellId(int cellId) { @@ -233,7 +243,7 @@ public class MenuCell { /** * Sets the ParentCellId - * NOTE: THIS IS USED INTERNALLY ONLY, PLEASE DO NOT SET + * NOTE: THIS IS USED INTERNALLY ONLY, PLEASE DO NOT SET * @param parentCellId the parent cell's Id */ public void setParentCellId(int parentCellId) { @@ -257,6 +267,6 @@ public class MenuCell { public String getDescription(){ return "MenuCell - ID: "+cellId+ " title: "+ title + " ArtworkName: "+ icon.getName() + " VoiceCommands: "+ voiceCommands.size() + " isSubCell: " + (parentCellId != Integer.MAX_VALUE ? "YES":"NO")+ - " hasSubCells: "+ (subCells.size() > 0 ? "YES":"NO"); + " hasSubCells: "+ (subCells != null && subCells.size() > 0 ? "YES":"NO"); } } diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/VoiceCommand.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/VoiceCommand.java index 4f6f51d56..90dae67bf 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/VoiceCommand.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/VoiceCommand.java @@ -32,6 +32,9 @@ package com.smartdevicelink.managers.screen.menu.cells; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; + import com.smartdevicelink.managers.screen.menu.VoiceCommandSelectionListener; import java.util.List; @@ -48,17 +51,20 @@ public class VoiceCommand { */ private VoiceCommandSelectionListener voiceCommandSelectionListener; - + /** + * Used Internally to identify the command + */ private int commandId; // CONSTRUCTOR(S) /** * Constructor that sets all parameters for this class + * NOTE: While it is possible to pass in null for the listener, It is the easiest way to know when it was triggered. * @param voiceCommands The strings the user can say to activate this voice command * @param voiceCommandSelectionListener The listener that will be called when the command is activated */ - public VoiceCommand(List voiceCommands, VoiceCommandSelectionListener voiceCommandSelectionListener){ + public VoiceCommand(@NonNull List voiceCommands, @Nullable VoiceCommandSelectionListener voiceCommandSelectionListener){ setVoiceCommands(voiceCommands); setVoiceCommandSelectionListener(voiceCommandSelectionListener); } @@ -69,7 +75,7 @@ public class VoiceCommand { * The strings the user can say to activate this voice command * @param voiceCommands - the list of commands to send to the head unit */ - public void setVoiceCommands(List voiceCommands) { + public void setVoiceCommands(@NonNull List voiceCommands) { this.voiceCommands = voiceCommands; } @@ -98,7 +104,8 @@ public class VoiceCommand { } /** - * set the command ID + * set the command' ID + * NOTE: PLEASE DO NOT SET. This is used internally * @param commandId the id to identify the command */ public void setCommandId(int commandId) { -- cgit v1.2.1 From c63ab3a45a80a30fed0d3f571106412db3b9c21f Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Tue, 30 Apr 2019 11:56:11 -0400 Subject: updates from testing --- .../managers/screen/menu/cells/MenuCellTests.java | 2 +- .../managers/screen/menu/BaseMenuManager.java | 14 ++++++++------ .../managers/screen/menu/BaseVoiceCommandManager.java | 5 +---- .../managers/screen/menu/cells/MenuCell.java | 2 +- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/cells/MenuCellTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/cells/MenuCellTests.java index b8d8eda13..7f25c2ad7 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/cells/MenuCellTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/cells/MenuCellTests.java @@ -85,7 +85,7 @@ public class MenuCellTests extends AndroidTestCase2 { assertEquals(menuCell2.getIcon(), Test.GENERAL_ARTWORK); assertEquals(menuCell2.getSubCells(), Test.GENERAL_MENUCELL_LIST); - MenuCell menuCell3 =new MenuCell(Test.GENERAL_STRING, menuSelectionListener, Test.GENERAL_ARTWORK, Test.GENERAL_STRING_LIST); + MenuCell menuCell3 =new MenuCell(Test.GENERAL_STRING, Test.GENERAL_ARTWORK, Test.GENERAL_STRING_LIST, menuSelectionListener); assertEquals(menuCell3.getTitle(), Test.GENERAL_STRING); assertEquals(menuCell3.getIcon(), Test.GENERAL_ARTWORK); assertEquals(menuCell3.getVoiceCommands(), Test.GENERAL_STRING_LIST); 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 b7621c2df..5ff20e278 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 @@ -314,7 +314,8 @@ abstract class BaseMenuManager extends BaseSubManager { if (menuCells.size() == 0){ DebugTool.logInfo("No main menu to send, returning"); if (listener != null){ - listener.onComplete(false); + // This can be considered a success if the user was clearing out their menu + listener.onComplete(true); } return; } @@ -331,7 +332,6 @@ abstract class BaseMenuManager extends BaseSubManager { subMenuCommands = subMenuCommandsForCells(menuCells, true); } - // add all built commands to inProgressUpdate inProgressUpdate = mainMenuCommands; inProgressUpdate.addAll(subMenuCommands); @@ -346,10 +346,12 @@ abstract class BaseMenuManager extends BaseSubManager { public void onFinished() { oldMenuCells = menuCells; - sendSubMenuCommands(subMenuCommands, listener); - - DebugTool.logInfo("Finished sending main menu commands. Sending sub menu commands."); - + if (subMenuCommands.size() > 0) { + sendSubMenuCommands(subMenuCommands, listener); + DebugTool.logInfo("Finished sending main menu commands. Sending sub menu commands."); + }else{ + DebugTool.logInfo("Finished sending main menu commands."); + } } @Override diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java index 3a334daa8..ec346bd37 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java @@ -231,7 +231,7 @@ abstract class BaseVoiceCommandManager extends BaseSubManager { if (voiceCommands == null || voiceCommands.size() == 0){ if (listener != null){ - listener.onComplete(false); + listener.onComplete(true); // no voice commands to send doesnt mean that its an error } DebugTool.logInfo("No Voice Commands to Send"); return; @@ -264,9 +264,6 @@ abstract class BaseVoiceCommandManager extends BaseSubManager { @Override public void onResponse(int correlationId, RPCResponse response) { - if (response != null && !response.getSuccess()){ - DebugTool.logError("Error sending voice commands: "+ response.getInfo()); - } } }); } diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java index c9c9a85b7..8a36e5672 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java @@ -116,7 +116,7 @@ public class MenuCell { * @param voiceCommands Voice commands that will activate the menu cell * @param listener Calls the code that will be run when the menu cell is selected */ - public MenuCell(@NonNull String title, @Nullable MenuSelectionListener listener, @Nullable SdlArtwork icon, @Nullable List voiceCommands) { + public MenuCell(@NonNull String title, @Nullable SdlArtwork icon, @Nullable List voiceCommands, @Nullable MenuSelectionListener listener) { setTitle(title); // title is the only required param setIcon(icon); setVoiceCommands(voiceCommands); -- cgit v1.2.1 From 7c01713b748f9684d3b90396e2e701dfe3899e36 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Tue, 30 Apr 2019 14:05:21 -0400 Subject: fixed deleting menu --- .../managers/screen/menu/BaseMenuManager.java | 31 +++++++++++----------- 1 file changed, 16 insertions(+), 15 deletions(-) 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 5ff20e278..59931356a 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 @@ -157,25 +157,26 @@ abstract class BaseMenuManager extends BaseSubManager { waitingUpdateMenuCells = cells; return; } - waitingOnHMIUpdate = false; - this.menuCells = new ArrayList<>(cells); + + // Update our Lists + this.oldMenuCells = new ArrayList<>(menuCells); + menuCells = new ArrayList<>(cells); // HashSet order doesnt matter / does not allow duplicates HashSet titleCheckSet = new HashSet<>(); HashSet allMenuVoiceCommands = new HashSet<>(); int voiceCommandCount = 0; - for (MenuCell cell : this.menuCells){ + for (MenuCell cell : menuCells){ titleCheckSet.add(cell.getTitle()); if (cell.getVoiceCommands() != null){ allMenuVoiceCommands.addAll(cell.getVoiceCommands()); voiceCommandCount += cell.getVoiceCommands().size(); } } - // Check for duplicate titles - if (titleCheckSet.size() != this.menuCells.size()){ + if (titleCheckSet.size() != menuCells.size()){ DebugTool.logError("Not all cell titles are unique. The menu will not be set"); return; } @@ -185,17 +186,11 @@ abstract class BaseMenuManager extends BaseSubManager { DebugTool.logError("Attempted to create a menu with duplicate voice commands. Voice commands must be unique. The menu will not be set"); return; } - // Set the IDs lastMenuId = menuCellIdMin; - updateIdsOnMenuCells(this.menuCells, parentIdNotFound); - - // Update our Lists - this.oldMenuCells = new ArrayList<>(menuCells); - + updateIdsOnMenuCells(menuCells, parentIdNotFound); // Upload the Artworks - List artworksToBeUploaded = findAllArtworksToBeUploadedFromCells(this.menuCells); - + List artworksToBeUploaded = findAllArtworksToBeUploadedFromCells(menuCells); if (artworksToBeUploaded.size() > 0 && fileManager.get() != null){ fileManager.get().uploadArtworks(artworksToBeUploaded, new MultipleFileCompletionListener() { @Override @@ -229,6 +224,7 @@ abstract class BaseMenuManager extends BaseSubManager { if (currentHMILevel == null || currentHMILevel.equals(HMILevel.HMI_NONE) || currentSystemContext.equals(SystemContext.SYSCTXT_MENU)){ // We are in NONE or the menu is in use, bail out of here + DebugTool.logInfo("HMI in None or System Context Menu, returning"); waitingOnHMIUpdate = true; waitingUpdateMenuCells = menuCells; return; @@ -236,6 +232,7 @@ abstract class BaseMenuManager extends BaseSubManager { if (inProgressUpdate != null && inProgressUpdate.size() > 0){ // there's an in-progress update so this needs to wait + DebugTool.logInfo("There is an in progress Menu Update, returning"); hasQueuedUpdate = true; return; } @@ -268,10 +265,10 @@ abstract class BaseMenuManager extends BaseSubManager { // DELETE OLD MENU ITEMS private void deleteCurrentMenu(final CompletionListener listener){ - if (oldMenuCells.size() == 0) { if (listener != null){ // technically this method is successful if there's nothing to delete + DebugTool.logInfo("No old cells to delete, returning"); listener.onComplete(true); } return; @@ -333,7 +330,7 @@ abstract class BaseMenuManager extends BaseSubManager { } // add all built commands to inProgressUpdate - inProgressUpdate = mainMenuCommands; + inProgressUpdate = new ArrayList<>(mainMenuCommands); inProgressUpdate.addAll(subMenuCommands); internalInterface.sendRequests(mainMenuCommands, new OnMultipleRequestListener() { @@ -350,6 +347,7 @@ abstract class BaseMenuManager extends BaseSubManager { sendSubMenuCommands(subMenuCommands, listener); DebugTool.logInfo("Finished sending main menu commands. Sending sub menu commands."); }else{ + inProgressUpdate = null; DebugTool.logInfo("Finished sending main menu commands."); } } @@ -381,6 +379,7 @@ abstract class BaseMenuManager extends BaseSubManager { @Override public void onFinished() { DebugTool.logInfo("Finished Updating Menu"); + inProgressUpdate = null; if (listener != null){ listener.onComplete(true); } @@ -589,6 +588,7 @@ abstract class BaseMenuManager extends BaseSubManager { // Auto-send an updated menu if we were in NONE and now we are not, and we need an update if (oldHMILevel.equals(HMILevel.HMI_NONE) && !currentHMILevel.equals(HMILevel.HMI_NONE) && !currentSystemContext.equals(SystemContext.SYSCTXT_MENU)){ if (waitingOnHMIUpdate){ + DebugTool.logInfo("We now have proper HMI, sending waiting update"); setMenuCells(waitingUpdateMenuCells); waitingUpdateMenuCells.clear(); return; @@ -602,6 +602,7 @@ abstract class BaseMenuManager extends BaseSubManager { if (oldContext.equals(SystemContext.SYSCTXT_MENU) && !currentSystemContext.equals(SystemContext.SYSCTXT_MENU) && !currentHMILevel.equals(HMILevel.HMI_NONE)){ if (waitingOnHMIUpdate){ + DebugTool.logInfo("We now have a proper system context, sending waiting update"); setMenuCells(waitingUpdateMenuCells); waitingUpdateMenuCells.clear(); } -- cgit v1.2.1 From 2377cb2e8f7b94066f37ea0c707a9e3587fad476 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Tue, 30 Apr 2019 14:35:15 -0400 Subject: fix bug in voice command manager --- .../managers/screen/menu/BaseVoiceCommandManager.java | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java index ec346bd37..e10c2aae6 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java @@ -133,7 +133,7 @@ abstract class BaseVoiceCommandManager extends BaseSubManager { waitingOnHMIUpdate = false; lastVoiceCommandId = voiceCommandIdMin; updateIdsOnVoiceCommands(voiceCommands); - oldVoiceCommands = voiceCommands; + oldVoiceCommands = new ArrayList<>(voiceCommands); this.voiceCommands = voiceCommands; updateWithListener(null); @@ -201,7 +201,9 @@ abstract class BaseVoiceCommandManager extends BaseSubManager { oldVoiceCommands.clear(); internalInterface.sendRequests(deleteVoiceCommands, new OnMultipleRequestListener() { @Override - public void onUpdate(int remainingRequests) {} + public void onUpdate(int remainingRequests) { + + } @Override public void onFinished() { @@ -213,10 +215,7 @@ abstract class BaseVoiceCommandManager extends BaseSubManager { @Override public void onError(int correlationId, Result resultCode, String info) { - DebugTool.logError("Error deleting old voice commands"); - if (listener != null){ - listener.onComplete(false); - } + } @Override @@ -233,7 +232,6 @@ abstract class BaseVoiceCommandManager extends BaseSubManager { if (listener != null){ listener.onComplete(true); // no voice commands to send doesnt mean that its an error } - DebugTool.logInfo("No Voice Commands to Send"); return; } @@ -242,7 +240,7 @@ abstract class BaseVoiceCommandManager extends BaseSubManager { internalInterface.sendRequests(inProgressUpdate, new OnMultipleRequestListener() { @Override public void onUpdate(int remainingRequests) { - DebugTool.logInfo("Remaining Voice Commands: "+ remainingRequests); + } @Override @@ -256,10 +254,7 @@ abstract class BaseVoiceCommandManager extends BaseSubManager { @Override public void onError(int correlationId, Result resultCode, String info) { - DebugTool.logError("Add Commands Failed: "+info); - if (listener != null){ - listener.onComplete(false); - } + } @Override -- cgit v1.2.1 From b0399b47ac26a363c4e152cd51a10fef1f242608 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Tue, 30 Apr 2019 14:36:40 -0400 Subject: remove unused imports --- .../com/smartdevicelink/managers/screen/menu/BaseMenuManager.java | 1 - .../managers/screen/menu/BaseVoiceCommandManager.java | 5 ----- 2 files changed, 6 deletions(-) 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 59931356a..2a6a72238 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 @@ -33,7 +33,6 @@ package com.smartdevicelink.managers.screen.menu; import android.support.annotation.NonNull; -import android.util.Log; import com.smartdevicelink.managers.BaseSubManager; import com.smartdevicelink.managers.CompletionListener; diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java index e10c2aae6..a87f4f206 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java @@ -45,11 +45,8 @@ import com.smartdevicelink.proxy.rpc.AddCommand; import com.smartdevicelink.proxy.rpc.DeleteCommand; import com.smartdevicelink.proxy.rpc.OnCommand; import com.smartdevicelink.proxy.rpc.OnHMIStatus; -import com.smartdevicelink.proxy.rpc.SetMediaClockTimer; -import com.smartdevicelink.proxy.rpc.StartTime; import com.smartdevicelink.proxy.rpc.enums.HMILevel; import com.smartdevicelink.proxy.rpc.enums.Result; -import com.smartdevicelink.proxy.rpc.enums.UpdateMode; import com.smartdevicelink.proxy.rpc.listeners.OnMultipleRequestListener; import com.smartdevicelink.proxy.rpc.listeners.OnRPCNotificationListener; import com.smartdevicelink.util.DebugTool; @@ -57,8 +54,6 @@ import com.smartdevicelink.util.DebugTool; import java.util.ArrayList; import java.util.List; -import static com.smartdevicelink.proxy.rpc.SetMediaClockTimer.countUpFromStartTime; - abstract class BaseVoiceCommandManager extends BaseSubManager { private List voiceCommands; -- cgit v1.2.1 From b8723d34c5254ecdbfbcf5f470de68a4dcb6faac Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Tue, 30 Apr 2019 15:04:32 -0400 Subject: remove redundant constructor --- .../smartdevicelink/managers/screen/menu/cells/MenuCell.java | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java index 8a36e5672..424243df9 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java @@ -86,17 +86,6 @@ public class MenuCell { // SINGLE MENU ITEM CONSTRUCTORS - /** - * Creates a new MenuCell Object with just the title set. - * NOTE: We recommend adding a {@link MenuSelectionListener} to notify you when the cell is clicked - * @param title The cell's primary text - */ - public MenuCell(@NonNull String title) { - setTitle(title); // title is the only required param - setCellId(MAX_ID); - setParentCellId(MAX_ID); - } - /** * Creates a new MenuCell Object with just the title set. * @param title The cell's primary text -- cgit v1.2.1 From 4ec9453feecf940dcf3f9f430368eabd471abcab Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Tue, 30 Apr 2019 15:08:39 -0400 Subject: refactor cells to protect their IDs --- .../managers/screen/BaseScreenManager.java | 4 +- .../managers/screen/menu/BaseMenuManager.java | 1 - .../screen/menu/BaseVoiceCommandManager.java | 1 - .../managers/screen/menu/MenuCell.java | 260 ++++++++++++++++++++ .../managers/screen/menu/VoiceCommand.java | 132 +++++++++++ .../managers/screen/menu/cells/MenuCell.java | 261 --------------------- .../managers/screen/menu/cells/VoiceCommand.java | 132 ----------- 7 files changed, 394 insertions(+), 397 deletions(-) create mode 100644 base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java create mode 100644 base/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommand.java delete mode 100644 base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java delete mode 100644 base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/VoiceCommand.java 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 a0aa19580..ec560dfd9 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/BaseScreenManager.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/BaseScreenManager.java @@ -40,8 +40,8 @@ import com.smartdevicelink.managers.file.FileManager; import com.smartdevicelink.managers.file.filetypes.SdlArtwork; import com.smartdevicelink.managers.screen.menu.MenuManager; import com.smartdevicelink.managers.screen.menu.VoiceCommandManager; -import com.smartdevicelink.managers.screen.menu.cells.MenuCell; -import com.smartdevicelink.managers.screen.menu.cells.VoiceCommand; +import com.smartdevicelink.managers.screen.menu.MenuCell; +import com.smartdevicelink.managers.screen.menu.VoiceCommand; import com.smartdevicelink.proxy.interfaces.ISdl; import com.smartdevicelink.proxy.rpc.enums.MetadataType; import com.smartdevicelink.proxy.rpc.enums.TextAlignment; 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 2a6a72238..ee8235395 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 @@ -39,7 +39,6 @@ import com.smartdevicelink.managers.CompletionListener; import com.smartdevicelink.managers.file.FileManager; import com.smartdevicelink.managers.file.MultipleFileCompletionListener; import com.smartdevicelink.managers.file.filetypes.SdlArtwork; -import com.smartdevicelink.managers.screen.menu.cells.MenuCell; import com.smartdevicelink.protocol.enums.FunctionID; import com.smartdevicelink.proxy.RPCNotification; import com.smartdevicelink.proxy.RPCRequest; diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java index a87f4f206..55b5ffd65 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java @@ -36,7 +36,6 @@ import android.support.annotation.NonNull; import com.smartdevicelink.managers.BaseSubManager; import com.smartdevicelink.managers.CompletionListener; -import com.smartdevicelink.managers.screen.menu.cells.VoiceCommand; import com.smartdevicelink.protocol.enums.FunctionID; import com.smartdevicelink.proxy.RPCNotification; import com.smartdevicelink.proxy.RPCResponse; diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java new file mode 100644 index 000000000..0ec33541a --- /dev/null +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java @@ -0,0 +1,260 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +package com.smartdevicelink.managers.screen.menu; + +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; + +import com.smartdevicelink.managers.file.filetypes.SdlArtwork; + +import java.util.List; + +public class MenuCell { + + /** + * The cell's text to be displayed + */ + private String title; + + /** + * The cell's icon to be displayed + */ + private SdlArtwork icon; + + /** + * The strings the user can say to activate this voice command + */ + private List voiceCommands; + + /** + * If this is not null, this cell will be a sub-menu button, displaying the sub-cells in a menu when pressed. + */ + private List subCells; + + /** + * The listener that will be called when the command is activated + */ + private MenuSelectionListener menuSelectionListener; + + /** + * Used internally for cell ordering + */ + private int parentCellId; + + /** + * Used internally for cell ordering + */ + private int cellId; + + /** + * MAX ID for cells - Cannot use Integer.MAX_INT as the value is too high. + */ + private static final int MAX_ID = 2000000000; + + // CONSTRUCTORS + + // SINGLE MENU ITEM CONSTRUCTORS + + /** + * Creates a new MenuCell Object with just the title set. + * @param title The cell's primary text + * @param listener a listener that notifies you when the cell was selected and lets you know its trigger source + */ + public MenuCell(@NonNull String title, @Nullable MenuSelectionListener listener) { + setTitle(title); // title is the only required param + setMenuSelectionListener(listener); + setCellId(MAX_ID); + setParentCellId(MAX_ID); + } + + /** + * Creates a new MenuCell Object with multiple parameters set + * @param title The cell's primary text + * @param icon The cell's image + * @param voiceCommands Voice commands that will activate the menu cell + * @param listener Calls the code that will be run when the menu cell is selected + */ + public MenuCell(@NonNull String title, @Nullable SdlArtwork icon, @Nullable List voiceCommands, @Nullable MenuSelectionListener listener) { + setTitle(title); // title is the only required param + setIcon(icon); + setVoiceCommands(voiceCommands); + setMenuSelectionListener(listener); + setCellId(MAX_ID); + setParentCellId(MAX_ID); + } + + // CONSTRUCTOR FOR CELL THAT WILL LINK TO SUB MENU + + /** + * Creates a new MenuCell Object with multiple parameters set + * NOTE: because this has sub-cells, there does not need to be a listener + * @param title The cell's primary text + * @param icon The cell's image + * @param subCells The sub-cells for the sub menu that will appear when the cell is selected + */ + public MenuCell(@NonNull String title, @Nullable SdlArtwork icon, @Nullable List subCells) { + setTitle(title); // title is the only required param + setIcon(icon); + setSubCells(subCells); + setCellId(MAX_ID); + setParentCellId(MAX_ID); + } + + // SETTERS / GETTERS + + /** + * Sets the title of the menu cell + * @param title - the title of the cell. Required + */ + public void setTitle(@NonNull String title){ + this.title = title; + } + + /** + * Gets the title of the menu cell + * @return The title of the cell object + */ + public String getTitle(){ + return title; + } + + /** + * Sets the icon of the menu cell + * @param icon - the icon being set, of type {@link SdlArtwork} + */ + public void setIcon(SdlArtwork icon){ + this.icon = icon; + } + + /** + * Gets the icon for the cell + * @return the {@link SdlArtwork} icon for the cell + */ + public SdlArtwork getIcon() { + return icon; + } + + /** + * A list of Strings that will be used for voice commands + * @param voiceCommands - the string list used by the IVI system for voice commands + */ + public void setVoiceCommands(List voiceCommands) { + this.voiceCommands = voiceCommands; + } + + /** + * the string list used by the IVI system for voice commands + * @return The String List used by the menu cell object for voice commands + */ + public List getVoiceCommands() { + return voiceCommands; + } + + /** + * The list of MenuCells that can be set as subCells + * @param subCells - the list of subCells for this menu item + */ + public void setSubCells(List subCells) { + this.subCells = subCells; + } + + /** + * The list of subCells for this menu item + * @return a list of MenuCells that are the subCells for this menu item + */ + public List getSubCells() { + return subCells; + } + + /** + * The listener for when a menu item is selected + * @param menuSelectionListener the listener for this menuCell object + */ + public void setMenuSelectionListener(MenuSelectionListener menuSelectionListener) { + this.menuSelectionListener = menuSelectionListener; + } + + /** + * The listener that gets triggered when the menuCell object is selected + * @return the MenuSelectionListener for the cell + */ + public MenuSelectionListener getMenuSelectionListener() { + return menuSelectionListener; + } + + /** + * Set the cell Id. + * * NOTE: THIS IS USED INTERNALLY ONLY, PLEASE DO NOT SET + * @param cellId - the cell Id + */ + void setCellId(int cellId) { + this.cellId = cellId; + } + + /** + * Get the cellId + * @return the cellId for this menuCell + */ + int getCellId() { + return cellId; + } + + /** + * Sets the ParentCellId + * NOTE: THIS IS USED INTERNALLY ONLY, PLEASE DO NOT SET + * @param parentCellId the parent cell's Id + */ + void setParentCellId(int parentCellId) { + this.parentCellId = parentCellId; + } + + /** + * Get the parent cell's Id + * @return the parent cell's Id + */ + int getParentCellId() { + return parentCellId; + } + + // HELPER + + /** + * Get the description of the cell + * @return a String description of the cell object + */ + public String getDescription(){ + return "MenuCell - ID: "+cellId+ " title: "+ title + " ArtworkName: "+ + icon.getName() + " VoiceCommands: "+ voiceCommands.size() + " isSubCell: " + (parentCellId != Integer.MAX_VALUE ? "YES":"NO")+ + " hasSubCells: "+ (subCells != null && subCells.size() > 0 ? "YES":"NO"); + } +} diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommand.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommand.java new file mode 100644 index 000000000..c912f36fb --- /dev/null +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommand.java @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +package com.smartdevicelink.managers.screen.menu; + +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; + +import com.smartdevicelink.managers.screen.menu.VoiceCommandSelectionListener; + +import java.util.List; + +public class VoiceCommand { + + /** + * The strings the user can say to activate this voice command + */ + private List voiceCommands; + + /** + * The listener that will be called when the command is activated + */ + private VoiceCommandSelectionListener voiceCommandSelectionListener; + + /** + * Used Internally to identify the command + */ + private int commandId; + + // CONSTRUCTOR(S) + + /** + * Constructor that sets all parameters for this class + * NOTE: While it is possible to pass in null for the listener, It is the easiest way to know when it was triggered. + * @param voiceCommands The strings the user can say to activate this voice command + * @param voiceCommandSelectionListener The listener that will be called when the command is activated + */ + public VoiceCommand(@NonNull List voiceCommands, @Nullable VoiceCommandSelectionListener voiceCommandSelectionListener){ + setVoiceCommands(voiceCommands); + setVoiceCommandSelectionListener(voiceCommandSelectionListener); + } + + // SETTERS / GETTERS + + /** + * The strings the user can say to activate this voice command + * @param voiceCommands - the list of commands to send to the head unit + */ + public void setVoiceCommands(@NonNull List voiceCommands) { + this.voiceCommands = voiceCommands; + } + + /** + * The strings the user can say to activate this voice command + * @return the List of voice commands + */ + public List getVoiceCommands() { + return voiceCommands; + } + + /** + * The listener that will be called when the command is activated + * @param voiceCommandSelectionListener - the listener for this object + */ + public void setVoiceCommandSelectionListener(VoiceCommandSelectionListener voiceCommandSelectionListener) { + this.voiceCommandSelectionListener = voiceCommandSelectionListener; + } + + /** + * The listener that will be called when the command is activated + * @return voiceCommandSelectionListener - the listener for this object + */ + public VoiceCommandSelectionListener getVoiceCommandSelectionListener() { + return voiceCommandSelectionListener; + } + + /** + * set the command' ID + * NOTE: PLEASE DO NOT SET. This is used internally + * @param commandId the id to identify the command + */ + void setCommandId(int commandId) { + this.commandId = commandId; + } + + /** + * the id used to identify the command + * @return the id + */ + int getCommandId() { + return commandId; + } + + // HELPER + + /** + * Get the description of the cell + * @return a String description of the cell object + */ + public String getDescription(){ + return "VOICE COMMAND - ID: "+commandId+ " First Object: "+ voiceCommands.get(0)+ " Voice Commands: "+ voiceCommands.size(); + } +} diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java deleted file mode 100644 index 424243df9..000000000 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/MenuCell.java +++ /dev/null @@ -1,261 +0,0 @@ -/* - * Copyright (c) 2019 Livio, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of the Livio Inc. nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -package com.smartdevicelink.managers.screen.menu.cells; - -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; - -import com.smartdevicelink.managers.file.filetypes.SdlArtwork; -import com.smartdevicelink.managers.screen.menu.MenuSelectionListener; - -import java.util.List; - -public class MenuCell { - - /** - * The cell's text to be displayed - */ - private String title; - - /** - * The cell's icon to be displayed - */ - private SdlArtwork icon; - - /** - * The strings the user can say to activate this voice command - */ - private List voiceCommands; - - /** - * If this is not null, this cell will be a sub-menu button, displaying the sub-cells in a menu when pressed. - */ - private List subCells; - - /** - * The listener that will be called when the command is activated - */ - private MenuSelectionListener menuSelectionListener; - - /** - * Used internally for cell ordering - */ - private int parentCellId; - - /** - * Used internally for cell ordering - */ - private int cellId; - - /** - * MAX ID for cells - Cannot use Integer.MAX_INT as the value is too high. - */ - private static final int MAX_ID = 2000000000; - - // CONSTRUCTORS - - // SINGLE MENU ITEM CONSTRUCTORS - - /** - * Creates a new MenuCell Object with just the title set. - * @param title The cell's primary text - * @param listener a listener that notifies you when the cell was selected and lets you know its trigger source - */ - public MenuCell(@NonNull String title, @Nullable MenuSelectionListener listener) { - setTitle(title); // title is the only required param - setMenuSelectionListener(listener); - setCellId(MAX_ID); - setParentCellId(MAX_ID); - } - - /** - * Creates a new MenuCell Object with multiple parameters set - * @param title The cell's primary text - * @param icon The cell's image - * @param voiceCommands Voice commands that will activate the menu cell - * @param listener Calls the code that will be run when the menu cell is selected - */ - public MenuCell(@NonNull String title, @Nullable SdlArtwork icon, @Nullable List voiceCommands, @Nullable MenuSelectionListener listener) { - setTitle(title); // title is the only required param - setIcon(icon); - setVoiceCommands(voiceCommands); - setMenuSelectionListener(listener); - setCellId(MAX_ID); - setParentCellId(MAX_ID); - } - - // CONSTRUCTOR FOR CELL THAT WILL LINK TO SUB MENU - - /** - * Creates a new MenuCell Object with multiple parameters set - * NOTE: because this has sub-cells, there does not need to be a listener - * @param title The cell's primary text - * @param icon The cell's image - * @param subCells The sub-cells for the sub menu that will appear when the cell is selected - */ - public MenuCell(@NonNull String title, @Nullable SdlArtwork icon, @Nullable List subCells) { - setTitle(title); // title is the only required param - setIcon(icon); - setSubCells(subCells); - setCellId(MAX_ID); - setParentCellId(MAX_ID); - } - - // SETTERS / GETTERS - - /** - * Sets the title of the menu cell - * @param title - the title of the cell. Required - */ - public void setTitle(@NonNull String title){ - this.title = title; - } - - /** - * Gets the title of the menu cell - * @return The title of the cell object - */ - public String getTitle(){ - return title; - } - - /** - * Sets the icon of the menu cell - * @param icon - the icon being set, of type {@link SdlArtwork} - */ - public void setIcon(SdlArtwork icon){ - this.icon = icon; - } - - /** - * Gets the icon for the cell - * @return the {@link SdlArtwork} icon for the cell - */ - public SdlArtwork getIcon() { - return icon; - } - - /** - * A list of Strings that will be used for voice commands - * @param voiceCommands - the string list used by the IVI system for voice commands - */ - public void setVoiceCommands(List voiceCommands) { - this.voiceCommands = voiceCommands; - } - - /** - * the string list used by the IVI system for voice commands - * @return The String List used by the menu cell object for voice commands - */ - public List getVoiceCommands() { - return voiceCommands; - } - - /** - * The list of MenuCells that can be set as subCells - * @param subCells - the list of subCells for this menu item - */ - public void setSubCells(List subCells) { - this.subCells = subCells; - } - - /** - * The list of subCells for this menu item - * @return a list of MenuCells that are the subCells for this menu item - */ - public List getSubCells() { - return subCells; - } - - /** - * The listener for when a menu item is selected - * @param menuSelectionListener the listener for this menuCell object - */ - public void setMenuSelectionListener(MenuSelectionListener menuSelectionListener) { - this.menuSelectionListener = menuSelectionListener; - } - - /** - * The listener that gets triggered when the menuCell object is selected - * @return the MenuSelectionListener for the cell - */ - public MenuSelectionListener getMenuSelectionListener() { - return menuSelectionListener; - } - - /** - * Set the cell Id. - * * NOTE: THIS IS USED INTERNALLY ONLY, PLEASE DO NOT SET - * @param cellId - the cell Id - */ - public void setCellId(int cellId) { - this.cellId = cellId; - } - - /** - * Get the cellId - * @return the cellId for this menuCell - */ - public int getCellId() { - return cellId; - } - - /** - * Sets the ParentCellId - * NOTE: THIS IS USED INTERNALLY ONLY, PLEASE DO NOT SET - * @param parentCellId the parent cell's Id - */ - public void setParentCellId(int parentCellId) { - this.parentCellId = parentCellId; - } - - /** - * Get the parent cell's Id - * @return the parent cell's Id - */ - public int getParentCellId() { - return parentCellId; - } - - // HELPER - - /** - * Get the description of the cell - * @return a String description of the cell object - */ - public String getDescription(){ - return "MenuCell - ID: "+cellId+ " title: "+ title + " ArtworkName: "+ - icon.getName() + " VoiceCommands: "+ voiceCommands.size() + " isSubCell: " + (parentCellId != Integer.MAX_VALUE ? "YES":"NO")+ - " hasSubCells: "+ (subCells != null && subCells.size() > 0 ? "YES":"NO"); - } -} diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/VoiceCommand.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/VoiceCommand.java deleted file mode 100644 index 90dae67bf..000000000 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/cells/VoiceCommand.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright (c) 2019 Livio, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of the Livio Inc. nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -package com.smartdevicelink.managers.screen.menu.cells; - -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; - -import com.smartdevicelink.managers.screen.menu.VoiceCommandSelectionListener; - -import java.util.List; - -public class VoiceCommand { - - /** - * The strings the user can say to activate this voice command - */ - private List voiceCommands; - - /** - * The listener that will be called when the command is activated - */ - private VoiceCommandSelectionListener voiceCommandSelectionListener; - - /** - * Used Internally to identify the command - */ - private int commandId; - - // CONSTRUCTOR(S) - - /** - * Constructor that sets all parameters for this class - * NOTE: While it is possible to pass in null for the listener, It is the easiest way to know when it was triggered. - * @param voiceCommands The strings the user can say to activate this voice command - * @param voiceCommandSelectionListener The listener that will be called when the command is activated - */ - public VoiceCommand(@NonNull List voiceCommands, @Nullable VoiceCommandSelectionListener voiceCommandSelectionListener){ - setVoiceCommands(voiceCommands); - setVoiceCommandSelectionListener(voiceCommandSelectionListener); - } - - // SETTERS / GETTERS - - /** - * The strings the user can say to activate this voice command - * @param voiceCommands - the list of commands to send to the head unit - */ - public void setVoiceCommands(@NonNull List voiceCommands) { - this.voiceCommands = voiceCommands; - } - - /** - * The strings the user can say to activate this voice command - * @return the List of voice commands - */ - public List getVoiceCommands() { - return voiceCommands; - } - - /** - * The listener that will be called when the command is activated - * @param voiceCommandSelectionListener - the listener for this object - */ - public void setVoiceCommandSelectionListener(VoiceCommandSelectionListener voiceCommandSelectionListener) { - this.voiceCommandSelectionListener = voiceCommandSelectionListener; - } - - /** - * The listener that will be called when the command is activated - * @return voiceCommandSelectionListener - the listener for this object - */ - public VoiceCommandSelectionListener getVoiceCommandSelectionListener() { - return voiceCommandSelectionListener; - } - - /** - * set the command' ID - * NOTE: PLEASE DO NOT SET. This is used internally - * @param commandId the id to identify the command - */ - public void setCommandId(int commandId) { - this.commandId = commandId; - } - - /** - * the id used to identify the command - * @return the id - */ - public int getCommandId() { - return commandId; - } - - // HELPER - - /** - * Get the description of the cell - * @return a String description of the cell object - */ - public String getDescription(){ - return "VOICE COMMAND - ID: "+commandId+ " First Object: "+ voiceCommands.get(0)+ " Voice Commands: "+ voiceCommands.size(); - } -} -- cgit v1.2.1 From a9aafa498678365e35daf21a5c8e7189ad51eda4 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Tue, 30 Apr 2019 15:13:15 -0400 Subject: refactor tests to match new cell structure --- .../managers/screen/menu/MenuCellTests.java | 91 ++++++++++++++++++++ .../managers/screen/menu/VoiceCommandTests.java | 64 ++++++++++++++ .../managers/screen/menu/cells/MenuCellTests.java | 99 ---------------------- .../screen/menu/cells/VoiceCommandTests.java | 65 -------------- .../java/com/smartdevicelink/test/Test.java | 13 ++- 5 files changed, 164 insertions(+), 168 deletions(-) create mode 100644 android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/MenuCellTests.java create mode 100644 android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/VoiceCommandTests.java delete mode 100644 android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/cells/MenuCellTests.java delete mode 100644 android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/cells/VoiceCommandTests.java diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/MenuCellTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/MenuCellTests.java new file mode 100644 index 000000000..00b34865a --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/MenuCellTests.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +package com.smartdevicelink.managers.screen.menu; + +import com.smartdevicelink.AndroidTestCase2; +import com.smartdevicelink.proxy.rpc.enums.TriggerSource; +import com.smartdevicelink.test.Test; + + +public class MenuCellTests extends AndroidTestCase2 { + + private MenuSelectionListener menuSelectionListener = new MenuSelectionListener() { + @Override + public void onTriggered(TriggerSource trigger) { + // stuff + } + }; + + @Override + public void setUp() throws Exception{ + super.setUp(); + } + + @Override + public void tearDown() throws Exception { + super.tearDown(); + } + + public void testSettersAndGetters(){ + + // set everything + MenuCell menuCell = new MenuCell(Test.GENERAL_STRING, menuSelectionListener); + menuCell.setIcon(Test.GENERAL_ARTWORK); + menuCell.setVoiceCommands(Test.GENERAL_STRING_LIST); + menuCell.setMenuSelectionListener(menuSelectionListener); + + // use getters and assert equality + assertEquals(menuCell.getTitle(), Test.GENERAL_STRING); + assertEquals(menuCell.getIcon(), Test.GENERAL_ARTWORK); + assertEquals(menuCell.getVoiceCommands(), Test.GENERAL_STRING_LIST); + assertEquals(menuCell.getMenuSelectionListener(), menuSelectionListener); + assertEquals(menuCell.getCellId(), Test.GENERAL_MENU_MAX_ID); + assertEquals(menuCell.getParentCellId(), Test.GENERAL_MENU_MAX_ID); + } + + public void testConstructors(){ + + // first constructor was tested in previous method, use the last two here + + MenuCell menuCell3 =new MenuCell(Test.GENERAL_STRING, Test.GENERAL_ARTWORK, Test.GENERAL_STRING_LIST, menuSelectionListener); + assertEquals(menuCell3.getTitle(), Test.GENERAL_STRING); + assertEquals(menuCell3.getIcon(), Test.GENERAL_ARTWORK); + assertEquals(menuCell3.getVoiceCommands(), Test.GENERAL_STRING_LIST); + assertEquals(menuCell3.getMenuSelectionListener(), menuSelectionListener); + + MenuCell menuCell4 =new MenuCell(Test.GENERAL_STRING, menuSelectionListener); + assertEquals(menuCell4.getTitle(), Test.GENERAL_STRING); + assertEquals(menuCell4.getMenuSelectionListener(), menuSelectionListener); + } + +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/VoiceCommandTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/VoiceCommandTests.java new file mode 100644 index 000000000..f8a8a538d --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/VoiceCommandTests.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +package com.smartdevicelink.managers.screen.menu; + +import com.smartdevicelink.AndroidTestCase2; +import com.smartdevicelink.test.Test; + +public class VoiceCommandTests extends AndroidTestCase2 { + + private VoiceCommandSelectionListener voiceCommandSelectionListener = new VoiceCommandSelectionListener() { + @Override + public void onVoiceCommandSelected() { + // Stuffs + } + }; + + @Override + public void setUp() throws Exception{ + super.setUp(); + } + + @Override + public void tearDown() throws Exception { + super.tearDown(); + } + + public void testSettersAndGetters(){ + VoiceCommand voiceCommand = new VoiceCommand(Test.GENERAL_STRING_LIST, voiceCommandSelectionListener); + + assertEquals(voiceCommand.getVoiceCommands(), Test.GENERAL_STRING_LIST); + assertEquals(voiceCommand.getVoiceCommandSelectionListener(), voiceCommandSelectionListener); + } + +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/cells/MenuCellTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/cells/MenuCellTests.java deleted file mode 100644 index 7f25c2ad7..000000000 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/cells/MenuCellTests.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) 2019 Livio, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of the Livio Inc. nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -package com.smartdevicelink.managers.screen.menu.cells; - -import com.smartdevicelink.AndroidTestCase2; -import com.smartdevicelink.managers.screen.menu.MenuSelectionListener; -import com.smartdevicelink.proxy.rpc.enums.TriggerSource; -import com.smartdevicelink.test.Test; - - -public class MenuCellTests extends AndroidTestCase2 { - - private MenuSelectionListener menuSelectionListener = new MenuSelectionListener() { - @Override - public void onTriggered(TriggerSource trigger) { - // stuff - } - }; - - @Override - public void setUp() throws Exception{ - super.setUp(); - } - - @Override - public void tearDown() throws Exception { - super.tearDown(); - } - - public void testSettersAndGetters(){ - - // set everything - MenuCell menuCell = new MenuCell(Test.GENERAL_STRING); - menuCell.setIcon(Test.GENERAL_ARTWORK); - menuCell.setVoiceCommands(Test.GENERAL_STRING_LIST); - menuCell.setSubCells(Test.GENERAL_MENUCELL_LIST); - menuCell.setMenuSelectionListener(menuSelectionListener); - - // use getters and assert equality - assertEquals(menuCell.getTitle(), Test.GENERAL_STRING); - assertEquals(menuCell.getIcon(), Test.GENERAL_ARTWORK); - assertEquals(menuCell.getVoiceCommands(), Test.GENERAL_STRING_LIST); - assertEquals(menuCell.getSubCells(), Test.GENERAL_MENUCELL_LIST); - assertEquals(menuCell.getMenuSelectionListener(), menuSelectionListener); - assertEquals(menuCell.getCellId(), Test.GENERAL_MENU_MAX_ID); - assertEquals(menuCell.getParentCellId(), Test.GENERAL_MENU_MAX_ID); - } - - public void testConstructors(){ - - // first constructor was tested in previous method, use the last two here - - MenuCell menuCell2 =new MenuCell(Test.GENERAL_STRING, Test.GENERAL_ARTWORK, Test.GENERAL_MENUCELL_LIST); - assertEquals(menuCell2.getTitle(), Test.GENERAL_STRING); - assertEquals(menuCell2.getIcon(), Test.GENERAL_ARTWORK); - assertEquals(menuCell2.getSubCells(), Test.GENERAL_MENUCELL_LIST); - - MenuCell menuCell3 =new MenuCell(Test.GENERAL_STRING, Test.GENERAL_ARTWORK, Test.GENERAL_STRING_LIST, menuSelectionListener); - assertEquals(menuCell3.getTitle(), Test.GENERAL_STRING); - assertEquals(menuCell3.getIcon(), Test.GENERAL_ARTWORK); - assertEquals(menuCell3.getVoiceCommands(), Test.GENERAL_STRING_LIST); - assertEquals(menuCell3.getMenuSelectionListener(), menuSelectionListener); - - MenuCell menuCell4 =new MenuCell(Test.GENERAL_STRING, menuSelectionListener); - assertEquals(menuCell4.getTitle(), Test.GENERAL_STRING); - assertEquals(menuCell4.getMenuSelectionListener(), menuSelectionListener); - } - -} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/cells/VoiceCommandTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/cells/VoiceCommandTests.java deleted file mode 100644 index 906727e89..000000000 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/cells/VoiceCommandTests.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2019 Livio, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of the Livio Inc. nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -package com.smartdevicelink.managers.screen.menu.cells; - -import com.smartdevicelink.AndroidTestCase2; -import com.smartdevicelink.managers.screen.menu.VoiceCommandSelectionListener; -import com.smartdevicelink.test.Test; - -public class VoiceCommandTests extends AndroidTestCase2 { - - private VoiceCommandSelectionListener voiceCommandSelectionListener = new VoiceCommandSelectionListener() { - @Override - public void onVoiceCommandSelected() { - // Stuffs - } - }; - - @Override - public void setUp() throws Exception{ - super.setUp(); - } - - @Override - public void tearDown() throws Exception { - super.tearDown(); - } - - public void testSettersAndGetters(){ - VoiceCommand voiceCommand = new VoiceCommand(Test.GENERAL_STRING_LIST, voiceCommandSelectionListener); - - assertEquals(voiceCommand.getVoiceCommands(), Test.GENERAL_STRING_LIST); - assertEquals(voiceCommand.getVoiceCommandSelectionListener(), voiceCommandSelectionListener); - } - -} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java index da44aea12..3a75cd55b 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java @@ -4,10 +4,10 @@ import android.graphics.Color; import android.util.Log; import com.smartdevicelink.R; -import com.smartdevicelink.SdlConnection.SdlSession2; import com.smartdevicelink.managers.file.filetypes.SdlArtwork; import com.smartdevicelink.managers.lockscreen.LockScreenConfig; -import com.smartdevicelink.managers.screen.menu.cells.MenuCell; +import com.smartdevicelink.managers.screen.menu.MenuCell; +import com.smartdevicelink.managers.screen.menu.MenuSelectionListener; import com.smartdevicelink.protocol.SdlProtocol; import com.smartdevicelink.protocol.enums.FunctionID; import com.smartdevicelink.proxy.SdlProxyBase; @@ -396,8 +396,6 @@ public class Test { public static final LightControlData GENERAL_LIGHTCONTROLDATA = new LightControlData(); public static final HMISettingsControlData GENERAL_HMISETTINGSCONTROLDATA = new HMISettingsControlData(); public static final SdlArtwork GENERAL_ARTWORK = new SdlArtwork(); - public static final MenuCell GENERAL_MENUCELL = new MenuCell(GENERAL_STRING); - public static final int GENERAL_MENU_MAX_ID = 2000000000; public static final HMICapabilities GENERAL_HMICAPABILITIES = new HMICapabilities(); @@ -454,6 +452,13 @@ public class Test { public static final List GENERAL_WEATHERDATA_LIST = Arrays.asList(GENERAL_WEATHERDATA); public static final List GENERAL_WEATHERALERT_LIST = Arrays.asList(GENERAL_WEATHERALERT); public static final List GENERAL_NAVIGATION_INSTRUCTION_LIST = Arrays.asList(GENERAL_NAVIGATION_INSTRUCTION); + public static final int GENERAL_MENU_MAX_ID = 2000000000; + public static final MenuCell GENERAL_MENUCELL = new MenuCell(GENERAL_STRING, new MenuSelectionListener() { + @Override + public void onTriggered(TriggerSource trigger) { + // + } + }); public static final List GENERAL_MENUCELL_LIST = Arrays.asList(GENERAL_MENUCELL); -- cgit v1.2.1 From b9705c8544db5306250317efb641b68559918430 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Tue, 30 Apr 2019 15:27:00 -0400 Subject: fix bug with waitingUpdateMenuCells --- .../java/com/smartdevicelink/managers/screen/menu/BaseMenuManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 ee8235395..aaedd298b 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 @@ -152,7 +152,7 @@ abstract class BaseMenuManager extends BaseSubManager { if (currentHMILevel == null || currentHMILevel.equals(HMILevel.HMI_NONE) || currentSystemContext.equals(SystemContext.SYSCTXT_MENU)){ // We are in NONE or the menu is in use, bail out of here waitingOnHMIUpdate = true; - waitingUpdateMenuCells = cells; + waitingUpdateMenuCells = new ArrayList<>(cells); return; } waitingOnHMIUpdate = false; -- cgit v1.2.1 From a02208f63235ab4b6b9994642d0ac91acaba1e75 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Tue, 30 Apr 2019 15:29:24 -0400 Subject: fix some context with artwork completion logging --- .../com/smartdevicelink/managers/screen/menu/BaseMenuManager.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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 aaedd298b..71b8f3ae8 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 @@ -193,12 +193,13 @@ abstract class BaseMenuManager extends BaseSubManager { fileManager.get().uploadArtworks(artworksToBeUploaded, new MultipleFileCompletionListener() { @Override public void onComplete(Map errors) { + if (errors != null && errors.size() > 0){ DebugTool.logError("Error uploading Menu Artworks: "+ errors.toString()); + }else{ + DebugTool.logInfo("Menu Artworks Uploaded"); } - - DebugTool.logInfo("Menu Artworks Uploaded"); - // Now that Artworks are on the head unit, proceed + // proceed updateMenuWithListener(null); } }); -- cgit v1.2.1 From 324f18b3d281e3d665d7cf5541703522d217d0f2 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Tue, 30 Apr 2019 15:40:07 -0400 Subject: applied suggested fixes, clarified method name --- .../managers/screen/menu/BaseMenuManager.java | 20 +++++++++----------- .../screen/menu/BaseVoiceCommandManager.java | 14 +++++--------- 2 files changed, 14 insertions(+), 20 deletions(-) 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 71b8f3ae8..f60e6c1a5 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 @@ -96,7 +96,7 @@ abstract class BaseMenuManager extends BaseSubManager { private SystemContext currentSystemContext; - public BaseMenuManager(@NonNull ISdl internalInterface, @NonNull FileManager fileManager) { + BaseMenuManager(@NonNull ISdl internalInterface, @NonNull FileManager fileManager) { super(internalInterface); @@ -200,12 +200,12 @@ abstract class BaseMenuManager extends BaseSubManager { DebugTool.logInfo("Menu Artworks Uploaded"); } // proceed - updateMenuWithListener(null); + updateMenuWithListener(); } }); }else{ // No Artworks to be uploaded, send off - updateMenuWithListener(null); + updateMenuWithListener(); } } @@ -219,7 +219,7 @@ abstract class BaseMenuManager extends BaseSubManager { // UPDATING SYSTEM - private void updateMenuWithListener(final CompletionListener listener){ + private void updateMenuWithListener(){ if (currentHMILevel == null || currentHMILevel.equals(HMILevel.HMI_NONE) || currentSystemContext.equals(SystemContext.SYSCTXT_MENU)){ // We are in NONE or the menu is in use, bail out of here @@ -246,13 +246,10 @@ abstract class BaseMenuManager extends BaseSubManager { if (!success){ DebugTool.logError("Error Sending Current Menu"); - if (listener != null){ - listener.onComplete(false); - } } if (hasQueuedUpdate){ - updateMenuWithListener(null); + updateMenuWithListener(); hasQueuedUpdate = false; } } @@ -319,7 +316,7 @@ abstract class BaseMenuManager extends BaseSubManager { List mainMenuCommands; final List subMenuCommands; - if (findAllArtworksToBeUploadedFromCells(menuCells).size() > 0 || !checkImageFields()){ + if (findAllArtworksToBeUploadedFromCells(menuCells).size() > 0 || !supportsImages()){ // Send artwork-less menu mainMenuCommands = mainMenuCommandsForCells(menuCells, false); subMenuCommands = subMenuCommandsForCells(menuCells, false); @@ -409,7 +406,7 @@ abstract class BaseMenuManager extends BaseSubManager { private List findAllArtworksToBeUploadedFromCells(List cells){ // Make sure we can use images in the menus - if (!checkImageFields()){ + if (!supportsImages()){ return new ArrayList<>(); } @@ -426,7 +423,8 @@ abstract class BaseMenuManager extends BaseSubManager { return artworks; } - private boolean checkImageFields(){ + @SuppressWarnings("BooleanMethodIsAlwaysInverted") + private boolean supportsImages(){ if (displayCapabilities != null && displayCapabilities.getImageFields() != null) { List imageFields = displayCapabilities.getImageFields(); for (ImageField field : imageFields) { diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java index 55b5ffd65..0931851d5 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java @@ -72,7 +72,7 @@ abstract class BaseVoiceCommandManager extends BaseSubManager { // CONSTRUCTORS - public BaseVoiceCommandManager(@NonNull ISdl internalInterface) { + BaseVoiceCommandManager(@NonNull ISdl internalInterface) { super(internalInterface); currentHMILevel = HMILevel.HMI_NONE; @@ -130,7 +130,7 @@ abstract class BaseVoiceCommandManager extends BaseSubManager { oldVoiceCommands = new ArrayList<>(voiceCommands); this.voiceCommands = voiceCommands; - updateWithListener(null); + updateWithListener(); } public List getVoiceCommands(){ @@ -139,7 +139,7 @@ abstract class BaseVoiceCommandManager extends BaseSubManager { // UPDATING SYSTEM - private void updateWithListener(final CompletionListener listener){ + private void updateWithListener(){ if (currentHMILevel == null || currentHMILevel.equals(HMILevel.HMI_NONE)){ waitingOnHMIUpdate = true; @@ -162,14 +162,10 @@ abstract class BaseVoiceCommandManager extends BaseSubManager { inProgressUpdate = null; if (hasQueuedUpdate){ - updateWithListener(null); + updateWithListener(); hasQueuedUpdate = false; } - if (listener != null){ - listener.onComplete(success2); - } - if (!success2){ DebugTool.logError("Error sending voice commands"); } @@ -308,7 +304,7 @@ abstract class BaseVoiceCommandManager extends BaseSubManager { if (waitingOnHMIUpdate){ setVoiceCommands(voiceCommands); }else{ - updateWithListener(null); + updateWithListener(); } } } -- cgit v1.2.1 From b8d5bfd3e334d04823660c2b4a271bd9a86adeda Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Wed, 1 May 2019 11:39:09 -0400 Subject: start of vcm tests --- .../managers/screen/menu/MenuManagerTests.java | 17 +++++ .../screen/menu/VoiceCommandManagerTests.java | 77 ++++++++++++++++++++++ .../screen/menu/BaseVoiceCommandManager.java | 18 ++--- 3 files changed, 103 insertions(+), 9 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 e766ed62a..f61128c8d 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 @@ -32,9 +32,26 @@ package com.smartdevicelink.managers.screen.menu; +import android.content.Context; + import com.smartdevicelink.AndroidTestCase2; public class MenuManagerTests extends AndroidTestCase2 { + public static final String TAG = "MenuManagerTests"; + private Context mTestContext; + + // SETUP / HELPERS + + @Override + public void setUp() throws Exception{ + super.setUp(); + mTestContext = this.getContext(); + } + + @Override + public void tearDown() throws Exception { + super.tearDown(); + } } diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManagerTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManagerTests.java index 49c77b116..bbddf6ab4 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManagerTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManagerTests.java @@ -33,8 +33,85 @@ package com.smartdevicelink.managers.screen.menu; import com.smartdevicelink.AndroidTestCase2; +import com.smartdevicelink.managers.BaseSubManager; +import com.smartdevicelink.managers.CompletionListener; +import com.smartdevicelink.proxy.interfaces.ISdl; +import com.smartdevicelink.proxy.rpc.enums.HMILevel; + +import java.util.Arrays; +import java.util.List; + +import static org.mockito.Mockito.mock; public class VoiceCommandManagerTests extends AndroidTestCase2 { + public static final String TAG = "VCMTests"; + private List commands; + private VoiceCommandManager voiceCommandManager; + private static final int voiceCommandIdMin = 1900000000; + + // SETUP / HELPERS + + @Override + public void setUp() throws Exception{ + super.setUp(); + + VoiceCommand command = new VoiceCommand(Arrays.asList("Command one", "Command two"), null); + VoiceCommand command2 = new VoiceCommand(Arrays.asList("Command three", "Command four"), null); + commands = Arrays.asList(command,command2); + + ISdl internalInterface = mock(ISdl.class); + voiceCommandManager = new VoiceCommandManager(internalInterface); + + // Check some stuff during setup + assertEquals(voiceCommandManager.currentHMILevel, HMILevel.HMI_NONE); + assertEquals(voiceCommandManager.getState(), BaseSubManager.SETTING_UP); + assertEquals(voiceCommandManager.lastVoiceCommandId, voiceCommandIdMin); + assertFalse(voiceCommandManager.hasQueuedUpdate); + assertFalse(voiceCommandManager.waitingOnHMIUpdate); + assertNotNull(voiceCommandManager.commandListener); + assertNotNull(voiceCommandManager.hmiListener); + assertNotNull(voiceCommandManager.voiceCommands); + assertNotNull(voiceCommandManager.oldVoiceCommands); + assertNull(voiceCommandManager.inProgressUpdate); + } + + @Override + public void tearDown() throws Exception { + + voiceCommandManager.dispose(); + + assertEquals(voiceCommandManager.lastVoiceCommandId, voiceCommandIdMin); + assertNull(voiceCommandManager.voiceCommands); + assertNull(voiceCommandManager.oldVoiceCommands); + assertNull(voiceCommandManager.currentHMILevel); + assertNull(voiceCommandManager.inProgressUpdate); + assertFalse(voiceCommandManager.hasQueuedUpdate); + assertFalse(voiceCommandManager.waitingOnHMIUpdate); + // after everything, make sure we are in the correct state + assertEquals(voiceCommandManager.getState(), BaseSubManager.SHUTDOWN); + + super.tearDown(); + } + + public void testStartVoiceCommandManager(){ + + voiceCommandManager.start(new CompletionListener() { + @Override + public void onComplete(boolean success) { + assertTrue(success); + // Make sure the state has changed, as the Screen Manager is dependant on it + assertEquals(voiceCommandManager.getState(), BaseSubManager.READY); + // now that we are started, set some voice commands + sendCommands(voiceCommandManager); + } + }); + } + + private void sendCommands(VoiceCommandManager voiceCommandManager){ + + voiceCommandManager.setVoiceCommands(commands); + + } } diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java index 0931851d5..e8b57ec05 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java @@ -55,20 +55,20 @@ import java.util.List; abstract class BaseVoiceCommandManager extends BaseSubManager { - private List voiceCommands; - private List oldVoiceCommands; + List voiceCommands; + List oldVoiceCommands; - private List inProgressUpdate; + List inProgressUpdate; - private int lastVoiceCommandId; + int lastVoiceCommandId; private static final int voiceCommandIdMin = 1900000000; - private boolean waitingOnHMIUpdate; - private boolean hasQueuedUpdate; + boolean waitingOnHMIUpdate; + boolean hasQueuedUpdate; - private HMILevel currentHMILevel; - private OnRPCNotificationListener hmiListener; - private OnRPCNotificationListener commandListener; + HMILevel currentHMILevel; + OnRPCNotificationListener hmiListener; + OnRPCNotificationListener commandListener; // CONSTRUCTORS -- cgit v1.2.1 From 61d63db0e516c39c045cfcb714100e7abf1441ab Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Wed, 1 May 2019 14:11:10 -0400 Subject: fixed an hmi update issue in vcm, more tests --- .../screen/menu/VoiceCommandManagerTests.java | 46 ++++++++++++++++++++-- .../screen/menu/BaseVoiceCommandManager.java | 3 +- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManagerTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManagerTests.java index bbddf6ab4..dc9dbd40d 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManagerTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManagerTests.java @@ -35,12 +35,21 @@ package com.smartdevicelink.managers.screen.menu; import com.smartdevicelink.AndroidTestCase2; import com.smartdevicelink.managers.BaseSubManager; import com.smartdevicelink.managers.CompletionListener; +import com.smartdevicelink.protocol.enums.FunctionID; import com.smartdevicelink.proxy.interfaces.ISdl; +import com.smartdevicelink.proxy.rpc.OnHMIStatus; import com.smartdevicelink.proxy.rpc.enums.HMILevel; +import com.smartdevicelink.proxy.rpc.listeners.OnRPCNotificationListener; + +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; import java.util.Arrays; import java.util.List; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; public class VoiceCommandManagerTests extends AndroidTestCase2 { @@ -49,6 +58,7 @@ public class VoiceCommandManagerTests extends AndroidTestCase2 { private List commands; private VoiceCommandManager voiceCommandManager; private static final int voiceCommandIdMin = 1900000000; + private OnRPCNotificationListener onHMIStatusListener; // SETUP / HELPERS @@ -61,6 +71,19 @@ public class VoiceCommandManagerTests extends AndroidTestCase2 { commands = Arrays.asList(command,command2); ISdl internalInterface = mock(ISdl.class); + // When internalInterface.addOnRPCNotificationListener(FunctionID.ON_HMI_STATUS, OnRPCNotificationListener) is called + // inside PermissionManager's constructor, then keep a reference to the OnRPCNotificationListener so we can trigger it later + // to emulate what Core does when it sends OnHMIStatus notification + Answer onHMIStatusAnswer = new Answer() { + @Override + public Void answer(InvocationOnMock invocation) { + Object[] args = invocation.getArguments(); + onHMIStatusListener = (OnRPCNotificationListener) args[1]; + return null; + } + }; + doAnswer(onHMIStatusAnswer).when(internalInterface).addOnRPCNotificationListener(eq(FunctionID.ON_HMI_STATUS), any(OnRPCNotificationListener.class)); + voiceCommandManager = new VoiceCommandManager(internalInterface); // Check some stuff during setup @@ -102,16 +125,33 @@ public class VoiceCommandManagerTests extends AndroidTestCase2 { assertTrue(success); // Make sure the state has changed, as the Screen Manager is dependant on it assertEquals(voiceCommandManager.getState(), BaseSubManager.READY); - // now that we are started, set some voice commands - sendCommands(voiceCommandManager); } }); } - private void sendCommands(VoiceCommandManager voiceCommandManager){ + public void testHMINotReady(){ + voiceCommandManager.currentHMILevel = HMILevel.HMI_NONE; voiceCommandManager.setVoiceCommands(commands); + // updating voice commands before HMI is ready + assertNull(voiceCommandManager.inProgressUpdate); + assertTrue(voiceCommandManager.waitingOnHMIUpdate); + assertEquals(voiceCommandManager.currentHMILevel, HMILevel.HMI_NONE); + + // The VCM should send the pending voice commands once HMI full occurs + sendFakeCoreOnHMIStatusNotifications(HMILevel.HMI_FULL); + assertEquals(voiceCommandManager.currentHMILevel, HMILevel.HMI_FULL); + // This being false means it received the hmi notification and sent the pending commands + assertFalse(voiceCommandManager.waitingOnHMIUpdate); + } + // Emulate what happens when Core sends OnHMIStatus notification + private void sendFakeCoreOnHMIStatusNotifications(HMILevel hmiLevel) { + if (hmiLevel != null) { + OnHMIStatus onHMIStatusFakeNotification = new OnHMIStatus(); + onHMIStatusFakeNotification.setHmiLevel(hmiLevel); + onHMIStatusListener.onNotified(onHMIStatusFakeNotification); + } } } diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java index e8b57ec05..c7ad2ac9a 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java @@ -120,6 +120,7 @@ abstract class BaseVoiceCommandManager extends BaseSubManager { // make sure hmi is not none if (currentHMILevel == null || currentHMILevel == HMILevel.HMI_NONE){ // Trying to send on HMI_NONE, waiting for full + this.voiceCommands = new ArrayList<>(voiceCommands); waitingOnHMIUpdate = true; return; } @@ -128,7 +129,7 @@ abstract class BaseVoiceCommandManager extends BaseSubManager { lastVoiceCommandId = voiceCommandIdMin; updateIdsOnVoiceCommands(voiceCommands); oldVoiceCommands = new ArrayList<>(voiceCommands); - this.voiceCommands = voiceCommands; + this.voiceCommands = new ArrayList<>(voiceCommands); updateWithListener(); } -- cgit v1.2.1 From 76ff34cf1137bac81d3aab19589e3cee1760e784 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Wed, 1 May 2019 15:51:03 -0400 Subject: vcm tests finished --- .../screen/menu/VoiceCommandManagerTests.java | 53 ++++++++++++++++++++-- .../screen/menu/BaseVoiceCommandManager.java | 4 +- 2 files changed, 52 insertions(+), 5 deletions(-) diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManagerTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManagerTests.java index dc9dbd40d..ff5ac77fd 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManagerTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManagerTests.java @@ -37,28 +37,34 @@ import com.smartdevicelink.managers.BaseSubManager; import com.smartdevicelink.managers.CompletionListener; import com.smartdevicelink.protocol.enums.FunctionID; import com.smartdevicelink.proxy.interfaces.ISdl; +import com.smartdevicelink.proxy.rpc.OnCommand; import com.smartdevicelink.proxy.rpc.OnHMIStatus; import com.smartdevicelink.proxy.rpc.enums.HMILevel; +import com.smartdevicelink.proxy.rpc.enums.TriggerSource; import com.smartdevicelink.proxy.rpc.listeners.OnRPCNotificationListener; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import java.util.Arrays; +import java.util.Collections; import java.util.List; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; public class VoiceCommandManagerTests extends AndroidTestCase2 { public static final String TAG = "VCMTests"; + private VoiceCommand command, command2, command3; private List commands; private VoiceCommandManager voiceCommandManager; private static final int voiceCommandIdMin = 1900000000; - private OnRPCNotificationListener onHMIStatusListener; + private OnRPCNotificationListener onHMIStatusListener, commandListener; // SETUP / HELPERS @@ -66,11 +72,14 @@ public class VoiceCommandManagerTests extends AndroidTestCase2 { public void setUp() throws Exception{ super.setUp(); - VoiceCommand command = new VoiceCommand(Arrays.asList("Command one", "Command two"), null); - VoiceCommand command2 = new VoiceCommand(Arrays.asList("Command three", "Command four"), null); + VoiceCommandSelectionListener mockListener = mock(VoiceCommandSelectionListener.class); + command = new VoiceCommand(Arrays.asList("Command one", "Command two"), null); + command2 = new VoiceCommand(Arrays.asList("Command three", "Command four"), null); + command3 = new VoiceCommand(Arrays.asList("Command five", "Command six"), mockListener); commands = Arrays.asList(command,command2); ISdl internalInterface = mock(ISdl.class); + // When internalInterface.addOnRPCNotificationListener(FunctionID.ON_HMI_STATUS, OnRPCNotificationListener) is called // inside PermissionManager's constructor, then keep a reference to the OnRPCNotificationListener so we can trigger it later // to emulate what Core does when it sends OnHMIStatus notification @@ -84,6 +93,16 @@ public class VoiceCommandManagerTests extends AndroidTestCase2 { }; doAnswer(onHMIStatusAnswer).when(internalInterface).addOnRPCNotificationListener(eq(FunctionID.ON_HMI_STATUS), any(OnRPCNotificationListener.class)); + Answer onCommandAnswer = new Answer() { + @Override + public Void answer(InvocationOnMock invocation) { + Object[] args = invocation.getArguments(); + commandListener = (OnRPCNotificationListener) args[1]; + return null; + } + }; + doAnswer(onCommandAnswer).when(internalInterface).addOnRPCNotificationListener(eq(FunctionID.ON_COMMAND), any(OnRPCNotificationListener.class)); + voiceCommandManager = new VoiceCommandManager(internalInterface); // Check some stuff during setup @@ -133,18 +152,46 @@ public class VoiceCommandManagerTests extends AndroidTestCase2 { voiceCommandManager.currentHMILevel = HMILevel.HMI_NONE; voiceCommandManager.setVoiceCommands(commands); + // updating voice commands before HMI is ready assertNull(voiceCommandManager.inProgressUpdate); assertTrue(voiceCommandManager.waitingOnHMIUpdate); + // these are the 2 commands we have waiting + assertEquals(voiceCommandManager.voiceCommands.size(), 2); assertEquals(voiceCommandManager.currentHMILevel, HMILevel.HMI_NONE); // The VCM should send the pending voice commands once HMI full occurs sendFakeCoreOnHMIStatusNotifications(HMILevel.HMI_FULL); + // Listener should be triggered - which sets new HMI level and should proceed to send our pending update assertEquals(voiceCommandManager.currentHMILevel, HMILevel.HMI_FULL); // This being false means it received the hmi notification and sent the pending commands assertFalse(voiceCommandManager.waitingOnHMIUpdate); } + public void testUpdatingCommands(){ + + // we have previously sent 2 VoiceCommand objects. we will now update it and have just one + + // This should have been cleared, but still initialized after the last send + assertEquals(voiceCommandManager.oldVoiceCommands.size(), 0); + // make sure the system returns us 2 delete commands + assertEquals(voiceCommandManager.deleteCommandsForVoiceCommands(commands).size(), 2); + // when we only send one command to update, we should only be returned one add command + assertEquals(voiceCommandManager.addCommandsForVoiceCommands(Collections.singletonList(command)).size(), 1); + + // Send a new single command, and test that its listener works, as it gets called from the VCM + voiceCommandManager.setVoiceCommands(Collections.singletonList(command3)); + + // Fake onCommand - we want to make sure that we can pass back onCommand events to our VoiceCommand Objects + OnCommand onCommand = new OnCommand(); + onCommand.setCmdID(command3.getCommandId()); + onCommand.setTriggerSource(TriggerSource.TS_VR); // these are voice commands + commandListener.onNotified(onCommand); // send off the notification + + // verify the mock listener has only been hit once + verify(command3.getVoiceCommandSelectionListener(), times(1)).onVoiceCommandSelected(); + } + // Emulate what happens when Core sends OnHMIStatus notification private void sendFakeCoreOnHMIStatusNotifications(HMILevel hmiLevel) { if (hmiLevel != null) { diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java index c7ad2ac9a..bb5708880 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java @@ -256,7 +256,7 @@ abstract class BaseVoiceCommandManager extends BaseSubManager { // DELETES - private List deleteCommandsForVoiceCommands(List voiceCommands){ + List deleteCommandsForVoiceCommands(List voiceCommands){ List deleteCommandList = new ArrayList<>(); for (VoiceCommand command : voiceCommands){ DeleteCommand delete = new DeleteCommand(command.getCommandId()); @@ -267,7 +267,7 @@ abstract class BaseVoiceCommandManager extends BaseSubManager { // COMMANDS - private List addCommandsForVoiceCommands(List voiceCommands){ + List addCommandsForVoiceCommands(List voiceCommands){ List addCommandList = new ArrayList<>(); for (VoiceCommand command : voiceCommands){ addCommandList.add(commandForVoiceCommand(command)); -- cgit v1.2.1 From 5c88470dfc49c8b62d6a25a031290f4c213aa6d2 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Wed, 1 May 2019 16:45:20 -0400 Subject: start of menu manager tests --- .../managers/screen/menu/MenuManagerTests.java | 67 ++++++++++++++++++++-- .../screen/menu/VoiceCommandManagerTests.java | 17 +++--- 2 files changed, 69 insertions(+), 15 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 f61128c8d..745c1d5f2 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 @@ -32,26 +32,83 @@ package com.smartdevicelink.managers.screen.menu; -import android.content.Context; - import com.smartdevicelink.AndroidTestCase2; +import com.smartdevicelink.managers.BaseSubManager; +import com.smartdevicelink.managers.file.FileManager; +import com.smartdevicelink.protocol.enums.FunctionID; +import com.smartdevicelink.proxy.interfaces.ISdl; +import com.smartdevicelink.proxy.rpc.listeners.OnRPCNotificationListener; + +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.mock; public class MenuManagerTests extends AndroidTestCase2 { - public static final String TAG = "MenuManagerTests"; - private Context mTestContext; + private OnRPCNotificationListener onHMIStatusListener, commandListener; + private MenuManager menuManager; // SETUP / HELPERS @Override public void setUp() throws Exception{ super.setUp(); - mTestContext = this.getContext(); + + // menu cell mock listener + MenuSelectionListener menuSelectionListener = mock(MenuSelectionListener.class); + + // Create our menu cells + + + ISdl internalInterface = mock(ISdl.class); + FileManager fileManager = mock(FileManager.class); + + // When internalInterface.addOnRPCNotificationListener(FunctionID.ON_HMI_STATUS, OnRPCNotificationListener) is called + // inside PermissionManager's constructor, then keep a reference to the OnRPCNotificationListener so we can trigger it later + // to emulate what Core does when it sends OnHMIStatus notification + Answer onHMIStatusAnswer = new Answer() { + @Override + public Void answer(InvocationOnMock invocation) { + Object[] args = invocation.getArguments(); + onHMIStatusListener = (OnRPCNotificationListener) args[1]; + return null; + } + }; + doAnswer(onHMIStatusAnswer).when(internalInterface).addOnRPCNotificationListener(eq(FunctionID.ON_HMI_STATUS), any(OnRPCNotificationListener.class)); + + Answer onCommandAnswer = new Answer() { + @Override + public Void answer(InvocationOnMock invocation) { + Object[] args = invocation.getArguments(); + commandListener = (OnRPCNotificationListener) args[1]; + return null; + } + }; + doAnswer(onCommandAnswer).when(internalInterface).addOnRPCNotificationListener(eq(FunctionID.ON_COMMAND), any(OnRPCNotificationListener.class)); + + menuManager = new MenuManager(internalInterface, fileManager); + + assertEquals(menuManager.getState(), BaseSubManager.SETTING_UP); + } @Override public void tearDown() throws Exception { + + menuManager.dispose(); + + // after everything, make sure we are in the correct state + assertEquals(menuManager.getState(), BaseSubManager.SHUTDOWN); + super.tearDown(); } + public void testStartMenuManager(){ + + } + } diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManagerTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManagerTests.java index ff5ac77fd..617e2e22a 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManagerTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManagerTests.java @@ -59,8 +59,7 @@ import static org.mockito.Mockito.verify; public class VoiceCommandManagerTests extends AndroidTestCase2 { - public static final String TAG = "VCMTests"; - private VoiceCommand command, command2, command3; + private VoiceCommand command, command3; private List commands; private VoiceCommandManager voiceCommandManager; private static final int voiceCommandIdMin = 1900000000; @@ -74,7 +73,7 @@ public class VoiceCommandManagerTests extends AndroidTestCase2 { VoiceCommandSelectionListener mockListener = mock(VoiceCommandSelectionListener.class); command = new VoiceCommand(Arrays.asList("Command one", "Command two"), null); - command2 = new VoiceCommand(Arrays.asList("Command three", "Command four"), null); + VoiceCommand command2 = new VoiceCommand(Arrays.asList("Command three", "Command four"), null); command3 = new VoiceCommand(Arrays.asList("Command five", "Command six"), mockListener); commands = Arrays.asList(command,command2); @@ -161,7 +160,7 @@ public class VoiceCommandManagerTests extends AndroidTestCase2 { assertEquals(voiceCommandManager.currentHMILevel, HMILevel.HMI_NONE); // The VCM should send the pending voice commands once HMI full occurs - sendFakeCoreOnHMIStatusNotifications(HMILevel.HMI_FULL); + sendFakeCoreOnHMIFullNotifications(); // Listener should be triggered - which sets new HMI level and should proceed to send our pending update assertEquals(voiceCommandManager.currentHMILevel, HMILevel.HMI_FULL); // This being false means it received the hmi notification and sent the pending commands @@ -193,12 +192,10 @@ public class VoiceCommandManagerTests extends AndroidTestCase2 { } // Emulate what happens when Core sends OnHMIStatus notification - private void sendFakeCoreOnHMIStatusNotifications(HMILevel hmiLevel) { - if (hmiLevel != null) { - OnHMIStatus onHMIStatusFakeNotification = new OnHMIStatus(); - onHMIStatusFakeNotification.setHmiLevel(hmiLevel); - onHMIStatusListener.onNotified(onHMIStatusFakeNotification); - } + private void sendFakeCoreOnHMIFullNotifications() { + OnHMIStatus onHMIStatusFakeNotification = new OnHMIStatus(); + onHMIStatusFakeNotification.setHmiLevel(HMILevel.HMI_FULL); + onHMIStatusListener.onNotified(onHMIStatusFakeNotification); } } -- cgit v1.2.1 From 6a567e317365549bc5d79af0ffdb09b0a511cfc3 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Tue, 7 May 2019 13:49:03 -0400 Subject: start of menu manger tests, some cleanup --- .../managers/screen/menu/MenuManagerTests.java | 82 ++++++++++++++++++++-- .../managers/screen/menu/BaseMenuManager.java | 19 +++-- 2 files changed, 84 insertions(+), 17 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 745c1d5f2..e71b5c96e 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 @@ -33,15 +33,26 @@ package com.smartdevicelink.managers.screen.menu; import com.smartdevicelink.AndroidTestCase2; +import com.smartdevicelink.R; import com.smartdevicelink.managers.BaseSubManager; +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.interfaces.ISdl; +import com.smartdevicelink.proxy.rpc.OnHMIStatus; +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.listeners.OnRPCNotificationListener; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doAnswer; @@ -49,8 +60,9 @@ import static org.mockito.Mockito.mock; public class MenuManagerTests extends AndroidTestCase2 { - private OnRPCNotificationListener onHMIStatusListener, commandListener; + private OnRPCNotificationListener onHMIStatusListener; private MenuManager menuManager; + private MenuCell mainCell1, mainCell3, mainCell2, mainCell4; // SETUP / HELPERS @@ -58,11 +70,8 @@ public class MenuManagerTests extends AndroidTestCase2 { public void setUp() throws Exception{ super.setUp(); - // menu cell mock listener - MenuSelectionListener menuSelectionListener = mock(MenuSelectionListener.class); - // Create our menu cells - + createTestCells(); ISdl internalInterface = mock(ISdl.class); FileManager fileManager = mock(FileManager.class); @@ -84,7 +93,7 @@ public class MenuManagerTests extends AndroidTestCase2 { @Override public Void answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); - commandListener = (OnRPCNotificationListener) args[1]; + OnRPCNotificationListener commandListener = (OnRPCNotificationListener) args[1]; return null; } }; @@ -92,7 +101,18 @@ public class MenuManagerTests extends AndroidTestCase2 { menuManager = new MenuManager(internalInterface, fileManager); + // Check some stuff during setup + assertEquals(menuManager.currentHMILevel, HMILevel.HMI_NONE); assertEquals(menuManager.getState(), BaseSubManager.SETTING_UP); + assertEquals(menuManager.currentSystemContext, SystemContext.SYSCTXT_MAIN); + assertEquals(menuManager.lastMenuId, 1); + assertNotNull(menuManager.menuCells); + assertNotNull(menuManager.waitingUpdateMenuCells); + assertNotNull(menuManager.oldMenuCells); + assertNotNull(menuManager.inProgressUpdate); + assertNotNull(menuManager.hmiListener); + assertNotNull(menuManager.commandListener); + assertNotNull(menuManager.displayListener); } @@ -101,6 +121,15 @@ public class MenuManagerTests extends AndroidTestCase2 { menuManager.dispose(); + assertEquals(menuManager.currentSystemContext, SystemContext.SYSCTXT_MAIN); + assertEquals(menuManager.lastMenuId, 1); + assertNull(menuManager.menuCells); + assertNull(menuManager.oldMenuCells); + assertNull(menuManager.currentHMILevel); + assertNull(menuManager.displayCapabilities); + assertNull(menuManager.inProgressUpdate); + assertNull(menuManager.waitingUpdateMenuCells); + // after everything, make sure we are in the correct state assertEquals(menuManager.getState(), BaseSubManager.SHUTDOWN); @@ -109,6 +138,47 @@ public class MenuManagerTests extends AndroidTestCase2 { public void testStartMenuManager(){ + menuManager.start(new CompletionListener() { + @Override + public void onComplete(boolean success) { + assertTrue(success); + // Make sure the state has changed, as the Screen Manager is dependant on it + assertEquals(menuManager.getState(), BaseSubManager.READY); + } + }); + } + + private void createTestCells(){ + + // menu cell mock listener + MenuSelectionListener menuSelectionListener1 = mock(MenuSelectionListener.class); + MenuSelectionListener menuSelectionListener2 = mock(MenuSelectionListener.class); + MenuSelectionListener menuSelectionListener3 = mock(MenuSelectionListener.class); + MenuSelectionListener menuSelectionListenerSub1 = mock(MenuSelectionListener.class); + MenuSelectionListener menuSelectionListenerSub2 = mock(MenuSelectionListener.class); + + // some arts + SdlArtwork livio = new SdlArtwork("livio", FileType.GRAPHIC_PNG, R.drawable.sdl_lockscreen_icon, false); + + // some voice commands + List voice2 = Collections.singletonList("Cell two"); + + mainCell1 = new MenuCell("Test Cell 1", livio, null, menuSelectionListener1); + mainCell2 = new MenuCell("Test Cell 2", livio, voice2, menuSelectionListener2); + mainCell3 = new MenuCell("Test Cell 3", menuSelectionListener3); + + // SUB MENU + MenuCell subCell1 = new MenuCell("SubCell 1", menuSelectionListenerSub1); + MenuCell subCell2 = new MenuCell("SubCell 2", menuSelectionListenerSub2); + + mainCell4 = new MenuCell("Test Cell 4", livio, Arrays.asList(subCell1,subCell2)); // sub menu parent cell + } + + // Emulate what happens when Core sends OnHMIStatus notification + private void sendFakeCoreOnHMIFullNotifications() { + OnHMIStatus onHMIStatusFakeNotification = new OnHMIStatus(); + onHMIStatusFakeNotification.setHmiLevel(HMILevel.HMI_FULL); + onHMIStatusListener.onNotified(onHMIStatusFakeNotification); } } 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 f60e6c1a5..0d0aaef7a 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 @@ -75,26 +75,23 @@ abstract class BaseMenuManager extends BaseSubManager { private final WeakReference fileManager; - private List menuCells; - private List waitingUpdateMenuCells; - private List oldMenuCells; - private List inProgressUpdate; + List menuCells, waitingUpdateMenuCells, oldMenuCells; + List inProgressUpdate; private boolean waitingOnHMIUpdate; private boolean hasQueuedUpdate; - private HMILevel currentHMILevel; + HMILevel currentHMILevel; - private OnRPCNotificationListener hmiListener; - private OnRPCNotificationListener commandListener; - private OnSystemCapabilityListener displayListener; - private DisplayCapabilities displayCapabilities; + OnRPCNotificationListener hmiListener, commandListener; + OnSystemCapabilityListener displayListener; + DisplayCapabilities displayCapabilities; private static final int MAX_ID = 2000000000; private static final int parentIdNotFound = MAX_ID; private static final int menuCellIdMin = 1; - private int lastMenuId; + int lastMenuId; - private SystemContext currentSystemContext; + SystemContext currentSystemContext; BaseMenuManager(@NonNull ISdl internalInterface, @NonNull FileManager fileManager) { -- cgit v1.2.1 From 4ea6a21e08afba55508958c1529455e213779094 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Tue, 7 May 2019 15:40:49 -0400 Subject: more testing --- .../managers/screen/menu/MenuManagerTests.java | 83 +++++++++++++++++++--- .../managers/screen/menu/BaseMenuManager.java | 6 +- 2 files changed, 78 insertions(+), 11 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 e71b5c96e..8c3bdb4f3 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 @@ -40,10 +40,12 @@ import com.smartdevicelink.managers.file.FileManager; import com.smartdevicelink.managers.file.filetypes.SdlArtwork; import com.smartdevicelink.protocol.enums.FunctionID; import com.smartdevicelink.proxy.interfaces.ISdl; +import com.smartdevicelink.proxy.rpc.OnCommand; import com.smartdevicelink.proxy.rpc.OnHMIStatus; 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.invocation.InvocationOnMock; @@ -57,12 +59,15 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; public class MenuManagerTests extends AndroidTestCase2 { - private OnRPCNotificationListener onHMIStatusListener; + private OnRPCNotificationListener onHMIStatusListener, commandListener; private MenuManager menuManager; - private MenuCell mainCell1, mainCell3, mainCell2, mainCell4; + private List cells; + private MenuCell mainCell1, mainCell4; // SETUP / HELPERS @@ -70,8 +75,7 @@ public class MenuManagerTests extends AndroidTestCase2 { public void setUp() throws Exception{ super.setUp(); - // Create our menu cells - createTestCells(); + cells = createTestCells(); ISdl internalInterface = mock(ISdl.class); FileManager fileManager = mock(FileManager.class); @@ -93,7 +97,7 @@ public class MenuManagerTests extends AndroidTestCase2 { @Override public Void answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); - OnRPCNotificationListener commandListener = (OnRPCNotificationListener) args[1]; + commandListener = (OnRPCNotificationListener) args[1]; return null; } }; @@ -148,7 +152,68 @@ public class MenuManagerTests extends AndroidTestCase2 { }); } - private void createTestCells(){ + public void testHMINotReady(){ + + menuManager.currentHMILevel = HMILevel.HMI_NONE; + menuManager.setMenuCells(cells); + + // updating voice commands before HMI is ready + assertTrue(menuManager.waitingOnHMIUpdate); + // these are the 2 commands we have waiting + assertEquals(menuManager.menuCells.size(), 0); + assertEquals(menuManager.waitingUpdateMenuCells.size(), 4); + assertEquals(menuManager.currentHMILevel, HMILevel.HMI_NONE); + // The VCM should send the pending voice commands once HMI full occurs + sendFakeCoreOnHMIFullNotifications(); + // Listener should be triggered - which sets new HMI level and should proceed to send our pending update + assertEquals(menuManager.currentHMILevel, HMILevel.HMI_FULL); + // This being false means it received the hmi notification and sent the pending commands + assertFalse(menuManager.waitingOnHMIUpdate); + } + + public void testUpdating(){ + + assertEquals(menuManager.oldMenuCells.size(), 0); // these were deleted with the previous series of deletions + assertEquals(menuManager.deleteCommandsForCells(cells).size(), 4); // 3 root cells and 1 sub menu + + // when we only send one command to update, we should only be returned one add command + List newArray = Arrays.asList(mainCell1, mainCell4); + assertEquals(menuManager.allCommandsForCells(newArray, false).size(), 4); // 1 root cells, 1 sub menu root cell, 2 sub menu cells + + menuManager.setMenuCells(newArray); + + // Unlike voice commands, the Menu Manager dynamically assigns Cell ID's. Because of this, we need to get the updated + // cell list after setting it and then test the listeners, as they use the newly assigned cell ID's. + List updatedCells = menuManager.getMenuCells(); + + for (MenuCell cell : updatedCells){ + + // grab 2 of our newly updated cells - 1 root and 1 sub cell, and make sure they can get triggered + if (cell.getDescription().equalsIgnoreCase("Test Cell 1")){ + // Fake onCommand - we want to make sure that we can pass back onCommand events to our root Menu Cell + OnCommand onCommand = new OnCommand(); + onCommand.setCmdID(cell.getCellId()); + onCommand.setTriggerSource(TriggerSource.TS_MENU); // these are voice commands + commandListener.onNotified(onCommand); // send off the notification + + // verify the mock listener has only been hit once for a root cell + verify(cell.getMenuSelectionListener(), times(1)).onTriggered(TriggerSource.TS_MENU); + } + + if (cell.getDescription().equalsIgnoreCase("SubCell 2")){ + // Fake onCommand - we want to make sure that we can pass back onCommand events to our sub Menu Cell + OnCommand onCommand2 = new OnCommand(); + onCommand2.setCmdID(cell.getCellId()); + onCommand2.setTriggerSource(TriggerSource.TS_MENU); // these are voice commands + commandListener.onNotified(onCommand2); // send off the notification + + // verify the mock listener has only been hit once for a sub cell + verify(cell.getMenuSelectionListener(), times(1)).onTriggered(TriggerSource.TS_MENU); + } + } + } + + private List createTestCells(){ // menu cell mock listener MenuSelectionListener menuSelectionListener1 = mock(MenuSelectionListener.class); @@ -164,14 +229,16 @@ public class MenuManagerTests extends AndroidTestCase2 { List voice2 = Collections.singletonList("Cell two"); mainCell1 = new MenuCell("Test Cell 1", livio, null, menuSelectionListener1); - mainCell2 = new MenuCell("Test Cell 2", livio, voice2, menuSelectionListener2); - mainCell3 = new MenuCell("Test Cell 3", menuSelectionListener3); + MenuCell mainCell2 = new MenuCell("Test Cell 2", livio, voice2, menuSelectionListener2); + MenuCell mainCell3 = new MenuCell("Test Cell 3", menuSelectionListener3); // SUB MENU MenuCell subCell1 = new MenuCell("SubCell 1", menuSelectionListenerSub1); MenuCell subCell2 = new MenuCell("SubCell 2", menuSelectionListenerSub2); mainCell4 = new MenuCell("Test Cell 4", livio, Arrays.asList(subCell1,subCell2)); // sub menu parent cell + + return Arrays.asList(mainCell1, mainCell2, mainCell3, mainCell4); } // Emulate what happens when Core sends OnHMIStatus notification 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 0d0aaef7a..ebcb318dd 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 @@ -78,7 +78,7 @@ abstract class BaseMenuManager extends BaseSubManager { List menuCells, waitingUpdateMenuCells, oldMenuCells; List inProgressUpdate; - private boolean waitingOnHMIUpdate; + boolean waitingOnHMIUpdate; private boolean hasQueuedUpdate; HMILevel currentHMILevel; @@ -454,7 +454,7 @@ abstract class BaseMenuManager extends BaseSubManager { // DELETES - private List deleteCommandsForCells(List cells){ + List deleteCommandsForCells(List cells){ List deletes = new ArrayList<>(); for (MenuCell cell : cells){ if (cell.getSubCells() == null){ @@ -495,7 +495,7 @@ abstract class BaseMenuManager extends BaseSubManager { return builtCommands; } - private List allCommandsForCells(List cells, boolean shouldHaveArtwork){ + List allCommandsForCells(List cells, boolean shouldHaveArtwork){ List builtCommands = new ArrayList<>(); // We need the index so we will use this type of loop -- cgit v1.2.1 From d17b59749162d82b15531fca8b138cd9a76a419b Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Tue, 7 May 2019 16:07:25 -0400 Subject: update test comments --- .../smartdevicelink/managers/screen/menu/MenuManagerTests.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 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 8c3bdb4f3..e0e56f220 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 @@ -163,7 +163,7 @@ public class MenuManagerTests extends AndroidTestCase2 { assertEquals(menuManager.menuCells.size(), 0); assertEquals(menuManager.waitingUpdateMenuCells.size(), 4); assertEquals(menuManager.currentHMILevel, HMILevel.HMI_NONE); - // The VCM should send the pending voice commands once HMI full occurs + // The Menu Manager should send new menu once HMI full occurs sendFakeCoreOnHMIFullNotifications(); // Listener should be triggered - which sets new HMI level and should proceed to send our pending update assertEquals(menuManager.currentHMILevel, HMILevel.HMI_FULL); @@ -193,7 +193,7 @@ public class MenuManagerTests extends AndroidTestCase2 { // Fake onCommand - we want to make sure that we can pass back onCommand events to our root Menu Cell OnCommand onCommand = new OnCommand(); onCommand.setCmdID(cell.getCellId()); - onCommand.setTriggerSource(TriggerSource.TS_MENU); // these are voice commands + onCommand.setTriggerSource(TriggerSource.TS_MENU); // these are menu commands commandListener.onNotified(onCommand); // send off the notification // verify the mock listener has only been hit once for a root cell @@ -204,7 +204,7 @@ public class MenuManagerTests extends AndroidTestCase2 { // Fake onCommand - we want to make sure that we can pass back onCommand events to our sub Menu Cell OnCommand onCommand2 = new OnCommand(); onCommand2.setCmdID(cell.getCellId()); - onCommand2.setTriggerSource(TriggerSource.TS_MENU); // these are voice commands + onCommand2.setTriggerSource(TriggerSource.TS_MENU); // these are menu commands commandListener.onNotified(onCommand2); // send off the notification // verify the mock listener has only been hit once for a sub cell @@ -225,7 +225,7 @@ public class MenuManagerTests extends AndroidTestCase2 { // some arts SdlArtwork livio = new SdlArtwork("livio", FileType.GRAPHIC_PNG, R.drawable.sdl_lockscreen_icon, false); - // some voice commands + // some menu cells List voice2 = Collections.singletonList("Cell two"); mainCell1 = new MenuCell("Test Cell 1", livio, null, menuSelectionListener1); -- cgit v1.2.1 From b7297b9ffc1c5d3a84dc65604fc62ed1fb1038f4 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Wed, 8 May 2019 11:21:47 -0400 Subject: adding custom equality methods to menucell --- .../managers/screen/menu/MenuCellTests.java | 19 ++++++++++++++ .../java/com/smartdevicelink/test/Test.java | 2 +- .../managers/screen/menu/MenuCell.java | 29 ++++++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/MenuCellTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/MenuCellTests.java index 00b34865a..9227a45e4 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/MenuCellTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/MenuCellTests.java @@ -88,4 +88,23 @@ public class MenuCellTests extends AndroidTestCase2 { assertEquals(menuCell4.getMenuSelectionListener(), menuSelectionListener); } + public void testEquality(){ + + //We should use assertTrue (or assertFalse) because we want to use the overridden equals() method + + MenuCell menuCell = new MenuCell(Test.GENERAL_STRING, Test.GENERAL_ARTWORK, Test.GENERAL_STRING_LIST, menuSelectionListener); + MenuCell menuCell2 = new MenuCell(Test.GENERAL_STRING, Test.GENERAL_ARTWORK, Test.GENERAL_STRING_LIST, menuSelectionListener); + + // these are the same object, should be equal. + assertTrue(menuCell.equals(menuCell)); + + // Make sure these are marked as equals, even though they are different objects + assertTrue(menuCell.equals(menuCell2)); + + MenuCell menuCell3 = new MenuCell(Test.GENERAL_STRING, null, Test.GENERAL_STRING_LIST, menuSelectionListener); + + // these should be different + assertFalse(menuCell.equals(menuCell3)); + } + } diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java index 3a75cd55b..7d576ce37 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java @@ -395,7 +395,7 @@ public class Test { public static final AudioControlData GENERAL_AUDIOCONTROLDATA = new AudioControlData(); public static final LightControlData GENERAL_LIGHTCONTROLDATA = new LightControlData(); public static final HMISettingsControlData GENERAL_HMISETTINGSCONTROLDATA = new HMISettingsControlData(); - public static final SdlArtwork GENERAL_ARTWORK = new SdlArtwork(); + public static final SdlArtwork GENERAL_ARTWORK = new SdlArtwork("sdl", FileType.GRAPHIC_PNG, R.drawable.ic_sdl, false); public static final HMICapabilities GENERAL_HMICAPABILITIES = new HMICapabilities(); diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java index 0ec33541a..3f2399f62 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java @@ -38,6 +38,7 @@ import android.support.annotation.Nullable; import com.smartdevicelink.managers.file.filetypes.SdlArtwork; import java.util.List; +import java.util.Objects; public class MenuCell { @@ -257,4 +258,32 @@ public class MenuCell { icon.getName() + " VoiceCommands: "+ voiceCommands.size() + " isSubCell: " + (parentCellId != Integer.MAX_VALUE ? "YES":"NO")+ " hasSubCells: "+ (subCells != null && subCells.size() > 0 ? "YES":"NO"); } + + /** + * Hash the parameters of the object and return the result for comparison + * @return the hash code as an int + */ + @Override + public int hashCode() { + int result = 1; + result = result + ((getTitle() == null) ? 0 : getTitle().hashCode()); + result = result + ((getIcon() == null || getIcon().getName() == null) ? 0 : getIcon().getName().hashCode()); + result = result + ((getVoiceCommands() == null) ? 0 : getVoiceCommands().hashCode()); + result = result + ((getSubCells() == null) ? 0 : getSubCells().hashCode()); + return result; + } + + + /** + * Uses our custom hash + * @param o - The object to compare + * @return boolean of whether the objects are the same or not + */ + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof MenuCell)) return false; + MenuCell menuCell = (MenuCell) o; + return hashCode() == menuCell.hashCode(); + } } -- cgit v1.2.1 From bc19129fcb001aea5010798c1444ce135cbdd007 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Wed, 8 May 2019 12:00:12 -0400 Subject: add rotation into hashing function --- .../java/com/smartdevicelink/managers/screen/menu/MenuCell.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java index 3f2399f62..22aa6c4e9 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java @@ -266,10 +266,10 @@ public class MenuCell { @Override public int hashCode() { int result = 1; - result = result + ((getTitle() == null) ? 0 : getTitle().hashCode()); - result = result + ((getIcon() == null || getIcon().getName() == null) ? 0 : getIcon().getName().hashCode()); - result = result + ((getVoiceCommands() == null) ? 0 : getVoiceCommands().hashCode()); - result = result + ((getSubCells() == null) ? 0 : getSubCells().hashCode()); + result = result + ((getTitle() == null) ? 0 : Integer.rotateLeft(getTitle().hashCode(), 2)); + result = result + ((getIcon() == null || getIcon().getName() == null) ? 0 : Integer.rotateLeft(getIcon().getName().hashCode(), 3)); + result = result + ((getVoiceCommands() == null) ? 0 : Integer.rotateLeft(getVoiceCommands().hashCode(), 4)); + result = result + ((getSubCells() == null) ? 0 : Integer.rotateLeft(getSubCells().hashCode(), 5)); return result; } -- cgit v1.2.1 From 732e7ff3d796630a60953d8bd6ff6e82a0955a81 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Wed, 8 May 2019 13:12:36 -0400 Subject: clean up some code --- .../com/smartdevicelink/managers/screen/menu/MenuCell.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java index 22aa6c4e9..11d8f5a74 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java @@ -261,21 +261,25 @@ public class MenuCell { /** * Hash the parameters of the object and return the result for comparison + * For each param, increase the rotation distance by one. + * It is necessary to rotate each of our properties because a simple bitwise OR will produce equivalent results if, for example: + * Object 1: getText() = "Hi", getSecondaryText() = "Hello" + * Object 2: getText() = "Hello", getSecondaryText() = "Hi" * @return the hash code as an int */ @Override public int hashCode() { int result = 1; - result = result + ((getTitle() == null) ? 0 : Integer.rotateLeft(getTitle().hashCode(), 2)); - result = result + ((getIcon() == null || getIcon().getName() == null) ? 0 : Integer.rotateLeft(getIcon().getName().hashCode(), 3)); - result = result + ((getVoiceCommands() == null) ? 0 : Integer.rotateLeft(getVoiceCommands().hashCode(), 4)); - result = result + ((getSubCells() == null) ? 0 : Integer.rotateLeft(getSubCells().hashCode(), 5)); + result += ((getTitle() == null) ? 0 : Integer.rotateLeft(getTitle().hashCode(), 2)); + result += ((getIcon() == null || getIcon().getName() == null) ? 0 : Integer.rotateLeft(getIcon().getName().hashCode(), 3)); + result += ((getVoiceCommands() == null) ? 0 : Integer.rotateLeft(getVoiceCommands().hashCode(), 4)); + result += ((getSubCells() == null) ? 0 : Integer.rotateLeft(getSubCells().hashCode(), 5)); return result; } /** - * Uses our custom hash + * Uses our custom hash for MenuCell objects, but does NOT compare the listener objects * @param o - The object to compare * @return boolean of whether the objects are the same or not */ -- cgit v1.2.1 From 2bac2901d874c8035f85cd14ef0bb50f426e7108 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Wed, 8 May 2019 13:21:51 -0400 Subject: clean up the javadocs --- .../main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java index 11d8f5a74..cc715cd5d 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java @@ -260,6 +260,7 @@ public class MenuCell { } /** + * Note: You should compare using the {@link #equals(Object)} method.
* Hash the parameters of the object and return the result for comparison * For each param, increase the rotation distance by one. * It is necessary to rotate each of our properties because a simple bitwise OR will produce equivalent results if, for example: @@ -279,7 +280,7 @@ public class MenuCell { /** - * Uses our custom hash for MenuCell objects, but does NOT compare the listener objects + * Uses our custom hashCode for MenuCell objects, but does NOT compare the listener objects * @param o - The object to compare * @return boolean of whether the objects are the same or not */ -- cgit v1.2.1 From 4002fde89c275d74f98c9e18ffc4616e2083ff1d Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Thu, 9 May 2019 14:24:13 -0400 Subject: fix per comments --- .../managers/screen/menu/MenuCellTests.java | 4 ++-- .../managers/screen/menu/MenuManagerTests.java | 2 +- .../screen/menu/VoiceCommandManagerTests.java | 2 +- .../java/com/smartdevicelink/test/Test.java | 2 +- .../managers/screen/menu/MenuManager.java | 4 ++-- .../managers/screen/menu/VoiceCommandManager.java | 4 ++-- .../managers/screen/BaseScreenManager.java | 6 +++--- .../managers/screen/menu/BaseMenuManager.java | 15 +++++--------- .../screen/menu/BaseVoiceCommandManager.java | 15 +++++--------- .../managers/screen/menu/MenuCell.java | 23 ++++++---------------- .../managers/screen/menu/VoiceCommand.java | 7 +++---- .../managers/screen/menu/MenuManager.java | 4 ++-- .../managers/screen/menu/VoiceCommandManager.java | 4 ++-- 13 files changed, 35 insertions(+), 57 deletions(-) diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/MenuCellTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/MenuCellTests.java index 00b34865a..720611358 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/MenuCellTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/MenuCellTests.java @@ -59,7 +59,7 @@ public class MenuCellTests extends AndroidTestCase2 { public void testSettersAndGetters(){ // set everything - MenuCell menuCell = new MenuCell(Test.GENERAL_STRING, menuSelectionListener); + MenuCell menuCell = new MenuCell(Test.GENERAL_STRING, null, null, menuSelectionListener); menuCell.setIcon(Test.GENERAL_ARTWORK); menuCell.setVoiceCommands(Test.GENERAL_STRING_LIST); menuCell.setMenuSelectionListener(menuSelectionListener); @@ -83,7 +83,7 @@ public class MenuCellTests extends AndroidTestCase2 { assertEquals(menuCell3.getVoiceCommands(), Test.GENERAL_STRING_LIST); assertEquals(menuCell3.getMenuSelectionListener(), menuSelectionListener); - MenuCell menuCell4 =new MenuCell(Test.GENERAL_STRING, menuSelectionListener); + MenuCell menuCell4 =new MenuCell(Test.GENERAL_STRING,null, null, menuSelectionListener); assertEquals(menuCell4.getTitle(), Test.GENERAL_STRING); assertEquals(menuCell4.getMenuSelectionListener(), menuSelectionListener); } 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 e0e56f220..b94a9bf98 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 @@ -81,7 +81,7 @@ public class MenuManagerTests extends AndroidTestCase2 { FileManager fileManager = mock(FileManager.class); // When internalInterface.addOnRPCNotificationListener(FunctionID.ON_HMI_STATUS, OnRPCNotificationListener) is called - // inside PermissionManager's constructor, then keep a reference to the OnRPCNotificationListener so we can trigger it later + // inside MenuManager's constructor, then keep a reference to the OnRPCNotificationListener so we can trigger it later // to emulate what Core does when it sends OnHMIStatus notification Answer onHMIStatusAnswer = new Answer() { @Override diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManagerTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManagerTests.java index 617e2e22a..db662c31f 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManagerTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManagerTests.java @@ -80,7 +80,7 @@ public class VoiceCommandManagerTests extends AndroidTestCase2 { ISdl internalInterface = mock(ISdl.class); // When internalInterface.addOnRPCNotificationListener(FunctionID.ON_HMI_STATUS, OnRPCNotificationListener) is called - // inside PermissionManager's constructor, then keep a reference to the OnRPCNotificationListener so we can trigger it later + // inside the VoiceCommandManager's constructor, then keep a reference to the OnRPCNotificationListener so we can trigger it later // to emulate what Core does when it sends OnHMIStatus notification Answer onHMIStatusAnswer = new Answer() { @Override diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java index 3a75cd55b..a27587aae 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java @@ -453,7 +453,7 @@ public class Test { public static final List GENERAL_WEATHERALERT_LIST = Arrays.asList(GENERAL_WEATHERALERT); public static final List GENERAL_NAVIGATION_INSTRUCTION_LIST = Arrays.asList(GENERAL_NAVIGATION_INSTRUCTION); public static final int GENERAL_MENU_MAX_ID = 2000000000; - public static final MenuCell GENERAL_MENUCELL = new MenuCell(GENERAL_STRING, new MenuSelectionListener() { + public static final MenuCell GENERAL_MENUCELL = new MenuCell(GENERAL_STRING,null, null, new MenuSelectionListener() { @Override public void onTriggered(TriggerSource trigger) { // diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManager.java b/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManager.java index 4a28a2792..c244d0d39 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManager.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManager.java @@ -42,9 +42,9 @@ import com.smartdevicelink.proxy.interfaces.ISdl; * * The MenuManager takes MenuCell objects and creates and sends all necessary RPCs to build out a menu */ -public class MenuManager extends BaseMenuManager { +class MenuManager extends BaseMenuManager { - public MenuManager(ISdl internalInterface, FileManager fileManager) { + MenuManager(ISdl internalInterface, FileManager fileManager) { // setup super(internalInterface, fileManager); } diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManager.java b/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManager.java index a892d3a2c..a5492a384 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManager.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManager.java @@ -41,9 +41,9 @@ import com.smartdevicelink.proxy.interfaces.ISdl; * * The VoiceCommandManager takes a List of VoiceCommand objects and sets them on the Head unit for you. */ -public class VoiceCommandManager extends BaseVoiceCommandManager { +class VoiceCommandManager extends BaseVoiceCommandManager { - public VoiceCommandManager(ISdl internalInterface) { + VoiceCommandManager(ISdl internalInterface) { // setup super(internalInterface); } 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 ec560dfd9..f5721c153 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/BaseScreenManager.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/BaseScreenManager.java @@ -73,13 +73,13 @@ abstract class BaseScreenManager extends BaseSubManager { DebugTool.logInfo("Starting screen manager, all sub managers are in ready state"); transitionToState(READY); } else if (softButtonManager.getState() == BaseSubManager.ERROR && textAndGraphicManager.getState() == BaseSubManager.ERROR && voiceCommandManager.getState() == BaseSubManager.ERROR && menuManager.getState() == BaseSubManager.ERROR) { - Log.e(TAG, "ERROR starting screen manager, both sub managers in error state"); + Log.e(TAG, "ERROR starting screen manager, one or more sub managers in error state"); transitionToState(ERROR); } else if (textAndGraphicManager.getState() == BaseSubManager.SETTING_UP || softButtonManager.getState() == BaseSubManager.SETTING_UP || voiceCommandManager.getState() == BaseSubManager.SETTING_UP || menuManager.getState() == BaseSubManager.SETTING_UP) { - DebugTool.logInfo("SETTING UP screen manager, one sub manager is still setting up"); + DebugTool.logInfo("SETTING UP screen manager, at least one sub manager is still setting up"); transitionToState(SETTING_UP); } else { - Log.w(TAG, "LIMITED starting screen manager, one sub manager in error state and the other is ready"); + Log.w(TAG, "LIMITED starting screen manager, at least one sub manager in error state and the other is ready"); transitionToState(LIMITED); } } else { 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 ebcb318dd..55d271a1e 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 @@ -101,11 +101,6 @@ abstract class BaseMenuManager extends BaseSubManager { this.fileManager = new WeakReference<>(fileManager); currentSystemContext = SystemContext.SYSCTXT_MAIN; currentHMILevel = HMILevel.HMI_NONE; - menuCells = new ArrayList<>(); - oldMenuCells = new ArrayList<>(); - waitingUpdateMenuCells = new ArrayList<>(); - inProgressUpdate = new ArrayList<>(); - lastMenuId = menuCellIdMin; addListeners(); } @@ -197,12 +192,12 @@ abstract class BaseMenuManager extends BaseSubManager { DebugTool.logInfo("Menu Artworks Uploaded"); } // proceed - updateMenuWithListener(); + update(); } }); }else{ // No Artworks to be uploaded, send off - updateMenuWithListener(); + update(); } } @@ -216,7 +211,7 @@ abstract class BaseMenuManager extends BaseSubManager { // UPDATING SYSTEM - private void updateMenuWithListener(){ + private void update(){ if (currentHMILevel == null || currentHMILevel.equals(HMILevel.HMI_NONE) || currentSystemContext.equals(SystemContext.SYSCTXT_MENU)){ // We are in NONE or the menu is in use, bail out of here @@ -246,7 +241,7 @@ abstract class BaseMenuManager extends BaseSubManager { } if (hasQueuedUpdate){ - updateMenuWithListener(); + update(); hasQueuedUpdate = false; } } @@ -313,7 +308,7 @@ abstract class BaseMenuManager extends BaseSubManager { List mainMenuCommands; final List subMenuCommands; - if (findAllArtworksToBeUploadedFromCells(menuCells).size() > 0 || !supportsImages()){ + if (findAllArtworksToBeUploadedFromCells(menuCells).size() == 0 || !supportsImages()){ // Send artwork-less menu mainMenuCommands = mainMenuCommandsForCells(menuCells, false); subMenuCommands = subMenuCommandsForCells(menuCells, false); diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java index bb5708880..e8effa5bf 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseVoiceCommandManager.java @@ -78,8 +78,6 @@ abstract class BaseVoiceCommandManager extends BaseSubManager { currentHMILevel = HMILevel.HMI_NONE; addListeners(); lastVoiceCommandId = voiceCommandIdMin; - voiceCommands = new ArrayList<>(); - oldVoiceCommands = new ArrayList<>(); } @Override @@ -131,7 +129,7 @@ abstract class BaseVoiceCommandManager extends BaseSubManager { oldVoiceCommands = new ArrayList<>(voiceCommands); this.voiceCommands = new ArrayList<>(voiceCommands); - updateWithListener(); + update(); } public List getVoiceCommands(){ @@ -140,7 +138,7 @@ abstract class BaseVoiceCommandManager extends BaseSubManager { // UPDATING SYSTEM - private void updateWithListener(){ + private void update(){ if (currentHMILevel == null || currentHMILevel.equals(HMILevel.HMI_NONE)){ waitingOnHMIUpdate = true; @@ -163,7 +161,7 @@ abstract class BaseVoiceCommandManager extends BaseSubManager { inProgressUpdate = null; if (hasQueuedUpdate){ - updateWithListener(); + update(); hasQueuedUpdate = false; } @@ -183,7 +181,7 @@ abstract class BaseVoiceCommandManager extends BaseSubManager { if (oldVoiceCommands == null || oldVoiceCommands.size() == 0){ if (listener != null){ - listener.onComplete(false); + listener.onComplete(true); } return; } @@ -276,9 +274,8 @@ abstract class BaseVoiceCommandManager extends BaseSubManager { } private AddCommand commandForVoiceCommand(VoiceCommand voiceCommand){ - AddCommand command = new AddCommand(); + AddCommand command = new AddCommand(voiceCommand.getCommandId()); command.setVrCommands(voiceCommand.getVoiceCommands()); - command.setCmdID(voiceCommand.getCommandId()); return command; } @@ -304,8 +301,6 @@ abstract class BaseVoiceCommandManager extends BaseSubManager { if (oldHMILevel.equals(HMILevel.HMI_NONE) && !currentHMILevel.equals(HMILevel.HMI_NONE)){ if (waitingOnHMIUpdate){ setVoiceCommands(voiceCommands); - }else{ - updateWithListener(); } } } diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java index 0ec33541a..27b539430 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java @@ -83,19 +83,7 @@ public class MenuCell { // CONSTRUCTORS - // SINGLE MENU ITEM CONSTRUCTORS - - /** - * Creates a new MenuCell Object with just the title set. - * @param title The cell's primary text - * @param listener a listener that notifies you when the cell was selected and lets you know its trigger source - */ - public MenuCell(@NonNull String title, @Nullable MenuSelectionListener listener) { - setTitle(title); // title is the only required param - setMenuSelectionListener(listener); - setCellId(MAX_ID); - setParentCellId(MAX_ID); - } + // SINGLE MENU ITEM CONSTRUCTOR /** * Creates a new MenuCell Object with multiple parameters set @@ -252,9 +240,10 @@ public class MenuCell { * Get the description of the cell * @return a String description of the cell object */ - public String getDescription(){ - return "MenuCell - ID: "+cellId+ " title: "+ title + " ArtworkName: "+ - icon.getName() + " VoiceCommands: "+ voiceCommands.size() + " isSubCell: " + (parentCellId != Integer.MAX_VALUE ? "YES":"NO")+ - " hasSubCells: "+ (subCells != null && subCells.size() > 0 ? "YES":"NO"); + @Override + public String toString(){ + return "MenuCell - ID: "+cellId+ " - title: "+ title + " - ArtworkName: "+ + (icon != null && icon.getName() != null ? icon.getName() : "Artwork is null") + " - VoiceCommands Size: "+ (voiceCommands != null ? voiceCommands.size() : "0") + " - isSubCell: " + (parentCellId != MAX_ID ? "YES":"NO")+ + " - hasSubCells: "+ (subCells != null && subCells.size() > 0 ? "YES":"NO"); } } diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommand.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommand.java index c912f36fb..02a7afff9 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommand.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommand.java @@ -35,8 +35,6 @@ package com.smartdevicelink.managers.screen.menu; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import com.smartdevicelink.managers.screen.menu.VoiceCommandSelectionListener; - import java.util.List; public class VoiceCommand { @@ -126,7 +124,8 @@ public class VoiceCommand { * Get the description of the cell * @return a String description of the cell object */ - public String getDescription(){ - return "VOICE COMMAND - ID: "+commandId+ " First Object: "+ voiceCommands.get(0)+ " Voice Commands: "+ voiceCommands.size(); + @Override + public String toString(){ + return "VOICE COMMAND - ID: "+commandId+ " - First Object: "+ ((voiceCommands.size() > 0) ? voiceCommands.get(0) : "Empty List")+ " - Voice Command List Size: "+ voiceCommands.size(); } } diff --git a/javaSE/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManager.java b/javaSE/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManager.java index 4a28a2792..c244d0d39 100644 --- a/javaSE/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManager.java +++ b/javaSE/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManager.java @@ -42,9 +42,9 @@ import com.smartdevicelink.proxy.interfaces.ISdl; * * The MenuManager takes MenuCell objects and creates and sends all necessary RPCs to build out a menu */ -public class MenuManager extends BaseMenuManager { +class MenuManager extends BaseMenuManager { - public MenuManager(ISdl internalInterface, FileManager fileManager) { + MenuManager(ISdl internalInterface, FileManager fileManager) { // setup super(internalInterface, fileManager); } diff --git a/javaSE/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManager.java b/javaSE/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManager.java index a892d3a2c..a5492a384 100644 --- a/javaSE/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManager.java +++ b/javaSE/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManager.java @@ -41,9 +41,9 @@ import com.smartdevicelink.proxy.interfaces.ISdl; * * The VoiceCommandManager takes a List of VoiceCommand objects and sets them on the Head unit for you. */ -public class VoiceCommandManager extends BaseVoiceCommandManager { +class VoiceCommandManager extends BaseVoiceCommandManager { - public VoiceCommandManager(ISdl internalInterface) { + VoiceCommandManager(ISdl internalInterface) { // setup super(internalInterface); } -- cgit v1.2.1 From 424133c7e2582ca813914446c0dbc2d3e8b9d1bd Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Thu, 9 May 2019 15:05:08 -0400 Subject: update per comments --- .../java/com/sdl/hellosdlandroid/SdlService.java | 117 +++++++++++++++------ .../managers/screen/menu/MenuManagerTests.java | 22 ++-- .../screen/menu/VoiceCommandManagerTests.java | 6 +- .../managers/screen/menu/MenuManager.java | 4 +- .../managers/screen/menu/VoiceCommandManager.java | 4 +- .../managers/screen/menu/BaseMenuManager.java | 4 +- .../managers/screen/menu/MenuManager.java | 4 +- .../managers/screen/menu/VoiceCommandManager.java | 4 +- 8 files changed, 109 insertions(+), 56 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 b180c851b..030c3b3d0 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 @@ -15,24 +15,28 @@ import com.smartdevicelink.managers.CompletionListener; import com.smartdevicelink.managers.SdlManager; import com.smartdevicelink.managers.SdlManagerListener; import com.smartdevicelink.managers.file.filetypes.SdlArtwork; +import com.smartdevicelink.managers.screen.menu.MenuCell; +import com.smartdevicelink.managers.screen.menu.MenuSelectionListener; +import com.smartdevicelink.managers.screen.menu.VoiceCommand; +import com.smartdevicelink.managers.screen.menu.VoiceCommandSelectionListener; import com.smartdevicelink.protocol.enums.FunctionID; import com.smartdevicelink.proxy.RPCNotification; import com.smartdevicelink.proxy.TTSChunkFactory; -import com.smartdevicelink.proxy.rpc.AddCommand; -import com.smartdevicelink.proxy.rpc.MenuParams; -import com.smartdevicelink.proxy.rpc.OnCommand; import com.smartdevicelink.proxy.rpc.OnHMIStatus; import com.smartdevicelink.proxy.rpc.Speak; import com.smartdevicelink.proxy.rpc.enums.AppHMIType; import com.smartdevicelink.proxy.rpc.enums.FileType; import com.smartdevicelink.proxy.rpc.enums.HMILevel; +import com.smartdevicelink.proxy.rpc.enums.TriggerSource; import com.smartdevicelink.proxy.rpc.listeners.OnRPCNotificationListener; import com.smartdevicelink.transport.BaseTransportConfig; import com.smartdevicelink.transport.MultiplexTransportConfig; import com.smartdevicelink.transport.TCPTransportConfig; import com.smartdevicelink.util.DebugTool; +import java.util.Arrays; import java.util.Collections; +import java.util.List; import java.util.Vector; public class SdlService extends Service { @@ -49,7 +53,6 @@ public class SdlService extends Service { private static final String WELCOME_SPEAK = "Welcome to Hello S D L"; private static final String TEST_COMMAND_NAME = "Test Command"; - private static final int TEST_COMMAND_ID = 1; private static final int FOREGROUND_SERVICE_ID = 111; @@ -159,28 +162,13 @@ public class SdlService extends Service { public void onNotified(RPCNotification notification) { OnHMIStatus status = (OnHMIStatus) notification; if (status.getHmiLevel() == HMILevel.HMI_FULL && ((OnHMIStatus) notification).getFirstRun()) { - sendCommands(); + setVoiceCommands(); + sendMenus(); performWelcomeSpeak(); performWelcomeShow(); } } }); - - // Menu Selected Listener - sdlManager.addOnRPCNotificationListener(FunctionID.ON_COMMAND, new OnRPCNotificationListener() { - @Override - public void onNotified(RPCNotification notification) { - OnCommand command = (OnCommand) notification; - Integer id = command.getCmdID(); - if(id != null){ - switch(id){ - case TEST_COMMAND_ID: - showTest(); - break; - } - } - } - }); } @Override @@ -207,16 +195,85 @@ public class SdlService extends Service { } /** - * Add commands for the app on SDL. + * Send some voice commands */ - private void sendCommands(){ - AddCommand command = new AddCommand(); - MenuParams params = new MenuParams(); - params.setMenuName(TEST_COMMAND_NAME); - command.setCmdID(TEST_COMMAND_ID); - command.setMenuParams(params); - command.setVrCommands(Collections.singletonList(TEST_COMMAND_NAME)); - sdlManager.sendRPC(command); + private void setVoiceCommands(){ + + List list1 = Arrays.asList("Command One"); + List list2 = Arrays.asList("Command two"); + + VoiceCommand voiceCommand1 = new VoiceCommand(list1, new VoiceCommandSelectionListener() { + @Override + public void onVoiceCommandSelected() { + Log.i(TAG, "Voice Command 1 triggered"); + } + }); + + VoiceCommand voiceCommand2 = new VoiceCommand(list2, new VoiceCommandSelectionListener() { + @Override + public void onVoiceCommandSelected() { + Log.i(TAG, "Voice Command 2 triggered"); + } + }); + + sdlManager.getScreenManager().setVoiceCommands(Arrays.asList(voiceCommand1,voiceCommand2)); + } + + /** + * Add menus for the app on SDL. + */ + private void sendMenus(){ + + // some arts + SdlArtwork livio = new SdlArtwork("livio", FileType.GRAPHIC_PNG, R.drawable.sdl, false); + + // some voice commands + List voice2 = Arrays.asList("Cell two"); + + MenuCell mainCell1 = new MenuCell("Test Cell 1", livio, null, new MenuSelectionListener() { + @Override + public void onTriggered(TriggerSource trigger) { + Log.i(TAG, "Test cell 1 triggered. Source: "+ trigger.toString()); + } + }); + + MenuCell mainCell2 = new MenuCell("Test Cell 2", null, voice2, new MenuSelectionListener() { + @Override + public void onTriggered(TriggerSource trigger) { + Log.i(TAG, "Test cell 2 triggered. Source: "+ trigger.toString()); + } + }); + + MenuCell mainCell3 = new MenuCell("Clear the menu",null, null, new MenuSelectionListener() { + @Override + public void onTriggered(TriggerSource trigger) { + Log.i(TAG, "Clearing Menu. Source: "+ trigger.toString()); + // Clear this thing + sdlManager.getScreenManager().setMenu(Collections.emptyList()); + } + }); + + // SUB MENU + + MenuCell subCell1 = new MenuCell("SubCell 1",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() { + @Override + public void onTriggered(TriggerSource trigger) { + Log.i(TAG, "Sub cell 2 triggered. Source: "+ trigger.toString()); + } + }); + + // sub menu parent cell + MenuCell mainCell4 = new MenuCell("Test Cell 4", livio, Arrays.asList(subCell1,subCell2)); + + // Send the entire menu off to be created + sdlManager.getScreenManager().setMenu(Arrays.asList(mainCell1, mainCell2, mainCell3, mainCell4)); } /** 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 b94a9bf98..dc51aed9e 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 @@ -110,10 +110,10 @@ public class MenuManagerTests extends AndroidTestCase2 { assertEquals(menuManager.getState(), BaseSubManager.SETTING_UP); assertEquals(menuManager.currentSystemContext, SystemContext.SYSCTXT_MAIN); assertEquals(menuManager.lastMenuId, 1); - assertNotNull(menuManager.menuCells); - assertNotNull(menuManager.waitingUpdateMenuCells); - assertNotNull(menuManager.oldMenuCells); - assertNotNull(menuManager.inProgressUpdate); + assertNull(menuManager.menuCells); + assertNull(menuManager.waitingUpdateMenuCells); + assertNull(menuManager.oldMenuCells); + assertNull(menuManager.inProgressUpdate); assertNotNull(menuManager.hmiListener); assertNotNull(menuManager.commandListener); assertNotNull(menuManager.displayListener); @@ -160,7 +160,6 @@ public class MenuManagerTests extends AndroidTestCase2 { // updating voice commands before HMI is ready assertTrue(menuManager.waitingOnHMIUpdate); // these are the 2 commands we have waiting - assertEquals(menuManager.menuCells.size(), 0); assertEquals(menuManager.waitingUpdateMenuCells.size(), 4); assertEquals(menuManager.currentHMILevel, HMILevel.HMI_NONE); // The Menu Manager should send new menu once HMI full occurs @@ -173,13 +172,12 @@ public class MenuManagerTests extends AndroidTestCase2 { public void testUpdating(){ - assertEquals(menuManager.oldMenuCells.size(), 0); // these were deleted with the previous series of deletions assertEquals(menuManager.deleteCommandsForCells(cells).size(), 4); // 3 root cells and 1 sub menu // when we only send one command to update, we should only be returned one add command List newArray = Arrays.asList(mainCell1, mainCell4); assertEquals(menuManager.allCommandsForCells(newArray, false).size(), 4); // 1 root cells, 1 sub menu root cell, 2 sub menu cells - + menuManager.currentHMILevel = HMILevel.HMI_FULL; menuManager.setMenuCells(newArray); // Unlike voice commands, the Menu Manager dynamically assigns Cell ID's. Because of this, we need to get the updated @@ -189,7 +187,7 @@ public class MenuManagerTests extends AndroidTestCase2 { for (MenuCell cell : updatedCells){ // grab 2 of our newly updated cells - 1 root and 1 sub cell, and make sure they can get triggered - if (cell.getDescription().equalsIgnoreCase("Test Cell 1")){ + if (cell.getTitle().equalsIgnoreCase("Test Cell 1")){ // Fake onCommand - we want to make sure that we can pass back onCommand events to our root Menu Cell OnCommand onCommand = new OnCommand(); onCommand.setCmdID(cell.getCellId()); @@ -200,7 +198,7 @@ public class MenuManagerTests extends AndroidTestCase2 { verify(cell.getMenuSelectionListener(), times(1)).onTriggered(TriggerSource.TS_MENU); } - if (cell.getDescription().equalsIgnoreCase("SubCell 2")){ + if (cell.getTitle().equalsIgnoreCase("SubCell 2")){ // Fake onCommand - we want to make sure that we can pass back onCommand events to our sub Menu Cell OnCommand onCommand2 = new OnCommand(); onCommand2.setCmdID(cell.getCellId()); @@ -230,11 +228,11 @@ public class MenuManagerTests extends AndroidTestCase2 { mainCell1 = new MenuCell("Test Cell 1", livio, null, menuSelectionListener1); MenuCell mainCell2 = new MenuCell("Test Cell 2", livio, voice2, menuSelectionListener2); - MenuCell mainCell3 = new MenuCell("Test Cell 3", menuSelectionListener3); + MenuCell mainCell3 = new MenuCell("Test Cell 3",null, null, menuSelectionListener3); // SUB MENU - MenuCell subCell1 = new MenuCell("SubCell 1", menuSelectionListenerSub1); - MenuCell subCell2 = new MenuCell("SubCell 2", menuSelectionListenerSub2); + MenuCell subCell1 = new MenuCell("SubCell 1",null, null, menuSelectionListenerSub1); + MenuCell subCell2 = new MenuCell("SubCell 2",null, null, menuSelectionListenerSub2); mainCell4 = new MenuCell("Test Cell 4", livio, Arrays.asList(subCell1,subCell2)); // sub menu parent cell diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManagerTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManagerTests.java index db662c31f..2b07fcfbf 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManagerTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManagerTests.java @@ -112,8 +112,8 @@ public class VoiceCommandManagerTests extends AndroidTestCase2 { assertFalse(voiceCommandManager.waitingOnHMIUpdate); assertNotNull(voiceCommandManager.commandListener); assertNotNull(voiceCommandManager.hmiListener); - assertNotNull(voiceCommandManager.voiceCommands); - assertNotNull(voiceCommandManager.oldVoiceCommands); + assertNull(voiceCommandManager.voiceCommands); + assertNull(voiceCommandManager.oldVoiceCommands); assertNull(voiceCommandManager.inProgressUpdate); } @@ -171,8 +171,6 @@ public class VoiceCommandManagerTests extends AndroidTestCase2 { // we have previously sent 2 VoiceCommand objects. we will now update it and have just one - // This should have been cleared, but still initialized after the last send - assertEquals(voiceCommandManager.oldVoiceCommands.size(), 0); // make sure the system returns us 2 delete commands assertEquals(voiceCommandManager.deleteCommandsForVoiceCommands(commands).size(), 2); // when we only send one command to update, we should only be returned one add command diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManager.java b/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManager.java index c244d0d39..4a28a2792 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManager.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManager.java @@ -42,9 +42,9 @@ import com.smartdevicelink.proxy.interfaces.ISdl; * * The MenuManager takes MenuCell objects and creates and sends all necessary RPCs to build out a menu */ -class MenuManager extends BaseMenuManager { +public class MenuManager extends BaseMenuManager { - MenuManager(ISdl internalInterface, FileManager fileManager) { + public MenuManager(ISdl internalInterface, FileManager fileManager) { // setup super(internalInterface, fileManager); } diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManager.java b/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManager.java index a5492a384..a892d3a2c 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManager.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManager.java @@ -41,9 +41,9 @@ import com.smartdevicelink.proxy.interfaces.ISdl; * * The VoiceCommandManager takes a List of VoiceCommand objects and sets them on the Head unit for you. */ -class VoiceCommandManager extends BaseVoiceCommandManager { +public class VoiceCommandManager extends BaseVoiceCommandManager { - VoiceCommandManager(ISdl internalInterface) { + public VoiceCommandManager(ISdl internalInterface) { // setup super(internalInterface); } 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 55d271a1e..70be2008a 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 @@ -150,7 +150,7 @@ abstract class BaseMenuManager extends BaseSubManager { waitingOnHMIUpdate = false; // Update our Lists - this.oldMenuCells = new ArrayList<>(menuCells); + this.oldMenuCells = new ArrayList<>(menuCells != null ? menuCells : cells); menuCells = new ArrayList<>(cells); // HashSet order doesnt matter / does not allow duplicates @@ -308,7 +308,7 @@ abstract class BaseMenuManager extends BaseSubManager { List mainMenuCommands; final List subMenuCommands; - if (findAllArtworksToBeUploadedFromCells(menuCells).size() == 0 || !supportsImages()){ + if (findAllArtworksToBeUploadedFromCells(menuCells).size() > 0 || !supportsImages()){ // Send artwork-less menu mainMenuCommands = mainMenuCommandsForCells(menuCells, false); subMenuCommands = subMenuCommandsForCells(menuCells, false); diff --git a/javaSE/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManager.java b/javaSE/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManager.java index c244d0d39..4a28a2792 100644 --- a/javaSE/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManager.java +++ b/javaSE/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManager.java @@ -42,9 +42,9 @@ import com.smartdevicelink.proxy.interfaces.ISdl; * * The MenuManager takes MenuCell objects and creates and sends all necessary RPCs to build out a menu */ -class MenuManager extends BaseMenuManager { +public class MenuManager extends BaseMenuManager { - MenuManager(ISdl internalInterface, FileManager fileManager) { + public MenuManager(ISdl internalInterface, FileManager fileManager) { // setup super(internalInterface, fileManager); } diff --git a/javaSE/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManager.java b/javaSE/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManager.java index a5492a384..a892d3a2c 100644 --- a/javaSE/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManager.java +++ b/javaSE/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommandManager.java @@ -41,9 +41,9 @@ import com.smartdevicelink.proxy.interfaces.ISdl; * * The VoiceCommandManager takes a List of VoiceCommand objects and sets them on the Head unit for you. */ -class VoiceCommandManager extends BaseVoiceCommandManager { +public class VoiceCommandManager extends BaseVoiceCommandManager { - VoiceCommandManager(ISdl internalInterface) { + public VoiceCommandManager(ISdl internalInterface) { // setup super(internalInterface); } -- cgit v1.2.1 From 086274997eabcdf99b85c785ba4cf78402b2204f Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Thu, 9 May 2019 15:11:20 -0400 Subject: make menu items more clear --- .../java/com/sdl/hellosdlandroid/SdlService.java | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 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 030c3b3d0..efdbff67b 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 @@ -244,15 +244,6 @@ public class SdlService extends Service { } }); - MenuCell mainCell3 = new MenuCell("Clear the menu",null, null, new MenuSelectionListener() { - @Override - public void onTriggered(TriggerSource trigger) { - Log.i(TAG, "Clearing Menu. Source: "+ trigger.toString()); - // Clear this thing - sdlManager.getScreenManager().setMenu(Collections.emptyList()); - } - }); - // SUB MENU MenuCell subCell1 = new MenuCell("SubCell 1",null, null, new MenuSelectionListener() { @@ -270,7 +261,16 @@ public class SdlService extends Service { }); // sub menu parent cell - MenuCell mainCell4 = new MenuCell("Test Cell 4", livio, Arrays.asList(subCell1,subCell2)); + MenuCell mainCell3 = new MenuCell("Test Cell 3 (sub menu)", livio, Arrays.asList(subCell1,subCell2)); + + MenuCell mainCell4 = new MenuCell("Clear the menu",null, null, new MenuSelectionListener() { + @Override + public void onTriggered(TriggerSource trigger) { + Log.i(TAG, "Clearing Menu. Source: "+ trigger.toString()); + // Clear this thing + sdlManager.getScreenManager().setMenu(Collections.emptyList()); + } + }); // Send the entire menu off to be created sdlManager.getScreenManager().setMenu(Arrays.asList(mainCell1, mainCell2, mainCell3, mainCell4)); -- cgit v1.2.1 From 41f05aa9189178892ca673c458db10f919136ac2 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Thu, 9 May 2019 15:53:52 -0400 Subject: update hello examples --- .../java/com/sdl/hellosdlandroid/SdlService.java | 2 +- .../java/com/smartdevicelink/java/SdlService.java | 117 ++++++++++++++++----- .../main/java/com/smartdevicelink/SdlService.java | 115 +++++++++++++++----- 3 files changed, 175 insertions(+), 59 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 efdbff67b..ec7af8ca0 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 @@ -228,7 +228,7 @@ public class SdlService extends Service { SdlArtwork livio = new SdlArtwork("livio", FileType.GRAPHIC_PNG, R.drawable.sdl, false); // some voice commands - List voice2 = Arrays.asList("Cell two"); + List voice2 = Collections.singletonList("Cell two"); MenuCell mainCell1 = new MenuCell("Test Cell 1", livio, null, new MenuSelectionListener() { @Override diff --git a/hello_sdl_java/src/main/java/com/smartdevicelink/java/SdlService.java b/hello_sdl_java/src/main/java/com/smartdevicelink/java/SdlService.java index 0330ce192..312b1faa4 100644 --- a/hello_sdl_java/src/main/java/com/smartdevicelink/java/SdlService.java +++ b/hello_sdl_java/src/main/java/com/smartdevicelink/java/SdlService.java @@ -37,6 +37,10 @@ import com.smartdevicelink.managers.CompletionListener; import com.smartdevicelink.managers.SdlManager; import com.smartdevicelink.managers.SdlManagerListener; import com.smartdevicelink.managers.file.filetypes.SdlArtwork; +import com.smartdevicelink.managers.screen.menu.MenuCell; +import com.smartdevicelink.managers.screen.menu.MenuSelectionListener; +import com.smartdevicelink.managers.screen.menu.VoiceCommand; +import com.smartdevicelink.managers.screen.menu.VoiceCommandSelectionListener; import com.smartdevicelink.protocol.enums.FunctionID; import com.smartdevicelink.proxy.RPCNotification; import com.smartdevicelink.proxy.TTSChunkFactory; @@ -44,13 +48,14 @@ import com.smartdevicelink.proxy.rpc.*; import com.smartdevicelink.proxy.rpc.enums.AppHMIType; import com.smartdevicelink.proxy.rpc.enums.FileType; import com.smartdevicelink.proxy.rpc.enums.HMILevel; +import com.smartdevicelink.proxy.rpc.enums.TriggerSource; import com.smartdevicelink.proxy.rpc.listeners.OnRPCNotificationListener; import com.smartdevicelink.transport.BaseTransportConfig; import com.smartdevicelink.util.DebugTool; -import java.util.Collections; -import java.util.HashMap; -import java.util.Vector; +import java.util.*; + +import static javafx.scene.input.KeyCode.R; public class SdlService { @@ -141,29 +146,14 @@ public class SdlService { public void onNotified(RPCNotification notification) { OnHMIStatus status = (OnHMIStatus) notification; if (status.getHmiLevel() == HMILevel.HMI_FULL && ((OnHMIStatus) notification).getFirstRun()) { - sendCommands(); + setVoiceCommands(); + sendMenus(); performWelcomeSpeak(); performWelcomeShow(); } } }); - notificationListenerHashMap.put(FunctionID.ON_COMMAND, new OnRPCNotificationListener() { - @Override - public void onNotified(RPCNotification notification) { - OnCommand command = (OnCommand) notification; - Integer id = command.getCmdID(); - if(id != null){ - switch(id){ - case TEST_COMMAND_ID: - showTest(); - break; - } - } - } - }); - - // Create App Icon, this is set in the SdlManager builder SdlArtwork appIcon = new SdlArtwork(ICON_FILENAME, FileType.GRAPHIC_PNG, IMAGE_DIR+"sdl_s_green.png", true); @@ -177,17 +167,86 @@ public class SdlService { } } +/** + * Send some voice commands + */ + private void setVoiceCommands(){ + + List list1 = Arrays.asList("Command One"); + List list2 = Arrays.asList("Command two"); + + VoiceCommand voiceCommand1 = new VoiceCommand(list1, new VoiceCommandSelectionListener() { + @Override + public void onVoiceCommandSelected() { + Log.i(TAG, "Voice Command 1 triggered"); + } + }); + + VoiceCommand voiceCommand2 = new VoiceCommand(list2, new VoiceCommandSelectionListener() { + @Override + public void onVoiceCommandSelected() { + Log.i(TAG, "Voice Command 2 triggered"); + } + }); + + sdlManager.getScreenManager().setVoiceCommands(Arrays.asList(voiceCommand1,voiceCommand2)); + } + /** - * Add commands for the app on SDL. + * Add menus for the app on SDL. */ - private void sendCommands(){ - AddCommand command = new AddCommand(); - MenuParams params = new MenuParams(); - params.setMenuName(TEST_COMMAND_NAME); - command.setCmdID(TEST_COMMAND_ID); - command.setMenuParams(params); - command.setVrCommands(Collections.singletonList(TEST_COMMAND_NAME)); - sdlManager.sendRPC(command); + private void sendMenus(){ + + // some arts + SdlArtwork livio = new SdlArtwork(ICON_FILENAME, FileType.GRAPHIC_PNG, IMAGE_DIR+"sdl_s_green.png", true); + + // some voice commands + List voice2 = Collections.singletonList("Cell two"); + + MenuCell mainCell1 = new MenuCell("Test Cell 1", livio, null, new MenuSelectionListener() { + @Override + public void onTriggered(TriggerSource trigger) { + Log.i(TAG, "Test cell 1 triggered. Source: "+ trigger.toString()); + } + }); + + MenuCell mainCell2 = new MenuCell("Test Cell 2", null, voice2, new MenuSelectionListener() { + @Override + public void onTriggered(TriggerSource trigger) { + Log.i(TAG, "Test cell 2 triggered. Source: "+ trigger.toString()); + } + }); + + // SUB MENU + + MenuCell subCell1 = new MenuCell("SubCell 1",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() { + @Override + public void onTriggered(TriggerSource trigger) { + Log.i(TAG, "Sub cell 2 triggered. Source: "+ trigger.toString()); + } + }); + + // sub menu parent cell + MenuCell mainCell3 = new MenuCell("Test Cell 3 (sub menu)", livio, Arrays.asList(subCell1,subCell2)); + + MenuCell mainCell4 = new MenuCell("Clear the menu",null, null, new MenuSelectionListener() { + @Override + public void onTriggered(TriggerSource trigger) { + Log.i(TAG, "Clearing Menu. Source: "+ trigger.toString()); + // Clear this thing + sdlManager.getScreenManager().setMenu(Collections.emptyList()); + } + }); + + // Send the entire menu off to be created + sdlManager.getScreenManager().setMenu(Arrays.asList(mainCell1, mainCell2, mainCell3, mainCell4)); } /** diff --git a/hello_sdl_java_ee/src/main/java/com/smartdevicelink/SdlService.java b/hello_sdl_java_ee/src/main/java/com/smartdevicelink/SdlService.java index 58d98cf8d..f8d51ed4e 100644 --- a/hello_sdl_java_ee/src/main/java/com/smartdevicelink/SdlService.java +++ b/hello_sdl_java_ee/src/main/java/com/smartdevicelink/SdlService.java @@ -5,6 +5,10 @@ import com.smartdevicelink.managers.CompletionListener; import com.smartdevicelink.managers.SdlManager; import com.smartdevicelink.managers.SdlManagerListener; import com.smartdevicelink.managers.file.filetypes.SdlArtwork; +import com.smartdevicelink.managers.screen.menu.MenuCell; +import com.smartdevicelink.managers.screen.menu.MenuSelectionListener; +import com.smartdevicelink.managers.screen.menu.VoiceCommand; +import com.smartdevicelink.managers.screen.menu.VoiceCommandSelectionListener; import com.smartdevicelink.protocol.enums.FunctionID; import com.smartdevicelink.proxy.RPCNotification; import com.smartdevicelink.proxy.TTSChunkFactory; @@ -12,13 +16,12 @@ import com.smartdevicelink.proxy.rpc.*; import com.smartdevicelink.proxy.rpc.enums.AppHMIType; import com.smartdevicelink.proxy.rpc.enums.FileType; import com.smartdevicelink.proxy.rpc.enums.HMILevel; +import com.smartdevicelink.proxy.rpc.enums.TriggerSource; import com.smartdevicelink.proxy.rpc.listeners.OnRPCNotificationListener; import com.smartdevicelink.transport.BaseTransportConfig; import com.smartdevicelink.util.DebugTool; -import java.util.Collections; -import java.util.HashMap; -import java.util.Vector; +import java.util.*; public class SdlService { @@ -109,29 +112,14 @@ public class SdlService { public void onNotified(RPCNotification notification) { OnHMIStatus status = (OnHMIStatus) notification; if (status.getHmiLevel() == HMILevel.HMI_FULL && ((OnHMIStatus) notification).getFirstRun()) { - sendCommands(); + setVoiceCommands(); + sendMenus(); performWelcomeSpeak(); performWelcomeShow(); } } }); - notificationListenerHashMap.put(FunctionID.ON_COMMAND, new OnRPCNotificationListener() { - @Override - public void onNotified(RPCNotification notification) { - OnCommand command = (OnCommand) notification; - Integer id = command.getCmdID(); - if(id != null){ - switch(id){ - case TEST_COMMAND_ID: - showTest(); - break; - } - } - } - }); - - // Create App Icon, this is set in the SdlManager builder SdlArtwork appIcon = new SdlArtwork(ICON_FILENAME, FileType.GRAPHIC_PNG, IMAGE_DIR+"sdl_s_green.png", true); @@ -145,17 +133,86 @@ public class SdlService { } } + /** + * Send some voice commands + */ + private void setVoiceCommands(){ + + List list1 = Arrays.asList("Command One"); + List list2 = Arrays.asList("Command two"); + + VoiceCommand voiceCommand1 = new VoiceCommand(list1, new VoiceCommandSelectionListener() { + @Override + public void onVoiceCommandSelected() { + Log.i(TAG, "Voice Command 1 triggered"); + } + }); + + VoiceCommand voiceCommand2 = new VoiceCommand(list2, new VoiceCommandSelectionListener() { + @Override + public void onVoiceCommandSelected() { + Log.i(TAG, "Voice Command 2 triggered"); + } + }); + + sdlManager.getScreenManager().setVoiceCommands(Arrays.asList(voiceCommand1,voiceCommand2)); + } + /** - * Add commands for the app on SDL. + * Add menus for the app on SDL. */ - private void sendCommands(){ - AddCommand command = new AddCommand(); - MenuParams params = new MenuParams(); - params.setMenuName(TEST_COMMAND_NAME); - command.setCmdID(TEST_COMMAND_ID); - command.setMenuParams(params); - command.setVrCommands(Collections.singletonList(TEST_COMMAND_NAME)); - sdlManager.sendRPC(command); + private void sendMenus(){ + + // some arts + SdlArtwork livio = new SdlArtwork(ICON_FILENAME, FileType.GRAPHIC_PNG, IMAGE_DIR+"sdl_s_green.png", true); + + // some voice commands + List voice2 = Collections.singletonList("Cell two"); + + MenuCell mainCell1 = new MenuCell("Test Cell 1", livio, null, new MenuSelectionListener() { + @Override + public void onTriggered(TriggerSource trigger) { + Log.i(TAG, "Test cell 1 triggered. Source: "+ trigger.toString()); + } + }); + + MenuCell mainCell2 = new MenuCell("Test Cell 2", null, voice2, new MenuSelectionListener() { + @Override + public void onTriggered(TriggerSource trigger) { + Log.i(TAG, "Test cell 2 triggered. Source: "+ trigger.toString()); + } + }); + + // SUB MENU + + MenuCell subCell1 = new MenuCell("SubCell 1",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() { + @Override + public void onTriggered(TriggerSource trigger) { + Log.i(TAG, "Sub cell 2 triggered. Source: "+ trigger.toString()); + } + }); + + // sub menu parent cell + MenuCell mainCell3 = new MenuCell("Test Cell 3 (sub menu)", livio, Arrays.asList(subCell1,subCell2)); + + MenuCell mainCell4 = new MenuCell("Clear the menu",null, null, new MenuSelectionListener() { + @Override + public void onTriggered(TriggerSource trigger) { + Log.i(TAG, "Clearing Menu. Source: "+ trigger.toString()); + // Clear this thing + sdlManager.getScreenManager().setMenu(Collections.emptyList()); + } + }); + + // Send the entire menu off to be created + sdlManager.getScreenManager().setMenu(Arrays.asList(mainCell1, mainCell2, mainCell3, mainCell4)); } /** -- cgit v1.2.1 From c8acb49c8b93a2636ccb5a151635ec738403af94 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Thu, 9 May 2019 16:02:33 -0400 Subject: small update --- .../src/main/java/com/sdl/hellosdlandroid/SdlService.java | 4 ++-- hello_sdl_java/src/main/java/com/smartdevicelink/java/SdlService.java | 4 ++-- hello_sdl_java_ee/src/main/java/com/smartdevicelink/SdlService.java | 4 ++-- 3 files changed, 6 insertions(+), 6 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 ec7af8ca0..2e99d2de4 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 @@ -199,8 +199,8 @@ public class SdlService extends Service { */ private void setVoiceCommands(){ - List list1 = Arrays.asList("Command One"); - List list2 = Arrays.asList("Command two"); + List list1 = Collections.singletonList("Command One"); + List list2 = Collections.singletonList("Command two"); VoiceCommand voiceCommand1 = new VoiceCommand(list1, new VoiceCommandSelectionListener() { @Override diff --git a/hello_sdl_java/src/main/java/com/smartdevicelink/java/SdlService.java b/hello_sdl_java/src/main/java/com/smartdevicelink/java/SdlService.java index 312b1faa4..b280eaa0b 100644 --- a/hello_sdl_java/src/main/java/com/smartdevicelink/java/SdlService.java +++ b/hello_sdl_java/src/main/java/com/smartdevicelink/java/SdlService.java @@ -172,8 +172,8 @@ public class SdlService { */ private void setVoiceCommands(){ - List list1 = Arrays.asList("Command One"); - List list2 = Arrays.asList("Command two"); + List list1 = Collections.singletonList("Command One"); + List list2 = Collections.singletonList("Command two"); VoiceCommand voiceCommand1 = new VoiceCommand(list1, new VoiceCommandSelectionListener() { @Override diff --git a/hello_sdl_java_ee/src/main/java/com/smartdevicelink/SdlService.java b/hello_sdl_java_ee/src/main/java/com/smartdevicelink/SdlService.java index f8d51ed4e..1d9719e6c 100644 --- a/hello_sdl_java_ee/src/main/java/com/smartdevicelink/SdlService.java +++ b/hello_sdl_java_ee/src/main/java/com/smartdevicelink/SdlService.java @@ -138,8 +138,8 @@ public class SdlService { */ private void setVoiceCommands(){ - List list1 = Arrays.asList("Command One"); - List list2 = Arrays.asList("Command two"); + List list1 = Collections.singletonList("Command One"); + List list2 = Collections.singletonList("Command two"); VoiceCommand voiceCommand1 = new VoiceCommand(list1, new VoiceCommandSelectionListener() { @Override -- cgit v1.2.1 From e00162407fd36bcc659d601906b33547c786cf4f Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Thu, 9 May 2019 16:20:29 -0400 Subject: fix npe for submenu icon --- .../src/main/java/com/sdl/hellosdlandroid/SdlService.java | 2 +- .../java/com/smartdevicelink/managers/screen/menu/BaseMenuManager.java | 2 +- hello_sdl_java/src/main/java/com/smartdevicelink/java/SdlService.java | 2 +- hello_sdl_java_ee/src/main/java/com/smartdevicelink/SdlService.java | 2 +- 4 files changed, 4 insertions(+), 4 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 2e99d2de4..2b0cbf27e 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 @@ -261,7 +261,7 @@ public class SdlService extends Service { }); // sub menu parent cell - MenuCell mainCell3 = new MenuCell("Test Cell 3 (sub menu)", livio, Arrays.asList(subCell1,subCell2)); + MenuCell mainCell3 = new MenuCell("Test Cell 3 (sub menu)", null, Arrays.asList(subCell1,subCell2)); MenuCell mainCell4 = new MenuCell("Clear the menu",null, null, new MenuSelectionListener() { @Override 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 70be2008a..f44f7e74e 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 @@ -525,7 +525,7 @@ abstract class BaseMenuManager extends BaseSubManager { private AddSubMenu subMenuCommandForMenuCell(MenuCell cell, boolean shouldHaveArtwork, int position){ AddSubMenu subMenu = new AddSubMenu(cell.getCellId(), cell.getTitle()); subMenu.setPosition(position); - subMenu.setMenuIcon((shouldHaveArtwork && (cell.getIcon().getName() != null)) ? cell.getIcon().getImageRPC() : null); + subMenu.setMenuIcon((shouldHaveArtwork && (cell.getIcon()!= null && cell.getIcon().getImageRPC() != null)) ? cell.getIcon().getImageRPC() : null); return subMenu; } diff --git a/hello_sdl_java/src/main/java/com/smartdevicelink/java/SdlService.java b/hello_sdl_java/src/main/java/com/smartdevicelink/java/SdlService.java index b280eaa0b..fb74c6e80 100644 --- a/hello_sdl_java/src/main/java/com/smartdevicelink/java/SdlService.java +++ b/hello_sdl_java/src/main/java/com/smartdevicelink/java/SdlService.java @@ -234,7 +234,7 @@ public class SdlService { }); // sub menu parent cell - MenuCell mainCell3 = new MenuCell("Test Cell 3 (sub menu)", livio, Arrays.asList(subCell1,subCell2)); + MenuCell mainCell3 = new MenuCell("Test Cell 3 (sub menu)", null, Arrays.asList(subCell1,subCell2)); MenuCell mainCell4 = new MenuCell("Clear the menu",null, null, new MenuSelectionListener() { @Override diff --git a/hello_sdl_java_ee/src/main/java/com/smartdevicelink/SdlService.java b/hello_sdl_java_ee/src/main/java/com/smartdevicelink/SdlService.java index 1d9719e6c..37f87dc55 100644 --- a/hello_sdl_java_ee/src/main/java/com/smartdevicelink/SdlService.java +++ b/hello_sdl_java_ee/src/main/java/com/smartdevicelink/SdlService.java @@ -200,7 +200,7 @@ public class SdlService { }); // sub menu parent cell - MenuCell mainCell3 = new MenuCell("Test Cell 3 (sub menu)", livio, Arrays.asList(subCell1,subCell2)); + MenuCell mainCell3 = new MenuCell("Test Cell 3 (sub menu)", null, Arrays.asList(subCell1,subCell2)); MenuCell mainCell4 = new MenuCell("Clear the menu",null, null, new MenuSelectionListener() { @Override -- cgit v1.2.1 From fc9c51ecd15a2f0ea077b7e9ec3da199e897f722 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Fri, 10 May 2019 10:08:27 -0400 Subject: fix npe and enhance hello examples --- .../java/com/sdl/hellosdlandroid/SdlService.java | 14 ++++++++++++-- .../managers/screen/menu/BaseMenuManager.java | 20 +++++++++++--------- .../java/com/smartdevicelink/java/SdlService.java | 13 +++++++++++-- .../main/java/com/smartdevicelink/SdlService.java | 13 +++++++++++-- 4 files changed, 45 insertions(+), 15 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 2b0cbf27e..e4f1919df 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 @@ -22,6 +22,7 @@ import com.smartdevicelink.managers.screen.menu.VoiceCommandSelectionListener; import com.smartdevicelink.protocol.enums.FunctionID; import com.smartdevicelink.proxy.RPCNotification; import com.smartdevicelink.proxy.TTSChunkFactory; +import com.smartdevicelink.proxy.rpc.Alert; import com.smartdevicelink.proxy.rpc.OnHMIStatus; import com.smartdevicelink.proxy.rpc.Speak; import com.smartdevicelink.proxy.rpc.enums.AppHMIType; @@ -230,10 +231,11 @@ public class SdlService extends Service { // some voice commands List voice2 = Collections.singletonList("Cell two"); - MenuCell mainCell1 = new MenuCell("Test Cell 1", livio, null, new MenuSelectionListener() { + MenuCell mainCell1 = new MenuCell("Test Cell 1 (speak)", livio, null, new MenuSelectionListener() { @Override public void onTriggered(TriggerSource trigger) { Log.i(TAG, "Test cell 1 triggered. Source: "+ trigger.toString()); + showTest(); } }); @@ -269,6 +271,7 @@ public class SdlService extends Service { Log.i(TAG, "Clearing Menu. Source: "+ trigger.toString()); // Clear this thing sdlManager.getScreenManager().setMenu(Collections.emptyList()); + showAlert("Menu Cleared"); } }); @@ -308,12 +311,19 @@ public class SdlService extends Service { */ private void showTest(){ sdlManager.getScreenManager().beginTransaction(); - sdlManager.getScreenManager().setTextField1("Command has been selected"); + sdlManager.getScreenManager().setTextField1("Test Cell 1 has been selected"); sdlManager.getScreenManager().setTextField2(""); sdlManager.getScreenManager().commit(null); sdlManager.sendRPC(new Speak(TTSChunkFactory.createSimpleTTSChunks(TEST_COMMAND_NAME))); } + private void showAlert(String text){ + Alert alert = new Alert(); + alert.setAlertText1(text); + alert.setDuration(5000); + sdlManager.sendRPC(alert); + } + } 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 f44f7e74e..5cf84bf74 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 @@ -532,17 +532,19 @@ abstract class BaseMenuManager extends BaseSubManager { // CELL COMMAND HANDLING private boolean callListenerForCells(List cells, OnCommand command){ - for (MenuCell cell : cells){ - if (cell.getCellId() == command.getCmdID() && cell.getMenuSelectionListener() != null){ - cell.getMenuSelectionListener().onTriggered(command.getTriggerSource()); - return true; - } - - if (cell.getSubCells() != null && cell.getSubCells().size() > 0){ - // for each cell, if it has sub cells, recursively loop through those as well - if (callListenerForCells(cell.getSubCells(), command)) { + if (cells != null && cells.size() > 0 && command != null) { + for (MenuCell cell : cells) { + if (cell.getCellId() == command.getCmdID() && cell.getMenuSelectionListener() != null) { + cell.getMenuSelectionListener().onTriggered(command.getTriggerSource()); return true; } + + if (cell.getSubCells() != null && cell.getSubCells().size() > 0) { + // for each cell, if it has sub cells, recursively loop through those as well + if (callListenerForCells(cell.getSubCells(), command)) { + return true; + } + } } } return false; diff --git a/hello_sdl_java/src/main/java/com/smartdevicelink/java/SdlService.java b/hello_sdl_java/src/main/java/com/smartdevicelink/java/SdlService.java index fb74c6e80..9af923026 100644 --- a/hello_sdl_java/src/main/java/com/smartdevicelink/java/SdlService.java +++ b/hello_sdl_java/src/main/java/com/smartdevicelink/java/SdlService.java @@ -203,10 +203,11 @@ public class SdlService { // some voice commands List voice2 = Collections.singletonList("Cell two"); - MenuCell mainCell1 = new MenuCell("Test Cell 1", livio, null, new MenuSelectionListener() { + MenuCell mainCell1 = new MenuCell("Test Cell 1 (speak)", livio, null, new MenuSelectionListener() { @Override public void onTriggered(TriggerSource trigger) { Log.i(TAG, "Test cell 1 triggered. Source: "+ trigger.toString()); + showTest(); } }); @@ -242,6 +243,7 @@ public class SdlService { Log.i(TAG, "Clearing Menu. Source: "+ trigger.toString()); // Clear this thing sdlManager.getScreenManager().setMenu(Collections.emptyList()); + showAlert("Menu Cleared"); } }); @@ -281,13 +283,20 @@ public class SdlService { */ private void showTest(){ sdlManager.getScreenManager().beginTransaction(); - sdlManager.getScreenManager().setTextField1("Command has been selected"); + sdlManager.getScreenManager().setTextField1("Test Cell 1 has been selected"); sdlManager.getScreenManager().setTextField2(""); sdlManager.getScreenManager().commit(null); sdlManager.sendRPC(new Speak(TTSChunkFactory.createSimpleTTSChunks(TEST_COMMAND_NAME))); } + private void showAlert(String text){ + Alert alert = new Alert(); + alert.setAlertText1(text); + alert.setDuration(5000); + sdlManager.sendRPC(alert); + } + public interface SdlServiceCallback{ void onEnd(); diff --git a/hello_sdl_java_ee/src/main/java/com/smartdevicelink/SdlService.java b/hello_sdl_java_ee/src/main/java/com/smartdevicelink/SdlService.java index 37f87dc55..aaf887222 100644 --- a/hello_sdl_java_ee/src/main/java/com/smartdevicelink/SdlService.java +++ b/hello_sdl_java_ee/src/main/java/com/smartdevicelink/SdlService.java @@ -169,10 +169,11 @@ public class SdlService { // some voice commands List voice2 = Collections.singletonList("Cell two"); - MenuCell mainCell1 = new MenuCell("Test Cell 1", livio, null, new MenuSelectionListener() { + MenuCell mainCell1 = new MenuCell("Test Cell 1 (speak)", livio, null, new MenuSelectionListener() { @Override public void onTriggered(TriggerSource trigger) { Log.i(TAG, "Test cell 1 triggered. Source: "+ trigger.toString()); + showTest(); } }); @@ -208,6 +209,7 @@ public class SdlService { Log.i(TAG, "Clearing Menu. Source: "+ trigger.toString()); // Clear this thing sdlManager.getScreenManager().setMenu(Collections.emptyList()); + showAlert("Menu Cleared"); } }); @@ -247,13 +249,20 @@ public class SdlService { */ private void showTest(){ sdlManager.getScreenManager().beginTransaction(); - sdlManager.getScreenManager().setTextField1("Command has been selected"); + sdlManager.getScreenManager().setTextField1("Test Cell 1 has been selected"); sdlManager.getScreenManager().setTextField2(""); sdlManager.getScreenManager().commit(null); sdlManager.sendRPC(new Speak(TTSChunkFactory.createSimpleTTSChunks(TEST_COMMAND_NAME))); } + private void showAlert(String text){ + Alert alert = new Alert(); + alert.setAlertText1(text); + alert.setDuration(5000); + sdlManager.sendRPC(alert); + } + public interface SdlServiceCallback{ void onEnd(); -- cgit v1.2.1 From cef5ff263bcfd71c21e10c1800aab6c8640eac28 Mon Sep 17 00:00:00 2001 From: Brett <3911458+BrettyWhite@users.noreply.github.com> Date: Fri, 10 May 2019 10:09:03 -0400 Subject: Update base/src/main/java/com/smartdevicelink/managers/screen/BaseScreenManager.java Co-Authored-By: Bilal Alsharifi <599206+bilal-alsharifi@users.noreply.github.com> --- .../java/com/smartdevicelink/managers/screen/BaseScreenManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 f5721c153..7187c90e1 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/BaseScreenManager.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/BaseScreenManager.java @@ -73,7 +73,7 @@ abstract class BaseScreenManager extends BaseSubManager { DebugTool.logInfo("Starting screen manager, all sub managers are in ready state"); transitionToState(READY); } else if (softButtonManager.getState() == BaseSubManager.ERROR && textAndGraphicManager.getState() == BaseSubManager.ERROR && voiceCommandManager.getState() == BaseSubManager.ERROR && menuManager.getState() == BaseSubManager.ERROR) { - Log.e(TAG, "ERROR starting screen manager, one or more sub managers in error state"); + Log.e(TAG, "ERROR starting screen manager, all sub managers are in error state"); transitionToState(ERROR); } else if (textAndGraphicManager.getState() == BaseSubManager.SETTING_UP || softButtonManager.getState() == BaseSubManager.SETTING_UP || voiceCommandManager.getState() == BaseSubManager.SETTING_UP || menuManager.getState() == BaseSubManager.SETTING_UP) { DebugTool.logInfo("SETTING UP screen manager, at least one sub manager is still setting up"); -- cgit v1.2.1 From bc347314c2325f21c7eb0a179bc66ccd4976e071 Mon Sep 17 00:00:00 2001 From: Brett <3911458+BrettyWhite@users.noreply.github.com> Date: Fri, 10 May 2019 10:09:18 -0400 Subject: Update base/src/main/java/com/smartdevicelink/managers/screen/BaseScreenManager.java Co-Authored-By: Bilal Alsharifi <599206+bilal-alsharifi@users.noreply.github.com> --- .../java/com/smartdevicelink/managers/screen/BaseScreenManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 7187c90e1..b6c040884 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/BaseScreenManager.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/BaseScreenManager.java @@ -79,7 +79,7 @@ abstract class BaseScreenManager extends BaseSubManager { DebugTool.logInfo("SETTING UP screen manager, at least one sub manager is still setting up"); transitionToState(SETTING_UP); } else { - Log.w(TAG, "LIMITED starting screen manager, at least one sub manager in error state and the other is ready"); + Log.w(TAG, "LIMITED starting screen manager, at least one sub manager is in error state and the others are ready"); transitionToState(LIMITED); } } else { -- cgit v1.2.1 From dd6c907eafb1a69b247676dea20c61596d882e56 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Fri, 10 May 2019 10:58:34 -0400 Subject: remove toString method in menucell --- .../com/smartdevicelink/managers/screen/menu/MenuCell.java | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java index 27b539430..030d4ef85 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java @@ -233,17 +233,4 @@ public class MenuCell { int getParentCellId() { return parentCellId; } - - // HELPER - - /** - * Get the description of the cell - * @return a String description of the cell object - */ - @Override - public String toString(){ - return "MenuCell - ID: "+cellId+ " - title: "+ title + " - ArtworkName: "+ - (icon != null && icon.getName() != null ? icon.getName() : "Artwork is null") + " - VoiceCommands Size: "+ (voiceCommands != null ? voiceCommands.size() : "0") + " - isSubCell: " + (parentCellId != MAX_ID ? "YES":"NO")+ - " - hasSubCells: "+ (subCells != null && subCells.size() > 0 ? "YES":"NO"); - } } -- cgit v1.2.1 From ffe1b9992cde52c11124477653292c574744d71e Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Fri, 10 May 2019 11:34:51 -0400 Subject: remove description. update branch from menu manager branch --- .../com/smartdevicelink/managers/screen/menu/MenuCell.java | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java index cc715cd5d..01f9e6a1a 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java @@ -249,16 +249,6 @@ public class MenuCell { // HELPER - /** - * Get the description of the cell - * @return a String description of the cell object - */ - public String getDescription(){ - return "MenuCell - ID: "+cellId+ " title: "+ title + " ArtworkName: "+ - icon.getName() + " VoiceCommands: "+ voiceCommands.size() + " isSubCell: " + (parentCellId != Integer.MAX_VALUE ? "YES":"NO")+ - " hasSubCells: "+ (subCells != null && subCells.size() > 0 ? "YES":"NO"); - } - /** * Note: You should compare using the {@link #equals(Object)} method.
* Hash the parameters of the object and return the result for comparison -- cgit v1.2.1 From 0da5535ce845fec8c9a2225e17ec538de580f491 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Fri, 10 May 2019 11:41:15 -0400 Subject: remove uneeded constructor to match menu manager branch --- .../com/smartdevicelink/managers/screen/menu/MenuCell.java | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java index 01f9e6a1a..445f5d04a 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java @@ -38,7 +38,6 @@ import android.support.annotation.Nullable; import com.smartdevicelink.managers.file.filetypes.SdlArtwork; import java.util.List; -import java.util.Objects; public class MenuCell { @@ -86,18 +85,6 @@ public class MenuCell { // SINGLE MENU ITEM CONSTRUCTORS - /** - * Creates a new MenuCell Object with just the title set. - * @param title The cell's primary text - * @param listener a listener that notifies you when the cell was selected and lets you know its trigger source - */ - public MenuCell(@NonNull String title, @Nullable MenuSelectionListener listener) { - setTitle(title); // title is the only required param - setMenuSelectionListener(listener); - setCellId(MAX_ID); - setParentCellId(MAX_ID); - } - /** * Creates a new MenuCell Object with multiple parameters set * @param title The cell's primary text -- cgit v1.2.1 From 618e5087606310547eb97f10599139751bda0792 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Mon, 13 May 2019 10:11:44 -0400 Subject: create menu cell states for algorithm --- .../managers/screen/menu/MenuCell.java | 45 ++++++++++++++++++++-- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java index 445f5d04a..08d633178 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java @@ -81,6 +81,21 @@ public class MenuCell { */ private static final int MAX_ID = 2000000000; + /** + * Used internally for dynamic updating + */ + static final int NOT_SET = 0x00, ADDITION = 0x30, DELETION = 0x60; + + /** + * The state of the cell as it is marked for changes. This is used internally with the enums defined above + */ + private int state; + + /** + * A lock used when setting / getting states + */ + private final Object STATE_LOCK = new Object(); + // CONSTRUCTORS // SINGLE MENU ITEM CONSTRUCTORS @@ -99,6 +114,7 @@ public class MenuCell { setMenuSelectionListener(listener); setCellId(MAX_ID); setParentCellId(MAX_ID); + setState(NOT_SET); } // CONSTRUCTOR FOR CELL THAT WILL LINK TO SUB MENU @@ -116,6 +132,7 @@ public class MenuCell { setSubCells(subCells); setCellId(MAX_ID); setParentCellId(MAX_ID); + setState(NOT_SET); } // SETTERS / GETTERS @@ -234,6 +251,26 @@ public class MenuCell { return parentCellId; } + /** + * Sets whether or not the state of the cell is marked for addition or deletion + * @param state - the state enum + */ + void setState(int state){ + synchronized (STATE_LOCK) { + this.state = state; + } + } + + /** + * Read the state of the cell + * @return Whether or not the cell is marked for addition or deletion + */ + int getState() { + synchronized (STATE_LOCK) { + return this.state; + } + } + // HELPER /** @@ -248,10 +285,10 @@ public class MenuCell { @Override public int hashCode() { int result = 1; - result += ((getTitle() == null) ? 0 : Integer.rotateLeft(getTitle().hashCode(), 2)); - result += ((getIcon() == null || getIcon().getName() == null) ? 0 : Integer.rotateLeft(getIcon().getName().hashCode(), 3)); - result += ((getVoiceCommands() == null) ? 0 : Integer.rotateLeft(getVoiceCommands().hashCode(), 4)); - result += ((getSubCells() == null) ? 0 : Integer.rotateLeft(getSubCells().hashCode(), 5)); + result += ((getTitle() == null) ? 0 : Integer.rotateLeft(getTitle().hashCode(), 1)); + result += ((getIcon() == null || getIcon().getName() == null) ? 0 : Integer.rotateLeft(getIcon().getName().hashCode(), 2)); + result += ((getVoiceCommands() == null) ? 0 : Integer.rotateLeft(getVoiceCommands().hashCode(), 3)); + result += ((getSubCells() == null) ? 0 : Integer.rotateLeft(getSubCells().hashCode(), 4)); return result; } -- cgit v1.2.1 From 9aed06ebf41e8c49d3adb867971cad18011fe6b1 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Mon, 13 May 2019 10:58:08 -0400 Subject: redo states with annotation based enum --- .../managers/screen/menu/MenuCell.java | 26 +++++++++++++++------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java index 08d633178..948052619 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java @@ -32,11 +32,14 @@ package com.smartdevicelink.managers.screen.menu; +import android.support.annotation.IntDef; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.smartdevicelink.managers.file.filetypes.SdlArtwork; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; import java.util.List; public class MenuCell { @@ -82,14 +85,20 @@ public class MenuCell { private static final int MAX_ID = 2000000000; /** - * Used internally for dynamic updating + * State enums used internally for dynamic updating + * These should be used to set the 'state' variable */ - static final int NOT_SET = 0x00, ADDITION = 0x30, DELETION = 0x60; + @IntDef({NOT_SET, MARKED_FOR_ADDITION, MARKED_FOR_DELETION}) + @Retention(RetentionPolicy.SOURCE) + @interface MenuCellState {} + static final int NOT_SET = 0; + static final int MARKED_FOR_ADDITION = 1; + static final int MARKED_FOR_DELETION = 2; /** * The state of the cell as it is marked for changes. This is used internally with the enums defined above */ - private int state; + private @MenuCellState int state; /** * A lock used when setting / getting states @@ -137,6 +146,8 @@ public class MenuCell { // SETTERS / GETTERS + // PUBLIC METHODS + /** * Sets the title of the menu cell * @param title - the title of the cell. Required @@ -217,9 +228,10 @@ public class MenuCell { return menuSelectionListener; } + // INTERNALLY USED METHODS + /** * Set the cell Id. - * * NOTE: THIS IS USED INTERNALLY ONLY, PLEASE DO NOT SET * @param cellId - the cell Id */ void setCellId(int cellId) { @@ -236,7 +248,6 @@ public class MenuCell { /** * Sets the ParentCellId - * NOTE: THIS IS USED INTERNALLY ONLY, PLEASE DO NOT SET * @param parentCellId the parent cell's Id */ void setParentCellId(int parentCellId) { @@ -255,7 +266,7 @@ public class MenuCell { * Sets whether or not the state of the cell is marked for addition or deletion * @param state - the state enum */ - void setState(int state){ + void setState(@MenuCellState int state){ synchronized (STATE_LOCK) { this.state = state; } @@ -265,7 +276,7 @@ public class MenuCell { * Read the state of the cell * @return Whether or not the cell is marked for addition or deletion */ - int getState() { + @MenuCellState int getState() { synchronized (STATE_LOCK) { return this.state; } @@ -292,7 +303,6 @@ public class MenuCell { return result; } - /** * Uses our custom hashCode for MenuCell objects, but does NOT compare the listener objects * @param o - The object to compare -- cgit v1.2.1 From 27a97b1363e7bc6170874cbcacd9083aaf3d2c67 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Mon, 13 May 2019 13:10:09 -0400 Subject: update enum --- .../java/com/smartdevicelink/managers/screen/menu/MenuCell.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java index 948052619..a7b35d2dd 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java @@ -88,10 +88,10 @@ public class MenuCell { * State enums used internally for dynamic updating * These should be used to set the 'state' variable */ - @IntDef({NOT_SET, MARKED_FOR_ADDITION, MARKED_FOR_DELETION}) + @IntDef({KEEP, MARKED_FOR_ADDITION, MARKED_FOR_DELETION}) @Retention(RetentionPolicy.SOURCE) @interface MenuCellState {} - static final int NOT_SET = 0; + static final int KEEP = 0; static final int MARKED_FOR_ADDITION = 1; static final int MARKED_FOR_DELETION = 2; @@ -123,7 +123,7 @@ public class MenuCell { setMenuSelectionListener(listener); setCellId(MAX_ID); setParentCellId(MAX_ID); - setState(NOT_SET); + setState(KEEP); } // CONSTRUCTOR FOR CELL THAT WILL LINK TO SUB MENU @@ -141,7 +141,7 @@ public class MenuCell { setSubCells(subCells); setCellId(MAX_ID); setParentCellId(MAX_ID); - setState(NOT_SET); + setState(KEEP); } // SETTERS / GETTERS -- cgit v1.2.1 From 104ed312a66998be73d523e68a6898ff7fbfcfcf Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Mon, 13 May 2019 16:48:40 -0400 Subject: checkpoint for steps 1 & 2 of algo --- .../managers/screen/menu/BaseMenuManager.java | 68 ++++++++++++++++++++++ .../managers/screen/menu/MenuCell.java | 22 +++---- 2 files changed, 79 insertions(+), 11 deletions(-) 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 5cf84bf74..69ab3c196 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 @@ -33,6 +33,7 @@ package com.smartdevicelink.managers.screen.menu; import android.support.annotation.NonNull; +import android.util.Log; import com.smartdevicelink.managers.BaseSubManager; import com.smartdevicelink.managers.CompletionListener; @@ -70,6 +71,7 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Objects; abstract class BaseMenuManager extends BaseSubManager { @@ -176,6 +178,7 @@ abstract class BaseMenuManager extends BaseSubManager { DebugTool.logError("Attempted to create a menu with duplicate voice commands. Voice commands must be unique. The menu will not be set"); return; } + // Set the IDs lastMenuId = menuCellIdMin; updateIdsOnMenuCells(menuCells, parentIdNotFound); @@ -228,6 +231,14 @@ abstract class BaseMenuManager extends BaseSubManager { return; } + // not sure if these will stay here + // update states + markOldCellsForDeletion(); + markNewCellsForAddition(); + + // compare the lists + compareOldAndNewLists(); + deleteCurrentMenu(new CompletionListener() { @Override public void onComplete(boolean success) { @@ -394,6 +405,63 @@ abstract class BaseMenuManager extends BaseSubManager { // OTHER HELPER METHODS: + // COMPARISONS + + private void markOldCellsForDeletion(){ + if (oldMenuCells != null && oldMenuCells.size() > 0){ + for (MenuCell cell : oldMenuCells){ + cell.setState(MenuCell.MARKED_FOR_DELETION); + } + } + } + + private void markNewCellsForAddition(){ + if (menuCells != null && menuCells.size() > 0){ + for (MenuCell cell : menuCells){ + cell.setState(MenuCell.MARKED_FOR_ADDITION); + } + } + } + + private void compareOldAndNewLists(){ + + if (oldMenuCells != null && oldMenuCells.size() > 0 && menuCells != null && menuCells.size() > 0) { + for (int i = 0; i < oldMenuCells.size(); i++) { + MenuCell oldCell = oldMenuCells.get(i); + for (int z = 0; z < menuCells.size(); z++) { + MenuCell cell = menuCells.get(z); + // We need to make sure position in the list is the same and that the cell itself is the same + // if so, remove the need to mark for addition or deletion + if (i == z && cell.equals(oldCell)){ + oldCell.setState(MenuCell.KEEP); + cell.setState(MenuCell.KEEP); + + // TODO: verify this listener logic + if (oldCell.getMenuSelectionListener() != null && cell.getMenuSelectionListener() != null){ + // If the new cell is the same based on our equality function, but we aren't updating, and the listeners are different + // swap them for the developer so they can keep getting their triggers. + if (oldCell.getMenuSelectionListener() != cell.getMenuSelectionListener()){ + cell.setMenuSelectionListener(oldCell.getMenuSelectionListener()); + } + } + } + + } + } + printCellStates(); + } + } + + private void printCellStates(){ + for (int i = 0; i < oldMenuCells.size(); i++) { + Log.i("Old MENU Cell: ", "Position: "+ i + " State: "+ oldMenuCells.get(i).getState()); + } + + for (int i = 0; i < menuCells.size(); i++) { + Log.i("New MENU Cell: ", "Position: "+ i + " State: "+ menuCells.get(i).getState()); + } + } + // ARTWORKS private List findAllArtworksToBeUploadedFromCells(List cells){ diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java index a7b35d2dd..8ead2ee8a 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java @@ -44,6 +44,17 @@ import java.util.List; public class MenuCell { + /** + * State enums used internally for dynamic updating + * These should be used to set the 'state' variable + */ + @IntDef({KEEP, MARKED_FOR_ADDITION, MARKED_FOR_DELETION}) + @Retention(RetentionPolicy.SOURCE) + @interface MenuCellState {} + static final int KEEP = 0; + static final int MARKED_FOR_ADDITION = 1; + static final int MARKED_FOR_DELETION = 2; + /** * The cell's text to be displayed */ @@ -84,17 +95,6 @@ public class MenuCell { */ private static final int MAX_ID = 2000000000; - /** - * State enums used internally for dynamic updating - * These should be used to set the 'state' variable - */ - @IntDef({KEEP, MARKED_FOR_ADDITION, MARKED_FOR_DELETION}) - @Retention(RetentionPolicy.SOURCE) - @interface MenuCellState {} - static final int KEEP = 0; - static final int MARKED_FOR_ADDITION = 1; - static final int MARKED_FOR_DELETION = 2; - /** * The state of the cell as it is marked for changes. This is used internally with the enums defined above */ -- cgit v1.2.1 From 93ddee8169f56fcaaca75769cb81fefe161606d9 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Tue, 14 May 2019 14:31:48 -0400 Subject: start of redo --- .../managers/screen/menu/BaseMenuManager.java | 68 +++++---------------- .../managers/screen/menu/MenuCell.java | 52 +++------------- .../managers/screen/menu/RunScore.java | 71 ++++++++++++++++++++++ 3 files changed, 95 insertions(+), 96 deletions(-) create mode 100644 base/src/main/java/com/smartdevicelink/managers/screen/menu/RunScore.java 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 69ab3c196..bb8c00285 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 @@ -32,6 +32,7 @@ package com.smartdevicelink.managers.screen.menu; +import android.support.annotation.IntDef; import android.support.annotation.NonNull; import android.util.Log; @@ -66,6 +67,8 @@ import com.smartdevicelink.util.DebugTool; import org.json.JSONException; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.HashSet; @@ -75,6 +78,17 @@ import java.util.Objects; abstract class BaseMenuManager extends BaseSubManager { + /** + * State enums used internally for dynamic updating + * These should be used to set the 'state' variable + */ + @IntDef({KEEP, MARKED_FOR_ADDITION, MARKED_FOR_DELETION}) + @Retention(RetentionPolicy.SOURCE) + @interface MenuCellState {} + static final int KEEP = 0; + static final int MARKED_FOR_ADDITION = 1; + static final int MARKED_FOR_DELETION = 2; + private final WeakReference fileManager; List menuCells, waitingUpdateMenuCells, oldMenuCells; @@ -231,11 +245,6 @@ abstract class BaseMenuManager extends BaseSubManager { return; } - // not sure if these will stay here - // update states - markOldCellsForDeletion(); - markNewCellsForAddition(); - // compare the lists compareOldAndNewLists(); @@ -407,60 +416,11 @@ abstract class BaseMenuManager extends BaseSubManager { // COMPARISONS - private void markOldCellsForDeletion(){ - if (oldMenuCells != null && oldMenuCells.size() > 0){ - for (MenuCell cell : oldMenuCells){ - cell.setState(MenuCell.MARKED_FOR_DELETION); - } - } - } - - private void markNewCellsForAddition(){ - if (menuCells != null && menuCells.size() > 0){ - for (MenuCell cell : menuCells){ - cell.setState(MenuCell.MARKED_FOR_ADDITION); - } - } - } - private void compareOldAndNewLists(){ - if (oldMenuCells != null && oldMenuCells.size() > 0 && menuCells != null && menuCells.size() > 0) { - for (int i = 0; i < oldMenuCells.size(); i++) { - MenuCell oldCell = oldMenuCells.get(i); - for (int z = 0; z < menuCells.size(); z++) { - MenuCell cell = menuCells.get(z); - // We need to make sure position in the list is the same and that the cell itself is the same - // if so, remove the need to mark for addition or deletion - if (i == z && cell.equals(oldCell)){ - oldCell.setState(MenuCell.KEEP); - cell.setState(MenuCell.KEEP); - - // TODO: verify this listener logic - if (oldCell.getMenuSelectionListener() != null && cell.getMenuSelectionListener() != null){ - // If the new cell is the same based on our equality function, but we aren't updating, and the listeners are different - // swap them for the developer so they can keep getting their triggers. - if (oldCell.getMenuSelectionListener() != cell.getMenuSelectionListener()){ - cell.setMenuSelectionListener(oldCell.getMenuSelectionListener()); - } - } - } - } - } - printCellStates(); - } } - private void printCellStates(){ - for (int i = 0; i < oldMenuCells.size(); i++) { - Log.i("Old MENU Cell: ", "Position: "+ i + " State: "+ oldMenuCells.get(i).getState()); - } - - for (int i = 0; i < menuCells.size(); i++) { - Log.i("New MENU Cell: ", "Position: "+ i + " State: "+ menuCells.get(i).getState()); - } - } // ARTWORKS diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java index 8ead2ee8a..03138c0ec 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java @@ -32,29 +32,15 @@ package com.smartdevicelink.managers.screen.menu; -import android.support.annotation.IntDef; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.smartdevicelink.managers.file.filetypes.SdlArtwork; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; import java.util.List; public class MenuCell { - /** - * State enums used internally for dynamic updating - * These should be used to set the 'state' variable - */ - @IntDef({KEEP, MARKED_FOR_ADDITION, MARKED_FOR_DELETION}) - @Retention(RetentionPolicy.SOURCE) - @interface MenuCellState {} - static final int KEEP = 0; - static final int MARKED_FOR_ADDITION = 1; - static final int MARKED_FOR_DELETION = 2; - /** * The cell's text to be displayed */ @@ -95,11 +81,6 @@ public class MenuCell { */ private static final int MAX_ID = 2000000000; - /** - * The state of the cell as it is marked for changes. This is used internally with the enums defined above - */ - private @MenuCellState int state; - /** * A lock used when setting / getting states */ @@ -123,7 +104,6 @@ public class MenuCell { setMenuSelectionListener(listener); setCellId(MAX_ID); setParentCellId(MAX_ID); - setState(KEEP); } // CONSTRUCTOR FOR CELL THAT WILL LINK TO SUB MENU @@ -141,7 +121,6 @@ public class MenuCell { setSubCells(subCells); setCellId(MAX_ID); setParentCellId(MAX_ID); - setState(KEEP); } // SETTERS / GETTERS @@ -262,26 +241,6 @@ public class MenuCell { return parentCellId; } - /** - * Sets whether or not the state of the cell is marked for addition or deletion - * @param state - the state enum - */ - void setState(@MenuCellState int state){ - synchronized (STATE_LOCK) { - this.state = state; - } - } - - /** - * Read the state of the cell - * @return Whether or not the cell is marked for addition or deletion - */ - @MenuCellState int getState() { - synchronized (STATE_LOCK) { - return this.state; - } - } - // HELPER /** @@ -299,7 +258,6 @@ public class MenuCell { result += ((getTitle() == null) ? 0 : Integer.rotateLeft(getTitle().hashCode(), 1)); result += ((getIcon() == null || getIcon().getName() == null) ? 0 : Integer.rotateLeft(getIcon().getName().hashCode(), 2)); result += ((getVoiceCommands() == null) ? 0 : Integer.rotateLeft(getVoiceCommands().hashCode(), 3)); - result += ((getSubCells() == null) ? 0 : Integer.rotateLeft(getSubCells().hashCode(), 4)); return result; } @@ -310,9 +268,19 @@ public class MenuCell { */ @Override public boolean equals(Object o) { + // if this is the same memory address, its the same if (this == o) return true; + // if this is not an instance of this class, not the same if (!(o instanceof MenuCell)) return false; + MenuCell menuCell = (MenuCell) o; + // check if one has sub-cells and if one doesnt, if so they are not equal + if (menuCell.getSubCells() != null && getSubCells() != null){ + if (menuCell.getSubCells() != getSubCells()){ + return false; + } + } + // if we get to this point, create the hashes and compare them return hashCode() == menuCell.hashCode(); } } diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/RunScore.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/RunScore.java new file mode 100644 index 000000000..393515870 --- /dev/null +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/RunScore.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +package com.smartdevicelink.managers.screen.menu; + +import java.util.List; + +class RunScore { + + private int score; + private List oldMenu, currentMenu; + + RunScore(int score, List oldMenu, List currentMenu){ + setScore(score); + setOldMenu(oldMenu); + setCurrentMenu(currentMenu); + } + + private void setCurrentMenu(List currentMenu) { + this.currentMenu = currentMenu; + } + + List getCurrentMenu() { + return currentMenu; + } + + private void setOldMenu(List oldMenu) { + this.oldMenu = oldMenu; + } + + List getOldMenu() { + return oldMenu; + } + + private void setScore(int score) { + this.score = score; + } + + public int getScore() { + return score; + } +} -- cgit v1.2.1 From 19c52a6e516dd51ce91ae8e324d9f72becf8e088 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Tue, 14 May 2019 16:37:16 -0400 Subject: base algo works :) on to sub-cells --- .../managers/screen/menu/BaseMenuManager.java | 67 +++++++++++++++++++++- 1 file changed, 65 insertions(+), 2 deletions(-) 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 bb8c00285..192ff7d1a 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 @@ -246,7 +246,7 @@ abstract class BaseMenuManager extends BaseSubManager { } // compare the lists - compareOldAndNewLists(); + compareOldAndNewLists(oldMenuCells, menuCells); deleteCurrentMenu(new CompletionListener() { @Override @@ -416,11 +416,74 @@ abstract class BaseMenuManager extends BaseSubManager { // COMPARISONS - private void compareOldAndNewLists(){ + private void compareOldAndNewLists(List oldCells, List newCells){ + if (oldCells == null || oldCells.size() == 0 || oldCells.equals(newCells)){ + // we don't need to be here as its the initial add, return + return; + } + + RunScore bestRunScore = null; + + // This first loop is for each 'run' + for (int run = 0; run < oldCells.size(); run++) { + + List oldArray = new ArrayList<>(oldCells.size()); + List newArray = new ArrayList<>(newCells.size()); + + // Set the statuses + setDeleteStatus(oldCells.size(), oldArray); + setAddStatus(newCells.size(), newArray); + + int startIndex = 0; + + for (int oldItems = run; oldItems < oldCells.size(); oldItems++) { + + for (int newItems = startIndex; newItems < newCells.size(); newItems++) { + + if (oldCells.get(oldItems).equals(newCells.get(newItems))){ + oldArray.set(oldItems, KEEP); + newArray.set(newItems, KEEP); + // set the new start index + startIndex = newItems + 1; + break; + } + } + } + + // Calculate number of adds, or the 'score' for this run + int numberOfAdds = 0; + + for (int x = 0; x < newArray.size(); x++) { + + if (newArray.get(x).equals(MARKED_FOR_ADDITION)){ + numberOfAdds++; + } + } + + if (bestRunScore == null || numberOfAdds < bestRunScore.getScore()){ + bestRunScore = new RunScore(numberOfAdds, oldArray, newArray); + } + + } + + Log.i("MENU Best Run Score", String.valueOf(bestRunScore.getScore())); + Log.i("MENU Best Run OLD", bestRunScore.getOldMenu().toString()); + Log.i("MENU Best Run NEW", bestRunScore.getCurrentMenu().toString()); } + private void setDeleteStatus(Integer size, List oldArray){ + for (int i = 0; i < size; i++) { + oldArray.add(MARKED_FOR_DELETION); + } + } + + private void setAddStatus(Integer size, List newArray){ + for (int i = 0; i < size; i++) { + newArray.add(MARKED_FOR_ADDITION); + } + } // ARTWORKS -- cgit v1.2.1 From aaec37944184f7ef4aaab7f84d607d7cdac4f402 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Tue, 14 May 2019 16:58:14 -0400 Subject: check subcell equality in main cells --- .../smartdevicelink/managers/screen/menu/BaseMenuManager.java | 3 ++- .../com/smartdevicelink/managers/screen/menu/MenuCell.java | 10 ++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) 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 192ff7d1a..794d31908 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 @@ -437,6 +437,7 @@ abstract class BaseMenuManager extends BaseSubManager { int startIndex = 0; + // Keep items that appear in both lists for (int oldItems = run; oldItems < oldCells.size(); oldItems++) { for (int newItems = startIndex; newItems < newCells.size(); newItems++) { @@ -455,12 +456,12 @@ abstract class BaseMenuManager extends BaseSubManager { int numberOfAdds = 0; for (int x = 0; x < newArray.size(); x++) { - if (newArray.get(x).equals(MARKED_FOR_ADDITION)){ numberOfAdds++; } } + // see if we have a new best score and set it if we do if (bestRunScore == null || numberOfAdds < bestRunScore.getScore()){ bestRunScore = new RunScore(numberOfAdds, oldArray, newArray); } diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java index 03138c0ec..0e4d8cc8a 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java @@ -275,8 +275,14 @@ public class MenuCell { MenuCell menuCell = (MenuCell) o; // check if one has sub-cells and if one doesnt, if so they are not equal - if (menuCell.getSubCells() != null && getSubCells() != null){ - if (menuCell.getSubCells() != getSubCells()){ + if (menuCell.getSubCells() == null && getSubCells() != null){ + return false; + } else if (menuCell.getSubCells() != null && getSubCells() == null){ + return false; + } else if (menuCell.getSubCells() != null && getSubCells() != null){ + if (!menuCell.getSubCells().containsAll(getSubCells())){ + return false; + }else if (!getSubCells().containsAll(menuCell.getSubCells())){ return false; } } -- cgit v1.2.1 From 00b37ff5959cfc8f61c014e0b61129ca2a2bdef1 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Wed, 15 May 2019 15:38:22 -0400 Subject: step commit, half working --- .../managers/screen/menu/BaseMenuManager.java | 172 ++++++++++++++++++--- 1 file changed, 150 insertions(+), 22 deletions(-) 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 794d31908..9a47181ef 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 @@ -91,8 +91,8 @@ abstract class BaseMenuManager extends BaseSubManager { private final WeakReference fileManager; - List menuCells, waitingUpdateMenuCells, oldMenuCells; - List inProgressUpdate; + List menuCells, waitingUpdateMenuCells, oldMenuCells, dynamicCells; + List inProgressUpdate, deleteCommands; boolean waitingOnHMIUpdate; private boolean hasQueuedUpdate; @@ -140,6 +140,8 @@ abstract class BaseMenuManager extends BaseSubManager { hasQueuedUpdate = false; waitingOnHMIUpdate = false; waitingUpdateMenuCells = null; + deleteCommands = null; + dynamicCells = null; // remove listeners internalInterface.removeOnRPCNotificationListener(FunctionID.ON_HMI_STATUS, hmiListener); @@ -245,8 +247,8 @@ abstract class BaseMenuManager extends BaseSubManager { return; } - // compare the lists - compareOldAndNewLists(oldMenuCells, menuCells); + // run the lists through the new algorithm + createDynamicUpdate(oldMenuCells, menuCells); deleteCurrentMenu(new CompletionListener() { @Override @@ -273,7 +275,7 @@ abstract class BaseMenuManager extends BaseSubManager { // DELETE OLD MENU ITEMS private void deleteCurrentMenu(final CompletionListener listener){ - if (oldMenuCells.size() == 0) { + if (oldMenuCells != null && oldMenuCells.size() == 0) { if (listener != null){ // technically this method is successful if there's nothing to delete DebugTool.logInfo("No old cells to delete, returning"); @@ -282,8 +284,25 @@ abstract class BaseMenuManager extends BaseSubManager { return; } - List deleteCommands = deleteCommandsForCells(oldMenuCells); - if (oldMenuCells != null && oldMenuCells.size() > 0) { + if (deleteCommands == null || deleteCommands.size() == 0){ + // no dynamic deletes required. return + if (listener != null){ + // technically this method is successful if there's nothing to delete + listener.onComplete(true); + } + return; + } + + for (RPCRequest delete : deleteCommands){ + try { + Log.i("MENU CELL DELETE: ", delete.serializeJSON().toString()); + } catch (JSONException e) { + e.printStackTrace(); + } + } + + //List deleteCommands = deleteCommandsForCells(oldMenuCells); + if (oldMenuCells != null) { oldMenuCells.clear(); } internalInterface.sendRequests(deleteCommands, new OnMultipleRequestListener() { @@ -295,6 +314,7 @@ abstract class BaseMenuManager extends BaseSubManager { @Override public void onFinished() { DebugTool.logInfo("Successfully deleted all old menu commands"); + deleteCommands.clear(); if (listener != null){ listener.onComplete(true); } @@ -316,8 +336,8 @@ abstract class BaseMenuManager extends BaseSubManager { private void sendCurrentMenu(final CompletionListener listener){ - if (menuCells.size() == 0){ - DebugTool.logInfo("No main menu to send, returning"); + if (dynamicCells.size() == 0){ + DebugTool.logInfo("No updates to send, returning"); if (listener != null){ // This can be considered a success if the user was clearing out their menu listener.onComplete(true); @@ -328,20 +348,24 @@ abstract class BaseMenuManager extends BaseSubManager { List mainMenuCommands; final List subMenuCommands; - if (findAllArtworksToBeUploadedFromCells(menuCells).size() > 0 || !supportsImages()){ + for (MenuCell cell : dynamicCells){ + Log.i("MENU CELL SEND: ", cell.getTitle() + " Position: "+ cell.getCellId()); + } + + if (findAllArtworksToBeUploadedFromCells(dynamicCells).size() > 0 || !supportsImages()){ // Send artwork-less menu - mainMenuCommands = mainMenuCommandsForCells(menuCells, false); - subMenuCommands = subMenuCommandsForCells(menuCells, false); + mainMenuCommands = mainMenuCommandsForCells(dynamicCells, false); + subMenuCommands = subMenuCommandsForCells(dynamicCells, false); } else { - mainMenuCommands = mainMenuCommandsForCells(menuCells, true); - subMenuCommands = subMenuCommandsForCells(menuCells, true); + mainMenuCommands = mainMenuCommandsForCells(dynamicCells, true); + subMenuCommands = subMenuCommandsForCells(dynamicCells, true); } // add all built commands to inProgressUpdate inProgressUpdate = new ArrayList<>(mainMenuCommands); inProgressUpdate.addAll(subMenuCommands); - internalInterface.sendRequests(mainMenuCommands, new OnMultipleRequestListener() { + internalInterface.sendSequentialRPCs(mainMenuCommands, new OnMultipleRequestListener() { @Override public void onUpdate(int remainingRequests) { // nothing here @@ -351,6 +375,9 @@ abstract class BaseMenuManager extends BaseSubManager { public void onFinished() { oldMenuCells = menuCells; + // we don't need these anymore + dynamicCells.clear(); + if (subMenuCommands.size() > 0) { sendSubMenuCommands(subMenuCommands, listener); DebugTool.logInfo("Finished sending main menu commands. Sending sub menu commands."); @@ -378,7 +405,7 @@ abstract class BaseMenuManager extends BaseSubManager { } private void sendSubMenuCommands(List commands, final CompletionListener listener){ - internalInterface.sendRequests(commands, new OnMultipleRequestListener() { + internalInterface.sendSequentialRPCs(commands, new OnMultipleRequestListener() { @Override public void onUpdate(int remainingRequests) { @@ -416,13 +443,118 @@ abstract class BaseMenuManager extends BaseSubManager { // COMPARISONS - private void compareOldAndNewLists(List oldCells, List newCells){ + private void createDynamicUpdate(List oldCells, List newCells){ if (oldCells == null || oldCells.size() == 0 || oldCells.equals(newCells)){ // we don't need to be here as its the initial add, return + if (dynamicCells == null){ + dynamicCells = new ArrayList<>(newCells); + }else{ + dynamicCells.addAll(newCells); + } return; } + RunScore bestScore = compareOldAndNewLists(oldCells, newCells); + + // we need to run through the keeps and see if they have subCells, as they also need to be run + // through the compare function. Take best run score and loop through keeps. + // Currently submenus can only be one level deep + List newIntArray = bestScore.getCurrentMenu(); + List oldIntArray = bestScore.getOldMenu(); + List keepsNew = new ArrayList<>(); + List keepsOld = new ArrayList<>(); + + // Set up deletes + List deletes = new ArrayList<>(); + for (int x = 0; x < oldIntArray.size(); x++) { + Integer old = oldIntArray.get(x); + if (old.equals(MARKED_FOR_DELETION)){ + // grab cell to send to function to create delete commands + deletes.add(oldCells.get(x)); + }else if (old.equals(KEEP)){ + // we need the array of keeps to check for sub cells + keepsOld.add(oldCells.get(x)); + } + } + // create the delete commands + deleteCommands = deleteCommandsForCells(deletes); + + // Set up the adds + List adds = new ArrayList<>(); + for (int x = 0; x < newIntArray.size(); x++) { + Integer newInt = newIntArray.get(x); + if (newInt.equals(MARKED_FOR_ADDITION)){ + // grab cell to send to function to create delete commands + adds.add(newCells.get(x)); + }else if (newInt.equals(KEEP)){ + // we need the array of keeps to check for sub cells + keepsNew.add(newCells.get(x)); + } + } + // add the cells needed to added here + if (dynamicCells == null){ + dynamicCells = new ArrayList<>(adds); + }else{ + dynamicCells.addAll(adds); + } + + + // now we can check the keeps lists for sub cells + if (keepsNew.size() > 0){ + // lets see if we have any cells that contain sub-cells + for (int i = 0; i < keepsNew.size(); i++) { + + MenuCell newCell = keepsNew.get(i); + + if (newCell.getSubCells() != null && newCell.getSubCells().size() > 0){ + // This cell HAS SUB-CELLS. Get the old cell + MenuCell oldCell = keepsOld.get(i); + + List newSubCells = newCell.getSubCells(); + List oldSubCells = oldCell.getSubCells(); + + RunScore subCellScore = compareOldAndNewLists(oldSubCells, newSubCells); + + // Grab the responses so that we can create the add / delete commands + List subCellNewArray = subCellScore.getCurrentMenu(); + List subCellOldArray = subCellScore.getOldMenu(); + + // Set up deletes + List subDeletes = new ArrayList<>(); + for (int x = 0; x < subCellOldArray.size(); x++) { + Integer old = subCellOldArray.get(x); + if (old.equals(MARKED_FOR_DELETION)){ + // grab cell to send to function to create delete commands + subDeletes.add(oldCells.get(x)); + } + } + // create the delete commands and append to previous delete list + deleteCommands.addAll(deleteCommandsForCells(subDeletes)); + + // Set up the adds + List subAdds = new ArrayList<>(); + for (int x = 0; x < subCellNewArray.size(); x++) { + Integer newInt = subCellNewArray.get(x); + if (newInt.equals(MARKED_FOR_ADDITION)){ + // grab cell to send to function to create delete commands + subAdds.add(newCells.get(x)); + } + } + // add subs to the list + dynamicCells.addAll(subAdds); + } + } + } + } + + private RunScore compareOldAndNewLists(List oldCells, List newCells){ + + if (oldCells == null || oldCells.size() == 0 || oldCells.equals(newCells)){ + // we don't need to be here as its the initial add, return + return null; + } + RunScore bestRunScore = null; // This first loop is for each 'run' @@ -467,11 +599,7 @@ abstract class BaseMenuManager extends BaseSubManager { } } - - Log.i("MENU Best Run Score", String.valueOf(bestRunScore.getScore())); - Log.i("MENU Best Run OLD", bestRunScore.getOldMenu().toString()); - Log.i("MENU Best Run NEW", bestRunScore.getCurrentMenu().toString()); - + return bestRunScore; } private void setDeleteStatus(Integer size, List oldArray){ -- cgit v1.2.1 From 026ca4258d63ff847840f88905a7254476837c51 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Wed, 15 May 2019 16:25:34 -0400 Subject: main menu positioning right, not showing on TDK --- .../managers/screen/menu/BaseMenuManager.java | 30 ++++++++++++++++------ 1 file changed, 22 insertions(+), 8 deletions(-) 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 9a47181ef..d29c4d10c 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 @@ -349,7 +349,7 @@ abstract class BaseMenuManager extends BaseSubManager { final List subMenuCommands; for (MenuCell cell : dynamicCells){ - Log.i("MENU CELL SEND: ", cell.getTitle() + " Position: "+ cell.getCellId()); + Log.i("MENU CELL SEND: ", cell.getTitle() ); } if (findAllArtworksToBeUploadedFromCells(dynamicCells).size() > 0 || !supportsImages()){ @@ -361,6 +361,14 @@ abstract class BaseMenuManager extends BaseSubManager { subMenuCommands = subMenuCommandsForCells(dynamicCells, true); } + for (RPCRequest request : mainMenuCommands){ + try { + Log.i("MENU ADD COMMAND: ", request.serializeJSON().toString()); + } catch (JSONException e) { + e.printStackTrace(); + } + } + // add all built commands to inProgressUpdate inProgressUpdate = new ArrayList<>(mainMenuCommands); inProgressUpdate.addAll(subMenuCommands); @@ -685,16 +693,22 @@ abstract class BaseMenuManager extends BaseSubManager { // COMMANDS / SUBMENU RPCs - private List mainMenuCommandsForCells(List cells, boolean shouldHaveArtwork) { + private List mainMenuCommandsForCells(List cellsToAdd, boolean shouldHaveArtwork) { List builtCommands = new ArrayList<>(); // We need the index so we will use this type of loop - for (int i = 0; i < cells.size(); i++) { - MenuCell cell = cells.get(i); - if (cell.getSubCells() != null && cell.getSubCells().size() > 0){ - builtCommands.add(subMenuCommandForMenuCell(cell, shouldHaveArtwork, i)); - }else{ - builtCommands.add(commandForMenuCell(cell, shouldHaveArtwork, i)); + for (int z = 0; z < menuCells.size(); z++) { + MenuCell mainCell = menuCells.get(z); + for (int i = 0; i < cellsToAdd.size(); i++) { + MenuCell addCell = cellsToAdd.get(i); + if (mainCell.equals(addCell)) { + Log.i("MENU CELL ADD", "NAME: "+ addCell.getTitle()+ " POSITION: "+ z); + if (addCell.getSubCells() != null && addCell.getSubCells().size() > 0) { + builtCommands.add(subMenuCommandForMenuCell(addCell, shouldHaveArtwork, z)); + } else { + builtCommands.add(commandForMenuCell(addCell, shouldHaveArtwork, z)); + } + } } } return builtCommands; -- cgit v1.2.1 From 578bc70e8b0f3dff730fe37841490e8d33a41c65 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Thu, 16 May 2019 10:52:12 -0400 Subject: dynamic cell update ordering works --- .../managers/screen/menu/BaseMenuManager.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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 d29c4d10c..5aa879705 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 @@ -397,7 +397,7 @@ abstract class BaseMenuManager extends BaseSubManager { @Override public void onError(int correlationId, Result resultCode, String info) { - + DebugTool.logError("Result: "+ resultCode.toString() + " Info: "+ info); } @Override @@ -465,6 +465,10 @@ abstract class BaseMenuManager extends BaseSubManager { RunScore bestScore = compareOldAndNewLists(oldCells, newCells); + Log.i("MENU Best Run Score", String.valueOf(bestScore.getScore())); + Log.i("MENU Best Run OLD", bestScore.getOldMenu().toString()); + Log.i("MENU Best Run NEW", bestScore.getCurrentMenu().toString()); + // we need to run through the keeps and see if they have subCells, as they also need to be run // through the compare function. Take best run score and loop through keeps. // Currently submenus can only be one level deep @@ -554,6 +558,8 @@ abstract class BaseMenuManager extends BaseSubManager { } } } + // update the cell IDs so we don't have any ID collisions + updateIdsOnDynamicCells(); } private RunScore compareOldAndNewLists(List oldCells, List newCells){ @@ -665,6 +671,14 @@ abstract class BaseMenuManager extends BaseSubManager { // IDs + private void updateIdsOnDynamicCells(){ + if (dynamicCells != null && dynamicCells.size() > 0) { + for (MenuCell cell : dynamicCells) { + cell.setCellId(++lastMenuId); + } + } + } + private void updateIdsOnMenuCells(List cells, int parentId){ for (MenuCell cell : cells){ cell.setCellId(++lastMenuId); -- cgit v1.2.1 From f85e9c2058735792962b2359055be08aa6df6b1d Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Thu, 16 May 2019 11:31:25 -0400 Subject: send sub menu update works --- .../managers/screen/menu/BaseMenuManager.java | 34 +++++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) 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 5aa879705..e4d74b88f 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 @@ -413,6 +413,15 @@ abstract class BaseMenuManager extends BaseSubManager { } private void sendSubMenuCommands(List commands, final CompletionListener listener){ + + for (RPCRequest command : commands){ + try { + Log.i("MENU SUB COMMAND", command.serializeJSON().toString()); + } catch (JSONException e) { + e.printStackTrace(); + } + } + internalInterface.sendSequentialRPCs(commands, new OnMultipleRequestListener() { @Override public void onUpdate(int remainingRequests) { @@ -511,7 +520,6 @@ abstract class BaseMenuManager extends BaseSubManager { dynamicCells.addAll(adds); } - // now we can check the keeps lists for sub cells if (keepsNew.size() > 0){ // lets see if we have any cells that contain sub-cells @@ -612,6 +620,11 @@ abstract class BaseMenuManager extends BaseSubManager { bestRunScore = new RunScore(numberOfAdds, oldArray, newArray); } + // if we have a case where we only need to add ONE, that's the best we can get + // same some computing and break out NOW + if (numberOfAdds == 1){ + break; + } } return bestRunScore; } @@ -672,9 +685,22 @@ abstract class BaseMenuManager extends BaseSubManager { // IDs private void updateIdsOnDynamicCells(){ - if (dynamicCells != null && dynamicCells.size() > 0) { - for (MenuCell cell : dynamicCells) { - cell.setCellId(++lastMenuId); + if (menuCells != null && menuCells.size() > 0 && dynamicCells != null && dynamicCells.size() > 0) { + for (int z = 0; z < menuCells.size(); z++) { + MenuCell mainCell = menuCells.get(z); + for (int i = 0; i < dynamicCells.size(); i++) { + MenuCell dynamicCell = dynamicCells.get(i); + if (mainCell.equals(dynamicCell)){ + int newId = ++ lastMenuId; + menuCells.get(z).setCellId(newId); + dynamicCells.get(i).setCellId(newId); + + // now we have to update our sub cells to use our new parent ID + if (dynamicCell.getSubCells() != null && dynamicCell.getSubCells().size() > 0){ + updateIdsOnMenuCells(dynamicCell.getSubCells(), newId); + } + } + } } } } -- cgit v1.2.1 From 2eb09fdb21164e70826f3cb929429a8d2c5ba135 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Fri, 17 May 2019 09:04:41 -0400 Subject: Revert "send sub menu update works" This reverts commit f85e9c2058735792962b2359055be08aa6df6b1d. --- .../managers/screen/menu/BaseMenuManager.java | 34 +++------------------- 1 file changed, 4 insertions(+), 30 deletions(-) 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 e4d74b88f..5aa879705 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 @@ -413,15 +413,6 @@ abstract class BaseMenuManager extends BaseSubManager { } private void sendSubMenuCommands(List commands, final CompletionListener listener){ - - for (RPCRequest command : commands){ - try { - Log.i("MENU SUB COMMAND", command.serializeJSON().toString()); - } catch (JSONException e) { - e.printStackTrace(); - } - } - internalInterface.sendSequentialRPCs(commands, new OnMultipleRequestListener() { @Override public void onUpdate(int remainingRequests) { @@ -520,6 +511,7 @@ abstract class BaseMenuManager extends BaseSubManager { dynamicCells.addAll(adds); } + // now we can check the keeps lists for sub cells if (keepsNew.size() > 0){ // lets see if we have any cells that contain sub-cells @@ -620,11 +612,6 @@ abstract class BaseMenuManager extends BaseSubManager { bestRunScore = new RunScore(numberOfAdds, oldArray, newArray); } - // if we have a case where we only need to add ONE, that's the best we can get - // same some computing and break out NOW - if (numberOfAdds == 1){ - break; - } } return bestRunScore; } @@ -685,22 +672,9 @@ abstract class BaseMenuManager extends BaseSubManager { // IDs private void updateIdsOnDynamicCells(){ - if (menuCells != null && menuCells.size() > 0 && dynamicCells != null && dynamicCells.size() > 0) { - for (int z = 0; z < menuCells.size(); z++) { - MenuCell mainCell = menuCells.get(z); - for (int i = 0; i < dynamicCells.size(); i++) { - MenuCell dynamicCell = dynamicCells.get(i); - if (mainCell.equals(dynamicCell)){ - int newId = ++ lastMenuId; - menuCells.get(z).setCellId(newId); - dynamicCells.get(i).setCellId(newId); - - // now we have to update our sub cells to use our new parent ID - if (dynamicCell.getSubCells() != null && dynamicCell.getSubCells().size() > 0){ - updateIdsOnMenuCells(dynamicCell.getSubCells(), newId); - } - } - } + if (dynamicCells != null && dynamicCells.size() > 0) { + for (MenuCell cell : dynamicCells) { + cell.setCellId(++lastMenuId); } } } -- cgit v1.2.1 From 2580acdbe55cf556e6e410f577108404c2cb2888 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Fri, 17 May 2019 10:37:29 -0400 Subject: case 1 works for sub cells --- .../managers/screen/menu/BaseMenuManager.java | 144 ++++++++++++++------- .../managers/screen/menu/MenuCell.java | 12 -- 2 files changed, 99 insertions(+), 57 deletions(-) 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 5aa879705..ed7ea5026 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 @@ -95,7 +95,7 @@ abstract class BaseMenuManager extends BaseSubManager { List inProgressUpdate, deleteCommands; boolean waitingOnHMIUpdate; - private boolean hasQueuedUpdate; + private boolean hasQueuedUpdate, firstMenu; HMILevel currentHMILevel; OnRPCNotificationListener hmiListener, commandListener; @@ -118,6 +118,7 @@ abstract class BaseMenuManager extends BaseSubManager { currentSystemContext = SystemContext.SYSCTXT_MAIN; currentHMILevel = HMILevel.HMI_NONE; lastMenuId = menuCellIdMin; + firstMenu = true; addListeners(); } @@ -142,6 +143,7 @@ abstract class BaseMenuManager extends BaseSubManager { waitingUpdateMenuCells = null; deleteCommands = null; dynamicCells = null; + firstMenu = true; // remove listeners internalInterface.removeOnRPCNotificationListener(FunctionID.ON_HMI_STATUS, hmiListener); @@ -349,7 +351,7 @@ abstract class BaseMenuManager extends BaseSubManager { final List subMenuCommands; for (MenuCell cell : dynamicCells){ - Log.i("MENU CELL SEND: ", cell.getTitle() ); + Log.i("MENU CELL SEND: ", cell.getTitle()+ " ID: "+ cell.getCellId() + " PARENT ID: "+ cell.getParentCellId()); } if (findAllArtworksToBeUploadedFromCells(dynamicCells).size() > 0 || !supportsImages()){ @@ -369,46 +371,58 @@ abstract class BaseMenuManager extends BaseSubManager { } } + for (RPCRequest request : subMenuCommands){ + try { + Log.i("MENU SUB COMMAND: ", request.serializeJSON().toString()); + } catch (JSONException e) { + e.printStackTrace(); + } + } + // add all built commands to inProgressUpdate inProgressUpdate = new ArrayList<>(mainMenuCommands); inProgressUpdate.addAll(subMenuCommands); - internalInterface.sendSequentialRPCs(mainMenuCommands, new OnMultipleRequestListener() { - @Override - public void onUpdate(int remainingRequests) { - // nothing here - } + if (mainMenuCommands.size() > 0) { + internalInterface.sendSequentialRPCs(mainMenuCommands, new OnMultipleRequestListener() { + @Override + public void onUpdate(int remainingRequests) { + // nothing here + } - @Override - public void onFinished() { + @Override + public void onFinished() { - oldMenuCells = menuCells; - // we don't need these anymore - dynamicCells.clear(); + oldMenuCells = menuCells; + // we don't need these anymore + dynamicCells.clear(); - if (subMenuCommands.size() > 0) { - sendSubMenuCommands(subMenuCommands, listener); - DebugTool.logInfo("Finished sending main menu commands. Sending sub menu commands."); - }else{ - inProgressUpdate = null; - DebugTool.logInfo("Finished sending main menu commands."); + if (subMenuCommands.size() > 0) { + sendSubMenuCommands(subMenuCommands, listener); + DebugTool.logInfo("Finished sending main menu commands. Sending sub menu commands."); + } else { + inProgressUpdate = null; + DebugTool.logInfo("Finished sending main menu commands."); + } } - } - @Override - public void onError(int correlationId, Result resultCode, String info) { - DebugTool.logError("Result: "+ resultCode.toString() + " Info: "+ info); - } + @Override + public void onError(int correlationId, Result resultCode, String info) { + DebugTool.logError("Result: " + resultCode.toString() + " Info: " + info); + } - @Override - public void onResponse(int correlationId, RPCResponse response) { - try { - DebugTool.logInfo("Main Menu response: "+ response.serializeJSON().toString()); - } catch (JSONException e) { - e.printStackTrace(); + @Override + public void onResponse(int correlationId, RPCResponse response) { + try { + DebugTool.logInfo("Main Menu response: " + response.serializeJSON().toString()); + } catch (JSONException e) { + e.printStackTrace(); + } } - } - }); + }); + }else{ + sendSubMenuCommands(subMenuCommands, null); + } } @@ -451,15 +465,27 @@ abstract class BaseMenuManager extends BaseSubManager { // COMPARISONS + private static boolean cmp( List l1, List l2 ) { + // make a copy of the list so the original list is not changed, and remove() is supported + ArrayList cp = new ArrayList<>( l1 ); + for ( Object o : l2 ) { + if ( !cp.remove( o ) ) { + return false; + } + } + return cp.isEmpty(); + } + private void createDynamicUpdate(List oldCells, List newCells){ - if (oldCells == null || oldCells.size() == 0 || oldCells.equals(newCells)){ - // we don't need to be here as its the initial add, return + if (firstMenu){ + // This is the first menu we are sending, just get it out if (dynamicCells == null){ dynamicCells = new ArrayList<>(newCells); }else{ dynamicCells.addAll(newCells); } + firstMenu = false; return; } @@ -518,16 +544,24 @@ abstract class BaseMenuManager extends BaseSubManager { for (int i = 0; i < keepsNew.size(); i++) { MenuCell newCell = keepsNew.get(i); - + Log.i("MENU", "KEEP: "+newCell.getTitle()); if (newCell.getSubCells() != null && newCell.getSubCells().size() > 0){ // This cell HAS SUB-CELLS. Get the old cell MenuCell oldCell = keepsOld.get(i); - + Log.i("MENU", "MATCHING SUB CELLS"); List newSubCells = newCell.getSubCells(); List oldSubCells = oldCell.getSubCells(); RunScore subCellScore = compareOldAndNewLists(oldSubCells, newSubCells); + if (subCellScore == null){ + return; + } + + Log.i("MENU SUB Run Score", String.valueOf(subCellScore.getScore())); + Log.i("MENU SUB Run OLD", subCellScore.getOldMenu().toString()); + Log.i("MENU SUB Run NEW", subCellScore.getCurrentMenu().toString()); + // Grab the responses so that we can create the add / delete commands List subCellNewArray = subCellScore.getCurrentMenu(); List subCellOldArray = subCellScore.getOldMenu(); @@ -538,7 +572,7 @@ abstract class BaseMenuManager extends BaseSubManager { Integer old = subCellOldArray.get(x); if (old.equals(MARKED_FOR_DELETION)){ // grab cell to send to function to create delete commands - subDeletes.add(oldCells.get(x)); + subDeletes.add(oldSubCells.get(x)); } } // create the delete commands and append to previous delete list @@ -550,11 +584,15 @@ abstract class BaseMenuManager extends BaseSubManager { Integer newInt = subCellNewArray.get(x); if (newInt.equals(MARKED_FOR_ADDITION)){ // grab cell to send to function to create delete commands - subAdds.add(newCells.get(x)); + subAdds.add(newSubCells.get(x)); } } + for (MenuCell cell : subAdds){ + Log.i("SUB MENU CELL ADD ", cell.getTitle()); + } // add subs to the list dynamicCells.addAll(subAdds); + menuCells.addAll(subAdds); } } } @@ -564,11 +602,6 @@ abstract class BaseMenuManager extends BaseSubManager { private RunScore compareOldAndNewLists(List oldCells, List newCells){ - if (oldCells == null || oldCells.size() == 0 || oldCells.equals(newCells)){ - // we don't need to be here as its the initial add, return - return null; - } - RunScore bestRunScore = null; // This first loop is for each 'run' @@ -672,9 +705,22 @@ abstract class BaseMenuManager extends BaseSubManager { // IDs private void updateIdsOnDynamicCells(){ - if (dynamicCells != null && dynamicCells.size() > 0) { - for (MenuCell cell : dynamicCells) { - cell.setCellId(++lastMenuId); + if (menuCells != null && menuCells.size() > 0 && dynamicCells != null && dynamicCells.size() > 0) { + for (int z = 0; z < menuCells.size(); z++) { + MenuCell mainCell = menuCells.get(z); + for (int i = 0; i < dynamicCells.size(); i++) { + MenuCell dynamicCell = dynamicCells.get(i); + if (mainCell.equals(dynamicCell)) { + int newId = ++lastMenuId; + menuCells.get(z).setCellId(newId); + dynamicCells.get(i).setCellId(newId); + + // now we have to update our sub cells to use our new parent ID + if (dynamicCell.getSubCells() != null && dynamicCell.getSubCells().size() > 0) { + updateIdsOnMenuCells(dynamicCell.getSubCells(), newId); + } + } + } } } } @@ -710,6 +756,14 @@ abstract class BaseMenuManager extends BaseSubManager { private List mainMenuCommandsForCells(List cellsToAdd, boolean shouldHaveArtwork) { List builtCommands = new ArrayList<>(); + for (MenuCell cell : menuCells){ + Log.i("MENU CELL COMMANDMAIN: ", cell.getTitle()+ " ID: "+ cell.getCellId() + " PARENT ID: "+ cell.getParentCellId()); + } + + for (MenuCell cell : cellsToAdd){ + Log.i("MENU CELL TO ADD: ", cell.getTitle()+ " ID: "+ cell.getCellId() + " PARENT ID: "+ cell.getParentCellId()); + } + // We need the index so we will use this type of loop for (int z = 0; z < menuCells.size(); z++) { MenuCell mainCell = menuCells.get(z); diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java index 0e4d8cc8a..7fb284bed 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java @@ -274,18 +274,6 @@ public class MenuCell { if (!(o instanceof MenuCell)) return false; MenuCell menuCell = (MenuCell) o; - // check if one has sub-cells and if one doesnt, if so they are not equal - if (menuCell.getSubCells() == null && getSubCells() != null){ - return false; - } else if (menuCell.getSubCells() != null && getSubCells() == null){ - return false; - } else if (menuCell.getSubCells() != null && getSubCells() != null){ - if (!menuCell.getSubCells().containsAll(getSubCells())){ - return false; - }else if (!getSubCells().containsAll(menuCell.getSubCells())){ - return false; - } - } // if we get to this point, create the hashes and compare them return hashCode() == menuCell.hashCode(); } -- cgit v1.2.1 From 7280d27018d08ac7018aca49f9d4fcbba1ebf705 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Mon, 20 May 2019 10:55:59 -0400 Subject: resetting --- .../managers/screen/menu/BaseMenuManager.java | 200 ++++----------------- .../managers/screen/menu/MenuCell.java | 12 ++ 2 files changed, 50 insertions(+), 162 deletions(-) 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 ed7ea5026..d4960dd81 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 @@ -74,7 +74,6 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Objects; abstract class BaseMenuManager extends BaseSubManager { @@ -95,7 +94,7 @@ abstract class BaseMenuManager extends BaseSubManager { List inProgressUpdate, deleteCommands; boolean waitingOnHMIUpdate; - private boolean hasQueuedUpdate, firstMenu; + private boolean hasQueuedUpdate; HMILevel currentHMILevel; OnRPCNotificationListener hmiListener, commandListener; @@ -118,7 +117,6 @@ abstract class BaseMenuManager extends BaseSubManager { currentSystemContext = SystemContext.SYSCTXT_MAIN; currentHMILevel = HMILevel.HMI_NONE; lastMenuId = menuCellIdMin; - firstMenu = true; addListeners(); } @@ -143,7 +141,6 @@ abstract class BaseMenuManager extends BaseSubManager { waitingUpdateMenuCells = null; deleteCommands = null; dynamicCells = null; - firstMenu = true; // remove listeners internalInterface.removeOnRPCNotificationListener(FunctionID.ON_HMI_STATUS, hmiListener); @@ -170,7 +167,6 @@ abstract class BaseMenuManager extends BaseSubManager { waitingOnHMIUpdate = false; // Update our Lists - this.oldMenuCells = new ArrayList<>(menuCells != null ? menuCells : cells); menuCells = new ArrayList<>(cells); // HashSet order doesnt matter / does not allow duplicates @@ -252,6 +248,9 @@ abstract class BaseMenuManager extends BaseSubManager { // run the lists through the new algorithm createDynamicUpdate(oldMenuCells, menuCells); + // make a copy of our current cells + this.oldMenuCells = new ArrayList<>(menuCells); + deleteCurrentMenu(new CompletionListener() { @Override public void onComplete(boolean success) { @@ -339,7 +338,7 @@ abstract class BaseMenuManager extends BaseSubManager { private void sendCurrentMenu(final CompletionListener listener){ if (dynamicCells.size() == 0){ - DebugTool.logInfo("No updates to send, returning"); + if (listener != null){ // This can be considered a success if the user was clearing out their menu listener.onComplete(true); @@ -383,47 +382,42 @@ abstract class BaseMenuManager extends BaseSubManager { inProgressUpdate = new ArrayList<>(mainMenuCommands); inProgressUpdate.addAll(subMenuCommands); - if (mainMenuCommands.size() > 0) { - internalInterface.sendSequentialRPCs(mainMenuCommands, new OnMultipleRequestListener() { - @Override - public void onUpdate(int remainingRequests) { - // nothing here - } + internalInterface.sendSequentialRPCs(mainMenuCommands, new OnMultipleRequestListener() { + @Override + public void onUpdate(int remainingRequests) { + // nothing here + } - @Override - public void onFinished() { + @Override + public void onFinished() { - oldMenuCells = menuCells; - // we don't need these anymore - dynamicCells.clear(); + oldMenuCells = menuCells; + // we don't need these anymore + dynamicCells.clear(); - if (subMenuCommands.size() > 0) { - sendSubMenuCommands(subMenuCommands, listener); - DebugTool.logInfo("Finished sending main menu commands. Sending sub menu commands."); - } else { - inProgressUpdate = null; - DebugTool.logInfo("Finished sending main menu commands."); - } + if (subMenuCommands.size() > 0) { + sendSubMenuCommands(subMenuCommands, listener); + DebugTool.logInfo("Finished sending main menu commands. Sending sub menu commands."); + } else { + inProgressUpdate = null; + DebugTool.logInfo("Finished sending main menu commands."); } + } - @Override - public void onError(int correlationId, Result resultCode, String info) { - DebugTool.logError("Result: " + resultCode.toString() + " Info: " + info); - } + @Override + public void onError(int correlationId, Result resultCode, String info) { + DebugTool.logError("Result: " + resultCode.toString() + " Info: " + info); + } - @Override - public void onResponse(int correlationId, RPCResponse response) { - try { - DebugTool.logInfo("Main Menu response: " + response.serializeJSON().toString()); - } catch (JSONException e) { - e.printStackTrace(); - } + @Override + public void onResponse(int correlationId, RPCResponse response) { + try { + DebugTool.logInfo("Main Menu response: " + response.serializeJSON().toString()); + } catch (JSONException e) { + e.printStackTrace(); } - }); - }else{ - sendSubMenuCommands(subMenuCommands, null); - } - + } + }); } private void sendSubMenuCommands(List commands, final CompletionListener listener){ @@ -437,6 +431,7 @@ abstract class BaseMenuManager extends BaseSubManager { public void onFinished() { DebugTool.logInfo("Finished Updating Menu"); inProgressUpdate = null; + if (listener != null){ listener.onComplete(true); } @@ -465,27 +460,15 @@ abstract class BaseMenuManager extends BaseSubManager { // COMPARISONS - private static boolean cmp( List l1, List l2 ) { - // make a copy of the list so the original list is not changed, and remove() is supported - ArrayList cp = new ArrayList<>( l1 ); - for ( Object o : l2 ) { - if ( !cp.remove( o ) ) { - return false; - } - } - return cp.isEmpty(); - } - private void createDynamicUpdate(List oldCells, List newCells){ - if (firstMenu){ + if (oldCells == null || oldCells.size() == 0){ // This is the first menu we are sending, just get it out if (dynamicCells == null){ dynamicCells = new ArrayList<>(newCells); }else{ dynamicCells.addAll(newCells); } - firstMenu = false; return; } @@ -495,107 +478,6 @@ abstract class BaseMenuManager extends BaseSubManager { Log.i("MENU Best Run OLD", bestScore.getOldMenu().toString()); Log.i("MENU Best Run NEW", bestScore.getCurrentMenu().toString()); - // we need to run through the keeps and see if they have subCells, as they also need to be run - // through the compare function. Take best run score and loop through keeps. - // Currently submenus can only be one level deep - List newIntArray = bestScore.getCurrentMenu(); - List oldIntArray = bestScore.getOldMenu(); - List keepsNew = new ArrayList<>(); - List keepsOld = new ArrayList<>(); - - // Set up deletes - List deletes = new ArrayList<>(); - for (int x = 0; x < oldIntArray.size(); x++) { - Integer old = oldIntArray.get(x); - if (old.equals(MARKED_FOR_DELETION)){ - // grab cell to send to function to create delete commands - deletes.add(oldCells.get(x)); - }else if (old.equals(KEEP)){ - // we need the array of keeps to check for sub cells - keepsOld.add(oldCells.get(x)); - } - } - // create the delete commands - deleteCommands = deleteCommandsForCells(deletes); - - // Set up the adds - List adds = new ArrayList<>(); - for (int x = 0; x < newIntArray.size(); x++) { - Integer newInt = newIntArray.get(x); - if (newInt.equals(MARKED_FOR_ADDITION)){ - // grab cell to send to function to create delete commands - adds.add(newCells.get(x)); - }else if (newInt.equals(KEEP)){ - // we need the array of keeps to check for sub cells - keepsNew.add(newCells.get(x)); - } - } - // add the cells needed to added here - if (dynamicCells == null){ - dynamicCells = new ArrayList<>(adds); - }else{ - dynamicCells.addAll(adds); - } - - - // now we can check the keeps lists for sub cells - if (keepsNew.size() > 0){ - // lets see if we have any cells that contain sub-cells - for (int i = 0; i < keepsNew.size(); i++) { - - MenuCell newCell = keepsNew.get(i); - Log.i("MENU", "KEEP: "+newCell.getTitle()); - if (newCell.getSubCells() != null && newCell.getSubCells().size() > 0){ - // This cell HAS SUB-CELLS. Get the old cell - MenuCell oldCell = keepsOld.get(i); - Log.i("MENU", "MATCHING SUB CELLS"); - List newSubCells = newCell.getSubCells(); - List oldSubCells = oldCell.getSubCells(); - - RunScore subCellScore = compareOldAndNewLists(oldSubCells, newSubCells); - - if (subCellScore == null){ - return; - } - - Log.i("MENU SUB Run Score", String.valueOf(subCellScore.getScore())); - Log.i("MENU SUB Run OLD", subCellScore.getOldMenu().toString()); - Log.i("MENU SUB Run NEW", subCellScore.getCurrentMenu().toString()); - - // Grab the responses so that we can create the add / delete commands - List subCellNewArray = subCellScore.getCurrentMenu(); - List subCellOldArray = subCellScore.getOldMenu(); - - // Set up deletes - List subDeletes = new ArrayList<>(); - for (int x = 0; x < subCellOldArray.size(); x++) { - Integer old = subCellOldArray.get(x); - if (old.equals(MARKED_FOR_DELETION)){ - // grab cell to send to function to create delete commands - subDeletes.add(oldSubCells.get(x)); - } - } - // create the delete commands and append to previous delete list - deleteCommands.addAll(deleteCommandsForCells(subDeletes)); - - // Set up the adds - List subAdds = new ArrayList<>(); - for (int x = 0; x < subCellNewArray.size(); x++) { - Integer newInt = subCellNewArray.get(x); - if (newInt.equals(MARKED_FOR_ADDITION)){ - // grab cell to send to function to create delete commands - subAdds.add(newSubCells.get(x)); - } - } - for (MenuCell cell : subAdds){ - Log.i("SUB MENU CELL ADD ", cell.getTitle()); - } - // add subs to the list - dynamicCells.addAll(subAdds); - menuCells.addAll(subAdds); - } - } - } // update the cell IDs so we don't have any ID collisions updateIdsOnDynamicCells(); } @@ -756,14 +638,6 @@ abstract class BaseMenuManager extends BaseSubManager { private List mainMenuCommandsForCells(List cellsToAdd, boolean shouldHaveArtwork) { List builtCommands = new ArrayList<>(); - for (MenuCell cell : menuCells){ - Log.i("MENU CELL COMMANDMAIN: ", cell.getTitle()+ " ID: "+ cell.getCellId() + " PARENT ID: "+ cell.getParentCellId()); - } - - for (MenuCell cell : cellsToAdd){ - Log.i("MENU CELL TO ADD: ", cell.getTitle()+ " ID: "+ cell.getCellId() + " PARENT ID: "+ cell.getParentCellId()); - } - // We need the index so we will use this type of loop for (int z = 0; z < menuCells.size(); z++) { MenuCell mainCell = menuCells.get(z); @@ -811,6 +685,7 @@ abstract class BaseMenuManager extends BaseSubManager { } private AddCommand commandForMenuCell(MenuCell cell, boolean shouldHaveArtwork, int position){ + Log.i("MENU", "ADD COMMAND FOR MENU CELL"); MenuParams params = new MenuParams(cell.getTitle()); params.setParentID(cell.getParentCellId() != MAX_ID ? cell.getParentCellId() : 0); @@ -825,6 +700,7 @@ abstract class BaseMenuManager extends BaseSubManager { } private AddSubMenu subMenuCommandForMenuCell(MenuCell cell, boolean shouldHaveArtwork, int position){ + Log.i("MENU", "SUB COMMAND FOR MENU CELL"); AddSubMenu subMenu = new AddSubMenu(cell.getCellId(), cell.getTitle()); subMenu.setPosition(position); subMenu.setMenuIcon((shouldHaveArtwork && (cell.getIcon()!= null && cell.getIcon().getImageRPC() != null)) ? cell.getIcon().getImageRPC() : null); diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java index 7fb284bed..0e4d8cc8a 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java @@ -274,6 +274,18 @@ public class MenuCell { if (!(o instanceof MenuCell)) return false; MenuCell menuCell = (MenuCell) o; + // check if one has sub-cells and if one doesnt, if so they are not equal + if (menuCell.getSubCells() == null && getSubCells() != null){ + return false; + } else if (menuCell.getSubCells() != null && getSubCells() == null){ + return false; + } else if (menuCell.getSubCells() != null && getSubCells() != null){ + if (!menuCell.getSubCells().containsAll(getSubCells())){ + return false; + }else if (!getSubCells().containsAll(menuCell.getSubCells())){ + return false; + } + } // if we get to this point, create the hashes and compare them return hashCode() == menuCell.hashCode(); } -- cgit v1.2.1 From f86525da4ee94ef321368dc95c5fd44e3cc9d33d Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Mon, 20 May 2019 13:39:08 -0400 Subject: clean up. root menu working --- .../managers/screen/menu/BaseMenuManager.java | 501 ++++++++++++--------- .../managers/screen/menu/MenuCell.java | 13 +- 2 files changed, 294 insertions(+), 220 deletions(-) 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 d4960dd81..988fbbeaa 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 @@ -41,6 +41,7 @@ import com.smartdevicelink.managers.CompletionListener; import com.smartdevicelink.managers.file.FileManager; import com.smartdevicelink.managers.file.MultipleFileCompletionListener; import com.smartdevicelink.managers.file.filetypes.SdlArtwork; +import com.smartdevicelink.protocol.enums.ControlFrameTags; import com.smartdevicelink.protocol.enums.FunctionID; import com.smartdevicelink.proxy.RPCNotification; import com.smartdevicelink.proxy.RPCRequest; @@ -90,8 +91,8 @@ abstract class BaseMenuManager extends BaseSubManager { private final WeakReference fileManager; - List menuCells, waitingUpdateMenuCells, oldMenuCells, dynamicCells; - List inProgressUpdate, deleteCommands; + List menuCells, waitingUpdateMenuCells, oldMenuCells; + List inProgressUpdate; boolean waitingOnHMIUpdate; private boolean hasQueuedUpdate; @@ -139,8 +140,6 @@ abstract class BaseMenuManager extends BaseSubManager { hasQueuedUpdate = false; waitingOnHMIUpdate = false; waitingUpdateMenuCells = null; - deleteCommands = null; - dynamicCells = null; // remove listeners internalInterface.removeOnRPCNotificationListener(FunctionID.ON_HMI_STATUS, hmiListener); @@ -209,12 +208,12 @@ abstract class BaseMenuManager extends BaseSubManager { DebugTool.logInfo("Menu Artworks Uploaded"); } // proceed - update(); + updateRootMenu(); } }); }else{ // No Artworks to be uploaded, send off - update(); + updateRootMenu(); } } @@ -228,7 +227,7 @@ abstract class BaseMenuManager extends BaseSubManager { // UPDATING SYSTEM - private void update(){ + private void updateRootMenu(){ if (currentHMILevel == null || currentHMILevel.equals(HMILevel.HMI_NONE) || currentSystemContext.equals(SystemContext.SYSCTXT_MENU)){ // We are in NONE or the menu is in use, bail out of here @@ -246,15 +245,59 @@ abstract class BaseMenuManager extends BaseSubManager { } // run the lists through the new algorithm - createDynamicUpdate(oldMenuCells, menuCells); + RunScore rootScore = createDynamicUpdate(oldMenuCells, menuCells); + + if (rootScore == null){ + // send initial menu (score will return null) + // make a copy of our current cells + DebugTool.logInfo("Creating initial Menu"); + this.oldMenuCells = new ArrayList<>(menuCells); + sendInitialMenu(); + }else{ + // lets dynamically update the root menu + dynamicUpdateRoot(rootScore); + } + } - // make a copy of our current cells - this.oldMenuCells = new ArrayList<>(menuCells); + private void dynamicUpdateRoot(RunScore bestRootScore){ + + // we need to run through the keeps and see if they have subCells, as they also need to be run + // through the compare function. + List newIntArray = bestRootScore.getCurrentMenu(); + List oldIntArray = bestRootScore.getOldMenu(); + List deleteCommands = new ArrayList<>(); + + // Set up deletes + List deletes = new ArrayList<>(); + for (int x = 0; x < oldIntArray.size(); x++) { + Integer old = oldIntArray.get(x); + if (old.equals(MARKED_FOR_DELETION)){ + // grab cell to send to function to create delete commands + deletes.add(oldMenuCells.get(x)); + } + } + // create the delete commands + deleteCommands = deleteCommandsForCells(deletes); + + // Set up the adds + List adds = new ArrayList<>(); + for (int x = 0; x < newIntArray.size(); x++) { + Integer newInt = newIntArray.get(x); + if (newInt.equals(MARKED_FOR_ADDITION)){ + // grab cell to send to function to create delete commands + adds.add(menuCells.get(x)); + } + } + + updateIdsOnDynamicCells(adds); + sendDynamicRootMenu(deleteCommands, adds); + } - deleteCurrentMenu(new CompletionListener() { + private void sendDynamicRootMenu(List deleteCommands,final List updatedCells){ + deleteMenuCells(deleteCommands,new CompletionListener() { @Override public void onComplete(boolean success) { - sendCurrentMenu(new CompletionListener() { + sendMenu(updatedCells, new CompletionListener() { @Override public void onComplete(boolean success) { inProgressUpdate = null; @@ -264,7 +307,7 @@ abstract class BaseMenuManager extends BaseSubManager { } if (hasQueuedUpdate){ - update(); + setMenuCells(waitingUpdateMenuCells); hasQueuedUpdate = false; } } @@ -273,203 +316,15 @@ abstract class BaseMenuManager extends BaseSubManager { }); } - // DELETE OLD MENU ITEMS - - private void deleteCurrentMenu(final CompletionListener listener){ - if (oldMenuCells != null && oldMenuCells.size() == 0) { - if (listener != null){ - // technically this method is successful if there's nothing to delete - DebugTool.logInfo("No old cells to delete, returning"); - listener.onComplete(true); - } - return; - } - - if (deleteCommands == null || deleteCommands.size() == 0){ - // no dynamic deletes required. return - if (listener != null){ - // technically this method is successful if there's nothing to delete - listener.onComplete(true); - } - return; - } - - for (RPCRequest delete : deleteCommands){ - try { - Log.i("MENU CELL DELETE: ", delete.serializeJSON().toString()); - } catch (JSONException e) { - e.printStackTrace(); - } - } - - //List deleteCommands = deleteCommandsForCells(oldMenuCells); - if (oldMenuCells != null) { - oldMenuCells.clear(); - } - internalInterface.sendRequests(deleteCommands, new OnMultipleRequestListener() { - @Override - public void onUpdate(int remainingRequests) { - - } - - @Override - public void onFinished() { - DebugTool.logInfo("Successfully deleted all old menu commands"); - deleteCommands.clear(); - if (listener != null){ - listener.onComplete(true); - } - } - - @Override - public void onError(int correlationId, Result resultCode, String info) { - - } - - @Override - public void onResponse(int correlationId, RPCResponse response) { - - } - }); - } - - // SEND NEW MENU ITEMS - - private void sendCurrentMenu(final CompletionListener listener){ - - if (dynamicCells.size() == 0){ - - if (listener != null){ - // This can be considered a success if the user was clearing out their menu - listener.onComplete(true); - } - return; - } - - List mainMenuCommands; - final List subMenuCommands; - - for (MenuCell cell : dynamicCells){ - Log.i("MENU CELL SEND: ", cell.getTitle()+ " ID: "+ cell.getCellId() + " PARENT ID: "+ cell.getParentCellId()); - } - - if (findAllArtworksToBeUploadedFromCells(dynamicCells).size() > 0 || !supportsImages()){ - // Send artwork-less menu - mainMenuCommands = mainMenuCommandsForCells(dynamicCells, false); - subMenuCommands = subMenuCommandsForCells(dynamicCells, false); - } else { - mainMenuCommands = mainMenuCommandsForCells(dynamicCells, true); - subMenuCommands = subMenuCommandsForCells(dynamicCells, true); - } - - for (RPCRequest request : mainMenuCommands){ - try { - Log.i("MENU ADD COMMAND: ", request.serializeJSON().toString()); - } catch (JSONException e) { - e.printStackTrace(); - } - } - - for (RPCRequest request : subMenuCommands){ - try { - Log.i("MENU SUB COMMAND: ", request.serializeJSON().toString()); - } catch (JSONException e) { - e.printStackTrace(); - } - } - - // add all built commands to inProgressUpdate - inProgressUpdate = new ArrayList<>(mainMenuCommands); - inProgressUpdate.addAll(subMenuCommands); - - internalInterface.sendSequentialRPCs(mainMenuCommands, new OnMultipleRequestListener() { - @Override - public void onUpdate(int remainingRequests) { - // nothing here - } - - @Override - public void onFinished() { - - oldMenuCells = menuCells; - // we don't need these anymore - dynamicCells.clear(); - - if (subMenuCommands.size() > 0) { - sendSubMenuCommands(subMenuCommands, listener); - DebugTool.logInfo("Finished sending main menu commands. Sending sub menu commands."); - } else { - inProgressUpdate = null; - DebugTool.logInfo("Finished sending main menu commands."); - } - } - - @Override - public void onError(int correlationId, Result resultCode, String info) { - DebugTool.logError("Result: " + resultCode.toString() + " Info: " + info); - } - - @Override - public void onResponse(int correlationId, RPCResponse response) { - try { - DebugTool.logInfo("Main Menu response: " + response.serializeJSON().toString()); - } catch (JSONException e) { - e.printStackTrace(); - } - } - }); - } - - private void sendSubMenuCommands(List commands, final CompletionListener listener){ - internalInterface.sendSequentialRPCs(commands, new OnMultipleRequestListener() { - @Override - public void onUpdate(int remainingRequests) { - - } - - @Override - public void onFinished() { - DebugTool.logInfo("Finished Updating Menu"); - inProgressUpdate = null; - - if (listener != null){ - listener.onComplete(true); - } - } - - @Override - public void onError(int correlationId, Result resultCode, String info) { - DebugTool.logError("Failed to send sub menu commands: "+ info); - if (listener != null){ - listener.onComplete(false); - } - } - - @Override - public void onResponse(int correlationId, RPCResponse response) { - try { - DebugTool.logInfo("Sub Menu response: "+ response.serializeJSON().toString()); - } catch (JSONException e) { - e.printStackTrace(); - } - } - }); - } // OTHER HELPER METHODS: // COMPARISONS - private void createDynamicUpdate(List oldCells, List newCells){ + private RunScore createDynamicUpdate(List oldCells, List newCells){ if (oldCells == null || oldCells.size() == 0){ - // This is the first menu we are sending, just get it out - if (dynamicCells == null){ - dynamicCells = new ArrayList<>(newCells); - }else{ - dynamicCells.addAll(newCells); - } - return; + return null; } RunScore bestScore = compareOldAndNewLists(oldCells, newCells); @@ -478,8 +333,7 @@ abstract class BaseMenuManager extends BaseSubManager { Log.i("MENU Best Run OLD", bestScore.getOldMenu().toString()); Log.i("MENU Best Run NEW", bestScore.getCurrentMenu().toString()); - // update the cell IDs so we don't have any ID collisions - updateIdsOnDynamicCells(); + return bestScore; } private RunScore compareOldAndNewLists(List oldCells, List newCells){ @@ -586,7 +440,7 @@ abstract class BaseMenuManager extends BaseSubManager { // IDs - private void updateIdsOnDynamicCells(){ + private void updateIdsOnDynamicCells(List dynamicCells){ if (menuCells != null && menuCells.size() > 0 && dynamicCells != null && dynamicCells.size() > 0) { for (int z = 0; z < menuCells.size(); z++) { MenuCell mainCell = menuCells.get(z); @@ -622,6 +476,7 @@ abstract class BaseMenuManager extends BaseSubManager { List deleteCommandsForCells(List cells){ List deletes = new ArrayList<>(); for (MenuCell cell : cells){ + Log.i("MENU CELL DELETE", "NAME: "+ cell.getTitle()); if (cell.getSubCells() == null){ DeleteCommand delete = new DeleteCommand(cell.getCellId()); deletes.add(delete); @@ -685,7 +540,6 @@ abstract class BaseMenuManager extends BaseSubManager { } private AddCommand commandForMenuCell(MenuCell cell, boolean shouldHaveArtwork, int position){ - Log.i("MENU", "ADD COMMAND FOR MENU CELL"); MenuParams params = new MenuParams(cell.getTitle()); params.setParentID(cell.getParentCellId() != MAX_ID ? cell.getParentCellId() : 0); @@ -700,7 +554,6 @@ abstract class BaseMenuManager extends BaseSubManager { } private AddSubMenu subMenuCommandForMenuCell(MenuCell cell, boolean shouldHaveArtwork, int position){ - Log.i("MENU", "SUB COMMAND FOR MENU CELL"); AddSubMenu subMenu = new AddSubMenu(cell.getCellId(), cell.getTitle()); subMenu.setPosition(position); subMenu.setMenuIcon((shouldHaveArtwork && (cell.getIcon()!= null && cell.getIcon().getImageRPC() != null)) ? cell.getIcon().getImageRPC() : null); @@ -790,4 +643,236 @@ abstract class BaseMenuManager extends BaseSubManager { }; internalInterface.addOnRPCNotificationListener(FunctionID.ON_COMMAND, commandListener); } + + // SEND NEW MENU ITEMS + + private void sendInitialMenu(){ + + if (currentHMILevel == null || currentHMILevel.equals(HMILevel.HMI_NONE) || currentSystemContext.equals(SystemContext.SYSCTXT_MENU)){ + // We are in NONE or the menu is in use, bail out of here + DebugTool.logInfo("HMI in None or System Context Menu, returning"); + waitingOnHMIUpdate = true; + waitingUpdateMenuCells = menuCells; + return; + } + + if (inProgressUpdate != null && inProgressUpdate.size() > 0){ + // there's an in-progress update so this needs to wait + DebugTool.logInfo("There is an in progress Menu Update, returning"); + hasQueuedUpdate = true; + return; + } + + // run the lists through the new algorithm + createDynamicUpdate(oldMenuCells, menuCells); + + deleteRootMenu(new CompletionListener() { + @Override + public void onComplete(boolean success) { + sendMenu(menuCells, new CompletionListener() { + @Override + public void onComplete(boolean success) { + inProgressUpdate = null; + + if (!success){ + DebugTool.logError("Error Sending Current Menu"); + } + + if (hasQueuedUpdate){ + setMenuCells(waitingUpdateMenuCells); + hasQueuedUpdate = false; + } + } + }); + } + }); + } + + private void sendMenu(final List menu, final CompletionListener listener){ + + if (menu.size() == 0){ + + if (listener != null){ + // This can be considered a success if the user was clearing out their menu + listener.onComplete(true); + } + return; + } + + List mainMenuCommands; + final List subMenuCommands; + + for (MenuCell cell : menu){ + Log.i("MENU CELL SEND: ", cell.getTitle()+ " ID: "+ cell.getCellId() + " PARENT ID: "+ cell.getParentCellId()); + } + + if (findAllArtworksToBeUploadedFromCells(menu).size() > 0 || !supportsImages()){ + // Send artwork-less menu + mainMenuCommands = mainMenuCommandsForCells(menu, false); + subMenuCommands = subMenuCommandsForCells(menu, false); + } else { + mainMenuCommands = mainMenuCommandsForCells(menu, true); + subMenuCommands = subMenuCommandsForCells(menu, true); + } + + for (RPCRequest request : mainMenuCommands){ + try { + Log.i("MENU ADD COMMAND: ", request.serializeJSON().toString()); + } catch (JSONException e) { + e.printStackTrace(); + } + } + + for (RPCRequest request : subMenuCommands){ + try { + Log.i("MENU SUB COMMAND: ", request.serializeJSON().toString()); + } catch (JSONException e) { + e.printStackTrace(); + } + } + + // add all built commands to inProgressUpdate + inProgressUpdate = new ArrayList<>(mainMenuCommands); + inProgressUpdate.addAll(subMenuCommands); + + internalInterface.sendSequentialRPCs(mainMenuCommands, new OnMultipleRequestListener() { + @Override + public void onUpdate(int remainingRequests) { + // nothing here + } + + @Override + public void onFinished() { + + oldMenuCells = new ArrayList<>(menuCells); + + if (subMenuCommands.size() > 0) { + sendSubMenuCommands(subMenuCommands, listener); + DebugTool.logInfo("Finished sending main menu commands. Sending sub menu commands."); + } else { + inProgressUpdate = null; + DebugTool.logInfo("Finished sending main menu commands."); + } + } + + @Override + public void onError(int correlationId, Result resultCode, String info) { + DebugTool.logError("Result: " + resultCode.toString() + " Info: " + info); + } + + @Override + public void onResponse(int correlationId, RPCResponse response) { + try { + DebugTool.logInfo("Main Menu response: " + response.serializeJSON().toString()); + } catch (JSONException e) { + e.printStackTrace(); + } + } + }); + } + + private void sendSubMenuCommands(List commands, final CompletionListener listener){ + internalInterface.sendSequentialRPCs(commands, new OnMultipleRequestListener() { + @Override + public void onUpdate(int remainingRequests) { + + } + + @Override + public void onFinished() { + DebugTool.logInfo("Finished Updating Menu"); + inProgressUpdate = null; + + if (listener != null){ + listener.onComplete(true); + } + } + + @Override + public void onError(int correlationId, Result resultCode, String info) { + DebugTool.logError("Failed to send sub menu commands: "+ info); + if (listener != null){ + listener.onComplete(false); + } + } + + @Override + public void onResponse(int correlationId, RPCResponse response) { + try { + DebugTool.logInfo("Sub Menu response: "+ response.serializeJSON().toString()); + } catch (JSONException e) { + e.printStackTrace(); + } + } + }); + } + + // DELETE OLD MENU ITEMS + + private void deleteRootMenu(final CompletionListener listener){ + + if (oldMenuCells != null && oldMenuCells.size() == 0) { + if (listener != null){ + // technically this method is successful if there's nothing to delete + DebugTool.logInfo("No old cells to delete, returning"); + listener.onComplete(true); + } + return; + } + deleteMenuCells(deleteCommandsForCells(oldMenuCells), listener); + } + + private void deleteMenuCells(List deleteCommands, final CompletionListener listener){ + if (oldMenuCells != null && oldMenuCells.size() == 0) { + if (listener != null){ + // technically this method is successful if there's nothing to delete + DebugTool.logInfo("No old cells to delete, returning"); + listener.onComplete(true); + } + return; + } + + if (deleteCommands == null || deleteCommands.size() == 0){ + // no dynamic deletes required. return + if (listener != null){ + // technically this method is successful if there's nothing to delete + listener.onComplete(true); + } + return; + } + + for (RPCRequest delete : deleteCommands){ + try { + Log.i("MENU CELL DELETE: ", delete.serializeJSON().toString()); + } catch (JSONException e) { + e.printStackTrace(); + } + } + + internalInterface.sendRequests(deleteCommands, new OnMultipleRequestListener() { + @Override + public void onUpdate(int remainingRequests) { + + } + + @Override + public void onFinished() { + DebugTool.logInfo("Successfully deleted cells"); + if (listener != null){ + listener.onComplete(true); + } + } + + @Override + public void onError(int correlationId, Result resultCode, String info) { + + } + + @Override + public void onResponse(int correlationId, RPCResponse response) { + + } + }); + } + } diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java index 0e4d8cc8a..e25bbaea9 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java @@ -258,6 +258,7 @@ public class MenuCell { result += ((getTitle() == null) ? 0 : Integer.rotateLeft(getTitle().hashCode(), 1)); result += ((getIcon() == null || getIcon().getName() == null) ? 0 : Integer.rotateLeft(getIcon().getName().hashCode(), 2)); result += ((getVoiceCommands() == null) ? 0 : Integer.rotateLeft(getVoiceCommands().hashCode(), 3)); + result += ((getSubCells() == null) ? 0 : Integer.rotateLeft(getSubCells().size(), 4)); return result; } @@ -274,18 +275,6 @@ public class MenuCell { if (!(o instanceof MenuCell)) return false; MenuCell menuCell = (MenuCell) o; - // check if one has sub-cells and if one doesnt, if so they are not equal - if (menuCell.getSubCells() == null && getSubCells() != null){ - return false; - } else if (menuCell.getSubCells() != null && getSubCells() == null){ - return false; - } else if (menuCell.getSubCells() != null && getSubCells() != null){ - if (!menuCell.getSubCells().containsAll(getSubCells())){ - return false; - }else if (!getSubCells().containsAll(menuCell.getSubCells())){ - return false; - } - } // if we get to this point, create the hashes and compare them return hashCode() == menuCell.hashCode(); } -- cgit v1.2.1 From d36d6574c307447eeafb66b9aaff008bd033f2e7 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Mon, 20 May 2019 16:43:39 -0400 Subject: listeners work on updated cells now --- .../managers/screen/menu/BaseMenuManager.java | 77 ++++++++++++++-------- 1 file changed, 50 insertions(+), 27 deletions(-) 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 988fbbeaa..4a46d0c14 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 @@ -41,7 +41,6 @@ import com.smartdevicelink.managers.CompletionListener; import com.smartdevicelink.managers.file.FileManager; import com.smartdevicelink.managers.file.MultipleFileCompletionListener; import com.smartdevicelink.managers.file.filetypes.SdlArtwork; -import com.smartdevicelink.protocol.enums.ControlFrameTags; import com.smartdevicelink.protocol.enums.FunctionID; import com.smartdevicelink.proxy.RPCNotification; import com.smartdevicelink.proxy.RPCRequest; @@ -72,7 +71,9 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.ref.WeakReference; import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Map; @@ -192,9 +193,6 @@ abstract class BaseMenuManager extends BaseSubManager { return; } - // Set the IDs - lastMenuId = menuCellIdMin; - updateIdsOnMenuCells(menuCells, parentIdNotFound); // Upload the Artworks List artworksToBeUploaded = findAllArtworksToBeUploadedFromCells(menuCells); if (artworksToBeUploaded.size() > 0 && fileManager.get() != null){ @@ -247,10 +245,13 @@ abstract class BaseMenuManager extends BaseSubManager { // run the lists through the new algorithm RunScore rootScore = createDynamicUpdate(oldMenuCells, menuCells); - if (rootScore == null){ + if (rootScore == null || rootScore.getScore() == 0){ // send initial menu (score will return null) // make a copy of our current cells DebugTool.logInfo("Creating initial Menu"); + // Set the IDs if needed + lastMenuId = menuCellIdMin; + updateIdsOnMenuCells(menuCells, parentIdNotFound); this.oldMenuCells = new ArrayList<>(menuCells); sendInitialMenu(); }else{ @@ -265,7 +266,7 @@ abstract class BaseMenuManager extends BaseSubManager { // through the compare function. List newIntArray = bestRootScore.getCurrentMenu(); List oldIntArray = bestRootScore.getOldMenu(); - List deleteCommands = new ArrayList<>(); + List deleteCommands; // Set up deletes List deletes = new ArrayList<>(); @@ -281,16 +282,31 @@ abstract class BaseMenuManager extends BaseSubManager { // Set up the adds List adds = new ArrayList<>(); + List keeps = new ArrayList<>(); for (int x = 0; x < newIntArray.size(); x++) { Integer newInt = newIntArray.get(x); if (newInt.equals(MARKED_FOR_ADDITION)){ - // grab cell to send to function to create delete commands + // grab cell to send to function to create add commands adds.add(menuCells.get(x)); + } else if (newInt.equals(KEEP)){ + keeps.add(menuCells.get(x)); } } + List addsWithNewIds = updateIdsOnDynamicCells(adds); + transferIdsToKeeps(keeps); + sendDynamicRootMenu(deleteCommands, addsWithNewIds); + } - updateIdsOnDynamicCells(adds); - sendDynamicRootMenu(deleteCommands, adds); + private void transferIdsToKeeps(List keeps){ + for (int z = 0; z < oldMenuCells.size(); z++) { + MenuCell mainCell = oldMenuCells.get(z); + for (int i = 0; i < keeps.size(); i++) { + MenuCell keptCell = keeps.get(i); + if (mainCell.equals(keptCell)) { + keptCell.setCellId(mainCell.getCellId()); + } + } + } } private void sendDynamicRootMenu(List deleteCommands,final List updatedCells){ @@ -307,7 +323,7 @@ abstract class BaseMenuManager extends BaseSubManager { } if (hasQueuedUpdate){ - setMenuCells(waitingUpdateMenuCells); + //setMenuCells(waitingUpdateMenuCells); hasQueuedUpdate = false; } } @@ -316,6 +332,15 @@ abstract class BaseMenuManager extends BaseSubManager { }); } + // SUB MENUS + + // This is called in the listener in the sendMenu and sendSubMenuCommands Methods + private void sendSubMenuUpdates(){ + + + + } + // OTHER HELPER METHODS: @@ -440,7 +465,7 @@ abstract class BaseMenuManager extends BaseSubManager { // IDs - private void updateIdsOnDynamicCells(List dynamicCells){ + private List updateIdsOnDynamicCells(List dynamicCells){ if (menuCells != null && menuCells.size() > 0 && dynamicCells != null && dynamicCells.size() > 0) { for (int z = 0; z < menuCells.size(); z++) { MenuCell mainCell = menuCells.get(z); @@ -450,24 +475,23 @@ abstract class BaseMenuManager extends BaseSubManager { int newId = ++lastMenuId; menuCells.get(z).setCellId(newId); dynamicCells.get(i).setCellId(newId); - - // now we have to update our sub cells to use our new parent ID - if (dynamicCell.getSubCells() != null && dynamicCell.getSubCells().size() > 0) { - updateIdsOnMenuCells(dynamicCell.getSubCells(), newId); - } } } } + return dynamicCells; } + return null; } private void updateIdsOnMenuCells(List cells, int parentId){ - for (MenuCell cell : cells){ - cell.setCellId(++lastMenuId); - cell.setParentCellId(parentId); - if (cell.getSubCells() != null && cell.getSubCells().size() > 0){ - updateIdsOnMenuCells(cell.getSubCells(), cell.getCellId()); - } + for (MenuCell cell : cells) { + int newId = ++lastMenuId; + Log.i("MENU", "UPDATING ID ON CELL: " + cell.getTitle() + " TO: " + newId); + cell.setCellId(newId); + cell.setParentCellId(parentId); + if (cell.getSubCells() != null && cell.getSubCells().size() > 0) { + updateIdsOnMenuCells(cell.getSubCells(), cell.getCellId()); + } } } @@ -542,7 +566,7 @@ abstract class BaseMenuManager extends BaseSubManager { private AddCommand commandForMenuCell(MenuCell cell, boolean shouldHaveArtwork, int position){ MenuParams params = new MenuParams(cell.getTitle()); - params.setParentID(cell.getParentCellId() != MAX_ID ? cell.getParentCellId() : 0); + params.setParentID(cell.getParentCellId() != MAX_ID ? cell.getParentCellId() : null); params.setPosition(position); AddCommand command = new AddCommand(cell.getCellId()); @@ -565,11 +589,13 @@ abstract class BaseMenuManager extends BaseSubManager { private boolean callListenerForCells(List cells, OnCommand command){ if (cells != null && cells.size() > 0 && command != null) { for (MenuCell cell : cells) { + + Log.i("MENU COMMANDS", "CHECKING CELL: "+ cell.getTitle() + " With Command ID: "+ cell.getCellId()); + if (cell.getCellId() == command.getCmdID() && cell.getMenuSelectionListener() != null) { cell.getMenuSelectionListener().onTriggered(command.getTriggerSource()); return true; } - if (cell.getSubCells() != null && cell.getSubCells().size() > 0) { // for each cell, if it has sub cells, recursively loop through those as well if (callListenerForCells(cell.getSubCells(), command)) { @@ -663,9 +689,6 @@ abstract class BaseMenuManager extends BaseSubManager { return; } - // run the lists through the new algorithm - createDynamicUpdate(oldMenuCells, menuCells); - deleteRootMenu(new CompletionListener() { @Override public void onComplete(boolean success) { -- cgit v1.2.1 From 3dd7d64d1bee92c102c3c95f12af626e276d6c70 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Mon, 20 May 2019 16:53:42 -0400 Subject: remove unneeded imports --- .../managers/screen/menu/BaseMenuManager.java | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) 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 4a46d0c14..d7566ca4f 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 @@ -32,7 +32,6 @@ package com.smartdevicelink.managers.screen.menu; -import android.support.annotation.IntDef; import android.support.annotation.NonNull; import android.util.Log; @@ -67,28 +66,17 @@ import com.smartdevicelink.util.DebugTool; import org.json.JSONException; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; import java.lang.ref.WeakReference; import java.util.ArrayList; -import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; abstract class BaseMenuManager extends BaseSubManager { - /** - * State enums used internally for dynamic updating - * These should be used to set the 'state' variable - */ - @IntDef({KEEP, MARKED_FOR_ADDITION, MARKED_FOR_DELETION}) - @Retention(RetentionPolicy.SOURCE) - @interface MenuCellState {} - static final int KEEP = 0; - static final int MARKED_FOR_ADDITION = 1; - static final int MARKED_FOR_DELETION = 2; + private static final int KEEP = 0; + private static final int MARKED_FOR_ADDITION = 1; + private static final int MARKED_FOR_DELETION = 2; private final WeakReference fileManager; -- cgit v1.2.1 From 914a08fe089926012dc48dc154cc8b778706f05d Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Tue, 21 May 2019 11:06:52 -0400 Subject: update old cell setting, equality checks, and start of sub compare --- .../managers/screen/menu/BaseMenuManager.java | 104 ++++++++++++++++++--- .../managers/screen/menu/MenuCell.java | 2 +- 2 files changed, 92 insertions(+), 14 deletions(-) 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 d7566ca4f..ebca883b4 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 @@ -80,7 +80,7 @@ abstract class BaseMenuManager extends BaseSubManager { private final WeakReference fileManager; - List menuCells, waitingUpdateMenuCells, oldMenuCells; + List menuCells, waitingUpdateMenuCells, oldMenuCells, keepsNew, keepsOld; List inProgressUpdate; boolean waitingOnHMIUpdate; @@ -155,6 +155,11 @@ abstract class BaseMenuManager extends BaseSubManager { waitingOnHMIUpdate = false; // Update our Lists + // set old list + if (menuCells != null) { + oldMenuCells = new ArrayList<>(menuCells); + } + // copy new list menuCells = new ArrayList<>(cells); // HashSet order doesnt matter / does not allow duplicates @@ -213,6 +218,8 @@ abstract class BaseMenuManager extends BaseSubManager { // UPDATING SYSTEM + // ROOT MENU + private void updateRootMenu(){ if (currentHMILevel == null || currentHMILevel.equals(HMILevel.HMI_NONE) || currentSystemContext.equals(SystemContext.SYSCTXT_MENU)){ @@ -233,7 +240,7 @@ abstract class BaseMenuManager extends BaseSubManager { // run the lists through the new algorithm RunScore rootScore = createDynamicUpdate(oldMenuCells, menuCells); - if (rootScore == null || rootScore.getScore() == 0){ + if (rootScore == null){ // send initial menu (score will return null) // make a copy of our current cells DebugTool.logInfo("Creating initial Menu"); @@ -258,11 +265,14 @@ abstract class BaseMenuManager extends BaseSubManager { // Set up deletes List deletes = new ArrayList<>(); + keepsOld = new ArrayList<>(); for (int x = 0; x < oldIntArray.size(); x++) { Integer old = oldIntArray.get(x); if (old.equals(MARKED_FOR_DELETION)){ // grab cell to send to function to create delete commands deletes.add(oldMenuCells.get(x)); + } else if (old.equals(KEEP)){ + keepsOld.add(oldMenuCells.get(x)); } } // create the delete commands @@ -270,21 +280,35 @@ abstract class BaseMenuManager extends BaseSubManager { // Set up the adds List adds = new ArrayList<>(); - List keeps = new ArrayList<>(); + keepsNew = new ArrayList<>(); for (int x = 0; x < newIntArray.size(); x++) { Integer newInt = newIntArray.get(x); if (newInt.equals(MARKED_FOR_ADDITION)){ // grab cell to send to function to create add commands adds.add(menuCells.get(x)); } else if (newInt.equals(KEEP)){ - keeps.add(menuCells.get(x)); + keepsNew.add(menuCells.get(x)); } } List addsWithNewIds = updateIdsOnDynamicCells(adds); - transferIdsToKeeps(keeps); - sendDynamicRootMenu(deleteCommands, addsWithNewIds); + transferIdsToKeeps(keepsNew); + + if (addsWithNewIds != null && addsWithNewIds.size() > 0){ + Log.i("MENU", "THERE ARE ROOT MENU UPDATES. SEND THESE OFF"); + sendDynamicRootMenu(deleteCommands, addsWithNewIds); + }else{ + Log.i("MENU", "EVERYTHING IS A KEEP. LETS CHECK THE SUB MENUS"); + sendSubMenuUpdates(); + } + } + // SUB MENU COMPARISONS + + + + // OTHER + private void transferIdsToKeeps(List keeps){ for (int z = 0; z < oldMenuCells.size(); z++) { MenuCell mainCell = oldMenuCells.get(z); @@ -324,9 +348,41 @@ abstract class BaseMenuManager extends BaseSubManager { // This is called in the listener in the sendMenu and sendSubMenuCommands Methods private void sendSubMenuUpdates(){ + // any cells that were re-added have their sub-cells added with them + // at this point all we care about are the cells that were deemed equal and kept. + if (keepsNew == null || keepsNew.size() == 0) { + return; + } + + for (int i = 0; i < keepsNew.size(); i++) { + MenuCell keptCell = keepsNew.get(i); + MenuCell oldKeptCell = keepsOld.get(i); + + if ((oldKeptCell.getSubCells() != null && oldKeptCell.getSubCells().size() > 0 && (keptCell.getSubCells() == null || keptCell.getSubCells().size() == 0))){ + // CASE 1: If the oldKeep[i] has a submenu and newKeep[i] does not, delete all submenu cells + Log.i("MENU SUB COMP", "New Cell "+keptCell.getTitle() + " No longer has subcells, delete all subcells from old"); + } else if ((oldKeptCell.getSubCells() == null || oldKeptCell.getSubCells().size() == 0) && keptCell.getSubCells() != null && keptCell.getSubCells().size() > 0){ + // CASE 2: If the oldKeep[i] doesn’t have a submenu and newKeep[i] does, add all submenu cells + Log.i("MENU SUB COMP", "New Cell "+keptCell.getTitle() + " has subcells, and previously didnt ADD SUBMENU STUFF"); + }else if (oldKeptCell.getSubCells() != null && oldKeptCell.getSubCells().size() > 0 && keptCell.getSubCells() != null && keptCell.getSubCells().size() > 0){ + // CASE 3: If BOTH have submenus, run the algorithm between them + Log.i("MENU SUB COMP", "Both Old and New: "+keptCell.getTitle() + " have sub cells. Run compare"); + } + // FOR EACH CELL WITH SUB CELLS, PRINT OUT INFO FOR THEIR SUBMENU + if (keptCell.getSubCells() != null && keptCell.getSubCells().size() > 0) { + for (MenuCell newCell : keptCell.getSubCells()) { + Log.i("MENU NEW SUBCELL", "TITLE: " + newCell.getTitle() + " PARENT: " + newCell.getParentCellId() + " ID: " + newCell.getCellId()); + } + } + if (oldKeptCell.getSubCells() != null && oldKeptCell.getSubCells().size() > 0) { + for (MenuCell oldCell : oldKeptCell.getSubCells()) { + Log.i("MENU OLD SUBCELL", "TITLE: " + oldCell.getTitle() + " PARENT: " + oldCell.getParentCellId() + " ID: " + oldCell.getCellId()); + } + } + } } @@ -702,7 +758,6 @@ abstract class BaseMenuManager extends BaseSubManager { private void sendMenu(final List menu, final CompletionListener listener){ if (menu.size() == 0){ - if (listener != null){ // This can be considered a success if the user was clearing out their menu listener.onComplete(true); @@ -761,8 +816,13 @@ abstract class BaseMenuManager extends BaseSubManager { sendSubMenuCommands(subMenuCommands, listener); DebugTool.logInfo("Finished sending main menu commands. Sending sub menu commands."); } else { - inProgressUpdate = null; - DebugTool.logInfo("Finished sending main menu commands."); + + if (keepsNew != null && keepsNew.size() > 0){ + sendSubMenuUpdates(); + }else { + inProgressUpdate = null; + DebugTool.logInfo("Finished sending main menu commands."); + } } } @@ -783,6 +843,19 @@ abstract class BaseMenuManager extends BaseSubManager { } private void sendSubMenuCommands(List commands, final CompletionListener listener){ + + if (commands != null){ + for (RPCRequest command: commands){ + try { + Log.i("MENU SUB COMMAND", command.serializeJSON().toString()); + } catch (JSONException e) { + e.printStackTrace(); + } + } + }else{ + Log.e("MENU", "SUB MENU COMMANDS NULL"); + } + internalInterface.sendSequentialRPCs(commands, new OnMultipleRequestListener() { @Override public void onUpdate(int remainingRequests) { @@ -791,11 +864,16 @@ abstract class BaseMenuManager extends BaseSubManager { @Override public void onFinished() { - DebugTool.logInfo("Finished Updating Menu"); - inProgressUpdate = null; - if (listener != null){ - listener.onComplete(true); + if (keepsNew != null && keepsNew.size() > 0){ + sendSubMenuUpdates(); + }else { + DebugTool.logInfo("Finished Updating Menu"); + inProgressUpdate = null; + + if (listener != null) { + listener.onComplete(true); + } } } diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java index e25bbaea9..0f067b4a4 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java @@ -258,7 +258,7 @@ public class MenuCell { result += ((getTitle() == null) ? 0 : Integer.rotateLeft(getTitle().hashCode(), 1)); result += ((getIcon() == null || getIcon().getName() == null) ? 0 : Integer.rotateLeft(getIcon().getName().hashCode(), 2)); result += ((getVoiceCommands() == null) ? 0 : Integer.rotateLeft(getVoiceCommands().hashCode(), 3)); - result += ((getSubCells() == null) ? 0 : Integer.rotateLeft(getSubCells().size(), 4)); + result += ((getSubCells() == null) ? 0 : Integer.rotateLeft(1, 4)); return result; } -- cgit v1.2.1 From ee48128533b7593450263f7d6f30a32283db6699 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Tue, 21 May 2019 11:40:39 -0400 Subject: sub cell command IDs fixed --- .../managers/screen/menu/BaseMenuManager.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) 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 ebca883b4..c508dd9b8 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 @@ -300,22 +300,17 @@ abstract class BaseMenuManager extends BaseSubManager { Log.i("MENU", "EVERYTHING IS A KEEP. LETS CHECK THE SUB MENUS"); sendSubMenuUpdates(); } - } - // SUB MENU COMPARISONS - - - // OTHER private void transferIdsToKeeps(List keeps){ for (int z = 0; z < oldMenuCells.size(); z++) { - MenuCell mainCell = oldMenuCells.get(z); + MenuCell oldCell = oldMenuCells.get(z); for (int i = 0; i < keeps.size(); i++) { MenuCell keptCell = keeps.get(i); - if (mainCell.equals(keptCell)) { - keptCell.setCellId(mainCell.getCellId()); + if (oldCell.equals(keptCell)) { + keptCell.setCellId(oldCell.getCellId()); } } } @@ -519,6 +514,10 @@ abstract class BaseMenuManager extends BaseSubManager { int newId = ++lastMenuId; menuCells.get(z).setCellId(newId); dynamicCells.get(i).setCellId(newId); + + if (mainCell.getSubCells() != null && mainCell.getSubCells().size() > 0) { + updateIdsOnMenuCells(mainCell.getSubCells(), mainCell.getCellId()); + } } } } -- cgit v1.2.1 From e3341e39c3e5be79b93e52938fe6b381e8dc0cd5 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Tue, 21 May 2019 14:20:07 -0400 Subject: update last log --- .../java/com/smartdevicelink/managers/screen/menu/BaseMenuManager.java | 1 + 1 file changed, 1 insertion(+) 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 c508dd9b8..4b7a8e90d 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 @@ -512,6 +512,7 @@ abstract class BaseMenuManager extends BaseSubManager { MenuCell dynamicCell = dynamicCells.get(i); if (mainCell.equals(dynamicCell)) { int newId = ++lastMenuId; + Log.i("MENU", "UPDATING ID ON DYNAMIC CELL: " + dynamicCell.getTitle() + " TO: " + newId); menuCells.get(z).setCellId(newId); dynamicCells.get(i).setCellId(newId); -- cgit v1.2.1 From de592818ae67d0fff1032e87d1daf21665d5801e Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Wed, 22 May 2019 14:02:58 -0400 Subject: continued work on subcell comparisons --- .../managers/screen/menu/BaseMenuManager.java | 53 +++++++++----- .../managers/screen/menu/RunScore.java | 1 + .../managers/screen/menu/SubCellCommandLists.java | 81 ++++++++++++++++++++++ 3 files changed, 117 insertions(+), 18 deletions(-) create mode 100644 base/src/main/java/com/smartdevicelink/managers/screen/menu/SubCellCommandLists.java 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 4b7a8e90d..fabedcb9e 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 @@ -349,35 +349,52 @@ abstract class BaseMenuManager extends BaseSubManager { return; } + List commandLists = new ArrayList<>(); + for (int i = 0; i < keepsNew.size(); i++) { MenuCell keptCell = keepsNew.get(i); MenuCell oldKeptCell = keepsOld.get(i); - if ((oldKeptCell.getSubCells() != null && oldKeptCell.getSubCells().size() > 0 && (keptCell.getSubCells() == null || keptCell.getSubCells().size() == 0))){ - // CASE 1: If the oldKeep[i] has a submenu and newKeep[i] does not, delete all submenu cells - Log.i("MENU SUB COMP", "New Cell "+keptCell.getTitle() + " No longer has subcells, delete all subcells from old"); - } else if ((oldKeptCell.getSubCells() == null || oldKeptCell.getSubCells().size() == 0) && keptCell.getSubCells() != null && keptCell.getSubCells().size() > 0){ - // CASE 2: If the oldKeep[i] doesn’t have a submenu and newKeep[i] does, add all submenu cells - Log.i("MENU SUB COMP", "New Cell "+keptCell.getTitle() + " has subcells, and previously didnt ADD SUBMENU STUFF"); - }else if (oldKeptCell.getSubCells() != null && oldKeptCell.getSubCells().size() > 0 && keptCell.getSubCells() != null && keptCell.getSubCells().size() > 0){ - // CASE 3: If BOTH have submenus, run the algorithm between them + if (oldKeptCell.getSubCells() != null && oldKeptCell.getSubCells().size() > 0 && keptCell.getSubCells() != null && keptCell.getSubCells().size() > 0){ + + // LOG STUFF - TO BE REMOVED Log.i("MENU SUB COMP", "Both Old and New: "+keptCell.getTitle() + " have sub cells. Run compare"); - } + // FOR EACH CELL WITH SUB CELLS, PRINT OUT INFO FOR THEIR SUBMENU + /*if (keptCell.getSubCells() != null && keptCell.getSubCells().size() > 0) { + for (MenuCell newCell : keptCell.getSubCells()) { + Log.i("MENU NEW SUBCELL", "TITLE: " + newCell.getTitle() + " PARENT: " + newCell.getParentCellId() + " ID: " + newCell.getCellId()); + } + } + if (oldKeptCell.getSubCells() != null && oldKeptCell.getSubCells().size() > 0) { + for (MenuCell oldCell : oldKeptCell.getSubCells()) { + Log.i("MENU OLD SUBCELL", "TITLE: " + oldCell.getTitle() + " PARENT: " + oldCell.getParentCellId() + " ID: " + oldCell.getCellId()); + } + }*/ + // ACTUAL LOGIC + RunScore subScore = compareOldAndNewLists(oldKeptCell.getSubCells(), keptCell.getSubCells()); - // FOR EACH CELL WITH SUB CELLS, PRINT OUT INFO FOR THEIR SUBMENU - if (keptCell.getSubCells() != null && keptCell.getSubCells().size() > 0) { - for (MenuCell newCell : keptCell.getSubCells()) { - Log.i("MENU NEW SUBCELL", "TITLE: " + newCell.getTitle() + " PARENT: " + newCell.getParentCellId() + " ID: " + newCell.getCellId()); - } - } - if (oldKeptCell.getSubCells() != null && oldKeptCell.getSubCells().size() > 0) { - for (MenuCell oldCell : oldKeptCell.getSubCells()) { - Log.i("MENU OLD SUBCELL", "TITLE: " + oldCell.getTitle() + " PARENT: " + oldCell.getParentCellId() + " ID: " + oldCell.getCellId()); + if (subScore != null){ + SubCellCommandLists commandList = new SubCellCommandLists(oldKeptCell.getTitle(), subScore, oldKeptCell.getSubCells(), keptCell.getSubCells()); + commandLists.add(commandList); } + } } + + for (SubCellCommandLists commandList : commandLists){ + Log.i("MENU SUB COMMAND LIST: ", "TITLE: "+ commandList.getMenuTitle()+ " RunScore: "+ commandList.getListsScore().getScore()); + } + + createSubMenuDynamicCommands(commandLists); + } + + private void createSubMenuDynamicCommands(List commandLists){ + + + + } diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/RunScore.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/RunScore.java index 393515870..2cc7db0b8 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/RunScore.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/RunScore.java @@ -68,4 +68,5 @@ class RunScore { public int getScore() { return score; } + } diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/SubCellCommandLists.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/SubCellCommandLists.java new file mode 100644 index 000000000..d2c478780 --- /dev/null +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/SubCellCommandLists.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +package com.smartdevicelink.managers.screen.menu; + +import java.util.List; + +class SubCellCommandLists { + + private RunScore listsScore; + private String menuTitle; + private List oldList, newList; + + SubCellCommandLists(String menuTitle, RunScore listsScore, List oldList, List newList){ + setMenuTitle(menuTitle); + setListsScore(listsScore); + setOldList(oldList); + setNewList(newList); + } + + private void setMenuTitle(String menuTitle) { + this.menuTitle = menuTitle; + } + + String getMenuTitle() { + return menuTitle; + } + + private void setListsScore(RunScore listsScore){ + this.listsScore = listsScore; + } + + RunScore getListsScore() { + return listsScore; + } + + private void setOldList(List oldList) { + this.oldList = oldList; + } + + List getOldList() { + return oldList; + } + + private void setNewList(List newList) { + this.newList = newList; + } + + List getNewList() { + return newList; + } +} -- cgit v1.2.1 From ab04f55226545ed171c664cc958fa45d357edaeb Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Wed, 22 May 2019 14:44:45 -0400 Subject: on initial looks, its working --- .../managers/screen/menu/BaseMenuManager.java | 208 ++++++++++++++++++--- 1 file changed, 182 insertions(+), 26 deletions(-) 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 fabedcb9e..521cef124 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 @@ -304,18 +304,6 @@ abstract class BaseMenuManager extends BaseSubManager { // OTHER - private void transferIdsToKeeps(List keeps){ - for (int z = 0; z < oldMenuCells.size(); z++) { - MenuCell oldCell = oldMenuCells.get(z); - for (int i = 0; i < keeps.size(); i++) { - MenuCell keptCell = keeps.get(i); - if (oldCell.equals(keptCell)) { - keptCell.setCellId(oldCell.getCellId()); - } - } - } - } - private void sendDynamicRootMenu(List deleteCommands,final List updatedCells){ deleteMenuCells(deleteCommands,new CompletionListener() { @Override @@ -360,18 +348,6 @@ abstract class BaseMenuManager extends BaseSubManager { // LOG STUFF - TO BE REMOVED Log.i("MENU SUB COMP", "Both Old and New: "+keptCell.getTitle() + " have sub cells. Run compare"); - // FOR EACH CELL WITH SUB CELLS, PRINT OUT INFO FOR THEIR SUBMENU - /*if (keptCell.getSubCells() != null && keptCell.getSubCells().size() > 0) { - for (MenuCell newCell : keptCell.getSubCells()) { - Log.i("MENU NEW SUBCELL", "TITLE: " + newCell.getTitle() + " PARENT: " + newCell.getParentCellId() + " ID: " + newCell.getCellId()); - } - } - if (oldKeptCell.getSubCells() != null && oldKeptCell.getSubCells().size() > 0) { - for (MenuCell oldCell : oldKeptCell.getSubCells()) { - Log.i("MENU OLD SUBCELL", "TITLE: " + oldCell.getTitle() + " PARENT: " + oldCell.getParentCellId() + " ID: " + oldCell.getCellId()); - } - }*/ - // ACTUAL LOGIC RunScore subScore = compareOldAndNewLists(oldKeptCell.getSubCells(), keptCell.getSubCells()); @@ -390,10 +366,74 @@ abstract class BaseMenuManager extends BaseSubManager { createSubMenuDynamicCommands(commandLists); } - private void createSubMenuDynamicCommands(List commandLists){ + private void createSubMenuDynamicCommands(final List commandLists){ + + // break out + if (commandLists.size() == 0){ + if (inProgressUpdate != null){ + inProgressUpdate = null; + } + + /*if (hasQueuedUpdate) { + //setMenuCells(waitingUpdateMenuCells); + hasQueuedUpdate = false; + }*/ + Log.i("MENU", "HOORAY ALL DYNAMIC SUB MENU STUFF DONE"); + return; + } + + SubCellCommandLists commandList = commandLists.remove(0); + + RunScore score = commandList.getListsScore(); + List newIntArray = score.getCurrentMenu(); + List oldIntArray = score.getOldMenu(); + List oldCells = commandList.getOldList(); + List newCells = commandList.getNewList(); + List subCellKeepsNew = new ArrayList<>(); + + List deleteCommands; + + // Set up deletes + List deletes = new ArrayList<>(); + for (int x = 0; x < oldIntArray.size(); x++) { + Integer old = oldIntArray.get(x); + if (old.equals(MARKED_FOR_DELETION)){ + // grab cell to send to function to create delete commands + deletes.add(oldCells.get(x)); + } + } + // create the delete commands + deleteCommands = deleteCommandsForCells(deletes); - + // Set up the adds + List adds = new ArrayList<>(); + for (int x = 0; x < newIntArray.size(); x++) { + Integer newInt = newIntArray.get(x); + if (newInt.equals(MARKED_FOR_ADDITION)){ + // grab cell to send to function to create add commands + adds.add(newCells.get(x)); + } else if (newInt.equals(KEEP)){ + subCellKeepsNew.add(newCells.get(x)); + } + } + final List addsWithNewIds = updateIdsOnDynamicSubCells(adds); + transferIdsToSubKeeps(oldCells, subCellKeepsNew); + deleteMenuCells(deleteCommands,new CompletionListener() { + @Override + public void onComplete(boolean success) { + if (addsWithNewIds != null && addsWithNewIds.size() > 0) { + sendDynamicSubMenu(addsWithNewIds, new CompletionListener() { + @Override + public void onComplete(boolean success) { + createSubMenuDynamicCommands(commandLists); + } + }); + } else{ + createSubMenuDynamicCommands(commandLists); + } + } + }); } @@ -544,6 +584,26 @@ abstract class BaseMenuManager extends BaseSubManager { return null; } + private List updateIdsOnDynamicSubCells(List dynamicCells){ + if (menuCells != null && menuCells.size() > 0 && dynamicCells != null && dynamicCells.size() > 0) { + for (int z = 0; z < menuCells.size(); z++) { + MenuCell mainCell = menuCells.get(z); + for (int i = 0; i < dynamicCells.size(); i++) { + MenuCell dynamicCell = dynamicCells.get(i); + if (mainCell.equals(dynamicCell)) { + int newId = ++lastMenuId; + Log.i("MENU", "UPDATING ID ON DYNAMIC CELL: " + dynamicCell.getTitle() + " TO: " + newId); + dynamicCells.get(i).setParentCellId(menuCells.get(z).getCellId()); + menuCells.get(z).setCellId(newId); + dynamicCells.get(i).setCellId(newId); + } + } + } + return dynamicCells; + } + return null; + } + private void updateIdsOnMenuCells(List cells, int parentId){ for (MenuCell cell : cells) { int newId = ++lastMenuId; @@ -556,6 +616,30 @@ abstract class BaseMenuManager extends BaseSubManager { } } + private void transferIdsToKeeps(List keeps){ + for (int z = 0; z < oldMenuCells.size(); z++) { + MenuCell oldCell = oldMenuCells.get(z); + for (int i = 0; i < keeps.size(); i++) { + MenuCell keptCell = keeps.get(i); + if (oldCell.equals(keptCell)) { + keptCell.setCellId(oldCell.getCellId()); + } + } + } + } + + private void transferIdsToSubKeeps(List old, List keeps){ + for (int z = 0; z < old.size(); z++) { + MenuCell oldCell = old.get(z); + for (int i = 0; i < keeps.size(); i++) { + MenuCell keptCell = keeps.get(i); + if (oldCell.equals(keptCell)) { + keptCell.setCellId(oldCell.getCellId()); + } + } + } + } + // DELETES List deleteCommandsForCells(List cells){ @@ -913,6 +997,78 @@ abstract class BaseMenuManager extends BaseSubManager { }); } + private void sendDynamicSubMenu(final List menu, final CompletionListener listener){ + + if (menu.size() == 0){ + if (listener != null){ + // This can be considered a success if the user was clearing out their menu + listener.onComplete(true); + } + return; + } + + List mainMenuCommands; + final List subMenuCommands; + + for (MenuCell cell : menu){ + Log.i("SUB MENU CELL SEND: ", cell.getTitle()+ " ID: "+ cell.getCellId() + " PARENT ID: "+ cell.getParentCellId()); + } + + if (findAllArtworksToBeUploadedFromCells(menu).size() > 0 || !supportsImages()){ + // Send artwork-less menu + mainMenuCommands = mainMenuCommandsForCells(menu, false); + subMenuCommands = subMenuCommandsForCells(menu, false); + } else { + mainMenuCommands = mainMenuCommandsForCells(menu, true); + subMenuCommands = subMenuCommandsForCells(menu, true); + } + + for (RPCRequest request : mainMenuCommands){ + try { + Log.i("MENU ADD COMMAND: ", request.serializeJSON().toString()); + } catch (JSONException e) { + e.printStackTrace(); + } + } + + for (RPCRequest request : subMenuCommands){ + try { + Log.i("MENU SUB COMMAND: ", request.serializeJSON().toString()); + } catch (JSONException e) { + e.printStackTrace(); + } + } + + internalInterface.sendSequentialRPCs(mainMenuCommands, new OnMultipleRequestListener() { + @Override + public void onUpdate(int remainingRequests) { + // nothing here + } + + @Override + public void onFinished() { + + if (listener != null){ + listener.onComplete(true); + } + } + + @Override + public void onError(int correlationId, Result resultCode, String info) { + DebugTool.logError("Result: " + resultCode.toString() + " Info: " + info); + } + + @Override + public void onResponse(int correlationId, RPCResponse response) { + try { + DebugTool.logInfo("Dynamic Sub Menu response: " + response.serializeJSON().toString()); + } catch (JSONException e) { + e.printStackTrace(); + } + } + }); + } + // DELETE OLD MENU ITEMS private void deleteRootMenu(final CompletionListener listener){ -- cgit v1.2.1 From b9472756d1570f3f66d524cf3b9cc4cfa70f5652 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Wed, 22 May 2019 16:31:18 -0400 Subject: more cleanup of menu manager class --- .../managers/screen/menu/BaseMenuManager.java | 43 +++++----------------- 1 file changed, 9 insertions(+), 34 deletions(-) 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 521cef124..41bc8e119 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 @@ -271,7 +271,7 @@ abstract class BaseMenuManager extends BaseSubManager { if (old.equals(MARKED_FOR_DELETION)){ // grab cell to send to function to create delete commands deletes.add(oldMenuCells.get(x)); - } else if (old.equals(KEEP)){ + } else if (old.equals(KEEP)) { keepsOld.add(oldMenuCells.get(x)); } } @@ -345,9 +345,6 @@ abstract class BaseMenuManager extends BaseSubManager { MenuCell oldKeptCell = keepsOld.get(i); if (oldKeptCell.getSubCells() != null && oldKeptCell.getSubCells().size() > 0 && keptCell.getSubCells() != null && keptCell.getSubCells().size() > 0){ - - // LOG STUFF - TO BE REMOVED - Log.i("MENU SUB COMP", "Both Old and New: "+keptCell.getTitle() + " have sub cells. Run compare"); // ACTUAL LOGIC RunScore subScore = compareOldAndNewLists(oldKeptCell.getSubCells(), keptCell.getSubCells()); @@ -355,14 +352,8 @@ abstract class BaseMenuManager extends BaseSubManager { SubCellCommandLists commandList = new SubCellCommandLists(oldKeptCell.getTitle(), subScore, oldKeptCell.getSubCells(), keptCell.getSubCells()); commandLists.add(commandList); } - } } - - for (SubCellCommandLists commandList : commandLists){ - Log.i("MENU SUB COMMAND LIST: ", "TITLE: "+ commandList.getMenuTitle()+ " RunScore: "+ commandList.getListsScore().getScore()); - } - createSubMenuDynamicCommands(commandLists); } @@ -374,10 +365,11 @@ abstract class BaseMenuManager extends BaseSubManager { inProgressUpdate = null; } - /*if (hasQueuedUpdate) { - //setMenuCells(waitingUpdateMenuCells); + if (hasQueuedUpdate) { + DebugTool.logInfo("Menu Manager has waiting updates, sending now"); + setMenuCells(waitingUpdateMenuCells); hasQueuedUpdate = false; - }*/ + } Log.i("MENU", "HOORAY ALL DYNAMIC SUB MENU STUFF DONE"); return; } @@ -426,18 +418,18 @@ abstract class BaseMenuManager extends BaseSubManager { sendDynamicSubMenu(addsWithNewIds, new CompletionListener() { @Override public void onComplete(boolean success) { + // recurse createSubMenuDynamicCommands(commandLists); } }); } else{ + // no add commands to send, recurse createSubMenuDynamicCommands(commandLists); } } }); - } - // OTHER HELPER METHODS: // COMPARISONS @@ -451,8 +443,6 @@ abstract class BaseMenuManager extends BaseSubManager { RunScore bestScore = compareOldAndNewLists(oldCells, newCells); Log.i("MENU Best Run Score", String.valueOf(bestScore.getScore())); - Log.i("MENU Best Run OLD", bestScore.getOldMenu().toString()); - Log.i("MENU Best Run NEW", bestScore.getCurrentMenu().toString()); return bestScore; } @@ -592,7 +582,7 @@ abstract class BaseMenuManager extends BaseSubManager { MenuCell dynamicCell = dynamicCells.get(i); if (mainCell.equals(dynamicCell)) { int newId = ++lastMenuId; - Log.i("MENU", "UPDATING ID ON DYNAMIC CELL: " + dynamicCell.getTitle() + " TO: " + newId); + Log.i("MENU", "UPDATING ID ON DYNAMIC SUB CELL: " + dynamicCell.getTitle() + " TO: " + newId); dynamicCells.get(i).setParentCellId(menuCells.get(z).getCellId()); menuCells.get(z).setCellId(newId); dynamicCells.get(i).setCellId(newId); @@ -735,8 +725,6 @@ abstract class BaseMenuManager extends BaseSubManager { if (cells != null && cells.size() > 0 && command != null) { for (MenuCell cell : cells) { - Log.i("MENU COMMANDS", "CHECKING CELL: "+ cell.getTitle() + " With Command ID: "+ cell.getCellId()); - if (cell.getCellId() == command.getCmdID() && cell.getMenuSelectionListener() != null) { cell.getMenuSelectionListener().onTriggered(command.getTriggerSource()); return true; @@ -911,8 +899,6 @@ abstract class BaseMenuManager extends BaseSubManager { @Override public void onFinished() { - oldMenuCells = new ArrayList<>(menuCells); - if (subMenuCommands.size() > 0) { sendSubMenuCommands(subMenuCommands, listener); DebugTool.logInfo("Finished sending main menu commands. Sending sub menu commands."); @@ -1008,7 +994,6 @@ abstract class BaseMenuManager extends BaseSubManager { } List mainMenuCommands; - final List subMenuCommands; for (MenuCell cell : menu){ Log.i("SUB MENU CELL SEND: ", cell.getTitle()+ " ID: "+ cell.getCellId() + " PARENT ID: "+ cell.getParentCellId()); @@ -1017,23 +1002,13 @@ abstract class BaseMenuManager extends BaseSubManager { if (findAllArtworksToBeUploadedFromCells(menu).size() > 0 || !supportsImages()){ // Send artwork-less menu mainMenuCommands = mainMenuCommandsForCells(menu, false); - subMenuCommands = subMenuCommandsForCells(menu, false); } else { mainMenuCommands = mainMenuCommandsForCells(menu, true); - subMenuCommands = subMenuCommandsForCells(menu, true); } for (RPCRequest request : mainMenuCommands){ try { - Log.i("MENU ADD COMMAND: ", request.serializeJSON().toString()); - } catch (JSONException e) { - e.printStackTrace(); - } - } - - for (RPCRequest request : subMenuCommands){ - try { - Log.i("MENU SUB COMMAND: ", request.serializeJSON().toString()); + Log.i("SUB MENU ADD COMMAND: ", request.serializeJSON().toString()); } catch (JSONException e) { e.printStackTrace(); } -- cgit v1.2.1 From e5d14eec4e72a1dd1cd93a332a414576461951ce Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Thu, 23 May 2019 09:58:31 -0400 Subject: allow dev to clear menu by sending empty array --- .../managers/screen/menu/BaseMenuManager.java | 28 ++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) 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 41bc8e119..fcc35fde0 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 @@ -250,11 +250,35 @@ abstract class BaseMenuManager extends BaseSubManager { this.oldMenuCells = new ArrayList<>(menuCells); sendInitialMenu(); }else{ - // lets dynamically update the root menu - dynamicUpdateRoot(rootScore); + if (menuCells.size() == 0 && (oldMenuCells != null && oldMenuCells.size() > 0)){ + // the dev wants to clear the menu. We have old cells and an empty array of new ones. + deleteMenuWhenNewCellsEmpty(); + }else { + // lets dynamically update the root menu + dynamicUpdateRoot(rootScore); + } } } + private void deleteMenuWhenNewCellsEmpty(){ + deleteMenuCells(deleteCommandsForCells(oldMenuCells), new CompletionListener() { + @Override + public void onComplete(boolean success) { + inProgressUpdate = null; + + if (!success){ + DebugTool.logError("Error Sending Current Menu"); + }else{ + DebugTool.logInfo("Successfully Cleared Menu"); + } + oldMenuCells = null; + if (hasQueuedUpdate){ + hasQueuedUpdate = false; + } + } + }); + } + private void dynamicUpdateRoot(RunScore bestRootScore){ // we need to run through the keeps and see if they have subCells, as they also need to be run -- cgit v1.2.1 From 41ef2970e4627059aaf53d7ba28ef23b14d8ccd9 Mon Sep 17 00:00:00 2001 From: Bilal Alsharifi Date: Thu, 23 May 2019 11:03:19 -0400 Subject: Update gradle --- .travis.yml | 4 ++-- android/build.gradle | 2 +- android/gradle/wrapper/gradle-wrapper.properties | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6c25dd665..96bbd4a27 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,7 @@ android: - ndk-bundle # The BuildTools version used by your project - - build-tools-27.0.3 + - build-tools-28.0.3 # The SDK version used to compile your project - android-28 @@ -52,7 +52,7 @@ script: - ./javaEE/gradlew -p ./javaEE test before_install: - - echo yes | sdkmanager "build-tools;27.0.3" + - echo yes | sdkmanager "build-tools;28.0.3" after_success: - bash <(curl -s https://codecov.io/bash) diff --git a/android/build.gradle b/android/build.gradle index 800d3be0e..4bb0929a1 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -7,7 +7,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.1.3' + classpath 'com.android.tools.build:gradle:3.4.1' // NOTE: Do not place your application dependencies here; they belong diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties index edbfc86a9..75b5534e8 100644 --- a/android/gradle/wrapper/gradle-wrapper.properties +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sun Apr 8 12:14:33 EDT 2018 +#Thu May 23 10:57:13 EDT 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip \ No newline at end of file +distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip -- cgit v1.2.1 From dbc6283fb9e6c360099c5ca6c9eccc0bb23007e5 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Thu, 23 May 2019 11:39:26 -0400 Subject: cleaning and re-naming --- .../managers/screen/menu/BaseMenuManager.java | 145 ++++++--------------- 1 file changed, 40 insertions(+), 105 deletions(-) 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 fcc35fde0..c14b3536f 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 @@ -33,7 +33,6 @@ package com.smartdevicelink.managers.screen.menu; import android.support.annotation.NonNull; -import android.util.Log; import com.smartdevicelink.managers.BaseSubManager; import com.smartdevicelink.managers.CompletionListener; @@ -199,12 +198,12 @@ abstract class BaseMenuManager extends BaseSubManager { DebugTool.logInfo("Menu Artworks Uploaded"); } // proceed - updateRootMenu(); + updateMenuAndDetermineBestUpdateMethod(); } }); }else{ // No Artworks to be uploaded, send off - updateRootMenu(); + updateMenuAndDetermineBestUpdateMethod(); } } @@ -220,7 +219,7 @@ abstract class BaseMenuManager extends BaseSubManager { // ROOT MENU - private void updateRootMenu(){ + private void updateMenuAndDetermineBestUpdateMethod(){ if (currentHMILevel == null || currentHMILevel.equals(HMILevel.HMI_NONE) || currentSystemContext.equals(SystemContext.SYSCTXT_MENU)){ // We are in NONE or the menu is in use, bail out of here @@ -238,7 +237,7 @@ abstract class BaseMenuManager extends BaseSubManager { } // run the lists through the new algorithm - RunScore rootScore = createDynamicUpdate(oldMenuCells, menuCells); + RunScore rootScore = runMenuCompareAlgorithm(oldMenuCells, menuCells); if (rootScore == null){ // send initial menu (score will return null) @@ -255,13 +254,13 @@ abstract class BaseMenuManager extends BaseSubManager { deleteMenuWhenNewCellsEmpty(); }else { // lets dynamically update the root menu - dynamicUpdateRoot(rootScore); + dynamicallyUpdateRootMenu(rootScore); } } } private void deleteMenuWhenNewCellsEmpty(){ - deleteMenuCells(deleteCommandsForCells(oldMenuCells), new CompletionListener() { + sendDeleteRPCs(createDeleteRPCsForCells(oldMenuCells), new CompletionListener() { @Override public void onComplete(boolean success) { inProgressUpdate = null; @@ -279,7 +278,7 @@ abstract class BaseMenuManager extends BaseSubManager { }); } - private void dynamicUpdateRoot(RunScore bestRootScore){ + private void dynamicallyUpdateRootMenu(RunScore bestRootScore){ // we need to run through the keeps and see if they have subCells, as they also need to be run // through the compare function. @@ -300,7 +299,7 @@ abstract class BaseMenuManager extends BaseSubManager { } } // create the delete commands - deleteCommands = deleteCommandsForCells(deletes); + deleteCommands = createDeleteRPCsForCells(deletes); // Set up the adds List adds = new ArrayList<>(); @@ -315,24 +314,25 @@ abstract class BaseMenuManager extends BaseSubManager { } } List addsWithNewIds = updateIdsOnDynamicCells(adds); - transferIdsToKeeps(keepsNew); + // this is needed for the onCommands to still work + transferIdsToKeptCells(oldMenuCells, keepsNew); if (addsWithNewIds != null && addsWithNewIds.size() > 0){ - Log.i("MENU", "THERE ARE ROOT MENU UPDATES. SEND THESE OFF"); - sendDynamicRootMenu(deleteCommands, addsWithNewIds); + DebugTool.logInfo("Sending root menu updates"); + sendDynamicRootMenuRPCs(deleteCommands, addsWithNewIds); }else{ - Log.i("MENU", "EVERYTHING IS A KEEP. LETS CHECK THE SUB MENUS"); - sendSubMenuUpdates(); + DebugTool.logInfo("All root menu items are kept. Check the sub menus"); + runSubMenuCompareAlgorithm(); } } // OTHER - private void sendDynamicRootMenu(List deleteCommands,final List updatedCells){ - deleteMenuCells(deleteCommands,new CompletionListener() { + private void sendDynamicRootMenuRPCs(List deleteCommands,final List updatedCells){ + sendDeleteRPCs(deleteCommands,new CompletionListener() { @Override public void onComplete(boolean success) { - sendMenu(updatedCells, new CompletionListener() { + createAndSendMenuCellRPCs(updatedCells, new CompletionListener() { @Override public void onComplete(boolean success) { inProgressUpdate = null; @@ -354,7 +354,7 @@ abstract class BaseMenuManager extends BaseSubManager { // SUB MENUS // This is called in the listener in the sendMenu and sendSubMenuCommands Methods - private void sendSubMenuUpdates(){ + private void runSubMenuCompareAlgorithm(){ // any cells that were re-added have their sub-cells added with them // at this point all we care about are the cells that were deemed equal and kept. if (keepsNew == null || keepsNew.size() == 0) { @@ -394,17 +394,22 @@ abstract class BaseMenuManager extends BaseSubManager { setMenuCells(waitingUpdateMenuCells); hasQueuedUpdate = false; } - Log.i("MENU", "HOORAY ALL DYNAMIC SUB MENU STUFF DONE"); + DebugTool.logInfo("All menu updates, including sub menus - done."); return; } SubCellCommandLists commandList = commandLists.remove(0); + // grab the scores RunScore score = commandList.getListsScore(); List newIntArray = score.getCurrentMenu(); List oldIntArray = score.getOldMenu(); + + // Grab the sub-menus from the parent cell List oldCells = commandList.getOldList(); List newCells = commandList.getNewList(); + + // Create the list for the adds List subCellKeepsNew = new ArrayList<>(); List deleteCommands; @@ -419,7 +424,7 @@ abstract class BaseMenuManager extends BaseSubManager { } } // create the delete commands - deleteCommands = deleteCommandsForCells(deletes); + deleteCommands = createDeleteRPCsForCells(deletes); // Set up the adds List adds = new ArrayList<>(); @@ -433,9 +438,10 @@ abstract class BaseMenuManager extends BaseSubManager { } } final List addsWithNewIds = updateIdsOnDynamicSubCells(adds); - transferIdsToSubKeeps(oldCells, subCellKeepsNew); + // this is needed for the onCommands to still work + transferIdsToKeptCells(oldCells, subCellKeepsNew); - deleteMenuCells(deleteCommands,new CompletionListener() { + sendDeleteRPCs(deleteCommands,new CompletionListener() { @Override public void onComplete(boolean success) { if (addsWithNewIds != null && addsWithNewIds.size() > 0) { @@ -458,15 +464,14 @@ abstract class BaseMenuManager extends BaseSubManager { // COMPARISONS - private RunScore createDynamicUpdate(List oldCells, List newCells){ + private RunScore runMenuCompareAlgorithm(List oldCells, List newCells){ if (oldCells == null || oldCells.size() == 0){ return null; } RunScore bestScore = compareOldAndNewLists(oldCells, newCells); - - Log.i("MENU Best Run Score", String.valueOf(bestScore.getScore())); + DebugTool.logInfo("Best menu run score: "+ bestScore.getScore()); return bestScore; } @@ -583,7 +588,6 @@ abstract class BaseMenuManager extends BaseSubManager { MenuCell dynamicCell = dynamicCells.get(i); if (mainCell.equals(dynamicCell)) { int newId = ++lastMenuId; - Log.i("MENU", "UPDATING ID ON DYNAMIC CELL: " + dynamicCell.getTitle() + " TO: " + newId); menuCells.get(z).setCellId(newId); dynamicCells.get(i).setCellId(newId); @@ -606,7 +610,6 @@ abstract class BaseMenuManager extends BaseSubManager { MenuCell dynamicCell = dynamicCells.get(i); if (mainCell.equals(dynamicCell)) { int newId = ++lastMenuId; - Log.i("MENU", "UPDATING ID ON DYNAMIC SUB CELL: " + dynamicCell.getTitle() + " TO: " + newId); dynamicCells.get(i).setParentCellId(menuCells.get(z).getCellId()); menuCells.get(z).setCellId(newId); dynamicCells.get(i).setCellId(newId); @@ -621,7 +624,6 @@ abstract class BaseMenuManager extends BaseSubManager { private void updateIdsOnMenuCells(List cells, int parentId){ for (MenuCell cell : cells) { int newId = ++lastMenuId; - Log.i("MENU", "UPDATING ID ON CELL: " + cell.getTitle() + " TO: " + newId); cell.setCellId(newId); cell.setParentCellId(parentId); if (cell.getSubCells() != null && cell.getSubCells().size() > 0) { @@ -630,19 +632,7 @@ abstract class BaseMenuManager extends BaseSubManager { } } - private void transferIdsToKeeps(List keeps){ - for (int z = 0; z < oldMenuCells.size(); z++) { - MenuCell oldCell = oldMenuCells.get(z); - for (int i = 0; i < keeps.size(); i++) { - MenuCell keptCell = keeps.get(i); - if (oldCell.equals(keptCell)) { - keptCell.setCellId(oldCell.getCellId()); - } - } - } - } - - private void transferIdsToSubKeeps(List old, List keeps){ + private void transferIdsToKeptCells(List old, List keeps){ for (int z = 0; z < old.size(); z++) { MenuCell oldCell = old.get(z); for (int i = 0; i < keeps.size(); i++) { @@ -656,10 +646,9 @@ abstract class BaseMenuManager extends BaseSubManager { // DELETES - List deleteCommandsForCells(List cells){ + private List createDeleteRPCsForCells(List cells){ List deletes = new ArrayList<>(); for (MenuCell cell : cells){ - Log.i("MENU CELL DELETE", "NAME: "+ cell.getTitle()); if (cell.getSubCells() == null){ DeleteCommand delete = new DeleteCommand(cell.getCellId()); deletes.add(delete); @@ -682,7 +671,6 @@ abstract class BaseMenuManager extends BaseSubManager { for (int i = 0; i < cellsToAdd.size(); i++) { MenuCell addCell = cellsToAdd.get(i); if (mainCell.equals(addCell)) { - Log.i("MENU CELL ADD", "NAME: "+ addCell.getTitle()+ " POSITION: "+ z); if (addCell.getSubCells() != null && addCell.getSubCells().size() > 0) { builtCommands.add(subMenuCommandForMenuCell(addCell, shouldHaveArtwork, z)); } else { @@ -718,7 +706,6 @@ abstract class BaseMenuManager extends BaseSubManager { builtCommands.add(commandForMenuCell(cell, shouldHaveArtwork, i)); } } - return builtCommands; } @@ -849,7 +836,7 @@ abstract class BaseMenuManager extends BaseSubManager { deleteRootMenu(new CompletionListener() { @Override public void onComplete(boolean success) { - sendMenu(menuCells, new CompletionListener() { + createAndSendMenuCellRPCs(menuCells, new CompletionListener() { @Override public void onComplete(boolean success) { inProgressUpdate = null; @@ -868,7 +855,7 @@ abstract class BaseMenuManager extends BaseSubManager { }); } - private void sendMenu(final List menu, final CompletionListener listener){ + private void createAndSendMenuCellRPCs(final List menu, final CompletionListener listener){ if (menu.size() == 0){ if (listener != null){ @@ -881,10 +868,6 @@ abstract class BaseMenuManager extends BaseSubManager { List mainMenuCommands; final List subMenuCommands; - for (MenuCell cell : menu){ - Log.i("MENU CELL SEND: ", cell.getTitle()+ " ID: "+ cell.getCellId() + " PARENT ID: "+ cell.getParentCellId()); - } - if (findAllArtworksToBeUploadedFromCells(menu).size() > 0 || !supportsImages()){ // Send artwork-less menu mainMenuCommands = mainMenuCommandsForCells(menu, false); @@ -894,22 +877,6 @@ abstract class BaseMenuManager extends BaseSubManager { subMenuCommands = subMenuCommandsForCells(menu, true); } - for (RPCRequest request : mainMenuCommands){ - try { - Log.i("MENU ADD COMMAND: ", request.serializeJSON().toString()); - } catch (JSONException e) { - e.printStackTrace(); - } - } - - for (RPCRequest request : subMenuCommands){ - try { - Log.i("MENU SUB COMMAND: ", request.serializeJSON().toString()); - } catch (JSONException e) { - e.printStackTrace(); - } - } - // add all built commands to inProgressUpdate inProgressUpdate = new ArrayList<>(mainMenuCommands); inProgressUpdate.addAll(subMenuCommands); @@ -929,7 +896,7 @@ abstract class BaseMenuManager extends BaseSubManager { } else { if (keepsNew != null && keepsNew.size() > 0){ - sendSubMenuUpdates(); + runSubMenuCompareAlgorithm(); }else { inProgressUpdate = null; DebugTool.logInfo("Finished sending main menu commands."); @@ -955,18 +922,6 @@ abstract class BaseMenuManager extends BaseSubManager { private void sendSubMenuCommands(List commands, final CompletionListener listener){ - if (commands != null){ - for (RPCRequest command: commands){ - try { - Log.i("MENU SUB COMMAND", command.serializeJSON().toString()); - } catch (JSONException e) { - e.printStackTrace(); - } - } - }else{ - Log.e("MENU", "SUB MENU COMMANDS NULL"); - } - internalInterface.sendSequentialRPCs(commands, new OnMultipleRequestListener() { @Override public void onUpdate(int remainingRequests) { @@ -977,7 +932,7 @@ abstract class BaseMenuManager extends BaseSubManager { public void onFinished() { if (keepsNew != null && keepsNew.size() > 0){ - sendSubMenuUpdates(); + runSubMenuCompareAlgorithm(); }else { DebugTool.logInfo("Finished Updating Menu"); inProgressUpdate = null; @@ -1019,10 +974,6 @@ abstract class BaseMenuManager extends BaseSubManager { List mainMenuCommands; - for (MenuCell cell : menu){ - Log.i("SUB MENU CELL SEND: ", cell.getTitle()+ " ID: "+ cell.getCellId() + " PARENT ID: "+ cell.getParentCellId()); - } - if (findAllArtworksToBeUploadedFromCells(menu).size() > 0 || !supportsImages()){ // Send artwork-less menu mainMenuCommands = mainMenuCommandsForCells(menu, false); @@ -1030,14 +981,6 @@ abstract class BaseMenuManager extends BaseSubManager { mainMenuCommands = mainMenuCommandsForCells(menu, true); } - for (RPCRequest request : mainMenuCommands){ - try { - Log.i("SUB MENU ADD COMMAND: ", request.serializeJSON().toString()); - } catch (JSONException e) { - e.printStackTrace(); - } - } - internalInterface.sendSequentialRPCs(mainMenuCommands, new OnMultipleRequestListener() { @Override public void onUpdate(int remainingRequests) { @@ -1072,18 +1015,18 @@ abstract class BaseMenuManager extends BaseSubManager { private void deleteRootMenu(final CompletionListener listener){ - if (oldMenuCells != null && oldMenuCells.size() == 0) { + if (oldMenuCells == null || oldMenuCells.size() == 0) { if (listener != null){ // technically this method is successful if there's nothing to delete DebugTool.logInfo("No old cells to delete, returning"); listener.onComplete(true); } - return; + } else { + sendDeleteRPCs(createDeleteRPCsForCells(oldMenuCells), listener); } - deleteMenuCells(deleteCommandsForCells(oldMenuCells), listener); } - private void deleteMenuCells(List deleteCommands, final CompletionListener listener){ + private void sendDeleteRPCs(List deleteCommands, final CompletionListener listener){ if (oldMenuCells != null && oldMenuCells.size() == 0) { if (listener != null){ // technically this method is successful if there's nothing to delete @@ -1102,14 +1045,6 @@ abstract class BaseMenuManager extends BaseSubManager { return; } - for (RPCRequest delete : deleteCommands){ - try { - Log.i("MENU CELL DELETE: ", delete.serializeJSON().toString()); - } catch (JSONException e) { - e.printStackTrace(); - } - } - internalInterface.sendRequests(deleteCommands, new OnMultipleRequestListener() { @Override public void onUpdate(int remainingRequests) { -- cgit v1.2.1 From 198682e2e09d2da03b31124c75e766323673fd96 Mon Sep 17 00:00:00 2001 From: Bilal Alsharifi Date: Thu, 23 May 2019 11:58:54 -0400 Subject: Update gradle --- android/build.gradle | 2 +- android/gradle/wrapper/gradle-wrapper.properties | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 4bb0929a1..f94362a81 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -7,7 +7,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.4.1' + classpath 'com.android.tools.build:gradle:3.3.1' // NOTE: Do not place your application dependencies here; they belong diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties index 75b5534e8..567cd660e 100644 --- a/android/gradle/wrapper/gradle-wrapper.properties +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Thu May 23 10:57:13 EDT 2019 +#Sun Jan 20 22:30:48 EST 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip \ No newline at end of file -- cgit v1.2.1 From a8302f56789f1436e3cd0d0cd8df7f1b57f32f32 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Thu, 23 May 2019 13:26:27 -0400 Subject: dynamic submenu list ordering fixed --- .../managers/screen/menu/BaseMenuManager.java | 106 ++++++++++++++++----- 1 file changed, 83 insertions(+), 23 deletions(-) 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 c14b3536f..a4904c3ec 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 @@ -33,6 +33,7 @@ package com.smartdevicelink.managers.screen.menu; import android.support.annotation.NonNull; +import android.util.Log; import com.smartdevicelink.managers.BaseSubManager; import com.smartdevicelink.managers.CompletionListener; @@ -315,7 +316,7 @@ abstract class BaseMenuManager extends BaseSubManager { } List addsWithNewIds = updateIdsOnDynamicCells(adds); // this is needed for the onCommands to still work - transferIdsToKeptCells(oldMenuCells, keepsNew); + transferIdsToKeptCells(keepsNew); if (addsWithNewIds != null && addsWithNewIds.size() > 0){ DebugTool.logInfo("Sending root menu updates"); @@ -373,6 +374,7 @@ abstract class BaseMenuManager extends BaseSubManager { RunScore subScore = compareOldAndNewLists(oldKeptCell.getSubCells(), keptCell.getSubCells()); if (subScore != null){ + DebugTool.logInfo("Sub menu Run Score: "+ oldKeptCell.getTitle()+ " Score: "+ subScore.getScore()); SubCellCommandLists commandList = new SubCellCommandLists(oldKeptCell.getTitle(), subScore, oldKeptCell.getSubCells(), keptCell.getSubCells()); commandLists.add(commandList); } @@ -406,8 +408,8 @@ abstract class BaseMenuManager extends BaseSubManager { List oldIntArray = score.getOldMenu(); // Grab the sub-menus from the parent cell - List oldCells = commandList.getOldList(); - List newCells = commandList.getNewList(); + final List oldCells = commandList.getOldList(); + final List newCells = commandList.getNewList(); // Create the list for the adds List subCellKeepsNew = new ArrayList<>(); @@ -437,23 +439,23 @@ abstract class BaseMenuManager extends BaseSubManager { subCellKeepsNew.add(newCells.get(x)); } } - final List addsWithNewIds = updateIdsOnDynamicSubCells(adds); + final List addsWithNewIds = updateIdsOnDynamicSubCells(oldCells, adds); // this is needed for the onCommands to still work - transferIdsToKeptCells(oldCells, subCellKeepsNew); + transferIdsToKeptSubCells(oldCells, subCellKeepsNew); sendDeleteRPCs(deleteCommands,new CompletionListener() { @Override public void onComplete(boolean success) { if (addsWithNewIds != null && addsWithNewIds.size() > 0) { - sendDynamicSubMenu(addsWithNewIds, new CompletionListener() { + createAndSendDynamicSubMenuRPCs(newCells, addsWithNewIds, new CompletionListener() { @Override public void onComplete(boolean success) { - // recurse + // recurse through next sub list createSubMenuDynamicCommands(commandLists); } }); } else{ - // no add commands to send, recurse + // no add commands to send, recurse through next sub list createSubMenuDynamicCommands(commandLists); } } @@ -602,16 +604,16 @@ abstract class BaseMenuManager extends BaseSubManager { return null; } - private List updateIdsOnDynamicSubCells(List dynamicCells){ - if (menuCells != null && menuCells.size() > 0 && dynamicCells != null && dynamicCells.size() > 0) { - for (int z = 0; z < menuCells.size(); z++) { - MenuCell mainCell = menuCells.get(z); + private List updateIdsOnDynamicSubCells(List oldList, List dynamicCells){ + if (oldList != null && oldList.size() > 0 && dynamicCells != null && dynamicCells.size() > 0) { + for (int z = 0; z < oldList.size(); z++) { + MenuCell mainCell = oldList.get(z); for (int i = 0; i < dynamicCells.size(); i++) { MenuCell dynamicCell = dynamicCells.get(i); if (mainCell.equals(dynamicCell)) { int newId = ++lastMenuId; - dynamicCells.get(i).setParentCellId(menuCells.get(z).getCellId()); - menuCells.get(z).setCellId(newId); + dynamicCells.get(i).setParentCellId(oldList.get(z).getParentCellId()); + oldList.get(z).setCellId(newId); dynamicCells.get(i).setCellId(newId); } } @@ -632,7 +634,19 @@ abstract class BaseMenuManager extends BaseSubManager { } } - private void transferIdsToKeptCells(List old, List keeps){ + private void transferIdsToKeptCells(List keeps) { + for (int z = 0; z < oldMenuCells.size(); z++) { + MenuCell oldCell = oldMenuCells.get(z); + for (int i = 0; i < keeps.size(); i++) { + MenuCell keptCell = keeps.get(i); + if (oldCell.equals(keptCell)) { + keptCell.setCellId(oldCell.getCellId()); + } + } + } + } + + private void transferIdsToKeptSubCells(List old, List keeps) { for (int z = 0; z < old.size(); z++) { MenuCell oldCell = old.get(z); for (int i = 0; i < keeps.size(); i++) { @@ -709,6 +723,20 @@ abstract class BaseMenuManager extends BaseSubManager { return builtCommands; } + List createCommandsForDynamicSubCells(List oldMenuCells, List cells, boolean shouldHaveArtwork) { + List builtCommands = new ArrayList<>(); + for (int z = 0; z < oldMenuCells.size(); z++) { + MenuCell oldCell = oldMenuCells.get(z); + for (int i = 0; i < cells.size(); i++) { + MenuCell cell = cells.get(i); + if (cell.equals(oldCell)){ + builtCommands.add(commandForMenuCell(cell, shouldHaveArtwork, z)); + } + } + } + return builtCommands; + } + private AddCommand commandForMenuCell(MenuCell cell, boolean shouldHaveArtwork, int position){ MenuParams params = new MenuParams(cell.getTitle()); @@ -877,6 +905,22 @@ abstract class BaseMenuManager extends BaseSubManager { subMenuCommands = subMenuCommandsForCells(menu, true); } + for (RPCRequest request : mainMenuCommands){ + try { + Log.i("ADD MENU COMMAND: ", request.serializeJSON().toString()); + } catch (JSONException e) { + e.printStackTrace(); + } + } + + for (RPCRequest request : subMenuCommands){ + try { + Log.i("ADD SUB MENU COMMAND: ", request.serializeJSON().toString()); + } catch (JSONException e) { + e.printStackTrace(); + } + } + // add all built commands to inProgressUpdate inProgressUpdate = new ArrayList<>(mainMenuCommands); inProgressUpdate.addAll(subMenuCommands); @@ -891,7 +935,7 @@ abstract class BaseMenuManager extends BaseSubManager { public void onFinished() { if (subMenuCommands.size() > 0) { - sendSubMenuCommands(subMenuCommands, listener); + sendSubMenuCommandRPCs(subMenuCommands, listener); DebugTool.logInfo("Finished sending main menu commands. Sending sub menu commands."); } else { @@ -920,7 +964,7 @@ abstract class BaseMenuManager extends BaseSubManager { }); } - private void sendSubMenuCommands(List commands, final CompletionListener listener){ + private void sendSubMenuCommandRPCs(List commands, final CompletionListener listener){ internalInterface.sendSequentialRPCs(commands, new OnMultipleRequestListener() { @Override @@ -962,11 +1006,12 @@ abstract class BaseMenuManager extends BaseSubManager { }); } - private void sendDynamicSubMenu(final List menu, final CompletionListener listener){ + private void createAndSendDynamicSubMenuRPCs(List newMenu, final List adds, final CompletionListener listener){ - if (menu.size() == 0){ + if (adds.size() == 0){ if (listener != null){ // This can be considered a success if the user was clearing out their menu + DebugTool.logError("Called createAndSendDynamicSubMenuRPCs with empty menu"); listener.onComplete(true); } return; @@ -974,11 +1019,19 @@ abstract class BaseMenuManager extends BaseSubManager { List mainMenuCommands; - if (findAllArtworksToBeUploadedFromCells(menu).size() > 0 || !supportsImages()){ + if (findAllArtworksToBeUploadedFromCells(adds).size() > 0 || !supportsImages()){ // Send artwork-less menu - mainMenuCommands = mainMenuCommandsForCells(menu, false); + mainMenuCommands = createCommandsForDynamicSubCells(newMenu, adds, false); } else { - mainMenuCommands = mainMenuCommandsForCells(menu, true); + mainMenuCommands = createCommandsForDynamicSubCells(newMenu, adds, true); + } + + for (RPCRequest request : mainMenuCommands){ + try { + Log.i("DYNAMIC SUB ADD COMMAN ", request.serializeJSON().toString()); + } catch (JSONException e) { + e.printStackTrace(); + } } internalInterface.sendSequentialRPCs(mainMenuCommands, new OnMultipleRequestListener() { @@ -1045,6 +1098,14 @@ abstract class BaseMenuManager extends BaseSubManager { return; } + for (RPCRequest delete : deleteCommands){ + try { + Log.i("MENU CELL DELETE: ", delete.serializeJSON().toString()); + } catch (JSONException e) { + e.printStackTrace(); + } + } + internalInterface.sendRequests(deleteCommands, new OnMultipleRequestListener() { @Override public void onUpdate(int remainingRequests) { @@ -1061,7 +1122,6 @@ abstract class BaseMenuManager extends BaseSubManager { @Override public void onError(int correlationId, Result resultCode, String info) { - } @Override -- cgit v1.2.1 From 364c3d3faa90ddd88bf105af127cc3e761fde4f9 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Thu, 23 May 2019 13:34:06 -0400 Subject: better logging, restricting more methods --- .../managers/screen/menu/BaseMenuManager.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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 a4904c3ec..fd2a7b307 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 @@ -248,7 +248,7 @@ abstract class BaseMenuManager extends BaseSubManager { lastMenuId = menuCellIdMin; updateIdsOnMenuCells(menuCells, parentIdNotFound); this.oldMenuCells = new ArrayList<>(menuCells); - sendInitialMenu(); + createAndSendFirstMenu(); }else{ if (menuCells.size() == 0 && (oldMenuCells != null && oldMenuCells.size() > 0)){ // the dev wants to clear the menu. We have old cells and an empty array of new ones. @@ -400,7 +400,9 @@ abstract class BaseMenuManager extends BaseSubManager { return; } - SubCellCommandLists commandList = commandLists.remove(0); + final SubCellCommandLists commandList = commandLists.remove(0); + + DebugTool.logInfo("Creating and Sending Dynamic Sub Commands For Root Menu Cell: "+ commandList.getMenuTitle()); // grab the scores RunScore score = commandList.getListsScore(); @@ -451,11 +453,13 @@ abstract class BaseMenuManager extends BaseSubManager { @Override public void onComplete(boolean success) { // recurse through next sub list + DebugTool.logInfo("Finished Sending Dynamic Sub Commands For Root Menu Cell: "+ commandList.getMenuTitle()); createSubMenuDynamicCommands(commandLists); } }); } else{ // no add commands to send, recurse through next sub list + DebugTool.logInfo("Finished Sending Dynamic Sub Commands For Root Menu Cell: "+ commandList.getMenuTitle()); createSubMenuDynamicCommands(commandLists); } } @@ -723,7 +727,7 @@ abstract class BaseMenuManager extends BaseSubManager { return builtCommands; } - List createCommandsForDynamicSubCells(List oldMenuCells, List cells, boolean shouldHaveArtwork) { + private List createCommandsForDynamicSubCells(List oldMenuCells, List cells, boolean shouldHaveArtwork) { List builtCommands = new ArrayList<>(); for (int z = 0; z < oldMenuCells.size(); z++) { MenuCell oldCell = oldMenuCells.get(z); @@ -844,7 +848,7 @@ abstract class BaseMenuManager extends BaseSubManager { // SEND NEW MENU ITEMS - private void sendInitialMenu(){ + private void createAndSendFirstMenu(){ if (currentHMILevel == null || currentHMILevel.equals(HMILevel.HMI_NONE) || currentSystemContext.equals(SystemContext.SYSCTXT_MENU)){ // We are in NONE or the menu is in use, bail out of here -- cgit v1.2.1 From e1ebfb371cbe27bc7f0e49595297ec932f58b92a Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Thu, 23 May 2019 14:08:38 -0400 Subject: fix ID setting for added cells in existing sub menu --- .../managers/screen/menu/BaseMenuManager.java | 12 ++++++++---- .../managers/screen/menu/SubCellCommandLists.java | 12 +++++++++++- 2 files changed, 19 insertions(+), 5 deletions(-) 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 fd2a7b307..0d5a89693 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 @@ -375,7 +375,7 @@ abstract class BaseMenuManager extends BaseSubManager { if (subScore != null){ DebugTool.logInfo("Sub menu Run Score: "+ oldKeptCell.getTitle()+ " Score: "+ subScore.getScore()); - SubCellCommandLists commandList = new SubCellCommandLists(oldKeptCell.getTitle(), subScore, oldKeptCell.getSubCells(), keptCell.getSubCells()); + SubCellCommandLists commandList = new SubCellCommandLists(oldKeptCell.getTitle(), oldKeptCell.getCellId(), subScore, oldKeptCell.getSubCells(), keptCell.getSubCells()); commandLists.add(commandList); } } @@ -441,7 +441,7 @@ abstract class BaseMenuManager extends BaseSubManager { subCellKeepsNew.add(newCells.get(x)); } } - final List addsWithNewIds = updateIdsOnDynamicSubCells(oldCells, adds); + final List addsWithNewIds = updateIdsOnDynamicSubCells(oldCells, adds, commandList.getParentId()); // this is needed for the onCommands to still work transferIdsToKeptSubCells(oldCells, subCellKeepsNew); @@ -608,7 +608,7 @@ abstract class BaseMenuManager extends BaseSubManager { return null; } - private List updateIdsOnDynamicSubCells(List oldList, List dynamicCells){ + private List updateIdsOnDynamicSubCells(List oldList, List dynamicCells, Integer parentId){ if (oldList != null && oldList.size() > 0 && dynamicCells != null && dynamicCells.size() > 0) { for (int z = 0; z < oldList.size(); z++) { MenuCell mainCell = oldList.get(z); @@ -616,8 +616,12 @@ abstract class BaseMenuManager extends BaseSubManager { MenuCell dynamicCell = dynamicCells.get(i); if (mainCell.equals(dynamicCell)) { int newId = ++lastMenuId; - dynamicCells.get(i).setParentCellId(oldList.get(z).getParentCellId()); oldList.get(z).setCellId(newId); + dynamicCells.get(i).setParentCellId(parentId); + dynamicCells.get(i).setCellId(newId); + }else{ + int newId = ++lastMenuId; + dynamicCells.get(i).setParentCellId(parentId); dynamicCells.get(i).setCellId(newId); } } diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/SubCellCommandLists.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/SubCellCommandLists.java index d2c478780..d77fc60ef 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/SubCellCommandLists.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/SubCellCommandLists.java @@ -38,15 +38,25 @@ class SubCellCommandLists { private RunScore listsScore; private String menuTitle; + private Integer parentId; private List oldList, newList; - SubCellCommandLists(String menuTitle, RunScore listsScore, List oldList, List newList){ + SubCellCommandLists(String menuTitle, Integer parentId, RunScore listsScore, List oldList, List newList){ setMenuTitle(menuTitle); + setParentId(parentId); setListsScore(listsScore); setOldList(oldList); setNewList(newList); } + private void setParentId(Integer parentId) { + this.parentId = parentId; + } + + Integer getParentId() { + return parentId; + } + private void setMenuTitle(String menuTitle) { this.menuTitle = menuTitle; } -- cgit v1.2.1 From c5e4e103a94f898a3768a3519d11b71958b8a081 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Thu, 23 May 2019 16:24:34 -0400 Subject: Create a menu compatibility mode --- .../com/smartdevicelink/managers/SdlManager.java | 13 ++++- .../managers/screen/ScreenManager.java | 4 +- .../managers/screen/menu/MenuManager.java | 4 +- .../smartdevicelink/managers/BaseSdlManager.java | 1 + .../managers/screen/BaseScreenManager.java | 6 ++- .../managers/screen/menu/BaseMenuManager.java | 58 +++++++++++++++------- .../com/smartdevicelink/managers/SdlManager.java | 11 ++++ .../managers/screen/ScreenManager.java | 4 +- 8 files changed, 73 insertions(+), 28 deletions(-) diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/managers/SdlManager.java b/android/sdl_android/src/main/java/com/smartdevicelink/managers/SdlManager.java index ea1e88dcc..76546bc7f 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/managers/SdlManager.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/managers/SdlManager.java @@ -233,7 +233,7 @@ public class SdlManager extends BaseSdlManager{ if (lockScreenConfig.isEnabled()) { this.lockScreenManager = new LockScreenManager(lockScreenConfig, context, _internalInterface); } - this.screenManager = new ScreenManager(_internalInterface, this.fileManager); + this.screenManager = new ScreenManager(_internalInterface, this.fileManager, enableDynamicMenuUpdates); if(getAppTypes().contains(AppHMIType.NAVIGATION) || getAppTypes().contains(AppHMIType.PROJECTION)){ this.videoStreamManager = new VideoStreamManager(_internalInterface); } else { @@ -1011,6 +1011,17 @@ public class SdlManager extends BaseSdlManager{ return this; } + /** + * Default: true. If set to false, the Menu Manager will enter a compatibility mode that deletes + * and re-adds menus and sub menus each time a new menu or menu item is set. We discourage its + * use due to performance issues on older head units. + * @param enableDynamicMenuUpdates - a boolean + */ + public Builder setEnableDynamicMenuUpdates(Boolean enableDynamicMenuUpdates){ + sdlManager.enableDynamicMenuUpdates = enableDynamicMenuUpdates; + return this; + } + public SdlManager build() { if (sdlManager.appName == null) { diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/ScreenManager.java b/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/ScreenManager.java index 7975bb5f2..db802e46d 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/ScreenManager.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/ScreenManager.java @@ -44,7 +44,7 @@ import com.smartdevicelink.proxy.interfaces.ISdl; */ public class ScreenManager extends BaseScreenManager { - public ScreenManager(@NonNull ISdl internalInterface, @NonNull FileManager fileManager) { - super(internalInterface, fileManager); + public ScreenManager(@NonNull ISdl internalInterface, @NonNull FileManager fileManager, Boolean enableDynamicMenuUpdates) { + super(internalInterface, fileManager, enableDynamicMenuUpdates); } } diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManager.java b/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManager.java index 4a28a2792..253b37900 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManager.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManager.java @@ -44,9 +44,9 @@ import com.smartdevicelink.proxy.interfaces.ISdl; */ public class MenuManager extends BaseMenuManager { - public MenuManager(ISdl internalInterface, FileManager fileManager) { + public MenuManager(ISdl internalInterface, FileManager fileManager, Boolean enableDynamicMenuUpdates) { // setup - super(internalInterface, fileManager); + super(internalInterface, fileManager, enableDynamicMenuUpdates); } } diff --git a/base/src/main/java/com/smartdevicelink/managers/BaseSdlManager.java b/base/src/main/java/com/smartdevicelink/managers/BaseSdlManager.java index 5f73be39d..6427ad067 100644 --- a/base/src/main/java/com/smartdevicelink/managers/BaseSdlManager.java +++ b/base/src/main/java/com/smartdevicelink/managers/BaseSdlManager.java @@ -65,6 +65,7 @@ abstract class BaseSdlManager { String appId, appName, shortAppName; boolean isMediaApp; + Boolean enableDynamicMenuUpdates; Language hmiLanguage; Vector hmiTypes; BaseTransportConfig transport; 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 b6c040884..4fb4c7e3f 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/BaseScreenManager.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/BaseScreenManager.java @@ -63,6 +63,7 @@ abstract class BaseScreenManager extends BaseSubManager { private TextAndGraphicManager textAndGraphicManager; private VoiceCommandManager voiceCommandManager; private MenuManager menuManager; + private Boolean enableDynamicMenuUpdates; // Sub manager listener private final CompletionListener subManagerListener = new CompletionListener() { @@ -90,9 +91,10 @@ abstract class BaseScreenManager extends BaseSubManager { } }; - BaseScreenManager(@NonNull ISdl internalInterface, @NonNull FileManager fileManager) { + BaseScreenManager(@NonNull ISdl internalInterface, @NonNull FileManager fileManager, Boolean enableDynamicMenuUpdates) { super(internalInterface); this.fileManager = new WeakReference<>(fileManager); + this.enableDynamicMenuUpdates = enableDynamicMenuUpdates; initialize(); } @@ -109,7 +111,7 @@ abstract class BaseScreenManager extends BaseSubManager { if (fileManager.get() != null) { this.softButtonManager = new SoftButtonManager(internalInterface, fileManager.get()); this.textAndGraphicManager = new TextAndGraphicManager(internalInterface, fileManager.get(), softButtonManager); - this.menuManager = new MenuManager(internalInterface, fileManager.get()); + this.menuManager = new MenuManager(internalInterface, fileManager.get(), enableDynamicMenuUpdates); } this.voiceCommandManager = new VoiceCommandManager(internalInterface); } 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 0d5a89693..c38a00154 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 @@ -85,6 +85,7 @@ abstract class BaseMenuManager extends BaseSubManager { boolean waitingOnHMIUpdate; private boolean hasQueuedUpdate; + Boolean enableDynamicMenuUpdates; HMILevel currentHMILevel; OnRPCNotificationListener hmiListener, commandListener; @@ -98,7 +99,7 @@ abstract class BaseMenuManager extends BaseSubManager { SystemContext currentSystemContext; - BaseMenuManager(@NonNull ISdl internalInterface, @NonNull FileManager fileManager) { + BaseMenuManager(@NonNull ISdl internalInterface, @NonNull FileManager fileManager, Boolean enableDynamicMenuUpdates) { super(internalInterface); @@ -107,6 +108,14 @@ abstract class BaseMenuManager extends BaseSubManager { currentSystemContext = SystemContext.SYSCTXT_MAIN; currentHMILevel = HMILevel.HMI_NONE; lastMenuId = menuCellIdMin; + + // if not set, we want this to be true by default + if (enableDynamicMenuUpdates == null){ + this.enableDynamicMenuUpdates = true; + }else{ + this.enableDynamicMenuUpdates = enableDynamicMenuUpdates; + } + addListeners(); } @@ -237,26 +246,37 @@ abstract class BaseMenuManager extends BaseSubManager { return; } - // run the lists through the new algorithm - RunScore rootScore = runMenuCompareAlgorithm(oldMenuCells, menuCells); - - if (rootScore == null){ - // send initial menu (score will return null) - // make a copy of our current cells - DebugTool.logInfo("Creating initial Menu"); - // Set the IDs if needed + if (enableDynamicMenuUpdates) { + // run the lists through the new algorithm + RunScore rootScore = runMenuCompareAlgorithm(oldMenuCells, menuCells); + if (rootScore == null) { + // send initial menu (score will return null) + // make a copy of our current cells + DebugTool.logInfo("Creating initial Menu"); + // Set the IDs if needed + lastMenuId = menuCellIdMin; + updateIdsOnMenuCells(menuCells, parentIdNotFound); + this.oldMenuCells = new ArrayList<>(menuCells); + createAndSendEntireMenu(); + } else { + if (menuCells.size() == 0 && (oldMenuCells != null && oldMenuCells.size() > 0)) { + // the dev wants to clear the menu. We have old cells and an empty array of new ones. + deleteMenuWhenNewCellsEmpty(); + } else { + // lets dynamically update the root menu + dynamicallyUpdateRootMenu(rootScore); + } + } + } else { + // we are in compatibility mode + DebugTool.logInfo("Updating menus in compatibility mode"); lastMenuId = menuCellIdMin; updateIdsOnMenuCells(menuCells, parentIdNotFound); - this.oldMenuCells = new ArrayList<>(menuCells); - createAndSendFirstMenu(); - }else{ - if (menuCells.size() == 0 && (oldMenuCells != null && oldMenuCells.size() > 0)){ - // the dev wants to clear the menu. We have old cells and an empty array of new ones. - deleteMenuWhenNewCellsEmpty(); - }else { - // lets dynamically update the root menu - dynamicallyUpdateRootMenu(rootScore); + // if the old cell array is not null, we want to delete the entire thing, else copy the new array + if (oldMenuCells == null) { + this.oldMenuCells = new ArrayList<>(menuCells); } + createAndSendEntireMenu(); } } @@ -852,7 +872,7 @@ abstract class BaseMenuManager extends BaseSubManager { // SEND NEW MENU ITEMS - private void createAndSendFirstMenu(){ + private void createAndSendEntireMenu(){ if (currentHMILevel == null || currentHMILevel.equals(HMILevel.HMI_NONE) || currentSystemContext.equals(SystemContext.SYSCTXT_MENU)){ // We are in NONE or the menu is in use, bail out of here diff --git a/javaSE/src/main/java/com/smartdevicelink/managers/SdlManager.java b/javaSE/src/main/java/com/smartdevicelink/managers/SdlManager.java index 146382de9..4adc29ef3 100644 --- a/javaSE/src/main/java/com/smartdevicelink/managers/SdlManager.java +++ b/javaSE/src/main/java/com/smartdevicelink/managers/SdlManager.java @@ -667,6 +667,17 @@ public class SdlManager extends BaseSdlManager{ return this; } + /** + * Default: true. If set to false, the Menu Manager will enter a compatibility mode that deletes + * and re-adds menus and sub menus each time a new menu or menu item is set. We discourage its + * use due to performance issues on older head units. + * @param enableDynamicMenuUpdates - a boolean + */ + public Builder setEnableDynamicMenuUpdates(Boolean enableDynamicMenuUpdates){ + sdlManager.enableDynamicMenuUpdates = enableDynamicMenuUpdates; + return this; + } + public SdlManager build() { if (sdlManager.appName == null) { diff --git a/javaSE/src/main/java/com/smartdevicelink/managers/screen/ScreenManager.java b/javaSE/src/main/java/com/smartdevicelink/managers/screen/ScreenManager.java index b9828f4c3..f2c61d1a1 100644 --- a/javaSE/src/main/java/com/smartdevicelink/managers/screen/ScreenManager.java +++ b/javaSE/src/main/java/com/smartdevicelink/managers/screen/ScreenManager.java @@ -42,7 +42,7 @@ import com.smartdevicelink.proxy.interfaces.ISdl; */ public class ScreenManager extends BaseScreenManager { - public ScreenManager(@NonNull ISdl internalInterface, @NonNull FileManager fileManager) { - super(internalInterface, fileManager); + public ScreenManager(@NonNull ISdl internalInterface, @NonNull FileManager fileManager, Boolean enableDynamicMenuUpdates) { + super(internalInterface, fileManager, enableDynamicMenuUpdates); } } -- cgit v1.2.1 From ff7ad73fcffa1250b8e634e53b6abdbb34d4d491 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Fri, 24 May 2019 10:13:59 -0400 Subject: remove builder setter, add 2 empty test classes --- .../managers/screen/menu/RunScoreTests.java | 50 ++++++++++++ .../screen/menu/SubCellCommandListTests.java | 49 ++++++++++++ .../com/smartdevicelink/managers/SdlManager.java | 13 +--- .../managers/screen/ScreenManager.java | 4 +- .../managers/screen/menu/MenuManager.java | 4 +- .../smartdevicelink/managers/BaseSdlManager.java | 1 - .../managers/screen/BaseScreenManager.java | 6 +- .../managers/screen/menu/BaseMenuManager.java | 17 ++-- .../managers/screen/menu/SubCellCommandList.java | 91 ++++++++++++++++++++++ .../managers/screen/menu/SubCellCommandLists.java | 91 ---------------------- .../com/smartdevicelink/managers/SdlManager.java | 11 --- .../managers/screen/ScreenManager.java | 4 +- 12 files changed, 204 insertions(+), 137 deletions(-) create mode 100644 android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/RunScoreTests.java create mode 100644 android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/SubCellCommandListTests.java create mode 100644 base/src/main/java/com/smartdevicelink/managers/screen/menu/SubCellCommandList.java delete mode 100644 base/src/main/java/com/smartdevicelink/managers/screen/menu/SubCellCommandLists.java diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/RunScoreTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/RunScoreTests.java new file mode 100644 index 000000000..1eef07622 --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/RunScoreTests.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +package com.smartdevicelink.managers.screen.menu; + +import com.smartdevicelink.AndroidTestCase2; + +public class RunScoreTests extends AndroidTestCase2 { + + + @Override + public void setUp() throws Exception{ + super.setUp(); + } + + @Override + public void tearDown() throws Exception { + super.tearDown(); + } + +} diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/SubCellCommandListTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/SubCellCommandListTests.java new file mode 100644 index 000000000..f47037dbe --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/SubCellCommandListTests.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +package com.smartdevicelink.managers.screen.menu; + +import com.smartdevicelink.AndroidTestCase2; + +public class SubCellCommandListTests extends AndroidTestCase2 { + + @Override + public void setUp() throws Exception{ + super.setUp(); + } + + @Override + public void tearDown() throws Exception { + super.tearDown(); + } + +} diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/managers/SdlManager.java b/android/sdl_android/src/main/java/com/smartdevicelink/managers/SdlManager.java index 76546bc7f..ea1e88dcc 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/managers/SdlManager.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/managers/SdlManager.java @@ -233,7 +233,7 @@ public class SdlManager extends BaseSdlManager{ if (lockScreenConfig.isEnabled()) { this.lockScreenManager = new LockScreenManager(lockScreenConfig, context, _internalInterface); } - this.screenManager = new ScreenManager(_internalInterface, this.fileManager, enableDynamicMenuUpdates); + this.screenManager = new ScreenManager(_internalInterface, this.fileManager); if(getAppTypes().contains(AppHMIType.NAVIGATION) || getAppTypes().contains(AppHMIType.PROJECTION)){ this.videoStreamManager = new VideoStreamManager(_internalInterface); } else { @@ -1011,17 +1011,6 @@ public class SdlManager extends BaseSdlManager{ return this; } - /** - * Default: true. If set to false, the Menu Manager will enter a compatibility mode that deletes - * and re-adds menus and sub menus each time a new menu or menu item is set. We discourage its - * use due to performance issues on older head units. - * @param enableDynamicMenuUpdates - a boolean - */ - public Builder setEnableDynamicMenuUpdates(Boolean enableDynamicMenuUpdates){ - sdlManager.enableDynamicMenuUpdates = enableDynamicMenuUpdates; - return this; - } - public SdlManager build() { if (sdlManager.appName == null) { diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/ScreenManager.java b/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/ScreenManager.java index db802e46d..7975bb5f2 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/ScreenManager.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/ScreenManager.java @@ -44,7 +44,7 @@ import com.smartdevicelink.proxy.interfaces.ISdl; */ public class ScreenManager extends BaseScreenManager { - public ScreenManager(@NonNull ISdl internalInterface, @NonNull FileManager fileManager, Boolean enableDynamicMenuUpdates) { - super(internalInterface, fileManager, enableDynamicMenuUpdates); + public ScreenManager(@NonNull ISdl internalInterface, @NonNull FileManager fileManager) { + super(internalInterface, fileManager); } } diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManager.java b/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManager.java index 253b37900..4a28a2792 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManager.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManager.java @@ -44,9 +44,9 @@ import com.smartdevicelink.proxy.interfaces.ISdl; */ public class MenuManager extends BaseMenuManager { - public MenuManager(ISdl internalInterface, FileManager fileManager, Boolean enableDynamicMenuUpdates) { + public MenuManager(ISdl internalInterface, FileManager fileManager) { // setup - super(internalInterface, fileManager, enableDynamicMenuUpdates); + super(internalInterface, fileManager); } } diff --git a/base/src/main/java/com/smartdevicelink/managers/BaseSdlManager.java b/base/src/main/java/com/smartdevicelink/managers/BaseSdlManager.java index 6427ad067..5f73be39d 100644 --- a/base/src/main/java/com/smartdevicelink/managers/BaseSdlManager.java +++ b/base/src/main/java/com/smartdevicelink/managers/BaseSdlManager.java @@ -65,7 +65,6 @@ abstract class BaseSdlManager { String appId, appName, shortAppName; boolean isMediaApp; - Boolean enableDynamicMenuUpdates; Language hmiLanguage; Vector hmiTypes; BaseTransportConfig transport; 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 4fb4c7e3f..b6c040884 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/BaseScreenManager.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/BaseScreenManager.java @@ -63,7 +63,6 @@ abstract class BaseScreenManager extends BaseSubManager { private TextAndGraphicManager textAndGraphicManager; private VoiceCommandManager voiceCommandManager; private MenuManager menuManager; - private Boolean enableDynamicMenuUpdates; // Sub manager listener private final CompletionListener subManagerListener = new CompletionListener() { @@ -91,10 +90,9 @@ abstract class BaseScreenManager extends BaseSubManager { } }; - BaseScreenManager(@NonNull ISdl internalInterface, @NonNull FileManager fileManager, Boolean enableDynamicMenuUpdates) { + BaseScreenManager(@NonNull ISdl internalInterface, @NonNull FileManager fileManager) { super(internalInterface); this.fileManager = new WeakReference<>(fileManager); - this.enableDynamicMenuUpdates = enableDynamicMenuUpdates; initialize(); } @@ -111,7 +109,7 @@ abstract class BaseScreenManager extends BaseSubManager { if (fileManager.get() != null) { this.softButtonManager = new SoftButtonManager(internalInterface, fileManager.get()); this.textAndGraphicManager = new TextAndGraphicManager(internalInterface, fileManager.get(), softButtonManager); - this.menuManager = new MenuManager(internalInterface, fileManager.get(), enableDynamicMenuUpdates); + this.menuManager = new MenuManager(internalInterface, fileManager.get()); } this.voiceCommandManager = new VoiceCommandManager(internalInterface); } 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 c38a00154..9fa1fe82e 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 @@ -99,7 +99,7 @@ abstract class BaseMenuManager extends BaseSubManager { SystemContext currentSystemContext; - BaseMenuManager(@NonNull ISdl internalInterface, @NonNull FileManager fileManager, Boolean enableDynamicMenuUpdates) { + BaseMenuManager(@NonNull ISdl internalInterface, @NonNull FileManager fileManager) { super(internalInterface); @@ -109,13 +109,6 @@ abstract class BaseMenuManager extends BaseSubManager { currentHMILevel = HMILevel.HMI_NONE; lastMenuId = menuCellIdMin; - // if not set, we want this to be true by default - if (enableDynamicMenuUpdates == null){ - this.enableDynamicMenuUpdates = true; - }else{ - this.enableDynamicMenuUpdates = enableDynamicMenuUpdates; - } - addListeners(); } @@ -382,7 +375,7 @@ abstract class BaseMenuManager extends BaseSubManager { return; } - List commandLists = new ArrayList<>(); + List commandLists = new ArrayList<>(); for (int i = 0; i < keepsNew.size(); i++) { @@ -395,7 +388,7 @@ abstract class BaseMenuManager extends BaseSubManager { if (subScore != null){ DebugTool.logInfo("Sub menu Run Score: "+ oldKeptCell.getTitle()+ " Score: "+ subScore.getScore()); - SubCellCommandLists commandList = new SubCellCommandLists(oldKeptCell.getTitle(), oldKeptCell.getCellId(), subScore, oldKeptCell.getSubCells(), keptCell.getSubCells()); + SubCellCommandList commandList = new SubCellCommandList(oldKeptCell.getTitle(), oldKeptCell.getCellId(), subScore, oldKeptCell.getSubCells(), keptCell.getSubCells()); commandLists.add(commandList); } } @@ -403,7 +396,7 @@ abstract class BaseMenuManager extends BaseSubManager { createSubMenuDynamicCommands(commandLists); } - private void createSubMenuDynamicCommands(final List commandLists){ + private void createSubMenuDynamicCommands(final List commandLists){ // break out if (commandLists.size() == 0){ @@ -420,7 +413,7 @@ abstract class BaseMenuManager extends BaseSubManager { return; } - final SubCellCommandLists commandList = commandLists.remove(0); + final SubCellCommandList commandList = commandLists.remove(0); DebugTool.logInfo("Creating and Sending Dynamic Sub Commands For Root Menu Cell: "+ commandList.getMenuTitle()); diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/SubCellCommandList.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/SubCellCommandList.java new file mode 100644 index 000000000..d5eee6ef1 --- /dev/null +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/SubCellCommandList.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +package com.smartdevicelink.managers.screen.menu; + +import java.util.List; + +class SubCellCommandList { + + private RunScore listsScore; + private String menuTitle; + private Integer parentId; + private List oldList, newList; + + SubCellCommandList(String menuTitle, Integer parentId, RunScore listsScore, List oldList, List newList){ + setMenuTitle(menuTitle); + setParentId(parentId); + setListsScore(listsScore); + setOldList(oldList); + setNewList(newList); + } + + private void setParentId(Integer parentId) { + this.parentId = parentId; + } + + Integer getParentId() { + return parentId; + } + + private void setMenuTitle(String menuTitle) { + this.menuTitle = menuTitle; + } + + String getMenuTitle() { + return menuTitle; + } + + private void setListsScore(RunScore listsScore){ + this.listsScore = listsScore; + } + + RunScore getListsScore() { + return listsScore; + } + + private void setOldList(List oldList) { + this.oldList = oldList; + } + + List getOldList() { + return oldList; + } + + private void setNewList(List newList) { + this.newList = newList; + } + + List getNewList() { + return newList; + } +} diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/SubCellCommandLists.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/SubCellCommandLists.java deleted file mode 100644 index d77fc60ef..000000000 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/SubCellCommandLists.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2019 Livio, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of the Livio Inc. nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -package com.smartdevicelink.managers.screen.menu; - -import java.util.List; - -class SubCellCommandLists { - - private RunScore listsScore; - private String menuTitle; - private Integer parentId; - private List oldList, newList; - - SubCellCommandLists(String menuTitle, Integer parentId, RunScore listsScore, List oldList, List newList){ - setMenuTitle(menuTitle); - setParentId(parentId); - setListsScore(listsScore); - setOldList(oldList); - setNewList(newList); - } - - private void setParentId(Integer parentId) { - this.parentId = parentId; - } - - Integer getParentId() { - return parentId; - } - - private void setMenuTitle(String menuTitle) { - this.menuTitle = menuTitle; - } - - String getMenuTitle() { - return menuTitle; - } - - private void setListsScore(RunScore listsScore){ - this.listsScore = listsScore; - } - - RunScore getListsScore() { - return listsScore; - } - - private void setOldList(List oldList) { - this.oldList = oldList; - } - - List getOldList() { - return oldList; - } - - private void setNewList(List newList) { - this.newList = newList; - } - - List getNewList() { - return newList; - } -} diff --git a/javaSE/src/main/java/com/smartdevicelink/managers/SdlManager.java b/javaSE/src/main/java/com/smartdevicelink/managers/SdlManager.java index 4adc29ef3..146382de9 100644 --- a/javaSE/src/main/java/com/smartdevicelink/managers/SdlManager.java +++ b/javaSE/src/main/java/com/smartdevicelink/managers/SdlManager.java @@ -667,17 +667,6 @@ public class SdlManager extends BaseSdlManager{ return this; } - /** - * Default: true. If set to false, the Menu Manager will enter a compatibility mode that deletes - * and re-adds menus and sub menus each time a new menu or menu item is set. We discourage its - * use due to performance issues on older head units. - * @param enableDynamicMenuUpdates - a boolean - */ - public Builder setEnableDynamicMenuUpdates(Boolean enableDynamicMenuUpdates){ - sdlManager.enableDynamicMenuUpdates = enableDynamicMenuUpdates; - return this; - } - public SdlManager build() { if (sdlManager.appName == null) { diff --git a/javaSE/src/main/java/com/smartdevicelink/managers/screen/ScreenManager.java b/javaSE/src/main/java/com/smartdevicelink/managers/screen/ScreenManager.java index f2c61d1a1..b9828f4c3 100644 --- a/javaSE/src/main/java/com/smartdevicelink/managers/screen/ScreenManager.java +++ b/javaSE/src/main/java/com/smartdevicelink/managers/screen/ScreenManager.java @@ -42,7 +42,7 @@ import com.smartdevicelink.proxy.interfaces.ISdl; */ public class ScreenManager extends BaseScreenManager { - public ScreenManager(@NonNull ISdl internalInterface, @NonNull FileManager fileManager, Boolean enableDynamicMenuUpdates) { - super(internalInterface, fileManager, enableDynamicMenuUpdates); + public ScreenManager(@NonNull ISdl internalInterface, @NonNull FileManager fileManager) { + super(internalInterface, fileManager); } } -- cgit v1.2.1 From 3428c486629391e45fb53bd90a576bcd6259c72e Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Fri, 24 May 2019 10:25:42 -0400 Subject: add MenuManagerCompatMode enum class --- .../screen/menu/MenuManagerCompatMode.java | 66 ++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManagerCompatMode.java diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManagerCompatMode.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManagerCompatMode.java new file mode 100644 index 000000000..11dea3a3c --- /dev/null +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManagerCompatMode.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +package com.smartdevicelink.managers.screen.menu; + +public enum MenuManagerCompatMode { + + /** + * FORCE_ON: Forces on compatibility mode. This will force the menu manager to delete and re-add + * each menu item for every menu update. This mode is generally not advised due to performance issues. + */ + FORCE_ON, + + /** + * FORCE_OFF: This mode forces the menu manager to always dynamically update menu items for each menu + * update. This will provide the best performance but may cause ordering issues on some SYNC Gen 3 head units. + */ + FORCE_OFF, + + /** + * ON_WITH_COMPAT_MODE: This mode checks whether the phone is connected to a SYNC Gen 3 head unit, which has known + * menu ordering issues. If it is, it will always delete and re-add every menu item, if not, it will dynamically update + * the menus. + */ + ON_WITH_COMPAT_MODE, + + ; + + public static MenuManagerCompatMode valueForString(String value) { + try{ + return valueOf(value); + }catch(Exception e){ + return null; + } + } + +} -- cgit v1.2.1 From 9942b4b662136e22b99039123ca4b00d29b360e9 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Fri, 24 May 2019 11:04:37 -0400 Subject: working updateMode setter --- .../screen/menu/DynamicMenuUpdatesModeTests.java | 99 ++++++++++++++++++++++ .../managers/screen/menu/MenuManagerTests.java | 2 - .../managers/screen/BaseScreenManager.java | 9 ++ .../managers/screen/menu/BaseMenuManager.java | 31 ++++++- .../screen/menu/DynamicMenuUpdatesMode.java | 66 +++++++++++++++ .../screen/menu/MenuManagerCompatMode.java | 66 --------------- 6 files changed, 203 insertions(+), 70 deletions(-) create mode 100644 android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/DynamicMenuUpdatesModeTests.java create mode 100644 base/src/main/java/com/smartdevicelink/managers/screen/menu/DynamicMenuUpdatesMode.java delete mode 100644 base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManagerCompatMode.java diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/DynamicMenuUpdatesModeTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/DynamicMenuUpdatesModeTests.java new file mode 100644 index 000000000..2d2a8853c --- /dev/null +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/DynamicMenuUpdatesModeTests.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +package com.smartdevicelink.managers.screen.menu; + +import junit.framework.TestCase; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class DynamicMenuUpdatesModeTests extends TestCase { + + /** + * Verifies that the enum values are not null upon valid assignment. + */ + public void testValidEnums() { + String example = "FORCE_ON"; + DynamicMenuUpdatesMode forceOn = DynamicMenuUpdatesMode.valueForString(example); + example = "FORCE_OFF"; + DynamicMenuUpdatesMode forceOff = DynamicMenuUpdatesMode.valueForString(example); + example = "ON_WITH_COMPAT_MODE"; + DynamicMenuUpdatesMode onWithCompatMode = DynamicMenuUpdatesMode.valueForString(example); + + assertNotNull("FORCE_ON returned null", forceOn); + assertNotNull("FORCE_OFF returned null", forceOff); + assertNotNull("ON_WITH_COMPAT_MODE returned null", onWithCompatMode); + } + + /** + * Verifies that an invalid assignment is null. + */ + public void testInvalidEnum() { + String example = "deFaUlt"; + try { + DynamicMenuUpdatesMode temp = DynamicMenuUpdatesMode.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } catch (IllegalArgumentException exception) { + fail("Invalid enum throws IllegalArgumentException."); + } + } + + /** + * Verifies that a null assignment is invalid. + */ + public void testNullEnum() { + String example = null; + try { + DynamicMenuUpdatesMode temp = DynamicMenuUpdatesMode.valueForString(example); + assertNull("Result of valueForString should be null.", temp); + } catch (NullPointerException exception) { + fail("Null string throws NullPointerException."); + } + } + + /** + * Verifies the possible enum values of DynamicMenuUpdatesMode. + */ + public void testListEnum() { + List enumValueList = Arrays.asList(DynamicMenuUpdatesMode.values()); + + List enumTestList = new ArrayList<>(); + enumTestList.add(DynamicMenuUpdatesMode.FORCE_ON); + enumTestList.add(DynamicMenuUpdatesMode.FORCE_OFF); + enumTestList.add(DynamicMenuUpdatesMode.ON_WITH_COMPAT_MODE); + + assertTrue("Enum value list does not match enum class list", + enumValueList.containsAll(enumTestList) && enumTestList.containsAll(enumValueList)); + } +} 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 dc51aed9e..3cccc2588 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 @@ -172,8 +172,6 @@ public class MenuManagerTests extends AndroidTestCase2 { public void testUpdating(){ - assertEquals(menuManager.deleteCommandsForCells(cells).size(), 4); // 3 root cells and 1 sub menu - // when we only send one command to update, we should only be returned one add command List newArray = Arrays.asList(mainCell1, mainCell4); assertEquals(menuManager.allCommandsForCells(newArray, false).size(), 4); // 1 root cells, 1 sub menu root cell, 2 sub menu cells 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 b6c040884..debe97a69 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/BaseScreenManager.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/BaseScreenManager.java @@ -38,6 +38,7 @@ import com.smartdevicelink.managers.BaseSubManager; import com.smartdevicelink.managers.CompletionListener; import com.smartdevicelink.managers.file.FileManager; import com.smartdevicelink.managers.file.filetypes.SdlArtwork; +import com.smartdevicelink.managers.screen.menu.DynamicMenuUpdatesMode; import com.smartdevicelink.managers.screen.menu.MenuManager; import com.smartdevicelink.managers.screen.menu.VoiceCommandManager; import com.smartdevicelink.managers.screen.menu.MenuCell; @@ -395,6 +396,14 @@ abstract class BaseScreenManager extends BaseSubManager { this.menuManager.setMenuCells(menuCells); } + /** + * Sets the behavior of how menus are updated. For explanations of the differences, see {@link DynamicMenuUpdatesMode} + * @param value - the update mode + */ + public void setDynamicMenuUpdatesMode(DynamicMenuUpdatesMode value){ + this.menuManager.setDynamicUpdatesMode(value); + } + /** * Begin a multiple updates transaction. The updates will be applied when commit() is called
* Note: if we don't use beginTransaction & commit, every update will be sent individually. 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 9fa1fe82e..737463a49 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 @@ -55,6 +55,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.enums.DisplayType; import com.smartdevicelink.proxy.rpc.enums.HMILevel; import com.smartdevicelink.proxy.rpc.enums.ImageFieldName; import com.smartdevicelink.proxy.rpc.enums.Result; @@ -82,10 +83,11 @@ abstract class BaseMenuManager extends BaseSubManager { List menuCells, waitingUpdateMenuCells, oldMenuCells, keepsNew, keepsOld; List inProgressUpdate; + DynamicMenuUpdatesMode dynamicMenuUpdatesMode; + private DisplayType displayType; boolean waitingOnHMIUpdate; private boolean hasQueuedUpdate; - Boolean enableDynamicMenuUpdates; HMILevel currentHMILevel; OnRPCNotificationListener hmiListener, commandListener; @@ -108,6 +110,7 @@ abstract class BaseMenuManager extends BaseSubManager { currentSystemContext = SystemContext.SYSCTXT_MAIN; currentHMILevel = HMILevel.HMI_NONE; lastMenuId = menuCellIdMin; + dynamicMenuUpdatesMode = DynamicMenuUpdatesMode.ON_WITH_COMPAT_MODE; addListeners(); } @@ -142,6 +145,10 @@ abstract class BaseMenuManager extends BaseSubManager { // SETTERS + public void setDynamicUpdatesMode(DynamicMenuUpdatesMode value){ + this.dynamicMenuUpdatesMode = value; + } + /** * Creates and sends all associated Menu RPCs * @param cells - the menu cells that are to be sent to the head unit, including their sub-cells. @@ -239,7 +246,7 @@ abstract class BaseMenuManager extends BaseSubManager { return; } - if (enableDynamicMenuUpdates) { + if (checkUpdateMode(dynamicMenuUpdatesMode, displayType)) { // run the lists through the new algorithm RunScore rootScore = runMenuCompareAlgorithm(oldMenuCells, menuCells); if (rootScore == null) { @@ -273,6 +280,23 @@ abstract class BaseMenuManager extends BaseSubManager { } } + private boolean checkUpdateMode(DynamicMenuUpdatesMode updateMode, DisplayType displayType){ + + if (updateMode.equals(DynamicMenuUpdatesMode.ON_WITH_COMPAT_MODE)){ + if (displayType == null){ + return true; + } + return (!displayType.equals(DisplayType.GEN3_8_INCH)); + + } else if (updateMode.equals(DynamicMenuUpdatesMode.FORCE_OFF)){ + return false; + } else if (updateMode.equals(DynamicMenuUpdatesMode.FORCE_ON)){ + return true; + } + + return true; + } + private void deleteMenuWhenNewCellsEmpty(){ sendDeleteRPCs(createDeleteRPCsForCells(oldMenuCells), new CompletionListener() { @Override @@ -809,6 +833,9 @@ abstract class BaseMenuManager extends BaseSubManager { @Override public void onCapabilityRetrieved(Object capability) { displayCapabilities = (DisplayCapabilities) capability; + if (displayCapabilities != null) { + displayType = displayCapabilities.getDisplayType(); + } } @Override diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/DynamicMenuUpdatesMode.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/DynamicMenuUpdatesMode.java new file mode 100644 index 000000000..b04cb4626 --- /dev/null +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/DynamicMenuUpdatesMode.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2019 Livio, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Livio Inc. nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +package com.smartdevicelink.managers.screen.menu; + +public enum DynamicMenuUpdatesMode { + + /** + * FORCE_ON: This mode forces the menu manager to always dynamically update menu items for each menu + * update. This will provide the best performance but may cause ordering issues on some SYNC Gen 3 head units. + */ + FORCE_ON, + + /** + * FORCE_OFF: Forces off compatibility mode. This will force the menu manager to delete and re-add + * each menu item for every menu update. This mode is generally not advised due to performance issues. + */ + FORCE_OFF, + + /** + * ON_WITH_COMPAT_MODE: This mode checks whether the phone is connected to a SYNC Gen 3 head unit, which has known + * menu ordering issues. If it is, it will always delete and re-add every menu item, if not, it will dynamically update + * the menus. + */ + ON_WITH_COMPAT_MODE, + + ; + + public static DynamicMenuUpdatesMode valueForString(String value) { + try{ + return valueOf(value); + }catch(Exception e){ + return null; + } + } + +} diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManagerCompatMode.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManagerCompatMode.java deleted file mode 100644 index 11dea3a3c..000000000 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuManagerCompatMode.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2019 Livio, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of the Livio Inc. nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -package com.smartdevicelink.managers.screen.menu; - -public enum MenuManagerCompatMode { - - /** - * FORCE_ON: Forces on compatibility mode. This will force the menu manager to delete and re-add - * each menu item for every menu update. This mode is generally not advised due to performance issues. - */ - FORCE_ON, - - /** - * FORCE_OFF: This mode forces the menu manager to always dynamically update menu items for each menu - * update. This will provide the best performance but may cause ordering issues on some SYNC Gen 3 head units. - */ - FORCE_OFF, - - /** - * ON_WITH_COMPAT_MODE: This mode checks whether the phone is connected to a SYNC Gen 3 head unit, which has known - * menu ordering issues. If it is, it will always delete and re-add every menu item, if not, it will dynamically update - * the menus. - */ - ON_WITH_COMPAT_MODE, - - ; - - public static MenuManagerCompatMode valueForString(String value) { - try{ - return valueOf(value); - }catch(Exception e){ - return null; - } - } - -} -- cgit v1.2.1 From df7a87d3cdd069d0190ff3967881c0a01413a12f Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Tue, 28 May 2019 09:48:47 -0400 Subject: adding tests for run score object --- .../smartdevicelink/managers/screen/menu/RunScoreTests.java | 12 ++++++++++++ .../managers/screen/menu/BaseMenuManager.java | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/RunScoreTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/RunScoreTests.java index 1eef07622..15128293c 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/RunScoreTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/RunScoreTests.java @@ -33,6 +33,7 @@ package com.smartdevicelink.managers.screen.menu; import com.smartdevicelink.AndroidTestCase2; +import com.smartdevicelink.test.Test; public class RunScoreTests extends AndroidTestCase2 { @@ -47,4 +48,15 @@ public class RunScoreTests extends AndroidTestCase2 { super.tearDown(); } + public void testSettersAndGetters(){ + + // set everything - we only use the constructor to set variables in the Menu Manager + RunScore runScore = new RunScore(Test.GENERAL_INT, Test.GENERAL_INTEGER_LIST, Test.GENERAL_INTEGER_LIST); + + // use getters and assert equality + assertEquals(runScore.getScore(), Test.GENERAL_INT); + assertEquals(runScore.getCurrentMenu(), Test.GENERAL_INTEGER_LIST); + assertEquals(runScore.getOldMenu(), Test.GENERAL_INTEGER_LIST); + } + } 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 737463a49..2ca15377b 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 @@ -246,6 +246,9 @@ abstract class BaseMenuManager extends BaseSubManager { return; } + // Checks against what the developer set for update mode and against the display type + // to determine how the menu will be updated. This has the ability to be changed during + // a session. if (checkUpdateMode(dynamicMenuUpdatesMode, displayType)) { // run the lists through the new algorithm RunScore rootScore = runMenuCompareAlgorithm(oldMenuCells, menuCells); @@ -259,6 +262,7 @@ abstract class BaseMenuManager extends BaseSubManager { this.oldMenuCells = new ArrayList<>(menuCells); createAndSendEntireMenu(); } else { + DebugTool.logInfo("Dynamically Updating Menu"); if (menuCells.size() == 0 && (oldMenuCells != null && oldMenuCells.size() > 0)) { // the dev wants to clear the menu. We have old cells and an empty array of new ones. deleteMenuWhenNewCellsEmpty(); -- cgit v1.2.1 From e91a04c3acc8d6172ea897b293a9eea37c9f8157 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Tue, 28 May 2019 10:08:26 -0400 Subject: tests for subcell command lists --- .../managers/screen/menu/SubCellCommandListTests.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/SubCellCommandListTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/SubCellCommandListTests.java index f47037dbe..c25fb7f41 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/SubCellCommandListTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/SubCellCommandListTests.java @@ -33,6 +33,7 @@ package com.smartdevicelink.managers.screen.menu; import com.smartdevicelink.AndroidTestCase2; +import com.smartdevicelink.test.Test; public class SubCellCommandListTests extends AndroidTestCase2 { @@ -46,4 +47,19 @@ public class SubCellCommandListTests extends AndroidTestCase2 { super.tearDown(); } + public void testSettersAndGetters() { + + RunScore runScore = new RunScore(Test.GENERAL_INT, Test.GENERAL_INTEGER_LIST, Test.GENERAL_INTEGER_LIST); + + // set everything + SubCellCommandList subCellCommandList = new SubCellCommandList(Test.GENERAL_STRING, Test.GENERAL_INTEGER, runScore, Test.GENERAL_MENUCELL_LIST, Test.GENERAL_MENUCELL_LIST); + + // use getters and assert equality + assertEquals(subCellCommandList.getMenuTitle(), Test.GENERAL_STRING); + assertEquals(subCellCommandList.getParentId(), Test.GENERAL_INTEGER); + assertEquals(runScore, runScore); + assertEquals(subCellCommandList.getNewList(), Test.GENERAL_MENUCELL_LIST); + assertEquals(subCellCommandList.getOldList(), Test.GENERAL_MENUCELL_LIST); + + } } -- cgit v1.2.1 From 6d9132c794732701fedc663523dd074b9f3e6373 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Tue, 28 May 2019 10:33:11 -0400 Subject: add tests to SM, add getter to MM --- .../managers/screen/ScreenManagerTests.java | 18 ++++++++++++++++++ .../java/com/smartdevicelink/test/Test.java | 9 +++++++++ .../managers/screen/BaseScreenManager.java | 8 ++++++++ .../managers/screen/menu/BaseMenuManager.java | 18 +++++++++++++++++- 4 files changed, 52 insertions(+), 1 deletion(-) diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/ScreenManagerTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/ScreenManagerTests.java index 872e09b81..04daed829 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/ScreenManagerTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/ScreenManagerTests.java @@ -4,10 +4,12 @@ import com.smartdevicelink.AndroidTestCase2; import com.smartdevicelink.managers.BaseSubManager; import com.smartdevicelink.managers.file.FileManager; import com.smartdevicelink.managers.file.filetypes.SdlArtwork; +import com.smartdevicelink.managers.screen.menu.DynamicMenuUpdatesMode; import com.smartdevicelink.proxy.interfaces.ISdl; import com.smartdevicelink.proxy.rpc.enums.FileType; import com.smartdevicelink.proxy.rpc.enums.MetadataType; import com.smartdevicelink.proxy.rpc.enums.TextAlignment; +import com.smartdevicelink.test.Test; import java.util.Arrays; import java.util.List; @@ -114,6 +116,22 @@ public class ScreenManagerTests extends AndroidTestCase2 { assertEquals(screenManager.getTextField4Type(), MetadataType.MEDIA_GENRE); } + public void testSetMenuManagerFields(){ + // make sure the default is set + assertEquals(screenManager.getDynamicMenuUpdatesMode(), DynamicMenuUpdatesMode.ON_WITH_COMPAT_MODE); + + screenManager.setDynamicMenuUpdatesMode(DynamicMenuUpdatesMode.FORCE_ON); + screenManager.setMenu(Test.GENERAL_MENUCELL_LIST); + + assertEquals(screenManager.getMenu(), Test.GENERAL_MENUCELL_LIST); + assertEquals(screenManager.getDynamicMenuUpdatesMode(), DynamicMenuUpdatesMode.FORCE_ON); + } + + public void testSetVoiceCommands(){ + screenManager.setVoiceCommands(Test.GENERAL_VOICE_COMMAND_LIST); + assertEquals(screenManager.getVoiceCommands(), Test.GENERAL_VOICE_COMMAND_LIST); + } + public void testSetSoftButtonObjects(){ // Create softButtonObject1 SoftButtonState softButtonState1 = new SoftButtonState("object1-state1", "it is", testArtwork); diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java index 451289d4e..c77894e93 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/Test.java @@ -8,6 +8,8 @@ import com.smartdevicelink.managers.file.filetypes.SdlArtwork; import com.smartdevicelink.managers.lockscreen.LockScreenConfig; import com.smartdevicelink.managers.screen.menu.MenuCell; import com.smartdevicelink.managers.screen.menu.MenuSelectionListener; +import com.smartdevicelink.managers.screen.menu.VoiceCommand; +import com.smartdevicelink.managers.screen.menu.VoiceCommandSelectionListener; import com.smartdevicelink.protocol.SdlProtocol; import com.smartdevicelink.protocol.enums.FunctionID; import com.smartdevicelink.proxy.SdlProxyBase; @@ -460,6 +462,13 @@ public class Test { } }); public static final List GENERAL_MENUCELL_LIST = Arrays.asList(GENERAL_MENUCELL); + public static final VoiceCommand GENERAL_VOICE_COMMAND = new VoiceCommand(GENERAL_STRING_LIST, new VoiceCommandSelectionListener() { + @Override + public void onVoiceCommandSelected() { + + } + }); + public static final List GENERAL_VOICE_COMMAND_LIST = Arrays.asList(GENERAL_VOICE_COMMAND); public static final JSONArray JSON_TURNS = new JSONArray(); 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 debe97a69..1047f4d67 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/BaseScreenManager.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/BaseScreenManager.java @@ -404,6 +404,14 @@ abstract class BaseScreenManager extends BaseSubManager { this.menuManager.setDynamicUpdatesMode(value); } + /** + * + * @return The currently set DynamicMenuUpdatesMode. It defaults to ON_WITH_COMPAT_MODE if not set. + */ + public DynamicMenuUpdatesMode getDynamicMenuUpdatesMode(){ + return this.menuManager.getDynamicMenuUpdatesMode(); + } + /** * Begin a multiple updates transaction. The updates will be applied when commit() is called
* Note: if we don't use beginTransaction & commit, every update will be sent individually. 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 2ca15377b..1d39bfa58 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 @@ -129,6 +129,7 @@ abstract class BaseMenuManager extends BaseSubManager { oldMenuCells = null; currentHMILevel = null; currentSystemContext = SystemContext.SYSCTXT_MAIN; + dynamicMenuUpdatesMode = DynamicMenuUpdatesMode.ON_WITH_COMPAT_MODE; displayCapabilities = null; inProgressUpdate = null; hasQueuedUpdate = false; @@ -222,7 +223,22 @@ abstract class BaseMenuManager extends BaseSubManager { * @return a List of Currently set menu cells */ public List getMenuCells(){ - return menuCells; + + if (menuCells != null) { + return menuCells; + } else if (waitingOnHMIUpdate && waitingUpdateMenuCells != null) { + // this will keep from returning null if the menu list is set and we are pending HMI FULL + return waitingUpdateMenuCells; + } else { + return null; + } + } + + /** + * @return The currently set DynamicMenuUpdatesMode. It defaults to ON_WITH_COMPAT_MODE + */ + public DynamicMenuUpdatesMode getDynamicMenuUpdatesMode() { + return this.dynamicMenuUpdatesMode; } // UPDATING SYSTEM -- cgit v1.2.1 From da47e9b1eb5ef4a642bb7f1567e16512e704e6aa Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Tue, 28 May 2019 14:47:07 -0400 Subject: root algorithm specific tests --- .../managers/screen/ScreenManagerTests.java | 6 +- .../managers/screen/menu/MenuManagerTests.java | 364 ++++++++++++++++++++- .../managers/screen/menu/BaseMenuManager.java | 2 +- 3 files changed, 367 insertions(+), 5 deletions(-) diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/ScreenManagerTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/ScreenManagerTests.java index 04daed829..23c60e295 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/ScreenManagerTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/ScreenManagerTests.java @@ -55,9 +55,12 @@ public class ScreenManagerTests extends AndroidTestCase2 { assertNull(screenManager.getTextField2Type()); assertNull(screenManager.getTextField3Type()); assertNull(screenManager.getTextField4Type()); + assertNull(screenManager.getMenu()); + assertNull(screenManager.getVoiceCommands()); assertTrue(screenManager.getSoftButtonObjects().isEmpty()); assertNull(screenManager.getSoftButtonObjectByName("test")); assertNull(screenManager.getSoftButtonObjectById(1)); + assertEquals(screenManager.getDynamicMenuUpdatesMode(), DynamicMenuUpdatesMode.ON_WITH_COMPAT_MODE); assertEquals(screenManager.getState(), BaseSubManager.READY); } @@ -117,9 +120,6 @@ public class ScreenManagerTests extends AndroidTestCase2 { } public void testSetMenuManagerFields(){ - // make sure the default is set - assertEquals(screenManager.getDynamicMenuUpdatesMode(), DynamicMenuUpdatesMode.ON_WITH_COMPAT_MODE); - screenManager.setDynamicMenuUpdatesMode(DynamicMenuUpdatesMode.FORCE_ON); screenManager.setMenu(Test.GENERAL_MENUCELL_LIST); 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 3cccc2588..f47262dbd 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 @@ -62,6 +62,9 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +/** + * the Algorithm specific tests are defined based on: https://github.com/smartdevicelink/sdl_evolution/blob/master/proposals/0210-mobile-dynamic-menu-cell-updating.md + */ public class MenuManagerTests extends AndroidTestCase2 { private OnRPCNotificationListener onHMIStatusListener, commandListener; @@ -109,6 +112,7 @@ public class MenuManagerTests extends AndroidTestCase2 { assertEquals(menuManager.currentHMILevel, HMILevel.HMI_NONE); assertEquals(menuManager.getState(), BaseSubManager.SETTING_UP); assertEquals(menuManager.currentSystemContext, SystemContext.SYSCTXT_MAIN); + assertEquals(menuManager.dynamicMenuUpdatesMode, DynamicMenuUpdatesMode.ON_WITH_COMPAT_MODE); assertEquals(menuManager.lastMenuId, 1); assertNull(menuManager.menuCells); assertNull(menuManager.waitingUpdateMenuCells); @@ -126,6 +130,7 @@ public class MenuManagerTests extends AndroidTestCase2 { menuManager.dispose(); assertEquals(menuManager.currentSystemContext, SystemContext.SYSCTXT_MAIN); + assertEquals(menuManager.dynamicMenuUpdatesMode, DynamicMenuUpdatesMode.ON_WITH_COMPAT_MODE); assertEquals(menuManager.lastMenuId, 1); assertNull(menuManager.menuCells); assertNull(menuManager.oldMenuCells); @@ -170,8 +175,11 @@ public class MenuManagerTests extends AndroidTestCase2 { assertFalse(menuManager.waitingOnHMIUpdate); } - public void testUpdating(){ + public void testUpdatingOldWay(){ + // Force Menu Manager to use the old way of deleting / sending all + menuManager.setDynamicUpdatesMode(DynamicMenuUpdatesMode.FORCE_OFF); + assertEquals(menuManager.dynamicMenuUpdatesMode, DynamicMenuUpdatesMode.FORCE_OFF); // when we only send one command to update, we should only be returned one add command List newArray = Arrays.asList(mainCell1, mainCell4); assertEquals(menuManager.allCommandsForCells(newArray, false).size(), 4); // 1 root cells, 1 sub menu root cell, 2 sub menu cells @@ -209,6 +217,176 @@ public class MenuManagerTests extends AndroidTestCase2 { } } + public void testAlgorithmTest1(){ + + // Force Menu Manager to use the new way + menuManager.setDynamicUpdatesMode(DynamicMenuUpdatesMode.FORCE_ON); + assertEquals(menuManager.dynamicMenuUpdatesMode, DynamicMenuUpdatesMode.FORCE_ON); + + // start fresh + menuManager.oldMenuCells = null; + menuManager.menuCells = null; + menuManager.inProgressUpdate = null; + menuManager.waitingUpdateMenuCells = null; + menuManager.waitingOnHMIUpdate = false; + + menuManager.currentHMILevel = HMILevel.HMI_FULL; + // send new cells. They should set the old way + List oldMenu = createDynamicMenu1(); + List newMenu = createDynamicMenu1New(); + menuManager.setMenuCells(oldMenu); + assertEquals(menuManager.menuCells.size(), 4); + + // this happens in the menu manager but lets make sure its behaving + RunScore runScore = menuManager.runMenuCompareAlgorithm(oldMenu, newMenu); + + List oldMenuScore = Arrays.asList(0,0,0,0); + List newMenuScore = Arrays.asList(0,0,0,0,1); + + assertEquals(runScore.getScore(), 1); + assertEquals(runScore.getOldMenu(), oldMenuScore); + assertEquals(runScore.getCurrentMenu(), newMenuScore); + + menuManager.setMenuCells(newMenu); + assertEquals(menuManager.menuCells.size(), 5); + } + + public void testAlgorithmTest2(){ + + // Force Menu Manager to use the new way + menuManager.setDynamicUpdatesMode(DynamicMenuUpdatesMode.FORCE_ON); + assertEquals(menuManager.dynamicMenuUpdatesMode, DynamicMenuUpdatesMode.FORCE_ON); + + // start fresh + menuManager.oldMenuCells = null; + menuManager.menuCells = null; + menuManager.inProgressUpdate = null; + menuManager.waitingUpdateMenuCells = null; + menuManager.waitingOnHMIUpdate = false; + + menuManager.currentHMILevel = HMILevel.HMI_FULL; + // send new cells. They should set the old way + List oldMenu = createDynamicMenu2(); + List newMenu = createDynamicMenu2New(); + menuManager.setMenuCells(oldMenu); + assertEquals(menuManager.menuCells.size(), 4); + + // this happens in the menu manager but lets make sure its behaving + RunScore runScore = menuManager.runMenuCompareAlgorithm(oldMenu, newMenu); + + List oldMenuScore = Arrays.asList(0,0,0,2); + List newMenuScore = Arrays.asList(0,0,0); + + assertEquals(runScore.getScore(), 0); + assertEquals(runScore.getOldMenu(), oldMenuScore); + assertEquals(runScore.getCurrentMenu(), newMenuScore); + + menuManager.setMenuCells(newMenu); + assertEquals(menuManager.menuCells.size(), 3); + } + + public void testAlgorithmTest3(){ + + // Force Menu Manager to use the new way + menuManager.setDynamicUpdatesMode(DynamicMenuUpdatesMode.FORCE_ON); + assertEquals(menuManager.dynamicMenuUpdatesMode, DynamicMenuUpdatesMode.FORCE_ON); + + // start fresh + menuManager.oldMenuCells = null; + menuManager.menuCells = null; + menuManager.inProgressUpdate = null; + menuManager.waitingUpdateMenuCells = null; + menuManager.waitingOnHMIUpdate = false; + + menuManager.currentHMILevel = HMILevel.HMI_FULL; + // send new cells. They should set the old way + List oldMenu = createDynamicMenu3(); + List newMenu = createDynamicMenu3New(); + menuManager.setMenuCells(oldMenu); + assertEquals(menuManager.menuCells.size(), 3); + + // this happens in the menu manager but lets make sure its behaving + RunScore runScore = menuManager.runMenuCompareAlgorithm(oldMenu, newMenu); + + List oldMenuScore = Arrays.asList(2,2,2); + List newMenuScore = Arrays.asList(1,1,1); + + assertEquals(runScore.getScore(), 3); + assertEquals(runScore.getOldMenu(), oldMenuScore); + assertEquals(runScore.getCurrentMenu(), newMenuScore); + + menuManager.setMenuCells(newMenu); + assertEquals(menuManager.menuCells.size(), 3); + } + + public void testAlgorithmTest4(){ + + // Force Menu Manager to use the new way + menuManager.setDynamicUpdatesMode(DynamicMenuUpdatesMode.FORCE_ON); + assertEquals(menuManager.dynamicMenuUpdatesMode, DynamicMenuUpdatesMode.FORCE_ON); + + // start fresh + menuManager.oldMenuCells = null; + menuManager.menuCells = null; + menuManager.inProgressUpdate = null; + menuManager.waitingUpdateMenuCells = null; + menuManager.waitingOnHMIUpdate = false; + + menuManager.currentHMILevel = HMILevel.HMI_FULL; + // send new cells. They should set the old way + List oldMenu = createDynamicMenu4(); + List newMenu = createDynamicMenu4New(); + menuManager.setMenuCells(oldMenu); + assertEquals(menuManager.menuCells.size(), 4); + + // this happens in the menu manager but lets make sure its behaving + RunScore runScore = menuManager.runMenuCompareAlgorithm(oldMenu, newMenu); + + List oldMenuScore = Arrays.asList(0,2,0,2); + List newMenuScore = Arrays.asList(1,0,1,0); + + assertEquals(runScore.getScore(), 2); + assertEquals(runScore.getOldMenu(), oldMenuScore); + assertEquals(runScore.getCurrentMenu(), newMenuScore); + + menuManager.setMenuCells(newMenu); + assertEquals(menuManager.menuCells.size(), 4); + } + + public void testAlgorithmTest5(){ + + // Force Menu Manager to use the new way + menuManager.setDynamicUpdatesMode(DynamicMenuUpdatesMode.FORCE_ON); + assertEquals(menuManager.dynamicMenuUpdatesMode, DynamicMenuUpdatesMode.FORCE_ON); + + // start fresh + menuManager.oldMenuCells = null; + menuManager.menuCells = null; + menuManager.inProgressUpdate = null; + menuManager.waitingUpdateMenuCells = null; + menuManager.waitingOnHMIUpdate = false; + + menuManager.currentHMILevel = HMILevel.HMI_FULL; + // send new cells. They should set the old way + List oldMenu = createDynamicMenu5(); + List newMenu = createDynamicMenu5New(); + menuManager.setMenuCells(oldMenu); + assertEquals(menuManager.menuCells.size(), 4); + + // this happens in the menu manager but lets make sure its behaving + RunScore runScore = menuManager.runMenuCompareAlgorithm(oldMenu, newMenu); + + List oldMenuScore = Arrays.asList(2,0,0,0); + List newMenuScore = Arrays.asList(0,0,0,1); + + assertEquals(runScore.getScore(), 1); + assertEquals(runScore.getOldMenu(), oldMenuScore); + assertEquals(runScore.getCurrentMenu(), newMenuScore); + + menuManager.setMenuCells(newMenu); + assertEquals(menuManager.menuCells.size(), 4); + } + private List createTestCells(){ // menu cell mock listener @@ -237,6 +415,190 @@ public class MenuManagerTests extends AndroidTestCase2 { return Arrays.asList(mainCell1, mainCell2, mainCell3, mainCell4); } + private List createDynamicMenu1(){ + + MenuSelectionListener menuSelectionListenerA = mock(MenuSelectionListener.class); + MenuSelectionListener menuSelectionListenerB = mock(MenuSelectionListener.class); + MenuSelectionListener menuSelectionListenerC = mock(MenuSelectionListener.class); + MenuSelectionListener menuSelectionListenerD = mock(MenuSelectionListener.class); + + MenuCell A = new MenuCell("A", null, null, menuSelectionListenerA); + + MenuCell B = new MenuCell("B", null, null, menuSelectionListenerB); + + MenuCell C = new MenuCell("C",null, null, menuSelectionListenerC); + + MenuCell D = new MenuCell("D", null, null, menuSelectionListenerD); + + return Arrays.asList(A, B, C, D); + + } + + private List createDynamicMenu1New(){ + + MenuSelectionListener menuSelectionListenerA = mock(MenuSelectionListener.class); + MenuSelectionListener menuSelectionListenerB = mock(MenuSelectionListener.class); + MenuSelectionListener menuSelectionListenerC = mock(MenuSelectionListener.class); + MenuSelectionListener menuSelectionListenerD = mock(MenuSelectionListener.class); + MenuSelectionListener menuSelectionListenerE = mock(MenuSelectionListener.class); + + MenuCell A = new MenuCell("A", null, null, menuSelectionListenerA); + + MenuCell B = new MenuCell("B", null, null, menuSelectionListenerB); + + MenuCell C = new MenuCell("C",null, null, menuSelectionListenerC); + + MenuCell D = new MenuCell("D", null, null, menuSelectionListenerD); + + MenuCell E = new MenuCell("E", null, null, menuSelectionListenerE); + + return Arrays.asList(A, B, C, D, E); + + } + + private List createDynamicMenu2(){ + + MenuSelectionListener menuSelectionListenerA = mock(MenuSelectionListener.class); + MenuSelectionListener menuSelectionListenerB = mock(MenuSelectionListener.class); + MenuSelectionListener menuSelectionListenerC = mock(MenuSelectionListener.class); + MenuSelectionListener menuSelectionListenerD = mock(MenuSelectionListener.class); + + MenuCell A = new MenuCell("A", null, null, menuSelectionListenerA); + + MenuCell B = new MenuCell("B", null, null, menuSelectionListenerB); + + MenuCell C = new MenuCell("C",null, null, menuSelectionListenerC); + + MenuCell D = new MenuCell("D", null, null, menuSelectionListenerD); + + return Arrays.asList(A, B, C, D); + + } + + private List createDynamicMenu2New(){ + + MenuSelectionListener menuSelectionListenerA = mock(MenuSelectionListener.class); + MenuSelectionListener menuSelectionListenerB = mock(MenuSelectionListener.class); + MenuSelectionListener menuSelectionListenerC = mock(MenuSelectionListener.class); + + MenuCell A = new MenuCell("A", null, null, menuSelectionListenerA); + + MenuCell B = new MenuCell("B", null, null, menuSelectionListenerB); + + MenuCell C = new MenuCell("C",null, null, menuSelectionListenerC); + + return Arrays.asList(A, B, C); + + } + + private List createDynamicMenu3(){ + + MenuSelectionListener menuSelectionListenerA = mock(MenuSelectionListener.class); + MenuSelectionListener menuSelectionListenerB = mock(MenuSelectionListener.class); + MenuSelectionListener menuSelectionListenerC = mock(MenuSelectionListener.class); + + MenuCell A = new MenuCell("A", null, null, menuSelectionListenerA); + + MenuCell B = new MenuCell("B", null, null, menuSelectionListenerB); + + MenuCell C = new MenuCell("C",null, null, menuSelectionListenerC); + + return Arrays.asList(A, B, C); + + } + + private List createDynamicMenu3New(){ + + MenuSelectionListener menuSelectionListenerD = mock(MenuSelectionListener.class); + MenuSelectionListener menuSelectionListenerE = mock(MenuSelectionListener.class); + MenuSelectionListener menuSelectionListenerF = mock(MenuSelectionListener.class); + + MenuCell D = new MenuCell("D", null, null, menuSelectionListenerD); + + MenuCell E = new MenuCell("E", null, null, menuSelectionListenerE); + + MenuCell F = new MenuCell("F", null, null, menuSelectionListenerF); + + return Arrays.asList(D, E, F); + + } + + private List createDynamicMenu4(){ + + MenuSelectionListener menuSelectionListenerA = mock(MenuSelectionListener.class); + MenuSelectionListener menuSelectionListenerB = mock(MenuSelectionListener.class); + MenuSelectionListener menuSelectionListenerC = mock(MenuSelectionListener.class); + MenuSelectionListener menuSelectionListenerD = mock(MenuSelectionListener.class); + + MenuCell A = new MenuCell("A", null, null, menuSelectionListenerA); + + MenuCell B = new MenuCell("B", null, null, menuSelectionListenerB); + + MenuCell C = new MenuCell("C",null, null, menuSelectionListenerC); + + MenuCell D = new MenuCell("D", null, null, menuSelectionListenerD); + + return Arrays.asList(A, B, C, D); + + } + + private List createDynamicMenu4New(){ + + MenuSelectionListener menuSelectionListenerA = mock(MenuSelectionListener.class); + MenuSelectionListener menuSelectionListenerB = mock(MenuSelectionListener.class); + MenuSelectionListener menuSelectionListenerC = mock(MenuSelectionListener.class); + MenuSelectionListener menuSelectionListenerD = mock(MenuSelectionListener.class); + + MenuCell A = new MenuCell("A", null, null, menuSelectionListenerA); + + MenuCell B = new MenuCell("B", null, null, menuSelectionListenerB); + + MenuCell C = new MenuCell("C",null, null, menuSelectionListenerC); + + MenuCell D = new MenuCell("D", null, null, menuSelectionListenerD); + + return Arrays.asList(B, A, D, C); + + } + + private List createDynamicMenu5(){ + + MenuSelectionListener menuSelectionListenerA = mock(MenuSelectionListener.class); + MenuSelectionListener menuSelectionListenerB = mock(MenuSelectionListener.class); + MenuSelectionListener menuSelectionListenerC = mock(MenuSelectionListener.class); + MenuSelectionListener menuSelectionListenerD = mock(MenuSelectionListener.class); + + MenuCell A = new MenuCell("A", null, null, menuSelectionListenerA); + + MenuCell B = new MenuCell("B", null, null, menuSelectionListenerB); + + MenuCell C = new MenuCell("C",null, null, menuSelectionListenerC); + + MenuCell D = new MenuCell("D", null, null, menuSelectionListenerD); + + return Arrays.asList(A, B, C, D); + + } + + private List createDynamicMenu5New(){ + + MenuSelectionListener menuSelectionListenerA = mock(MenuSelectionListener.class); + MenuSelectionListener menuSelectionListenerB = mock(MenuSelectionListener.class); + MenuSelectionListener menuSelectionListenerC = mock(MenuSelectionListener.class); + MenuSelectionListener menuSelectionListenerD = mock(MenuSelectionListener.class); + + MenuCell A = new MenuCell("A", null, null, menuSelectionListenerA); + + MenuCell B = new MenuCell("B", null, null, menuSelectionListenerB); + + MenuCell C = new MenuCell("C",null, null, menuSelectionListenerC); + + MenuCell D = new MenuCell("D", null, null, menuSelectionListenerD); + + return Arrays.asList(B, C, D, A); + + } + // Emulate what happens when Core sends OnHMIStatus notification private void sendFakeCoreOnHMIFullNotifications() { OnHMIStatus onHMIStatusFakeNotification = new OnHMIStatus(); 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 1d39bfa58..d6b4afcf9 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 @@ -527,7 +527,7 @@ abstract class BaseMenuManager extends BaseSubManager { // COMPARISONS - private RunScore runMenuCompareAlgorithm(List oldCells, List newCells){ + RunScore runMenuCompareAlgorithm(List oldCells, List newCells){ if (oldCells == null || oldCells.size() == 0){ return null; -- cgit v1.2.1 From 232e349285220b667150eee28efdd86ac7703c88 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Tue, 28 May 2019 15:37:40 -0400 Subject: additional testing --- .../managers/screen/menu/MenuManagerTests.java | 56 +++++++++++++++++++--- .../managers/screen/menu/BaseMenuManager.java | 2 + 2 files changed, 51 insertions(+), 7 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 f47262dbd..73581cab4 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 @@ -118,6 +118,8 @@ public class MenuManagerTests extends AndroidTestCase2 { assertNull(menuManager.waitingUpdateMenuCells); assertNull(menuManager.oldMenuCells); assertNull(menuManager.inProgressUpdate); + assertNull(menuManager.keepsNew); + assertNull(menuManager.keepsOld); assertNotNull(menuManager.hmiListener); assertNotNull(menuManager.commandListener); assertNotNull(menuManager.displayListener); @@ -138,6 +140,8 @@ public class MenuManagerTests extends AndroidTestCase2 { assertNull(menuManager.displayCapabilities); assertNull(menuManager.inProgressUpdate); assertNull(menuManager.waitingUpdateMenuCells); + assertNull(menuManager.keepsNew); + assertNull(menuManager.keepsOld); // after everything, make sure we are in the correct state assertEquals(menuManager.getState(), BaseSubManager.SHUTDOWN); @@ -185,6 +189,9 @@ public class MenuManagerTests extends AndroidTestCase2 { assertEquals(menuManager.allCommandsForCells(newArray, false).size(), 4); // 1 root cells, 1 sub menu root cell, 2 sub menu cells menuManager.currentHMILevel = HMILevel.HMI_FULL; menuManager.setMenuCells(newArray); + // Algorithm should NOT have run + assertNull(menuManager.keepsNew); + assertNull(menuManager.keepsOld); // Unlike voice commands, the Menu Manager dynamically assigns Cell ID's. Because of this, we need to get the updated // cell list after setting it and then test the listeners, as they use the newly assigned cell ID's. @@ -249,6 +256,8 @@ public class MenuManagerTests extends AndroidTestCase2 { menuManager.setMenuCells(newMenu); assertEquals(menuManager.menuCells.size(), 5); + assertEquals(menuManager.keepsNew.size(), 4); + assertEquals(menuManager.keepsOld.size(), 4); } public void testAlgorithmTest2(){ @@ -283,6 +292,8 @@ public class MenuManagerTests extends AndroidTestCase2 { menuManager.setMenuCells(newMenu); assertEquals(menuManager.menuCells.size(), 3); + assertEquals(menuManager.keepsNew.size(), 3); + assertEquals(menuManager.keepsOld.size(), 3); } public void testAlgorithmTest3(){ @@ -317,6 +328,8 @@ public class MenuManagerTests extends AndroidTestCase2 { menuManager.setMenuCells(newMenu); assertEquals(menuManager.menuCells.size(), 3); + assertEquals(menuManager.keepsNew.size(), 0); + assertEquals(menuManager.keepsOld.size(), 0); } public void testAlgorithmTest4(){ @@ -351,6 +364,8 @@ public class MenuManagerTests extends AndroidTestCase2 { menuManager.setMenuCells(newMenu); assertEquals(menuManager.menuCells.size(), 4); + assertEquals(menuManager.keepsNew.size(), 2); + assertEquals(menuManager.keepsOld.size(), 2); } public void testAlgorithmTest5(){ @@ -385,8 +400,42 @@ public class MenuManagerTests extends AndroidTestCase2 { menuManager.setMenuCells(newMenu); assertEquals(menuManager.menuCells.size(), 4); + assertEquals(menuManager.keepsNew.size(), 3); + assertEquals(menuManager.keepsOld.size(), 3); } + public void testClearingMenu(){ + + // Make sure we can send an empty menu with no issues + // start fresh + menuManager.oldMenuCells = null; + menuManager.menuCells = null; + menuManager.inProgressUpdate = null; + menuManager.waitingUpdateMenuCells = null; + menuManager.waitingOnHMIUpdate = false; + + menuManager.currentHMILevel = HMILevel.HMI_FULL; + // send new cells. They should set the old way + List oldMenu = createDynamicMenu1(); + List newMenu = Collections.emptyList(); + menuManager.setMenuCells(oldMenu); + assertEquals(menuManager.menuCells.size(), 4); + + menuManager.setMenuCells(newMenu); + assertEquals(menuManager.menuCells.size(), 0); + } + + // HELPERS + + // Emulate what happens when Core sends OnHMIStatus notification + private void sendFakeCoreOnHMIFullNotifications() { + OnHMIStatus onHMIStatusFakeNotification = new OnHMIStatus(); + onHMIStatusFakeNotification.setHmiLevel(HMILevel.HMI_FULL); + onHMIStatusListener.onNotified(onHMIStatusFakeNotification); + } + + // CREATING CELLS FOR TEST CASES + private List createTestCells(){ // menu cell mock listener @@ -599,11 +648,4 @@ public class MenuManagerTests extends AndroidTestCase2 { } - // Emulate what happens when Core sends OnHMIStatus notification - private void sendFakeCoreOnHMIFullNotifications() { - OnHMIStatus onHMIStatusFakeNotification = new OnHMIStatus(); - onHMIStatusFakeNotification.setHmiLevel(HMILevel.HMI_FULL); - onHMIStatusListener.onNotified(onHMIStatusFakeNotification); - } - } 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 d6b4afcf9..f0fe26a08 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 @@ -135,6 +135,8 @@ abstract class BaseMenuManager extends BaseSubManager { hasQueuedUpdate = false; waitingOnHMIUpdate = false; waitingUpdateMenuCells = null; + keepsNew = null; + keepsOld = null; // remove listeners internalInterface.removeOnRPCNotificationListener(FunctionID.ON_HMI_STATUS, hmiListener); -- cgit v1.2.1 From 5ecc90b3c37ea10099f1fe4e4e93ec9456d93651 Mon Sep 17 00:00:00 2001 From: BrettyWhite Date: Tue, 28 May 2019 16:06:50 -0400 Subject: remove unneeded logs --- .../managers/screen/menu/BaseMenuManager.java | 32 ---------------------- 1 file changed, 32 deletions(-) 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 f0fe26a08..db58c80a0 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 @@ -975,22 +975,6 @@ abstract class BaseMenuManager extends BaseSubManager { subMenuCommands = subMenuCommandsForCells(menu, true); } - for (RPCRequest request : mainMenuCommands){ - try { - Log.i("ADD MENU COMMAND: ", request.serializeJSON().toString()); - } catch (JSONException e) { - e.printStackTrace(); - } - } - - for (RPCRequest request : subMenuCommands){ - try { - Log.i("ADD SUB MENU COMMAND: ", request.serializeJSON().toString()); - } catch (JSONException e) { - e.printStackTrace(); - } - } - // add all built commands to inProgressUpdate inProgressUpdate = new ArrayList<>(mainMenuCommands); inProgressUpdate.addAll(subMenuCommands); @@ -1096,14 +1080,6 @@ abstract class BaseMenuManager extends BaseSubManager { mainMenuCommands = createCommandsForDynamicSubCells(newMenu, adds, true); } - for (RPCRequest request : mainMenuCommands){ - try { - Log.i("DYNAMIC SUB ADD COMMAN ", request.serializeJSON().toString()); - } catch (JSONException e) { - e.printStackTrace(); - } - } - internalInterface.sendSequentialRPCs(mainMenuCommands, new OnMultipleRequestListener() { @Override public void onUpdate(int remainingRequests) { @@ -1168,14 +1144,6 @@ abstract class BaseMenuManager extends BaseSubManager { return; } - for (RPCRequest delete : deleteCommands){ - try { - Log.i("MENU CELL DELETE: ", delete.serializeJSON().toString()); - } catch (JSONException e) { - e.printStackTrace(); - } - } - internalInterface.sendRequests(deleteCommands, new OnMultipleRequestListener() { @Override public void onUpdate(int remainingRequests) { -- cgit v1.2.1 From 186681984d56b29ed528870ec1c885ff950955c0 Mon Sep 17 00:00:00 2001 From: Bilal Alsharifi Date: Thu, 30 May 2019 10:26:36 -0400 Subject: Remove unused var --- .../com/smartdevicelink/managers/screen/menu/MenuCell.java | 8 +------- .../smartdevicelink/managers/screen/menu/VoiceCommand.java | 11 ----------- 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java index 0f067b4a4..781216028 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java @@ -81,11 +81,6 @@ public class MenuCell { */ private static final int MAX_ID = 2000000000; - /** - * A lock used when setting / getting states - */ - private final Object STATE_LOCK = new Object(); - // CONSTRUCTORS // SINGLE MENU ITEM CONSTRUCTORS @@ -274,8 +269,7 @@ public class MenuCell { // if this is not an instance of this class, not the same if (!(o instanceof MenuCell)) return false; - MenuCell menuCell = (MenuCell) o; // if we get to this point, create the hashes and compare them - return hashCode() == menuCell.hashCode(); + return hashCode() == o.hashCode(); } } diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommand.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommand.java index 02a7afff9..8227b3087 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommand.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/VoiceCommand.java @@ -117,15 +117,4 @@ public class VoiceCommand { int getCommandId() { return commandId; } - - // HELPER - - /** - * Get the description of the cell - * @return a String description of the cell object - */ - @Override - public String toString(){ - return "VOICE COMMAND - ID: "+commandId+ " - First Object: "+ ((voiceCommands.size() > 0) ? voiceCommands.get(0) : "Empty List")+ " - Voice Command List Size: "+ voiceCommands.size(); - } } -- cgit v1.2.1 From 4358049123222c144a07cc07e1b85ce653b3c362 Mon Sep 17 00:00:00 2001 From: Bilal Alsharifi Date: Thu, 30 May 2019 11:51:31 -0400 Subject: Create a deep copy of the menuCells internally --- .../managers/file/filetypes/SdlArtwork.java | 56 ++++++++++++++++++---- .../managers/screen/BaseScreenManager.java | 1 + .../managers/screen/menu/BaseMenuManager.java | 19 +++++++- .../managers/screen/menu/MenuCell.java | 37 +++++++++++++- .../managers/file/filetypes/SdlArtwork.java | 51 ++++++++++++++++---- 5 files changed, 145 insertions(+), 19 deletions(-) diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/managers/file/filetypes/SdlArtwork.java b/android/sdl_android/src/main/java/com/smartdevicelink/managers/file/filetypes/SdlArtwork.java index 805fd775a..22dc3eaf6 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/managers/file/filetypes/SdlArtwork.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/managers/file/filetypes/SdlArtwork.java @@ -35,15 +35,19 @@ package com.smartdevicelink.managers.file.filetypes; import android.net.Uri; import android.support.annotation.NonNull; +import com.smartdevicelink.managers.screen.menu.MenuCell; import com.smartdevicelink.proxy.rpc.Image; import com.smartdevicelink.proxy.rpc.enums.FileType; import com.smartdevicelink.proxy.rpc.enums.ImageType; import com.smartdevicelink.proxy.rpc.enums.StaticIconName; +import java.util.ArrayList; +import java.util.Arrays; + /** * A class that extends SdlFile, representing artwork (JPEG, PNG, or BMP) to be uploaded to core */ -public class SdlArtwork extends SdlFile { +public class SdlArtwork extends SdlFile implements Cloneable{ private boolean isTemplate; private Image imageRPC; @@ -125,14 +129,50 @@ public class SdlArtwork extends SdlFile { */ public Image getImageRPC() { if (imageRPC == null) { - if (isStaticIcon()) { - imageRPC = new Image(getName(), ImageType.STATIC); - imageRPC.setIsTemplate(true); - } else { - imageRPC = new Image(getName(), ImageType.DYNAMIC); - imageRPC.setIsTemplate(isTemplate); - } + imageRPC = createImageRPC(); } return imageRPC; } + + private Image createImageRPC(){ + Image image; + if (isStaticIcon()) { + image = new Image(getName(), ImageType.STATIC); + image.setIsTemplate(true); + } else { + image = new Image(getName(), ImageType.DYNAMIC); + image.setIsTemplate(isTemplate); + } + return image; + } + + /** + * Creates a deep copy of the object + * @return deep copy of the object + */ + @Override + public SdlArtwork clone() { + final SdlArtwork clone; + try { + clone = (SdlArtwork) super.clone(); + } catch (CloneNotSupportedException e) { + throw new RuntimeException("superclass messed up", e); + } + clone.setName(this.getName()); + clone.setResourceId(this.getResourceId()); + clone.setUri(Uri.parse(this.getUri().toString())); + if (this.getFileData() != null){ + byte[] data = new byte[this.getFileData().length]; + for (int i = 0; i < this.getFileData().length; i++) { + data[i] = this.getFileData()[i]; + } + clone.setFileData(data); + } + clone.setType(this.getType()); + clone.setPersistent(this.isPersistent()); + clone.setStaticIcon(this.isStaticIcon()); + clone.isTemplate = this.isTemplate; + clone.imageRPC = this.createImageRPC(); + return clone; + } } \ No newline at end of file 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 1047f4d67..6795b4d9d 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/BaseScreenManager.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/BaseScreenManager.java @@ -390,6 +390,7 @@ abstract class BaseScreenManager extends BaseSubManager { /** * Creates and sends all associated Menu RPCs + * Note: the manager will store a deep copy the menuCells internally to be able to handle future updates correctly * @param menuCells - the menu cells that are to be sent to the head unit, including their sub-cells. */ public void setMenu(List menuCells){ 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 db58c80a0..3b23d6b47 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 @@ -158,10 +158,13 @@ abstract class BaseMenuManager extends BaseSubManager { */ public void setMenuCells(List cells){ + // Create a deep copy of the list so future changes by developers don't affect the algorithm logic + List clonedCells = cloneMenuCellsList(cells); + if (currentHMILevel == null || currentHMILevel.equals(HMILevel.HMI_NONE) || currentSystemContext.equals(SystemContext.SYSCTXT_MENU)){ // We are in NONE or the menu is in use, bail out of here waitingOnHMIUpdate = true; - waitingUpdateMenuCells = new ArrayList<>(cells); + waitingUpdateMenuCells = new ArrayList<>(clonedCells); return; } waitingOnHMIUpdate = false; @@ -172,7 +175,7 @@ abstract class BaseMenuManager extends BaseSubManager { oldMenuCells = new ArrayList<>(menuCells); } // copy new list - menuCells = new ArrayList<>(cells); + menuCells = new ArrayList<>(clonedCells); // HashSet order doesnt matter / does not allow duplicates HashSet titleCheckSet = new HashSet<>(); @@ -1169,4 +1172,16 @@ abstract class BaseMenuManager extends BaseSubManager { }); } + private List cloneMenuCellsList (List originalList){ + if (originalList == null){ + return null; + } + + List clone = new ArrayList<>(); + for (MenuCell menuCell : originalList){ + clone.add(menuCell.clone()); + } + return clone; + } + } diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java index 781216028..a772862f8 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java @@ -37,9 +37,10 @@ import android.support.annotation.Nullable; import com.smartdevicelink.managers.file.filetypes.SdlArtwork; +import java.util.ArrayList; import java.util.List; -public class MenuCell { +public class MenuCell implements Cloneable{ /** * The cell's text to be displayed @@ -272,4 +273,38 @@ public class MenuCell { // if we get to this point, create the hashes and compare them return hashCode() == o.hashCode(); } + + /** + * Creates a deep copy of the object + * @return deep copy of the object + */ + @Override + public MenuCell clone() { + final MenuCell clone; + try { + clone = (MenuCell) super.clone(); + } catch (CloneNotSupportedException e) { + throw new RuntimeException("superclass messed up", e); + } + clone.title = this.title; + clone.icon = this.icon == null ? null : this.icon.clone(); + clone.voiceCommands = null; + if (this.voiceCommands != null){ + clone.voiceCommands = new ArrayList<>(); + for (String voiceCommand : this.voiceCommands) { + clone.voiceCommands.add(voiceCommand); + } + } + clone.subCells = null; + if (this.subCells != null) { + clone.subCells = new ArrayList<>(); + for (MenuCell subCell : this.subCells) { + clone.subCells.add(subCell == null ? null : subCell.clone()); + } + } + clone.menuSelectionListener = this.menuSelectionListener; + clone.parentCellId = this.parentCellId; + clone.cellId = this.cellId; + return clone; + } } diff --git a/javaSE/src/main/java/com/smartdevicelink/managers/file/filetypes/SdlArtwork.java b/javaSE/src/main/java/com/smartdevicelink/managers/file/filetypes/SdlArtwork.java index 6e8085e0a..f13b523aa 100644 --- a/javaSE/src/main/java/com/smartdevicelink/managers/file/filetypes/SdlArtwork.java +++ b/javaSE/src/main/java/com/smartdevicelink/managers/file/filetypes/SdlArtwork.java @@ -40,7 +40,7 @@ import com.smartdevicelink.proxy.rpc.enums.StaticIconName; /** * A class that extends SdlFile, representing artwork (JPEG, PNG, or BMP) to be uploaded to core */ -public class SdlArtwork extends SdlFile { +public class SdlArtwork extends SdlFile implements Cloneable{ private boolean isTemplate; private Image imageRPC; @@ -112,14 +112,49 @@ public class SdlArtwork extends SdlFile { */ public Image getImageRPC() { if (imageRPC == null) { - if (isStaticIcon()) { - imageRPC = new Image(getName(), ImageType.STATIC); - imageRPC.setIsTemplate(true); - } else { - imageRPC = new Image(getName(), ImageType.DYNAMIC); - imageRPC.setIsTemplate(isTemplate); - } + imageRPC = createImageRPC(); } return imageRPC; } + + private Image createImageRPC(){ + Image image; + if (isStaticIcon()) { + image = new Image(getName(), ImageType.STATIC); + image.setIsTemplate(true); + } else { + image = new Image(getName(), ImageType.DYNAMIC); + image.setIsTemplate(isTemplate); + } + return image; + } + + /** + * Creates a deep copy of the object + * @return deep copy of the object + */ + @Override + public SdlArtwork clone() { + final SdlArtwork clone; + try { + clone = (SdlArtwork) super.clone(); + } catch (CloneNotSupportedException e) { + throw new RuntimeException("superclass messed up", e); + } + clone.setName(this.getName()); + clone.setFilePath(this.getFilePath()); + if (this.getFileData() != null){ + byte[] data = new byte[this.getFileData().length]; + for (int i = 0; i < this.getFileData().length; i++) { + data[i] = this.getFileData()[i]; + } + clone.setFileData(data); + } + clone.setType(this.getType()); + clone.setPersistent(this.isPersistent()); + clone.setStaticIcon(this.isStaticIcon()); + clone.isTemplate = this.isTemplate; + clone.imageRPC = this.createImageRPC(); + return clone; + } } \ No newline at end of file -- cgit v1.2.1 From 71422fde26587b15ea037acd401088dd88b14d7e Mon Sep 17 00:00:00 2001 From: Bilal Alsharifi Date: Thu, 30 May 2019 14:16:05 -0400 Subject: optimize imports --- .../com/smartdevicelink/test/proxy/SystemCapabilityManagerTests.java | 1 - .../smartdevicelink/test/rpc/datatypes/AppServiceCapabilityTest.java | 3 --- .../java/com/smartdevicelink/managers/file/filetypes/SdlArtwork.java | 4 ---- .../java/com/smartdevicelink/managers/screen/BaseScreenManager.java | 4 ++-- .../com/smartdevicelink/managers/screen/menu/BaseMenuManager.java | 1 - 5 files changed, 2 insertions(+), 11 deletions(-) diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/proxy/SystemCapabilityManagerTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/proxy/SystemCapabilityManagerTests.java index baa53272b..385a6d12a 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/proxy/SystemCapabilityManagerTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/proxy/SystemCapabilityManagerTests.java @@ -37,7 +37,6 @@ import com.smartdevicelink.proxy.rpc.listeners.OnMultipleRequestListener; import com.smartdevicelink.proxy.rpc.listeners.OnRPCListener; import com.smartdevicelink.proxy.rpc.listeners.OnRPCNotificationListener; import com.smartdevicelink.proxy.rpc.listeners.OnRPCRequestListener; -import com.smartdevicelink.proxy.rpc.listeners.OnRPCResponseListener; import com.smartdevicelink.streaming.audio.AudioStreamingCodec; import com.smartdevicelink.streaming.audio.AudioStreamingParams; import com.smartdevicelink.streaming.video.VideoStreamingParameters; diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/AppServiceCapabilityTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/AppServiceCapabilityTest.java index ca03861cd..997984514 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/AppServiceCapabilityTest.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/test/rpc/datatypes/AppServiceCapabilityTest.java @@ -5,9 +5,6 @@ import com.smartdevicelink.protocol.enums.FunctionID; import com.smartdevicelink.proxy.rpc.AppServiceCapability; import com.smartdevicelink.proxy.rpc.AppServiceManifest; import com.smartdevicelink.proxy.rpc.AppServiceRecord; -import com.smartdevicelink.proxy.rpc.MediaServiceManifest; -import com.smartdevicelink.proxy.rpc.NavigationServiceManifest; -import com.smartdevicelink.proxy.rpc.SdlMsgVersion; import com.smartdevicelink.proxy.rpc.enums.AppServiceType; import com.smartdevicelink.proxy.rpc.enums.ServiceUpdateReason; import com.smartdevicelink.test.JsonUtils; diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/managers/file/filetypes/SdlArtwork.java b/android/sdl_android/src/main/java/com/smartdevicelink/managers/file/filetypes/SdlArtwork.java index 22dc3eaf6..ec01f84e4 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/managers/file/filetypes/SdlArtwork.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/managers/file/filetypes/SdlArtwork.java @@ -35,15 +35,11 @@ package com.smartdevicelink.managers.file.filetypes; import android.net.Uri; import android.support.annotation.NonNull; -import com.smartdevicelink.managers.screen.menu.MenuCell; import com.smartdevicelink.proxy.rpc.Image; import com.smartdevicelink.proxy.rpc.enums.FileType; import com.smartdevicelink.proxy.rpc.enums.ImageType; import com.smartdevicelink.proxy.rpc.enums.StaticIconName; -import java.util.ArrayList; -import java.util.Arrays; - /** * A class that extends SdlFile, representing artwork (JPEG, PNG, or BMP) to be uploaded to core */ 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 6795b4d9d..fea7513f4 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/BaseScreenManager.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/BaseScreenManager.java @@ -39,10 +39,10 @@ import com.smartdevicelink.managers.CompletionListener; import com.smartdevicelink.managers.file.FileManager; import com.smartdevicelink.managers.file.filetypes.SdlArtwork; import com.smartdevicelink.managers.screen.menu.DynamicMenuUpdatesMode; -import com.smartdevicelink.managers.screen.menu.MenuManager; -import com.smartdevicelink.managers.screen.menu.VoiceCommandManager; import com.smartdevicelink.managers.screen.menu.MenuCell; +import com.smartdevicelink.managers.screen.menu.MenuManager; import com.smartdevicelink.managers.screen.menu.VoiceCommand; +import com.smartdevicelink.managers.screen.menu.VoiceCommandManager; import com.smartdevicelink.proxy.interfaces.ISdl; import com.smartdevicelink.proxy.rpc.enums.MetadataType; import com.smartdevicelink.proxy.rpc.enums.TextAlignment; 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 3b23d6b47..d3df2d3d6 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 @@ -33,7 +33,6 @@ package com.smartdevicelink.managers.screen.menu; import android.support.annotation.NonNull; -import android.util.Log; import com.smartdevicelink.managers.BaseSubManager; import com.smartdevicelink.managers.CompletionListener; -- cgit v1.2.1 From ffb97d5a9b5161a99377bc1135a9db180baffcbe Mon Sep 17 00:00:00 2001 From: Bilal Alsharifi Date: Thu, 30 May 2019 15:52:37 -0400 Subject: Add some break statements --- .../managers/screen/menu/BaseMenuManager.java | 29 ++++++++++++---------- 1 file changed, 16 insertions(+), 13 deletions(-) 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 d3df2d3d6..20ab24994 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 @@ -375,13 +375,13 @@ abstract class BaseMenuManager extends BaseSubManager { keepsNew.add(menuCells.get(x)); } } - List addsWithNewIds = updateIdsOnDynamicCells(adds); + updateIdsOnDynamicCells(adds); // this is needed for the onCommands to still work transferIdsToKeptCells(keepsNew); - if (addsWithNewIds != null && addsWithNewIds.size() > 0){ + if (adds != null && adds.size() > 0){ DebugTool.logInfo("Sending root menu updates"); - sendDynamicRootMenuRPCs(deleteCommands, addsWithNewIds); + sendDynamicRootMenuRPCs(deleteCommands, adds); }else{ DebugTool.logInfo("All root menu items are kept. Check the sub menus"); runSubMenuCompareAlgorithm(); @@ -647,7 +647,7 @@ abstract class BaseMenuManager extends BaseSubManager { // IDs - private List updateIdsOnDynamicCells(List dynamicCells){ + private void updateIdsOnDynamicCells(List dynamicCells){ if (menuCells != null && menuCells.size() > 0 && dynamicCells != null && dynamicCells.size() > 0) { for (int z = 0; z < menuCells.size(); z++) { MenuCell mainCell = menuCells.get(z); @@ -661,12 +661,11 @@ abstract class BaseMenuManager extends BaseSubManager { if (mainCell.getSubCells() != null && mainCell.getSubCells().size() > 0) { updateIdsOnMenuCells(mainCell.getSubCells(), mainCell.getCellId()); } + break; } } } - return dynamicCells; } - return null; } private List updateIdsOnDynamicSubCells(List oldList, List dynamicCells, Integer parentId){ @@ -692,14 +691,14 @@ abstract class BaseMenuManager extends BaseSubManager { return null; } - private void updateIdsOnMenuCells(List cells, int parentId){ + private void updateIdsOnMenuCells(List cells, int parentId) { for (MenuCell cell : cells) { - int newId = ++lastMenuId; - cell.setCellId(newId); - cell.setParentCellId(parentId); - if (cell.getSubCells() != null && cell.getSubCells().size() > 0) { - updateIdsOnMenuCells(cell.getSubCells(), cell.getCellId()); - } + int newId = ++lastMenuId; + cell.setCellId(newId); + cell.setParentCellId(parentId); + if (cell.getSubCells() != null && cell.getSubCells().size() > 0) { + updateIdsOnMenuCells(cell.getSubCells(), cell.getCellId()); + } } } @@ -710,6 +709,7 @@ abstract class BaseMenuManager extends BaseSubManager { MenuCell keptCell = keeps.get(i); if (oldCell.equals(keptCell)) { keptCell.setCellId(oldCell.getCellId()); + break; } } } @@ -722,6 +722,7 @@ abstract class BaseMenuManager extends BaseSubManager { MenuCell keptCell = keeps.get(i); if (oldCell.equals(keptCell)) { keptCell.setCellId(oldCell.getCellId()); + break; } } } @@ -759,6 +760,7 @@ abstract class BaseMenuManager extends BaseSubManager { } else { builtCommands.add(commandForMenuCell(addCell, shouldHaveArtwork, z)); } + break; } } } @@ -800,6 +802,7 @@ abstract class BaseMenuManager extends BaseSubManager { MenuCell cell = cells.get(i); if (cell.equals(oldCell)){ builtCommands.add(commandForMenuCell(cell, shouldHaveArtwork, z)); + break; } } } -- cgit v1.2.1 From 2b9f472c92ca237ec647c4744cd711e25e91ed60 Mon Sep 17 00:00:00 2001 From: Bilal Alsharifi Date: Thu, 30 May 2019 16:50:37 -0400 Subject: Fix NPE in SdlArtwork.clone() --- .../java/com/smartdevicelink/managers/file/filetypes/SdlArtwork.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/managers/file/filetypes/SdlArtwork.java b/android/sdl_android/src/main/java/com/smartdevicelink/managers/file/filetypes/SdlArtwork.java index ec01f84e4..b1885d1a9 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/managers/file/filetypes/SdlArtwork.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/managers/file/filetypes/SdlArtwork.java @@ -156,7 +156,7 @@ public class SdlArtwork extends SdlFile implements Cloneable{ } clone.setName(this.getName()); clone.setResourceId(this.getResourceId()); - clone.setUri(Uri.parse(this.getUri().toString())); + clone.setUri(this.getUri() == null ? null : Uri.parse(this.getUri().toString())); if (this.getFileData() != null){ byte[] data = new byte[this.getFileData().length]; for (int i = 0; i < this.getFileData().length; i++) { -- cgit v1.2.1 From c9dd5c014f4713232bf8d613367d37e7403b6a1d Mon Sep 17 00:00:00 2001 From: Bilal Alsharifi Date: Fri, 31 May 2019 15:25:01 -0400 Subject: Add NonNull annotations --- .../managers/screen/BaseScreenManager.java | 6 +++--- .../managers/screen/menu/BaseMenuManager.java | 15 +++++++-------- 2 files changed, 10 insertions(+), 11 deletions(-) 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 fea7513f4..2afd0f6f6 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/BaseScreenManager.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/BaseScreenManager.java @@ -376,7 +376,7 @@ abstract class BaseScreenManager extends BaseSubManager { * Set voice commands * @param voiceCommands the voice commands to be sent to the head unit */ - public void setVoiceCommands(List voiceCommands){ + public void setVoiceCommands(@NonNull List voiceCommands){ this.voiceCommandManager.setVoiceCommands(voiceCommands); } @@ -393,7 +393,7 @@ abstract class BaseScreenManager extends BaseSubManager { * Note: the manager will store a deep copy the menuCells internally to be able to handle future updates correctly * @param menuCells - the menu cells that are to be sent to the head unit, including their sub-cells. */ - public void setMenu(List menuCells){ + public void setMenu(@NonNull List menuCells){ this.menuManager.setMenuCells(menuCells); } @@ -401,7 +401,7 @@ abstract class BaseScreenManager extends BaseSubManager { * Sets the behavior of how menus are updated. For explanations of the differences, see {@link DynamicMenuUpdatesMode} * @param value - the update mode */ - public void setDynamicMenuUpdatesMode(DynamicMenuUpdatesMode value){ + public void setDynamicMenuUpdatesMode(@NonNull DynamicMenuUpdatesMode value){ this.menuManager.setDynamicUpdatesMode(value); } 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 20ab24994..33b002513 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 @@ -147,7 +147,7 @@ abstract class BaseMenuManager extends BaseSubManager { // SETTERS - public void setDynamicUpdatesMode(DynamicMenuUpdatesMode value){ + public void setDynamicUpdatesMode(@NonNull DynamicMenuUpdatesMode value){ this.dynamicMenuUpdatesMode = value; } @@ -155,7 +155,7 @@ abstract class BaseMenuManager extends BaseSubManager { * Creates and sends all associated Menu RPCs * @param cells - the menu cells that are to be sent to the head unit, including their sub-cells. */ - public void setMenuCells(List cells){ + public void setMenuCells(@NonNull List cells){ // Create a deep copy of the list so future changes by developers don't affect the algorithm logic List clonedCells = cloneMenuCellsList(cells); @@ -944,11 +944,11 @@ abstract class BaseMenuManager extends BaseSubManager { public void onComplete(boolean success) { inProgressUpdate = null; - if (!success){ + if (!success) { DebugTool.logError("Error Sending Current Menu"); } - if (hasQueuedUpdate){ + if (hasQueuedUpdate) { setMenuCells(waitingUpdateMenuCells); hasQueuedUpdate = false; } @@ -1174,16 +1174,15 @@ abstract class BaseMenuManager extends BaseSubManager { }); } - private List cloneMenuCellsList (List originalList){ - if (originalList == null){ + private List cloneMenuCellsList(List originalList) { + if (originalList == null) { return null; } List clone = new ArrayList<>(); - for (MenuCell menuCell : originalList){ + for (MenuCell menuCell : originalList) { clone.add(menuCell.clone()); } return clone; } - } -- cgit v1.2.1