1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-04 18:29:23 +02:00

work in progress

This commit is contained in:
Nikolay Pultsin 2010-12-18 13:26:37 +00:00
parent aba621c9de
commit 93e3df976b
11 changed files with 69 additions and 67 deletions

View file

@ -38,7 +38,6 @@ import android.widget.TextView;
import org.geometerplus.zlibrary.core.filesystem.ZLFile; import org.geometerplus.zlibrary.core.filesystem.ZLFile;
import org.geometerplus.zlibrary.core.image.ZLImage; import org.geometerplus.zlibrary.core.image.ZLImage;
import org.geometerplus.zlibrary.core.image.ZLImageProxy;
import org.geometerplus.zlibrary.core.image.ZLLoadableImage; import org.geometerplus.zlibrary.core.image.ZLLoadableImage;
import org.geometerplus.zlibrary.core.resources.ZLResource; import org.geometerplus.zlibrary.core.resources.ZLResource;
@ -49,10 +48,7 @@ import org.geometerplus.zlibrary.ui.android.image.ZLAndroidImageManager;
import org.geometerplus.fbreader.bookmodel.BookModel; import org.geometerplus.fbreader.bookmodel.BookModel;
import org.geometerplus.fbreader.formats.FormatPlugin; import org.geometerplus.fbreader.formats.FormatPlugin;
import org.geometerplus.fbreader.formats.PluginCollection; import org.geometerplus.fbreader.formats.PluginCollection;
import org.geometerplus.fbreader.library.Author; import org.geometerplus.fbreader.library.*;
import org.geometerplus.fbreader.library.Book;
import org.geometerplus.fbreader.library.SeriesInfo;
import org.geometerplus.fbreader.library.Tag;
import org.geometerplus.android.fbreader.preferences.BookInfoActivity; import org.geometerplus.android.fbreader.preferences.BookInfoActivity;
@ -61,6 +57,7 @@ public class BookStatusActivity extends Activity {
private final ZLResource myResource = ZLResource.resource("bookInfo"); private final ZLResource myResource = ZLResource.resource("bookInfo");
private Book myBook; private Book myBook;
private ZLImage myImage;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -69,12 +66,15 @@ public class BookStatusActivity extends Activity {
new org.geometerplus.zlibrary.ui.android.library.UncaughtExceptionHandler(this) new org.geometerplus.zlibrary.ui.android.library.UncaughtExceptionHandler(this)
); );
final String path = getIntent().getStringExtra(CURRENT_BOOK_PATH_KEY);
final ZLFile file = ZLFile.createFileByPath(path);
myImage = Library.getCover(file);
if (SQLiteBooksDatabase.Instance() == null) { if (SQLiteBooksDatabase.Instance() == null) {
new SQLiteBooksDatabase(this, "LIBRARY"); new SQLiteBooksDatabase(this, "LIBRARY");
} }
final String path = getIntent().getStringExtra(CURRENT_BOOK_PATH_KEY);
final ZLFile file = ZLFile.createFileByPath(path);
myBook = Book.getByFile(file); myBook = Book.getByFile(file);
requestWindowFeature(Window.FEATURE_NO_TITLE); requestWindowFeature(Window.FEATURE_NO_TITLE);
@ -138,7 +138,7 @@ public class BookStatusActivity extends Activity {
} }
private void setupCover(Book book) { private void setupCover(Book book) {
final ImageView coverView = (ImageView) findViewById(R.id.book_cover); final ImageView coverView = (ImageView)findViewById(R.id.book_cover);
final int maxHeight = 250; // FIXME: hardcoded constant final int maxHeight = 250; // FIXME: hardcoded constant
final int maxWidth = maxHeight * 3 / 4; final int maxWidth = maxHeight * 3 / 4;
@ -146,21 +146,15 @@ public class BookStatusActivity extends Activity {
coverView.setVisibility(View.GONE); coverView.setVisibility(View.GONE);
coverView.setImageDrawable(null); coverView.setImageDrawable(null);
final FormatPlugin plugin = PluginCollection.Instance().getPlugin(book.File); if (myImage == null) {
if (plugin == null) {
return; return;
} }
final ZLImage image = plugin.readCover(book); if (myImage instanceof ZLLoadableImage) {
if (image == null) { ((ZLLoadableImage)myImage).synchronize();
return;
}
if (image instanceof ZLLoadableImage) {
((ZLLoadableImage)image).synchronize();
} }
final ZLAndroidImageData data = final ZLAndroidImageData data =
((ZLAndroidImageManager)ZLAndroidImageManager.Instance()).getImageData(image); ((ZLAndroidImageManager)ZLAndroidImageManager.Instance()).getImageData(myImage);
if (data == null) { if (data == null) {
return; return;
} }

View file

@ -268,11 +268,7 @@ public final class FileManager extends BaseActivity {
public ZLImage getCover() { public ZLImage getCover() {
if (!myCoverIsInitialized) { if (!myCoverIsInitialized) {
myCoverIsInitialized = true; myCoverIsInitialized = true;
final Book book = getBook(); myCover = Library.getCover(myFile);
final FormatPlugin plugin = PluginCollection.Instance().getPlugin(myFile);
if (book != null && plugin != null) {
myCover = plugin.readCover(book);
}
} }
return myCover; return myCover;
} }

View file

@ -24,10 +24,8 @@ import java.util.Set;
import android.app.Activity; import android.app.Activity;
import android.app.Dialog; import android.app.Dialog;
import android.os.Bundle; import android.os.Bundle;
//import android.util.StringBuilderPrinter;
import android.view.View; import android.view.View;
import android.widget.ImageView; import android.widget.ImageView;
//import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import android.content.Intent; import android.content.Intent;
import android.graphics.Bitmap; import android.graphics.Bitmap;
@ -43,9 +41,7 @@ import org.geometerplus.zlibrary.ui.android.image.ZLAndroidImageData;
import org.geometerplus.fbreader.network.*; import org.geometerplus.fbreader.network.*;
public class NetworkBookInfoActivity extends Activity implements NetworkView.EventListener { public class NetworkBookInfoActivity extends Activity implements NetworkView.EventListener {
private NetworkBookItem myBook; private NetworkBookItem myBook;
private final ZLResource myResource = ZLResource.resource("networkBookView"); private final ZLResource myResource = ZLResource.resource("networkBookView");
@ -79,27 +75,6 @@ public class NetworkBookInfoActivity extends Activity implements NetworkView.Eve
setupInfo(); setupInfo();
setupCover(); setupCover();
setupButtons(); setupButtons();
/*LinearLayout layout = (LinearLayout) findViewById(R.id.network_book_cover).getParent();
TextView detailsTitle = new TextView(this, null, android.R.attr.listSeparatorTextViewStyle);
TextView details = new TextView(this);
detailsTitle.setText("Debug Details");
StringBuilder builder = new StringBuilder();
StringBuilderPrinter printer = new StringBuilderPrinter(builder);
printer.println("Id = " + myBook.Id);
printer.println("Index = " + myBook.Index);
printer.println("Cover = " + myBook.Cover);
printer.println("References (" + myBook.myReferences.size() + "):");
for (BookReference ref: myBook.myReferences) {
printer.println( ref.toString() );
}
details.setText(builder.toString());
layout.addView(detailsTitle);
layout.addView(details);*/
} }
@Override @Override

View file

@ -28,7 +28,7 @@ public abstract class FormatPlugin {
public abstract boolean acceptsFile(ZLFile file); public abstract boolean acceptsFile(ZLFile file);
public abstract boolean readMetaInfo(Book book); public abstract boolean readMetaInfo(Book book);
public abstract boolean readModel(BookModel model); public abstract boolean readModel(BookModel model);
public abstract ZLImage readCover(Book book); public abstract ZLImage readCover(ZLFile file);
/* /*
public static void detectEncodingAndLanguage(Book book, InputStream stream) throws IOException { public static void detectEncodingAndLanguage(Book book, InputStream stream) throws IOException {

View file

@ -42,7 +42,7 @@ public class FB2Plugin extends FormatPlugin {
} }
@Override @Override
public ZLImage readCover(Book book) { public ZLImage readCover(ZLFile file) {
return new FB2CoverReader().readCover(book.File); return new FB2CoverReader().readCover(file);
} }
} }

View file

@ -50,7 +50,7 @@ public class HtmlPlugin extends FormatPlugin {
} }
@Override @Override
public ZLImage readCover(Book book) { public ZLImage readCover(ZLFile file) {
return null; return null;
} }
} }

View file

@ -58,8 +58,8 @@ public class OEBPlugin extends FormatPlugin {
} }
@Override @Override
public ZLImage readCover(Book book) { public ZLImage readCover(ZLFile file) {
final ZLFile opfFile = getOpfFile(book.File); final ZLFile opfFile = getOpfFile(file);
return (opfFile != null) ? new OEBCoverReader().readCover(opfFile) : null; return (opfFile != null) ? new OEBCoverReader().readCover(opfFile) : null;
} }
} }

View file

@ -133,10 +133,10 @@ public class MobipocketPlugin extends PdbPlugin {
} }
@Override @Override
public ZLImage readCover(Book book) { public ZLImage readCover(ZLFile file) {
InputStream stream = null; InputStream stream = null;
try { try {
stream = book.File.getInputStream(); stream = file.getInputStream();
final PdbHeader header = new PdbHeader(stream); final PdbHeader header = new PdbHeader(stream);
PdbUtil.skip(stream, header.Offsets[0] + 16 - header.length()); PdbUtil.skip(stream, header.Offsets[0] + 16 - header.length());
if (PdbUtil.readInt(stream) != 0x4D4F4249) /* "MOBI" */ { if (PdbUtil.readInt(stream) != 0x4D4F4249) /* "MOBI" */ {
@ -202,11 +202,10 @@ public class MobipocketPlugin extends PdbPlugin {
coverIndex = thumbIndex; coverIndex = thumbIndex;
} }
final ZLFile file = book.File;
final MobipocketStream mpStream = new MobipocketStream(file);
// TODO: implement // TODO: implement
/*int index = pbStream.firstImageLocationIndex(file.path()); /*final MobipocketStream mpStream = new MobipocketStream(file);
int index = pbStream.firstImageLocationIndex(file.path());
if (index >= 0) { if (index >= 0) {
std::pair<int,int> imageLocation = pbStream.imageLocation(pbStream.header(), index + coverIndex); std::pair<int,int> imageLocation = pbStream.imageLocation(pbStream.header(), index + coverIndex);
if ((imageLocation.first > 0) && (imageLocation.second > 0)) { if ((imageLocation.first > 0) && (imageLocation.second > 0)) {

View file

@ -57,7 +57,7 @@ public class PluckerPlugin extends PdbPlugin {
} }
@Override @Override
public ZLImage readCover(Book book) { public ZLImage readCover(ZLFile file) {
return null; return null;
} }
} }

View file

@ -60,11 +60,6 @@ public class BookTree extends LibraryTree {
@Override @Override
protected ZLImage createCover() { protected ZLImage createCover() {
final FormatPlugin plugin = PluginCollection.Instance().getPlugin(Book.File); return Library.getCover(Book.File);
if (plugin != null) {
return plugin.readCover(Book);
}
return null;
} }
} }

View file

@ -21,10 +21,14 @@ package org.geometerplus.fbreader.library;
import java.io.File; import java.io.File;
import java.util.*; import java.util.*;
//import java.lang.ref.WeakReference;
import org.geometerplus.zlibrary.core.filesystem.*; import org.geometerplus.zlibrary.core.filesystem.*;
import org.geometerplus.zlibrary.core.image.ZLImage;
import org.geometerplus.zlibrary.core.util.ZLMiscUtil; import org.geometerplus.zlibrary.core.util.ZLMiscUtil;
import org.geometerplus.fbreader.formats.FormatPlugin;
import org.geometerplus.fbreader.formats.PluginCollection;
import org.geometerplus.fbreader.Paths; import org.geometerplus.fbreader.Paths;
public final class Library { public final class Library {
@ -425,4 +429,43 @@ public final class Library {
book.File.getPhysicalFile().delete(); book.File.getPhysicalFile().delete();
} }
} }
/*
private static final HashMap<String,WeakReference<ZLImage>> ourCoverMap =
new HashMap<String,WeakReference<ZLImage>>();
private static final WeakReference<ZLImage> NULL_IMAGE = new WeakReference<ZLImage>(null);
*/
public static ZLImage getCover(ZLFile file) {
final FormatPlugin plugin = PluginCollection.Instance().getPlugin(file);
if (plugin != null) {
return plugin.readCover(file);
}
return null;
/*
synchronized(ourCoverMap) {
final String path = file.getPath();
final WeakReference<ZLImage> ref = ourCoverMap.get(path);
if (ref == NULL_IMAGE) {
return null;
} else if (ref != null) {
final ZLImage image = ref.get();
if (image != null) {
return image;
}
}
ZLImage image = null;
final FormatPlugin plugin = PluginCollection.Instance().getPlugin(file);
if (plugin != null) {
image = plugin.readCover(file);
}
if (image == null) {
ourCoverMap.put(path, NULL_IMAGE);
} else {
ourCoverMap.put(path, new WeakReference<ZLImage>(image));
}
return image;
}
*/
}
} }