mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-03 01:39:18 +02:00
Method to save covers
This commit is contained in:
parent
0f02d4e923
commit
abc27fd653
7 changed files with 120 additions and 1 deletions
|
@ -464,4 +464,16 @@ public class BookCollectionShadow extends AbstractBookCollection implements Serv
|
|||
// method from ServiceConnection interface
|
||||
public synchronized void onServiceDisconnected(ComponentName name) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void saveCovers() {
|
||||
if (myInterface == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
myInterface.saveCovers();
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,4 +48,6 @@ interface LibraryInterface {
|
|||
String getHighlightingStyle(in int styleId);
|
||||
List<String> highlightingStyles();
|
||||
void saveHighlightingStyle(in String style);
|
||||
|
||||
void saveCovers();
|
||||
}
|
||||
|
|
|
@ -273,6 +273,10 @@ public class LibraryService extends Service {
|
|||
public void saveHighlightingStyle(String style) {
|
||||
myCollection.saveHighlightingStyle(SerializerUtil.deserializeStyle(style));
|
||||
}
|
||||
|
||||
public void saveCovers() {
|
||||
myCollection.saveCovers();
|
||||
}
|
||||
}
|
||||
|
||||
private volatile LibraryImplementation myLibrary;
|
||||
|
|
|
@ -20,16 +20,27 @@
|
|||
package org.geometerplus.fbreader.book;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.*;
|
||||
|
||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||
import org.geometerplus.zlibrary.core.filesystem.ZLPhysicalFile;
|
||||
import org.geometerplus.zlibrary.core.image.ZLImage;
|
||||
import org.geometerplus.zlibrary.core.image.ZLLoadableImage;
|
||||
|
||||
import org.geometerplus.zlibrary.text.view.ZLTextPosition;
|
||||
import org.geometerplus.zlibrary.ui.android.image.ZLAndroidImageData;
|
||||
import org.geometerplus.zlibrary.ui.android.image.ZLAndroidImageManager;
|
||||
|
||||
import org.geometerplus.fbreader.bookmodel.BookReadingException;
|
||||
import org.geometerplus.fbreader.formats.*;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Environment;
|
||||
|
||||
public class BookCollection extends AbstractBookCollection {
|
||||
private final BooksDatabase myDatabase;
|
||||
public final List<String> BookDirectories;
|
||||
|
@ -680,4 +691,59 @@ public class BookCollection extends AbstractBookCollection {
|
|||
myDatabase.saveStyle(style);
|
||||
fireBookEvent(BookEvent.BookmarkStyleChanged, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveCovers() {
|
||||
for (BookQuery query = new BookQuery(new Filter.Empty(), 20); ; query = query.next()) {
|
||||
final List<Book> partOfBooks = books(query);
|
||||
if (partOfBooks.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
for (Book b : partOfBooks) {
|
||||
saveCover(b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void saveCover(Book b) {
|
||||
final ZLImage image = BookUtil.getCover(b);
|
||||
|
||||
if (image == null) {
|
||||
return;
|
||||
}
|
||||
if (image instanceof ZLLoadableImage) {
|
||||
final ZLLoadableImage loadableImage = (ZLLoadableImage)image;
|
||||
if (!loadableImage.isSynchronized()) {
|
||||
loadableImage.synchronize();
|
||||
}
|
||||
}
|
||||
final ZLAndroidImageData data =
|
||||
((ZLAndroidImageManager)ZLAndroidImageManager.Instance()).getImageData(image);
|
||||
if (data == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Bitmap coverBitmap = data.getFullSizeBitmap();
|
||||
if (coverBitmap == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
|
||||
|
||||
File myPath = new File(extStorageDirectory, "/FBReaderJ/Covers");
|
||||
myPath.mkdirs();
|
||||
|
||||
OutputStream outStream = null;
|
||||
File file = new File(myPath, b.getId() + ".PNG");
|
||||
try {
|
||||
outStream = new FileOutputStream(file);
|
||||
coverBitmap.compress(Bitmap.CompressFormat.PNG, 100, outStream);
|
||||
outStream.flush();
|
||||
outStream.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,4 +86,6 @@ public interface IBookCollection {
|
|||
HighlightingStyle getHighlightingStyle(int styleId);
|
||||
List<HighlightingStyle> highlightingStyles();
|
||||
void saveHighlightingStyle(HighlightingStyle style);
|
||||
|
||||
void saveCovers();
|
||||
}
|
||||
|
|
33
third-party/AmbilWarna/.project
vendored
Normal file
33
third-party/AmbilWarna/.project
vendored
Normal file
|
@ -0,0 +1,33 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>AmbilWarna</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
2
third-party/AmbilWarna/project.properties
vendored
2
third-party/AmbilWarna/project.properties
vendored
|
@ -11,4 +11,4 @@ android.library=true
|
|||
# Indicates whether an apk should be generated for each density.
|
||||
split.density=false
|
||||
# Project target.
|
||||
target=android-11
|
||||
target=android-14
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue