diff options
author | BrettyWhite <geekman3454@protonmail.com> | 2019-04-29 16:52:41 -0400 |
---|---|---|
committer | BrettyWhite <geekman3454@protonmail.com> | 2019-04-29 16:52:41 -0400 |
commit | 5276306957fc821d99f020065ffe51e2209fb068 (patch) | |
tree | 9d1ff47de135414ff351309df86a884018cc5b77 | |
parent | 1c295a6528abcacc6ee4605d0c1b9df564ae5576 (diff) | |
download | sdl_android-5276306957fc821d99f020065ffe51e2209fb068.tar.gz |
some debugging
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<String> titleCheckSet = new HashSet<>(); HashSet<String> 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<SdlArtwork> artworksToBeUploaded = findAllArtworksToBeUploadedFromCells(menuCells); + List<SdlArtwork> 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<RPCRequest> 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<ImageField> imageFields = displayCapabilities.getImageFields(); - for (ImageField field: imageFields){ - if (field.getName().equals(ImageFieldName.cmdIcon)){ - return true; + if (displayCapabilities != null && displayCapabilities.getImageFields() != null) { + List<ImageField> 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<RPCRequest> subMenuCommandsForCells(List<MenuCell> cells, boolean shouldHaveArtwork){ List<RPCRequest> 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); } |