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

drawable -> ZLFile mechanism is gone

This commit is contained in:
Nikolay Pultsin 2010-11-06 11:10:15 +00:00
parent 4b981deadf
commit 0f94dc0e80
8 changed files with 93 additions and 63 deletions

View file

@ -19,8 +19,6 @@
package org.geometerplus.android.fbreader.network;
import org.geometerplus.zlibrary.core.filesystem.ZLResourceFile;
import org.geometerplus.zlibrary.core.image.ZLFileImage;
import org.geometerplus.zlibrary.core.image.ZLImage;
import org.geometerplus.zlibrary.core.resources.ZLResource;
@ -54,7 +52,6 @@ public class AddCustomCatalogItemTree extends NetworkTree {
@Override
protected ZLImage createCover() {
ZLResourceFile file = ((ZLAndroidLibrary)ZLAndroidLibrary.Instance()).createDrawableFile(R.drawable.ic_list_plus);
return new ZLFileImage("image/png", file);
return ((ZLAndroidLibrary)ZLAndroidLibrary.Instance()).createImage(R.drawable.ic_list_plus);
}
}

View file

@ -37,8 +37,6 @@ import android.graphics.Bitmap;
import org.geometerplus.zlibrary.ui.android.R;
import org.geometerplus.zlibrary.core.resources.ZLResource;
import org.geometerplus.zlibrary.core.filesystem.ZLResourceFile;
import org.geometerplus.zlibrary.core.image.ZLFileImage;
import org.geometerplus.zlibrary.core.image.ZLImage;
import org.geometerplus.zlibrary.ui.android.image.ZLAndroidImageManager;
@ -113,10 +111,8 @@ abstract class NetworkBaseActivity extends ListActivity
// this set is used to track whether this activity will be notified, when specific cover will be synchronized.
private HashSet<String> myAwaitedCovers = new HashSet<String>();
private ZLFileImage myFBReaderIcon = new ZLFileImage(
"image/auto",
((ZLAndroidLibrary)ZLAndroidLibrary.Instance()).createDrawableFile(R.drawable.fbreader)
);
private ZLImage myFBReaderIcon =
((ZLAndroidLibrary)ZLAndroidLibrary.Instance()).createImage(R.drawable.fbreader);
private void setupCover(final ImageView coverView, NetworkTree tree, int width, int height) {
Bitmap coverBitmap = null;

View file

@ -24,8 +24,6 @@ import java.util.LinkedList;
import java.util.ListIterator;
import org.geometerplus.zlibrary.core.image.ZLImage;
import org.geometerplus.zlibrary.core.image.ZLFileImage;
import org.geometerplus.zlibrary.core.filesystem.ZLResourceFile;
import org.geometerplus.zlibrary.core.resources.ZLResource;
import org.geometerplus.fbreader.tree.FBTree;
@ -55,8 +53,7 @@ public class SearchItemTree extends NetworkTree {
@Override
protected ZLImage createCover() {
ZLResourceFile file = ((ZLAndroidLibrary)ZLAndroidLibrary.Instance()).createDrawableFile(R.drawable.ic_list_searchresult);
return new ZLFileImage("image/png", file);
return ((ZLAndroidLibrary)ZLAndroidLibrary.Instance()).createImage(R.drawable.ic_list_searchresult);
}
public void setSearchResult(SearchResult result) {

View file

@ -0,0 +1,35 @@
/*
* Copyright (C) 2007-2010 Geometer Plus <contact@geometerplus.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
package org.geometerplus.zlibrary.ui.android.image;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
final class ZLAndroidArrayBasedImageData extends ZLAndroidImageData {
private final byte[] myArray;
ZLAndroidArrayBasedImageData(byte[] array) {
myArray = array;
}
protected Bitmap decodeWithOptions(BitmapFactory.Options options) {
return BitmapFactory.decodeByteArray(myArray, 0, myArray.length, options);
}
}

View file

@ -24,18 +24,18 @@ import android.graphics.BitmapFactory;
import org.geometerplus.zlibrary.core.image.ZLImageData;
public final class ZLAndroidImageData implements ZLImageData {
private byte[] myArray;
public abstract class ZLAndroidImageData implements ZLImageData {
private Bitmap myBitmap;
private int myRealWidth;
private int myRealHeight;
private int myLastRequestedWidth;
private int myLastRequestedHeight;
ZLAndroidImageData(byte[] array) {
myArray = array;
protected ZLAndroidImageData() {
}
protected abstract Bitmap decodeWithOptions(BitmapFactory.Options options);
public synchronized Bitmap getBitmap(int maxWidth, int maxHeight) {
if ((maxWidth == 0) || (maxHeight == 0)) {
return null;
@ -49,7 +49,7 @@ public final class ZLAndroidImageData implements ZLImageData {
final BitmapFactory.Options options = new BitmapFactory.Options();
if (myRealWidth <= 0) {
options.inJustDecodeBounds = true;
BitmapFactory.decodeByteArray(myArray, 0, myArray.length, options);
decodeWithOptions(options);
myRealWidth = options.outWidth;
myRealHeight = options.outHeight;
}
@ -60,7 +60,7 @@ public final class ZLAndroidImageData implements ZLImageData {
coefficient *= 2;
}
options.inSampleSize = coefficient;
myBitmap = BitmapFactory.decodeByteArray(myArray, 0, myArray.length, options);
myBitmap = decodeWithOptions(options);
if (myBitmap != null) {
myLastRequestedWidth = maxWidth;
myLastRequestedHeight = maxHeight;

View file

@ -23,7 +23,9 @@ import org.geometerplus.zlibrary.core.image.*;
public final class ZLAndroidImageManager extends ZLImageManager {
public ZLAndroidImageData getImageData(ZLImage image) {
if (image instanceof ZLSingleImage) {
if (image instanceof ZLAndroidImageData) {
return (ZLAndroidImageData)image;
} else if (image instanceof ZLSingleImage) {
ZLSingleImage singleImage = (ZLSingleImage)image;
if ("image/palm".equals(singleImage.mimeType())) {
return null;
@ -32,7 +34,7 @@ public final class ZLAndroidImageManager extends ZLImageManager {
if (array == null) {
return null;
}
return new ZLAndroidImageData(array);
return new ZLAndroidArrayBasedImageData(array);
} else {
//TODO
return null;

View file

@ -0,0 +1,40 @@
/*
* Copyright (C) 2007-2010 Geometer Plus <contact@geometerplus.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
package org.geometerplus.zlibrary.ui.android.image;
import org.geometerplus.zlibrary.core.image.ZLImage;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.content.res.Resources;
public final class ZLAndroidResourceBasedImageData extends ZLAndroidImageData implements ZLImage {
private final Resources myResources;
private final int myId;
public ZLAndroidResourceBasedImageData(Resources resources, int id) {
myResources = resources;
myId = id;
}
protected Bitmap decodeWithOptions(BitmapFactory.Options options) {
return BitmapFactory.decodeResource(myResources, myId, options);
}
}

View file

@ -32,10 +32,12 @@ import android.text.format.DateFormat;
import org.geometerplus.zlibrary.core.library.ZLibrary;
import org.geometerplus.zlibrary.core.filesystem.ZLResourceFile;
import org.geometerplus.zlibrary.core.network.ZLNetworkException;
import org.geometerplus.zlibrary.core.image.ZLImage;
import org.geometerplus.zlibrary.ui.android.R;
import org.geometerplus.zlibrary.ui.android.view.ZLAndroidWidget;
import org.geometerplus.zlibrary.ui.android.dialogs.ZLAndroidDialogManager;
import org.geometerplus.zlibrary.ui.android.image.ZLAndroidResourceBasedImageData;
import org.geometerplus.android.fbreader.network.BookDownloader;
import org.geometerplus.android.fbreader.network.BookDownloaderService;
@ -100,8 +102,8 @@ public final class ZLAndroidLibrary extends ZLibrary {
return new AndroidAssetsFile(path);
}
public ZLResourceFile createDrawableFile(int drawableId) {
return new AndroidDrawableFile(drawableId);
public ZLImage createImage(int drawableId) {
return new ZLAndroidResourceBasedImageData(myApplication.getResources(), drawableId);
}
@Override
@ -130,44 +132,6 @@ public final class ZLAndroidLibrary extends ZLibrary {
return (myActivity != null) ? myActivity.getScreenBrightness() : 0;
}
private final class AndroidDrawableFile extends ZLResourceFile {
private int myId;
AndroidDrawableFile(int drawableId) {
super("drawable/" + drawableId);
myId = drawableId;
}
@Override
public boolean exists() {
return true;
}
@Override
public long size() {
try {
AssetFileDescriptor descriptor =
myApplication.getResources().openRawResourceFd(myId);
long length = descriptor.getLength();
descriptor.close();
return length;
} catch (IOException e) {
return 0;
} catch (Resources.NotFoundException e) {
return 0;
}
}
@Override
public InputStream getInputStream() throws IOException {
try {
return myApplication.getResources().openRawResource(myId);
} catch (Resources.NotFoundException e) {
throw new IOException(e.getMessage());
}
}
}
private final class AndroidAssetsFile extends ZLResourceFile {
AndroidAssetsFile(String path) {
super(path);
@ -204,7 +168,6 @@ public final class ZLAndroidLibrary extends ZLibrary {
@Override
public InputStream getInputStream() throws IOException {
System.err.println("open: " + getPath());
return myApplication.getAssets().open(getPath());
}
}