package com.mobile.constellations.util;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

import org.apache.http.util.EncodingUtils;

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

public class CommUtils {

	/**
	 * 根据一个网络连接(String)获取bitmap图像
	 * 
	 * @param imageUri
	 * @return
	 * @throws MalformedURLException
	 */
	public static Bitmap getbitmap(String imageUri) {
		// 显示网络上的图片
		Bitmap bitmap = null;
		try {
			URL myFileUrl = new URL(imageUri);
			HttpURLConnection conn = (HttpURLConnection) myFileUrl
					.openConnection();
			conn.setDoInput(true);
			conn.connect();
			InputStream is = conn.getInputStream();
			bitmap = BitmapFactory.decodeStream(is);
			is.close();
		} catch (IOException e) {
			e.printStackTrace();
			return null;
		}
		return bitmap;
	}
	
	public static String getFromAssets(Context context,String FileName){
	     String result = "";
	     try{
	      InputStream in = context.getAssets().open(FileName);//获取资源
	      int length = in.available();//获取文字字数
	      byte[]buffer = new byte[length];
	      in.read(buffer);//读到数组中
	            //设置编码
	      result = EncodingUtils.getString(buffer, "UTF-8");
	     }catch (Exception e) {
	  }
	  return result;
	    }
}
