summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Kast <Julian.kast@livio.io>2020-09-17 13:40:18 -0400
committerGitHub <noreply@github.com>2020-09-17 13:40:18 -0400
commit6e93579d490d60deb382e96ee4bc8d7581989929 (patch)
tree4ebfa7351832f0f6ff7525c077c0a116fdfcd260
parentb5746a4621852c330d45e7b8fdace833c8b95d94 (diff)
downloadsdl_android-6e93579d490d60deb382e96ee4bc8d7581989929.tar.gz
[SDL 0278] Screen Manager Template Management (#1492)
* Work in Progress * BaseTextAndGraphicsManager changes * TextAndGraphicsUpdateOperation updates for template management * TextAndGraphicsState updates for template managment * remove comment and fix existing unit test * Added getTemplateConfiguration method and made currentState method package private * Add test to TextAndGraphicManagerTest * Fix unit test and remove commented out code * Fix test to expand code cov * Remove added constructors and use chainable setters * Fix error in shouldUpdateTemplateConfig method * Added unit test to test template change * Added unit test * Added check to cancel the operation if text / layout changes and images still need to be uploaded * Add unit test for if a show fails * Added comments and simplified logic * Fix comparing TemplateConfigurations * Add comments and fix formatting * Add java Docs to baseScreenManager * Change name of var and fix formatiing * Added final to vars that go reverted when fixing merge conflicts * Add @nonNull to templateConfiguration * Removing sending newScreenData to updatePendingOperationsWithNewScreenData as it is equal to currentScreenData at this point * Make setLayout var local * Fixing error where setDisplayLayout dosn't call listener if it fails * Added showRPCSupportsTemplateConfiguration() Method to T&G update operation * Added check to make sure we don't get an npe if internalInterface is null * added check to make sure we don't send an unnecessary templateConfig with show * Fixed issue with setDisplayLayout request updating capabilities when request fails * Documentation updates to screenManager * Formatting fix * Fix javaDocs and comments * Fixed issue with updateCurrentScreenDataFromShow * Change TextsAndGraphicsState to TextAndGraphicState to align with IOS Co-authored-by: Julian Kast <julian@livio.com>
-rw-r--r--android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/TextAndGraphicManagerTests.java110
-rw-r--r--android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/TextAndGraphicUpdateOperationTest.java197
-rw-r--r--base/src/main/java/com/smartdevicelink/managers/lifecycle/BaseSystemCapabilityManager.java4
-rw-r--r--base/src/main/java/com/smartdevicelink/managers/screen/BaseScreenManager.java75
-rw-r--r--base/src/main/java/com/smartdevicelink/managers/screen/BaseTextAndGraphicManager.java126
-rw-r--r--base/src/main/java/com/smartdevicelink/managers/screen/TextAndGraphicUpdateOperation.java193
-rw-r--r--base/src/main/java/com/smartdevicelink/managers/screen/TextsAndGraphicsState.java40
7 files changed, 605 insertions, 140 deletions
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/TextAndGraphicManagerTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/TextAndGraphicManagerTests.java
index e65911ccb..58e5b8fda 100644
--- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/TextAndGraphicManagerTests.java
+++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/TextAndGraphicManagerTests.java
@@ -17,10 +17,13 @@ import com.smartdevicelink.protocol.enums.FunctionID;
import com.smartdevicelink.managers.ISdl;
import com.smartdevicelink.proxy.rpc.DisplayCapability;
import com.smartdevicelink.proxy.rpc.OnHMIStatus;
+import com.smartdevicelink.proxy.rpc.TemplateConfiguration;
import com.smartdevicelink.proxy.rpc.TextField;
import com.smartdevicelink.proxy.rpc.WindowCapability;
import com.smartdevicelink.proxy.rpc.enums.FileType;
import com.smartdevicelink.proxy.rpc.enums.HMILevel;
+import com.smartdevicelink.proxy.rpc.enums.MetadataType;
+import com.smartdevicelink.proxy.rpc.enums.PredefinedLayout;
import com.smartdevicelink.proxy.rpc.enums.SystemCapabilityType;
import com.smartdevicelink.proxy.rpc.enums.TextAlignment;
import com.smartdevicelink.proxy.rpc.enums.TextFieldName;
@@ -58,7 +61,8 @@ public class TextAndGraphicManagerTests {
// SETUP / HELPERS
private TextAndGraphicManager textAndGraphicManager;
- private SdlArtwork testArtwork;
+ private SdlArtwork testArtwork1, testArtwork2;
+ private TemplateConfiguration configuration1, configuration2;
@Before
public void setUp() throws Exception{
@@ -69,11 +73,20 @@ public class TextAndGraphicManagerTests {
FileManager fileManager = mock(FileManager.class);
SoftButtonManager softButtonManager = mock(SoftButtonManager.class);
- testArtwork = new SdlArtwork();
- testArtwork.setName("testFile");
+ testArtwork1 = new SdlArtwork();
+ testArtwork1.setName("testFile");
Uri uri = Uri.parse("android.resource://" + mTestContext.getPackageName() + "/drawable/ic_sdl");
- testArtwork.setUri(uri);
- testArtwork.setType(FileType.GRAPHIC_PNG);
+ testArtwork1.setUri(uri);
+ testArtwork1.setType(FileType.GRAPHIC_PNG);
+
+ testArtwork2 = new SdlArtwork();
+ testArtwork2.setName("testFile2");
+ Uri uri2 = Uri.parse("android.resource://" + mTestContext.getPackageName() + "/drawable/ic_sdl");
+ testArtwork2.setUri(uri2);
+ testArtwork2.setType(FileType.GRAPHIC_PNG);
+
+ configuration1 = new TemplateConfiguration(PredefinedLayout.GRAPHIC_WITH_TEXT.toString());
+ configuration2 = new TemplateConfiguration(PredefinedLayout.DOUBLE_GRAPHIC_WITH_SOFTBUTTONS.toString());
Taskmaster taskmaster = new Taskmaster.Builder().build();
taskmaster.start();
@@ -157,7 +170,6 @@ public class TextAndGraphicManagerTests {
@Test
public void testInstantiation(){
-
assertNull(textAndGraphicManager.getTextField1());
assertNull(textAndGraphicManager.getTextField2());
assertNull(textAndGraphicManager.getTextField3());
@@ -224,14 +236,14 @@ public class TextAndGraphicManagerTests {
@Test
public void testSetPrimaryGraphic() {
- textAndGraphicManager.setPrimaryGraphic(testArtwork);
- assertEquals(textAndGraphicManager.getPrimaryGraphic(), testArtwork);
+ textAndGraphicManager.setPrimaryGraphic(testArtwork1);
+ assertEquals(textAndGraphicManager.getPrimaryGraphic(), testArtwork1);
}
@Test
public void testSetSecondaryGraphic() {
- textAndGraphicManager.setSecondaryGraphic(testArtwork);
- assertEquals(textAndGraphicManager.getSecondaryGraphic(), testArtwork);
+ textAndGraphicManager.setSecondaryGraphic(testArtwork1);
+ assertEquals(textAndGraphicManager.getSecondaryGraphic(), testArtwork1);
}
// TEST DISPOSE
@@ -288,7 +300,83 @@ public class TextAndGraphicManagerTests {
assertTrue(textAndGraphicManager.hasData());
textAndGraphicManager.setTextField1(null);
- textAndGraphicManager.setPrimaryGraphic(testArtwork);
+ textAndGraphicManager.setPrimaryGraphic(testArtwork1);
assertTrue(textAndGraphicManager.hasData());
}
+
+ @Test
+ public void resetFieldsToCurrentScreenDataTest() {
+ textAndGraphicManager.setTextField1("textField1");
+ textAndGraphicManager.setTextField2("textField2");
+ textAndGraphicManager.setTextField3("textField3");
+ textAndGraphicManager.setTextField4("textField4");
+ textAndGraphicManager.setTextField1Type(MetadataType.MEDIA_TITLE);
+ textAndGraphicManager.setTextField2Type(MetadataType.MEDIA_TITLE);
+ textAndGraphicManager.setTextField3Type(MetadataType.MEDIA_TITLE);
+ textAndGraphicManager.setTextField4Type(MetadataType.MEDIA_TITLE);
+ textAndGraphicManager.setMediaTrackTextField("mediaTrackTextField");
+ textAndGraphicManager.setTitle("title");
+ textAndGraphicManager.setPrimaryGraphic(testArtwork1);
+ textAndGraphicManager.setSecondaryGraphic(testArtwork2);
+ textAndGraphicManager.changeLayout(configuration1, null);
+ textAndGraphicManager.currentScreenData = textAndGraphicManager.currentState();
+
+ assertTrue(textAndGraphicManager.currentScreenData.getTextField1().equals(textAndGraphicManager.getTextField1()));
+ assertTrue(textAndGraphicManager.currentScreenData.getTextField2().equals(textAndGraphicManager.getTextField2()));
+ assertTrue(textAndGraphicManager.currentScreenData.getTextField3().equals(textAndGraphicManager.getTextField3()));
+ assertTrue(textAndGraphicManager.currentScreenData.getTextField4().equals(textAndGraphicManager.getTextField4()));
+ assertTrue(textAndGraphicManager.currentScreenData.getTitle().equals(textAndGraphicManager.getTitle()));
+ assertTrue(textAndGraphicManager.currentScreenData.getMediaTrackTextField().equals(textAndGraphicManager.getMediaTrackTextField()));
+ assertTrue(textAndGraphicManager.currentScreenData.getTextField1Type().toString().equals(textAndGraphicManager.getTextField1Type().toString()));
+ assertTrue(textAndGraphicManager.currentScreenData.getTextField2Type().toString().equals(textAndGraphicManager.getTextField2Type().toString()));
+ assertTrue(textAndGraphicManager.currentScreenData.getTextField3Type().toString().equals(textAndGraphicManager.getTextField3Type().toString()));
+ assertTrue(textAndGraphicManager.currentScreenData.getTextField4Type().toString().equals(textAndGraphicManager.getTextField4Type().toString()));
+ assertTrue(textAndGraphicManager.currentScreenData.getPrimaryGraphic().getName().equals(textAndGraphicManager.getPrimaryGraphic().getName()));
+ assertTrue(textAndGraphicManager.currentScreenData.getSecondaryGraphic().getName().equals(textAndGraphicManager.getSecondaryGraphic().getName()));
+ assertTrue(textAndGraphicManager.currentScreenData.getTemplateConfiguration().getStore().equals(textAndGraphicManager.getTemplateConfiguration().getStore()));
+
+ textAndGraphicManager.setTextField1("BadData");
+ textAndGraphicManager.setTextField2("BadData");
+ textAndGraphicManager.setTextField3("BadData");
+ textAndGraphicManager.setTextField4("BadData");
+ textAndGraphicManager.setTextField1Type(MetadataType.HUMIDITY);
+ textAndGraphicManager.setTextField2Type(MetadataType.HUMIDITY);
+ textAndGraphicManager.setTextField3Type(MetadataType.HUMIDITY);
+ textAndGraphicManager.setTextField4Type(MetadataType.HUMIDITY);
+ textAndGraphicManager.setMediaTrackTextField("BadData");
+ textAndGraphicManager.setTitle("BadData");
+ textAndGraphicManager.setPrimaryGraphic(testArtwork2);
+ textAndGraphicManager.setSecondaryGraphic(testArtwork1);
+ textAndGraphicManager.changeLayout(configuration2, null);
+
+ assertFalse(textAndGraphicManager.currentScreenData.getTextField1().equals(textAndGraphicManager.getTextField1()));
+ assertFalse(textAndGraphicManager.currentScreenData.getTextField2().equals(textAndGraphicManager.getTextField2()));
+ assertFalse(textAndGraphicManager.currentScreenData.getTextField3().equals(textAndGraphicManager.getTextField3()));
+ assertFalse(textAndGraphicManager.currentScreenData.getTextField4().equals(textAndGraphicManager.getTextField4()));
+ assertFalse(textAndGraphicManager.currentScreenData.getTitle().equals(textAndGraphicManager.getTitle()));
+ assertFalse(textAndGraphicManager.currentScreenData.getMediaTrackTextField().equals(textAndGraphicManager.getMediaTrackTextField()));
+ assertFalse(textAndGraphicManager.currentScreenData.getTextField1Type().toString().equals(textAndGraphicManager.getTextField1Type().toString()));
+ assertFalse(textAndGraphicManager.currentScreenData.getTextField2Type().toString().equals(textAndGraphicManager.getTextField2Type().toString()));
+ assertFalse(textAndGraphicManager.currentScreenData.getTextField3Type().toString().equals(textAndGraphicManager.getTextField3Type().toString()));
+ assertFalse(textAndGraphicManager.currentScreenData.getTextField4Type().toString().equals(textAndGraphicManager.getTextField4Type().toString()));
+ assertFalse(textAndGraphicManager.currentScreenData.getPrimaryGraphic().getName().equals(textAndGraphicManager.getPrimaryGraphic().getName()));
+ assertFalse(textAndGraphicManager.currentScreenData.getSecondaryGraphic().getName().equals(textAndGraphicManager.getSecondaryGraphic().getName()));
+ assertFalse(textAndGraphicManager.currentScreenData.getTemplateConfiguration().getStore().equals(textAndGraphicManager.getTemplateConfiguration().getStore()));
+
+ textAndGraphicManager.resetFieldsToCurrentScreenData();
+
+ assertTrue(textAndGraphicManager.currentScreenData.getTextField1().equals(textAndGraphicManager.getTextField1()));
+ assertTrue(textAndGraphicManager.currentScreenData.getTextField2().equals(textAndGraphicManager.getTextField2()));
+ assertTrue(textAndGraphicManager.currentScreenData.getTextField3().equals(textAndGraphicManager.getTextField3()));
+ assertTrue(textAndGraphicManager.currentScreenData.getTextField4().equals(textAndGraphicManager.getTextField4()));
+ assertTrue(textAndGraphicManager.currentScreenData.getTitle().equals(textAndGraphicManager.getTitle()));
+ assertTrue(textAndGraphicManager.currentScreenData.getMediaTrackTextField().equals(textAndGraphicManager.getMediaTrackTextField()));
+ assertTrue(textAndGraphicManager.currentScreenData.getTextField1Type().toString().equals(textAndGraphicManager.getTextField1Type().toString()));
+ assertTrue(textAndGraphicManager.currentScreenData.getTextField2Type().toString().equals(textAndGraphicManager.getTextField2Type().toString()));
+ assertTrue(textAndGraphicManager.currentScreenData.getTextField3Type().toString().equals(textAndGraphicManager.getTextField3Type().toString()));
+ assertTrue(textAndGraphicManager.currentScreenData.getTextField4Type().toString().equals(textAndGraphicManager.getTextField4Type().toString()));
+ assertTrue(textAndGraphicManager.currentScreenData.getPrimaryGraphic().getName().equals(textAndGraphicManager.getPrimaryGraphic().getName()));
+ assertTrue(textAndGraphicManager.currentScreenData.getSecondaryGraphic().getName().equals(textAndGraphicManager.getSecondaryGraphic().getName()));
+ assertTrue(textAndGraphicManager.currentScreenData.getTemplateConfiguration().getStore().equals(textAndGraphicManager.getTemplateConfiguration().getStore()));
+ }
}
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/TextAndGraphicUpdateOperationTest.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/TextAndGraphicUpdateOperationTest.java
index 94f75d764..e00ce9b02 100644
--- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/TextAndGraphicUpdateOperationTest.java
+++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/TextAndGraphicUpdateOperationTest.java
@@ -17,13 +17,17 @@ import com.smartdevicelink.managers.ISdl;
import com.smartdevicelink.proxy.rpc.ImageField;
import com.smartdevicelink.proxy.rpc.MetadataTags;
import com.smartdevicelink.proxy.rpc.SdlMsgVersion;
+import com.smartdevicelink.proxy.rpc.SetDisplayLayout;
+import com.smartdevicelink.proxy.rpc.SetDisplayLayoutResponse;
import com.smartdevicelink.proxy.rpc.Show;
import com.smartdevicelink.proxy.rpc.ShowResponse;
+import com.smartdevicelink.proxy.rpc.TemplateConfiguration;
import com.smartdevicelink.proxy.rpc.TextField;
import com.smartdevicelink.proxy.rpc.WindowCapability;
import com.smartdevicelink.proxy.rpc.enums.FileType;
import com.smartdevicelink.proxy.rpc.enums.ImageFieldName;
import com.smartdevicelink.proxy.rpc.enums.MetadataType;
+import com.smartdevicelink.proxy.rpc.enums.PredefinedLayout;
import com.smartdevicelink.proxy.rpc.enums.TextAlignment;
import com.smartdevicelink.proxy.rpc.enums.TextFieldName;
@@ -57,10 +61,11 @@ public class TextAndGraphicUpdateOperationTest {
private SdlArtwork testArtwork1, testArtwork2, testArtwork3, testArtwork4;
private TextAlignment textAlignment;
private WindowCapability defaultMainWindowCapability;
- private Show currentScreenData;
+ private TextAndGraphicState currentScreenData;
private CompletionListener listener;
private TextAndGraphicManager.CurrentScreenDataUpdatedListener currentScreenDataUpdatedListener;
private SdlArtwork blankArtwork;
+ private TemplateConfiguration configuration;
ISdl internalInterface;
FileManager fileManager;
@@ -79,6 +84,52 @@ public class TextAndGraphicUpdateOperationTest {
}
};
+ private Answer<Void> onShowFail = new Answer<Void>() {
+ @Override
+ public Void answer(InvocationOnMock invocation) {
+ Object[] args = invocation.getArguments();
+ RPCRequest message = (RPCRequest) args[0];
+ if (message instanceof Show) {
+ int correlationId = message.getCorrelationID();
+ ShowResponse showResponse = new ShowResponse();
+ showResponse.setSuccess(false);
+ message.getOnRPCResponseListener().onResponse(correlationId, showResponse);
+ }
+ return null;
+ }
+ };
+
+ private Answer<Void> onSetDisplayLayoutSuccess = new Answer<Void>() {
+ @Override
+ public Void answer(InvocationOnMock invocation) {
+ Object[] args = invocation.getArguments();
+ RPCRequest message = (RPCRequest) args[0];
+ if (message instanceof SetDisplayLayout) {
+ int correlationId = message.getCorrelationID();
+ SetDisplayLayoutResponse setDisplayLayoutResponse = new SetDisplayLayoutResponse();
+ setDisplayLayoutResponse.setSuccess(true);
+ message.getOnRPCResponseListener().onResponse(correlationId, setDisplayLayoutResponse);
+ }
+ return null;
+ }
+ };
+
+ private Answer<Void> onSetDisplayLayoutCanceled = new Answer<Void>() {
+ @Override
+ public Void answer(InvocationOnMock invocation) {
+ Object[] args = invocation.getArguments();
+ RPCRequest message = (RPCRequest) args[0];
+ if (message instanceof SetDisplayLayout) {
+ int correlationId = message.getCorrelationID();
+ textAndGraphicUpdateOperation.cancelTask();
+ SetDisplayLayoutResponse setDisplayLayoutResponse = new SetDisplayLayoutResponse();
+ setDisplayLayoutResponse.setSuccess(true);
+ message.getOnRPCResponseListener().onResponse(correlationId, setDisplayLayoutResponse);
+ }
+ return null;
+ }
+ };
+
private Answer<Void> onShowSuccessCanceled = new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) {
@@ -170,26 +221,35 @@ public class TextAndGraphicUpdateOperationTest {
testArtwork4.setUri(uri4);
testArtwork4.setType(FileType.GRAPHIC_PNG);
- currentScreenData = new Show();
- currentScreenData.setMainField1("Old");
- currentScreenData.setMainField2("Text");
- currentScreenData.setMainField3("Not");
- currentScreenData.setMainField4("Important");
+ configuration = new TemplateConfiguration();
+ configuration.setTemplate(PredefinedLayout.GRAPHIC_WITH_TEXT.toString());
+
+ currentScreenData = new TextAndGraphicState();
+ currentScreenData.setTextField1("Old");
+ currentScreenData.setTextField2("Text");
+ currentScreenData.setTextField3("Not");
+ currentScreenData.setTextField4("Important");
- currentScreenData.setGraphic(testArtwork1.getImageRPC());
- currentScreenData.setSecondaryGraphic(testArtwork2.getImageRPC());
+ currentScreenData.setPrimaryGraphic(testArtwork1);
+ currentScreenData.setSecondaryGraphic(testArtwork2);
+ currentScreenData.setTemplateConfiguration(configuration);
currentScreenDataUpdatedListener = new TextAndGraphicManager.CurrentScreenDataUpdatedListener() {
@Override
- public void onUpdate(Show show) {
+ public void onUpdate(TextAndGraphicState newState) {
+
+ }
+
+ @Override
+ public void onError() {
}
};
defaultMainWindowCapability = getWindowCapability(4);
- TextsAndGraphicsState textsAndGraphicsState = new TextsAndGraphicsState(textField1, textField2, textField3, textField4,
- mediaTrackField, title, testArtwork3, testArtwork4, textAlignment, textField1Type, textField2Type, textField3Type, textField4Type);
+ TextAndGraphicState textsAndGraphicsState = new TextAndGraphicState(textField1, textField2, textField3, textField4,
+ mediaTrackField, title, testArtwork3, testArtwork4, textAlignment, textField1Type, textField2Type, textField3Type, textField4Type, null);
textAndGraphicUpdateOperation = new TextAndGraphicUpdateOperation(internalInterface, fileManager, defaultMainWindowCapability, currentScreenData, textsAndGraphicsState, listener, currentScreenDataUpdatedListener);
}
@@ -266,29 +326,29 @@ public class TextAndGraphicUpdateOperationTest {
// Test Images need to be uploaded, sending text and uploading images
textAndGraphicUpdateOperation.onExecute();
- assertEquals(textAndGraphicUpdateOperation.getCurrentScreenData().getMainField1(), textField1);
- assertEquals(textAndGraphicUpdateOperation.getCurrentScreenData().getMainField2(), textField2);
- assertEquals(textAndGraphicUpdateOperation.getCurrentScreenData().getMainField3(), textField3);
- assertEquals(textAndGraphicUpdateOperation.getCurrentScreenData().getMainField4(), textField4);
- assertEquals(textAndGraphicUpdateOperation.getCurrentScreenData().getAlignment(), textAlignment);
- assertEquals(textAndGraphicUpdateOperation.getCurrentScreenData().getGraphic(), testArtwork3.getImageRPC());
- assertEquals(textAndGraphicUpdateOperation.getCurrentScreenData().getSecondaryGraphic(), testArtwork4.getImageRPC());
+ assertEquals(textAndGraphicUpdateOperation.getCurrentScreenData().getTextField1(), textField1);
+ assertEquals(textAndGraphicUpdateOperation.getCurrentScreenData().getTextField2(), textField2);
+ assertEquals(textAndGraphicUpdateOperation.getCurrentScreenData().getTextField3(), textField3);
+ assertEquals(textAndGraphicUpdateOperation.getCurrentScreenData().getTextField4(), textField4);
+ assertEquals(textAndGraphicUpdateOperation.getCurrentScreenData().getTextAlignment(), textAlignment);
+ assertEquals(textAndGraphicUpdateOperation.getCurrentScreenData().getPrimaryGraphic(), testArtwork3);
+ assertEquals(textAndGraphicUpdateOperation.getCurrentScreenData().getSecondaryGraphic(), testArtwork4);
// Test The files to be updated are already uploaded, send the full show immediately
String textField11 = "It's not";
- TextsAndGraphicsState textsAndGraphicsState = new TextsAndGraphicsState(textField11, textField2, textField3, textField4,
- mediaTrackField, title, testArtwork1, testArtwork2, textAlignment, textField1Type, textField2Type, textField3Type, textField4Type);
+ TextAndGraphicState textsAndGraphicsState = new TextAndGraphicState(textField11, textField2, textField3, textField4,
+ mediaTrackField, title, testArtwork1, testArtwork2, textAlignment, textField1Type, textField2Type, textField3Type, textField4Type, null);
textAndGraphicUpdateOperation = new TextAndGraphicUpdateOperation(internalInterface, fileManager, defaultMainWindowCapability, currentScreenData, textsAndGraphicsState, listener, currentScreenDataUpdatedListener);
textAndGraphicUpdateOperation.onExecute();
- assertEquals(textAndGraphicUpdateOperation.getCurrentScreenData().getMainField1(), textField11);
+ assertEquals(textAndGraphicUpdateOperation.getCurrentScreenData().getTextField1(), textField11);
//Test: If there are no images to update, just send the text
- TextsAndGraphicsState textsAndGraphicsStateNullImages = new TextsAndGraphicsState(textField1, textField2, textField3, textField4,
- mediaTrackField, title, blankArtwork, blankArtwork, textAlignment, textField1Type, textField2Type, textField3Type, textField4Type);
+ TextAndGraphicState textsAndGraphicsStateNullImages = new TextAndGraphicState(textField1, textField2, textField3, textField4,
+ mediaTrackField, title, blankArtwork, blankArtwork, textAlignment, textField1Type, textField2Type, textField3Type, textField4Type, null);
textAndGraphicUpdateOperation = new TextAndGraphicUpdateOperation(internalInterface, fileManager, defaultMainWindowCapability, currentScreenData, textsAndGraphicsStateNullImages, listener, currentScreenDataUpdatedListener);
textAndGraphicUpdateOperation.onExecute();
- assertEquals(textAndGraphicUpdateOperation.getCurrentScreenData().getMainField1(), textField1);
+ assertEquals(textAndGraphicUpdateOperation.getCurrentScreenData().getTextField1(), textField1);
// Verifies that uploadArtworks gets called only with the fist textAndGraphicsUpdateOperation.onExecute call
verify(fileManager, times(1)).uploadArtworks(any(List.class), any(MultipleFileCompletionListener.class));
@@ -298,7 +358,7 @@ public class TextAndGraphicUpdateOperationTest {
public void testCanceledRightAway() {
textAndGraphicUpdateOperation.cancelTask();
textAndGraphicUpdateOperation.onExecute();
- assertEquals(textAndGraphicUpdateOperation.getCurrentScreenData().getMainField1(), "Old");
+ assertEquals(textAndGraphicUpdateOperation.getCurrentScreenData().getTextField1(), "Old");
}
@Test
@@ -310,7 +370,7 @@ public class TextAndGraphicUpdateOperationTest {
// Test Canceled after Image upload
textAndGraphicUpdateOperation.onExecute();
verify(internalInterface, times(1)).sendRPC(any(Show.class));
- assertEquals(textAndGraphicUpdateOperation.getCurrentScreenData().getMainField1(), textField1);
+ assertEquals(textAndGraphicUpdateOperation.getCurrentScreenData().getTextField1(), textField1);
}
@@ -324,6 +384,22 @@ public class TextAndGraphicUpdateOperationTest {
}
+ @Test
+ public void testTaskCanceledAfterSetDisplayLayout() {
+ doAnswer(onSetDisplayLayoutCanceled).when(internalInterface).sendRPC(any(SetDisplayLayout.class));
+ when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(5, 0));
+
+ TemplateConfiguration configuration = new TemplateConfiguration().setTemplate(PredefinedLayout.DOUBLE_GRAPHIC_WITH_SOFTBUTTONS.toString());
+ TextAndGraphicState textsAndGraphicsState = new TextAndGraphicState(textField1, textField2, textField3, textField4,
+ mediaTrackField, title, testArtwork3, testArtwork4, textAlignment, textField1Type, textField2Type, textField3Type, textField4Type, configuration);
+ textAndGraphicUpdateOperation = new TextAndGraphicUpdateOperation(internalInterface, fileManager, defaultMainWindowCapability, currentScreenData, textsAndGraphicsState, listener, currentScreenDataUpdatedListener);
+ textAndGraphicUpdateOperation.onExecute();
+ assertEquals(textAndGraphicUpdateOperation.getCurrentScreenData().getTemplateConfiguration().getStore(), configuration.getStore());
+ verify(internalInterface, times(0)).sendRPC(any(Show.class));
+ }
+
+
+
/**
* Test getting number of lines available to be set based off of windowCapability
*/
@@ -348,8 +424,8 @@ public class TextAndGraphicUpdateOperationTest {
Show inputShow = new Show();
- TextsAndGraphicsState textsAndGraphicsState = new TextsAndGraphicsState(textField1, null, null, null,
- mediaTrackField, title, testArtwork3, testArtwork4, textAlignment, MetadataType.HUMIDITY, null, null, null);
+ TextAndGraphicState textsAndGraphicsState = new TextAndGraphicState(textField1, null, null, null,
+ mediaTrackField, title, testArtwork3, testArtwork4, textAlignment, MetadataType.HUMIDITY, null, null, null, null);
textAndGraphicUpdateOperation = new TextAndGraphicUpdateOperation(internalInterface, fileManager, getWindowCapability(1), currentScreenData, textsAndGraphicsState, listener, currentScreenDataUpdatedListener);
Show assembledShow = textAndGraphicUpdateOperation.assembleShowText(inputShow);
@@ -404,8 +480,8 @@ public class TextAndGraphicUpdateOperationTest {
defaultMainWindowCapability = getWindowCapability(2);
// Force it to return display with support for only 2 lines of text
- TextsAndGraphicsState textsAndGraphicsState = new TextsAndGraphicsState(textField1, null, null, null,
- mediaTrackField, title, testArtwork3, testArtwork4, textAlignment, MetadataType.HUMIDITY, null, null, null);
+ TextAndGraphicState textsAndGraphicsState = new TextAndGraphicState(textField1, null, null, null,
+ mediaTrackField, title, testArtwork3, testArtwork4, textAlignment, MetadataType.HUMIDITY, null, null, null, null);
textAndGraphicUpdateOperation = new TextAndGraphicUpdateOperation(internalInterface, fileManager, defaultMainWindowCapability, currentScreenData, textsAndGraphicsState, listener, currentScreenDataUpdatedListener);
Show assembledShow = textAndGraphicUpdateOperation.assembleShowText(inputShow);
@@ -507,8 +583,8 @@ public class TextAndGraphicUpdateOperationTest {
// Force it to return display with support for only 3 lines of text
defaultMainWindowCapability = getWindowCapability(3);
- TextsAndGraphicsState textsAndGraphicsState = new TextsAndGraphicsState(textField1, null, null, null,
- mediaTrackField, title, testArtwork3, testArtwork4, textAlignment, MetadataType.HUMIDITY, null, null, null);
+ TextAndGraphicState textsAndGraphicsState = new TextAndGraphicState(textField1, null, null, null,
+ mediaTrackField, title, testArtwork3, testArtwork4, textAlignment, MetadataType.HUMIDITY, null, null, null, null);
textAndGraphicUpdateOperation = new TextAndGraphicUpdateOperation(internalInterface, fileManager, defaultMainWindowCapability, currentScreenData, textsAndGraphicsState, listener, currentScreenDataUpdatedListener);
Show assembledShow = textAndGraphicUpdateOperation.assembleShowText(inputShow);
@@ -621,8 +697,8 @@ public class TextAndGraphicUpdateOperationTest {
List<TextField> textFieldNames = Arrays.asList(tx1, tx2, tx3, tx4, tx5, tx6);
defaultMainWindowCapability.setTextFields(textFieldNames);
- TextsAndGraphicsState textsAndGraphicsState = new TextsAndGraphicsState(textField1, null, null, null,
- mediaTrackField, title, testArtwork3, testArtwork4, textAlignment, MetadataType.HUMIDITY, null, null, null);
+ TextAndGraphicState textsAndGraphicsState = new TextAndGraphicState(textField1, null, null, null,
+ mediaTrackField, title, testArtwork3, testArtwork4, textAlignment, MetadataType.HUMIDITY, null, null, null, null);
textAndGraphicUpdateOperation = new TextAndGraphicUpdateOperation(internalInterface, fileManager, defaultMainWindowCapability, currentScreenData, textsAndGraphicsState, listener, currentScreenDataUpdatedListener);
textsAndGraphicsState.setMediaTrackTextField("HI");
textsAndGraphicsState.setTitle("bye");
@@ -741,8 +817,8 @@ public class TextAndGraphicUpdateOperationTest {
Show inputShow = new Show();
- TextsAndGraphicsState textsAndGraphicsState = new TextsAndGraphicsState(textField1, null, null, null,
- mediaTrackField, title, testArtwork3, testArtwork4, textAlignment, MetadataType.HUMIDITY, null, null, null);
+ TextAndGraphicState textsAndGraphicsState = new TextAndGraphicState(textField1, null, null, null,
+ mediaTrackField, title, testArtwork3, testArtwork4, textAlignment, MetadataType.HUMIDITY, null, null, null, null);
textsAndGraphicsState.setMediaTrackTextField("HI");
textsAndGraphicsState.setTitle("bye");
@@ -867,7 +943,7 @@ public class TextAndGraphicUpdateOperationTest {
mainShow.setMainField3("Sauce");
mainShow.setMainField4("");
- Show newShow = textAndGraphicUpdateOperation.extractTextFromShow(mainShow);
+ Show newShow = textAndGraphicUpdateOperation.extractTextAndLayoutFromShow(mainShow);
assertEquals(newShow.getMainField1(), "test");
assertEquals(newShow.getMainField3(), "Sauce");
@@ -883,20 +959,59 @@ public class TextAndGraphicUpdateOperationTest {
// Test when artwork hasn't been uploaded
when(fileManager.hasUploadedFile(any(SdlFile.class))).thenReturn(false);
- TextsAndGraphicsState textsAndGraphicsState = new TextsAndGraphicsState(textField1, textField2, textField3, textField4,
- mediaTrackField, title, testArtwork3, testArtwork4, textAlignment, textField1Type, textField2Type, textField3Type, textField4Type);
+ TextAndGraphicState textsAndGraphicsState = new TextAndGraphicState(textField1, textField2, textField3, textField4,
+ mediaTrackField, title, testArtwork3, testArtwork4, textAlignment, textField1Type, textField2Type, textField3Type, textField4Type, configuration);
textAndGraphicUpdateOperation = new TextAndGraphicUpdateOperation(internalInterface, fileManager, defaultMainWindowCapability, currentScreenData, textsAndGraphicsState, listener, currentScreenDataUpdatedListener);
testShow = textAndGraphicUpdateOperation.createImageOnlyShowWithPrimaryArtwork(testArtwork1, testArtwork2);
assertNull(testShow);
// Test when artwork has been uploaded
when(fileManager.hasUploadedFile(any(SdlFile.class))).thenReturn(true);
- textsAndGraphicsState = new TextsAndGraphicsState(textField1, textField2, textField3, textField4,
- mediaTrackField, title, testArtwork3, testArtwork4, textAlignment, textField1Type, textField2Type, textField3Type, textField4Type);
+ textsAndGraphicsState = new TextAndGraphicState(textField1, textField2, textField3, textField4,
+ mediaTrackField, title, testArtwork3, testArtwork4, textAlignment, textField1Type, textField2Type, textField3Type, textField4Type, configuration);
textAndGraphicUpdateOperation = new TextAndGraphicUpdateOperation(internalInterface, fileManager, defaultMainWindowCapability, currentScreenData, textsAndGraphicsState, listener, currentScreenDataUpdatedListener);
testShow = textAndGraphicUpdateOperation.createImageOnlyShowWithPrimaryArtwork(testArtwork1, testArtwork2);
assertEquals(testShow.getGraphic(), testArtwork1.getImageRPC());
assertEquals(testShow.getSecondaryGraphic(), testArtwork2.getImageRPC());
}
+ @Test
+ public void testTemplateChange() {
+ doAnswer(onShowSuccess).when(internalInterface).sendRPC(any(Show.class));
+ doAnswer(onSetDisplayLayoutSuccess).when(internalInterface).sendRPC(any(SetDisplayLayout.class));
+ doAnswer(onArtworkUploadSuccess).when(fileManager).uploadArtworks(any(List.class), any(MultipleFileCompletionListener.class));
+ when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(6, 0));
+
+ TextAndGraphicState textsAndGraphicsState = new TextAndGraphicState(textField1, textField2, textField3, textField4,
+ mediaTrackField, title, testArtwork3, testArtwork4, textAlignment, textField1Type, textField2Type, textField3Type, textField4Type, configuration);
+ textAndGraphicUpdateOperation = new TextAndGraphicUpdateOperation(internalInterface, fileManager, defaultMainWindowCapability, currentScreenData, textsAndGraphicsState, listener, currentScreenDataUpdatedListener);
+ textAndGraphicUpdateOperation.onExecute();
+ assertEquals(textAndGraphicUpdateOperation.getCurrentScreenData().getTemplateConfiguration().getStore(), configuration.getStore());
+
+ when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(5, 0));
+
+ TemplateConfiguration configuration2 = new TemplateConfiguration().setTemplate(PredefinedLayout.DOUBLE_GRAPHIC_WITH_SOFTBUTTONS.toString());
+ textsAndGraphicsState = new TextAndGraphicState(textField1, textField2, textField3, textField4,
+ mediaTrackField, title, testArtwork3, testArtwork4, textAlignment, textField1Type, textField2Type, textField3Type, textField4Type, configuration2);
+ textAndGraphicUpdateOperation = new TextAndGraphicUpdateOperation(internalInterface, fileManager, defaultMainWindowCapability, currentScreenData, textsAndGraphicsState, listener, currentScreenDataUpdatedListener);
+ textAndGraphicUpdateOperation.onExecute();
+ assertEquals(textAndGraphicUpdateOperation.getCurrentScreenData().getTemplateConfiguration().getStore(), configuration2.getStore());
+ }
+
+ @Test
+ public void testOnShowFail() {
+ doAnswer(onShowFail).when(internalInterface).sendRPC(any(Show.class));
+ when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(6, 0));
+
+ TextAndGraphicState textsAndGraphicsState = new TextAndGraphicState(textField1, textField2, textField3, textField4,
+ mediaTrackField, title, testArtwork3, testArtwork4, textAlignment, textField1Type, textField2Type, textField3Type, textField4Type, configuration);
+ textAndGraphicUpdateOperation = new TextAndGraphicUpdateOperation(internalInterface, fileManager, defaultMainWindowCapability, currentScreenData, textsAndGraphicsState, listener, currentScreenDataUpdatedListener);
+ textAndGraphicUpdateOperation.onExecute();
+ assertEquals(textAndGraphicUpdateOperation.getCurrentScreenData().getTemplateConfiguration().getStore(), configuration.getStore());
+
+ // Verifies that uploadArtworks does not get called because a sendShow failed with text and layout change
+ verify(fileManager, times(0)).uploadArtworks(any(List.class), any(MultipleFileCompletionListener.class));
+
+ }
+
}
diff --git a/base/src/main/java/com/smartdevicelink/managers/lifecycle/BaseSystemCapabilityManager.java b/base/src/main/java/com/smartdevicelink/managers/lifecycle/BaseSystemCapabilityManager.java
index 052ecb5c4..a6fe2d18b 100644
--- a/base/src/main/java/com/smartdevicelink/managers/lifecycle/BaseSystemCapabilityManager.java
+++ b/base/src/main/java/com/smartdevicelink/managers/lifecycle/BaseSystemCapabilityManager.java
@@ -272,6 +272,10 @@ abstract class BaseSystemCapabilityManager {
switch (message.getFunctionID()) {
case SET_DISPLAY_LAYOUT:
SetDisplayLayoutResponse response = (SetDisplayLayoutResponse) message;
+ // If a setDisplayLayout fails, Capabilities did not change
+ if (!response.getSuccess()) {
+ return;
+ }
setCapability(SystemCapabilityType.DISPLAY, response.getDisplayCapabilities());
setCapability(SystemCapabilityType.BUTTON, response.getButtonCapabilities());
setCapability(SystemCapabilityType.PRESET_BANK, response.getPresetBankCapabilities());
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 297c114d3..2f7019068 100644
--- a/base/src/main/java/com/smartdevicelink/managers/screen/BaseScreenManager.java
+++ b/base/src/main/java/com/smartdevicelink/managers/screen/BaseScreenManager.java
@@ -51,6 +51,7 @@ 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.rpc.KeyboardProperties;
+import com.smartdevicelink.proxy.rpc.TemplateConfiguration;
import com.smartdevicelink.proxy.rpc.enums.ButtonName;
import com.smartdevicelink.proxy.rpc.enums.InteractionMode;
import com.smartdevicelink.proxy.rpc.enums.MetadataType;
@@ -152,8 +153,16 @@ abstract class BaseScreenManager extends BaseSubManager {
}
/**
- * Set the textField1 on the head unit screen
- * Sending an empty String "" will clear the field
+ * The top text field within a template layout. Pass an empty string "" to clear the text field.
+ *
+ * If the system does not support a full 4 fields, this will automatically be concatenated and properly send the field available.
+ *
+ * If 3 lines are available: [field1, field2, field3 - field 4]
+ *
+ * If 2 lines are available: [field1 - field2, field3 - field4]
+ *
+ * If 1 line is available: [field1 - field2 - field3 - field4]
+ *
* @param textField1 String value represents the textField1
*/
public void setTextField1(String textField1) {
@@ -170,8 +179,16 @@ abstract class BaseScreenManager extends BaseSubManager {
}
/**
- * Set the textField2 on the head unit screen
- * Sending an empty String "" will clear the field
+ * Sets the second text field within a template layout. Pass an empty string "" to clear the text field.
+ *
+ * If the system does not support a full 4 fields, this will automatically be concatenated and properly send the field available.
+ *
+ * If 3 lines are available: [field1, field2, field3 - field 4]
+ *
+ * If 2 lines are available: [field1 - field2, field3 - field4]
+ *
+ * If 1 line is available: [field1 - field2 - field3 - field4]
+ *
* @param textField2 String value represents the textField1
*/
public void setTextField2(String textField2) {
@@ -187,8 +204,16 @@ abstract class BaseScreenManager extends BaseSubManager {
}
/**
- * Set the textField3 on the head unit screen
- * Sending an empty String "" will clear the field
+ * Sets the third text field within a template layout. Pass an empty string "" to clear the text field.
+ *
+ * If the system does not support a full 4 fields, this will automatically be concatenated and properly send the field available.
+ *
+ * If 3 lines are available: [field1, field2, field3 - field 4]
+ *
+ * If 2 lines are available: [field1 - field2, field3 - field4]
+ *
+ * If 1 line is available: [field1 - field2 - field3 - field4]
+ *
* @param textField3 String value represents the textField1
*/
public void setTextField3(String textField3) {
@@ -204,8 +229,16 @@ abstract class BaseScreenManager extends BaseSubManager {
}
/**
- * Set the textField4 on the head unit screen
- * Sending an empty String "" will clear the field
+ * Sets the fourth text field within a template layout. Pass an empty string "" to clear the text field.
+ *
+ * If the system does not support a full 4 fields, this will automatically be concatenated and properly send the field available.
+ *
+ * If 3 lines are available: [field1, field2, field3 - field 4]
+ *
+ * If 2 lines are available: [field1 - field2, field3 - field4]
+ *
+ * If 1 line is available: [field1 - field2 - field3 - field4]
+ *
* @param textField4 String value represents the textField1
*/
public void setTextField4(String textField4) {
@@ -378,6 +411,26 @@ abstract class BaseScreenManager extends BaseSubManager {
}
/**
+ * Change the current layout to a new layout and optionally update the layout's night and day color schemes. The values set for the text, graphics,
+ * buttons and template title persist between layout changes. To update the text, graphics, buttons and template title at the same time as the template,
+ * batch all the updates between beginTransaction and commit. If the layout update fails while batching, then the updated text, graphics, buttons or template title will also not be updated.
+ *
+ * If you are connected on a < v6.0 connection and batching the update, the layout will be updated, then the text and graphics will be updated.
+ * If you are connected on a >= v6.0 connection, the layout will be updated at the same time that the text and graphics are updated.
+ *
+ * If this update is batched between beginTransaction and commit, the completionListener here will not be called. Use the completionListener with commit(completionListener)
+ *
+ * NOTE: If this update returns an false, it may have been superseded by another update.
+ * This means that it was cancelled while in-progress because another update was requested, whether batched or not.
+ *
+ * @param templateConfiguration The new configuration of the template, including the layout and color scheme.
+ * @param listener A listener that will be called when the layout change finished.
+ */
+ public void changeLayout(@NonNull TemplateConfiguration templateConfiguration, CompletionListener listener) {
+ textAndGraphicManager.changeLayout(templateConfiguration, listener);
+ }
+
+ /**
* Set softButtonObjects list and upload the images to the head unit
* @param softButtonObjects the list of the SoftButtonObject values that should be displayed on the head unit
*/
@@ -580,7 +633,11 @@ abstract class BaseScreenManager extends BaseSubManager {
}
/**
- * Send the updates that were started after beginning the transaction
+ * Pairs with beginTransaction() to batch text, graphic, and layout changes into a single update with a callback when the update is complete.
+ * Update text fields with new text set into the text field properties, updates the primary and secondary images with new image(s) if new one(s) been set,
+ * and updates the template if one was changed using changeLayout(TemplateConfiguration, CompletionListener).
+ * NOTE: The CompletionListener in changeLayout(TemplateConfiguration, CompletionListener) will not be called if the update is batched into this update
+ * NOTE: If this CompletionListener returns false, it may have been superseded by another update. This means that it was cancelled while in-progress because another update was requested, whether batched or not.
* @param listener a CompletionListener that has a callback that will be called when the updates are finished
*/
public void commit(final CompletionListener listener){
diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/BaseTextAndGraphicManager.java b/base/src/main/java/com/smartdevicelink/managers/screen/BaseTextAndGraphicManager.java
index 3542dd269..50bf7fb4e 100644
--- a/base/src/main/java/com/smartdevicelink/managers/screen/BaseTextAndGraphicManager.java
+++ b/base/src/main/java/com/smartdevicelink/managers/screen/BaseTextAndGraphicManager.java
@@ -46,7 +46,7 @@ import com.smartdevicelink.protocol.enums.FunctionID;
import com.smartdevicelink.proxy.RPCNotification;
import com.smartdevicelink.proxy.rpc.DisplayCapability;
import com.smartdevicelink.proxy.rpc.OnHMIStatus;
-import com.smartdevicelink.proxy.rpc.Show;
+import com.smartdevicelink.proxy.rpc.TemplateConfiguration;
import com.smartdevicelink.proxy.rpc.WindowCapability;
import com.smartdevicelink.proxy.rpc.enums.HMILevel;
import com.smartdevicelink.proxy.rpc.enums.MetadataType;
@@ -72,7 +72,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
private static final String TAG = "TextAndGraphicManager";
boolean isDirty;
- Show currentScreenData;
+ TextAndGraphicState currentScreenData;
HMILevel currentHMILevel;
private final WeakReference<SoftButtonManager> softButtonManager;
WindowCapability defaultMainWindowCapability;
@@ -85,6 +85,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
private TextAlignment textAlignment;
private String textField1, textField2, textField3, textField4, mediaTrackTextField, title;
private MetadataType textField1Type, textField2Type, textField3Type, textField4Type;
+ private TemplateConfiguration templateConfiguration;
TextAndGraphicUpdateOperation updateOperation;
private CompletionListener currentOperationListener;
Queue transactionQueue;
@@ -100,7 +101,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
isDirty = false;
textAlignment = CENTERED;
currentHMILevel = HMILevel.HMI_NONE;
- currentScreenData = new Show();
+ currentScreenData = new TextAndGraphicState();
this.transactionQueue = newTransactionQueue();
addListeners();
}
@@ -174,14 +175,14 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
}
if (isDirty) {
isDirty = false;
- sdlUpdate(listener);
+ sdlUpdate(true, listener);
} else if (listener != null) {
listener.onComplete(true);
}
}
- private synchronized void sdlUpdate(final CompletionListener listener) {
- if (this.transactionQueue.getTasksAsList().size() > 0) {
+ private synchronized void sdlUpdate(Boolean supersedePreviousOperations, final CompletionListener listener) {
+ if (this.transactionQueue.getTasksAsList().size() > 0 && supersedePreviousOperations) {
// Transactions already in queue, we need to clear it out
transactionQueue.clear();
updateOperation = null;
@@ -191,7 +192,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
}
// Task can be READY, about to start and popped of the queue, so we have to cancel it, to prevent it from starting
- if (updateOperation != null && updateOperation.getState() == Task.READY) {
+ if (updateOperation != null && updateOperation.getState() == Task.READY && supersedePreviousOperations) {
updateOperation.cancelTask();
if (currentOperationListener != null) {
currentOperationListener.onComplete(false);
@@ -199,7 +200,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
}
// If Task is IN_PROGRESS, it’s not on the queue, we need to mark it as cancelled. The task will return at some point when it checks its status and call the listener back
- if (updateOperation != null && updateOperation.getState() == Task.IN_PROGRESS) {
+ if (updateOperation != null && updateOperation.getState() == Task.IN_PROGRESS && supersedePreviousOperations) {
updateOperation.cancelTask();
}
@@ -207,9 +208,18 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
CurrentScreenDataUpdatedListener currentScreenDataUpdateListener = new CurrentScreenDataUpdatedListener() {
@Override
- public void onUpdate(Show show) {
- updatePendingOperationsWithNewScreenData(show);
- currentScreenData = show;
+ public void onUpdate(TextAndGraphicState newScreenData) {
+ if(newScreenData != null) {
+ // Update our current screen data
+ currentScreenData = newScreenData;
+ updatePendingOperationsWithNewScreenData();
+ }
+ }
+
+ @Override
+ public void onError() {
+ // Invalidate data that's different from our current screen data
+ resetFieldsToCurrentScreenData();
}
};
@@ -217,21 +227,39 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
transactionQueue.add(updateOperation, false);
}
+ void resetFieldsToCurrentScreenData() {
+ textField1 = currentScreenData.getTextField1();
+ textField2 = currentScreenData.getTextField2();
+ textField3 = currentScreenData.getTextField3();
+ textField4 = currentScreenData.getTextField4();
+ mediaTrackTextField = currentScreenData.getMediaTrackTextField();
+ title = currentScreenData.getTitle();
+ textAlignment = currentScreenData.getTextAlignment();
+ textField1Type = currentScreenData.getTextField1Type();
+ textField2Type = currentScreenData.getTextField2Type();
+ textField3Type = currentScreenData.getTextField3Type();
+ textField4Type = currentScreenData.getTextField4Type();
+ primaryGraphic = currentScreenData.getPrimaryGraphic();
+ secondaryGraphic = currentScreenData.getSecondaryGraphic();
+ templateConfiguration = currentScreenData.getTemplateConfiguration();
+ }
+
//Updates pending task with current screen data
- void updatePendingOperationsWithNewScreenData(Show newScreenData) {
+ void updatePendingOperationsWithNewScreenData() {
for (Task task : transactionQueue.getTasksAsList()) {
if (!(task instanceof TextAndGraphicUpdateOperation)) {
continue;
}
- ((TextAndGraphicUpdateOperation) task).setCurrentScreenData(newScreenData);
+ ((TextAndGraphicUpdateOperation) task).setCurrentScreenData(currentScreenData);
}
- if (this.softButtonManager.get() != null && newScreenData.getMainField1() != null) {
- this.softButtonManager.get().setCurrentMainField1(currentScreenData.getMainField1());
+ if (this.softButtonManager.get() != null && currentScreenData.getTextField1() != null) {
+ this.softButtonManager.get().setCurrentMainField1(currentScreenData.getTextField1());
}
}
interface CurrentScreenDataUpdatedListener {
- void onUpdate(Show show);
+ void onUpdate(TextAndGraphicState newState);
+ void onError();
}
@@ -277,9 +305,9 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
// Convert to State
- private TextsAndGraphicsState currentState() {
- return new TextsAndGraphicsState(textField1, textField2, textField3, textField4, mediaTrackTextField,
- title, primaryGraphic, secondaryGraphic, textAlignment, textField1Type, textField2Type, textField3Type, textField4Type);
+ TextAndGraphicState currentState() {
+ return new TextAndGraphicState(textField1, textField2, textField3, textField4, mediaTrackTextField,
+ title, primaryGraphic, secondaryGraphic, textAlignment, textField1Type, textField2Type, textField3Type, textField4Type, templateConfiguration);
}
// Getters / Setters
@@ -288,7 +316,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
this.textAlignment = textAlignment;
// If we aren't batching, send the update immediately, if we are, set ourselves as dirty (so we know we should send an update after the batch ends)
if (!batchingUpdates) {
- sdlUpdate(null);
+ sdlUpdate(true, null);
} else {
isDirty = true;
}
@@ -301,7 +329,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
void setMediaTrackTextField(String mediaTrackTextField) {
this.mediaTrackTextField = mediaTrackTextField;
if (!batchingUpdates) {
- sdlUpdate(null);
+ sdlUpdate(true, null);
} else {
isDirty = true;
}
@@ -314,7 +342,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
void setTextField1(String textField1) {
this.textField1 = textField1;
if (!batchingUpdates) {
- sdlUpdate(null);
+ sdlUpdate(true, null);
} else {
isDirty = true;
}
@@ -327,7 +355,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
void setTextField2(String textField2) {
this.textField2 = textField2;
if (!batchingUpdates) {
- sdlUpdate(null);
+ sdlUpdate(true, null);
} else {
isDirty = true;
}
@@ -340,7 +368,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
void setTextField3(String textField3) {
this.textField3 = textField3;
if (!batchingUpdates) {
- sdlUpdate(null);
+ sdlUpdate(true, null);
} else {
isDirty = true;
}
@@ -353,7 +381,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
void setTextField4(String textField4) {
this.textField4 = textField4;
if (!batchingUpdates) {
- sdlUpdate(null);
+ sdlUpdate(true, null);
} else {
isDirty = true;
}
@@ -366,7 +394,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
void setTextField1Type(MetadataType textField1Type) {
this.textField1Type = textField1Type;
if (!batchingUpdates) {
- sdlUpdate(null);
+ sdlUpdate(true, null);
} else {
isDirty = true;
}
@@ -379,7 +407,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
void setTextField2Type(MetadataType textField2Type) {
this.textField2Type = textField2Type;
if (!batchingUpdates) {
- sdlUpdate(null);
+ sdlUpdate(true, null);
} else {
isDirty = true;
}
@@ -392,7 +420,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
void setTextField3Type(MetadataType textField3Type) {
this.textField3Type = textField3Type;
if (!batchingUpdates) {
- sdlUpdate(null);
+ sdlUpdate(true, null);
} else {
isDirty = true;
}
@@ -405,7 +433,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
void setTextField4Type(MetadataType textField4Type) {
this.textField4Type = textField4Type;
if (!batchingUpdates) {
- sdlUpdate(null);
+ sdlUpdate(true, null);
} else {
isDirty = true;
}
@@ -418,7 +446,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
void setTitle(String title) {
this.title = title;
if (!batchingUpdates) {
- sdlUpdate(null);
+ sdlUpdate(true, null);
} else {
isDirty = true;
}
@@ -431,7 +459,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
void setPrimaryGraphic(SdlArtwork primaryGraphic) {
this.primaryGraphic = primaryGraphic;
if (!batchingUpdates) {
- sdlUpdate(null);
+ sdlUpdate(true, null);
} else {
isDirty = true;
}
@@ -444,12 +472,39 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
void setSecondaryGraphic(SdlArtwork secondaryGraphic) {
this.secondaryGraphic = secondaryGraphic;
if (!batchingUpdates) {
- sdlUpdate(null);
+ sdlUpdate(true, null);
} else {
isDirty = true;
}
}
+ /**
+ * Change the current layout to a new layout and optionally update the layout's night and day color schemes.
+ * The values set for the text, graphics, buttons and template title persist between layout changes.
+ * To update the text, graphics, buttons and template title at the same time as the template, batch all the updates between beginTransaction and commit.
+ * If the layout update fails while batching, then the updated text, graphics, buttons or template title will also not be updated.
+ *
+ * @param templateConfiguration The new configuration of the template, including the layout and color scheme.
+ * @param listener A listener that will be called when the layout change finished.
+ */
+ void changeLayout(TemplateConfiguration templateConfiguration, CompletionListener listener) {
+ setTemplateConfiguration(templateConfiguration);
+ if(!batchingUpdates) {
+ sdlUpdate(true, listener);
+ } else {
+ isDirty = true;
+ }
+ }
+
+ TemplateConfiguration getTemplateConfiguration() {
+ return templateConfiguration;
+ }
+
+ void setTemplateConfiguration(TemplateConfiguration templateConfiguration) {
+ // Don't do the `isBatchingUpdates` like elsewhere because the call is already handled in `changeLayout(TemplateConfiguration templateConfiguration, CompletionListener listener) `
+ this.templateConfiguration = templateConfiguration;
+ }
+
SdlArtwork getSecondaryGraphic() {
return secondaryGraphic;
}
@@ -486,6 +541,10 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
for (WindowCapability windowCapability : display.getWindowCapabilities()) {
int currentWindowID = windowCapability.getWindowID() != null ? windowCapability.getWindowID() : PredefinedWindows.DEFAULT_WINDOW.getValue();
if (currentWindowID == PredefinedWindows.DEFAULT_WINDOW.getValue()) {
+ // Check if the window capability is equal to the one we already have. If it is, abort.
+ if(defaultMainWindowCapability != null && defaultMainWindowCapability.getStore().equals(windowCapability.getStore())){
+ return;
+ }
defaultMainWindowCapability = windowCapability;
}
}
@@ -493,7 +552,8 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
// Update the queue's suspend state
updateTransactionQueueSuspended();
if (hasData()) {
- sdlUpdate(null);
+ // HAX: Capability updates cannot supersede earlier updates because of the case where a developer batched a `changeLayout` call w/ T&G changes on < 6.0 systems could cause this to come in before the operation completes. That would cause the operation to report a "failure" (because it was superseded by this call) when in fact the operation didn't fail at all and is just being adjusted.
+ sdlUpdate(false, null);
}
}
diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/TextAndGraphicUpdateOperation.java b/base/src/main/java/com/smartdevicelink/managers/screen/TextAndGraphicUpdateOperation.java
index a4e1348c8..8cdc464b5 100644
--- a/base/src/main/java/com/smartdevicelink/managers/screen/TextAndGraphicUpdateOperation.java
+++ b/base/src/main/java/com/smartdevicelink/managers/screen/TextAndGraphicUpdateOperation.java
@@ -9,7 +9,9 @@ import com.smartdevicelink.managers.file.MultipleFileCompletionListener;
import com.smartdevicelink.managers.file.filetypes.SdlArtwork;
import com.smartdevicelink.proxy.RPCResponse;
import com.smartdevicelink.proxy.rpc.MetadataTags;
+import com.smartdevicelink.proxy.rpc.SetDisplayLayout;
import com.smartdevicelink.proxy.rpc.Show;
+import com.smartdevicelink.proxy.rpc.TemplateConfiguration;
import com.smartdevicelink.proxy.rpc.WindowCapability;
import com.smartdevicelink.proxy.rpc.enums.ImageFieldName;
import com.smartdevicelink.proxy.rpc.enums.MetadataType;
@@ -32,13 +34,14 @@ class TextAndGraphicUpdateOperation extends Task {
private final WeakReference<ISdl> internalInterface;
private final WeakReference<FileManager> fileManager;
WindowCapability defaultMainWindowCapability;
- private Show currentScreenData;
- private final TextsAndGraphicsState updatedState;
- private final CompletionListener listener;
+ private TextAndGraphicState currentScreenData;
+ private final TextAndGraphicState updatedState;
private final TextAndGraphicManager.CurrentScreenDataUpdatedListener currentScreenDataUpdateListener;
+ private final CompletionListener listener;
+ private Show fullShow;
TextAndGraphicUpdateOperation(ISdl internalInterface, FileManager fileManager, WindowCapability currentCapabilities,
- Show currentScreenData, TextsAndGraphicsState newState, CompletionListener listener, TextAndGraphicManager.CurrentScreenDataUpdatedListener currentScreenDataUpdateListener) {
+ TextAndGraphicState currentScreenData, TextAndGraphicState newState, CompletionListener listener, TextAndGraphicManager.CurrentScreenDataUpdatedListener currentScreenDataUpdateListener) {
super("TextAndGraphicUpdateOperation");
this.internalInterface = new WeakReference<>(internalInterface);
this.fileManager = new WeakReference<>(fileManager);
@@ -60,16 +63,40 @@ class TextAndGraphicUpdateOperation extends Task {
return;
}
- // Build a show with everything from `self.newState`, we'll pull things out later if we can.
- Show fullShow = new Show();
+ fullShow = new Show();
fullShow.setAlignment(updatedState.getTextAlignment());
fullShow = assembleShowText(fullShow);
fullShow = assembleShowImages(fullShow);
+ fullShow = assembleLayout(fullShow);
+
+
+ if (showRPCSupportsTemplateConfiguration()) {
+ updateGraphicsAndShow(fullShow);
+ } else {
+ if (shouldUpdateTemplateConfig()) {
+ sendSetDisplayLayoutWithTemplateConfiguration(updatedState.getTemplateConfiguration(), new CompletionListener() {
+ @Override
+ public void onComplete(boolean success) {
+ if (getState() == Task.CANCELED || !success) {
+ // Task was canceled or SetDisplayLayout was not a success
+ finishOperation(false);
+ return;
+ }
+ updateGraphicsAndShow(fullShow);
+ }
+ });
+ } else {
+ // just send the show
+ updateGraphicsAndShow(fullShow);
+ }
+ }
+ }
+ void updateGraphicsAndShow(Show show) {
if (!shouldUpdatePrimaryImage() && !shouldUpdateSecondaryImage()) {
DebugTool.logInfo(TAG, "No images to send, sending text");
// If there are no images to update, just send the text
- sendShow(extractTextFromShow(fullShow), new CompletionListener() {
+ sendShow(extractTextAndLayoutFromShow(show), new CompletionListener() {
@Override
public void onComplete(boolean success) {
finishOperation(success);
@@ -79,7 +106,7 @@ class TextAndGraphicUpdateOperation extends Task {
} else if (!sdlArtworkNeedsUpload(updatedState.getPrimaryGraphic()) && !sdlArtworkNeedsUpload(updatedState.getSecondaryGraphic())) {
DebugTool.logInfo(TAG, "Images already uploaded, sending full update");
// The files to be updated are already uploaded, send the full show immediately
- sendShow(fullShow, new CompletionListener() {
+ sendShow(show, new CompletionListener() {
@Override
public void onComplete(boolean success) {
finishOperation(success);
@@ -88,10 +115,11 @@ class TextAndGraphicUpdateOperation extends Task {
} else {
DebugTool.logInfo(TAG, "Images need to be uploaded, sending text and uploading images");
- sendShow(extractTextFromShow(fullShow), new CompletionListener() {
+ sendShow(extractTextAndLayoutFromShow(show), new CompletionListener() {
@Override
public void onComplete(boolean success) {
- if (getState() == Task.CANCELED) {
+ if (getState() == Task.CANCELED || !success) {
+ // Task was canceled or update to text / layout was not a success
finishOperation(false);
return;
}
@@ -111,15 +139,51 @@ class TextAndGraphicUpdateOperation extends Task {
show.setOnRPCResponseListener(new OnRPCResponseListener() {
@Override
public void onResponse(int correlationId, RPCResponse response) {
- DebugTool.logInfo(TAG, "Text and Graphic update completed");
if (response.getSuccess()) {
+ DebugTool.logInfo(TAG, "Text and Graphic update completed");
updateCurrentScreenDataFromShow(show);
+ } else {
+ DebugTool.logInfo(TAG, "Text and Graphic Show failed");
+ currentScreenDataUpdateListener.onError();
}
listener.onComplete(response.getSuccess());
}
});
- internalInterface.get().sendRPC(show);
+ if(internalInterface.get() != null){
+ internalInterface.get().sendRPC(show);
+ } else {
+ DebugTool.logInfo(TAG, "ISdl is null Text and Graphic update failed");
+ currentScreenDataUpdateListener.onError();
+ finishOperation(false);
+ return;
+ }
+
+ }
+
+ private void sendSetDisplayLayoutWithTemplateConfiguration(TemplateConfiguration configuration, final CompletionListener listener){
+ final SetDisplayLayout setLayout = new SetDisplayLayout().setDisplayLayout(configuration.getTemplate()).setDayColorScheme(configuration.getDayColorScheme()).setNightColorScheme(configuration.getNightColorScheme());
+ setLayout.setOnRPCResponseListener(new OnRPCResponseListener() {
+ @Override
+ public void onResponse(int correlationId, RPCResponse response) {
+ if(response.getSuccess()){
+ updateCurrentScreenDataFromSetDisplayLayout(setLayout);
+ }
+ else {
+ DebugTool.logInfo(TAG, "Text and Graphic SetDisplayLayout failed");
+ currentScreenDataUpdateListener.onError();
+ }
+ listener.onComplete(response.getSuccess());
+ }
+ });
+ if(internalInterface.get() != null){
+ internalInterface.get().sendRPC(setLayout);
+ } else {
+ DebugTool.logInfo(TAG, "ISdl is null Text and Graphic update failed");
+ currentScreenDataUpdateListener.onError();
+ finishOperation(false);
+ return;
+ }
}
@@ -221,7 +285,7 @@ class TextAndGraphicUpdateOperation extends Task {
return show;
}
- int numberOfLines = defaultMainWindowCapability != null ? ManagerUtility.WindowCapabilityUtility.getMaxNumberOfMainFieldLines(defaultMainWindowCapability) : 4;
+ int numberOfLines = defaultMainWindowCapability == null || shouldUpdateTemplateConfig() ? 4 : ManagerUtility.WindowCapabilityUtility.getMaxNumberOfMainFieldLines(defaultMainWindowCapability);
switch (numberOfLines) {
case 1:
@@ -428,7 +492,7 @@ class TextAndGraphicUpdateOperation extends Task {
// Extraction
- Show extractTextFromShow(Show show) {
+ Show extractTextAndLayoutFromShow(Show show) {
Show newShow = new Show();
newShow.setMainField1(show.getMainField1());
newShow.setMainField2(show.getMainField2());
@@ -438,6 +502,9 @@ class TextAndGraphicUpdateOperation extends Task {
newShow.setMetadataTags(show.getMetadataTags());
newShow.setAlignment(show.getAlignment());
+ if (showRPCSupportsTemplateConfiguration()) {
+ newShow.setTemplateConfiguration(show.getTemplateConfiguration());
+ }
return newShow;
}
@@ -452,42 +519,70 @@ class TextAndGraphicUpdateOperation extends Task {
return newShow;
}
+ Show assembleLayout(Show show) {
+ if (!showRPCSupportsTemplateConfiguration() || !shouldUpdateTemplateConfig()) {
+ return show;
+ }
+ show.setTemplateConfiguration(updatedState.getTemplateConfiguration());
+ return show;
+ }
+
+ private void updateCurrentScreenDataFromSetDisplayLayout(SetDisplayLayout setDisplayLayout) {
+ currentScreenData.setTemplateConfiguration(new TemplateConfiguration().setTemplate(setDisplayLayout.getDisplayLayout()).setDayColorScheme(setDisplayLayout.getDayColorScheme()).setNightColorScheme(setDisplayLayout.getNightColorScheme()));
+ if (currentScreenDataUpdateListener != null) {
+ currentScreenDataUpdateListener.onUpdate(currentScreenData);
+ }
+ }
+
private void updateCurrentScreenDataFromShow(Show show) {
if (show == null) {
DebugTool.logError(TAG, "can not updateCurrentScreenDataFromShow from null show");
return;
}
-
- // If the items are null, they were not updated, so we can't just set it directly
+ // This is intentionally checking `mainField1` for every textField because the fields may be in different places based on the capabilities, then check it's own field in case that's the only field thats being used.
if (show.getMainField1() != null) {
- currentScreenData.setMainField1(show.getMainField1());
+ currentScreenData.setTextField1(updatedState.getTextField1());
}
- if (show.getMainField2() != null) {
- currentScreenData.setMainField2(show.getMainField2());
+ if (show.getMainField1() != null || show.getMainField2() != null) {
+ currentScreenData.setTextField2(updatedState.getTextField2());
}
- if (show.getMainField3() != null) {
- currentScreenData.setMainField3(show.getMainField3());
+ if (show.getMainField1() != null || show.getMainField3() != null) {
+ currentScreenData.setTextField3(updatedState.getTextField3());
}
- if (show.getMainField4() != null) {
- currentScreenData.setMainField4(show.getMainField4());
+ if (show.getMainField1() != null || show.getMainField4() != null) {
+ currentScreenData.setTextField4(updatedState.getTextField4());
}
if (show.getTemplateTitle() != null) {
- currentScreenData.setTemplateTitle(show.getTemplateTitle());
+ currentScreenData.setTitle(updatedState.getTitle());
}
if (show.getMediaTrack() != null) {
- currentScreenData.setMediaTrack(show.getMediaTrack());
+ currentScreenData.setMediaTrackTextField(updatedState.getMediaTrackTextField());
}
- if (show.getMetadataTags() != null) {
- currentScreenData.setMetadataTags(show.getMetadataTags());
+
+ // This is intentionally checking show.metadataTags.mainField1 because the tags may be in different places based on the capabilities, then check its own field in case that's the only field that's being used.
+ if(show.getMetadataTags() != null){
+ if(show.getMetadataTags().getMainField1() != null) {
+ currentScreenData.setTextField1Type(updatedState.getTextField1Type());
+ }
+ if (show.getMetadataTags().getMainField1() != null || show.getMetadataTags().getMainField2() != null) {
+ currentScreenData.setTextField2Type(updatedState.getTextField2Type());
+ }
+ if (show.getMetadataTags().getMainField1() != null || show.getMetadataTags().getMainField3() != null) {
+ currentScreenData.setTextField3Type(updatedState.getTextField3Type());
+ }
+ if (show.getMetadataTags().getMainField1() != null || show.getMetadataTags().getMainField4() != null) {
+ currentScreenData.setTextField4Type(updatedState.getTextField4Type());
+ }
}
+
if (show.getAlignment() != null) {
- currentScreenData.setAlignment(show.getAlignment());
+ currentScreenData.setTextAlignment(updatedState.getTextAlignment());
}
if (show.getGraphic() != null) {
- currentScreenData.setGraphic(show.getGraphic());
+ currentScreenData.setPrimaryGraphic(updatedState.getPrimaryGraphic());
}
if (show.getSecondaryGraphic() != null) {
- currentScreenData.setSecondaryGraphic(show.getSecondaryGraphic());
+ currentScreenData.setSecondaryGraphic(updatedState.getSecondaryGraphic());
}
if (currentScreenDataUpdateListener != null) {
currentScreenDataUpdateListener.onUpdate(currentScreenData);
@@ -496,6 +591,13 @@ class TextAndGraphicUpdateOperation extends Task {
// Helpers
+ private boolean showRPCSupportsTemplateConfiguration() {
+ if (internalInterface.get() == null || internalInterface.get().getSdlMsgVersion() == null) {
+ return false;
+ }
+ return internalInterface.get().getSdlMsgVersion().getMajorVersion() >= 6;
+ }
+
private List<String> findValidMainTextFields() {
List<String> array = new ArrayList<>();
@@ -555,8 +657,9 @@ class TextAndGraphicUpdateOperation extends Task {
* @return true if primaryGraphic should be updated, false if not
*/
private boolean shouldUpdatePrimaryImage() {
- boolean templateSupportsPrimaryArtwork = templateSupportsImageField(ImageFieldName.graphic);
- String currentScreenDataPrimaryGraphicName = (currentScreenData != null && currentScreenData.getGraphic() != null) ? currentScreenData.getGraphic().getValue() : null;
+ // If the template is updating, we don't yet know it's capabilities. Just assume the template supports the primary image.
+ boolean templateSupportsPrimaryArtwork = templateSupportsImageField(ImageFieldName.graphic) || shouldUpdateTemplateConfig();
+ String currentScreenDataPrimaryGraphicName = (currentScreenData != null && currentScreenData.getPrimaryGraphic() != null) ? currentScreenData.getPrimaryGraphic().getName() : null;
String primaryGraphicName = updatedState.getPrimaryGraphic() != null ? updatedState.getPrimaryGraphic().getName() : null;
boolean graphicMatchesExisting = CompareUtils.areStringsEqual(currentScreenDataPrimaryGraphicName, primaryGraphicName, true, true);
@@ -570,14 +673,15 @@ class TextAndGraphicUpdateOperation extends Task {
* @return true if secondaryGraphic should be updated, false if not
*/
private boolean shouldUpdateSecondaryImage() {
- boolean templateSupportsSecondaryArtwork = templateSupportsImageField(ImageFieldName.secondaryGraphic);
- String currentScreenDataSecondaryGraphicName = (currentScreenData != null && currentScreenData.getSecondaryGraphic() != null) ? currentScreenData.getSecondaryGraphic().getValue() : null;
+ // If the template is updating, we don't yet know it's capabilities. Just assume the template supports the secondary image.
+ boolean templateSupportsSecondaryArtwork = templateSupportsImageField(ImageFieldName.secondaryGraphic) || shouldUpdateTemplateConfig();
+ String currentScreenDataSecondaryGraphicName = (currentScreenData != null && currentScreenData.getSecondaryGraphic() != null) ? currentScreenData.getSecondaryGraphic().getName() : null;
String secondaryGraphicName = updatedState.getSecondaryGraphic() != null ? updatedState.getSecondaryGraphic().getName() : null;
boolean graphicMatchesExisting = CompareUtils.areStringsEqual(currentScreenDataSecondaryGraphicName, secondaryGraphicName, true, true);
// Cannot detect if there is a secondary image below v5.0, so we'll just try to detect if the primary image is allowed and allow the secondary image if it is.
- if (internalInterface.get().getSdlMsgVersion().getMajorVersion() >= 5) {
+ if (internalInterface.get() != null && internalInterface.get().getSdlMsgVersion().getMajorVersion() >= 5) {
return templateSupportsSecondaryArtwork && !graphicMatchesExisting;
} else {
return templateSupportsImageField(ImageFieldName.graphic) && !graphicMatchesExisting;
@@ -599,7 +703,8 @@ class TextAndGraphicUpdateOperation extends Task {
* @return true if mediaTrackTextField should be updated, false if not
*/
private boolean shouldUpdateMediaTrackField() {
- return templateSupportsTextField(TextFieldName.mediaTrack);
+ // If the template is updating, we don't yet know it's capabilities. Just assume the template supports the media text field.
+ return templateSupportsTextField(TextFieldName.mediaTrack) || shouldUpdateTemplateConfig();
}
/**
@@ -608,7 +713,17 @@ class TextAndGraphicUpdateOperation extends Task {
* @return true if title should be updated, false if not
*/
private boolean shouldUpdateTitleField() {
- return templateSupportsTextField(TextFieldName.templateTitle);
+ // If the template is updating, we don't yet know it's capabilities. Just assume the template supports the template title text field.
+ return templateSupportsTextField(TextFieldName.templateTitle) || shouldUpdateTemplateConfig();
+ }
+
+ private Boolean shouldUpdateTemplateConfig() {
+ if(updatedState.getTemplateConfiguration() == null) {
+ return false;
+ } else if(currentScreenData.getTemplateConfiguration() == null) {
+ return true;
+ }
+ return !updatedState.getTemplateConfiguration().getStore().equals(currentScreenData.getTemplateConfiguration().getStore());
}
/**
@@ -620,11 +735,11 @@ class TextAndGraphicUpdateOperation extends Task {
return defaultMainWindowCapability == null || ManagerUtility.WindowCapabilityUtility.hasTextFieldOfName(defaultMainWindowCapability, name);
}
- Show getCurrentScreenData() {
+ TextAndGraphicState getCurrentScreenData() {
return currentScreenData;
}
- void setCurrentScreenData(Show currentScreenData) {
+ void setCurrentScreenData(TextAndGraphicState currentScreenData) {
this.currentScreenData = currentScreenData;
}
diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/TextsAndGraphicsState.java b/base/src/main/java/com/smartdevicelink/managers/screen/TextsAndGraphicsState.java
index 601c98832..5337dc1e1 100644
--- a/base/src/main/java/com/smartdevicelink/managers/screen/TextsAndGraphicsState.java
+++ b/base/src/main/java/com/smartdevicelink/managers/screen/TextsAndGraphicsState.java
@@ -1,19 +1,24 @@
package com.smartdevicelink.managers.screen;
import com.smartdevicelink.managers.file.filetypes.SdlArtwork;
+import com.smartdevicelink.proxy.rpc.TemplateConfiguration;
import com.smartdevicelink.proxy.rpc.enums.MetadataType;
import com.smartdevicelink.proxy.rpc.enums.TextAlignment;
-class TextsAndGraphicsState {
+class TextAndGraphicState {
private String textField1, textField2, textField3, textField4, mediaTrackTextField, title;
private MetadataType textField1Type, textField2Type, textField3Type, textField4Type;
- private final TextAlignment textAlignment;
- private final SdlArtwork primaryGraphic;
- private final SdlArtwork secondaryGraphic;
+ private TextAlignment textAlignment;
+ private SdlArtwork primaryGraphic, secondaryGraphic;
+ private TemplateConfiguration templateConfiguration;
- TextsAndGraphicsState(String textField1, String textField2, String textField3, String textField4, String mediaTrackTextField,
- String title, SdlArtwork primaryGraphic, SdlArtwork secondaryGraphic, TextAlignment textAlignment,
- MetadataType textField1Type, MetadataType textField2Type, MetadataType textField3Type, MetadataType textField4Type) {
+ TextAndGraphicState() {
+ }
+
+ TextAndGraphicState(String textField1, String textField2, String textField3, String textField4, String mediaTrackTextField,
+ String title, SdlArtwork primaryGraphic, SdlArtwork secondaryGraphic, TextAlignment textAlignment,
+ MetadataType textField1Type, MetadataType textField2Type, MetadataType textField3Type, MetadataType textField4Type,
+ TemplateConfiguration templateConfiguration) {
this.textField1 = textField1;
this.textField2 = textField2;
this.textField3 = textField3;
@@ -27,6 +32,7 @@ class TextsAndGraphicsState {
this.textField2Type = textField2Type;
this.textField3Type = textField3Type;
this.textField4Type = textField4Type;
+ this.templateConfiguration = templateConfiguration;
}
String getTextField1() {
@@ -113,11 +119,31 @@ class TextsAndGraphicsState {
return textAlignment;
}
+ void setTextAlignment(TextAlignment textAlignment) {
+ this.textAlignment = textAlignment;
+ }
+
SdlArtwork getPrimaryGraphic() {
return primaryGraphic;
}
+ void setPrimaryGraphic(SdlArtwork primaryGraphic) {
+ this.primaryGraphic = primaryGraphic;
+ }
+
SdlArtwork getSecondaryGraphic() {
return secondaryGraphic;
}
+
+ void setSecondaryGraphic(SdlArtwork secondaryGraphic) {
+ this.secondaryGraphic = secondaryGraphic;
+ }
+
+ TemplateConfiguration getTemplateConfiguration() {
+ return templateConfiguration;
+ }
+
+ void setTemplateConfiguration(TemplateConfiguration templateConfiguration) {
+ this.templateConfiguration = templateConfiguration;
+ }
}