Search in sources :

Example 11 with AndroidVersion

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

the class PlatformComponentsPanel method updatePlatformItems.

private void updatePlatformItems() {
    myPlatformDetailsRootNode.removeAllChildren();
    myPlatformSummaryRootNode.removeAllChildren();
    myStates.clear();
    List<AndroidVersion> versions = Lists.newArrayList(myCurrentPackages.keySet());
    versions = Lists.reverse(versions);
    for (AndroidVersion version : versions) {
        Set<UpdaterTreeNode> versionNodes = Sets.newHashSet();
        UpdaterTreeNode marker = new ParentTreeNode(version);
        myPlatformDetailsRootNode.add(marker);
        boolean obsolete = false;
        for (UpdatablePackage info : myCurrentPackages.get(version)) {
            RepoPackage pkg = info.getRepresentative();
            PackageNodeModel model = new PackageNodeModel(info);
            myStates.add(model);
            UpdaterTreeNode node = new DetailsTreeNode(model, myModificationListener, myConfigurable);
            marker.add(node);
            versionNodes.add(node);
            if (pkg.obsolete() && pkg.getTypeDetails() instanceof DetailsTypes.PlatformDetailsType) {
                obsolete = true;
            }
        }
        if (!obsolete) {
            SummaryTreeNode node = SummaryTreeNode.createNode(version, versionNodes);
            if (node != null) {
                myPlatformSummaryRootNode.add(node);
            }
        }
    }
    refreshModified();
    SdkUpdaterConfigPanel.resizeColumnsToFit(myPlatformDetailTable);
    SdkUpdaterConfigPanel.resizeColumnsToFit(myPlatformSummaryTable);
    myPlatformDetailTable.updateUI();
    myPlatformSummaryTable.updateUI();
    TreeUtil.expandAll(myPlatformDetailTable.getTree());
    TreeUtil.expandAll(myPlatformSummaryTable.getTree());
}
Also used : DetailsTypes(com.android.sdklib.repository.meta.DetailsTypes) AndroidVersion(com.android.sdklib.AndroidVersion) UpdatablePackage(com.android.repository.api.UpdatablePackage) RepoPackage(com.android.repository.api.RepoPackage)

Example 12 with AndroidVersion

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

the class InstantRunPositionManager method getPsiFileByLocation.

/**
   * Returns the PSI file corresponding to the given JDI location.
   * This method is overridden so that we may provide an API specific version of the sources for platform (android.jar) classes.
   *
   * TODO: This method is implemented as part of InstantRunPositionManager, although it has nothing to do with instant run.
   * The issue is that the position manager extension API is a little odd: the position manager that was added last is the one that gets
   * used, and luckily for us, the instant run position manager is being added last. Ideally, we should move just the code that identifies
   * the Psi File given a location to a separate extension mechanism. See b.android.com/208140
   */
@Nullable
@Override
protected PsiFile getPsiFileByLocation(Project project, Location location) {
    PsiFile file = super.getPsiFileByLocation(project, location);
    if (file == null) {
        return null;
    }
    if (!DebuggerSettings.getInstance().SHOW_ALTERNATIVE_SOURCE) {
        return file;
    }
    // we only care about providing an alternate source for files inside the platform.
    if (!AndroidFacet.isInAndroidSdk(file)) {
        return file;
    }
    XDebugSession session = XDebuggerManager.getInstance(project).getCurrentSession();
    if (session == null) {
        return file;
    }
    String relPath = getRelPathFromSourceRoot(project, file);
    if (relPath == null) {
        return file;
    }
    AndroidVersion version = session.getDebugProcess().getProcessHandler().getUserData(AndroidSessionInfo.ANDROID_DEVICE_API_LEVEL);
    if (version == null) {
        return file;
    }
    PsiFile source = getSourceForApiLevel(project, version, relPath);
    return source == null ? file : source;
}
Also used : XDebugSession(com.intellij.xdebugger.XDebugSession) PsiFile(com.intellij.psi.PsiFile) AndroidVersion(com.android.sdklib.AndroidVersion) Nullable(org.jetbrains.annotations.Nullable)

Example 13 with AndroidVersion

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

the class TemplateParameterStep2 method validate.

@Override
public boolean validate() {
    setErrorHtml(null);
    AndroidVersion minApi = myState.get(AddAndroidActivityPath.KEY_MIN_SDK);
    Integer buildApi = myState.get(AddAndroidActivityPath.KEY_BUILD_SDK);
    TemplateEntry templateEntry = myState.get(AddAndroidActivityPath.KEY_SELECTED_TEMPLATE);
    if (templateEntry == null) {
        return false;
    }
    for (Parameter param : templateEntry.getParameters()) {
        if (param != null) {
            Object value = getStateParameterValue(param);
            String error = param.validate(getProject(), getModule(), myState.get(AddAndroidActivityPath.KEY_SOURCE_PROVIDER), myState.get(myPackageNameKey), value != null ? value : "", getRelatedValues(param));
            if (error != null) {
                // Highlight?
                setErrorHtml(error);
                return false;
            }
            // Check to see that the selection's constraints are met if this is a combo box
            if (value instanceof ApiComboBoxItem) {
                ApiComboBoxItem selectedItem = (ApiComboBoxItem) value;
                if (minApi == null || buildApi == null) {
                    return false;
                }
                String message = selectedItem.validate(minApi.getFeatureLevel(), buildApi);
                if (message != null) {
                    setErrorHtml(message);
                    return false;
                }
            }
        }
    }
    return true;
}
Also used : ApiComboBoxItem(com.android.tools.idea.ui.ApiComboBoxItem) AndroidVersion(com.android.sdklib.AndroidVersion)

Example 14 with AndroidVersion

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

the class AddAndroidActivityPath method getDirectories.

private Map<String, Object> getDirectories() {
    Map<String, Object> templateParameters = Maps.newHashMap();
    Module module = getModule();
    assert module != null;
    AndroidFacet facet = AndroidFacet.getInstance(module);
    assert facet != null;
    AndroidPlatform platform = AndroidPlatform.getInstance(module);
    if (platform != null) {
        templateParameters.put(ATTR_BUILD_API, platform.getTarget().getVersion().getFeatureLevel());
        templateParameters.put(ATTR_BUILD_API_STRING, getBuildApiString(platform.getTarget().getVersion()));
    }
    // Read minSdkVersion and package from manifest and/or build.gradle files
    AndroidModuleInfo moduleInfo = AndroidModuleInfo.get(facet);
    AndroidModel androidModel = facet.getAndroidModel();
    SourceProvider sourceProvider1 = myState.get(KEY_SOURCE_PROVIDER);
    if (sourceProvider1 != null && androidModel != null) {
        String packageName = myState.get(KEY_PACKAGE_NAME);
        assert packageName != null;
        templateParameters.putAll(selectSourceProvider(sourceProvider1, androidModel, module, packageName));
    }
    AndroidVersion minSdkVersion = moduleInfo.getMinSdkVersion();
    String minSdkName = minSdkVersion.getApiString();
    templateParameters.put(ATTR_MIN_API, minSdkName);
    templateParameters.put(ATTR_TARGET_API, moduleInfo.getTargetSdkVersion().getApiLevel());
    templateParameters.put(ATTR_MIN_API_LEVEL, minSdkVersion.getFeatureLevel());
    templateParameters.put(ATTR_IS_LIBRARY_MODULE, facet.isLibraryProject());
    try {
        templateParameters.put(ATTR_DEBUG_KEYSTORE_SHA1, KeystoreUtils.sha1(getDebugKeystore(facet)));
    } catch (Exception e) {
        LOG.info("Could not compute SHA1 hash of debug keystore.", e);
        templateParameters.put(ATTR_DEBUG_KEYSTORE_SHA1, "");
    }
    @SuppressWarnings("deprecation") String projectLocation = NewModuleWizardState.ATTR_PROJECT_LOCATION;
    Project project = getProject();
    assert project != null;
    templateParameters.put(projectLocation, project.getBasePath());
    // We're really interested in the directory name on disk, not the module name. These will be different if you give a module the same
    // name as its containing project.
    String moduleName = new File(module.getModuleFilePath()).getParentFile().getName();
    templateParameters.put(FormFactorUtils.ATTR_MODULE_NAME, moduleName);
    return templateParameters;
}
Also used : IdeaSourceProvider(org.jetbrains.android.facet.IdeaSourceProvider) SourceProvider(com.android.builder.model.SourceProvider) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) AndroidVersion(com.android.sdklib.AndroidVersion) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) AndroidModuleInfo(com.android.tools.idea.model.AndroidModuleInfo) Project(com.intellij.openapi.project.Project) AndroidModel(com.android.tools.idea.model.AndroidModel) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 15 with AndroidVersion

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

the class AndroidSdkUtils method findBestTarget.

@Nullable
private static IAndroidTarget findBestTarget(@NotNull IAndroidTarget[] targets) {
    IAndroidTarget bestTarget = null;
    int maxApiLevel = -1;
    for (IAndroidTarget target : targets) {
        AndroidVersion version = target.getVersion();
        if (target.isPlatform() && !version.isPreview() && version.getApiLevel() > maxApiLevel) {
            bestTarget = target;
            maxApiLevel = version.getApiLevel();
        }
    }
    return bestTarget;
}
Also used : IAndroidTarget(com.android.sdklib.IAndroidTarget) AndroidVersion(com.android.sdklib.AndroidVersion) Nullable(org.jetbrains.annotations.Nullable)

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