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; 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.image.ZLImage;
import org.geometerplus.zlibrary.core.resources.ZLResource; import org.geometerplus.zlibrary.core.resources.ZLResource;
@ -54,7 +52,6 @@ public class AddCustomCatalogItemTree extends NetworkTree {
@Override @Override
protected ZLImage createCover() { protected ZLImage createCover() {
ZLResourceFile file = ((ZLAndroidLibrary)ZLAndroidLibrary.Instance()).createDrawableFile(R.drawable.ic_list_plus); return ((ZLAndroidLibrary)ZLAndroidLibrary.Instance()).createImage(R.drawable.ic_list_plus);
return new ZLFileImage("image/png", file);
} }
} }

View file

@ -37,8 +37,6 @@ import android.graphics.Bitmap;
import org.geometerplus.zlibrary.ui.android.R; import org.geometerplus.zlibrary.ui.android.R;
import org.geometerplus.zlibrary.core.resources.ZLResource; 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.core.image.ZLImage;
import org.geometerplus.zlibrary.ui.android.image.ZLAndroidImageManager; 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. // 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 HashSet<String> myAwaitedCovers = new HashSet<String>();
private ZLFileImage myFBReaderIcon = new ZLFileImage( private ZLImage myFBReaderIcon =
"image/auto", ((ZLAndroidLibrary)ZLAndroidLibrary.Instance()).createImage(R.drawable.fbreader);
((ZLAndroidLibrary)ZLAndroidLibrary.Instance()).createDrawableFile(R.drawable.fbreader)
);
private void setupCover(final ImageView coverView, NetworkTree tree, int width, int height) { private void setupCover(final ImageView coverView, NetworkTree tree, int width, int height) {
Bitmap coverBitmap = null; Bitmap coverBitmap = null;

View file

@ -24,8 +24,6 @@ import java.util.LinkedList;
import java.util.ListIterator; import java.util.ListIterator;
import org.geometerplus.zlibrary.core.image.ZLImage; 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.zlibrary.core.resources.ZLResource;
import org.geometerplus.fbreader.tree.FBTree; import org.geometerplus.fbreader.tree.FBTree;
@ -55,8 +53,7 @@ public class SearchItemTree extends NetworkTree {
@Override @Override
protected ZLImage createCover() { protected ZLImage createCover() {
ZLResourceFile file = ((ZLAndroidLibrary)ZLAndroidLibrary.Instance()).createDrawableFile(R.drawable.ic_list_searchresult); return ((ZLAndroidLibrary)ZLAndroidLibrary.Instance()).createImage(R.drawable.ic_list_searchresult);
return new ZLFileImage("image/png", file);
} }
public void setSearchResult(SearchResult result) { 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; import org.geometerplus.zlibrary.core.image.ZLImageData;
public final class ZLAndroidImageData implements ZLImageData { public abstract class ZLAndroidImageData implements ZLImageData {
private byte[] myArray;
private Bitmap myBitmap; private Bitmap myBitmap;
private int myRealWidth; private int myRealWidth;
private int myRealHeight; private int myRealHeight;
private int myLastRequestedWidth; private int myLastRequestedWidth;
private int myLastRequestedHeight; private int myLastRequestedHeight;
ZLAndroidImageData(byte[] array) { protected ZLAndroidImageData() {
myArray = array;
} }
protected abstract Bitmap decodeWithOptions(BitmapFactory.Options options);
public synchronized Bitmap getBitmap(int maxWidth, int maxHeight) { public synchronized Bitmap getBitmap(int maxWidth, int maxHeight) {
if ((maxWidth == 0) || (maxHeight == 0)) { if ((maxWidth == 0) || (maxHeight == 0)) {
return null; return null;
@ -49,7 +49,7 @@ public final class ZLAndroidImageData implements ZLImageData {
final BitmapFactory.Options options = new BitmapFactory.Options(); final BitmapFactory.Options options = new BitmapFactory.Options();
if (myRealWidth <= 0) { if (myRealWidth <= 0) {
options.inJustDecodeBounds = true; options.inJustDecodeBounds = true;
BitmapFactory.decodeByteArray(myArray, 0, myArray.length, options); decodeWithOptions(options);
myRealWidth = options.outWidth; myRealWidth = options.outWidth;
myRealHeight = options.outHeight; myRealHeight = options.outHeight;
} }
@ -60,7 +60,7 @@ public final class ZLAndroidImageData implements ZLImageData {
coefficient *= 2; coefficient *= 2;
} }
options.inSampleSize = coefficient; options.inSampleSize = coefficient;
myBitmap = BitmapFactory.decodeByteArray(myArray, 0, myArray.length, options); myBitmap = decodeWithOptions(options);
if (myBitmap != null) { if (myBitmap != null) {
myLastRequestedWidth = maxWidth; myLastRequestedWidth = maxWidth;
myLastRequestedHeight = maxHeight; myLastRequestedHeight = maxHeight;

View file

@ -23,7 +23,9 @@ import org.geometerplus.zlibrary.core.image.*;
public final class ZLAndroidImageManager extends ZLImageManager { public final class ZLAndroidImageManager extends ZLImageManager {
public ZLAndroidImageData getImageData(ZLImage image) { 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; ZLSingleImage singleImage = (ZLSingleImage)image;
if ("image/palm".equals(singleImage.mimeType())) { if ("image/palm".equals(singleImage.mimeType())) {
return null; return null;
@ -32,7 +34,7 @@ public final class ZLAndroidImageManager extends ZLImageManager {
if (array == null) { if (array == null) {
return null; return null;
} }
return new ZLAndroidImageData(array); return new ZLAndroidArrayBasedImageData(array);
} else { } else {
//TODO //TODO
return null; 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.library.ZLibrary;
import org.geometerplus.zlibrary.core.filesystem.ZLResourceFile; import org.geometerplus.zlibrary.core.filesystem.ZLResourceFile;
import org.geometerplus.zlibrary.core.network.ZLNetworkException; 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.R;
import org.geometerplus.zlibrary.ui.android.view.ZLAndroidWidget; import org.geometerplus.zlibrary.ui.android.view.ZLAndroidWidget;
import org.geometerplus.zlibrary.ui.android.dialogs.ZLAndroidDialogManager; 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.BookDownloader;
import org.geometerplus.android.fbreader.network.BookDownloaderService; import org.geometerplus.android.fbreader.network.BookDownloaderService;
@ -100,8 +102,8 @@ public final class ZLAndroidLibrary extends ZLibrary {
return new AndroidAssetsFile(path); return new AndroidAssetsFile(path);
} }
public ZLResourceFile createDrawableFile(int drawableId) { public ZLImage createImage(int drawableId) {
return new AndroidDrawableFile(drawableId); return new ZLAndroidResourceBasedImageData(myApplication.getResources(), drawableId);
} }
@Override @Override
@ -130,44 +132,6 @@ public final class ZLAndroidLibrary extends ZLibrary {
return (myActivity != null) ? myActivity.getScreenBrightness() : 0; 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 { private final class AndroidAssetsFile extends ZLResourceFile {
AndroidAssetsFile(String path) { AndroidAssetsFile(String path) {
super(path); super(path);
@ -204,7 +168,6 @@ public final class ZLAndroidLibrary extends ZLibrary {
@Override @Override
public InputStream getInputStream() throws IOException { public InputStream getInputStream() throws IOException {
System.err.println("open: " + getPath());
return myApplication.getAssets().open(getPath()); return myApplication.getAssets().open(getPath());
} }
} }