summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Henigan <robert.henigan@livio.io>2020-10-05 11:04:45 -0400
committerGitHub <noreply@github.com>2020-10-05 11:04:45 -0400
commitfb5bc6eb580902a3c13f7d079d71599f4b3bf6f4 (patch)
tree355caf51e3d33bd22a31694b4895a620aac9e146
parent3f91db4adcfc285b8c06cab0d1f81887fa1d25a4 (diff)
parentd4f285d22f00e10cdb20e159f3862fd5afeeab41 (diff)
downloadsdl_android-fb5bc6eb580902a3c13f7d079d71599f4b3bf6f4.tar.gz
Merge pull request #1522 from smartdevicelink/feature/reformat_hello_sdl_code
Reformat hello sdl code
-rwxr-xr-xandroid/hello_sdl_android/build.gradle2
-rwxr-xr-xandroid/hello_sdl_android/src/main/AndroidManifest.xml25
-rwxr-xr-xandroid/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/MainActivity.java58
-rwxr-xr-xandroid/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java46
-rwxr-xr-xandroid/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlRouterService.java3
-rwxr-xr-xandroid/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlService.java786
-rwxr-xr-xandroid/hello_sdl_android/src/main/res/layout/activity_main.xml2
-rwxr-xr-xandroid/hello_sdl_android/src/main/res/menu/main.xml4
-rwxr-xr-xandroid/hello_sdl_android/src/main/res/xml/accessory_filter.xml2
-rw-r--r--javaEE/hello_sdl_java_ee/src/main/java/com/smartdevicelink/Main.java6
-rw-r--r--javaEE/hello_sdl_java_ee/src/main/java/com/smartdevicelink/SdlService.java89
-rw-r--r--javaSE/hello_sdl_java/src/main/java/com/smartdevicelink/java/Main.java6
-rw-r--r--javaSE/hello_sdl_java/src/main/java/com/smartdevicelink/java/SdlService.java84
13 files changed, 559 insertions, 554 deletions
diff --git a/android/hello_sdl_android/build.gradle b/android/hello_sdl_android/build.gradle
index f990b38e6..6270e028d 100755
--- a/android/hello_sdl_android/build.gradle
+++ b/android/hello_sdl_android/build.gradle
@@ -17,7 +17,7 @@ android {
}
}
flavorDimensions "default"
- productFlavors{
+ productFlavors {
multi_sec_high {
buildConfigField 'String', 'TRANSPORT', '"MULTI"'
buildConfigField 'String', 'SECURITY', '"HIGH"'
diff --git a/android/hello_sdl_android/src/main/AndroidManifest.xml b/android/hello_sdl_android/src/main/AndroidManifest.xml
index 214a04355..289b4c7e7 100755
--- a/android/hello_sdl_android/src/main/AndroidManifest.xml
+++ b/android/hello_sdl_android/src/main/AndroidManifest.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- package="com.sdl.hellosdlandroid">
+ xmlns:tools="http://schemas.android.com/tools"
+ package="com.sdl.hellosdlandroid">
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.INTERNET" />
@@ -20,7 +20,7 @@
tools:ignore="DeepLinks">
<activity
android:name=".MainActivity"
- android:label="@string/app_name" >
+ android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
@@ -28,8 +28,9 @@
</intent-filter>
</activity>
- <activity android:name="com.smartdevicelink.transport.USBAccessoryAttachmentActivity"
- android:launchMode="singleTop">
+ <activity
+ android:name="com.smartdevicelink.transport.USBAccessoryAttachmentActivity"
+ android:launchMode="singleTop">
<intent-filter>
<action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" />
</intent-filter>
@@ -49,23 +50,27 @@
android:process="com.smartdevicelink.router"
android:foregroundServiceType="connectedDevice">
<intent-filter>
- <action android:name="com.smartdevicelink.router.service"/>
+ <action android:name="com.smartdevicelink.router.service" />
</intent-filter>
- <meta-data android:name="@string/sdl_router_service_version_name" android:value="@integer/sdl_router_service_version_value" />
+ <meta-data
+ android:name="@string/sdl_router_service_version_name"
+ android:value="@integer/sdl_router_service_version_value" />
</service>
+
<receiver
android:name=".SdlReceiver"
android:enabled="true"
android:exported="true"
tools:ignore="ExportedReceiver">
<intent-filter>
- <action android:name="com.smartdevicelink.USB_ACCESSORY_ATTACHED"/> <!--For AOA -->
+ <action android:name="com.smartdevicelink.USB_ACCESSORY_ATTACHED" /> <!--For AOA -->
<action android:name="android.bluetooth.device.action.ACL_CONNECTED" />
<action android:name="sdl.router.startservice" />
</intent-filter>
</receiver>
- <activity android:name="com.smartdevicelink.managers.lockscreen.SDLLockScreenActivity"
- android:launchMode="singleTop"/>
+ <activity
+ android:name="com.smartdevicelink.managers.lockscreen.SDLLockScreenActivity"
+ android:launchMode="singleTop" />
</application>
</manifest> \ No newline at end of file
diff --git a/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/MainActivity.java b/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/MainActivity.java
index 69a86129a..43ad79ac7 100755
--- a/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/MainActivity.java
+++ b/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/MainActivity.java
@@ -9,35 +9,35 @@ import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- //If we are connected to a module we want to start our SdlService
- if(BuildConfig.TRANSPORT.equals("MULTI") || BuildConfig.TRANSPORT.equals("MULTI_HB")) {
- SdlReceiver.queryForConnectedService(this);
- }else if(BuildConfig.TRANSPORT.equals("TCP")) {
- Intent proxyIntent = new Intent(this, SdlService.class);
- startService(proxyIntent);
- }
- }
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_main);
+ //If we are connected to a module we want to start our SdlService
+ if (BuildConfig.TRANSPORT.equals("MULTI") || BuildConfig.TRANSPORT.equals("MULTI_HB")) {
+ SdlReceiver.queryForConnectedService(this);
+ } else if (BuildConfig.TRANSPORT.equals("TCP")) {
+ Intent proxyIntent = new Intent(this, SdlService.class);
+ startService(proxyIntent);
+ }
+ }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.main, menu);
- return true;
- }
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ // Inflate the menu; this adds items to the action bar if it is present.
+ getMenuInflater().inflate(R.menu.main, menu);
+ return true;
+ }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
- int id = item.getItemId();
- if (id == R.id.action_settings) {
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ // Handle action bar item clicks here. The action bar will
+ // automatically handle clicks on the Home/Up button, so long
+ // as you specify a parent activity in AndroidManifest.xml.
+ int id = item.getItemId();
+ if (id == R.id.action_settings) {
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
}
diff --git a/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java b/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java
index a63258a49..32c0ab1d5 100755
--- a/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java
+++ b/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlReceiver.java
@@ -8,31 +8,31 @@ import com.smartdevicelink.transport.SdlBroadcastReceiver;
import com.smartdevicelink.transport.SdlRouterService;
import com.smartdevicelink.util.DebugTool;
-public class SdlReceiver extends SdlBroadcastReceiver {
- private static final String TAG = "SdlBroadcastReceiver";
+public class SdlReceiver extends SdlBroadcastReceiver {
+ private static final String TAG = "SdlBroadcastReceiver";
- @Override
- public void onSdlEnabled(Context context, Intent intent) {
- DebugTool.logInfo(TAG, "SDL Enabled");
- intent.setClass(context, SdlService.class);
+ @Override
+ public void onSdlEnabled(Context context, Intent intent) {
+ DebugTool.logInfo(TAG, "SDL Enabled");
+ intent.setClass(context, SdlService.class);
- // SdlService needs to be foregrounded in Android O and above
- // This will prevent apps in the background from crashing when they try to start SdlService
- // Because Android O doesn't allow background apps to start background services
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- context.startForegroundService(intent);
- } else {
- context.startService(intent);
- }
- }
+ // SdlService needs to be foregrounded in Android O and above
+ // This will prevent apps in the background from crashing when they try to start SdlService
+ // Because Android O doesn't allow background apps to start background services
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ context.startForegroundService(intent);
+ } else {
+ context.startService(intent);
+ }
+ }
- @Override
- public Class<? extends SdlRouterService> defineLocalSdlRouterClass() {
- return com.sdl.hellosdlandroid.SdlRouterService.class;
- }
+ @Override
+ public Class<? extends SdlRouterService> defineLocalSdlRouterClass() {
+ return com.sdl.hellosdlandroid.SdlRouterService.class;
+ }
- @Override
- public void onReceive(Context context, Intent intent) {
- super.onReceive(context, intent); // Required if overriding this method
- }
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ super.onReceive(context, intent); // Required if overriding this method
+ }
} \ No newline at end of file
diff --git a/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlRouterService.java b/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlRouterService.java
index b4bec8cde..b04939034 100755
--- a/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlRouterService.java
+++ b/android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlRouterService.java
@@ -1,8 +1,7 @@
package com.sdl.hellosdlandroid;
-public class SdlRouterService extends com.smartdevicelink.transport.SdlRouterService {
-
+public class SdlRouterService extends com.smartdevicelink.transport.SdlRouterService {
}
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 9a7ef2eeb..0b83e0842 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
@@ -56,397 +56,397 @@ import java.util.Vector;
public class SdlService extends Service {
- private static final String TAG = "SDL Service";
-
- private static final String APP_NAME = "Hello Sdl";
- private static final String APP_NAME_ES = "Hola Sdl";
- private static final String APP_NAME_FR = "Bonjour Sdl";
- private static final String APP_ID = "8678309";
-
- private static final String ICON_FILENAME = "hello_sdl_icon.png";
- private static final String SDL_IMAGE_FILENAME = "sdl_full_image.png";
-
- private static final String WELCOME_SHOW = "Welcome to HelloSDL";
- 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 FOREGROUND_SERVICE_ID = 111;
-
- // 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 = 12247;
- private static final String DEV_MACHINE_IP_ADDRESS = "m.sdl.tools";
-
- // variable to create and call functions of the SyncProxy
- private SdlManager sdlManager = null;
- private List<ChoiceCell> choiceCellList;
-
- @Override
- public IBinder onBind(Intent intent) {
- return null;
- }
-
- @Override
- public void onCreate() {
- Log.d(TAG, "onCreate");
- super.onCreate();
-
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- enterForeground();
- }
- }
-
- // Helper method to let the service enter foreground mode
- @SuppressLint("NewApi")
- public void enterForeground() {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- NotificationChannel channel = new NotificationChannel(APP_ID, "SdlService", NotificationManager.IMPORTANCE_DEFAULT);
- NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
- if (notificationManager != null) {
- notificationManager.createNotificationChannel(channel);
- Notification serviceNotification = new Notification.Builder(this, channel.getId())
- .setContentTitle("Connected through SDL")
- .setSmallIcon(R.drawable.ic_sdl)
- .build();
- startForeground(FOREGROUND_SERVICE_ID, serviceNotification);
- }
- }
- }
-
- @Override
- public int onStartCommand(Intent intent, int flags, int startId) {
- startProxy();
- return START_STICKY;
- }
-
- @Override
- public void onDestroy() {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- stopForeground(true);
- }
-
- if (sdlManager != null) {
- sdlManager.dispose();
- }
-
- super.onDestroy();
- }
-
- private void startProxy() {
- // This logic is to select the correct transport and security levels defined in the selected build flavor
- // Build flavors are selected by the "build variants" tab typically located in the bottom left of Android Studio
- // Typically in your app, you will only set one of these.
- if (sdlManager == null) {
- Log.i(TAG, "Starting SDL Proxy");
- // Enable DebugTool for debug build type
- if (BuildConfig.DEBUG){
- DebugTool.enableDebugTool();
- }
- BaseTransportConfig transport = null;
- if (BuildConfig.TRANSPORT.equals("MULTI")) {
- int securityLevel;
- if (BuildConfig.SECURITY.equals("HIGH")) {
- securityLevel = MultiplexTransportConfig.FLAG_MULTI_SECURITY_HIGH;
- } else if (BuildConfig.SECURITY.equals("MED")) {
- securityLevel = MultiplexTransportConfig.FLAG_MULTI_SECURITY_MED;
- } else if (BuildConfig.SECURITY.equals("LOW")) {
- securityLevel = MultiplexTransportConfig.FLAG_MULTI_SECURITY_LOW;
- } else {
- securityLevel = MultiplexTransportConfig.FLAG_MULTI_SECURITY_OFF;
- }
- transport = new MultiplexTransportConfig(this, APP_ID, securityLevel);
- } else if (BuildConfig.TRANSPORT.equals("TCP")) {
- transport = new TCPTransportConfig(TCP_PORT, DEV_MACHINE_IP_ADDRESS, true);
- } else if (BuildConfig.TRANSPORT.equals("MULTI_HB")) {
- MultiplexTransportConfig mtc = new MultiplexTransportConfig(this, APP_ID, MultiplexTransportConfig.FLAG_MULTI_SECURITY_OFF);
- mtc.setRequiresHighBandwidth(true);
- transport = mtc;
- }
-
- // The app type to be used
- Vector<AppHMIType> appType = new Vector<>();
- appType.add(AppHMIType.DEFAULT);
-
- // The manager listener helps you know when certain events that pertain to the SDL Manager happen
- // Here we will listen for ON_HMI_STATUS and ON_COMMAND notifications
- SdlManagerListener listener = new SdlManagerListener() {
- @Override
- public void onStart() {
- // HMI Status Listener
- sdlManager.addOnRPCNotificationListener(FunctionID.ON_HMI_STATUS, new OnRPCNotificationListener() {
- @Override
- public void onNotified(RPCNotification notification) {
- OnHMIStatus onHMIStatus = (OnHMIStatus)notification;
- if (onHMIStatus.getWindowID() != null && onHMIStatus.getWindowID() != PredefinedWindows.DEFAULT_WINDOW.getValue()) {
- return;
- }
- if (onHMIStatus.getHmiLevel() == HMILevel.HMI_FULL && onHMIStatus.getFirstRun()) {
- setVoiceCommands();
- sendMenus();
- performWelcomeSpeak();
- performWelcomeShow();
- preloadChoices();
- subscribeToButtons();
- }
- }
- });
- }
-
- @Override
- public void onDestroy() {
- SdlService.this.stopSelf();
- }
-
- @Override
- public void onError(String info, Exception e) {
- }
-
- @Override
- public LifecycleConfigurationUpdate managerShouldUpdateLifecycle(Language language, Language hmiLanguage) {
- boolean isNeedUpdate = false;
- String appName = APP_NAME;
- String ttsName = APP_NAME;
- switch (language) {
- case ES_MX:
- isNeedUpdate = true;
- ttsName = APP_NAME_ES;
- break;
- case FR_CA:
- isNeedUpdate = true;
- ttsName = APP_NAME_FR;
- break;
- default:
- break;
- }
- switch (hmiLanguage) {
- case ES_MX:
- isNeedUpdate = true;
- appName = APP_NAME_ES;
- break;
- case FR_CA:
- isNeedUpdate = true;
- appName = APP_NAME_FR;
- break;
- default:
- break;
- }
- if (isNeedUpdate) {
- Vector<TTSChunk> chunks = new Vector<>(Collections.singletonList(new TTSChunk(ttsName, SpeechCapabilities.TEXT)));
- return new LifecycleConfigurationUpdate(appName, null, chunks, null);
- } else {
- return null;
- }
- }
- };
-
- // Create App Icon, this is set in the SdlManager builder
- SdlArtwork appIcon = new SdlArtwork(ICON_FILENAME, FileType.GRAPHIC_PNG, R.mipmap.ic_launcher, true);
-
- // The manager builder sets options for your session
- SdlManager.Builder builder = new SdlManager.Builder(this, APP_ID, APP_NAME, listener);
- builder.setAppTypes(appType);
- builder.setTransportType(transport);
- builder.setAppIcon(appIcon);
- sdlManager = builder.build();
- sdlManager.start();
- }
- }
-
- /**
- * Send some voice commands
- */
- private void setVoiceCommands(){
-
- List<String> list1 = Collections.singletonList("Command One");
- List<String> list2 = Collections.singletonList("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<String> voice2 = Collections.singletonList("Cell two");
-
- 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();
- }
- });
-
- 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)", MenuLayout.LIST, null, Arrays.asList(subCell1,subCell2));
-
- MenuCell mainCell4 = new MenuCell("Show Perform Interaction", null, null, new MenuSelectionListener() {
- @Override
- public void onTriggered(TriggerSource trigger) {
- showPerformInteraction();
- }
- });
-
- MenuCell mainCell5 = 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.<MenuCell>emptyList());
- showAlert("Menu Cleared");
- }
- });
-
- // Send the entire menu off to be created
- sdlManager.getScreenManager().setMenu(Arrays.asList(mainCell1, mainCell2, mainCell3, mainCell4, mainCell5));
- }
-
- /**
- * Will speak a sample welcome message
- */
- private void performWelcomeSpeak(){
- List<TTSChunk> chunks = Collections.singletonList(new TTSChunk(WELCOME_SPEAK, SpeechCapabilities.TEXT));
- sdlManager.sendRPC(new Speak(chunks));
- }
-
- /**
- * Use the Screen Manager to set the initial screen text and set the image.
- * Because we are setting multiple items, we will call beginTransaction() first,
- * and finish with commit() when we are done.
- */
- private void performWelcomeShow() {
- sdlManager.getScreenManager().beginTransaction();
- sdlManager.getScreenManager().setTextField1(APP_NAME);
- sdlManager.getScreenManager().setTextField2(WELCOME_SHOW);
- sdlManager.getScreenManager().setPrimaryGraphic(new SdlArtwork(SDL_IMAGE_FILENAME, FileType.GRAPHIC_PNG, R.drawable.sdl, true));
- sdlManager.getScreenManager().commit(new CompletionListener() {
- @Override
- public void onComplete(boolean success) {
- if (success){
- Log.i(TAG, "welcome show successful");
- }
- }
- });
- }
-
- /**
- * Attempts to Subscribe to all preset buttons
- */
- private void subscribeToButtons() {
- ButtonName[] buttonNames = {ButtonName.PLAY_PAUSE, ButtonName.SEEKLEFT, ButtonName.SEEKRIGHT, ButtonName.AC_MAX, ButtonName.AC, ButtonName.RECIRCULATE,
- ButtonName.FAN_UP, ButtonName.FAN_DOWN, ButtonName.TEMP_UP, ButtonName.TEMP_DOWN, ButtonName.FAN_DOWN, ButtonName.DEFROST_MAX, ButtonName.DEFROST_REAR, ButtonName.DEFROST,
- ButtonName.UPPER_VENT, ButtonName.LOWER_VENT, ButtonName.VOLUME_UP, ButtonName.VOLUME_DOWN, ButtonName.EJECT, ButtonName.SOURCE, ButtonName.SHUFFLE, ButtonName.REPEAT};
-
- OnButtonListener onButtonListener = new OnButtonListener() {
- @Override
- public void onPress(ButtonName buttonName, OnButtonPress buttonPress) {
- sdlManager.getScreenManager().setTextField1(buttonName + " pressed");
- }
-
- @Override
- public void onEvent(ButtonName buttonName, OnButtonEvent buttonEvent) {
- sdlManager.getScreenManager().setTextField2(buttonName + " " + buttonEvent.getButtonEventMode());
- }
-
- @Override
- public void onError(String info) {
- Log.i(TAG, "onError: " + info);
- }
- };
-
- for (ButtonName buttonName : buttonNames) {
- sdlManager.getScreenManager().addButtonListener(buttonName, onButtonListener);
- }
- }
-
- /**
- * Will show a sample test message on screen as well as speak a sample test message
- */
- private void showTest(){
- sdlManager.getScreenManager().beginTransaction();
- sdlManager.getScreenManager().setTextField1("Test Cell 1 has been selected");
- sdlManager.getScreenManager().setTextField2("");
- sdlManager.getScreenManager().commit(null);
-
- List<TTSChunk> chunks = Collections.singletonList(new TTSChunk(TEST_COMMAND_NAME, SpeechCapabilities.TEXT));
- sdlManager.sendRPC(new Speak(chunks));
- }
-
- private void showAlert(String text){
- Alert alert = new Alert();
- alert.setAlertText1(text);
- alert.setDuration(5000);
- sdlManager.sendRPC(alert);
- }
-
- // Choice Set
-
- private void preloadChoices(){
- ChoiceCell cell1 = new ChoiceCell("Item 1");
- ChoiceCell cell2 = new ChoiceCell("Item 2");
- ChoiceCell cell3 = new ChoiceCell("Item 3");
- choiceCellList = new ArrayList<>(Arrays.asList(cell1,cell2,cell3));
- sdlManager.getScreenManager().preloadChoices(choiceCellList, null);
- }
-
- private void showPerformInteraction(){
- if (choiceCellList != null) {
- ChoiceSet choiceSet = new ChoiceSet("Choose an Item from the list", choiceCellList, new ChoiceSetSelectionListener() {
- @Override
- public void onChoiceSelected(ChoiceCell choiceCell, TriggerSource triggerSource, int rowIndex) {
- showAlert(choiceCell.getText() + " was selected");
- }
-
- @Override
- public void onError(String error) {
- Log.e(TAG, "There was an error showing the perform interaction: "+ error);
- }
- });
- sdlManager.getScreenManager().presentChoiceSet(choiceSet, InteractionMode.MANUAL_ONLY);
- }
- }
+ private static final String TAG = "SDL Service";
+
+ private static final String APP_NAME = "Hello Sdl";
+ private static final String APP_NAME_ES = "Hola Sdl";
+ private static final String APP_NAME_FR = "Bonjour Sdl";
+ private static final String APP_ID = "8678309";
+
+ private static final String ICON_FILENAME = "hello_sdl_icon.png";
+ private static final String SDL_IMAGE_FILENAME = "sdl_full_image.png";
+
+ private static final String WELCOME_SHOW = "Welcome to HelloSDL";
+ 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 FOREGROUND_SERVICE_ID = 111;
+
+ // 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 = 12247;
+ private static final String DEV_MACHINE_IP_ADDRESS = "m.sdl.tools";
+
+ // variable to create and call functions of the SyncProxy
+ private SdlManager sdlManager = null;
+ private List<ChoiceCell> choiceCellList;
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ return null;
+ }
+
+ @Override
+ public void onCreate() {
+ Log.d(TAG, "onCreate");
+ super.onCreate();
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ enterForeground();
+ }
+ }
+
+ // Helper method to let the service enter foreground mode
+ @SuppressLint("NewApi")
+ public void enterForeground() {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ NotificationChannel channel = new NotificationChannel(APP_ID, "SdlService", NotificationManager.IMPORTANCE_DEFAULT);
+ NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
+ if (notificationManager != null) {
+ notificationManager.createNotificationChannel(channel);
+ Notification serviceNotification = new Notification.Builder(this, channel.getId())
+ .setContentTitle("Connected through SDL")
+ .setSmallIcon(R.drawable.ic_sdl)
+ .build();
+ startForeground(FOREGROUND_SERVICE_ID, serviceNotification);
+ }
+ }
+ }
+
+ @Override
+ public int onStartCommand(Intent intent, int flags, int startId) {
+ startProxy();
+ return START_STICKY;
+ }
+
+ @Override
+ public void onDestroy() {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ stopForeground(true);
+ }
+
+ if (sdlManager != null) {
+ sdlManager.dispose();
+ }
+
+ super.onDestroy();
+ }
+
+ private void startProxy() {
+ // This logic is to select the correct transport and security levels defined in the selected build flavor
+ // Build flavors are selected by the "build variants" tab typically located in the bottom left of Android Studio
+ // Typically in your app, you will only set one of these.
+ if (sdlManager == null) {
+ Log.i(TAG, "Starting SDL Proxy");
+ // Enable DebugTool for debug build type
+ if (BuildConfig.DEBUG) {
+ DebugTool.enableDebugTool();
+ }
+ BaseTransportConfig transport = null;
+ if (BuildConfig.TRANSPORT.equals("MULTI")) {
+ int securityLevel;
+ if (BuildConfig.SECURITY.equals("HIGH")) {
+ securityLevel = MultiplexTransportConfig.FLAG_MULTI_SECURITY_HIGH;
+ } else if (BuildConfig.SECURITY.equals("MED")) {
+ securityLevel = MultiplexTransportConfig.FLAG_MULTI_SECURITY_MED;
+ } else if (BuildConfig.SECURITY.equals("LOW")) {
+ securityLevel = MultiplexTransportConfig.FLAG_MULTI_SECURITY_LOW;
+ } else {
+ securityLevel = MultiplexTransportConfig.FLAG_MULTI_SECURITY_OFF;
+ }
+ transport = new MultiplexTransportConfig(this, APP_ID, securityLevel);
+ } else if (BuildConfig.TRANSPORT.equals("TCP")) {
+ transport = new TCPTransportConfig(TCP_PORT, DEV_MACHINE_IP_ADDRESS, true);
+ } else if (BuildConfig.TRANSPORT.equals("MULTI_HB")) {
+ MultiplexTransportConfig mtc = new MultiplexTransportConfig(this, APP_ID, MultiplexTransportConfig.FLAG_MULTI_SECURITY_OFF);
+ mtc.setRequiresHighBandwidth(true);
+ transport = mtc;
+ }
+
+ // The app type to be used
+ Vector<AppHMIType> appType = new Vector<>();
+ appType.add(AppHMIType.DEFAULT);
+
+ // The manager listener helps you know when certain events that pertain to the SDL Manager happen
+ // Here we will listen for ON_HMI_STATUS and ON_COMMAND notifications
+ SdlManagerListener listener = new SdlManagerListener() {
+ @Override
+ public void onStart() {
+ // HMI Status Listener
+ sdlManager.addOnRPCNotificationListener(FunctionID.ON_HMI_STATUS, new OnRPCNotificationListener() {
+ @Override
+ public void onNotified(RPCNotification notification) {
+ OnHMIStatus onHMIStatus = (OnHMIStatus) notification;
+ if (onHMIStatus.getWindowID() != null && onHMIStatus.getWindowID() != PredefinedWindows.DEFAULT_WINDOW.getValue()) {
+ return;
+ }
+ if (onHMIStatus.getHmiLevel() == HMILevel.HMI_FULL && onHMIStatus.getFirstRun()) {
+ setVoiceCommands();
+ sendMenus();
+ performWelcomeSpeak();
+ performWelcomeShow();
+ preloadChoices();
+ subscribeToButtons();
+ }
+ }
+ });
+ }
+
+ @Override
+ public void onDestroy() {
+ SdlService.this.stopSelf();
+ }
+
+ @Override
+ public void onError(String info, Exception e) {
+ }
+
+ @Override
+ public LifecycleConfigurationUpdate managerShouldUpdateLifecycle(Language language, Language hmiLanguage) {
+ boolean isNeedUpdate = false;
+ String appName = APP_NAME;
+ String ttsName = APP_NAME;
+ switch (language) {
+ case ES_MX:
+ isNeedUpdate = true;
+ ttsName = APP_NAME_ES;
+ break;
+ case FR_CA:
+ isNeedUpdate = true;
+ ttsName = APP_NAME_FR;
+ break;
+ default:
+ break;
+ }
+ switch (hmiLanguage) {
+ case ES_MX:
+ isNeedUpdate = true;
+ appName = APP_NAME_ES;
+ break;
+ case FR_CA:
+ isNeedUpdate = true;
+ appName = APP_NAME_FR;
+ break;
+ default:
+ break;
+ }
+ if (isNeedUpdate) {
+ Vector<TTSChunk> chunks = new Vector<>(Collections.singletonList(new TTSChunk(ttsName, SpeechCapabilities.TEXT)));
+ return new LifecycleConfigurationUpdate(appName, null, chunks, null);
+ } else {
+ return null;
+ }
+ }
+ };
+
+ // Create App Icon, this is set in the SdlManager builder
+ SdlArtwork appIcon = new SdlArtwork(ICON_FILENAME, FileType.GRAPHIC_PNG, R.mipmap.ic_launcher, true);
+
+ // The manager builder sets options for your session
+ SdlManager.Builder builder = new SdlManager.Builder(this, APP_ID, APP_NAME, listener);
+ builder.setAppTypes(appType);
+ builder.setTransportType(transport);
+ builder.setAppIcon(appIcon);
+ sdlManager = builder.build();
+ sdlManager.start();
+ }
+ }
+
+ /**
+ * Send some voice commands
+ */
+ private void setVoiceCommands() {
+
+ List<String> list1 = Collections.singletonList("Command One");
+ List<String> list2 = Collections.singletonList("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<String> voice2 = Collections.singletonList("Cell two");
+
+ 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();
+ }
+ });
+
+ 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)", MenuLayout.LIST, null, Arrays.asList(subCell1, subCell2));
+
+ MenuCell mainCell4 = new MenuCell("Show Perform Interaction", null, null, new MenuSelectionListener() {
+ @Override
+ public void onTriggered(TriggerSource trigger) {
+ showPerformInteraction();
+ }
+ });
+
+ MenuCell mainCell5 = 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.<MenuCell>emptyList());
+ showAlert("Menu Cleared");
+ }
+ });
+
+ // Send the entire menu off to be created
+ sdlManager.getScreenManager().setMenu(Arrays.asList(mainCell1, mainCell2, mainCell3, mainCell4, mainCell5));
+ }
+
+ /**
+ * Will speak a sample welcome message
+ */
+ private void performWelcomeSpeak() {
+ List<TTSChunk> chunks = Collections.singletonList(new TTSChunk(WELCOME_SPEAK, SpeechCapabilities.TEXT));
+ sdlManager.sendRPC(new Speak(chunks));
+ }
+
+ /**
+ * Use the Screen Manager to set the initial screen text and set the image.
+ * Because we are setting multiple items, we will call beginTransaction() first,
+ * and finish with commit() when we are done.
+ */
+ private void performWelcomeShow() {
+ sdlManager.getScreenManager().beginTransaction();
+ sdlManager.getScreenManager().setTextField1(APP_NAME);
+ sdlManager.getScreenManager().setTextField2(WELCOME_SHOW);
+ sdlManager.getScreenManager().setPrimaryGraphic(new SdlArtwork(SDL_IMAGE_FILENAME, FileType.GRAPHIC_PNG, R.drawable.sdl, true));
+ sdlManager.getScreenManager().commit(new CompletionListener() {
+ @Override
+ public void onComplete(boolean success) {
+ if (success) {
+ Log.i(TAG, "welcome show successful");
+ }
+ }
+ });
+ }
+
+ /**
+ * Attempts to Subscribe to all preset buttons
+ */
+ private void subscribeToButtons() {
+ ButtonName[] buttonNames = {ButtonName.PLAY_PAUSE, ButtonName.SEEKLEFT, ButtonName.SEEKRIGHT, ButtonName.AC_MAX, ButtonName.AC, ButtonName.RECIRCULATE,
+ ButtonName.FAN_UP, ButtonName.FAN_DOWN, ButtonName.TEMP_UP, ButtonName.TEMP_DOWN, ButtonName.FAN_DOWN, ButtonName.DEFROST_MAX, ButtonName.DEFROST_REAR, ButtonName.DEFROST,
+ ButtonName.UPPER_VENT, ButtonName.LOWER_VENT, ButtonName.VOLUME_UP, ButtonName.VOLUME_DOWN, ButtonName.EJECT, ButtonName.SOURCE, ButtonName.SHUFFLE, ButtonName.REPEAT};
+
+ OnButtonListener onButtonListener = new OnButtonListener() {
+ @Override
+ public void onPress(ButtonName buttonName, OnButtonPress buttonPress) {
+ sdlManager.getScreenManager().setTextField1(buttonName + " pressed");
+ }
+
+ @Override
+ public void onEvent(ButtonName buttonName, OnButtonEvent buttonEvent) {
+ sdlManager.getScreenManager().setTextField2(buttonName + " " + buttonEvent.getButtonEventMode());
+ }
+
+ @Override
+ public void onError(String info) {
+ Log.i(TAG, "onError: " + info);
+ }
+ };
+
+ for (ButtonName buttonName : buttonNames) {
+ sdlManager.getScreenManager().addButtonListener(buttonName, onButtonListener);
+ }
+ }
+
+ /**
+ * Will show a sample test message on screen as well as speak a sample test message
+ */
+ private void showTest() {
+ sdlManager.getScreenManager().beginTransaction();
+ sdlManager.getScreenManager().setTextField1("Test Cell 1 has been selected");
+ sdlManager.getScreenManager().setTextField2("");
+ sdlManager.getScreenManager().commit(null);
+
+ List<TTSChunk> chunks = Collections.singletonList(new TTSChunk(TEST_COMMAND_NAME, SpeechCapabilities.TEXT));
+ sdlManager.sendRPC(new Speak(chunks));
+ }
+
+ private void showAlert(String text) {
+ Alert alert = new Alert();
+ alert.setAlertText1(text);
+ alert.setDuration(5000);
+ sdlManager.sendRPC(alert);
+ }
+
+ // Choice Set
+
+ private void preloadChoices() {
+ ChoiceCell cell1 = new ChoiceCell("Item 1");
+ ChoiceCell cell2 = new ChoiceCell("Item 2");
+ ChoiceCell cell3 = new ChoiceCell("Item 3");
+ choiceCellList = new ArrayList<>(Arrays.asList(cell1, cell2, cell3));
+ sdlManager.getScreenManager().preloadChoices(choiceCellList, null);
+ }
+
+ private void showPerformInteraction() {
+ if (choiceCellList != null) {
+ ChoiceSet choiceSet = new ChoiceSet("Choose an Item from the list", choiceCellList, new ChoiceSetSelectionListener() {
+ @Override
+ public void onChoiceSelected(ChoiceCell choiceCell, TriggerSource triggerSource, int rowIndex) {
+ showAlert(choiceCell.getText() + " was selected");
+ }
+
+ @Override
+ public void onError(String error) {
+ Log.e(TAG, "There was an error showing the perform interaction: " + error);
+ }
+ });
+ sdlManager.getScreenManager().presentChoiceSet(choiceSet, InteractionMode.MANUAL_ONLY);
+ }
+ }
}
diff --git a/android/hello_sdl_android/src/main/res/layout/activity_main.xml b/android/hello_sdl_android/src/main/res/layout/activity_main.xml
index 8da613491..b4ed2fb3d 100755
--- a/android/hello_sdl_android/src/main/res/layout/activity_main.xml
+++ b/android/hello_sdl_android/src/main/res/layout/activity_main.xml
@@ -6,7 +6,7 @@
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
- tools:context="com.sdl.hellosdlandroid.MainActivity" >
+ tools:context="com.sdl.hellosdlandroid.MainActivity">
<TextView
android:layout_width="wrap_content"
diff --git a/android/hello_sdl_android/src/main/res/menu/main.xml b/android/hello_sdl_android/src/main/res/menu/main.xml
index d74718db3..898fd7765 100755
--- a/android/hello_sdl_android/src/main/res/menu/main.xml
+++ b/android/hello_sdl_android/src/main/res/menu/main.xml
@@ -1,12 +1,12 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
- tools:context="com.sdl.hellosdlandroid.MainActivity" >
+ tools:context="com.sdl.hellosdlandroid.MainActivity">
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
- app:showAsAction="never"/>
+ app:showAsAction="never" />
</menu>
diff --git a/android/hello_sdl_android/src/main/res/xml/accessory_filter.xml b/android/hello_sdl_android/src/main/res/xml/accessory_filter.xml
index 4b0ab7c83..6a6e1ea97 100755
--- a/android/hello_sdl_android/src/main/res/xml/accessory_filter.xml
+++ b/android/hello_sdl_android/src/main/res/xml/accessory_filter.xml
@@ -3,5 +3,5 @@
<usb-accessory
manufacturer="SDL"
model="Core"
- version="1.0"/>
+ version="1.0" />
</resource> \ No newline at end of file
diff --git a/javaEE/hello_sdl_java_ee/src/main/java/com/smartdevicelink/Main.java b/javaEE/hello_sdl_java_ee/src/main/java/com/smartdevicelink/Main.java
index 8f685e984..22302d816 100644
--- a/javaEE/hello_sdl_java_ee/src/main/java/com/smartdevicelink/Main.java
+++ b/javaEE/hello_sdl_java_ee/src/main/java/com/smartdevicelink/Main.java
@@ -7,8 +7,8 @@ package com.smartdevicelink;
// @ServerEndpoint("/")
- // @Stateful(name = "SDLSessionEJB")
- public class Main {
+// @Stateful(name = "SDLSessionEJB")
+public class Main {
/* Session session;
static Thread thread = null, mainThread;
@@ -48,4 +48,4 @@ package com.smartdevicelink;
}
};
*/
- }
+}
diff --git a/javaEE/hello_sdl_java_ee/src/main/java/com/smartdevicelink/SdlService.java b/javaEE/hello_sdl_java_ee/src/main/java/com/smartdevicelink/SdlService.java
index 779c357ee..87bbf4c67 100644
--- a/javaEE/hello_sdl_java_ee/src/main/java/com/smartdevicelink/SdlService.java
+++ b/javaEE/hello_sdl_java_ee/src/main/java/com/smartdevicelink/SdlService.java
@@ -48,7 +48,9 @@ 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.*;
+import com.smartdevicelink.proxy.rpc.Alert;
+import com.smartdevicelink.proxy.rpc.OnHMIStatus;
+import com.smartdevicelink.proxy.rpc.Speak;
import com.smartdevicelink.proxy.rpc.enums.*;
import com.smartdevicelink.proxy.rpc.listeners.OnRPCNotificationListener;
import com.smartdevicelink.transport.BaseTransportConfig;
@@ -59,23 +61,22 @@ import java.util.*;
public class SdlService {
- private static final String TAG = "SDL Service";
+ private static final String TAG = "SDL Service";
- private static final String APP_NAME = "Hello Sdl";
- private static final String APP_NAME_ES = "Hola Sdl";
- private static final String APP_NAME_FR = "Bonjour Sdl";
- private static final String APP_ID = "8678309";
+ private static final String APP_NAME = "Hello Sdl";
+ private static final String APP_NAME_ES = "Hola Sdl";
+ private static final String APP_NAME_FR = "Bonjour Sdl";
+ private static final String APP_ID = "8678309";
- private static final String ICON_FILENAME = "hello_sdl_icon.png";
- private static final String SDL_IMAGE_FILENAME = "sdl_full_image.png";
+ private static final String ICON_FILENAME = "hello_sdl_icon.png";
+ private static final String SDL_IMAGE_FILENAME = "sdl_full_image.png";
- private static final String WELCOME_SHOW = "Welcome to HelloSDL";
- private static final String WELCOME_SPEAK = "Welcome to Hello S D L";
+ private static final String WELCOME_SHOW = "Welcome to HelloSDL";
+ private static final String WELCOME_SPEAK = "Welcome to Hello S D L";
- private static final String TEST_COMMAND_NAME = "Test Command";
-
- private static final String IMAGE_DIR = "assets/images/";
+ private static final String TEST_COMMAND_NAME = "Test Command";
+ private static final String IMAGE_DIR = "assets/images/";
// variable to create and call functions of the SyncProxy
@@ -85,14 +86,14 @@ public class SdlService {
private SdlServiceCallback callback;
- public SdlService(BaseTransportConfig config, SdlServiceCallback callback){
+ public SdlService(BaseTransportConfig config, SdlServiceCallback callback) {
this.callback = callback;
buildSdlManager(config);
}
public void start() {
DebugTool.logInfo("SdlService start() ");
- if(sdlManager != null){
+ if (sdlManager != null) {
sdlManager.start();
}
}
@@ -128,7 +129,7 @@ public class SdlService {
public void onDestroy(SdlManager sdlManager) {
DebugTool.logInfo("SdlManager onDestroy ");
SdlService.this.sdlManager = null;
- if(SdlService.this.callback != null){
+ if (SdlService.this.callback != null) {
SdlService.this.callback.onEnd();
}
}
@@ -138,7 +139,7 @@ public class SdlService {
}
@Override
- public LifecycleConfigurationUpdate managerShouldUpdateLifecycle(Language language){
+ public LifecycleConfigurationUpdate managerShouldUpdateLifecycle(Language language) {
String appName;
switch (language) {
case ES_MX:
@@ -151,12 +152,12 @@ public class SdlService {
return null;
}
- return new LifecycleConfigurationUpdate(appName,null,TTSChunkFactory.createSimpleTTSChunks(appName), null);
+ return new LifecycleConfigurationUpdate(appName, null, TTSChunkFactory.createSimpleTTSChunks(appName), null);
}
};
- HashMap<FunctionID,OnRPCNotificationListener> notificationListenerHashMap = new HashMap<FunctionID,OnRPCNotificationListener>();
+ HashMap<FunctionID, OnRPCNotificationListener> notificationListenerHashMap = new HashMap<FunctionID, OnRPCNotificationListener>();
notificationListenerHashMap.put(FunctionID.ON_HMI_STATUS, new OnRPCNotificationListener() {
@Override
public void onNotified(RPCNotification notification) {
@@ -172,7 +173,7 @@ public class SdlService {
});
// 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);
+ SdlArtwork appIcon = new SdlArtwork(ICON_FILENAME, FileType.GRAPHIC_PNG, IMAGE_DIR + "sdl_s_green.png", true);
// The manager builder sets options for your session
SdlManager.Builder builder = new SdlManager.Builder(APP_ID, APP_NAME, listener);
@@ -187,7 +188,7 @@ public class SdlService {
/**
* Send some voice commands
*/
- private void setVoiceCommands(){
+ private void setVoiceCommands() {
List<String> list1 = Collections.singletonList("Command One");
List<String> list2 = Collections.singletonList("Command two");
@@ -206,16 +207,16 @@ public class SdlService {
}
});
- sdlManager.getScreenManager().setVoiceCommands(Arrays.asList(voiceCommand1,voiceCommand2));
+ sdlManager.getScreenManager().setVoiceCommands(Arrays.asList(voiceCommand1, voiceCommand2));
}
/**
- * Add menus for the app on SDL.
+ * Add menus for the app on SDL.
*/
- private void sendMenus(){
+ private void sendMenus() {
// some arts
- SdlArtwork livio = new SdlArtwork(ICON_FILENAME, FileType.GRAPHIC_PNG, IMAGE_DIR+"sdl_s_green.png", true);
+ SdlArtwork livio = new SdlArtwork(ICON_FILENAME, FileType.GRAPHIC_PNG, IMAGE_DIR + "sdl_s_green.png", true);
// some voice commands
List<String> voice2 = Collections.singletonList("Cell two");
@@ -223,7 +224,7 @@ public class SdlService {
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());
+ Log.i(TAG, "Test cell 1 triggered. Source: " + trigger.toString());
showTest();
}
});
@@ -231,28 +232,28 @@ public class SdlService {
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());
+ Log.i(TAG, "Test cell 2 triggered. Source: " + trigger.toString());
}
});
// SUB MENU
- MenuCell subCell1 = new MenuCell("SubCell 1",null, null, new MenuSelectionListener() {
+ 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());
+ Log.i(TAG, "Sub cell 1 triggered. Source: " + trigger.toString());
}
});
- MenuCell subCell2 = new MenuCell("SubCell 2",null, null, new MenuSelectionListener() {
+ MenuCell subCell2 = new MenuCell("SubCell 2", null, null, new MenuSelectionListener() {
@Override
public void onTriggered(TriggerSource trigger) {
- Log.i(TAG, "Sub cell 2 triggered. Source: "+ trigger.toString());
+ Log.i(TAG, "Sub cell 2 triggered. Source: " + trigger.toString());
}
});
// sub menu parent cell
- MenuCell mainCell3 = new MenuCell("Test Cell 3 (sub menu)", null, Arrays.asList(subCell1,subCell2));
+ MenuCell mainCell3 = new MenuCell("Test Cell 3 (sub menu)", null, Arrays.asList(subCell1, subCell2));
MenuCell mainCell4 = new MenuCell("Show Perform Interaction", null, null, new MenuSelectionListener() {
@Override
@@ -261,10 +262,10 @@ public class SdlService {
}
});
- MenuCell mainCell5 = new MenuCell("Clear the menu",null, null, new MenuSelectionListener() {
+ MenuCell mainCell5 = new MenuCell("Clear the menu", null, null, new MenuSelectionListener() {
@Override
public void onTriggered(TriggerSource trigger) {
- Log.i(TAG, "Clearing Menu. Source: "+ trigger.toString());
+ Log.i(TAG, "Clearing Menu. Source: " + trigger.toString());
// Clear this thing
sdlManager.getScreenManager().setMenu(Collections.<MenuCell>emptyList());
showAlert("Menu Cleared");
@@ -278,7 +279,7 @@ public class SdlService {
/**
* Will speak a sample welcome message
*/
- private void performWelcomeSpeak(){
+ private void performWelcomeSpeak() {
sdlManager.sendRPC(new Speak(TTSChunkFactory.createSimpleTTSChunks(WELCOME_SPEAK)));
}
@@ -291,11 +292,11 @@ public class SdlService {
sdlManager.getScreenManager().beginTransaction();
sdlManager.getScreenManager().setTextField1(APP_NAME);
sdlManager.getScreenManager().setTextField2(WELCOME_SHOW);
- sdlManager.getScreenManager().setPrimaryGraphic(new SdlArtwork(SDL_IMAGE_FILENAME, FileType.GRAPHIC_PNG, IMAGE_DIR+"sdl.png", true));
+ sdlManager.getScreenManager().setPrimaryGraphic(new SdlArtwork(SDL_IMAGE_FILENAME, FileType.GRAPHIC_PNG, IMAGE_DIR + "sdl.png", true));
sdlManager.getScreenManager().commit(new CompletionListener() {
@Override
public void onComplete(boolean success) {
- if (success){
+ if (success) {
Log.i(TAG, "welcome show successful");
}
}
@@ -305,7 +306,7 @@ public class SdlService {
/**
* Will show a sample test message on screen as well as speak a sample test message
*/
- private void showTest(){
+ private void showTest() {
sdlManager.getScreenManager().beginTransaction();
sdlManager.getScreenManager().setTextField1("Test Cell 1 has been selected");
sdlManager.getScreenManager().setTextField2("");
@@ -314,28 +315,28 @@ public class SdlService {
sdlManager.sendRPC(new Speak(TTSChunkFactory.createSimpleTTSChunks(TEST_COMMAND_NAME)));
}
- private void showAlert(String text){
+ private void showAlert(String text) {
Alert alert = new Alert();
alert.setAlertText1(text);
alert.setDuration(5000);
sdlManager.sendRPC(alert);
}
- public interface SdlServiceCallback{
+ public interface SdlServiceCallback {
void onEnd();
}
// Choice Set
- private void preloadChoices(){
+ private void preloadChoices() {
ChoiceCell cell1 = new ChoiceCell("Item 1");
ChoiceCell cell2 = new ChoiceCell("Item 2");
ChoiceCell cell3 = new ChoiceCell("Item 3");
- choiceCellList = new ArrayList<>(Arrays.asList(cell1,cell2,cell3));
+ choiceCellList = new ArrayList<>(Arrays.asList(cell1, cell2, cell3));
sdlManager.getScreenManager().preloadChoices(choiceCellList, null);
}
- private void showPerformInteraction(){
+ private void showPerformInteraction() {
if (choiceCellList != null) {
ChoiceSet choiceSet = new ChoiceSet("Choose an Item from the list", choiceCellList, new ChoiceSetSelectionListener() {
@Override
@@ -345,7 +346,7 @@ public class SdlService {
@Override
public void onError(String error) {
- Log.e(TAG, "There was an error showing the perform interaction: "+ error);
+ Log.e(TAG, "There was an error showing the perform interaction: " + error);
}
});
sdlManager.getScreenManager().presentChoiceSet(choiceSet, InteractionMode.MANUAL_ONLY);
diff --git a/javaSE/hello_sdl_java/src/main/java/com/smartdevicelink/java/Main.java b/javaSE/hello_sdl_java/src/main/java/com/smartdevicelink/java/Main.java
index 0f67efe0b..4e622195f 100644
--- a/javaSE/hello_sdl_java/src/main/java/com/smartdevicelink/java/Main.java
+++ b/javaSE/hello_sdl_java/src/main/java/com/smartdevicelink/java/Main.java
@@ -50,14 +50,14 @@ public class Main {
mainThread = Thread.currentThread();
startSdlService();
- while(!mainThread.isInterrupted()) {
+ while (!mainThread.isInterrupted()) {
try {
synchronized (LOCK) {
LOCK.wait();
}
System.gc();
Thread.sleep(500);
- DebugTool.logInfo(TAG, "Attempting to start SDL Service again");
+ DebugTool.logInfo(TAG, "Attempting to start SDL Service again");
startSdlService();
DebugTool.logInfo(TAG, "SdlService started");
@@ -89,7 +89,7 @@ public class Main {
@Override
public void run() {
DebugTool.logInfo(TAG, "Starting SDL Service");
- sdlService = new SdlService(new WebSocketServerConfig(5432, -1), serviceCallback);
+ sdlService = new SdlService(new WebSocketServerConfig(5432, -1), serviceCallback);
sdlService.start();
System.gc();
diff --git a/javaSE/hello_sdl_java/src/main/java/com/smartdevicelink/java/SdlService.java b/javaSE/hello_sdl_java/src/main/java/com/smartdevicelink/java/SdlService.java
index a9d81b766..176d6010e 100644
--- a/javaSE/hello_sdl_java/src/main/java/com/smartdevicelink/java/SdlService.java
+++ b/javaSE/hello_sdl_java/src/main/java/com/smartdevicelink/java/SdlService.java
@@ -58,22 +58,22 @@ import java.util.*;
public class SdlService {
- private static final String TAG = "SDL Service";
+ private static final String TAG = "SDL Service";
- private static final String APP_NAME = "Hello Sdl";
- private static final String APP_NAME_ES = "Hola Sdl";
- private static final String APP_NAME_FR = "Bonjour Sdl";
- private static final String APP_ID = "8678309";
+ private static final String APP_NAME = "Hello Sdl";
+ private static final String APP_NAME_ES = "Hola Sdl";
+ private static final String APP_NAME_FR = "Bonjour Sdl";
+ private static final String APP_ID = "8678309";
- private static final String ICON_FILENAME = "hello_sdl_icon.png";
- private static final String SDL_IMAGE_FILENAME = "sdl_full_image.png";
+ private static final String ICON_FILENAME = "hello_sdl_icon.png";
+ private static final String SDL_IMAGE_FILENAME = "sdl_full_image.png";
- private static final String WELCOME_SHOW = "Welcome to HelloSDL";
- private static final String WELCOME_SPEAK = "Welcome to Hello S D L";
+ private static final String WELCOME_SHOW = "Welcome to HelloSDL";
+ private static final String WELCOME_SPEAK = "Welcome to Hello S D L";
- private static final String TEST_COMMAND_NAME = "Test Command";
+ private static final String TEST_COMMAND_NAME = "Test Command";
- private static final String IMAGE_DIR = "hello_sdl_java/assets/images/";
+ private static final String IMAGE_DIR = "hello_sdl_java/assets/images/";
// variable to create and call functions of the SyncProxy
private SdlManager sdlManager = null;
@@ -81,14 +81,14 @@ public class SdlService {
private final SdlServiceCallback callback;
- public SdlService(BaseTransportConfig config, SdlServiceCallback callback){
+ public SdlService(BaseTransportConfig config, SdlServiceCallback callback) {
this.callback = callback;
buildSdlManager(config);
}
public void start() {
DebugTool.logInfo(TAG, "SdlService start() ");
- if(sdlManager != null){
+ if (sdlManager != null) {
sdlManager.start();
}
}
@@ -124,7 +124,7 @@ public class SdlService {
public void onDestroy(SdlManager sdlManager) {
DebugTool.logInfo(TAG, "SdlManager onDestroy ");
SdlService.this.sdlManager = null;
- if(SdlService.this.callback != null){
+ if (SdlService.this.callback != null) {
SdlService.this.callback.onEnd();
stop();
}
@@ -173,7 +173,7 @@ public class SdlService {
};
- HashMap<FunctionID,OnRPCNotificationListener> notificationListenerHashMap = new HashMap<>();
+ HashMap<FunctionID, OnRPCNotificationListener> notificationListenerHashMap = new HashMap<>();
notificationListenerHashMap.put(FunctionID.ON_HMI_STATUS, new OnRPCNotificationListener() {
@Override
public void onNotified(RPCNotification notification) {
@@ -190,7 +190,7 @@ public class SdlService {
});
// 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);
+ SdlArtwork appIcon = new SdlArtwork(ICON_FILENAME, FileType.GRAPHIC_PNG, IMAGE_DIR + "sdl_s_green.png", true);
// The manager builder sets options for your session
SdlManager.Builder builder = new SdlManager.Builder(APP_ID, APP_NAME, listener);
@@ -205,7 +205,7 @@ public class SdlService {
/**
* Send some voice commands
*/
- private void setVoiceCommands(){
+ private void setVoiceCommands() {
List<String> list1 = Collections.singletonList("Command One");
List<String> list2 = Collections.singletonList("Command two");
@@ -224,16 +224,16 @@ public class SdlService {
}
});
- sdlManager.getScreenManager().setVoiceCommands(Arrays.asList(voiceCommand1,voiceCommand2));
+ sdlManager.getScreenManager().setVoiceCommands(Arrays.asList(voiceCommand1, voiceCommand2));
}
/**
- * Add menus for the app on SDL.
+ * Add menus for the app on SDL.
*/
- private void sendMenus(){
+ private void sendMenus() {
// some arts
- SdlArtwork livio = new SdlArtwork(ICON_FILENAME, FileType.GRAPHIC_PNG, IMAGE_DIR+"sdl_s_green.png", true);
+ SdlArtwork livio = new SdlArtwork(ICON_FILENAME, FileType.GRAPHIC_PNG, IMAGE_DIR + "sdl_s_green.png", true);
// some voice commands
List<String> voice2 = Collections.singletonList("Cell two");
@@ -241,7 +241,7 @@ public class SdlService {
MenuCell mainCell1 = new MenuCell("Test Cell 1 (speak)", livio, null, new MenuSelectionListener() {
@Override
public void onTriggered(TriggerSource trigger) {
- DebugTool.logInfo(TAG, "Test cell 1 triggered. Source: "+ trigger.toString());
+ DebugTool.logInfo(TAG, "Test cell 1 triggered. Source: " + trigger.toString());
showTest();
}
});
@@ -249,28 +249,28 @@ public class SdlService {
MenuCell mainCell2 = new MenuCell("Test Cell 2", null, voice2, new MenuSelectionListener() {
@Override
public void onTriggered(TriggerSource trigger) {
- DebugTool.logInfo(TAG, "Test cell 2 triggered. Source: "+ trigger.toString());
+ DebugTool.logInfo(TAG, "Test cell 2 triggered. Source: " + trigger.toString());
}
});
// SUB MENU
- MenuCell subCell1 = new MenuCell("SubCell 1",null, null, new MenuSelectionListener() {
+ MenuCell subCell1 = new MenuCell("SubCell 1", null, null, new MenuSelectionListener() {
@Override
public void onTriggered(TriggerSource trigger) {
- DebugTool.logInfo(TAG, "Sub cell 1 triggered. Source: "+ trigger.toString());
+ DebugTool.logInfo(TAG, "Sub cell 1 triggered. Source: " + trigger.toString());
}
});
- MenuCell subCell2 = new MenuCell("SubCell 2",null, null, new MenuSelectionListener() {
+ MenuCell subCell2 = new MenuCell("SubCell 2", null, null, new MenuSelectionListener() {
@Override
public void onTriggered(TriggerSource trigger) {
- DebugTool.logInfo(TAG, "Sub cell 2 triggered. Source: "+ trigger.toString());
+ DebugTool.logInfo(TAG, "Sub cell 2 triggered. Source: " + trigger.toString());
}
});
// sub menu parent cell
- MenuCell mainCell3 = new MenuCell("Test Cell 3 (sub menu)", MenuLayout.LIST, null, Arrays.asList(subCell1,subCell2));
+ MenuCell mainCell3 = new MenuCell("Test Cell 3 (sub menu)", MenuLayout.LIST, null, Arrays.asList(subCell1, subCell2));
MenuCell mainCell4 = new MenuCell("Show Perform Interaction", null, null, new MenuSelectionListener() {
@Override
@@ -279,10 +279,10 @@ public class SdlService {
}
});
- MenuCell mainCell5 = new MenuCell("Clear the menu",null, null, new MenuSelectionListener() {
+ MenuCell mainCell5 = new MenuCell("Clear the menu", null, null, new MenuSelectionListener() {
@Override
public void onTriggered(TriggerSource trigger) {
- DebugTool.logInfo(TAG, "Clearing Menu. Source: "+ trigger.toString());
+ DebugTool.logInfo(TAG, "Clearing Menu. Source: " + trigger.toString());
// Clear this thing
sdlManager.getScreenManager().setMenu(Collections.<MenuCell>emptyList());
showAlert("Menu Cleared");
@@ -296,7 +296,7 @@ public class SdlService {
/**
* Will speak a sample welcome message
*/
- private void performWelcomeSpeak(){
+ private void performWelcomeSpeak() {
List<TTSChunk> chunks = Collections.singletonList(new TTSChunk(WELCOME_SPEAK, SpeechCapabilities.TEXT));
sdlManager.sendRPC(new Speak(chunks));
}
@@ -310,11 +310,11 @@ public class SdlService {
sdlManager.getScreenManager().beginTransaction();
sdlManager.getScreenManager().setTextField1(APP_NAME);
sdlManager.getScreenManager().setTextField2(WELCOME_SHOW);
- sdlManager.getScreenManager().setPrimaryGraphic(new SdlArtwork(SDL_IMAGE_FILENAME, FileType.GRAPHIC_PNG, IMAGE_DIR+"sdl.png", true));
+ sdlManager.getScreenManager().setPrimaryGraphic(new SdlArtwork(SDL_IMAGE_FILENAME, FileType.GRAPHIC_PNG, IMAGE_DIR + "sdl.png", true));
sdlManager.getScreenManager().commit(new CompletionListener() {
@Override
public void onComplete(boolean success) {
- if (success){
+ if (success) {
DebugTool.logInfo(TAG, "welcome show successful");
}
}
@@ -329,10 +329,10 @@ public class SdlService {
ButtonName.FAN_UP, ButtonName.FAN_DOWN, ButtonName.TEMP_UP, ButtonName.TEMP_DOWN, ButtonName.FAN_DOWN, ButtonName.DEFROST_MAX, ButtonName.DEFROST_REAR, ButtonName.DEFROST,
ButtonName.UPPER_VENT, ButtonName.LOWER_VENT, ButtonName.VOLUME_UP, ButtonName.VOLUME_DOWN, ButtonName.EJECT, ButtonName.SOURCE, ButtonName.SHUFFLE, ButtonName.REPEAT};
- OnButtonListener onButtonListener = new OnButtonListener() {
+ OnButtonListener onButtonListener = new OnButtonListener() {
@Override
public void onPress(ButtonName buttonName, OnButtonPress buttonPress) {
- sdlManager.getScreenManager().setTextField1(buttonName + " pressed");
+ sdlManager.getScreenManager().setTextField1(buttonName + " pressed");
DebugTool.logInfo(TAG, "onPress: " + buttonName);
}
@@ -355,7 +355,7 @@ public class SdlService {
/**
* Will show a sample test message on screen as well as speak a sample test message
*/
- private void showTest(){
+ private void showTest() {
sdlManager.getScreenManager().beginTransaction();
sdlManager.getScreenManager().setTextField1("Test Cell 1 has been selected");
sdlManager.getScreenManager().setTextField2("");
@@ -365,28 +365,28 @@ public class SdlService {
sdlManager.sendRPC(new Speak(chunks));
}
- private void showAlert(String text){
+ private void showAlert(String text) {
Alert alert = new Alert();
alert.setAlertText1(text);
alert.setDuration(5000);
sdlManager.sendRPC(alert);
}
- public interface SdlServiceCallback{
+ public interface SdlServiceCallback {
void onEnd();
}
// Choice Set
- private void preloadChoices(){
+ private void preloadChoices() {
ChoiceCell cell1 = new ChoiceCell("Item 1");
ChoiceCell cell2 = new ChoiceCell("Item 2");
ChoiceCell cell3 = new ChoiceCell("Item 3");
- choiceCellList = new ArrayList<>(Arrays.asList(cell1,cell2,cell3));
+ choiceCellList = new ArrayList<>(Arrays.asList(cell1, cell2, cell3));
sdlManager.getScreenManager().preloadChoices(choiceCellList, null);
}
- private void showPerformInteraction(){
+ private void showPerformInteraction() {
if (choiceCellList != null) {
ChoiceSet choiceSet = new ChoiceSet("Choose an Item from the list", choiceCellList, new ChoiceSetSelectionListener() {
@Override
@@ -396,7 +396,7 @@ public class SdlService {
@Override
public void onError(String error) {
- DebugTool.logError(TAG, "There was an error showing the perform interaction: "+ error);
+ DebugTool.logError(TAG, "There was an error showing the perform interaction: " + error);
}
});
sdlManager.getScreenManager().presentChoiceSet(choiceSet, InteractionMode.MANUAL_ONLY);