Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fc5c9968 authored by Vincent Bourgmayer's avatar Vincent Bourgmayer
Browse files

remove enableADB controller, and add a basic mechanism to display URL in instruction

parent 00abe678
Loading
Loading
Loading
Loading
+0 −148
Original line number Diff line number Diff line
/*
 * Copyright 2019-2021 - ECORP SAS 

 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */
package ecorp.easy.installer.controllers.subcontrollers;

import ecorp.easy.installer.utils.UiUtils;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.control.ContentDisplay;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.VBox;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * FXML Controller class
 *
 * @author Vincent
 */
public class EnableADBController extends AbstractSubSteppedController  {
    private final static Logger logger = LoggerFactory.getLogger(EnableADBController.class);

    @FXML private VBox instructionsContainer;
    @FXML private ImageView enableADBImg;
    private int stepIndex;
    private int currentInstructionIndex;
    private int imgIndex;
    
    @Override
    public void initialize(URL location, ResourceBundle resources) {
        super.initialize(location, resources); //To change body of generated methods, choose Tools | Templates.
        stepIndex =0;
        imgIndex =1;
        currentInstructionIndex = 0;
        loadStepContent(instructionsContainer.getChildren());
        updateImage();
        emphasizeLabel((Label) instructionsContainer.getChildren().get(currentInstructionIndex));
    }
    
    /**
     * Update instruction's Image
     */
    private void updateImage(){
        this.enableADBImg.setImage(UiUtils.loadImage("enableADB"+imgIndex+".png"));
    }
    
    /**
     * create lbl instance
     * apply style, etc...
     * @param text the text's translation key
     * @param imageName The name of the image to add as icon for the label
     * @return Label object The label instance to add into the view
     */
    private Label createInstructionLabel(String text, String imageName){
        Label result = new Label(i18n.getString(text));
        result.setWrapText(true);
        result.getStyleClass().addAll("subtitle");
        result.setGraphic(new ImageView(UiUtils.loadImage(imageName)));
        result.setGraphicTextGap(18); //set spacing between icon and text
        result.setContentDisplay(ContentDisplay.LEFT); //set Icon to be displayed on left
        result.getStyleClass().add("leftInsets"); //set css class to don't cover icon with emphased background
        return result;
    }
    
    /**
     * Load the content to display
     * @param instructions 
     */
    private void loadStepContent(final ObservableList<Node> instructions){
        instructions.clear();
        
        switch(stepIndex){
            case 0: //enable dev mode
                instructions.add(0, createInstructionLabel("devMode_instr_settings", "icon-gear.png"));
                instructions.add(1, createInstructionLabel("devMode_instr_build","icon-wrench.png"));     
                instructions.add(2, createInstructionLabel("devMode_instr_tap7","icon-hand.png"));     
                break;
            case 1: //enable usb debugging
                parentController.setViewTitle("debugADB_mTitle");
                instructions.add(0, createInstructionLabel("debugADB_instr_settings", "icon-gear.png"));
                instructions.add(1, createInstructionLabel("debugADB_instr_search","icon-wrench.png"));     
                instructions.add(2, createInstructionLabel("debugADB_instr_androidDebug","icon-hand.png"));     
                break;
            case 2: //enable file transfer
                parentController.setViewTitle("enableMTP_mTitle");
                instructions.add(0, createInstructionLabel("enableMTP_instr_settings", "icon-gear.png"));
                instructions.add(1, createInstructionLabel("enableMTP_instr_scrollToUSBConfig", "icon-wrench.png"));     
                instructions.add(2, createInstructionLabel("enableMTP_instr_selectMTP", "icon-hand.png"));     
                break;
            case 3: //remove all G's account
                parentController.setViewTitle("removeAccounts_mTitle");
                instructions.add(0, createInstructionLabel("debugADB_instr_settings", "icon-gear.png"));
                instructions.add(1, createInstructionLabel("removeAccounts_instr_openAccounts", "icon-wrench.png"));
                instructions.add(2, createInstructionLabel("removeAccounts_instr_selectAccounts", "icon-hand.png"));
                break;
            default:
                break;
        }
    }
    
    @Override
    protected void onNextButtonClicked() {
        final ObservableList<Node> instructions = instructionsContainer.getChildren();
        
        deemphasizeLabel((Label) instructions.get(currentInstructionIndex));
        ++imgIndex;
       
        if(currentInstructionIndex == instructions.size()-1){
            currentInstructionIndex = 0;
                ++stepIndex;
                
                UiUtils.playFadeAnimation(instructionsContainer.getParent(), 
                e->{ //Load new content
                    loadStepContent(instructions); 
                    emphasizeLabel((Label) instructions.get(currentInstructionIndex));
                    updateImage();},
                e->{});
        }else{
            if(stepIndex == 3 && currentInstructionIndex == instructions.size()-2){ //at last step, move to device detection
                parentController.resetNextButtonEventHandler();
            }
            ++currentInstructionIndex; 
            // The two below lines can't be put at the end of the method
            // because of FadeAnimation below
            emphasizeLabel((Label) instructions.get(currentInstructionIndex));
            updateImage();
        }
    }
}
 No newline at end of file
+44 −2
Original line number Diff line number Diff line
@@ -5,6 +5,15 @@
 */
package ecorp.easy.installer.graphics;

import ecorp.easy.installer.AppConstants;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javafx.scene.Node;
import javafx.scene.control.Hyperlink;
import javafx.scene.control.Label;
import javafx.scene.text.Text;
import javafx.scene.text.TextFlow;

@@ -13,7 +22,10 @@ import javafx.scene.text.TextFlow;
 * @author vincent
 */
public class Instruction extends TextFlow{
    private final String HIGHLIGHTED_CSS = "currentSubStep";
    private final static String URL_REGEX = "((https?):((//)|(\\\\))+[\\w\\d:#@%/;$()~_?\\+-=\\\\\\.&]*)";
    private final static Pattern URL_PATTERN = Pattern.compile(URL_REGEX, Pattern.CASE_INSENSITIVE);
    private final static String HIGHLIGHTED_CSS = "currentSubStep";
    
    private final String text;
    private final String key;//used for picture
    private boolean emphasized;
@@ -61,6 +73,36 @@ public class Instruction extends TextFlow{
    
    private void formatText(){
        //apply basic css, etc..
        getChildren().add(new Text(text));
        //If text contains url, extract it and create url object
        List<String> urls = extractUrls(text);
        if(urls.size() > 0){
            HashMap<Integer, Node> nodesWithUrl = new HashMap<>();
        
            for(String url : urls){
                nodesWithUrl.put(text.indexOf(url), new Hyperlink(url));
            }
            
            for(String noUrl : URL_PATTERN.split(text)){
                nodesWithUrl.put(text.indexOf(noUrl), new Label(noUrl));
            }
            getChildren().addAll(nodesWithUrl.values());
        }else{
            getChildren().add(new Label(text));
        }
    }
    
    private List<String> extractUrls(String text)
    {
        List<String> containedUrls = new ArrayList<String>();
        Matcher urlMatcher = URL_PATTERN.matcher(text);

        while (urlMatcher.find())
        {
            containedUrls.add(text.substring(urlMatcher.start(0),
                    urlMatcher.end(0)));
        }

        return containedUrls;
    }
    
}
+3 −1
Original line number Diff line number Diff line
@@ -290,3 +290,5 @@ stepTitle_enableOemUnlock= Enable OEM unlocking
stepTitle_beforeInstallation= Before installation
stepTitle_rebootDevice= Reboot device
stepTitle_rebootBootloader = "Rebooting in bootloader mode"

testWithUrl = Open http://e.foundation and close
 No newline at end of file
+1 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ steps:
        title: devMode_mTitle
        titleIcon: icon-hand.png
        instructions:
            - testWithUrl
            - devMode_instr_settings
            - devMode_instr_build
            - devMode_instr_tap7