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

new ZLResourceFile logic has been implemented

This commit is contained in:
Nikolay Pultsin 2010-11-08 21:30:44 +00:00
parent eadd934695
commit 94c8ba1885
4 changed files with 31 additions and 9 deletions

View file

@ -88,6 +88,8 @@ public abstract class ZLFile {
} else if ((parent instanceof ZLPhysicalFile) && (parent.getParent() == null)) { } else if ((parent instanceof ZLPhysicalFile) && (parent.getParent() == null)) {
// parent is a directory // parent is a directory
file = new ZLPhysicalFile(parent.getPath() + '/' + name); file = new ZLPhysicalFile(parent.getPath() + '/' + name);
} else if (parent instanceof ZLResourceFile) {
file = ZLResourceFile.createResourceFile((ZLResourceFile)parent, name);
} else { } else {
file = ZLArchiveEntryFile.createArchiveEntryFile(parent, name); file = ZLArchiveEntryFile.createArchiveEntryFile(parent, name);
} }

View file

@ -26,6 +26,10 @@ public abstract class ZLResourceFile extends ZLFile {
return ZLibrary.Instance().createResourceFile(path); return ZLibrary.Instance().createResourceFile(path);
} }
static ZLResourceFile createResourceFile(ZLResourceFile parent, String name) {
return ZLibrary.Instance().createResourceFile(parent, name);
}
private final String myPath; private final String myPath;
protected ZLResourceFile(String path) { protected ZLResourceFile(String path) {
@ -33,10 +37,6 @@ public abstract class ZLResourceFile extends ZLFile {
init(); init();
} }
public boolean isDirectory() {
return false;
}
public String getPath() { public String getPath() {
return myPath; return myPath;
} }
@ -45,10 +45,6 @@ public abstract class ZLResourceFile extends ZLFile {
return myPath.substring(myPath.lastIndexOf('/') + 1); return myPath.substring(myPath.lastIndexOf('/') + 1);
} }
public ZLFile getParent() {
return null;
}
public ZLPhysicalFile getPhysicalFile() { public ZLPhysicalFile getPhysicalFile() {
return null; return null;
} }

View file

@ -34,6 +34,7 @@ public abstract class ZLibrary {
} }
abstract public ZLResourceFile createResourceFile(String path); abstract public ZLResourceFile createResourceFile(String path);
abstract public ZLResourceFile createResourceFile(ZLResourceFile parent, String name);
abstract public String getVersionName(); abstract public String getVersionName();
abstract public String getCurrentTimeString(); abstract public String getCurrentTimeString();

View file

@ -103,6 +103,11 @@ public final class ZLAndroidLibrary extends ZLibrary {
return new AndroidAssetsFile(path); return new AndroidAssetsFile(path);
} }
@Override
public ZLResourceFile createResourceFile(ZLResourceFile parent, String name) {
return new AndroidAssetsFile((AndroidAssetsFile)parent, name);
}
public ZLImage createImage(int drawableId) { public ZLImage createImage(int drawableId) {
return new ZLAndroidResourceBasedImageData(myApplication.getResources(), drawableId); return new ZLAndroidResourceBasedImageData(myApplication.getResources(), drawableId);
} }
@ -144,8 +149,21 @@ public final class ZLAndroidLibrary extends ZLibrary {
} }
private final class AndroidAssetsFile extends ZLResourceFile { private final class AndroidAssetsFile extends ZLResourceFile {
private final AndroidAssetsFile myParent;
AndroidAssetsFile(AndroidAssetsFile parent, String name) {
super(parent.getPath().length() == 0 ? name : parent.getPath() + '/' + name);
myParent = parent;
}
AndroidAssetsFile(String path) { AndroidAssetsFile(String path) {
super(path); super(path);
if (path.length() == 0) {
myParent = null;
} else {
final int index = path.lastIndexOf('/');
myParent = new AndroidAssetsFile(index >= 0 ? path.substring(0, path.lastIndexOf('/')) : "");
}
} }
@Override @Override
@ -155,7 +173,7 @@ public final class ZLAndroidLibrary extends ZLibrary {
if (names != null && names.length != 0) { if (names != null && names.length != 0) {
ArrayList<ZLFile> files = new ArrayList<ZLFile>(names.length); ArrayList<ZLFile> files = new ArrayList<ZLFile>(names.length);
for (String n : names) { for (String n : names) {
files.add(new AndroidAssetsFile(getPath() + "/" + n)); files.add(new AndroidAssetsFile(this, n));
} }
return files; return files;
} }
@ -202,5 +220,10 @@ public final class ZLAndroidLibrary extends ZLibrary {
public InputStream getInputStream() throws IOException { public InputStream getInputStream() throws IOException {
return myApplication.getAssets().open(getPath()); return myApplication.getAssets().open(getPath());
} }
@Override
public ZLFile getParent() {
return myParent;
}
} }
} }