If you think the Android project android-gskbyte-utils listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*******************************************************************************
* Copyright (c) 2013 Jose Alcal Correa.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-3.0.txt
* //www.java2s.com
* Contributors:
* Jose Alcal Correa - initial API and implementation
******************************************************************************/package org.gskbyte.bitmap;
import android.content.Context;
import android.graphics.Bitmap;
/**
* BitmapManager class
*
* A bitmap manager stores bitmaps and allows referencing them using their path.
* The bitmaps are loaded only when they are requested for the first time.
*
* This is a simple implementation that doesn't care too much about memory usage.
* LRUBitmapManager is much more interesting.
* */publicclass BitmapManager
extends AbstractBitmapManager
{
public BitmapManager(Context context)
{
super(context);
}
public BitmapManager(Context context, int numLoadThreads)
{
super(context, numLoadThreads);
}
@Override
protected BitmapRef initializeReference(int location, String path)
{
returnnew BitmapReference(location, path);
}
@Override
publicint countLoadedBitmaps()
{
// this could be optimized, but it's not likely to be called often
int count = 0;
for(BitmapRef r : references.values()) {
if(((BitmapReference)r).bitmap != null)
++count;
}
return count;
}
@Override
publicvoid releaseAllBitmaps()
{
for(BitmapRef r : references.values()) {
r.freeResources();
}
}
/**
* Simple specialization of a BitmapReference. Just stores a bitmap in it.
* */finalclass BitmapReference
extends AbstractBitmapManager.BitmapRef
{
Bitmap bitmap;
public BitmapReference(int location, String path)
{
super(location, path);
}
@Override
public Bitmap getBitmap(ScaleMode scaleMode, int maxWidth, int maxHeight)
{
if(bitmap == null) {
bitmap = loadBitmap(scaleMode, maxWidth, maxHeight);
}
return bitmap;
}
@Override
publicboolean isLoaded()
{
return bitmap != null;
}
@Override
publicvoid freeResources()
{
if(bitmap!=null) {
//bitmap.recycle();
bitmap = null;
}
}
}
}