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();
}
}
}
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());
}
}
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;
}
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;
}
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());
}
Aggregations