Android Open Source - android-gskbyte-utils Indexed 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 w w .jav a  2  s. c  om
 * Contributors:
 *     Jose Alcal Correa - initial API and implementation
 ******************************************************************************/
package org.gskbyte.bitmap;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;

import org.gskbyte.bitmap.AbstractBitmapManager.ScaleMode;

import android.graphics.Bitmap;

/**
 * Class used to reference a subset of a bitmap manager.
 * Provides the same functionality as ReferencedBitmaps, but also allows to
 * access the bitmaps in the order their paths were added.
 * 
 * Duplicates are allowed in the list.
 * */

public class IndexedBitmaps
extends ReferencedBitmaps
{

protected final ArrayList<String> keyList = new ArrayList<String>();

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

/**
 * Adds a path to a bitmap, depending on the initial default location, and adds
 * its path to the end of the list.
 * @param path A path to a bitmap.
 * @param aliases Aliases for the given bitmap file. All must have length() > 0.
 * */
@Override
public void addPath(String path, String ... aliases)
{
    super.addPath(path, aliases);
    keyList.add(path);
    for(String alias : aliases)
        keyList.add(alias);
}

/**
 * Returns an unmodifiable copy of the managed keys.
 * @return a list with all managed keys.
 * */
public List<String> getKeyList()
{ return Collections.unmodifiableList(keyList); }

/**
 * 
 * */
@Override
public int size()
{ return keyList.size(); }

/**
 * Adds a list of paths to a bitmap, depending on the initial default location, and adds
 * their path to the end of the list.
 * @param paths A list of paths to bitmaps
 * */
public void addPaths(List<String> path)
{
    for(String s : path) {
        addPath(s);
    }
}

/**
 * Returns a path given the index in which it was added.
 * @param index The key's index.
 * */
public String getKeyAt(int index)
{ return keyList.get(index); }

/**
 * Returns a Bitmap given the index in which its path it was added.
 * @param index The bitmap's path index.
 * */
public Bitmap getAt(int index)
{
    String path = keyList.get(index);
    return bitmapManager.get(path);
}

/**
 * Returns a Bitmap given the index in which its path it was added.
 * @param index The bitmap's path index.
 * */
public Bitmap getAt(int index, ScaleMode scaleMode, int maxWidth, int maxHeight)
{
    String path = keyList.get(index);
    return bitmapManager.get(path, scaleMode, maxWidth, maxHeight);
}

/**
 * Returns true if the given Bitmap is present in memory
 * @param The bitmap's path index
 * @returns true if a Bitmap for the given path is loaded into memory
 * */
public boolean isBitmapLoadedAt(int index)
{
    return bitmapManager.isBitmapLoaded( keyList.get(index) );
}

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

/**
 * Returns the path for the first existing path. The paths are iterated in insertion order.
 * @return The path for the fist existing bitmap file
 * */
@Override
public String getFirstExistingKey()
{
    for(int i=0; i<size(); ++i) {
        boolean exists = existsBitmapFileAt(i);
        if(exists) {
            return getKeyAt( i );
        }
    }
    
    return null;
}

/**
 * Returns the file path for a random bitmap.
 * @return A file path for an existing bitmap file
 * */
public String getRandomExistingKey()
{
    final int numBitmaps = size();
    if(numBitmaps > 1) {
        Random r = new Random();
        int startindex = r.nextInt( numBitmaps );
        for(int i=0; i<numBitmaps; ++i) {
            int index = (startindex+i) %numBitmaps;
            boolean exists = existsBitmapFileAt(index);
            if(exists) {
                return getKeyAt( index );
            }
        }
        return null;
    } else {
        return getFirstExistingKey();
    }
}



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

}




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