Search in sources :

Example 1 with ScopedStateStore

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());
}
Also used : DetailsTypes(com.android.sdklib.repository.meta.DetailsTypes) ScopedStateStore(com.android.tools.idea.wizard.dynamic.ScopedStateStore) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) RepoFactory(com.android.sdklib.repository.meta.RepoFactory) AvdInfo(com.android.sdklib.internal.avd.AvdInfo) MockFileOp(com.android.repository.testframework.MockFileOp) AvdManagerConnection(com.android.tools.idea.avdmanager.AvdManagerConnection) FakePackage(com.android.repository.testframework.FakePackage) File(java.io.File) RemotePackage(com.android.repository.api.RemotePackage) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map)

Example 2 with ScopedStateStore

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));
}
Also used : ScopedStateStore(com.android.tools.idea.wizard.dynamic.ScopedStateStore) NewFormFactorModulePath(com.android.tools.idea.npw.deprecated.NewFormFactorModulePath) File(java.io.File)

Example 3 with ScopedStateStore

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));
}
Also used : ScopedStateStore(com.android.tools.idea.wizard.dynamic.ScopedStateStore) NewProjectModelTest(com.android.tools.idea.npw.NewProjectModelTest) Test(org.junit.Test)

Example 4 with ScopedStateStore

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));
    }
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ModuleTemplate(com.android.tools.idea.npw.ModuleTemplate) ScopedStateStore(com.android.tools.idea.wizard.dynamic.ScopedStateStore) FormFactor(com.android.tools.idea.npw.FormFactor) ModuleTemplateProvider(com.android.tools.idea.npw.ModuleTemplateProvider) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with ScopedStateStore

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);
    }
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) Set(java.util.Set) ScopedStateStore(com.android.tools.idea.wizard.dynamic.ScopedStateStore) JBLabel(com.intellij.ui.components.JBLabel) ScopedDataBinder(com.android.tools.idea.wizard.dynamic.ScopedDataBinder) Nullable(org.jetbrains.annotations.Nullable) HyperlinkAdapter(com.intellij.ui.HyperlinkAdapter)

Aggregations

ScopedStateStore (com.android.tools.idea.wizard.dynamic.ScopedStateStore)7 File (java.io.File)3 Nullable (org.jetbrains.annotations.Nullable)2 RemotePackage (com.android.repository.api.RemotePackage)1 FakePackage (com.android.repository.testframework.FakePackage)1 MockFileOp (com.android.repository.testframework.MockFileOp)1 AvdInfo (com.android.sdklib.internal.avd.AvdInfo)1 AndroidSdkHandler (com.android.sdklib.repository.AndroidSdkHandler)1 DetailsTypes (com.android.sdklib.repository.meta.DetailsTypes)1 RepoFactory (com.android.sdklib.repository.meta.RepoFactory)1 AvdManagerConnection (com.android.tools.idea.avdmanager.AvdManagerConnection)1 FormFactor (com.android.tools.idea.npw.FormFactor)1 ModuleTemplate (com.android.tools.idea.npw.ModuleTemplate)1 ModuleTemplateProvider (com.android.tools.idea.npw.ModuleTemplateProvider)1 NewProjectModelTest (com.android.tools.idea.npw.NewProjectModelTest)1 ConfigureAndroidModuleStepDynamic (com.android.tools.idea.npw.deprecated.ConfigureAndroidModuleStepDynamic)1 NewFormFactorModulePath (com.android.tools.idea.npw.deprecated.NewFormFactorModulePath)1 ScopedDataBinder (com.android.tools.idea.wizard.dynamic.ScopedDataBinder)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1