use of com.android.sdklib.IAndroidTarget in project android by JetBrains.
the class AndroidSdkUtils method isGlassInstalled.
public static boolean isGlassInstalled() {
StudioLoggerProgressIndicator progress = new StudioLoggerProgressIndicator(AndroidSdkUtils.class);
AndroidSdkHandler handler = AndroidSdks.getInstance().tryToChooseSdkHandler();
Collection<IAndroidTarget> targets = handler.getAndroidTargetManager(progress).getTargets(progress);
for (IAndroidTarget target : targets) {
if (!target.isPlatform() && target.getName().startsWith("Glass Development Kit")) {
return true;
}
}
return false;
}
use of com.android.sdklib.IAndroidTarget in project android by JetBrains.
the class AndroidSdkUtils method findAppropriateAndroidPlatform.
@Nullable
public static Sdk findAppropriateAndroidPlatform(@NotNull IAndroidTarget target, @NotNull AndroidSdkData sdkData, boolean forMaven) {
for (Sdk sdk : ProjectJdkTable.getInstance().getAllJdks()) {
String homePath = sdk.getHomePath();
AndroidSdks androidSdks = AndroidSdks.getInstance();
if (homePath != null && androidSdks.isAndroidSdk(sdk)) {
AndroidSdkData currentSdkData = getSdkData(homePath);
if (sdkData.equals(currentSdkData)) {
AndroidSdkAdditionalData data = androidSdks.getAndroidSdkAdditionalData(sdk);
if (data != null) {
IAndroidTarget currentTarget = data.getBuildTarget(currentSdkData);
if (currentTarget != null && target.hashString().equals(currentTarget.hashString()) && checkSdkRoots(sdk, target, forMaven)) {
return sdk;
}
}
}
}
}
return null;
}
use of com.android.sdklib.IAndroidTarget in project android by JetBrains.
the class AndroidSdkUtils method createNewAndroidPlatform.
/**
* Creates a new IDEA Android SDK. User is prompt for the paths of the Android SDK and JDK if necessary.
*
* @param sdkPath the path of Android SDK.
* @return the created IDEA Android SDK, or {@null} if it was not possible to create it.
*/
@Nullable
public static Sdk createNewAndroidPlatform(@Nullable String sdkPath, boolean promptUser) {
Sdk jdk = Jdks.getInstance().chooseOrCreateJavaSdk();
if (sdkPath != null && jdk != null) {
sdkPath = toSystemIndependentName(sdkPath);
IAndroidTarget target = findBestTarget(sdkPath);
if (target != null) {
Sdk sdk = AndroidSdks.getInstance().create(target, new File(sdkPath), AndroidSdks.getInstance().chooseNameForNewLibrary(target), jdk, true);
if (sdk != null) {
return sdk;
}
}
}
String jdkPath = jdk == null ? null : jdk.getHomePath();
return promptUser ? promptUserForSdkCreation(null, sdkPath, jdkPath) : null;
}
use of com.android.sdklib.IAndroidTarget in project android by JetBrains.
the class AndroidTestBase method createLatestAndroidSdk.
public static Sdk createLatestAndroidSdk() {
String sdkPath = TestUtils.getSdk().toString();
String platformDir = TestUtils.getLatestAndroidPlatform();
Sdk sdk = ProjectJdkTable.getInstance().createSdk("android_test_sdk", AndroidSdkType.getInstance());
SdkModificator sdkModificator = sdk.getSdkModificator();
sdkModificator.setHomePath(sdkPath);
VirtualFile androidJar = JarFileSystem.getInstance().findFileByPath(sdkPath + "/platforms/" + platformDir + "/android.jar!/");
sdkModificator.addRoot(androidJar, OrderRootType.CLASSES);
VirtualFile resFolder = LocalFileSystem.getInstance().findFileByPath(sdkPath + "/platforms/" + platformDir + "/data/res");
sdkModificator.addRoot(resFolder, OrderRootType.CLASSES);
VirtualFile docsFolder = LocalFileSystem.getInstance().findFileByPath(sdkPath + "/docs/reference");
if (docsFolder != null) {
sdkModificator.addRoot(docsFolder, JavadocOrderRootType.getInstance());
}
AndroidSdkAdditionalData data = new AndroidSdkAdditionalData(sdk);
AndroidSdkData sdkData = AndroidSdkData.getSdkData(sdkPath);
assertNotNull(sdkData);
IAndroidTarget target = null;
IAndroidTarget[] targets = sdkData.getTargets();
for (IAndroidTarget t : targets) {
if (t.getLocation().contains(platformDir)) {
target = t;
break;
}
}
assertNotNull(target);
data.setBuildTarget(target);
sdkModificator.setSdkAdditionalData(data);
ExternalAnnotationsSupport.attachJdkAnnotations(sdkModificator);
sdkModificator.commitChanges();
return sdk;
}
use of com.android.sdklib.IAndroidTarget in project android by JetBrains.
the class ThemeEditorUtils method getModuleThemeQualifiedNamesList.
/**
* Returns the list of the qualified names of all the user-defined themes available from a given module
*/
@NotNull
public static ImmutableList<String> getModuleThemeQualifiedNamesList(@NotNull Module module) {
AndroidFacet facet = AndroidFacet.getInstance(module);
assert facet != null;
ConfigurationManager manager = facet.getConfigurationManager();
// We create a new ResourceResolverCache instead of using cache from myConfiguration to optimize memory instead of time/speed,
// because we are about to create a lot of instances of ResourceResolver here that won't be used outside of this method
final ResourceResolverCache resolverCache = new ResourceResolverCache(manager);
final IAndroidTarget target = manager.getTarget();
final Map<ResourceValue, Boolean> cache = new HashMap<ResourceValue, Boolean>();
final Set<String> themeNamesSet = Sets.newTreeSet(String.CASE_INSENSITIVE_ORDER);
ResourceFolderVisitor visitor = new ResourceFolderVisitor() {
@Override
public void visitResourceFolder(@NotNull LocalResourceRepository resources, String moduleName, @NotNull String variantName, boolean isSelected) {
if (!isSelected) {
return;
}
for (String simpleThemeName : resources.getItemsOfType(ResourceType.STYLE)) {
String themeStyleResourceUrl = SdkConstants.STYLE_RESOURCE_PREFIX + simpleThemeName;
List<ResourceItem> themeItems = resources.getResourceItem(ResourceType.STYLE, simpleThemeName);
assert themeItems != null;
for (ResourceItem themeItem : themeItems) {
ResourceResolver resolver = resolverCache.getResourceResolver(target, themeStyleResourceUrl, themeItem.getConfiguration());
ResourceValue themeItemResourceValue = themeItem.getResourceValue(false);
assert themeItemResourceValue != null;
if (resolver.isTheme(themeItemResourceValue, cache)) {
themeNamesSet.add(simpleThemeName);
break;
}
}
}
}
};
acceptResourceResolverVisitor(facet, visitor);
return ImmutableList.copyOf(themeNamesSet);
}
Aggregations