Search in sources :

Example 6 with AndroidModel

use of com.android.tools.idea.model.AndroidModel in project android by JetBrains.

the class DataBindingUtil method onIdeaProjectSet.

/**
   * Called by the {@linkplain AndroidFacet} to refresh its data binding status.
   *
   * @param facet the {@linkplain AndroidFacet} whose IdeaProject is just set.
   */
public static void onIdeaProjectSet(AndroidFacet facet) {
    AndroidModel androidModel = facet.getAndroidModel();
    if (androidModel != null) {
        boolean wasEnabled = facet.isDataBindingEnabled();
        boolean enabled = androidModel.getDataBindingEnabled();
        if (enabled != wasEnabled) {
            facet.setDataBindingEnabled(enabled);
            ourDataBindingEnabledModificationCount.incrementAndGet();
        }
    }
}
Also used : AndroidModel(com.android.tools.idea.model.AndroidModel)

Example 7 with AndroidModel

use of com.android.tools.idea.model.AndroidModel in project android by JetBrains.

the class ResourceFolderManager method computeFolders.

private List<VirtualFile> computeFolders() {
    if (myFacet.requiresAndroidModel()) {
        JpsAndroidModuleProperties state = myFacet.getConfiguration().getState();
        AndroidModel androidModel = myFacet.getAndroidModel();
        List<VirtualFile> resDirectories = new ArrayList<>();
        if (androidModel == null) {
            // Read string property
            if (state != null) {
                String path = state.RES_FOLDERS_RELATIVE_PATH;
                if (path != null) {
                    VirtualFileManager manager = VirtualFileManager.getInstance();
                    // writes the property
                    for (String url : Splitter.on(';').omitEmptyStrings().trimResults().split(path)) {
                        VirtualFile dir = manager.findFileByUrl(url);
                        if (dir != null) {
                            resDirectories.add(dir);
                        }
                    }
                } else {
                    // First time; have not yet computed the res folders
                    // just try the default: src/main/res/ (from Gradle templates), res/ (from exported Eclipse projects)
                    String mainRes = '/' + FD_SOURCES + '/' + FD_MAIN + '/' + FD_RES;
                    VirtualFile dir = AndroidRootUtil.getFileByRelativeModulePath(myFacet.getModule(), mainRes, true);
                    if (dir != null) {
                        resDirectories.add(dir);
                    } else {
                        String res = '/' + FD_RES;
                        dir = AndroidRootUtil.getFileByRelativeModulePath(myFacet.getModule(), res, true);
                        if (dir != null) {
                            resDirectories.add(dir);
                        }
                    }
                }
            }
        } else {
            for (IdeaSourceProvider provider : IdeaSourceProvider.getCurrentSourceProviders(myFacet)) {
                resDirectories.addAll(provider.getResDirectories());
            }
            // before the gradle model has been initialized asynchronously
            if (state != null) {
                StringBuilder path = new StringBuilder(400);
                for (VirtualFile dir : resDirectories) {
                    if (path.length() != 0) {
                        // Deliberately using ';' instead of File.pathSeparator since on Unix File.pathSeparator is ":"
                        // which is also used in URLs, meaning we could end up with something like "file://foo:file://bar"
                        path.append(';');
                    }
                    path.append(dir.getUrl());
                }
                state.RES_FOLDERS_RELATIVE_PATH = path.toString();
            }
            // Also refresh the app resources whenever the variant changes
            if (!myVariantListenerAdded) {
                myVariantListenerAdded = true;
                BuildVariantView.getInstance(myFacet.getModule().getProject()).addListener(this::invalidate);
            }
        }
        // Listen to root change events. Be notified when project is initialized so we can update the
        // resource set, if necessary.
        ProjectResourceRepositoryRootListener.ensureSubscribed(myFacet.getModule().getProject());
        return resDirectories;
    } else {
        return new ArrayList<>(myFacet.getMainIdeaSourceProvider().getResDirectories());
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager) AndroidModel(com.android.tools.idea.model.AndroidModel) JpsAndroidModuleProperties(org.jetbrains.jps.android.model.impl.JpsAndroidModuleProperties)

Example 8 with AndroidModel

use of com.android.tools.idea.model.AndroidModel in project android by JetBrains.

the class AndroidProcessChooserDialog method collectAllProcessNames.

@NotNull
private static Set<String> collectAllProcessNames(Project project) {
    final List<AndroidFacet> facets = ProjectFacetManager.getInstance(project).getFacets(AndroidFacet.ID);
    final Set<String> result = new HashSet<String>();
    for (AndroidFacet facet : facets) {
        final String packageName = AndroidCompileUtil.getAaptManifestPackage(facet);
        if (packageName != null) {
            result.add(packageName.toLowerCase());
        }
        final Manifest manifest = facet.getManifest();
        if (manifest != null) {
            final XmlElement xmlElement = manifest.getXmlElement();
            if (xmlElement != null) {
                collectProcessNames(xmlElement, result);
            }
        }
        final AndroidModel androidModel = facet.getAndroidModel();
        if (androidModel != null) {
            result.addAll(androidModel.getAllApplicationIds());
        }
    }
    return result;
}
Also used : AndroidModel(com.android.tools.idea.model.AndroidModel) XmlElement(com.intellij.psi.xml.XmlElement) Manifest(org.jetbrains.android.dom.manifest.Manifest) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) HashSet(com.intellij.util.containers.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with AndroidModel

use of com.android.tools.idea.model.AndroidModel in project kotlin by JetBrains.

the class IntellijLintProject method createModuleProject.

/** Creates a new module project */
@Nullable
private static LintModuleProject createModuleProject(@NonNull LintClient client, @NonNull Module module) {
    AndroidFacet facet = AndroidFacet.getInstance(module);
    File dir;
    if (facet != null) {
        final VirtualFile mainContentRoot = AndroidRootUtil.getMainContentRoot(facet);
        if (mainContentRoot == null) {
            return null;
        }
        dir = new File(FileUtil.toSystemDependentName(mainContentRoot.getPath()));
    } else {
        String moduleDirPath = AndroidRootUtil.getModuleDirPath(module);
        if (moduleDirPath == null) {
            return null;
        }
        dir = new File(FileUtil.toSystemDependentName(moduleDirPath));
    }
    LintModuleProject project = null;
    if (facet == null) {
        project = new LintModuleProject(client, dir, dir, module);
        AndroidFacet f = findAndroidFacetInProject(module.getProject());
        if (f != null) {
            project.mGradleProject = f.requiresAndroidModel();
        }
    } else if (facet.requiresAndroidModel()) {
        AndroidModel androidModel = facet.getAndroidModel();
        if (androidModel instanceof AndroidGradleModel) {
            project = new LintGradleProject(client, dir, dir, facet, (AndroidGradleModel) androidModel);
        } else {
            project = new LintAndroidModelProject(client, dir, dir, facet, androidModel);
        }
    } else {
        project = new LintAndroidProject(client, dir, dir, facet);
    }
    if (project != null) {
        client.registerProject(dir, project);
    }
    return project;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AndroidModel(com.android.tools.idea.model.AndroidModel) AndroidGradleModel(com.android.tools.idea.gradle.AndroidGradleModel) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) Nullable(org.jetbrains.annotations.Nullable)

Example 10 with AndroidModel

use of com.android.tools.idea.model.AndroidModel in project android by JetBrains.

the class LintIdeUtils method getResourceDirectories.

/** Returns the resource directories to use for the given module */
@NotNull
public static List<File> getResourceDirectories(@NotNull AndroidFacet facet) {
    if (facet.requiresAndroidModel()) {
        AndroidModel androidModel = facet.getAndroidModel();
        if (androidModel != null) {
            List<File> resDirectories = new ArrayList<File>();
            List<SourceProvider> sourceProviders = androidModel.getActiveSourceProviders();
            for (SourceProvider provider : sourceProviders) {
                for (File file : provider.getResDirectories()) {
                    if (file.isDirectory()) {
                        resDirectories.add(file);
                    }
                }
            }
            return resDirectories;
        }
    }
    return new ArrayList<File>(facet.getMainSourceProvider().getResDirectories());
}
Also used : AndroidModel(com.android.tools.idea.model.AndroidModel) ArrayList(java.util.ArrayList) SourceProvider(com.android.builder.model.SourceProvider) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

AndroidModel (com.android.tools.idea.model.AndroidModel)12 VirtualFile (com.intellij.openapi.vfs.VirtualFile)9 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)7 File (java.io.File)6 SourceProvider (com.android.builder.model.SourceProvider)3 Module (com.intellij.openapi.module.Module)3 NotNull (org.jetbrains.annotations.NotNull)3 Nullable (org.jetbrains.annotations.Nullable)3 ArrayList (java.util.ArrayList)2 ProductFlavorContainer (com.android.builder.model.ProductFlavorContainer)1 AndroidVersion (com.android.sdklib.AndroidVersion)1 AndroidGradleModel (com.android.tools.idea.gradle.AndroidGradleModel)1 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)1 AndroidModuleInfo (com.android.tools.idea.model.AndroidModuleInfo)1 AppResourceRepository (com.android.tools.idea.res.AppResourceRepository)1 FileResourceRepository (com.android.tools.idea.res.FileResourceRepository)1 ResourceClassRegistry (com.android.tools.idea.res.ResourceClassRegistry)1 Project (com.intellij.openapi.project.Project)1 CompilerModuleExtension (com.intellij.openapi.roots.CompilerModuleExtension)1 VirtualFileManager (com.intellij.openapi.vfs.VirtualFileManager)1