use of com.android.tools.idea.wizard.dynamic.ScopedStateStore in project android by JetBrains.
the class AndroidVirtualDeviceTest method testCreateDevice.
public void testCreateDevice() throws Exception {
MockFileOp fop = new MockFileOp();
recordPlatform23(fop);
recordGoogleApisAddon23(fop);
recordGoogleApisSysImg23(fop);
fop.recordExistingFile(new File(DeviceArtDescriptor.getBundledDescriptorsFolder(), "nexus_5x"));
AndroidSdkHandler sdkHandler = new AndroidSdkHandler(new File("/sdk"), new File("/android-home"), fop);
final AvdManagerConnection connection = new AvdManagerConnection(sdkHandler);
FakePackage.FakeRemotePackage remotePlatform = new FakePackage.FakeRemotePackage("platforms;android-23");
RepoFactory factory = AndroidSdkHandler.getRepositoryModule().createLatestFactory();
DetailsTypes.PlatformDetailsType platformDetailsType = factory.createPlatformDetailsType();
platformDetailsType.setApiLevel(23);
remotePlatform.setTypeDetails((TypeDetails) platformDetailsType);
Map<String, RemotePackage> remotes = Maps.newHashMap();
remotes.put("platforms;android-23", remotePlatform);
AndroidVirtualDevice avd = new AndroidVirtualDevice(new ScopedStateStore(ScopedStateStore.Scope.STEP, null, null), remotes, true, fop);
final AvdInfo avdInfo = avd.createAvd(connection, sdkHandler);
assertNotNull(avdInfo);
disposeOnTearDown(() -> connection.deleteAvd(avdInfo));
assertNotNull(avdInfo);
Map<String, String> properties = avdInfo.getProperties();
Map<String, String> referenceMap = getReferenceMap();
for (Map.Entry<String, String> entry : referenceMap.entrySet()) {
assertEquals(entry.getKey(), entry.getValue(), FileUtil.toSystemIndependentName(properties.get(entry.getKey())));
}
// AVD manager will set some extra properties that we don't care about and that may be system dependant.
// We do not care about those so we only ensure we have the ones we need.
File skin = new File(properties.get(AvdManager.AVD_INI_SKIN_PATH));
assertEquals("nexus_5x", skin.getName());
}
use of com.android.tools.idea.wizard.dynamic.ScopedStateStore in project android by JetBrains.
the class NewFormFactorModulePathTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
myPath = new NewFormFactorModulePath(MOBILE, new File("/"), getTestRootDisposable());
ScopedStateStore wizardState = new ScopedStateStore(WIZARD, null, null);
myPath.setState(new ScopedStateStore(PATH, wizardState, null));
}
use of com.android.tools.idea.wizard.dynamic.ScopedStateStore in project android by JetBrains.
the class ConfigureAndroidProjectStepTest method packageNameDeriverSantizesCompanyDomainKey.
@Test
public void packageNameDeriverSantizesCompanyDomainKey() {
ScopedStateStore state = new ScopedStateStore(ScopedStateStore.Scope.WIZARD, null, null);
ScopedStateStore stepState = new ScopedStateStore(ScopedStateStore.Scope.STEP, state, null);
stepState.put(APPLICATION_NAME_KEY, "My&App");
stepState.put(COMPANY_DOMAIN_KEY, "sub.exa-mple.com");
assertEquals("com.exa_mple.sub.myapp", ConfigureAndroidProjectStep.PACKAGE_NAME_DERIVER.deriveValue(stepState, null, null));
stepState.put(COMPANY_DOMAIN_KEY, "#.badstartchar.com");
assertEquals("com.badstartchar.myapp", ConfigureAndroidProjectStep.PACKAGE_NAME_DERIVER.deriveValue(stepState, null, null));
stepState.put(COMPANY_DOMAIN_KEY, "TEST.ALLCAPS.COM");
assertEquals("com.allcaps.test.myapp", ConfigureAndroidProjectStep.PACKAGE_NAME_DERIVER.deriveValue(stepState, null, null));
}
use of com.android.tools.idea.wizard.dynamic.ScopedStateStore in project android by JetBrains.
the class ChooseModuleTypeStep method init.
@Override
public void init() {
super.init();
ImmutableList.Builder<ModuleTemplate> deviceTemplates = ImmutableList.builder();
ImmutableList.Builder<ModuleTemplate> extrasTemplates = ImmutableList.builder();
Set<FormFactor> formFactorSet = Sets.newHashSet();
// Android device templates are shown first, with less important templates following
for (ModuleTemplateProvider provider : myModuleTypesProviders) {
for (ModuleTemplate moduleTemplate : provider.getModuleTemplates()) {
FormFactor formFactor = moduleTemplate.getFormFactor();
if (formFactor != null) {
if (formFactor == FormFactor.GLASS && !AndroidSdkUtils.isGlassInstalled()) {
// Hidden if not installed
continue;
}
if (formFactor != FormFactor.CAR) {
// Auto is not a standalone module (but rather a modification to a mobile module):
deviceTemplates.add(moduleTemplate);
formFactorSet.add(formFactor);
}
} else {
extrasTemplates.add(moduleTemplate);
}
}
}
for (final FormFactor formFactor : formFactorSet) {
registerValueDeriver(FormFactorUtils.getInclusionKey(formFactor), new ValueDeriver<Boolean>() {
@Nullable
@Override
public Boolean deriveValue(@NotNull ScopedStateStore state, @Nullable ScopedStateStore.Key changedKey, @Nullable Boolean currentValue) {
ModuleTemplate moduleTemplate = myState.get(SELECTED_MODULE_TYPE_KEY);
return moduleTemplate != null && Objects.equal(formFactor, moduleTemplate.getFormFactor());
}
});
}
List<ModuleTemplate> galleryTemplatesList = deviceTemplates.build();
List<ModuleTemplate> extrasTemplatesList = extrasTemplates.build();
Iterable<ModuleTemplate> allTemplates = Iterables.concat(galleryTemplatesList, extrasTemplatesList);
myFormFactorGallery.setModel(JBList.createDefaultListModel(Iterables.toArray(allTemplates, ModuleTemplate.class)));
ModuleTypeBinding binding = new ModuleTypeBinding();
register(SELECTED_MODULE_TYPE_KEY, myPanel, binding);
myFormFactorGallery.addListSelectionListener(new ModuleTypeSelectionListener());
if (!galleryTemplatesList.isEmpty()) {
myState.put(SELECTED_MODULE_TYPE_KEY, galleryTemplatesList.get(0));
}
}
use of com.android.tools.idea.wizard.dynamic.ScopedStateStore in project android by JetBrains.
the class FormFactorSdkControls method init.
/**
* @param state The ScopedStateStore in which to store our selections
* @param downloadSuccess A Runnable that will be run if any valid items were found for this form factor.
* @param downloadFailed A Runnable that will be run if no valid items were found for this form factor.
*/
public void init(final ScopedStateStore state, final Runnable loadComplete) {
myBinder.register(myInclusionKey, myInclusionCheckBox);
myHelpMeChooseLink.addHyperlinkListener(new HyperlinkAdapter() {
@Override
protected void hyperlinkActivated(HyperlinkEvent e) {
Integer minApiLevel = state.get(getMinApiLevelKey(MOBILE));
ChooseApiLevelDialog chooseApiLevelDialog = new ChooseApiLevelDialog(null, minApiLevel == null ? 0 : minApiLevel);
Disposer.register(myDisposable, chooseApiLevelDialog.getDisposable());
if (chooseApiLevelDialog.showAndGet()) {
int selectedApiLevel = chooseApiLevelDialog.getSelectedApiLevel();
ScopedDataBinder.setSelectedItem(myMinSdkCombobox, Integer.toString(selectedApiLevel));
}
}
});
// (that is, Mobile).
if (myStatsPanel.isVisible()) {
myBinder.register(API_FEEDBACK_KEY, myHelpMeChooseLabel2, new ScopedDataBinder.ComponentBinding<String, JBLabel>() {
@Override
public void setValue(@Nullable String newValue, @NotNull JBLabel label) {
final JBLabel referenceLabel = label;
final String referenceString = newValue;
ApplicationManager.getApplication().invokeLater(() -> referenceLabel.setText(referenceString));
}
});
myBinder.registerValueDeriver(API_FEEDBACK_KEY, new ScopedDataBinder.ValueDeriver<String>() {
@Nullable
@Override
public Set<ScopedStateStore.Key<?>> getTriggerKeys() {
return makeSetOf(getTargetComboBoxKey(MOBILE));
}
@Nullable
@Override
public String deriveValue(@NotNull ScopedStateStore state, ScopedStateStore.Key changedKey, @Nullable String currentValue) {
FormFactorApiComboBox.AndroidTargetComboBoxItem selectedItem = state.get(getTargetComboBoxKey(MOBILE));
String name = Integer.toString(selectedItem == null ? 0 : selectedItem.getApiLevel());
if (selectedItem != null && selectedItem.target != null) {
name = selectedItem.target.getVersion().getApiString();
}
return getApiHelpText(selectedItem == null || !myStatsPanel.isVisible() ? 0 : selectedItem.getApiLevel(), name);
}
});
}
myMinSdkCombobox.init(myFormFactor, myMinApi, loadComplete, () -> {
myInclusionCheckBox.setEnabled(true);
myLabel.setEnabled(true);
myMinSdkCombobox.setEnabled(true);
}, () -> {
myInclusionCheckBox.setSelected(false);
myNotAvailableLabel.setVisible(true);
});
myMinSdkCombobox.registerWith(myBinder);
myMinSdkCombobox.loadSavedApi();
if (myStatsPanel.isVisible()) {
DistributionService.getInstance().refresh(() -> ApplicationManager.getApplication().invokeLater(() -> {
((CardLayout) myStatsPanel.getLayout()).show(myStatsPanel, "stats");
myBinder.invokeUpdate(getTargetComboBoxKey(MOBILE));
}), () -> ApplicationManager.getApplication().invokeLater(() -> {
((CardLayout) myStatsPanel.getLayout()).show(myStatsPanel, "stats");
myBinder.invokeUpdate(getTargetComboBoxKey(MOBILE));
myStatsLoadFailedLabel.setVisible(true);
}));
}
if (myFormFactor.equals(MOBILE) && state.getNotNull(WH_SDK_ENABLED_KEY, false)) {
myBinder.register(IS_INSTANT_APP_KEY, myInstantAppCheckbox);
myInstantAppCheckbox.setVisible(true);
}
}
Aggregations