Kaynağa Gözat

Add common editor public library -- 添加common editor 公共库 (issue40: #14499)

Ray Zhang 4 yıl önce
ebeveyn
işleme
bdd02601ff

+ 36 - 33
ApexDrivers/CommonEditorLib/src/main/java/com/usai/commoneditorlib/CommonEditorActivity.java

@@ -1,5 +1,7 @@
 package com.usai.commoneditorlib;
 
+import android.app.AlertDialog;
+//import android.app.ProgressDialog;/**/
 import android.app.ProgressDialog;
 import android.content.Context;
 import android.content.Intent;
@@ -104,19 +106,19 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
         public JSONArray missingfields;
     }
 
-    public ProgressDialog showProgressAlert(String title,String msg) {
-        ProgressDialog pd = new ProgressDialog(this);
-        pd.setTitle(title);
-        pd.setMessage(msg);
-        /**
-         * false,表示 ProgressDialog 是不能通过 Back 键取消
-         * 数据加载完成后必须要调用 ProgressDialog 的 dismiss() 方法来关闭对话框
-         * */
-        pd.setCancelable(false);
-        pd.show();
-
-        return pd;
-    }
+//    public ProgressDialog showProgressAlert(String title,String msg) {
+//        ProgressDialog pd = new ProgressDialog(this);
+//        pd.setTitle(title);
+//        pd.setMessage(msg);
+//        /**
+//         * false,表示 ProgressDialog 是不能通过 Back 键取消
+//         * 数据加载完成后必须要调用 ProgressDialog 的 dismiss() 方法来关闭对话框
+//         * */
+//        pd.setCancelable(false);
+//        pd.show();
+//
+//        return pd;
+//    }
 
     @Override
     public boolean onCreateOptionsMenu(Menu menu) {
@@ -262,7 +264,7 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
 
 
 
-            final ProgressDialog pd = showProgressAlert("Loading","Please wait");
+            final ProgressDialog pd = RAUtil.waiting_alert(this,"Loading","Please wait");
             new Thread(new Runnable() {
                 @Override
                 public void run() {
@@ -291,11 +293,12 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
                                         adapter.notifyDataSetChanged();
 
                                     } else {
-                                        Utils.alertMessage(mCtx,"Warning","Error");
+
+                                        RAUtil.alertMessage(mCtx,"Warning","Error");
                                     }
 
                                 } else {
-                                    Utils.message_alert(mCtx,"Warning","Error");
+                                    RAUtil.alertMessage(mCtx,"Warning","Error");
                                 }
 
                             }
@@ -398,7 +401,7 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
             String url_down = data.getStringExtra("url_down");
             String url_up = data.getStringExtra("url_up");
             String path = data.getStringExtra("path");
-            Utils.cacheLocalImageToURL(path,url_up); // 将图片移动到缓存目录
+            RAUtil.cacheLocalImageToURL(this,path,url_up); // 将图片移动到缓存目录
             // 对应更新数据,然刷新该行
             imgIsChanged(url_down,url_up,group,child,btn,url_up);
         }
@@ -498,7 +501,7 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
             String url_up = data.getStringExtra("url_up"); // value
             String path = data.getStringExtra("path");
 
-            Utils.cacheLocalImageToURL(path,url_down);
+            RAUtil.cacheLocalImageToURL(CommonEditorActivity.this,path,url_down);
 
             signatureIsChanged(url_down,url_up,group,child);
         }
@@ -1117,7 +1120,7 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
             endEditting();
         }
 
-        final ProgressDialog pd = showProgressAlert("Loading","Please wait");
+        final ProgressDialog pd = RAUtil.waiting_alert(CommonEditorActivity.this,"Loading","Please wait");
 
         if (url_type == URL_REMOTE) {
 
@@ -1150,7 +1153,7 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
                         public void run() {
                             pd.dismiss();
                             if (editor_json == null) {
-                                Utils.message_alert(mCtx,"Warning","net error");
+                                RAUtil.alertMessage(mCtx,"Warning","net error");
                                 adapter.notifyDataSetChanged();
                                 return;
                             }
@@ -1162,7 +1165,7 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
                                 adapter.notifyDataSetChanged();
 
                             } else {
-                                Utils.message_alert(mCtx,"Warning",editor_json.optString("err_msg"));
+                                RAUtil.alertMessage(mCtx,"Warning",editor_json.optString("err_msg"));
                             }
                         }
                     });
@@ -1318,7 +1321,7 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
                                         JSONObject itemjson_j = sectionjson.optJSONObject("item_" + j);
                                         String key_j = itemjson_j.optString("name");
 
-                                        if (key_j == null || key_j.isEmpty()) {
+                                        if ( key_j.isEmpty()) {
                                             continue;
                                         }
 
@@ -2458,7 +2461,7 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
 
         Bitmap placeHolder = BitmapFactory.decodeResource(getResources(),R.drawable.not_found);
         if (img_url_0 != null && !img_url_0.isEmpty()) {
-            Bitmap bmp0 = Utils.loadCacheImage(img_url_up_0,placeHolder);
+            Bitmap bmp0 = RAUtil.loadCacheImage(this,img_url_up_0,placeHolder);
             if (bmp0 != null) {
                 holder.setImage0(img_url_up_0,bmp0);
             } else {
@@ -2468,7 +2471,7 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
         }
 
         if (img_url_1 != null && !img_url_1.isEmpty()) {
-            Bitmap bmp1 = Utils.loadCacheImage(img_url_up_1,placeHolder);
+            Bitmap bmp1 = RAUtil.loadCacheImage(this,img_url_up_1,placeHolder);
             if (bmp1 != null) {
                 holder.setImage1(img_url_up_1,bmp1);
             } else {
@@ -2478,7 +2481,7 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
         }
 
         if (img_url_2 != null && !img_url_2.isEmpty()) {
-            Bitmap bmp2 = Utils.loadCacheImage(img_url_up_2,placeHolder);
+            Bitmap bmp2 = RAUtil.loadCacheImage(this,img_url_up_2,placeHolder);
             if (bmp2 != null) {
                 holder.setImage2(img_url_up_2,bmp2);
             } else {
@@ -2505,7 +2508,7 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
 
                 try {
 
-                    bitmap = Utils.loadCacheImage(path,null);
+                    bitmap = RAUtil.loadCacheImage(CommonEditorActivity.this,path,null);
 
 
                     if (bitmap == null) {
@@ -2535,7 +2538,7 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
                     if (bitmap == null) {
                         bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.not_found);
                     }
-                    Utils.cacheImage(path,bitmap);
+                    RAUtil.cacheImage(CommonEditorActivity.this,path,bitmap);
                     // 更新数据,刷新行
                     runOnUiThread(new Runnable() {
                         @Override
@@ -3066,7 +3069,7 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
 
             img_url = "http://img.gank.io/6ade6383-bc8e-40e4-9919-605901ad0ca5?imageView2/0/w/100";
             Bitmap placeHolder = BitmapFactory.decodeResource(getResources(),R.drawable.not_found);
-            Bitmap bmp = Utils.loadCacheImage(img_url,placeHolder);
+            Bitmap bmp = RAUtil.loadCacheImage(CommonEditorActivity.this,img_url,placeHolder);
             if (bmp != null) {
                 holder.model_img_btn.setImageBitmap(bmp);
             } else {
@@ -3194,7 +3197,7 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
         }
         Bitmap placeHolder = BitmapFactory.decodeResource(getResources(),R.drawable.not_found);
         if (img_url != null && !img_url.isEmpty()) {
-            Bitmap bmp = Utils.loadCacheImage(img_url,placeHolder);
+            Bitmap bmp = RAUtil.loadCacheImage(CommonEditorActivity.this,img_url,placeHolder);
             if (bmp != null) {
                 holder.signature_iv.setImageBitmap(bmp);
             } else {
@@ -4034,7 +4037,7 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
                     JSONObject params = new JSONObject();
                     params.put(name,val);
 
-                    final ProgressDialog pd = Utils.waiting_alert(mCtx,"loading","please wait");
+                    final ProgressDialog pd = RAUtil.waiting_alert(mCtx,"loading","please wait");
                     final JSONObject final_params = params;
                     new Thread(new Runnable() {
                         @Override
@@ -4056,7 +4059,7 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
                                             setValue(name,value);
                                         }
                                     } else {
-                                        Utils.alertMessage(mCtx,"",editor_json.optString("err_msg"));
+                                        RAUtil.alertMessage(mCtx,"",editor_json.optString("err_msg"));
                                     }
 
                                 }
@@ -4130,7 +4133,7 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
 
                     JSONObject params = new JSONObject();
                     params.put(name,val);
-                    final ProgressDialog pd = Utils.waiting_alert(mCtx,"loading","please wait");
+                    final ProgressDialog pd = RAUtil.waiting_alert(mCtx,"loading","please wait");
                     final JSONObject final_params = params;
                     new Thread(new Runnable() {
                         @Override
@@ -4153,7 +4156,7 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
                                             setValue(name,value);
                                         }
                                     } else {
-                                        Utils.message_alert(mCtx,"",editor_json.optString("err_msg"));
+                                        RAUtil.alertMessage(mCtx,"",editor_json.optString("err_msg"));
                                     }
 
                                 }

+ 0 - 294
ApexDrivers/CommonEditorLib/src/main/java/com/usai/commoneditorlib/Utils.java

@@ -1,294 +0,0 @@
-package com.usai.commoneditorlib;
-
-import android.app.AlertDialog;
-import android.app.ProgressDialog;
-import android.content.Context;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.PackageManager;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.os.Bundle;
-import android.os.Environment;
-
-
-//import com.usai.commoneditorlib.RedAntApplication;
-
-import org.json.JSONObject;
-
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-import java.util.UUID;
-
-/**
- * Created by macmini1 on 2017/8/17.
- */
-
-public class Utils {
-
-//    public static String getApplicationName(Context context) {
-//
-//        if (context == null) {
-//            return null;
-//        }
-//
-//        PackageManager packageManager = null;
-//        ApplicationInfo applicationInfo = null;
-//        try {
-//            packageManager = context.getPackageManager();
-//            applicationInfo = packageManager.getApplicationInfo(context.getPackageName(), 0);
-//        } catch (PackageManager.NameNotFoundException e) {
-//            applicationInfo = null;
-//        }
-//        String applicationName = (String) packageManager.getApplicationLabel(applicationInfo);
-//        return applicationName;
-//    }
-
-//
-//
-//    public static Bitmap loadCacheImage(String path,Bitmap holder) {
-//
-////        System.gc();
-////        try {
-////            Context context = RedAntApplication.getInstance().getApplicationContext();
-////            String file_path = Environment.getExternalStorageDirectory().getPath() + "/" + getApplicationName(context) + "/Cache/Image" + stringToMD5(path);
-////            File file = new File(file_path);
-////            if (!file.exists()) {
-////                loadImage(path);
-////                return holder;
-////            }
-////            Bitmap bitmap = BitmapFactory.decodeFile(file_path);
-////            return bitmap;
-////
-////        } catch (Exception e) {
-////            e.printStackTrace();
-////        }
-////
-////        return holder;
-//
-//        return loadCacheImage(path,holder,false);
-//    }
-//
-//    public static Bitmap loadCacheImage(String path,Bitmap holder, boolean remoteLoad) {
-//        System.gc();
-//        try {
-//            Context context = RedAntApplication.getInstance().getApplicationContext();
-//            String file_path = Environment.getExternalStorageDirectory().getPath() + "/" + getApplicationName(context) + "/Cache/Image" + stringToMD5(path);
-//            File file = new File(file_path);
-//            if (!file.exists()) {
-//                if (remoteLoad) {
-//                    loadImage(path);
-//                }
-//                return holder;
-//            }
-//            Bitmap bitmap = BitmapFactory.decodeFile(file_path);
-//            return bitmap;
-//
-//        } catch (Exception e) {
-//            e.printStackTrace();
-//        }
-//
-//        return holder;
-//    }
-//
-//    public static String cacheTmpImage(Bitmap bitmap) {
-//        if (bitmap == null) {
-//            return null;
-//        }
-//
-//        bitmap = compressBitmap(bitmap);
-//
-//        Context context = RedAntApplication.getInstance().getApplicationContext();
-//        String file_path = Environment.getExternalStorageDirectory().getPath() + "/" + getApplicationName(context) + "/Cache/Tmp";
-//        File dir_file = new File(file_path);
-//        if (!dir_file.exists()) {
-//            dir_file.mkdirs();
-//        }
-//        file_path = file_path + UUID.randomUUID().toString();
-//        try {
-//
-//            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file_path));
-//            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos);
-//            bos.flush();
-//            bos.close();
-//
-//            return file_path;
-//        } catch (IOException e) {
-//            e.printStackTrace();
-//
-//        }
-//
-//        return null;
-//
-//    }
-//
-//    public static void loadImage(final String path) {
-//        new Thread(new Runnable() {
-//            @Override
-//            public void run() {
-//                HttpURLConnection cnn = null;
-//                Bitmap bitmap = null;
-//                try {
-//                    URL url = new URL(path);
-//                    cnn = (HttpURLConnection)url.openConnection();
-//                    cnn.setRequestMethod("GET");
-//                    cnn.setUseCaches(false);
-//                    cnn.setConnectTimeout(1500);
-//                    cnn.setReadTimeout(1500);
-//                    bitmap = BitmapFactory.decodeStream(cnn.getInputStream());
-//
-//                    if (bitmap != null) {
-//                        cacheImage(path,bitmap);
-//                    }
-//
-//
-//                } catch (IOException e) {
-//                    e.printStackTrace();
-//
-//                } finally {
-//                    if (cnn != null) {
-//                        cnn.disconnect();
-//                    }
-//
-//                }
-//            }
-//        }).start();
-//    }
-//
-//    public static void cacheLocalImageToURL(String path,String url) {
-//
-//
-//        String filename =stringToMD5(url);
-//        File file = new File(path);
-//
-//
-//
-//        if (file.exists()) {
-//
-//            Context context = RedAntApplication.getInstance().getApplicationContext();
-//            String file_path = Environment.getExternalStorageDirectory().getPath() + "/" + getApplicationName(context) + "/Cache/Image";
-//            File tmpF = new File(file_path);
-//            if (!tmpF.exists()) {
-//                tmpF.mkdirs();
-//            }
-//            file_path = file_path + "/" + filename;
-//
-//            InputStream is = null;
-//            FileOutputStream os = null;
-//            try {
-//                is = new FileInputStream(file);
-//                os = new FileOutputStream(file_path);
-//                byte[] buffer = new byte[1024];
-//                int read = 0;
-//                while ((read = is.read(buffer)) != -1) {
-//                    os.write(buffer,0,read);
-//                }
-//
-//            } catch (IOException e) {
-//                e.printStackTrace();
-//            } finally {
-//                try {
-//
-//                    os.flush();
-//                    os.close();
-//                    is.close();
-//
-//                } catch (IOException e) {
-//                    e.printStackTrace();
-//                }
-//            }
-//
-//        }
-//
-//    }
-//
-//    public static void cacheImage(String path,Bitmap bitmap) {
-//
-//
-//        bitmap = compressBitmap(bitmap);
-//
-//        try {
-//
-//            Context context = RedAntApplication.getInstance().getApplicationContext();
-//            String file_dir = Environment.getExternalStorageDirectory().getPath() + "/" + getApplicationName(context) + "/Cache/Image";
-//            File dir = new File(file_dir);
-//            if (!dir.exists()) {
-//                dir.mkdirs();
-//            }
-//            String file_path = file_dir + "/" + stringToMD5(path);
-//
-//            File file = new File(file_path);
-//
-//            savePhotoToFile(bitmap,file);
-//
-//        } catch (Exception e) {
-//            e.printStackTrace();
-//        }
-//
-//
-//    }
-//
-//    private static Bitmap compressBitmap(Bitmap bitmap) {
-//        int width = 500;
-//        int height = 500;
-//        if (bitmap.getWidth() > width || bitmap.getHeight() > height) {
-//            bitmap = Bitmap.createScaledBitmap(bitmap,width,height,false);
-//        }
-//        return bitmap;
-//    }
-//
-//    private static void savePhotoToFile(Bitmap bitmap, File photoFile) {
-//        if (photoFile == null || bitmap == null) {
-//            return;
-//        }
-//        try {
-//
-//            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(photoFile));
-//            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos);
-//            bos.flush();
-//            bos.close();
-//
-//        } catch (IOException e) {
-//            e.printStackTrace();
-//
-//        }
-//    }
-//
-//
-//    public static ProgressDialog waiting_alert(Context ctx,String title, String msg) {
-//        if (ctx == null) {
-//            return null;
-//        }
-//        ProgressDialog pd = new ProgressDialog(ctx);
-//        pd.setTitle(title);
-//        pd.setMessage(msg);
-//
-//        pd.setCancelable(true);
-//
-//        pd.show();
-//
-//        return pd;
-//    }
-//
-//    public static void message_alert(Context ctx,String title,String msg) {
-//        if (ctx == null) {
-//            return;
-//        }
-//        new AlertDialog.Builder(ctx)
-//                .setTitle(title)
-//                .setMessage(msg)
-//                .show();
-//    }
-//
-//
-
-
-}

BIN
ApexDrivers/CommonEditorLib/src/main/res/drawable/not_found.png


+ 18 - 0
ApexDrivers/CommonEditorLib/src/main/res/drawable/red_border.xml

@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <!--背景色-->
+    <solid android:color="#FFFFFF" />
+
+    <!--边框颜色-->
+    <stroke
+        android:width="0.01dp"
+        android:color="#ff0000" />
+
+    <padding
+        android:bottom="1dp"
+        android:left="1dp"
+        android:right="1dp"
+        android:top="1dp" />
+
+</shape>

+ 174 - 0
ApexDrivers/RAUtilsLibrary/src/main/java/com/usai/redant/rautils/utils/RAUtil.java

@@ -2,6 +2,7 @@ package com.usai.redant.rautils.utils;
 
 import android.app.Activity;
 import android.app.Application;
+import android.app.ProgressDialog;
 import android.content.Context;
 import android.content.DialogInterface;
 import android.content.Intent;
@@ -11,12 +12,14 @@ import android.content.pm.PackageManager;
 import android.content.res.AssetManager;
 import android.content.res.Resources;
 import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
 import android.graphics.Canvas;
 import android.graphics.Matrix;
 import android.graphics.Paint;
 import android.location.LocationManager;
 import android.os.Build;
 import android.os.Bundle;
+import android.os.Environment;
 import android.provider.Settings;
 import androidx.core.app.ActivityCompat;
 import androidx.core.content.PermissionChecker;
@@ -32,8 +35,10 @@ import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
 
+import java.io.BufferedOutputStream;
 import java.io.BufferedReader;
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -42,6 +47,8 @@ import java.io.UnsupportedEncodingException;
 import java.lang.reflect.Array;
 import java.lang.reflect.Field;
 import java.lang.reflect.InvocationTargetException;
+import java.net.HttpURLConnection;
+import java.net.URL;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.util.ArrayList;
@@ -91,7 +98,20 @@ public class RAUtil {
         return null;
     }
 
+    public static ProgressDialog waiting_alert(Context ctx, String title, String msg) {
+        if (ctx == null) {
+            return null;
+        }
+        ProgressDialog pd = new ProgressDialog(ctx);
+        pd.setTitle(title);
+        pd.setMessage(msg);
+
+        pd.setCancelable(true);
 
+        pd.show();
+
+        return pd;
+    }
     // 读取json文件的方法,也可写成工具类方便使用
     public static JSONObject getJsonFromAsset(Context context, String fileName) {
 
@@ -896,6 +916,160 @@ public class RAUtil {
 
         return Pattern.matches(passwordRegex,password);
     }
+    public static void cacheImage(Context context,String path,Bitmap bitmap) {
+
+
+        bitmap = compressBitmap(bitmap);
+
+        try {
+
+            // Context context = RedAntApplication.getInstance().getApplicationContext();
+            String file_dir = Environment.getExternalStorageDirectory().getPath() + "/" + getApplicationName(context) + "/Cache/Image";
+            File dir = new File(file_dir);
+            if (!dir.exists()) {
+                dir.mkdirs();
+            }
+            String file_path = file_dir + "/" + stringToMD5(path);
+
+            File file = new File(file_path);
+
+            savePhotoToFile(bitmap,file);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+
+    }
+    private static Bitmap compressBitmap(Bitmap bitmap) {
+        int width = 500;
+        int height = 500;
+        if (bitmap.getWidth() > width || bitmap.getHeight() > height) {
+            bitmap = Bitmap.createScaledBitmap(bitmap,width,height,false);
+        }
+        return bitmap;
+    }
+
+    private static void savePhotoToFile(Bitmap bitmap, File photoFile) {
+        if (photoFile == null || bitmap == null) {
+            return;
+        }
+        try {
+
+            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(photoFile));
+            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos);
+            bos.flush();
+            bos.close();
+
+        } catch (IOException e) {
+            e.printStackTrace();
+
+        }
+    }
+    public static void cacheLocalImageToURL(Context context,String path,String url) {
+
+
+        String filename =stringToMD5(url);
+        File file = new File(path);
+
+
+
+        if (file.exists()) {
+
+            // Context context = RedAntApplication.getInstance().getApplicationContext();
+            String file_path = Environment.getExternalStorageDirectory().getPath() + "/" + getApplicationName(context) + "/Cache/Image";
+            File tmpF = new File(file_path);
+            if (!tmpF.exists()) {
+                tmpF.mkdirs();
+            }
+            file_path = file_path + "/" + filename;
+
+            InputStream is = null;
+            FileOutputStream os = null;
+            try {
+                is = new FileInputStream(file);
+                os = new FileOutputStream(file_path);
+                byte[] buffer = new byte[1024];
+                int read = 0;
+                while ((read = is.read(buffer)) != -1) {
+                    os.write(buffer,0,read);
+                }
+
+            } catch (IOException e) {
+                e.printStackTrace();
+            } finally {
+                try {
+
+                    os.flush();
+                    os.close();
+                    is.close();
+
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+
+        }
+
+    }
 
 
+    public static Bitmap loadCacheImage(Context context,String path,Bitmap holder) {
+
+        return loadCacheImage(context,path,holder,false);
+    }
+    public static Bitmap loadCacheImage(Context context,String path,Bitmap holder, boolean remoteLoad) {
+        System.gc();
+        try {
+//            Context context = RedAntApplication.getInstance().getApplicationContext();
+            String file_path = Environment.getExternalStorageDirectory().getPath() + "/" + getApplicationName(context) + "/Cache/Image" + stringToMD5(path);
+            File file = new File(file_path);
+            if (!file.exists()) {
+                if (remoteLoad) {
+                    loadImage(context,path);
+                }
+                return holder;
+            }
+            Bitmap bitmap = BitmapFactory.decodeFile(file_path);
+            return bitmap;
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        return holder;
+    }
+
+    public static void loadImage(final Context context, final String path) {
+        new Thread(new Runnable() {
+            @Override
+            public void run() {
+                HttpURLConnection cnn = null;
+                Bitmap bitmap = null;
+                try {
+                    URL url = new URL(path);
+                    cnn = (HttpURLConnection)url.openConnection();
+                    cnn.setRequestMethod("GET");
+                    cnn.setUseCaches(false);
+                    cnn.setConnectTimeout(1500);
+                    cnn.setReadTimeout(1500);
+                    bitmap = BitmapFactory.decodeStream(cnn.getInputStream());
+
+                    if (bitmap != null) {
+                        cacheImage(context,path,bitmap);
+                    }
+
+
+                } catch (IOException e) {
+                    e.printStackTrace();
+
+                } finally {
+                    if (cnn != null) {
+                        cnn.disconnect();
+                    }
+
+                }
+            }
+        }).start();
+    }
 }