summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Kast <julian@livio.com>2020-08-21 16:08:35 -0400
committerJulian Kast <julian@livio.com>2020-08-21 16:08:35 -0400
commitbe7157d524736b19fb9277c5cad3dc0e9bec3935 (patch)
tree3e6599da5a2247b556d3d7375818c335e5d47ede
parent43f81dff43becf0bf6b37f2bbd78736ea189d194 (diff)
downloadsdl_android-be7157d524736b19fb9277c5cad3dc0e9bec3935.tar.gz
IOS alignment
-rw-r--r--base/src/main/java/com/smartdevicelink/managers/screen/BaseTextAndGraphicManager.java109
-rw-r--r--base/src/main/java/com/smartdevicelink/managers/screen/TextAndGraphicUpdateOperation.java19
-rw-r--r--base/src/main/java/com/smartdevicelink/managers/screen/TextsAndGraphicsState.java14
3 files changed, 83 insertions, 59 deletions
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 437aecb06..b8190edaa 100644
--- a/base/src/main/java/com/smartdevicelink/managers/screen/BaseTextAndGraphicManager.java
+++ b/base/src/main/java/com/smartdevicelink/managers/screen/BaseTextAndGraphicManager.java
@@ -34,6 +34,7 @@ package com.smartdevicelink.managers.screen;
import androidx.annotation.NonNull;
import com.livio.taskmaster.Queue;
+import com.livio.taskmaster.Task;
import com.smartdevicelink.managers.BaseSubManager;
import com.smartdevicelink.managers.CompletionListener;
import com.smartdevicelink.managers.file.FileManager;
@@ -56,6 +57,7 @@ import com.smartdevicelink.proxy.rpc.listeners.OnRPCNotificationListener;
import com.smartdevicelink.util.DebugTool;
import java.lang.ref.WeakReference;
+import java.util.ArrayList;
import java.util.List;
import static com.smartdevicelink.proxy.rpc.enums.TextAlignment.CENTERED;
@@ -73,9 +75,8 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
Show currentScreenData;
HMILevel currentHMILevel;
WindowCapability defaultMainWindowCapability;
- private boolean pendingHMIFull, batchingUpdates;
+ private boolean batchingUpdates;
private final WeakReference<FileManager> fileManager;
- private CompletionListener pendingHMIListener;
SdlArtwork blankArtwork;
private OnRPCNotificationListener hmiListener;
private OnSystemCapabilityListener onDisplaysCapabilityListener;
@@ -84,12 +85,8 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
private String textField1, textField2, textField3, textField4, mediaTrackTextField, title;
private MetadataType textField1Type, textField2Type, textField3Type, textField4Type;
private TextAndGraphicUpdateOperation updateOperation;
-
-
private Queue transactionQueue;
- private TextsAndGraphicsState textsAndGraphicsState;
-
//Constructors
BaseTextAndGraphicManager(@NonNull ISdl internalInterface, @NonNull FileManager fileManager) {
@@ -98,7 +95,6 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
this.fileManager = new WeakReference<>(fileManager);
batchingUpdates = false;
isDirty = false;
- pendingHMIFull = false;
textAlignment = CENTERED;
currentHMILevel = HMILevel.HMI_NONE;
currentScreenData = new Show();
@@ -130,9 +126,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
blankArtwork = null;
defaultMainWindowCapability = null;
currentScreenData = null;
- pendingHMIListener = null;
isDirty = false;
- pendingHMIFull = false;
updateOperation = null;
// Cancel the operations
@@ -169,22 +163,10 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
// Upload / Send
protected void update(CompletionListener listener) {
-
// check if is batch update
if (batchingUpdates) {
return;
}
-
- // make sure hmi is not none
- if (currentHMILevel == null || currentHMILevel == HMILevel.HMI_NONE) {
- //Trying to send show on HMI_NONE, waiting for full
- pendingHMIFull = true;
- if (listener != null) {
- pendingHMIListener = listener;
- }
- return;
- }
-
if (isDirty) {
isDirty = false;
sdlUpdate(listener);
@@ -194,7 +176,6 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
}
private synchronized void sdlUpdate(final CompletionListener listener) {
-
if (transactionQueue.getTasksAsList().size() > 0) {
//Transactions already exist, cancelling them
transactionQueue.clear();
@@ -203,20 +184,76 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
}
return;
}
- updateOperation = new TextAndGraphicUpdateOperation(internalInterface, fileManager.get(), defaultMainWindowCapability, currentScreenData, currentState(), new CompletionListener() {
+ CurrentScreenDataUpdatedListener currentScreenDataUpdateListener = new CurrentScreenDataUpdatedListener() {
+ @Override
+ public void onUpdate(Show show) {
+ updatePendingOperationsWithNewScreenData(show);
+ }
+ };
+ CompletionListener updateOperationListener = new CompletionListener() {
@Override
public void onComplete(boolean success) {
-
- if (updateOperation.getSentShow() != null) {
- currentScreenData = updateOperation.getSentShow();
- }
if (listener != null) {
listener.onComplete(success);
}
}
- });
+ };
+
+ updateOperation = new TextAndGraphicUpdateOperation(internalInterface, fileManager.get(), defaultMainWindowCapability, currentScreenData, currentState(), updateOperationListener, currentScreenDataUpdateListener);
transactionQueue.add(updateOperation, false);
}
+ //Updates pending task with current screen data
+ void updatePendingOperationsWithNewScreenData(Show newScreenData){
+ for(Task task: transactionQueue.getTasksAsList()){
+ if(!(task instanceof TextAndGraphicUpdateOperation) || task.getState() == Task.IN_PROGRESS){
+ continue;
+ }
+ ((TextAndGraphicUpdateOperation) task).setCurrentScreenData(newScreenData);
+ }
+ }
+
+ interface CurrentScreenDataUpdatedListener{
+ void onUpdate(Show show);
+ }
+
+
+ private List<String> findNonNullTextFields() {
+ List<String> array = new ArrayList<>();
+
+ if (textField1 != null) {
+ array.add(textField1);
+ }
+
+ if (textField2 != null) {
+ array.add(textField2);
+ }
+
+ if (textField3 != null) {
+ array.add(textField3);
+ }
+
+ if (textField4 != null) {
+ array.add(textField4);
+ }
+
+ if(title != null){
+ array.add(title);
+ }
+
+ if(mediaTrackTextField != null){
+ array.add(mediaTrackTextField);
+ }
+
+ return array;
+ }
+
+ Boolean hasData() {
+ boolean hasTextFields = (findNonNullTextFields().size() > 0);
+ boolean hasImageFields = (primaryGraphic != null) || (secondaryGraphic != null);
+
+ return hasTextFields || hasImageFields;
+ }
+
// Convert to State
@@ -410,22 +447,12 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
if (onHMIStatus.getWindowID() != null && onHMIStatus.getWindowID() != PredefinedWindows.DEFAULT_WINDOW.getValue()) {
return;
}
-
currentHMILevel = onHMIStatus.getHmiLevel();
updateTransactionQueueSuspended();
- if (currentHMILevel == HMILevel.HMI_FULL) {
- if (pendingHMIFull) {
- DebugTool.logInfo(TAG, "Acquired HMI_FULL with pending update. Sending now");
- pendingHMIFull = false;
- sdlUpdate(pendingHMIListener);
- pendingHMIListener = null;
- }
- }
}
};
internalInterface.addOnRPCNotificationListener(FunctionID.ON_HMI_STATUS, hmiListener);
-
onDisplaysCapabilityListener = new OnSystemCapabilityListener() {
@Override
public void onCapabilityRetrieved(Object capability) {
@@ -442,12 +469,18 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
}
}
}
+ // Update the queue's suspend state
+ updateTransactionQueueSuspended();
+ if (hasData()) {
+ update(null);
+ }
}
@Override
public void onError(String info) {
DebugTool.logError(TAG, "Display Capability cannot be retrieved");
defaultMainWindowCapability = null;
+ updateTransactionQueueSuspended();
}
};
this.internalInterface.addOnSystemCapabilityListener(SystemCapabilityType.DISPLAYS, onDisplaysCapabilityListener);
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 4028b1a44..f6e79391f 100644
--- a/base/src/main/java/com/smartdevicelink/managers/screen/TextAndGraphicUpdateOperation.java
+++ b/base/src/main/java/com/smartdevicelink/managers/screen/TextAndGraphicUpdateOperation.java
@@ -33,6 +33,7 @@ public class TextAndGraphicUpdateOperation extends Task {
private Show currentScreenData, sentShow;
private TextsAndGraphicsState updatedState;
private CompletionListener listener;
+ private TextAndGraphicManager.CurrentScreenDataUpdatedListener currentScreenDataUpdateListener;
/**
@@ -44,7 +45,7 @@ public class TextAndGraphicUpdateOperation extends Task {
* @param listener
*/
public TextAndGraphicUpdateOperation(ISdl internalInterface, FileManager fileManager, WindowCapability currentCapabilities,
- Show currentScreenData, TextsAndGraphicsState newState, CompletionListener listener) {
+ Show currentScreenData, TextsAndGraphicsState newState, CompletionListener listener, TextAndGraphicManager.CurrentScreenDataUpdatedListener currentScreenDataUpdateListener) {
super("TextAndGraphicUpdateOperation");
this.internalInterface = new WeakReference<>(internalInterface);
this.fileManager = new WeakReference<>(fileManager);
@@ -52,6 +53,7 @@ public class TextAndGraphicUpdateOperation extends Task {
this.currentScreenData = currentScreenData;
this.updatedState = newState;
this.listener = listener;
+ this.currentScreenDataUpdateListener = currentScreenDataUpdateListener;
}
@Override
@@ -68,6 +70,8 @@ public class TextAndGraphicUpdateOperation extends Task {
// Build a show with everything from `self.newState`, we'll pull things out later if we can.
Show fullShow = new Show();
fullShow.setAlignment(updatedState.getTextAlignment());
+ //TODO IOS ask about tages, Dont they just get set when we assembleShowText
+ // fullShow.setMetadataTags(updatedState.getM);
fullShow = assembleShowText(fullShow);
fullShow = assembleShowImages(fullShow);
@@ -78,7 +82,6 @@ public class TextAndGraphicUpdateOperation extends Task {
@Override
public void onComplete(boolean success) {
finishOperation(success);
- return;
}
});
@@ -89,7 +92,6 @@ public class TextAndGraphicUpdateOperation extends Task {
@Override
public void onComplete(boolean success) {
finishOperation(success);
- return;
}
});
} else {
@@ -106,7 +108,6 @@ public class TextAndGraphicUpdateOperation extends Task {
@Override
public void onComplete(boolean success) {
finishOperation(success);
- return;
}
});
@@ -131,7 +132,7 @@ public class TextAndGraphicUpdateOperation extends Task {
private void handleResponse(boolean success) {
DebugTool.logInfo(TAG, "Text and Graphic update completed");
if (success) {
- updateCurrentScreenDataState(show);
+ updateCurrentScreenDataFromShow(show);
}
listener.onComplete(success);
}
@@ -145,9 +146,9 @@ public class TextAndGraphicUpdateOperation extends Task {
@Override
public void onComplete(boolean success) {
Show showWithGraphics = createImageOnlyShowWithPrimaryArtwork(updatedState.getPrimaryGraphic(), updatedState.getSecondaryGraphic());
+ //TODO Ask about logic here, Should we do if(success) then create and sendShow with Graphic or return false
if (showWithGraphics != null) {
DebugTool.logInfo(TAG, "Sending update with the successfully uploaded images");
- //Check for cancel
sendShow(showWithGraphics, new CompletionListener() {
@Override
public void onComplete(boolean success) {
@@ -483,7 +484,8 @@ public class TextAndGraphicUpdateOperation extends Task {
return newShow;
}
- private void updateCurrentScreenDataState(Show show) {
+ //TODO IOS different by maybe same
+ private void updateCurrentScreenDataFromShow(Show show) {
if (show == null) {
DebugTool.logError(TAG, "can not updateCurrentScreenDataFromShow from null show");
@@ -521,6 +523,9 @@ public class TextAndGraphicUpdateOperation extends Task {
if (show.getSecondaryGraphic() != null) {
currentScreenData.setSecondaryGraphic(show.getSecondaryGraphic());
}
+ if (currentScreenDataUpdateListener != null) {
+ currentScreenDataUpdateListener.onUpdate(show);
+ }
}
// Helpers
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 55f572905..ce0d473cc 100644
--- a/base/src/main/java/com/smartdevicelink/managers/screen/TextsAndGraphicsState.java
+++ b/base/src/main/java/com/smartdevicelink/managers/screen/TextsAndGraphicsState.java
@@ -12,8 +12,6 @@ public class TextsAndGraphicsState {
private TextAlignment textAlignment;
private SdlArtwork primaryGraphic, secondaryGraphic;
- public TextsAndGraphicsState(){}
-
public 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) {
@@ -116,23 +114,11 @@ public class TextsAndGraphicsState {
return textAlignment;
}
- public void setTextAlignment(TextAlignment textAlignment) {
- this.textAlignment = textAlignment;
- }
-
public SdlArtwork getPrimaryGraphic() {
return primaryGraphic;
}
- public void setPrimaryGraphic(SdlArtwork primaryGraphic) {
- this.primaryGraphic = primaryGraphic;
- }
-
public SdlArtwork getSecondaryGraphic() {
return secondaryGraphic;
}
-
- public void setSecondaryGraphic(SdlArtwork secondaryGraphic) {
- this.secondaryGraphic = secondaryGraphic;
- }
}