项目中用到的图片的加载,别人已经写好了,把这个工具贴出来,主要是为了自己以后用的方便,哈哈
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.lang.ref.WeakReference;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.WeakHashMap;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Environment;
import android.view.View;
import com.ihandy.local.core.exception.Logger;
import com.ihandy.xgxsigndome.AppConstants;
import com.ihandy.xgxsigndome.dao.SQLiteHelper;
import com.ihandy.xgxsigndome.hessian.HessianBase;
import com.ihandy.xgxsigndome.ui.StartActivity;
import com.ihandy.xgxsigndome.ui.helper.ProgressDialog;
import com.ihandy.xgxsigndome.util.DateUtils;
import com.ihandy.xgxsigndome.util.StringUtils;
@SuppressLint("NewApi")
public final class ImageResource {
/** sd卡存图片路径 */
public final static String SD_CPIC = "/cpic/";
public final static String SD_CPIC_IMAGE = SD_CPIC+"images/";
public final static String SD_CPIC_HTML = SD_CPIC+"pages/";
/**下载的资源保存的基 路径 **/
public final static String RESOURCE_SAVE_BASE_PATH = Environment.getExternalStorageDirectory().getPath();
protected static final String TAG = "ImageResource";
private WeakHashMap<String, WeakReference<Bitmap>> mBitmaps;
private WeakHashMap<String, WeakReference<Drawable>> mDrawables;
public ImageResource() {
mBitmaps = new WeakHashMap<String, WeakReference<Bitmap>>();
mDrawables = new WeakHashMap<String, WeakReference<Drawable>>();
}
/** */
public Bitmap zhengshu_no() {
return getCacheBitmap("zhengshu_no.png");
}
/** */
public Bitmap zhengshu() {
return getCacheBitmap("zhengshu.png");
}
/** */
public Bitmap user_video1() {
return getCacheBitmap("user_video1.png");
}
/** 视频2 */
public Bitmap user_video2() {
return getCacheBitmap("user_video2.png");
}
/** */
public Bitmap oldCustomerOnlyYouOnlyImg() {
return getCacheBitmap("only_you_only.png");
}
/** */
public Bitmap oldCustomerOnlyYouOnlyBottomBarImg() {
return getCacheBitmap("only_you_only_bottombar.png");
}
/** */
public Drawable broadcast_leaflet() {
return getCacheDrawable("broadcast_leaflet.png");
}
/** */
public Bitmap tips_addition() {
return getCacheBitmap("tips_addition.png");
}
/** 提示 - */
public Bitmap tips_applicant() {
return getCacheBitmap("tips_applicant.png");
}
/** 提示 - */
public Bitmap tips_benefit() {
return getCacheBitmap("tips_benefit.png");
}
/** 提示 - */
public Bitmap tips_insurant() {
return getCacheBitmap("tips_insurant.png");
}
/** 提示 - */
public Bitmap tips_pay() {
return getCacheBitmap("tips_pay.png");
}
/** 提示 - */
public Bitmap tips_pay_acc() {
return getCacheBitmap("tips_pay_acc.png");
}
/** 提示 - */
public Bitmap tips_suggest() {
return getCacheBitmap("tips_suggest.png");
}
/** 提示 - */
public Bitmap tips_user() {
return getCacheBitmap("tips_user.png");
}
/** 提示 - */
public Bitmap tips_pay_transfer() {
return getCacheBitmap("tips_pay_transfer.png");
}
/** 理财概要 底部栏 */
public Bitmap main_bottom3() {
return getCacheBitmap("main_bottom3.png");
}
/** 支付成功 */
public Bitmap succeed_txt4() {
return getCacheBitmap("succeed_txt4.png");
}
/** 支付成功 */
public Bitmap succeed_txt2() {
return getCacheBitmap("succeed_txt2.png");
}
/** 头像 男 */
public Bitmap default_male_face() {
return getCacheBitmap("default_male_face.png");
}
/** 头像 女 */
public Bitmap default_female_face() {
return getCacheBitmap("default_female_face.png");
}
/** 头像 女 */
public Bitmap demo_user_face() {
return getCacheBitmap("demo_user_face.png");
}
/** 支付成功 */
public Drawable succeed_txt3() {
return getCacheDrawable("succeed_txt3.png");
}
/** 启动页 背景图片 */
public static Drawable start_bg_drawable() {
return getDrawable("start_bg.png");
}
/** 登录 背景图片 */
public static Drawable login_bg() {
return getDrawable("login_bg.png");
}
/** */
public Drawable title_bar() {
return getCacheDrawable("title_bar.png");
}
public Drawable bg() {
return getCacheDrawable("bg.png");
}
/** 告知 背景图片 */
public Bitmap tell_content() {
return getCacheBitmap("tell_content.png");
}
/* */
public Drawable survey() {
return getCacheDrawable("survey.png");
}
/** */
public Drawable product_hlnn() {
return getCacheDrawable("product_hlnn.png");
}
/***/
public Drawable product_yfnn() {
return getCacheDrawable("product_yfnn.png");
}
/***/
public Drawable product_fhax() {
return getCacheDrawable("product_fhax.png");
}
/** */
public Drawable product_hfnn() {
return getCacheDrawable("product_hfnn.png");
}
/** */
public Drawable product_hxrs_c() {
return getCacheDrawable("product_hxrs_c.png");
}
/** */
public Drawable product_hxrs_b() {
return getCacheDrawable("product_hxrs_b.png");
}
/** */
public Drawable product_hxrs() {
return getCacheDrawable("product_hxrs.png");
}
/** */
public Drawable product_jxrs() {
return getCacheDrawable("product_jxrs.png");
}
/** */
public Drawable product_jxrs_b() {
return getCacheDrawable("product_jxrs_b.png");
}
/***金尊人生 背景图片
* @return
*/
public Drawable product_jzrs(){
return getCacheDrawable("product_jzrs.png");
}
/**
* @return
*/
public Drawable product_zyh(){
return getCacheDrawable("product_zyh.png");
}
/***
* @return
*/
public Drawable product_ctak(){
return getCacheDrawable("product_ctak.png");
}
/***
* @return
*/
public Drawable product_jyrs() {
return getCacheDrawable("product_jyrs.png");
}
/**
* @return
*/
public Drawable product_bbak(){
return getCacheDrawable("product_bbak.png");
}
//------------------4.18----------------
/***
* @return
*/
public Drawable product_lxak(){
return getCacheDrawable("product_lxak.png");
}
/***福享安康两全保险(分红型) 背景图片
* @return
*/
public Drawable product_fxak(){
return getCacheDrawable("product_fxak.png");
}
/***如意安康两全保险 背景图片
* @return
*/
public Drawable product_ryak(){
return getCacheDrawable("product_ryak.png");
}
/***万全安康重大疾病保险 背景图片
* @return
*/
public Drawable product_wqak(){
return getCacheDrawable("product_wqak.png");
}
public Drawable product_feature_bg_jzrs() {
return getCacheDrawable("product_feature_bg_jzrs.png");
}
/** 产品特色 鸿鑫人生B */
public Drawable product_feature_bg_hxrs_b() {
return getCacheDrawable("product_feature_bg_hxrs_b.png");
}
/** 产品特色 鸿鑫人生c */
public Drawable product_feature_bg_hxrs_c() {
return getCacheDrawable("product_feature_bg_hxrs_c.png");
}
/** 产品特色 金享人生 */
public Drawable product_feature_bg_jxrs() {
return getCacheDrawable("product_feature_bg_jxrs.png");
}
/** 产品特色 金享人生B款 */
public Drawable product_feature_bg_jxrs_b() {
return getCacheDrawable("product_feature_bg_jxrs_b.png");
}
/** 产品特色 鸿鑫人生 */
public Drawable product_feature_bg_hxrs() {
return getCacheDrawable("product_feature_bg_hxrs.png");
}
/** 产品特色 鸿发年年 */
public Drawable product_feature_bg_hfnn() {
return getCacheDrawable("product_feature_bg_hfnn.png");
}
/** 产品特色 鸿利年年 */
public Drawable product_feature_bg_hlnn() {
return getCacheDrawable("product_feature_bg_hlnn.png");
}
/** 产品特色 银福年年 */
public Drawable product_feature_bg_yfnn() {
return getCacheDrawable("product_feature_bg_yfnn.png");
}
/** 产品特色 福惠安享 */
public Drawable product_feature_bg_fhax() {
return getCacheDrawable("product_feature_bg_fhax.png");
}
/** 产品特色 状元红 */
public Drawable product_feature_bg_zyh() {
return getCacheDrawable("product_feature_bg_zyh.png");
}
/** 产品特色 长泰安康 */
public Drawable product_feature_bg_ctak() {
return getCacheDrawable("product_feature_bg_ctak.png");
}
/** 产品特色金玉人生——zhangshenhe*/
public Drawable product_feature_bg_jyrs(){
return getCacheDrawable("product_feature_bg_jyrs.png");
}
/** 产品特色宝宝安康——zhangshenhe*/
public Drawable product_feature_bg_bbak(){
return getCacheDrawable("product_feature_bg_bbak.png");
}
/** 产品特色 乐享安康两全保险(分红型)*/
public Drawable product_feature_bg_lxak(){
return getCacheDrawable("product_feature_bg_lxak.png");
}
/** 产品特色 福享安康两全保险(分红型)*/
public Drawable product_feature_bg_fxak(){
return getCacheDrawable("product_feature_bg_fxak.png");
}
/** 产品特色 如意安康两全保险*/
public Drawable product_feature_bg_ryak(){
return getCacheDrawable("product_feature_bg_ryak.png");
}
/** 产品特色 万全安康重大疾病保险*/
public Drawable product_feature_bg_wqak(){
return getCacheDrawable("product_feature_bg_wqak.png");
}
/** 人工核保不可收费 */
public Drawable verify_bg() {
return getCacheDrawable("verify_bg.png");
}
/** 支付界面 */
public Drawable pay_bg() {
return getCacheDrawable("pay_bg.png");
}
/** 警告 */
public Drawable tell_warn() {
return getCacheDrawable("tell_warn.png");
}
/** 附加险 */
public Drawable addtion_bg() {
return getCacheDrawable("addtion_bg.jpg");
}
/** 签署并关联《投保确认书》 */
public Drawable associate_bg() {
return getCacheDrawable("associate_bg.png");
}
/** 产品信息 产品简介 鸿鑫人生B 按钮效果 */
public Drawable product_feature_selector_hxrs_b() {
return getStateDrawable("product_feature_normal_hxrs_b.png", "product_feature_pressed_hxrs_b.png");
}
/** 产品信息 产品简介 金享人生 按钮效果 */
public Drawable product_feature_selector_jxrs() {
return getStateDrawable("product_feature_normal_jxrs.png", "product_feature_pressed_jxrs.png");
}
/** 产品信息 产品简介 金享人生B款 按钮效果 */
public Drawable product_feature_selector_jxrs_b() {
return getStateDrawable("product_feature_normal_jxrs_b.png", "product_feature_pressed_jxrs_b.png");
}
/** 产品信息 产品简介 鸿鑫人生 按钮效果 */
public Drawable product_feature_selector_hxrs() {
return getStateDrawable("product_feature_normal_hxrs.png", "product_feature_pressed_hxrs.png");
}
public Drawable product_feature_selector_jzrs(){
return getStateDrawable("product_feature_normal_jzrs.png", "product_feature_pressed_jzrs.png");
}
/**产品信息 产品简介 鸿鑫人生 c按钮效果*/
public Drawable product_feature_selector_hxrs_c(){
return getStateDrawable("product_feature_normal_hxrs_c.png", "product_feature_pressed_hxrs_c.png");
}
/**产品信息 产品简介 鸿发年年 按钮效果*/
public Drawable product_feature_selector_hfnn(){
return getStateDrawable("product_feature_normal_hfnn.png", "product_feature_pressed_hfnn.png");
}
/**产品信息 产品简介 鸿利年年 按钮效果*/
public Drawable product_feature_selector_hlnn(){
return getStateDrawable("product_feature_normal_hlnn.png", "product_feature_pressed_hlnn.png");
}
/**产品信息 产品简介 银福年年 按钮效果*/
public Drawable product_feature_selector_yfnn(){
return getStateDrawable("product_feature_normal_yfnn.png", "product_feature_pressed_yfnn.png");
}
/**产品信息 产品简介 福惠安享 按钮效果*/
public Drawable product_feature_selector_fhax(){
return getStateDrawable("product_feature_normal_fhax.png", "product_feature_pressed_fhax.png");
}
/**产品信息 产品简介 状元红 按钮效果*/
public Drawable product_feature_selector_zyh(){
return getStateDrawable("product_feature_normal_zyh.png", "product_feature_pressed_zyh.png");
}
/**产品信息 产品简介 长泰安康 按钮效果*/
public Drawable product_feature_selector_ctak(){
return getStateDrawable("product_feature_normal_ctak.png", "product_feature_pressed_ctak.png");
}
/**产品信息 产品简介 金玉人生 按钮效果 ——zhangshenhe*/
public Drawable product_feature_selector_jyrs() {
return getStateDrawable("product_feature_normal_jyrs.png", "product_feature_pressed_jyrs.png");
}
/** 产品信息 产品简介 宝宝安康 按钮效果 ——zhangshenhe*/
public Drawable product_feature_selector_bbak() {
return getStateDrawable("product_feature_normal_bbak.png", "product_feature_pressed_bbak.png");
}
/**产品信息 产品简介 乐享安康 按钮效果*/
public Drawable product_feature_selector_lxak(){
return getStateDrawable("product_feature_normal_lxak.png", "product_feature_pressed_lxak.png");
}
/**产品信息 产品简介 福享安康 按钮效果*/
public Drawable product_feature_selector_fxak(){
return getStateDrawable("product_feature_normal_fxak.png", "product_feature_pressed_fxak.png");
}
/**产品信息 产品简介 如意安康 按钮效果*/
public Drawable product_feature_selector_ryak(){
return getStateDrawable("product_feature_normal_ryak.png", "product_feature_pressed_ryak.png");
}
/**产品信息 产品简介 万全安康重大疾病保险 按钮效果*/
public Drawable product_feature_selector_wqak(){
return getStateDrawable("product_feature_normal_wqak.png", "product_feature_pressed_wqak.png");
}
/** 状态按钮效果 */
private Drawable getStateDrawable(String key_normal, String key_pressed) {
Drawable normal = getCacheDrawable(key_normal);
Drawable selected = getCacheDrawable(key_pressed);
Drawable pressed = selected;
StateListDrawable result = new StateListDrawable();
result.addState(StateView.PRESSED_ENABLED_STATE_SET, pressed);
result.addState(StateView.ENABLED_FOCUSED_STATE_SET, selected);
result.addState(StateView.ENABLED_STATE_SET, normal);
result.addState(StateView.FOCUSED_STATE_SET, selected);
result.addState(StateView.EMPTY_STATE_SET, normal);
return result;
}
/**
* 从SD卡 加载图片
*
* @param imgName 图片名称
* @return
*/
private static Bitmap getBitmap(String imgName) {
return BitmapFactory.decodeFile(RESOURCE_SAVE_BASE_PATH + SD_CPIC_IMAGE + imgName);
}
/***
* @param imgName 图片名称
* @return
*/
public static Drawable getDrawable(String imgName) {
return BitmapDrawable.createFromPath(RESOURCE_SAVE_BASE_PATH + SD_CPIC_IMAGE + imgName);
}
/***
* @param updateResourceMap 需要下载更新的资源列表
* @param serverDateTime 服务端时间
*/
@TargetApi(Build.VERSION_CODES.CUPCAKE)
public static void downloadResource(final StartActivity ctx,
final Map<String, String> updateResourceMap,
final Map<String,ModifiedResource> downloadModifyResMap,
final long serverCurrentTimeMills) {
File baseDir = new File(RESOURCE_SAVE_BASE_PATH + SD_CPIC_IMAGE);
if (!baseDir.exists()) {
baseDir.mkdirs();
}
File htmlDir = new File(RESOURCE_SAVE_BASE_PATH + SD_CPIC_HTML);
if (!htmlDir.exists()) {
htmlDir.mkdirs();
}
new AsyncTask<Void, Void, Integer>() {
private ProgressDialog dp;
@Override
protected void onPreExecute() {
dp = new ProgressDialog(ctx);
dp.progress_dialog_title.setText("正在下载图片,请稍候...");
final int totalImgNum = updateResourceMap==null? 0 : updateResourceMap.size();
dp.setMaxCount(totalImgNum);
dp.show();
}
@Override
protected Integer doInBackground(Void... params) {
try {
int successDownloadCounter = 0; //成功下载的资源数量
int resourceCounter = 0;//资源数量 计算器
if (updateResourceMap != null && updateResourceMap.keySet()!= null) {
Iterator<String> fileNameIter = updateResourceMap.keySet().iterator();
final Map<String,Long> allResourceLenthMap = SQLiteHelper.findAllResourceNamesSizePairMap();
while(fileNameIter.hasNext()) {
final String fileName = fileNameIter.next();
final String downloadURI = updateResourceMap.get(fileName);
//如果成功下载资源
if(downloadPic(fileName,downloadURI,allResourceLenthMap)) {
successDownloadCounter++;
if(downloadModifyResMap!=null && downloadModifyResMap.containsKey(fileName)) {
SQLiteHelper.addSuccessDownloadedModifyResource(downloadModifyResMap.get(fileName));
}
}
dp.refresh_next(); //再刷新下载进度
resourceCounter++;
}
}
return resourceCounter;
} catch (Exception e) {
Logger.printStackTrace(TAG, e);
}
return 0;
}
@Override
protected void onPostExecute(final Integer successDownloadCounter) {
if (dp != null) {
dp.dismiss();
if(successDownloadCounter>0 && successDownloadCounter == updateResourceMap.size()) {
SQLiteHelper.updateLastUpdateResourceDateTime(DateUtils.format(new Date(serverCurrentTimeMills), DateUtils.DATE_TIME_PATTERN));
}
}
}
}.execute();
}
/**
* 单个下载 需要更新的资源文件 ,图片的保存位置:sdcard/cpic/images
* @param imgName 图片名称
* @param resourceURI 资源文件的uri, 服务端返回的 uri格式: /imgUploadDir/fileName
* @return 返回是否成功下载资源文件
*/
private static boolean downloadPic(final String imgName,String resourceURI,final Map<String,Long> allResourceLenthMap) {
boolean downloadSuccessFlag = true;
int fileLength = 0;
if(StringUtils.isEmpty(resourceURI)) {
downloadSuccessFlag = false;
}else {
String path = RESOURCE_SAVE_BASE_PATH;
if (isImageFile(resourceURI)) {
path += SD_CPIC_IMAGE;//存到图片文件夹 sdcard/cpic/images
} else if (isHtmlFile(resourceURI)) {
path += SD_CPIC_HTML;
} else {
path += SD_CPIC; //存到 sdcard/cpic/
}
InputStream is = null;
FileOutputStream fileOutputStream = null;
File localResourceFile = null;
try {
final String slash = "/";
if (!resourceURI.startsWith(slash)) {
resourceURI = slash + resourceURI;
}
final String fullUrl = "http://" + HessianBase.CONNECTION_URL + HessianBase.CONTEXT_PATH + resourceURI;
final URL picUrl = new URL(fullUrl);
HttpURLConnection conn = (HttpURLConnection) picUrl.openConnection();
conn.setReadTimeout(3 * 1000);
conn.setRequestMethod("GET");
conn.setDoInput(true);
conn.connect();
is = conn.getInputStream();
fileLength = (int) conn.getContentLength();
if (fileLength > 0) {
int byteReadTotal = 0;
localResourceFile = new File(path, imgName);
fileOutputStream = new FileOutputStream(localResourceFile);
int bytesRead = -1;
byte[] buf = new byte[1024];
while ((bytesRead = is.read(buf)) != -1) {
fileOutputStream.write(buf, 0, bytesRead);
byteReadTotal +=bytesRead;
}
fileOutputStream.flush();
//如果下载的文件,差1K 没有下载完 ,则下载失败
if(Math.abs(fileLength - byteReadTotal)>= AppConstants.LOST_IMG_SIZE_LIMITED) {
downloadSuccessFlag = false;
localResourceFile.delete();
}
}else {
downloadSuccessFlag = false;
}
} catch (Exception e) {
Logger.printStackTrace(TAG, e);
if(localResourceFile != null){
localResourceFile.delete();
}
downloadSuccessFlag = false;
} finally {
try {
if (fileOutputStream != null)
fileOutputStream.close();
if (is != null)
is.close();
} catch (IOException ex) {
Logger.printStackTrace(TAG, ex);
if(localResourceFile != null){
localResourceFile.delete();
}
downloadSuccessFlag = false;
}
}
}
//如果图片下载成功,并且 数据库中存储的文件大小与下载下来的文件大小不一致,则更新库中的图片大小
if(downloadSuccessFlag && allResourceLenthMap.containsKey(imgName) && fileLength!= allResourceLenthMap.get(imgName)) {
SQLiteHelper.updateResourceSizeByResourceName(imgName, fileLength);
}
return downloadSuccessFlag;
}
/**
* 从缓存加载图片
*
* @param imgName 图片名称
* @return
*/
private Bitmap getCacheBitmap(String imgName) {
//从SD卡
// if (mBitmaps.containsKey(imgName)) {
// WeakReference<Bitmap> softReference = mBitmaps.get(imgName);
// Bitmap drawable = softReference.get();
// if (drawable != null && !drawable.isRecycled()) {
// return drawable;
// }
// }
// //先从SD卡中加载
// Bitmap sd_img = getBitmap(imgName);
// if (sd_img != null && !sd_img.isRecycled()) { //如果图像加载成功,则放入bitMap缓存
// mBitmaps.put(imgName, new WeakReference<Bitmap>(sd_img));
// }
if(mBitmaps.containsKey(imgName)){
WeakReference<Bitmap> weakReference = mBitmaps.get(imgName);
Bitmap drawable = weakReference.get();
if(null!=drawable && !drawable.isRecycled()){
return drawable;
}
}
Bitmap sd_img = getBitmap(imgName);
if(sd_img!=null && !sd_img.isRecycled()){
mBitmaps.put(imgName, new WeakReference<Bitmap>(sd_img));
}
return sd_img;
}
/***
* @param imgFileName 图片文件名称
* @return
*/
private Drawable getCacheDrawable(String imgFileName) {
//从SD卡
if (mDrawables.containsKey(imgFileName)) {
WeakReference<Drawable> softReference = mDrawables.get(imgFileName);
Drawable drawable = softReference.get();
if (drawable != null) {
return drawable;
}
}
//从SD卡中加载
Drawable drawImg = getDrawable(imgFileName);
if (drawImg != null) {
mDrawables.put(imgFileName, new WeakReference<Drawable>(drawImg));
}
return drawImg;
}
/**成功下载了的 修改资源 **/
public static final class ModifiedResource implements Serializable{
private static final long serialVersionUID = 1L;
public Set<Integer> modifyVersions;
public String resourceName;
public ModifiedResource(String resourceName){
this.resourceName = resourceName;
}
public ModifiedResource(Set<Integer> versions, String resourceName) {
this.modifyVersions = versions;
this.resourceName = resourceName;
}
public void addModifyVersion(int version) {
if(this.modifyVersions ==null) {
modifyVersions = new HashSet<Integer>();
modifyVersions.add(version);
}
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((resourceName == null) ? 0 : resourceName.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ModifiedResource other = (ModifiedResource) obj;
if (resourceName == null) {
if (other.resourceName != null)
return false;
} else if (!resourceName.equals(other.resourceName))
return false;
return true;
}
}
private static class StateView extends View {
public StateView(Context context) {
super(context);
}
public static int[] PRESSED_ENABLED_STATE_SET = View.PRESSED_ENABLED_STATE_SET;
public static int[] ENABLED_FOCUSED_STATE_SET = View.ENABLED_FOCUSED_STATE_SET;
public static int[] ENABLED_STATE_SET = View.ENABLED_STATE_SET;
public static int[] FOCUSED_STATE_SET = View.FOCUSED_STATE_SET;
public static int[] EMPTY_STATE_SET = View.EMPTY_STATE_SET;
}
/****
* 是否是图片文件
*
* @param fileName
* @return
*/
private static boolean isImageFile(String fileName) {
fileName = fileName.toLowerCase();
return fileName.endsWith("png") || fileName.endsWith("jpg") || fileName.endsWith("jpeg")
|| fileName.endsWith("gif") || fileName.equals("bmp");
}
/****
* 是否是html文件
* @param fileName
* @return
*/
private static boolean isHtmlFile(String fileName) {
fileName = fileName.toLowerCase();
return fileName.endsWith(".html");
}
}
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.lang.ref.WeakReference;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.WeakHashMap;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Environment;
import android.view.View;
import com.ihandy.local.core.exception.Logger;
import com.ihandy.xgxsigndome.AppConstants;
import com.ihandy.xgxsigndome.dao.SQLiteHelper;
import com.ihandy.xgxsigndome.hessian.HessianBase;
import com.ihandy.xgxsigndome.ui.StartActivity;
import com.ihandy.xgxsigndome.ui.helper.ProgressDialog;
import com.ihandy.xgxsigndome.util.DateUtils;
import com.ihandy.xgxsigndome.util.StringUtils;
@SuppressLint("NewApi")
public final class ImageResource {
/** sd卡存图片路径 */
public final static String SD_CPIC = "/cpic/";
public final static String SD_CPIC_IMAGE = SD_CPIC+"images/";
public final static String SD_CPIC_HTML = SD_CPIC+"pages/";
/**下载的资源保存的基 路径 **/
public final static String RESOURCE_SAVE_BASE_PATH = Environment.getExternalStorageDirectory().getPath();
protected static final String TAG = "ImageResource";
private WeakHashMap<String, WeakReference<Bitmap>> mBitmaps;
private WeakHashMap<String, WeakReference<Drawable>> mDrawables;
public ImageResource() {
mBitmaps = new WeakHashMap<String, WeakReference<Bitmap>>();
mDrawables = new WeakHashMap<String, WeakReference<Drawable>>();
}
/** */
public Bitmap zhengshu_no() {
return getCacheBitmap("zhengshu_no.png");
}
/** */
public Bitmap zhengshu() {
return getCacheBitmap("zhengshu.png");
}
/** */
public Bitmap user_video1() {
return getCacheBitmap("user_video1.png");
}
/** 视频2 */
public Bitmap user_video2() {
return getCacheBitmap("user_video2.png");
}
/** */
public Bitmap oldCustomerOnlyYouOnlyImg() {
return getCacheBitmap("only_you_only.png");
}
/** */
public Bitmap oldCustomerOnlyYouOnlyBottomBarImg() {
return getCacheBitmap("only_you_only_bottombar.png");
}
/** */
public Drawable broadcast_leaflet() {
return getCacheDrawable("broadcast_leaflet.png");
}
/** */
public Bitmap tips_addition() {
return getCacheBitmap("tips_addition.png");
}
/** 提示 - */
public Bitmap tips_applicant() {
return getCacheBitmap("tips_applicant.png");
}
/** 提示 - */
public Bitmap tips_benefit() {
return getCacheBitmap("tips_benefit.png");
}
/** 提示 - */
public Bitmap tips_insurant() {
return getCacheBitmap("tips_insurant.png");
}
/** 提示 - */
public Bitmap tips_pay() {
return getCacheBitmap("tips_pay.png");
}
/** 提示 - */
public Bitmap tips_pay_acc() {
return getCacheBitmap("tips_pay_acc.png");
}
/** 提示 - */
public Bitmap tips_suggest() {
return getCacheBitmap("tips_suggest.png");
}
/** 提示 - */
public Bitmap tips_user() {
return getCacheBitmap("tips_user.png");
}
/** 提示 - */
public Bitmap tips_pay_transfer() {
return getCacheBitmap("tips_pay_transfer.png");
}
/** 理财概要 底部栏 */
public Bitmap main_bottom3() {
return getCacheBitmap("main_bottom3.png");
}
/** 支付成功 */
public Bitmap succeed_txt4() {
return getCacheBitmap("succeed_txt4.png");
}
/** 支付成功 */
public Bitmap succeed_txt2() {
return getCacheBitmap("succeed_txt2.png");
}
/** 头像 男 */
public Bitmap default_male_face() {
return getCacheBitmap("default_male_face.png");
}
/** 头像 女 */
public Bitmap default_female_face() {
return getCacheBitmap("default_female_face.png");
}
/** 头像 女 */
public Bitmap demo_user_face() {
return getCacheBitmap("demo_user_face.png");
}
/** 支付成功 */
public Drawable succeed_txt3() {
return getCacheDrawable("succeed_txt3.png");
}
/** 启动页 背景图片 */
public static Drawable start_bg_drawable() {
return getDrawable("start_bg.png");
}
/** 登录 背景图片 */
public static Drawable login_bg() {
return getDrawable("login_bg.png");
}
/** */
public Drawable title_bar() {
return getCacheDrawable("title_bar.png");
}
public Drawable bg() {
return getCacheDrawable("bg.png");
}
/** 告知 背景图片 */
public Bitmap tell_content() {
return getCacheBitmap("tell_content.png");
}
/* */
public Drawable survey() {
return getCacheDrawable("survey.png");
}
/** */
public Drawable product_hlnn() {
return getCacheDrawable("product_hlnn.png");
}
/***/
public Drawable product_yfnn() {
return getCacheDrawable("product_yfnn.png");
}
/***/
public Drawable product_fhax() {
return getCacheDrawable("product_fhax.png");
}
/** */
public Drawable product_hfnn() {
return getCacheDrawable("product_hfnn.png");
}
/** */
public Drawable product_hxrs_c() {
return getCacheDrawable("product_hxrs_c.png");
}
/** */
public Drawable product_hxrs_b() {
return getCacheDrawable("product_hxrs_b.png");
}
/** */
public Drawable product_hxrs() {
return getCacheDrawable("product_hxrs.png");
}
/** */
public Drawable product_jxrs() {
return getCacheDrawable("product_jxrs.png");
}
/** */
public Drawable product_jxrs_b() {
return getCacheDrawable("product_jxrs_b.png");
}
/***金尊人生 背景图片
* @return
*/
public Drawable product_jzrs(){
return getCacheDrawable("product_jzrs.png");
}
/**
* @return
*/
public Drawable product_zyh(){
return getCacheDrawable("product_zyh.png");
}
/***
* @return
*/
public Drawable product_ctak(){
return getCacheDrawable("product_ctak.png");
}
/***
* @return
*/
public Drawable product_jyrs() {
return getCacheDrawable("product_jyrs.png");
}
/**
* @return
*/
public Drawable product_bbak(){
return getCacheDrawable("product_bbak.png");
}
//------------------4.18----------------
/***
* @return
*/
public Drawable product_lxak(){
return getCacheDrawable("product_lxak.png");
}
/***福享安康两全保险(分红型) 背景图片
* @return
*/
public Drawable product_fxak(){
return getCacheDrawable("product_fxak.png");
}
/***如意安康两全保险 背景图片
* @return
*/
public Drawable product_ryak(){
return getCacheDrawable("product_ryak.png");
}
/***万全安康重大疾病保险 背景图片
* @return
*/
public Drawable product_wqak(){
return getCacheDrawable("product_wqak.png");
}
public Drawable product_feature_bg_jzrs() {
return getCacheDrawable("product_feature_bg_jzrs.png");
}
/** 产品特色 鸿鑫人生B */
public Drawable product_feature_bg_hxrs_b() {
return getCacheDrawable("product_feature_bg_hxrs_b.png");
}
/** 产品特色 鸿鑫人生c */
public Drawable product_feature_bg_hxrs_c() {
return getCacheDrawable("product_feature_bg_hxrs_c.png");
}
/** 产品特色 金享人生 */
public Drawable product_feature_bg_jxrs() {
return getCacheDrawable("product_feature_bg_jxrs.png");
}
/** 产品特色 金享人生B款 */
public Drawable product_feature_bg_jxrs_b() {
return getCacheDrawable("product_feature_bg_jxrs_b.png");
}
/** 产品特色 鸿鑫人生 */
public Drawable product_feature_bg_hxrs() {
return getCacheDrawable("product_feature_bg_hxrs.png");
}
/** 产品特色 鸿发年年 */
public Drawable product_feature_bg_hfnn() {
return getCacheDrawable("product_feature_bg_hfnn.png");
}
/** 产品特色 鸿利年年 */
public Drawable product_feature_bg_hlnn() {
return getCacheDrawable("product_feature_bg_hlnn.png");
}
/** 产品特色 银福年年 */
public Drawable product_feature_bg_yfnn() {
return getCacheDrawable("product_feature_bg_yfnn.png");
}
/** 产品特色 福惠安享 */
public Drawable product_feature_bg_fhax() {
return getCacheDrawable("product_feature_bg_fhax.png");
}
/** 产品特色 状元红 */
public Drawable product_feature_bg_zyh() {
return getCacheDrawable("product_feature_bg_zyh.png");
}
/** 产品特色 长泰安康 */
public Drawable product_feature_bg_ctak() {
return getCacheDrawable("product_feature_bg_ctak.png");
}
/** 产品特色金玉人生——zhangshenhe*/
public Drawable product_feature_bg_jyrs(){
return getCacheDrawable("product_feature_bg_jyrs.png");
}
/** 产品特色宝宝安康——zhangshenhe*/
public Drawable product_feature_bg_bbak(){
return getCacheDrawable("product_feature_bg_bbak.png");
}
/** 产品特色 乐享安康两全保险(分红型)*/
public Drawable product_feature_bg_lxak(){
return getCacheDrawable("product_feature_bg_lxak.png");
}
/** 产品特色 福享安康两全保险(分红型)*/
public Drawable product_feature_bg_fxak(){
return getCacheDrawable("product_feature_bg_fxak.png");
}
/** 产品特色 如意安康两全保险*/
public Drawable product_feature_bg_ryak(){
return getCacheDrawable("product_feature_bg_ryak.png");
}
/** 产品特色 万全安康重大疾病保险*/
public Drawable product_feature_bg_wqak(){
return getCacheDrawable("product_feature_bg_wqak.png");
}
/** 人工核保不可收费 */
public Drawable verify_bg() {
return getCacheDrawable("verify_bg.png");
}
/** 支付界面 */
public Drawable pay_bg() {
return getCacheDrawable("pay_bg.png");
}
/** 警告 */
public Drawable tell_warn() {
return getCacheDrawable("tell_warn.png");
}
/** 附加险 */
public Drawable addtion_bg() {
return getCacheDrawable("addtion_bg.jpg");
}
/** 签署并关联《投保确认书》 */
public Drawable associate_bg() {
return getCacheDrawable("associate_bg.png");
}
/** 产品信息 产品简介 鸿鑫人生B 按钮效果 */
public Drawable product_feature_selector_hxrs_b() {
return getStateDrawable("product_feature_normal_hxrs_b.png", "product_feature_pressed_hxrs_b.png");
}
/** 产品信息 产品简介 金享人生 按钮效果 */
public Drawable product_feature_selector_jxrs() {
return getStateDrawable("product_feature_normal_jxrs.png", "product_feature_pressed_jxrs.png");
}
/** 产品信息 产品简介 金享人生B款 按钮效果 */
public Drawable product_feature_selector_jxrs_b() {
return getStateDrawable("product_feature_normal_jxrs_b.png", "product_feature_pressed_jxrs_b.png");
}
/** 产品信息 产品简介 鸿鑫人生 按钮效果 */
public Drawable product_feature_selector_hxrs() {
return getStateDrawable("product_feature_normal_hxrs.png", "product_feature_pressed_hxrs.png");
}
public Drawable product_feature_selector_jzrs(){
return getStateDrawable("product_feature_normal_jzrs.png", "product_feature_pressed_jzrs.png");
}
/**产品信息 产品简介 鸿鑫人生 c按钮效果*/
public Drawable product_feature_selector_hxrs_c(){
return getStateDrawable("product_feature_normal_hxrs_c.png", "product_feature_pressed_hxrs_c.png");
}
/**产品信息 产品简介 鸿发年年 按钮效果*/
public Drawable product_feature_selector_hfnn(){
return getStateDrawable("product_feature_normal_hfnn.png", "product_feature_pressed_hfnn.png");
}
/**产品信息 产品简介 鸿利年年 按钮效果*/
public Drawable product_feature_selector_hlnn(){
return getStateDrawable("product_feature_normal_hlnn.png", "product_feature_pressed_hlnn.png");
}
/**产品信息 产品简介 银福年年 按钮效果*/
public Drawable product_feature_selector_yfnn(){
return getStateDrawable("product_feature_normal_yfnn.png", "product_feature_pressed_yfnn.png");
}
/**产品信息 产品简介 福惠安享 按钮效果*/
public Drawable product_feature_selector_fhax(){
return getStateDrawable("product_feature_normal_fhax.png", "product_feature_pressed_fhax.png");
}
/**产品信息 产品简介 状元红 按钮效果*/
public Drawable product_feature_selector_zyh(){
return getStateDrawable("product_feature_normal_zyh.png", "product_feature_pressed_zyh.png");
}
/**产品信息 产品简介 长泰安康 按钮效果*/
public Drawable product_feature_selector_ctak(){
return getStateDrawable("product_feature_normal_ctak.png", "product_feature_pressed_ctak.png");
}
/**产品信息 产品简介 金玉人生 按钮效果 ——zhangshenhe*/
public Drawable product_feature_selector_jyrs() {
return getStateDrawable("product_feature_normal_jyrs.png", "product_feature_pressed_jyrs.png");
}
/** 产品信息 产品简介 宝宝安康 按钮效果 ——zhangshenhe*/
public Drawable product_feature_selector_bbak() {
return getStateDrawable("product_feature_normal_bbak.png", "product_feature_pressed_bbak.png");
}
/**产品信息 产品简介 乐享安康 按钮效果*/
public Drawable product_feature_selector_lxak(){
return getStateDrawable("product_feature_normal_lxak.png", "product_feature_pressed_lxak.png");
}
/**产品信息 产品简介 福享安康 按钮效果*/
public Drawable product_feature_selector_fxak(){
return getStateDrawable("product_feature_normal_fxak.png", "product_feature_pressed_fxak.png");
}
/**产品信息 产品简介 如意安康 按钮效果*/
public Drawable product_feature_selector_ryak(){
return getStateDrawable("product_feature_normal_ryak.png", "product_feature_pressed_ryak.png");
}
/**产品信息 产品简介 万全安康重大疾病保险 按钮效果*/
public Drawable product_feature_selector_wqak(){
return getStateDrawable("product_feature_normal_wqak.png", "product_feature_pressed_wqak.png");
}
/** 状态按钮效果 */
private Drawable getStateDrawable(String key_normal, String key_pressed) {
Drawable normal = getCacheDrawable(key_normal);
Drawable selected = getCacheDrawable(key_pressed);
Drawable pressed = selected;
StateListDrawable result = new StateListDrawable();
result.addState(StateView.PRESSED_ENABLED_STATE_SET, pressed);
result.addState(StateView.ENABLED_FOCUSED_STATE_SET, selected);
result.addState(StateView.ENABLED_STATE_SET, normal);
result.addState(StateView.FOCUSED_STATE_SET, selected);
result.addState(StateView.EMPTY_STATE_SET, normal);
return result;
}
/**
* 从SD卡 加载图片
*
* @param imgName 图片名称
* @return
*/
private static Bitmap getBitmap(String imgName) {
return BitmapFactory.decodeFile(RESOURCE_SAVE_BASE_PATH + SD_CPIC_IMAGE + imgName);
}
/***
* @param imgName 图片名称
* @return
*/
public static Drawable getDrawable(String imgName) {
return BitmapDrawable.createFromPath(RESOURCE_SAVE_BASE_PATH + SD_CPIC_IMAGE + imgName);
}
/***
* @param updateResourceMap 需要下载更新的资源列表
* @param serverDateTime 服务端时间
*/
@TargetApi(Build.VERSION_CODES.CUPCAKE)
public static void downloadResource(final StartActivity ctx,
final Map<String, String> updateResourceMap,
final Map<String,ModifiedResource> downloadModifyResMap,
final long serverCurrentTimeMills) {
File baseDir = new File(RESOURCE_SAVE_BASE_PATH + SD_CPIC_IMAGE);
if (!baseDir.exists()) {
baseDir.mkdirs();
}
File htmlDir = new File(RESOURCE_SAVE_BASE_PATH + SD_CPIC_HTML);
if (!htmlDir.exists()) {
htmlDir.mkdirs();
}
new AsyncTask<Void, Void, Integer>() {
private ProgressDialog dp;
@Override
protected void onPreExecute() {
dp = new ProgressDialog(ctx);
dp.progress_dialog_title.setText("正在下载图片,请稍候...");
final int totalImgNum = updateResourceMap==null? 0 : updateResourceMap.size();
dp.setMaxCount(totalImgNum);
dp.show();
}
@Override
protected Integer doInBackground(Void... params) {
try {
int successDownloadCounter = 0; //成功下载的资源数量
int resourceCounter = 0;//资源数量 计算器
if (updateResourceMap != null && updateResourceMap.keySet()!= null) {
Iterator<String> fileNameIter = updateResourceMap.keySet().iterator();
final Map<String,Long> allResourceLenthMap = SQLiteHelper.findAllResourceNamesSizePairMap();
while(fileNameIter.hasNext()) {
final String fileName = fileNameIter.next();
final String downloadURI = updateResourceMap.get(fileName);
//如果成功下载资源
if(downloadPic(fileName,downloadURI,allResourceLenthMap)) {
successDownloadCounter++;
if(downloadModifyResMap!=null && downloadModifyResMap.containsKey(fileName)) {
SQLiteHelper.addSuccessDownloadedModifyResource(downloadModifyResMap.get(fileName));
}
}
dp.refresh_next(); //再刷新下载进度
resourceCounter++;
}
}
return resourceCounter;
} catch (Exception e) {
Logger.printStackTrace(TAG, e);
}
return 0;
}
@Override
protected void onPostExecute(final Integer successDownloadCounter) {
if (dp != null) {
dp.dismiss();
if(successDownloadCounter>0 && successDownloadCounter == updateResourceMap.size()) {
SQLiteHelper.updateLastUpdateResourceDateTime(DateUtils.format(new Date(serverCurrentTimeMills), DateUtils.DATE_TIME_PATTERN));
}
}
}
}.execute();
}
/**
* 单个下载 需要更新的资源文件 ,图片的保存位置:sdcard/cpic/images
* @param imgName 图片名称
* @param resourceURI 资源文件的uri, 服务端返回的 uri格式: /imgUploadDir/fileName
* @return 返回是否成功下载资源文件
*/
private static boolean downloadPic(final String imgName,String resourceURI,final Map<String,Long> allResourceLenthMap) {
boolean downloadSuccessFlag = true;
int fileLength = 0;
if(StringUtils.isEmpty(resourceURI)) {
downloadSuccessFlag = false;
}else {
String path = RESOURCE_SAVE_BASE_PATH;
if (isImageFile(resourceURI)) {
path += SD_CPIC_IMAGE;//存到图片文件夹 sdcard/cpic/images
} else if (isHtmlFile(resourceURI)) {
path += SD_CPIC_HTML;
} else {
path += SD_CPIC; //存到 sdcard/cpic/
}
InputStream is = null;
FileOutputStream fileOutputStream = null;
File localResourceFile = null;
try {
final String slash = "/";
if (!resourceURI.startsWith(slash)) {
resourceURI = slash + resourceURI;
}
final String fullUrl = "http://" + HessianBase.CONNECTION_URL + HessianBase.CONTEXT_PATH + resourceURI;
final URL picUrl = new URL(fullUrl);
HttpURLConnection conn = (HttpURLConnection) picUrl.openConnection();
conn.setReadTimeout(3 * 1000);
conn.setRequestMethod("GET");
conn.setDoInput(true);
conn.connect();
is = conn.getInputStream();
fileLength = (int) conn.getContentLength();
if (fileLength > 0) {
int byteReadTotal = 0;
localResourceFile = new File(path, imgName);
fileOutputStream = new FileOutputStream(localResourceFile);
int bytesRead = -1;
byte[] buf = new byte[1024];
while ((bytesRead = is.read(buf)) != -1) {
fileOutputStream.write(buf, 0, bytesRead);
byteReadTotal +=bytesRead;
}
fileOutputStream.flush();
//如果下载的文件,差1K 没有下载完 ,则下载失败
if(Math.abs(fileLength - byteReadTotal)>= AppConstants.LOST_IMG_SIZE_LIMITED) {
downloadSuccessFlag = false;
localResourceFile.delete();
}
}else {
downloadSuccessFlag = false;
}
} catch (Exception e) {
Logger.printStackTrace(TAG, e);
if(localResourceFile != null){
localResourceFile.delete();
}
downloadSuccessFlag = false;
} finally {
try {
if (fileOutputStream != null)
fileOutputStream.close();
if (is != null)
is.close();
} catch (IOException ex) {
Logger.printStackTrace(TAG, ex);
if(localResourceFile != null){
localResourceFile.delete();
}
downloadSuccessFlag = false;
}
}
}
//如果图片下载成功,并且 数据库中存储的文件大小与下载下来的文件大小不一致,则更新库中的图片大小
if(downloadSuccessFlag && allResourceLenthMap.containsKey(imgName) && fileLength!= allResourceLenthMap.get(imgName)) {
SQLiteHelper.updateResourceSizeByResourceName(imgName, fileLength);
}
return downloadSuccessFlag;
}
/**
* 从缓存加载图片
*
* @param imgName 图片名称
* @return
*/
private Bitmap getCacheBitmap(String imgName) {
//从SD卡
// if (mBitmaps.containsKey(imgName)) {
// WeakReference<Bitmap> softReference = mBitmaps.get(imgName);
// Bitmap drawable = softReference.get();
// if (drawable != null && !drawable.isRecycled()) {
// return drawable;
// }
// }
// //先从SD卡中加载
// Bitmap sd_img = getBitmap(imgName);
// if (sd_img != null && !sd_img.isRecycled()) { //如果图像加载成功,则放入bitMap缓存
// mBitmaps.put(imgName, new WeakReference<Bitmap>(sd_img));
// }
if(mBitmaps.containsKey(imgName)){
WeakReference<Bitmap> weakReference = mBitmaps.get(imgName);
Bitmap drawable = weakReference.get();
if(null!=drawable && !drawable.isRecycled()){
return drawable;
}
}
Bitmap sd_img = getBitmap(imgName);
if(sd_img!=null && !sd_img.isRecycled()){
mBitmaps.put(imgName, new WeakReference<Bitmap>(sd_img));
}
return sd_img;
}
/***
* @param imgFileName 图片文件名称
* @return
*/
private Drawable getCacheDrawable(String imgFileName) {
//从SD卡
if (mDrawables.containsKey(imgFileName)) {
WeakReference<Drawable> softReference = mDrawables.get(imgFileName);
Drawable drawable = softReference.get();
if (drawable != null) {
return drawable;
}
}
//从SD卡中加载
Drawable drawImg = getDrawable(imgFileName);
if (drawImg != null) {
mDrawables.put(imgFileName, new WeakReference<Drawable>(drawImg));
}
return drawImg;
}
/**成功下载了的 修改资源 **/
public static final class ModifiedResource implements Serializable{
private static final long serialVersionUID = 1L;
public Set<Integer> modifyVersions;
public String resourceName;
public ModifiedResource(String resourceName){
this.resourceName = resourceName;
}
public ModifiedResource(Set<Integer> versions, String resourceName) {
this.modifyVersions = versions;
this.resourceName = resourceName;
}
public void addModifyVersion(int version) {
if(this.modifyVersions ==null) {
modifyVersions = new HashSet<Integer>();
modifyVersions.add(version);
}
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((resourceName == null) ? 0 : resourceName.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ModifiedResource other = (ModifiedResource) obj;
if (resourceName == null) {
if (other.resourceName != null)
return false;
} else if (!resourceName.equals(other.resourceName))
return false;
return true;
}
}
private static class StateView extends View {
public StateView(Context context) {
super(context);
}
public static int[] PRESSED_ENABLED_STATE_SET = View.PRESSED_ENABLED_STATE_SET;
public static int[] ENABLED_FOCUSED_STATE_SET = View.ENABLED_FOCUSED_STATE_SET;
public static int[] ENABLED_STATE_SET = View.ENABLED_STATE_SET;
public static int[] FOCUSED_STATE_SET = View.FOCUSED_STATE_SET;
public static int[] EMPTY_STATE_SET = View.EMPTY_STATE_SET;
}
/****
* 是否是图片文件
*
* @param fileName
* @return
*/
private static boolean isImageFile(String fileName) {
fileName = fileName.toLowerCase();
return fileName.endsWith("png") || fileName.endsWith("jpg") || fileName.endsWith("jpeg")
|| fileName.endsWith("gif") || fileName.equals("bmp");
}
/****
* 是否是html文件
* @param fileName
* @return
*/
private static boolean isHtmlFile(String fileName) {
fileName = fileName.toLowerCase();
return fileName.endsWith(".html");
}
}