use of com.android.layoutlib.bridge.Bridge in project android_frameworks_base by ResurrectionRemix.
the class Main method setUp.
/**
* Initialize the bridge and the resource maps.
*/
@BeforeClass
public static void setUp() {
File data_dir = new File(PLATFORM_DIR, "data");
File res = new File(data_dir, "res");
sFrameworkRepo = new FrameworkResources(new FolderWrapper(res));
sFrameworkRepo.loadResources();
sFrameworkRepo.loadPublicResources(getLogger());
sProjectResources = new ResourceRepository(new FolderWrapper(TEST_RES_DIR + APP_TEST_RES), false) {
@NonNull
@Override
protected ResourceItem createResourceItem(@NonNull String name) {
return new ResourceItem(name);
}
};
sProjectResources.loadResources();
File fontLocation = new File(data_dir, "fonts");
File buildProp = new File(PLATFORM_DIR, "build.prop");
File attrs = new File(res, "values" + File.separator + "attrs.xml");
sBridge = new Bridge();
sBridge.init(ConfigGenerator.loadProperties(buildProp), fontLocation, ConfigGenerator.getEnumMap(attrs), getLayoutLog());
}
use of com.android.layoutlib.bridge.Bridge in project android_frameworks_base by DirtyUnicorns.
the class Main method setUp.
/**
* Initialize the bridge and the resource maps.
*/
@BeforeClass
public static void setUp() {
File data_dir = new File(PLATFORM_DIR, "data");
File res = new File(data_dir, "res");
sFrameworkRepo = new FrameworkResources(new FolderWrapper(res));
sFrameworkRepo.loadResources();
sFrameworkRepo.loadPublicResources(getLogger());
sProjectResources = new ResourceRepository(new FolderWrapper(TEST_RES_DIR + APP_TEST_RES), false) {
@NonNull
@Override
protected ResourceItem createResourceItem(@NonNull String name) {
return new ResourceItem(name);
}
};
sProjectResources.loadResources();
File fontLocation = new File(data_dir, "fonts");
File buildProp = new File(PLATFORM_DIR, "build.prop");
File attrs = new File(res, "values" + File.separator + "attrs.xml");
sBridge = new Bridge();
sBridge.init(ConfigGenerator.loadProperties(buildProp), fontLocation, ConfigGenerator.getEnumMap(attrs), getLayoutLog());
}
use of com.android.layoutlib.bridge.Bridge in project android_frameworks_base by AOSPA.
the class Main method setUp.
/**
* Initialize the bridge and the resource maps.
*/
@BeforeClass
public static void setUp() {
File data_dir = new File(PLATFORM_DIR, "data");
File res = new File(data_dir, "res");
sFrameworkRepo = new FrameworkResources(new FolderWrapper(res));
sFrameworkRepo.loadResources();
sFrameworkRepo.loadPublicResources(getLogger());
sProjectResources = new ResourceRepository(new FolderWrapper(TEST_RES_DIR + APP_TEST_RES), false) {
@NonNull
@Override
protected ResourceItem createResourceItem(@NonNull String name) {
return new ResourceItem(name);
}
};
sProjectResources.loadResources();
File fontLocation = new File(data_dir, "fonts");
File buildProp = new File(PLATFORM_DIR, "build.prop");
File attrs = new File(res, "values" + File.separator + "attrs.xml");
sBridge = new Bridge();
sBridge.init(ConfigGenerator.loadProperties(buildProp), fontLocation, ConfigGenerator.getEnumMap(attrs), getLayoutLog());
}
use of com.android.layoutlib.bridge.Bridge in project android_frameworks_base by crdroidandroid.
the class Main method setUp.
/**
* Initialize the bridge and the resource maps.
*/
@BeforeClass
public static void setUp() {
File data_dir = new File(PLATFORM_DIR, "data");
File res = new File(data_dir, "res");
sFrameworkRepo = new FrameworkResources(new FolderWrapper(res));
sFrameworkRepo.loadResources();
sFrameworkRepo.loadPublicResources(getLogger());
sProjectResources = new ResourceRepository(new FolderWrapper(TEST_RES_DIR + APP_TEST_RES), false) {
@NonNull
@Override
protected ResourceItem createResourceItem(@NonNull String name) {
return new ResourceItem(name);
}
};
sProjectResources.loadResources();
File fontLocation = new File(data_dir, "fonts");
File buildProp = new File(PLATFORM_DIR, "build.prop");
File attrs = new File(res, "values" + File.separator + "attrs.xml");
sBridge = new Bridge();
sBridge.init(ConfigGenerator.loadProperties(buildProp), fontLocation, ConfigGenerator.getEnumMap(attrs), getLayoutLog());
}
use of com.android.layoutlib.bridge.Bridge in project android by JetBrains.
the class LayoutLibraryLoader method load.
@Nullable
public static LayoutLibrary load(@NotNull IAndroidTarget target, @NotNull Map<String, Map<String, Integer>> enumMap) throws RenderingException, IOException {
final String fontFolderPath = FileUtil.toSystemIndependentName((target.getPath(IAndroidTarget.FONTS)));
final VirtualFile fontFolder = LocalFileSystem.getInstance().findFileByPath(fontFolderPath);
if (fontFolder == null || !fontFolder.isDirectory()) {
throw new RenderingException(LayoutlibBundle.message("android.directory.cannot.be.found.error", FileUtil.toSystemDependentName(fontFolderPath)));
}
final String platformFolderPath = target.isPlatform() ? target.getLocation() : target.getParent().getLocation();
final File platformFolder = new File(platformFolderPath);
if (!platformFolder.isDirectory()) {
throw new RenderingException(LayoutlibBundle.message("android.directory.cannot.be.found.error", FileUtil.toSystemDependentName(platformFolderPath)));
}
final File buildProp = new File(platformFolder, SdkConstants.FN_BUILD_PROP);
if (!buildProp.isFile()) {
throw new RenderingException(LayoutlibBundle.message("android.file.not.exist.error", FileUtil.toSystemDependentName(buildProp.getPath())));
}
if (!SystemInfo.isJavaVersionAtLeast("1.8") && target.getVersion().getFeatureLevel() >= 24) {
// From N, we require to be running in Java 8
throw new UnsupportedJavaRuntimeException(LayoutlibBundle.message("android.layout.preview.unsupported.jdk", SdkVersionInfo.getCodeName(target.getVersion().getFeatureLevel())));
}
LayoutLibrary library;
final ILogger logger = new LogWrapper(LOG);
if (USE_SDK_LAYOUTLIB) {
final String resFolderPath = FileUtil.toSystemIndependentName((target.getPath(IAndroidTarget.RESOURCES)));
final VirtualFile resFolder = LocalFileSystem.getInstance().findFileByPath(resFolderPath);
if (resFolder == null || !resFolder.isDirectory()) {
throw new RenderingException(LayoutlibBundle.message("android.directory.cannot.be.found.error", FileUtil.toSystemDependentName(resFolderPath)));
}
final String layoutLibJarPath = FileUtil.toSystemIndependentName((target.getPath(IAndroidTarget.LAYOUT_LIB)));
final VirtualFile layoutLibJar = LocalFileSystem.getInstance().findFileByPath(layoutLibJarPath);
if (layoutLibJar == null || layoutLibJar.isDirectory()) {
throw new RenderingException(LayoutlibBundle.message("android.file.not.exist.error", FileUtil.toSystemDependentName(layoutLibJarPath)));
}
library = LayoutLibrary.load(layoutLibJar.getPath(), logger, ApplicationNamesInfo.getInstance().getFullProductName());
} else {
// We instantiate the local Bridge implementation and pass it to the LayoutLibrary instance
library = LayoutLibrary.load(new Bridge(), LayoutLibraryLoader.class.getClassLoader());
}
if (library.getStatus() != LoadStatus.LOADED) {
throw new RenderingException(library.getLoadMessage());
}
final Map<String, String> buildPropMap = ProjectProperties.parsePropertyFile(new BufferingFileWrapper(buildProp), logger);
final LayoutLog layoutLog = new LayoutLogWrapper(LOG);
if (library.init(buildPropMap, new File(fontFolder.getPath()), enumMap, layoutLog)) {
return library;
} else {
return null;
}
}
Aggregations