summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Kast <julian@livio.com>2020-06-24 17:18:42 -0400
committerJulian Kast <julian@livio.com>2020-06-24 17:18:42 -0400
commit49646d926aed791dc23188c5ecb8983a4765418c (patch)
tree7e45b8a9445736c9d8168f41df6b9605c225c7d0
parentccb27966b55111996843ffb5ed6c4c8be6cd4942 (diff)
downloadsdl_android-49646d926aed791dc23188c5ecb8983a4765418c.tar.gz
Added subscribe to preset buttons to hello_sdl for android and javaSE
-rwxr-xr-xandroid/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlService.java52
-rw-r--r--hello_sdl_java/src/main/java/com/smartdevicelink/java/SdlService.java48
2 files changed, 98 insertions, 2 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 ec8afa812..090e53a91 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
@@ -12,6 +12,7 @@ import android.os.IBinder;
import android.util.Log;
import com.smartdevicelink.managers.CompletionListener;
+import com.smartdevicelink.managers.OnButtonListener;
import com.smartdevicelink.managers.SdlManager;
import com.smartdevicelink.managers.SdlManagerListener;
import com.smartdevicelink.managers.file.filetypes.SdlArtwork;
@@ -27,9 +28,12 @@ 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.OnButtonEvent;
+import com.smartdevicelink.proxy.rpc.OnButtonPress;
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.ButtonName;
import com.smartdevicelink.proxy.rpc.enums.FileType;
import com.smartdevicelink.proxy.rpc.enums.HMILevel;
import com.smartdevicelink.proxy.rpc.enums.InteractionMode;
@@ -78,6 +82,9 @@ public class SdlService extends Service {
private SdlManager sdlManager = null;
private List<ChoiceCell> choiceCellList;
+ private ButtonName[] buttonNames = {ButtonName.PRESET_0, ButtonName.PRESET_1, ButtonName.PRESET_2, ButtonName.PRESET_3, ButtonName.PRESET_4, ButtonName.PRESET_5, ButtonName.PRESET_6, ButtonName.PRESET_7};
+ private OnButtonListener onButtonListener;
+
@Override
public IBinder onBind(Intent intent) {
return null;
@@ -183,6 +190,7 @@ public class SdlService extends Service {
performWelcomeSpeak();
performWelcomeShow();
preloadChoices();
+ subscribeToPresetButtons();
}
}
});
@@ -339,8 +347,15 @@ public class SdlService extends Service {
}
});
+ MenuCell mainCell6 = new MenuCell("Unsubscribe to preset buttons",null, null, new MenuSelectionListener() {
+ @Override
+ public void onTriggered(TriggerSource trigger) {
+ unsubscribeToPresetButtons();
+ }
+ });
+
// Send the entire menu off to be created
- sdlManager.getScreenManager().setMenu(Arrays.asList(mainCell1, mainCell2, mainCell3, mainCell4, mainCell5));
+ sdlManager.getScreenManager().setMenu(Arrays.asList(mainCell1, mainCell2, mainCell3, mainCell4, mainCell5, mainCell6));
}
/**
@@ -371,6 +386,41 @@ public class SdlService extends Service {
}
/**
+ * Attempts to Subscribe to all preset buttons
+ */
+ private void subscribeToPresetButtons() {
+ onButtonListener = new OnButtonListener() {
+ @Override
+ public void onPress(ButtonName buttonName, OnButtonPress buttonPress) {
+ Log.i(TAG, "onPress: " + buttonName);
+ }
+
+ @Override
+ public void onEvent(ButtonName buttonName, OnButtonEvent buttonEvent) {
+ Log.i(TAG, "onEvent: " + buttonName + " " + buttonEvent);
+ }
+
+ @Override
+ public void onError(String info) {
+ Log.i(TAG, "onError: " + info);
+ }
+ };
+
+ for (ButtonName buttonName : buttonNames) {
+ sdlManager.getScreenManager().addButtonListener(buttonName, onButtonListener);
+ }
+ }
+
+ /**
+ * Attempts to Unsubscribe to all preset Buttons
+ */
+ private void unsubscribeToPresetButtons() {
+ for (ButtonName buttonName : buttonNames) {
+ sdlManager.getScreenManager().removeButtonListener(buttonName, onButtonListener);
+ }
+ }
+
+ /**
* Will show a sample test message on screen as well as speak a sample test message
*/
private void showTest(){
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 d4611e8b3..67d7c297e 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
@@ -34,6 +34,7 @@ package com.smartdevicelink.java;
import android.util.Log;
import com.smartdevicelink.managers.CompletionListener;
+import com.smartdevicelink.managers.OnButtonListener;
import com.smartdevicelink.managers.SdlManager;
import com.smartdevicelink.managers.SdlManagerListener;
import com.smartdevicelink.managers.file.filetypes.SdlArtwork;
@@ -84,6 +85,9 @@ public class SdlService {
private SdlServiceCallback callback;
+ private ButtonName[] buttonNames = {ButtonName.PRESET_0, ButtonName.PRESET_1, ButtonName.PRESET_2, ButtonName.PRESET_3, ButtonName.PRESET_4, ButtonName.PRESET_5, ButtonName.PRESET_6, ButtonName.PRESET_7};
+ private OnButtonListener onButtonListener;
+
public SdlService(BaseTransportConfig config, SdlServiceCallback callback){
this.callback = callback;
@@ -295,8 +299,15 @@ public class SdlService {
}
});
+ MenuCell mainCell6 = new MenuCell("Unsubscribe to preset buttons",null, null, new MenuSelectionListener() {
+ @Override
+ public void onTriggered(TriggerSource trigger) {
+ unsubscribeToPresetButtons();
+ }
+ });
+
// Send the entire menu off to be created
- sdlManager.getScreenManager().setMenu(Arrays.asList(mainCell1, mainCell2, mainCell3, mainCell4, mainCell5));
+ sdlManager.getScreenManager().setMenu(Arrays.asList(mainCell1, mainCell2, mainCell3, mainCell4, mainCell5, mainCell6));
}
/**
@@ -327,6 +338,41 @@ public class SdlService {
}
/**
+ * Attempts to Subscribe to all preset buttons
+ */
+ private void subscribeToPresetButtons() {
+ onButtonListener = new OnButtonListener() {
+ @Override
+ public void onPress(ButtonName buttonName, OnButtonPress buttonPress) {
+ Log.i(TAG, "onPress: " + buttonName);
+ }
+
+ @Override
+ public void onEvent(ButtonName buttonName, OnButtonEvent buttonEvent) {
+ Log.i(TAG, "onEvent: " + buttonName + " " + buttonEvent);
+ }
+
+ @Override
+ public void onError(String info) {
+ Log.i(TAG, "onError: " + info);
+ }
+ };
+
+ for (ButtonName buttonName : buttonNames) {
+ sdlManager.getScreenManager().addButtonListener(buttonName, onButtonListener);
+ }
+ }
+
+ /**
+ * Attempts to Unsubscribe to all preset Buttons
+ */
+ private void unsubscribeToPresetButtons() {
+ for (ButtonName buttonName : buttonNames) {
+ sdlManager.getScreenManager().removeButtonListener(buttonName, onButtonListener);
+ }
+ }
+
+ /**
* Will show a sample test message on screen as well as speak a sample test message
*/
private void showTest(){