Search in sources :

Example 61 with AndroidVersion

use of com.android.sdklib.AndroidVersion in project android by JetBrains.

the class NewVectorAssetAction method createWizard.

@Nullable
@Override
protected ModelWizard createWizard(@NotNull AndroidFacet facet) {
    Module module = facet.getModule();
    Project project = module.getProject();
    AndroidModuleModel androidModel = AndroidModuleModel.get(module);
    if (androidModel != null) {
        AndroidVersion minSdkVersion = androidModel.getMinSdkVersion();
        String version = androidModel.getAndroidProject().getModelVersion();
        GradleVersion revision = GradleVersion.parse(version);
        if (revision.compareIgnoringQualifiers(VECTOR_ASSET_GENERATION_REVISION) < 0 && (minSdkVersion == null || minSdkVersion.getApiLevel() < VECTOR_DRAWABLE_API_LEVEL)) {
            Messages.showErrorDialog(project, ERROR_MESSAGE, ERROR_TITLE);
            return null;
        }
    }
    ModelWizard.Builder wizardBuilder = new ModelWizard.Builder();
    wizardBuilder.addStep(new NewVectorAssetStep(new GenerateVectorIconModel(facet), facet));
    return wizardBuilder.build();
}
Also used : Project(com.intellij.openapi.project.Project) NewVectorAssetStep(com.android.tools.idea.npw.assetstudio.wizard.NewVectorAssetStep) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) GenerateVectorIconModel(com.android.tools.idea.npw.assetstudio.wizard.GenerateVectorIconModel) Module(com.intellij.openapi.module.Module) AndroidVersion(com.android.sdklib.AndroidVersion) GradleVersion(com.android.ide.common.repository.GradleVersion) ModelWizard(com.android.tools.idea.wizard.model.ModelWizard) Nullable(org.jetbrains.annotations.Nullable)

Example 62 with AndroidVersion

use of com.android.sdklib.AndroidVersion in project android by JetBrains.

the class InstallPlatformHyperlink method execute.

@Override
protected void execute(@NotNull Project project) {
    List<String> requested = Lists.newArrayList();
    for (AndroidVersion version : myAndroidVersions) {
        requested.add(DetailsTypes.getPlatformPath(version));
    }
    ModelWizardDialog dialog = SdkQuickfixUtils.createDialogForPaths(project, requested);
    if (dialog != null && dialog.showAndGet()) {
        GradleSyncInvoker.getInstance().requestProjectSyncAndSourceGeneration(project, null);
    }
}
Also used : AndroidVersion(com.android.sdklib.AndroidVersion) ModelWizardDialog(com.android.tools.idea.wizard.model.ModelWizardDialog)

Example 63 with AndroidVersion

use of com.android.sdklib.AndroidVersion in project android by JetBrains.

the class TemplateUtils method getKnownVersions.

/**
   * Returns a list of known API names
   *
   * @return a list of string API names, starting from 1 and up through the
   * maximum known versions (with no gaps)
   */
@NotNull
public static String[] getKnownVersions() {
    final AndroidSdkData sdkData = AndroidSdks.getInstance().tryToChooseAndroidSdk();
    assert sdkData != null;
    int max = SdkVersionInfo.HIGHEST_KNOWN_STABLE_API;
    IAndroidTarget[] targets = sdkData.getTargets();
    SparseArray<IAndroidTarget> apiTargets = null;
    for (IAndroidTarget target : targets) {
        if (target.isPlatform()) {
            AndroidVersion version = target.getVersion();
            if (!version.isPreview()) {
                int apiLevel = version.getApiLevel();
                max = Math.max(max, apiLevel);
                if (apiLevel > SdkVersionInfo.HIGHEST_KNOWN_API) {
                    if (apiTargets == null) {
                        apiTargets = new SparseArray<IAndroidTarget>();
                    }
                    apiTargets.put(apiLevel, target);
                }
            }
        }
    }
    String[] versions = new String[max];
    for (int api = 1; api <= max; api++) {
        String name = SdkVersionInfo.getAndroidName(api);
        // noinspection ConstantConditions
        if (name == null) {
            if (apiTargets != null) {
                IAndroidTarget target = apiTargets.get(api);
                if (target != null) {
                    name = AndroidSdkUtils.getTargetLabel(target);
                }
            }
            if (name == null) {
                name = String.format("API %1$d", api);
            }
        }
        versions[api - 1] = name;
    }
    return versions;
}
Also used : AndroidSdkData(org.jetbrains.android.sdk.AndroidSdkData) IAndroidTarget(com.android.sdklib.IAndroidTarget) AndroidVersion(com.android.sdklib.AndroidVersion) NotNull(org.jetbrains.annotations.NotNull)

Example 64 with AndroidVersion

use of com.android.sdklib.AndroidVersion in project android by JetBrains.

the class HotswapAction method doUpdate.

@Override
protected void doUpdate(@NotNull AnActionEvent e, @NotNull Project project) {
    Presentation presentation = e.getPresentation();
    presentation.setEnabled(false);
    if (!InstantRunSettings.isInstantRunEnabled()) {
        presentation.setText("Apply Changes: Instant Run has been disabled");
        return;
    }
    RunnerAndConfigurationSettings settings = RunManager.getInstance(project).getSelectedConfiguration();
    if (settings == null) {
        presentation.setText("Apply Changes: No run configuration selected");
        return;
    }
    AndroidSessionInfo session = getAndroidSessionInfo(project, settings);
    if (session == null) {
        presentation.setText(String.format("Apply Changes: No active '%1$s' launch", settings.getName()));
        return;
    }
    ProcessHandler processHandler = getActiveProcessHandler(project, settings);
    if (processHandler == null) {
        presentation.setText(String.format("Apply Changes: No active '%1$s' launch", settings.getName()));
        return;
    }
    RunConfiguration configuration = settings.getConfiguration();
    if (!(configuration instanceof ModuleBasedConfiguration)) {
        presentation.setText(String.format("Apply Changes: '%1$s' is not a module based configuration", settings.getName()));
        return;
    }
    Module module = ((ModuleBasedConfiguration) configuration).getConfigurationModule().getModule();
    if (module == null) {
        presentation.setText(String.format("Apply Changes: No module specified in '%1$s'", settings.getName()));
        return;
    }
    if (!(configuration instanceof AndroidRunConfigurationBase)) {
        presentation.setText(String.format("Apply Changes: '%1$s' is not an Android launch configuration", settings.getName()));
        return;
    }
    if (!((AndroidRunConfigurationBase) configuration).supportsInstantRun()) {
        presentation.setText(String.format("Apply Changes: Configuration '%1$s' does not support instant run", settings.getName()));
        return;
    }
    AndroidVersion androidVersion = InstantRunManager.getMinDeviceApiLevel(processHandler);
    if (androidVersion == null) {
        presentation.setText(String.format("Apply Changes: Cannot locate device from '%1$s'", settings.getName()));
        return;
    }
    if (!InstantRunManager.isInstantRunCapableDeviceVersion(androidVersion)) {
        presentation.setText(String.format("Apply Changes: Target device API level (%1$s) too low for Instant Run", androidVersion));
        return;
    }
    InstantRunGradleSupport status = InstantRunGradleUtils.getIrSupportStatus(InstantRunGradleUtils.getAppModel(module), androidVersion);
    if (status != SUPPORTED) {
        String notification = status.getUserNotification();
        if (notification == null) {
            notification = status.toString();
        }
        presentation.setText("Apply Changes: " + notification);
        return;
    }
    presentation.setText("Apply Changes" + getShortcutText());
    presentation.setEnabled(true);
}
Also used : RunConfiguration(com.intellij.execution.configurations.RunConfiguration) AndroidRunConfigurationBase(com.android.tools.idea.run.AndroidRunConfigurationBase) AndroidSessionInfo(com.android.tools.idea.run.AndroidSessionInfo) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) ProcessHandler(com.intellij.execution.process.ProcessHandler) InstantRunGradleSupport(com.android.tools.idea.fd.gradle.InstantRunGradleSupport) Presentation(com.intellij.openapi.actionSystem.Presentation) ModuleBasedConfiguration(com.intellij.execution.configurations.ModuleBasedConfiguration) Module(com.intellij.openapi.module.Module) AndroidVersion(com.android.sdklib.AndroidVersion)

Example 65 with AndroidVersion

use of com.android.sdklib.AndroidVersion in project android by JetBrains.

the class InstantRunPositionManager method createSourcesByApiLevel.

private static Map<AndroidVersion, VirtualFile> createSourcesByApiLevel() {
    Collection<? extends LocalPackage> sourcePackages = getAllPlatformSourcePackages();
    Map<AndroidVersion, VirtualFile> sourcesByApi = Maps.newHashMap();
    for (LocalPackage sourcePackage : sourcePackages) {
        TypeDetails typeDetails = sourcePackage.getTypeDetails();
        if (!(typeDetails instanceof DetailsTypes.ApiDetailsType)) {
            Logger.getInstance(InstantRunPositionManager.class).warn("Unable to get type details for source package @ " + sourcePackage.getLocation().getPath());
            continue;
        }
        DetailsTypes.ApiDetailsType details = (DetailsTypes.ApiDetailsType) typeDetails;
        AndroidVersion version = details.getAndroidVersion();
        VirtualFile sourceFolder = VfsUtil.findFileByIoFile(sourcePackage.getLocation(), true);
        if (sourceFolder != null && sourceFolder.isValid()) {
            sourcesByApi.put(version, sourceFolder);
        }
    }
    return ImmutableMap.copyOf(sourcesByApi);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TypeDetails(com.android.repository.impl.meta.TypeDetails) LocalPackage(com.android.repository.api.LocalPackage) DetailsTypes(com.android.sdklib.repository.meta.DetailsTypes) AndroidVersion(com.android.sdklib.AndroidVersion)

Aggregations

AndroidVersion (com.android.sdklib.AndroidVersion)89 Test (org.junit.Test)21 NotNull (org.jetbrains.annotations.NotNull)14 IAndroidTarget (com.android.sdklib.IAndroidTarget)12 IDevice (com.android.ddmlib.IDevice)11 Nullable (org.jetbrains.annotations.Nullable)9 MockPlatformTarget (com.android.sdklib.internal.androidTarget.MockPlatformTarget)8 Module (com.intellij.openapi.module.Module)8 File (java.io.File)8 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)8 AndroidPlatform (org.jetbrains.android.sdk.AndroidPlatform)8 DetailsTypes (com.android.sdklib.repository.meta.DetailsTypes)6 Project (com.intellij.openapi.project.Project)5 Abi (com.android.sdklib.devices.Abi)4 InstantRunGradleSupport (com.android.tools.idea.fd.gradle.InstantRunGradleSupport)4 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)4 OutputFile (com.android.build.OutputFile)3 TypeDetails (com.android.repository.impl.meta.TypeDetails)3 AvdInfo (com.android.sdklib.internal.avd.AvdInfo)3 ModelWizardDialog (com.android.tools.idea.wizard.model.ModelWizardDialog)3