1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-05 10:49:24 +02:00

assets instead of our own resources file mechanism

This commit is contained in:
Nikolay Pultsin 2010-11-06 05:29:34 +00:00
parent ee7fcb6413
commit c74164d1da
72 changed files with 59 additions and 28 deletions

View file

@ -9,7 +9,6 @@ menu_icons_dir = "icons/menu"
tabs_icons_dir = "icons/tabs"
others_icons_dir = "icons/others"
text_search_icons_dir = "icons/text_search"
data_dir = "data"
def clean_res_dir(dir):
if os.path.exists(dir):
@ -31,7 +30,6 @@ def process_data_dir(prefix, dir, res_dir, replace_dot = 1):
clean_res_dir(raw_res_dir)
clean_res_dir(drawable_res_dir)
process_data_dir("data__", data_dir, raw_res_dir)
shutil.copyfile("icons/fbreader.png", drawable_res_dir + "/fbreader.png")
process_data_dir("", tree_icons_dir, drawable_res_dir, 0)
process_data_dir("", menu_icons_dir, drawable_res_dir, 0)

View file

@ -32,7 +32,7 @@ abstract class FB2TagManager {
static ArrayList<Tag> humanReadableTags(String id) {
if (ourMap.isEmpty()) {
new FB2TagInfoReader().read(
ZLResourceFile.createResourceFile("data/formats/fb2/fb2genres.xml")
ZLResourceFile.createResourceFile("formats/fb2/fb2genres.xml")
);
}
return ourMap.get(id);

View file

@ -218,9 +218,9 @@ cycle:
public static List<String> xhtmlDTDs() {
if (ourExternalDTDs.isEmpty()) {
ourExternalDTDs.add("data/formats/xhtml/xhtml-lat1.ent");
ourExternalDTDs.add("data/formats/xhtml/xhtml-special.ent");
ourExternalDTDs.add("data/formats/xhtml/xhtml-symbol.ent");
ourExternalDTDs.add("formats/xhtml/xhtml-lat1.ent");
ourExternalDTDs.add("formats/xhtml/xhtml-special.ent");
ourExternalDTDs.add("formats/xhtml/xhtml-symbol.ent");
}
return ourExternalDTDs;
}

View file

@ -53,13 +53,13 @@ public final class Library {
public static ZLResourceFile getHelpFile() {
final ZLResourceFile file = ZLResourceFile.createResourceFile(
"data/help/MiniHelp." + Locale.getDefault().getLanguage() + ".fb2"
"help/MiniHelp." + Locale.getDefault().getLanguage() + ".fb2"
);
if (file.exists()) {
return file;
}
return ZLResourceFile.createResourceFile("data/help/MiniHelp.en.fb2");
return ZLResourceFile.createResourceFile("help/MiniHelp.en.fb2");
}
private static Book getBook(ZLFile bookFile, FileInfoSet fileInfos, Map<Long,Book> saved, boolean doReadMetaInfo) {

View file

@ -144,7 +144,7 @@ class OPDSLinkXMLReader extends OPDSXMLReader {
}
final String sslCertificate;
final String path = "data/network/" + siteName + ".crt";
final String path = "network/" + siteName + ".crt";
if (ZLResourceFile.createResourceFile(path).exists()) {
sslCertificate = path;
} else {

View file

@ -52,7 +52,7 @@ public abstract class ZLApplication {
protected ZLApplication() {
ourInstance = this;
new MenubarCreator().read(ZLResourceFile.createResourceFile("data/default/menubar.xml"));
new MenubarCreator().read(ZLResourceFile.createResourceFile("default/menubar.xml"));
}
final Menubar getMenubar() {

View file

@ -50,6 +50,6 @@ class ZLKeyBindingsReader extends ZLXMLReaderAdapter {
}
public void readBindings() {
read(ZLResourceFile.createResourceFile("data/default/keymap.xml"));
read(ZLResourceFile.createResourceFile("default/keymap.xml"));
}
}

View file

@ -39,7 +39,7 @@ public final class ZLEncodingCollection {
private ZLEncodingCollection() {
new ZLEncodingCollectionReader().read(
ZLResourceFile.createResourceFile("data/encodings/Encodings.xml")
ZLResourceFile.createResourceFile("encodings/Encodings.xml")
);
}

View file

@ -55,6 +55,6 @@ public abstract class ZLLanguageList {
}
public static ZLFile patternsFile() {
return ZLResourceFile.createResourceFile("data/languagePatterns.tar");
return ZLResourceFile.createResourceFile("languagePatterns.tar");
}
}

View file

@ -65,8 +65,8 @@ final class ZLTreeResource extends ZLResource {
public static void loadData(String language) {
final String fileName = language + ".xml";
ResourceTreeReader reader = new ResourceTreeReader();
reader.readDocument(ourRoot, ZLResourceFile.createResourceFile("data/resources/zlibrary/" + fileName));
reader.readDocument(ourRoot, ZLResourceFile.createResourceFile("data/resources/application/" + fileName));
reader.readDocument(ourRoot, ZLResourceFile.createResourceFile("resources/zlibrary/" + fileName));
reader.readDocument(ourRoot, ZLResourceFile.createResourceFile("resources/application/" + fileName));
}
private ZLTreeResource(String name, String value) {

View file

@ -44,7 +44,7 @@ public final class ZLTextTeXHyphenator extends ZLTextHyphenator {
if (language != null) {
new ZLTextHyphenationReader(this).read(ZLResourceFile.createResourceFile(
"data/hyphenationPatterns/" + language + ".pattern"
"hyphenationPatterns/" + language + ".pattern"
));
}
}

View file

@ -31,7 +31,7 @@ public class ZLTextStyleCollection {
private final ZLTextStyleDecoration[] myDecorationMap = new ZLTextStyleDecoration[256];
private ZLTextStyleCollection() {
new TextStyleReader(this).read(ZLResourceFile.createResourceFile("data/default/styles.xml"));
new TextStyleReader(this).read(ZLResourceFile.createResourceFile("default/styles.xml"));
}
public static ZLTextStyleCollection Instance() {

View file

@ -98,7 +98,12 @@ public final class ZLAndroidLibrary extends ZLibrary {
@Override
public ZLResourceFile createResourceFile(String path) {
return new AndroidResourceFile(path);
final String drawablePrefix = "R.drawable.";
if (path.startsWith(drawablePrefix)) {
return new AndroidResourceFile(path.substring(drawablePrefix.length()));
} else {
return new AndroidAssetsFile(path);
}
}
@Override
@ -131,17 +136,10 @@ public final class ZLAndroidLibrary extends ZLibrary {
private boolean myExists;
private int myResourceId;
AndroidResourceFile(String path) {
super(path);
final String drawablePrefix = "R.drawable.";
AndroidResourceFile(String fieldName) {
super(fieldName);
try {
if (path.startsWith(drawablePrefix)) {
final String fieldName = path.substring(drawablePrefix.length());
myResourceId = R.drawable.class.getField(fieldName).getInt(null);
} else {
final String fieldName = path.replace("/", "__").replace(".", "_").replace("-", "_").toLowerCase();
myResourceId = R.raw.class.getField(fieldName).getInt(null);
}
myExists = true;
} catch (NoSuchFieldException e) {
} catch (IllegalAccessException e) {
@ -180,4 +178,39 @@ public final class ZLAndroidLibrary extends ZLibrary {
}
}
}
private final class AndroidAssetsFile extends ZLResourceFile {
AndroidAssetsFile(String path) {
super(path);
System.err.println("file " + path + " : " + exists());
}
@Override
public boolean exists() {
try {
AssetFileDescriptor descriptor = myActivity.getAssets().openFd(getPath());
descriptor.close();
return true;
} catch (IOException e) {
return false;
}
}
@Override
public long size() {
try {
AssetFileDescriptor descriptor = myActivity.getAssets().openFd(getPath());
long length = descriptor.getLength();
descriptor.close();
return length;
} catch (IOException e) {
return 0;
}
}
@Override
public InputStream getInputStream() throws IOException {
return myActivity.getAssets().open(getPath());
}
}
}