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:
parent
ee7fcb6413
commit
c74164d1da
72 changed files with 59 additions and 28 deletions
|
@ -9,7 +9,6 @@ menu_icons_dir = "icons/menu"
|
||||||
tabs_icons_dir = "icons/tabs"
|
tabs_icons_dir = "icons/tabs"
|
||||||
others_icons_dir = "icons/others"
|
others_icons_dir = "icons/others"
|
||||||
text_search_icons_dir = "icons/text_search"
|
text_search_icons_dir = "icons/text_search"
|
||||||
data_dir = "data"
|
|
||||||
|
|
||||||
def clean_res_dir(dir):
|
def clean_res_dir(dir):
|
||||||
if os.path.exists(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(raw_res_dir)
|
||||||
clean_res_dir(drawable_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")
|
shutil.copyfile("icons/fbreader.png", drawable_res_dir + "/fbreader.png")
|
||||||
process_data_dir("", tree_icons_dir, drawable_res_dir, 0)
|
process_data_dir("", tree_icons_dir, drawable_res_dir, 0)
|
||||||
process_data_dir("", menu_icons_dir, drawable_res_dir, 0)
|
process_data_dir("", menu_icons_dir, drawable_res_dir, 0)
|
||||||
|
|
|
@ -32,7 +32,7 @@ abstract class FB2TagManager {
|
||||||
static ArrayList<Tag> humanReadableTags(String id) {
|
static ArrayList<Tag> humanReadableTags(String id) {
|
||||||
if (ourMap.isEmpty()) {
|
if (ourMap.isEmpty()) {
|
||||||
new FB2TagInfoReader().read(
|
new FB2TagInfoReader().read(
|
||||||
ZLResourceFile.createResourceFile("data/formats/fb2/fb2genres.xml")
|
ZLResourceFile.createResourceFile("formats/fb2/fb2genres.xml")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return ourMap.get(id);
|
return ourMap.get(id);
|
||||||
|
|
|
@ -218,9 +218,9 @@ cycle:
|
||||||
|
|
||||||
public static List<String> xhtmlDTDs() {
|
public static List<String> xhtmlDTDs() {
|
||||||
if (ourExternalDTDs.isEmpty()) {
|
if (ourExternalDTDs.isEmpty()) {
|
||||||
ourExternalDTDs.add("data/formats/xhtml/xhtml-lat1.ent");
|
ourExternalDTDs.add("formats/xhtml/xhtml-lat1.ent");
|
||||||
ourExternalDTDs.add("data/formats/xhtml/xhtml-special.ent");
|
ourExternalDTDs.add("formats/xhtml/xhtml-special.ent");
|
||||||
ourExternalDTDs.add("data/formats/xhtml/xhtml-symbol.ent");
|
ourExternalDTDs.add("formats/xhtml/xhtml-symbol.ent");
|
||||||
}
|
}
|
||||||
return ourExternalDTDs;
|
return ourExternalDTDs;
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,13 +53,13 @@ public final class Library {
|
||||||
|
|
||||||
public static ZLResourceFile getHelpFile() {
|
public static ZLResourceFile getHelpFile() {
|
||||||
final ZLResourceFile file = ZLResourceFile.createResourceFile(
|
final ZLResourceFile file = ZLResourceFile.createResourceFile(
|
||||||
"data/help/MiniHelp." + Locale.getDefault().getLanguage() + ".fb2"
|
"help/MiniHelp." + Locale.getDefault().getLanguage() + ".fb2"
|
||||||
);
|
);
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
return file;
|
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) {
|
private static Book getBook(ZLFile bookFile, FileInfoSet fileInfos, Map<Long,Book> saved, boolean doReadMetaInfo) {
|
||||||
|
|
|
@ -144,7 +144,7 @@ class OPDSLinkXMLReader extends OPDSXMLReader {
|
||||||
}
|
}
|
||||||
|
|
||||||
final String sslCertificate;
|
final String sslCertificate;
|
||||||
final String path = "data/network/" + siteName + ".crt";
|
final String path = "network/" + siteName + ".crt";
|
||||||
if (ZLResourceFile.createResourceFile(path).exists()) {
|
if (ZLResourceFile.createResourceFile(path).exists()) {
|
||||||
sslCertificate = path;
|
sslCertificate = path;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -52,7 +52,7 @@ public abstract class ZLApplication {
|
||||||
protected ZLApplication() {
|
protected ZLApplication() {
|
||||||
ourInstance = this;
|
ourInstance = this;
|
||||||
|
|
||||||
new MenubarCreator().read(ZLResourceFile.createResourceFile("data/default/menubar.xml"));
|
new MenubarCreator().read(ZLResourceFile.createResourceFile("default/menubar.xml"));
|
||||||
}
|
}
|
||||||
|
|
||||||
final Menubar getMenubar() {
|
final Menubar getMenubar() {
|
||||||
|
|
|
@ -50,6 +50,6 @@ class ZLKeyBindingsReader extends ZLXMLReaderAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void readBindings() {
|
public void readBindings() {
|
||||||
read(ZLResourceFile.createResourceFile("data/default/keymap.xml"));
|
read(ZLResourceFile.createResourceFile("default/keymap.xml"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ public final class ZLEncodingCollection {
|
||||||
|
|
||||||
private ZLEncodingCollection() {
|
private ZLEncodingCollection() {
|
||||||
new ZLEncodingCollectionReader().read(
|
new ZLEncodingCollectionReader().read(
|
||||||
ZLResourceFile.createResourceFile("data/encodings/Encodings.xml")
|
ZLResourceFile.createResourceFile("encodings/Encodings.xml")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,6 +55,6 @@ public abstract class ZLLanguageList {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ZLFile patternsFile() {
|
public static ZLFile patternsFile() {
|
||||||
return ZLResourceFile.createResourceFile("data/languagePatterns.tar");
|
return ZLResourceFile.createResourceFile("languagePatterns.tar");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,8 +65,8 @@ final class ZLTreeResource extends ZLResource {
|
||||||
public static void loadData(String language) {
|
public static void loadData(String language) {
|
||||||
final String fileName = language + ".xml";
|
final String fileName = language + ".xml";
|
||||||
ResourceTreeReader reader = new ResourceTreeReader();
|
ResourceTreeReader reader = new ResourceTreeReader();
|
||||||
reader.readDocument(ourRoot, ZLResourceFile.createResourceFile("data/resources/zlibrary/" + fileName));
|
reader.readDocument(ourRoot, ZLResourceFile.createResourceFile("resources/zlibrary/" + fileName));
|
||||||
reader.readDocument(ourRoot, ZLResourceFile.createResourceFile("data/resources/application/" + fileName));
|
reader.readDocument(ourRoot, ZLResourceFile.createResourceFile("resources/application/" + fileName));
|
||||||
}
|
}
|
||||||
|
|
||||||
private ZLTreeResource(String name, String value) {
|
private ZLTreeResource(String name, String value) {
|
||||||
|
|
|
@ -44,7 +44,7 @@ public final class ZLTextTeXHyphenator extends ZLTextHyphenator {
|
||||||
|
|
||||||
if (language != null) {
|
if (language != null) {
|
||||||
new ZLTextHyphenationReader(this).read(ZLResourceFile.createResourceFile(
|
new ZLTextHyphenationReader(this).read(ZLResourceFile.createResourceFile(
|
||||||
"data/hyphenationPatterns/" + language + ".pattern"
|
"hyphenationPatterns/" + language + ".pattern"
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ public class ZLTextStyleCollection {
|
||||||
private final ZLTextStyleDecoration[] myDecorationMap = new ZLTextStyleDecoration[256];
|
private final ZLTextStyleDecoration[] myDecorationMap = new ZLTextStyleDecoration[256];
|
||||||
|
|
||||||
private ZLTextStyleCollection() {
|
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() {
|
public static ZLTextStyleCollection Instance() {
|
||||||
|
|
|
@ -98,7 +98,12 @@ public final class ZLAndroidLibrary extends ZLibrary {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ZLResourceFile createResourceFile(String path) {
|
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
|
@Override
|
||||||
|
@ -131,17 +136,10 @@ public final class ZLAndroidLibrary extends ZLibrary {
|
||||||
private boolean myExists;
|
private boolean myExists;
|
||||||
private int myResourceId;
|
private int myResourceId;
|
||||||
|
|
||||||
AndroidResourceFile(String path) {
|
AndroidResourceFile(String fieldName) {
|
||||||
super(path);
|
super(fieldName);
|
||||||
final String drawablePrefix = "R.drawable.";
|
|
||||||
try {
|
try {
|
||||||
if (path.startsWith(drawablePrefix)) {
|
myResourceId = R.drawable.class.getField(fieldName).getInt(null);
|
||||||
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;
|
myExists = true;
|
||||||
} catch (NoSuchFieldException e) {
|
} catch (NoSuchFieldException e) {
|
||||||
} catch (IllegalAccessException 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());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue