Android Open Source - 4est Asset






From Project

Back to project page 4est.

License

The source code is released under:

MIT License

If you think the Android project 4est 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

package com.wordsaretoys.rise.utility;
// ww  w.j  a v  a  2 s .c  o  m
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

/**
 * methods for loading and managing assets
 */
public class Asset {

  /**
   * reads a text file from the assets
   */
  static public String getTextAsset(Context context, String fileName) {
    String text = "";
    try {
      InputStream stream = context.getAssets().open(fileName);
      BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
      String line;
        while( (line = reader.readLine()) != null) {
          text += line + "\n";
        }
    } catch(IOException e) {
      e.printStackTrace();
    }
    return text;
  }

  /**
   * read image file from assets into bitmap 
   */
  static public Bitmap getBitmapAsset(Context context, String fileName) {
      InputStream istr;
      Bitmap bitmap = null;
      try {
          istr = context.getAssets().open(fileName);
          bitmap = BitmapFactory.decodeStream(istr);
      } catch (IOException e) {
        e.printStackTrace();
      }
      return bitmap;  
  }
  
  /**
   * read image file from assets into color array 
   */
  static public int[] getImageAsset(Context context, String fileName) {
      InputStream istr;
      Bitmap bitmap = null;
      try {
          istr = context.getAssets().open(fileName);
          bitmap = BitmapFactory.decodeStream(istr);
      } catch (IOException e) {
        e.printStackTrace();
      }
    // extract the bitmap data
    int w = bitmap.getWidth();
    int h = bitmap.getHeight();
    int[] c = new int[w * h];
    bitmap.getPixels(c, 0, w, 0, 0, w, h);
      return c;  
  }
  
  /**
   * read a binary file from the assets
   */
  static public boolean getBinaryAsset(Context context, String fileName, byte[] buffer) {
    try {
      InputStream stream = context.getAssets().open(fileName);
      BufferedInputStream bist = new BufferedInputStream(stream);
      bist.read(buffer);
    } catch(Exception e) {
      e.printStackTrace();
      return false;
    }
    return true;
  }
  
}




Java Source Code List

com.wordsaretoys.forest.Audio.java
com.wordsaretoys.forest.Debris.java
com.wordsaretoys.forest.Game.java
com.wordsaretoys.forest.GlView.java
com.wordsaretoys.forest.MainActivity.java
com.wordsaretoys.forest.Map.java
com.wordsaretoys.forest.Player.java
com.wordsaretoys.forest.Render.java
com.wordsaretoys.forest.Rotors.java
com.wordsaretoys.forest.Shared.java
com.wordsaretoys.forest.Skybox.java
com.wordsaretoys.rise.geometry.Camera.java
com.wordsaretoys.rise.geometry.Geom.java
com.wordsaretoys.rise.geometry.Mote.java
com.wordsaretoys.rise.geometry.Ortho.java
com.wordsaretoys.rise.geometry.Quaternion.java
com.wordsaretoys.rise.geometry.Vector.java
com.wordsaretoys.rise.glwrapper.Mesh.java
com.wordsaretoys.rise.glwrapper.Shader.java
com.wordsaretoys.rise.glwrapper.Texture.java
com.wordsaretoys.rise.meshutil.HeightMapper.java
com.wordsaretoys.rise.meshutil.IndexBuffer.java
com.wordsaretoys.rise.meshutil.SurfaceMapper.java
com.wordsaretoys.rise.meshutil.VertexBuffer.java
com.wordsaretoys.rise.meshutil.Vindexer.java
com.wordsaretoys.rise.pattern.Bitmap.java
com.wordsaretoys.rise.pattern.F2FSumMap.java
com.wordsaretoys.rise.pattern.I2FCutMap.java
com.wordsaretoys.rise.pattern.I2FMap.java
com.wordsaretoys.rise.pattern.I2IMap.java
com.wordsaretoys.rise.pattern.Pattern.java
com.wordsaretoys.rise.pattern.Ring.java
com.wordsaretoys.rise.utility.Asset.java
com.wordsaretoys.rise.utility.Board.java
com.wordsaretoys.rise.utility.Dbg.java
com.wordsaretoys.rise.utility.Interval.java
com.wordsaretoys.rise.utility.Misc.java
com.wordsaretoys.rise.utility.Needle.java