Search in sources :

Example 1 with Result

use of com.android.tools.idea.ui.validation.Validator.Result in project android by JetBrains.

the class ConfigureDeviceOptionsStep method attachBindingsAndValidators.

private void attachBindingsAndValidators() {
    final AvdDeviceData deviceModel = getModel().getDeviceData();
    myBindings.bindTwoWay(new TextProperty(myDeviceName), deviceModel.name());
    myBindings.bind(deviceModel.diagonalScreenSize(), myDiagScreenSizeAdapter);
    myBindings.bind(deviceModel.screenResolutionWidth(), myScreenResWidthAdapter);
    myBindings.bind(deviceModel.screenResolutionHeight(), myScreenResHeightAdapter);
    myBindings.bindTwoWay(myRamField.storage(), deviceModel.ramStorage());
    myBindings.bindTwoWay(new SelectedProperty(myHasHardwareButtons), deviceModel.hasHardwareButtons());
    myBindings.bindTwoWay(new SelectedProperty(myHasHardwareKeyboard), deviceModel.hasHardwareKeyboard());
    myBindings.bindTwoWay(new SelectedItemProperty<>(myNavigationControlsCombo), deviceModel.navigation());
    myBindings.bindTwoWay(new SelectedProperty(myIsScreenRound), deviceModel.isScreenRound());
    myBindings.bindTwoWay(new SelectedProperty(mySupportsLandscape), deviceModel.supportsLandscape());
    myBindings.bindTwoWay(new SelectedProperty(mySupportsPortrait), deviceModel.supportsPortrait());
    myBindings.bindTwoWay(new SelectedProperty(myHasBackFacingCamera), deviceModel.hasBackCamera());
    myBindings.bindTwoWay(new SelectedProperty(myHasFrontFacingCamera), deviceModel.hasFrontCamera());
    myBindings.bindTwoWay(new SelectedProperty(myHasAccelerometer), deviceModel.hasAccelerometer());
    myBindings.bindTwoWay(new SelectedProperty(myHasGyroscope), deviceModel.hasGyroscope());
    myBindings.bindTwoWay(new SelectedProperty(myHasGps), deviceModel.hasGps());
    myBindings.bindTwoWay(new SelectedProperty(myHasProximitySensor), deviceModel.hasProximitySensor());
    myBindings.bindTwoWay(new SelectedItemProperty<>(myCustomSkinPath.getComboBox()), deviceModel.customSkinFile());
    SelectedItemProperty<IdDisplay> selectedDeviceType = new SelectedItemProperty<>(myDeviceTypeComboBox);
    myBindings.bindTwoWay(selectedDeviceType, deviceModel.deviceType());
    myListeners.receive(selectedDeviceType, idDisplayOptional -> {
        if (idDisplayOptional.isPresent()) {
            IdDisplay selectedType = idDisplayOptional.get();
            getModel().getDeviceData().isWear().set(selectedType.equals(SystemImage.WEAR_TAG));
            getModel().getDeviceData().isTv().set(selectedType.equals(SystemImage.TV_TAG));
            myIsScreenRound.setEnabled(selectedType.equals(SystemImage.WEAR_TAG));
            myIsScreenRound.setSelected(getModel().getDeviceData().isScreenRound().get());
        }
    });
    myValidatorPanel.registerValidator(deviceModel.name().isEmpty().not(), "Please write a name for the new device.");
    myValidatorPanel.registerValidator(myDiagScreenSizeAdapter.inSync().and(deviceModel.diagonalScreenSize().isEqualTo(myDiagScreenSizeAdapter)), "Please enter a non-zero positive floating point value for the screen size.");
    myValidatorPanel.registerValidator(myScreenResWidthAdapter.inSync().and(deviceModel.screenResolutionWidth().isEqualTo(myScreenResWidthAdapter)), "Please enter a valid value for the screen width.");
    myValidatorPanel.registerValidator(myScreenResHeightAdapter.inSync().and(deviceModel.screenResolutionHeight().isEqualTo(myScreenResHeightAdapter)), "Please enter a valid value for the screen height.");
    myValidatorPanel.registerValidator(deviceModel.ramStorage(), value -> (value.getSize() > 0) ? Result.OK : new Result(Validator.Severity.ERROR, "Please specify a non-zero amount of RAM."));
    myValidatorPanel.registerValidator(deviceModel.screenDpi().isGreaterThan(0), "The given resolution and screen size specified have a DPI that is too low.");
    myValidatorPanel.registerValidator(deviceModel.supportsLandscape().or(deviceModel.supportsPortrait()), "A device must support at least one orientation (Portrait or Landscape).");
    myValidatorPanel.registerValidator(deviceModel.customSkinFile(), value -> {
        File skinPath = value.orElse(null);
        if (skinPath != null && !FileUtil.filesEqual(skinPath, AvdWizardUtils.NO_SKIN) && !skinPath.getPath().equals(skinPath.getName())) {
            File layoutFile = new File(skinPath, SdkConstants.FN_SKIN_LAYOUT);
            if (!layoutFile.isFile()) {
                return new Result(Validator.Severity.ERROR, "The skin directory does not point to a valid skin.");
            }
        }
        return Result.OK;
    });
    myValidatorPanel.registerValidator(getModel().getDeviceData().compatibleSkinSize(), Validator.Severity.WARNING, "The selected skin is not large enough to view the entire screen.");
}
Also used : SelectedItemProperty(com.android.tools.idea.ui.properties.swing.SelectedItemProperty) IdDisplay(com.android.sdklib.repository.IdDisplay) File(java.io.File) TextProperty(com.android.tools.idea.ui.properties.swing.TextProperty) SelectedProperty(com.android.tools.idea.ui.properties.swing.SelectedProperty) Result(com.android.tools.idea.ui.validation.Validator.Result)

Aggregations

IdDisplay (com.android.sdklib.repository.IdDisplay)1 SelectedItemProperty (com.android.tools.idea.ui.properties.swing.SelectedItemProperty)1 SelectedProperty (com.android.tools.idea.ui.properties.swing.SelectedProperty)1 TextProperty (com.android.tools.idea.ui.properties.swing.TextProperty)1 Result (com.android.tools.idea.ui.validation.Validator.Result)1 File (java.io.File)1