use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.
the class GenerateBackupDescriptorFix method isApplicable.
@Override
public boolean isApplicable(@NotNull PsiElement startElement, @NotNull PsiElement endElement, @NotNull AndroidQuickfixContexts.ContextType contextType) {
AndroidFacet facet = AndroidFacet.getInstance(startElement);
AppResourceRepository appResources = facet == null ? null : facet.getAppResources(true);
return appResources == null || !appResources.getItemsOfType(ResourceType.XML).contains(myUrl.name);
}
use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.
the class EmulatorTargetConfigurable method getAvdCompatibilityWarning.
@Nullable
private String getAvdCompatibilityWarning() {
IdDisplay selectedItem = (IdDisplay) myAvdCombo.getComboBox().getSelectedItem();
if (selectedItem != null) {
final String selectedAvdName = selectedItem.getId();
final Module module = myContext.getModule();
if (module == null) {
return null;
}
final AndroidFacet facet = AndroidFacet.getInstance(module);
if (facet == null) {
return null;
}
final AvdManager avdManager = facet.getAvdManagerSilently();
if (avdManager == null) {
return null;
}
final AvdInfo avd = avdManager.getAvd(selectedAvdName, false);
if (avd == null || avd.getSystemImage() == null) {
return null;
}
AndroidPlatform platform = facet.getConfiguration().getAndroidPlatform();
if (platform == null) {
return null;
}
AndroidVersion minSdk = AndroidModuleInfo.get(facet).getRuntimeMinSdkVersion();
LaunchCompatibility compatibility = LaunchCompatibility.canRunOnAvd(minSdk, platform.getTarget(), avd.getSystemImage());
if (compatibility.isCompatible() == ThreeState.NO) {
// todo: provide info about current module configuration
return String.format("'%1$s' may be incompatible with your configuration (%2$s)", selectedAvdName, StringUtil.notNullize(compatibility.getReason()));
}
}
return null;
}
use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.
the class AvdComboBox method doUpdateAvds.
private void doUpdateAvds() {
final Module module = getModule();
if (module == null || module.isDisposed()) {
return;
}
final AndroidFacet facet = AndroidFacet.getInstance(module);
final IdDisplay[] newAvds;
if (facet != null) {
final Set<String> filteringSet = new HashSet<String>();
if (myShowNotLaunchedOnly) {
final AndroidDebugBridge debugBridge = AndroidSdkUtils.getDebugBridge(facet.getModule().getProject());
if (debugBridge != null) {
for (IDevice device : debugBridge.getDevices()) {
final String avdName = device.getAvdName();
if (avdName != null && avdName.length() > 0) {
filteringSet.add(avdName);
}
}
}
}
final List<IdDisplay> newAvdList = new ArrayList<IdDisplay>();
if (myAddEmptyElement) {
newAvdList.add(IdDisplay.create("", ""));
}
for (AvdInfo avd : facet.getAllAvds()) {
String displayName = avd.getProperties().get(AvdManager.AVD_INI_DISPLAY_NAME);
final String avdName = displayName == null || displayName.isEmpty() ? avd.getName() : displayName;
if (!filteringSet.contains(avdName)) {
newAvdList.add(IdDisplay.create(avd.getName(), avdName));
}
}
newAvds = ArrayUtil.toObjectArray(newAvdList, IdDisplay.class);
} else {
newAvds = new IdDisplay[0];
}
if (!Arrays.equals(myOldAvds, newAvds)) {
myOldAvds = newAvds;
final Object selected = getComboBox().getSelectedItem();
getComboBox().setModel(new DefaultComboBoxModel(newAvds));
getComboBox().setSelectedItem(selected);
}
}
use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.
the class CreateResourceDialogUtils method getResourceDirectory.
@Nullable
public static PsiDirectory getResourceDirectory(@Nullable SourceProvider sourceProvider, @NotNull Module module, boolean create) {
ApplicationManager.getApplication().assertReadAccessAllowed();
if (sourceProvider != null) {
final PsiManager manager = PsiManager.getInstance(module.getProject());
for (final File file : sourceProvider.getResDirectories()) {
if (create && !file.exists()) {
PsiDirectory dir = ApplicationManager.getApplication().runWriteAction(new Computable<PsiDirectory>() {
@Override
public PsiDirectory compute() {
return DirectoryUtil.mkdirs(manager, FileUtil.toSystemIndependentName(file.getPath()));
}
});
if (dir != null) {
return dir;
}
} else {
VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByIoFile(file);
if (virtualFile != null) {
PsiDirectory dir = manager.findDirectory(virtualFile);
if (dir != null) {
return dir;
}
}
}
}
}
// Otherwise use the main source set:
AndroidFacet facet = AndroidFacet.getInstance(module);
if (facet != null) {
VirtualFile res = facet.getPrimaryResourceDir();
if (res != null) {
return PsiManager.getInstance(module.getProject()).findDirectory(res);
}
}
return null;
}
use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.
the class AndroidLintExternalAnnotator method collectInformation.
@Override
public State collectInformation(@NotNull PsiFile file) {
final Module module = ModuleUtilCore.findModuleForPsiElement(file);
if (module == null) {
return null;
}
final AndroidFacet facet = AndroidFacet.getInstance(module);
if (facet == null && !LintIdeProject.hasAndroidModule(module.getProject())) {
return null;
}
final VirtualFile vFile = file.getVirtualFile();
if (vFile == null) {
return null;
}
final FileType fileType = file.getFileType();
if (fileType == StdFileTypes.XML) {
if (facet == null || facet.getLocalResourceManager().getFileResourceFolderType(file) == null && !ANDROID_MANIFEST_XML.equals(vFile.getName())) {
return null;
}
} else if (fileType == FileTypes.PLAIN_TEXT) {
if (!AndroidCommonUtils.PROGUARD_CFG_FILE_NAME.equals(file.getName()) && !AndroidCompileUtil.OLD_PROGUARD_CFG_FILE_NAME.equals(file.getName())) {
return null;
}
} else if (fileType == GroovyFileType.GROOVY_FILE_TYPE) {
if (!SdkUtils.endsWithIgnoreCase(file.getName(), DOT_GRADLE)) {
return null;
}
// Ensure that we're listening to the PSI structure for Gradle file edit notifications
Project project = file.getProject();
if (AndroidProjectInfo.getInstance(project).requiresAndroidModel()) {
PsiProjectListener.getInstance(project);
}
} else if (fileType != StdFileTypes.JAVA && fileType != StdFileTypes.PROPERTIES) {
return null;
}
final List<Issue> issues = getIssuesFromInspections(file.getProject(), file);
if (issues.size() == 0) {
return null;
}
return new State(module, vFile, file.getText(), issues);
}
Aggregations