From 5073783b01f3dd44d0be7edb4858018026524271 Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Sat, 19 Dec 2020 21:40:00 +0100 Subject: [PATCH 01/26] update MainWindowController to integrate FadeIn/FadeOut animation when changing view --- .../controllers/MainWindowController.java | 100 +++++++++++------- .../subcontrollers/FlashSceneController.java | 15 ++- 2 files changed, 71 insertions(+), 44 deletions(-) diff --git a/src/main/java/ecorp/easy/installer/controllers/MainWindowController.java b/src/main/java/ecorp/easy/installer/controllers/MainWindowController.java index e068bd84..fd15faf8 100644 --- a/src/main/java/ecorp/easy/installer/controllers/MainWindowController.java +++ b/src/main/java/ecorp/easy/installer/controllers/MainWindowController.java @@ -25,6 +25,7 @@ import ecorp.easy.installer.threads.ThreadFactory; import java.io.IOException; import java.net.URL; import java.util.ResourceBundle; +import javafx.animation.FadeTransition; import javafx.fxml.Initializable; import javafx.application.Platform; @@ -36,9 +37,11 @@ import javafx.scene.control.Label; import javafx.scene.input.MouseEvent; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; +import javafx.scene.Node; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.Pane; import javafx.scene.control.Button; +import javafx.util.Duration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** @@ -159,56 +162,44 @@ public class MainWindowController implements Initializable { logger.info("loadSubScene("+currentSubRootId+")"); if(currentSubRootId == null || currentSubRootId.isEmpty()){ - currentSubRootId =loadSubUI("1-beforeYouBegin.fxml"); - titleLabel.setText(i18n.getString("before_mTitle")); + currentSubRootId =loadSubUI("1-beforeYouBegin.fxml", "before_mTitle"); }else{ switch(currentSubRootId){ case "beforeYouBeginRoot": - removeNodeFromRoot(currentSubRootId); - currentSubRootId = loadSubUI("2-connectDevice.fxml"); - this.titleLabel.setText(i18n.getString("connect_mTitle")); + changeView(currentSubRootId, "2-connectDevice.fxml", "connect_mTitle"); break; case "connectDeviceRoot": - removeNodeFromRoot(currentSubRootId); - currentSubRootId = loadSubUI("3-enableADB.fxml"); - this.titleLabel.setText(i18n.getString("devMode_mTitle")); + changeView(currentSubRootId, "3-enableADB.fxml", "devMode_mTitle"); break; case "enableDevMode": - removeNodeFromRoot(currentSubRootId); - currentSubRootId = loadSubUI("4-deviceDetected.fxml"); - this.titleLabel.setText(i18n.getString("detect_mTitle")); + changeView(currentSubRootId, "4-deviceDetected.fxml", "detect_mTitle"); disableNextButton(true); break; case "deviceDetectedRoot": - removeNodeFromRoot(currentSubRootId); - currentSubRootId = loadSubUI("5-downloadSrc.fxml"); - this.titleLabel.setText(i18n.getString("download_mTitle")); + changeView(currentSubRootId, "5-downloadSrc.fxml", "download_mTitle"); disableNextButton(true); break; case "downloadSceneRoot": - removeNodeFromRoot(currentSubRootId); - currentSubRootId = loadSubUI("6-flashScene.fxml"); - this.titleLabel.setText(i18n.getString("installationTitle")); + changeView(currentSubRootId, "6-flashScene.fxml", "installationTitle"); break; case "flashSceneRoot": - removeNodeFromRoot(currentSubRootId); - currentSubRootId= loadSubUI("7-flashResult.fxml"); + changeView(currentSubRootId, "7-flashResult.fxml", "installationTitle"); break; case "flashResultRoot": - removeNodeFromRoot(currentSubRootId); + final String fxmlFileName; + final String nextViewTitle; if( isFlashed ){ - currentSubRootId=loadSubUI("8-congrats.fxml"); - this.titleLabel.setText(i18n.getString("congrats_mTitle")); + fxmlFileName = "8-congrats.fxml"; + nextViewTitle ="congrats_mTitle"; } else{ - currentSubRootId=loadSubUI("9-feedback.fxml"); - this.titleLabel.setText(i18n.getString("feedback_mTitle")); + fxmlFileName = "9-feedback.fxml"; + nextViewTitle ="feedback_mTitle"; } + changeView(currentSubRootId, fxmlFileName, nextViewTitle); break; case "congratsRoot": - removeNodeFromRoot(currentSubRootId); - currentSubRootId=loadSubUI("9-feedback.fxml"); - this.titleLabel.setText(i18n.getString("feedback_mTitle")); + changeView(currentSubRootId, "9-feedback.fxml", "feedback_mTitle"); break; case "feedbackRoot": Platform.exit(); @@ -221,9 +212,7 @@ public class MainWindowController implements Initializable { } public void retryToFlash(){ - removeNodeFromRoot(currentSubRootId); - currentSubRootId = loadSubUI("6-flashScene.fxml"); - this.titleLabel.setText(i18n.getString("installationTitle")); + changeView(currentSubRootId, "6-flashScene.fxml", "installationTitle"); } /** @@ -236,14 +225,43 @@ public class MainWindowController implements Initializable { } + /** - * Remove a node from the root - * @param nodeId fx:id of the node - * @return true if element removed + * Used to remove currentView's root node from scene + * Required for return to flashScene after accountUI view + * @param rootId */ - public boolean removeNodeFromRoot(String nodeId){ - return root.getChildren().removeIf( n -> n.getId().equals(nodeId)); + public void removeNodeFromRoot(final String rootId) { + root.getChildren().removeIf( n -> n.getId().equals(rootId)); } + + /** + * Close previous view after a fadeOut, and open new view + * @param previousNodeId + * @param fxmlName + * @param viewTitle + */ + public void changeView(final String previousNodeId, final String fxmlName, final String viewTitle){ + Node elementNode = null; + for(Node node : root.getChildren() ){ + if( node.getId().equals(previousNodeId) ){ + elementNode = node; + break; + } + } + if(elementNode == null) return ; + + FadeTransition fadeOutTransition = new FadeTransition(Duration.millis(500), elementNode); + fadeOutTransition.setFromValue(1.0); + fadeOutTransition.setToValue(0.0); + + fadeOutTransition.setOnFinished(e -> { + removeNodeFromRoot(previousNodeId); + currentSubRootId= loadSubUI(fxmlName, viewTitle); + }); + fadeOutTransition.play(); + } + /** * Load UI from FXML file @@ -267,12 +285,21 @@ public class MainWindowController implements Initializable { /** * Load the subScene from FXML and return the controller * @param fxmlName fxml file name + * @param viewTitle the title for the new View * @return subRoot. */ - public String loadSubUI(String fxmlName){ + public String loadSubUI(final String fxmlName, final String viewTitle){ + titleLabel.setText(i18n.getString(viewTitle)); FXMLLoader loader = loadFXML(fxmlName); Pane subRoot = (Pane) loader.getRoot(); root.getChildren().add(0, subRoot); //adding this element as first subNode, let other element like button to still be clickable on small screen + subRoot.setOpacity(0.0); + FadeTransition fadeInTransition = new FadeTransition(Duration.millis(500), subRoot); + fadeInTransition.setFromValue(0.0); + fadeInTransition.setToValue(1.0); + fadeInTransition.play(); + + return subRoot.getId(); } @@ -339,4 +366,5 @@ public class MainWindowController implements Initializable { public Device getDevice() { return device; } + } diff --git a/src/main/java/ecorp/easy/installer/controllers/subcontrollers/FlashSceneController.java b/src/main/java/ecorp/easy/installer/controllers/subcontrollers/FlashSceneController.java index 5bc16ab2..797a0e29 100644 --- a/src/main/java/ecorp/easy/installer/controllers/subcontrollers/FlashSceneController.java +++ b/src/main/java/ecorp/easy/installer/controllers/subcontrollers/FlashSceneController.java @@ -189,10 +189,7 @@ public class FlashSceneController extends AbstractSubSteppedController implement } //Update instruction title - String title = db.getString("stepTitle"); - if(title != null){ - stepTitleLabel.setText(i18n.getString(title)); - } + final String title = db.getString("stepTitle"); //Get Type of step ("action" or "load") switch(db.getString("stepType")){ @@ -203,10 +200,10 @@ public class FlashSceneController extends AbstractSubSteppedController implement onLoadStepType(db); break; case AppConstants.ASK_ACCOUNT_KEY: - displaySpecificView("6-2-eAccount.fxml"); + displaySpecificView("6-2-eAccount.fxml", title); break; case AppConstants.UNLOCK_OEM_KEY: - displaySpecificView("6-3-unlockOEM.fxml"); + displaySpecificView("6-3-unlockOEM.fxml", title); break; default: logger.warn("Try to load invalid step's type"); @@ -220,13 +217,15 @@ public class FlashSceneController extends AbstractSubSteppedController implement * Note: This could be replace by a call to parentController.loadSubUI("6-2-eAccount.fxml") * but how to reset current ui to this one after ? */ - private void displaySpecificView(String fxmlName){ + private void displaySpecificView(final String fxmlName, final String viewTitle){ //Masque previous UI //@TODO it's better to apply to each children flashSceneRoot.setVisible(false); flashSceneRoot.setManaged(false); //Affiche the new One - final String tempRootId = parentController.loadSubUI(fxmlName); + + + final String tempRootId = parentController.loadSubUI(fxmlName, viewTitle); parentController.setNextButtonOnClickListener(( MouseEvent event) -> { parentController.resetNextButtonEventHandler(); parentController.removeNodeFromRoot(tempRootId); -- GitLab From 49b9fd961c06e1ff6c50b555476b08a556b6a6df Mon Sep 17 00:00:00 2001 From: vincent Bourgmayer Date: Tue, 22 Dec 2020 19:54:45 +0100 Subject: [PATCH 02/26] try to set fade in/out transition for enableADB views --- .../subcontrollers/EnableADBController.java | 29 ++++++++++++++++++- src/main/resources/fxml/3-enableADB.fxml | 4 +-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/main/java/ecorp/easy/installer/controllers/subcontrollers/EnableADBController.java b/src/main/java/ecorp/easy/installer/controllers/subcontrollers/EnableADBController.java index 44aab4a8..96e12cf4 100644 --- a/src/main/java/ecorp/easy/installer/controllers/subcontrollers/EnableADBController.java +++ b/src/main/java/ecorp/easy/installer/controllers/subcontrollers/EnableADBController.java @@ -19,10 +19,15 @@ package ecorp.easy.installer.controllers.subcontrollers; import java.net.URL; import java.util.ArrayList; import java.util.ResourceBundle; +import javafx.animation.FadeTransition; +import javafx.event.ActionEvent; +import javafx.event.EventHandler; import javafx.fxml.FXML; import javafx.scene.control.Label; import javafx.scene.image.Image; import javafx.scene.image.ImageView; +import javafx.scene.layout.HBox; +import javafx.util.Duration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -37,7 +42,7 @@ public class EnableADBController extends AbstractSubSteppedController { @FXML private Label firstSubStep; @FXML private Label secondSubStep; @FXML private Label thirdSubStep; - + @FXML private HBox instructionsContainer; @FXML private ImageView enableADBImg; private ArrayList