ResourceReader.java :  » UnTagged » hentaymaster » GameUtils » Android Open Source

Android Open Source » UnTagged » hentaymaster 
hentaymaster » GameUtils » ResourceReader.java
package GameUtils;

import java.io.InputStream;

import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class ResourceReader
{
  static private AssetManager s_assetMgr = null;
  private byte [] m_data = null;
  private int m_offset = 0;
  
  static public void SetAssetManager ( AssetManager am)
  {
    s_assetMgr = am;
  }
  
  public ResourceReader(String resourceName)
  {
    try
    {
      InputStream is = s_assetMgr.open(resourceName);
      m_offset = 0;
      m_data = new byte[is.available()];
      is.read(m_data, 0, m_data.length);
    }
    catch(Exception e)
    {
    }
  }
  
  public byte [] GetData () { return m_data; }
  
  public int GetInt ()
  {
    int result = ((((m_data[m_offset + 3] & 0xFF)) << 24) + (((m_data [m_offset + 2] & 0xFF)) << 16) + (((m_data [m_offset + 1] & 0xFF)) << 8) + ((m_data [m_offset] & 0xFF)));
    m_offset += 4;    
    return result;
  }
  
  public Bitmap GetBitmap ()
  {
    int size = GetInt();
    Bitmap bmp = BitmapFactory.decodeByteArray(m_data, m_offset, size);
    m_offset += size;
    return bmp;
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.