Android Open Source - android-gskbyte-utils Referenced Bitmaps






From Project

Back to project page android-gskbyte-utils.

License

The source code is released under:

GNU Lesser General Public License

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
 * /*  w  ww. j  a  v  a2 s  .co m*/
 * Contributors:
 *     Jose Alcal Correa - initial API and implementation
 ******************************************************************************/
package org.gskbyte.bitmap;

import java.util.HashSet;
import java.util.Set;

import org.gskbyte.bitmap.AbstractBitmapManager.ScaleMode;

import android.graphics.Bitmap;

/**
 * Class used to reference a subset of a bitmap manager.
 * This allows having a single BitmapManager per app, allowing just a section
 * of the app to access only to some bitmaps.
 * 
 * Eases the calls to the BitmapManager because the location for the bitmaps
 * is set at the beginning.
 * */
public class ReferencedBitmaps
{

protected final Set<String> keys = new HashSet<String>();

protected int uniqueCounter = 0;

protected final AbstractBitmapManager bitmapManager;
protected final int locationForBitmaps;

/**
 * Constructor.
 * @param manager The referenced manager
 * @param locationForBitmaps Default location for added paths
 * */
public ReferencedBitmaps(AbstractBitmapManager manager, int locationForBitmaps)
{
    this.bitmapManager = manager;
    this.locationForBitmaps = locationForBitmaps;
}

public final AbstractBitmapManager getBitmapManager()
{ return bitmapManager; }

public final int getLocationForBitmaps()
{ return locationForBitmaps; }

/**
 * Adds a path to a bitmap, depending on the initial default location.
 * @param path A path to a bitmap.
 * @param alias An extra alias to a bitmap. Must have length() > 0.
 * */
public void addPath(String path, String ... aliases)
{
    bitmapManager.addPath(locationForBitmaps, path, aliases);
    if(!keys.contains(path))
        ++uniqueCounter;
    keys.add(path);
    for(String alias : aliases)
        keys.add(alias);
}

/**
 * Adds an alias to an already referenced bitmap, depending on the initial default location.
 * @param path A path to a bitmap.
 * @param alias An extra alias to a bitmap. Must have length() > 0.
 * @return true if the given path existed (if not, nothing is done)
 * */
public boolean addAliases(String path, String ... aliases)
{
    if(keys.contains(path)) {
        bitmapManager.addAliases(path, aliases);
        for(String alias : aliases)
            keys.add(alias);
        return true;
    } else {
        return false;
    }
}

/**
 * @Deprecated Use containsKey, its name is more adequated
 * Indicates if this contains the given path.
 * @return true if there is a bitmap reference for the given path
 * */
@Deprecated
public boolean containsPath(String path)
{ return containsKey(path); }

/**
 * Indicates if this references the given key.
 * @return true if there is a bitmap reference for the given key
 * */
public boolean containsKey(String key)
{ return keys.contains(key); }

/**
 * Returns true if the given Bitmap is present in memory. Asks the underlying manager.
 * @param The bitmap's path
 * @returns true if a Bitmap for the given path is loaded into memory
 * */
public boolean isBitmapLoaded(String key)
{ return bitmapManager.isBitmapLoaded(key); }

/**
 * Returns true if the given Bitmap file is present in the file system. Asks the underlying manager.
 * @param The bitmap's path
 * @returns true if a file for the given path exists
 * */
public boolean existsBitmapFile(String key)
{ return bitmapManager.existsBitmapFile(key); }

/**
 * Checks the presence of all bitmaps in the file system 
 * @returns true if all contained Bitmaps are present in the file system. Asks the underlying manager.
 * */
public boolean existAllBitmaps()
{
    for(String key : keys) {
        if(!bitmapManager.existsBitmapFile(key))
            return false;
    }
    
    return true;
}

/**
 * Returns the number of references.
 * */
public int size()
{ return uniqueCounter; }

/**
 * Returns the number of existing bitmap files from the referenced by this.
 * @return the number of existing referenced bitmap files
 * */
public int countExistingBitmapFiles()
{
    int counter = 0;
    for(String k : keys) {
        if(bitmapManager.existsBitmapFile(k)) {
            ++counter;
        }
    }
    return counter;
}

/**
 * Returns a bitmap given its path.
 * @param key The key for the bitmap,
 * */
public Bitmap get(String key)
{ return bitmapManager.get(key); }


/**
 * Returns a bitmap given its path.
 * @param key The key for the bitmap
 * @param scaleMode
 * @param maxWidth
 * @param maxHeight
 * */
public Bitmap get(String key, ScaleMode scaleMode, int maxWidth, int maxHeight)
{ return bitmapManager.get(key, scaleMode, maxWidth, maxHeight); }

/**
 * @Deprecated Use getFirstExistingKey()
 * Returns the path for the first existing path.
 * @return The path for the fist existing bitmap file
 * */
@Deprecated
protected String getFirstExistingFilePath()
{
    return getFirstExistingKey();
}

/**
 * Returns the path for the first existing path.
 * @return The path for the fist existing bitmap file
 * */
protected String getFirstExistingKey()
{
    for(String key : keys) {
        boolean exists = existsBitmapFile(key);
        if(exists)
            return key;
    }
    
    return null;
}

/**
 * Clears all references to bitmaps, but does not release them.
 * */
public void clear()
{ clear(false); }

/**
 * Clears all references to bitmaps.
 * @param releaseBitmaps Wether the referenced bitmaps should be cleared or not.
 * */
public void clear(boolean releaseBitmaps)
{
    if(releaseBitmaps)
        freeResources();
    keys.clear();
}

/**
 * Frees memory by releasing all referenced bitmaps.
 * */
public void freeResources()
{
    for(String s : keys) {
        bitmapManager.freeBitmap(s);
    }
}

}




Java Source Code List

com.woozzu.android.widget.IndexScroller.java
com.woozzu.android.widget.IndexableListView.java
org.gskbyte.FragmentWrapperActivity.java
org.gskbyte.animation.ExpandAnimation.java
org.gskbyte.bitmap.AbstractBitmapManager.java
org.gskbyte.bitmap.BitmapColorizer.java
org.gskbyte.bitmap.BitmapManager.java
org.gskbyte.bitmap.CachedBitmapColorizer.java
org.gskbyte.bitmap.IndexedBitmaps.java
org.gskbyte.bitmap.LRUBitmapCache.java
org.gskbyte.bitmap.LRUBitmapManager.java
org.gskbyte.bitmap.PrivateBitmapManager.java
org.gskbyte.bitmap.ReferencedBitmaps.java
org.gskbyte.collection.ArrayHashMap.java
org.gskbyte.collection.DoubleSparseArray.java
org.gskbyte.collection.ListHashMap.java
org.gskbyte.dialog.DownloadDialogFragment.java
org.gskbyte.dialog.LoadDialogFragment.java
org.gskbyte.dialog.OpenLinkDialogBuilder.java
org.gskbyte.dialog.PickerDialogFragment.java
org.gskbyte.download.DiskDownload.java
org.gskbyte.download.DownloadManager.java
org.gskbyte.download.Download.java
org.gskbyte.download.MemoryDownload.java
org.gskbyte.drawable.AutoBackgroundButtonDrawable.java
org.gskbyte.listener.IListenable.java
org.gskbyte.listener.ListenableNG.java
org.gskbyte.listener.Listenable.java
org.gskbyte.preferences.DialogSeekBarPreference.java
org.gskbyte.preferences.InlineSeekBarPreference.java
org.gskbyte.remote.AsyncURLRequest.java
org.gskbyte.remote.URLRequest.java
org.gskbyte.tasks.QueuedTaskExecutor.java
org.gskbyte.tasks.TaskStep.java
org.gskbyte.tasks.Task.java
org.gskbyte.ui.ArrayAdapterWithDefaultValue.java
org.gskbyte.ui.ListAdapter.java
org.gskbyte.ui.ColorDialog.ColorDialog.java
org.gskbyte.ui.ColorDialog.ColorPreference.java
org.gskbyte.ui.iconifiedMainMenuList.EntryView.java
org.gskbyte.ui.iconifiedMainMenuList.MainMenuAdapter.java
org.gskbyte.ui.iconifiedMainMenuList.MenuEntry.java
org.gskbyte.util.FrequentIntents.java
org.gskbyte.util.IOUtils.java
org.gskbyte.util.Logger.java
org.gskbyte.util.OpenFileHandlerFactory.java
org.gskbyte.util.OpenFileHandler.java
org.gskbyte.util.XmlUtils.java
org.gskbyte.view.AsyncImageView.java
org.gskbyte.view.AutoBackgroundButton.java
org.gskbyte.view.AutoBackgroundImageButton.java
org.gskbyte.view.AutoHeightImageView.java
org.gskbyte.view.ExpandedGridView.java
org.gskbyte.view.ExpandedListView.java
org.gskbyte.view.FontUtil.java
org.gskbyte.view.FontableButton.java
org.gskbyte.view.FontableCheckBox.java
org.gskbyte.view.FontableEditText.java
org.gskbyte.view.FontableTextView.java
org.gskbyte.view.FullWidthImageView.java
org.gskbyte.view.ProportionalHeightLayout.java
org.gskbyte.view.PullToRefreshListView.java
org.gskbyte.view.SquaredLayout.java
org.gskbyte.view.StepSeekBar.java
org.gskbyte.view.TextViewUtil.java
org.gskbyte.view.ViewUtils.java