use of com.android.tools.idea.ui.properties.expressions.optional.AsOptionalExpression in project android by JetBrains.
the class NewVectorAssetStep method onWizardStarting.
@Override
protected void onWizardStarting(@NotNull ModelWizard.Facade wizard) {
final Runnable onAssetModified = myPreviewUpdater::enqueueUpdate;
loadAssetPath();
SelectedProperty iconSelected = new SelectedProperty(myMaterialIconRadioButton);
myListeners.receiveAndFire(iconSelected, isIconActive -> {
myIconPickerPanel.setVisible(isIconActive);
myBrowserPanel.setVisible(!isIconActive);
myActiveAsset.set(isIconActive ? myIconButton.getAsset() : myBrowser.getAsset());
});
ActionListener assetListener = actionEvent -> {
onAssetModified.run();
saveAssetPath();
};
myIconButton.addAssetListener(assetListener);
myBrowser.addAssetListener(assetListener);
Disposer.register(this, myIconButton);
Disposer.register(this, myBrowser);
final BoolProperty overrideSize = new SelectedProperty(myOverrideSizeCheckBox);
final IntProperty width = new IntValueProperty();
final IntProperty height = new IntValueProperty();
myGeneralBindings.bindTwoWay(new StringToIntAdapterProperty(new TextProperty(myWidthTextField)), width);
myGeneralBindings.bindTwoWay(new StringToIntAdapterProperty(new TextProperty(myHeightTextField)), height);
myGeneralBindings.bind(new EnabledProperty(myWidthTextField), overrideSize);
myGeneralBindings.bind(new EnabledProperty(myHeightTextField), overrideSize);
myListeners.listenAll(overrideSize, myOriginalSize).withAndFire(() -> {
if (!overrideSize.get() || !myOriginalSize.get().isPresent()) {
width.set(DEFAULT_MATERIAL_ICON_SIZE);
height.set(DEFAULT_MATERIAL_ICON_SIZE);
} else {
width.set(myOriginalSize.getValue().width);
height.set(myOriginalSize.getValue().height);
}
});
final IntProperty opacityValue = new SliderValueProperty(myOpacitySlider);
myGeneralBindings.bind(new TextProperty(myOpacityValueLabel), new FormatExpression("%d %%", opacityValue));
final BoolProperty autoMirrored = new SelectedProperty(myEnableAutoMirroredCheckBox);
myListeners.listenAll(myActiveAsset, overrideSize, width, height, opacityValue, autoMirrored).with(onAssetModified);
final StringProperty name = new TextProperty(myOutputNameField);
myListeners.listenAndFire(myActiveAsset, sender -> {
myActiveAssetBindings.releaseAll();
myActiveAssetBindings.bind(name, new Expression<String>(myActiveAsset.get().path()) {
@NotNull
@Override
public String get() {
File path = myActiveAsset.get().path().get();
if (path.exists() && !path.isDirectory()) {
String name1 = FileUtil.getNameWithoutExtension(path).toLowerCase(Locale.getDefault());
if (!name1.startsWith(ICON_PREFIX)) {
name1 = ICON_PREFIX + AndroidResourceUtil.getValidResourceFileName(name1);
}
return AndroidResourceUtil.getValidResourceFileName(name1);
} else {
return "ic_vector_name";
}
}
});
myActiveAssetBindings.bind(myActiveAsset.get().opacity(), opacityValue);
myActiveAssetBindings.bind(myActiveAsset.get().autoMirrored(), autoMirrored);
myActiveAssetBindings.bind(myActiveAsset.get().outputWidth(), width);
myActiveAssetBindings.bind(myActiveAsset.get().outputHeight(), height);
});
// Refresh the asset preview, but fire using invokeLater, as this lets the UI lay itself out,
// which should happen before the "generate preview" logic runs.
ApplicationManager.getApplication().invokeLater(onAssetModified, ModalityState.any());
// Cast VectorAsset -> BaseAsset
myGeneralBindings.bind(myIconGenerator.sourceAsset(), new AsOptionalExpression<>(myActiveAsset));
myGeneralBindings.bind(myIconGenerator.name(), name);
}
Aggregations