package com.android.library;

import android.app.Application;
import android.content.Context;
import android.content.res.Resources;
import android.support.annotation.ArrayRes;
import android.support.annotation.StringRes;

import com.android.library.httptask.TestVolley;
import com.android.library.utils.LogMgr;
import com.android.volley.Cache;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.RequestQueue.RequestFilter;
import com.android.volley.RequestQueue.RequestFinishedListener;
import com.android.volley.VolleyLog;

/**
 * Created by KEVIN.DAI on 15/7/8.
 */
public class BaseApplication extends Application {

    private static Context mContext;
    /**
     * Global request queue for Volley.
     */
    private static RequestQueue mReqQueue;

    @Override
    public void onCreate() {

        super.onCreate();
        mContext = getApplicationContext();
        initVolley();
    }

    public static Context getContext() {

        return mContext;
    }

    public static Resources getAppResources() {

        return mContext.getResources();
    }

    public static String getAppString(@StringRes int resId) {

        return getAppResources().getString(resId);
    }

    public static String getAppString(@StringRes int resId, Object... formatArgs) {

        return getAppResources().getString(resId, formatArgs);
    }

    public static String[] getAppStringArray(@ArrayRes int resId) {

        return getAppResources().getStringArray(resId);
    }

//    private static void releaseContext() {
//
//        mContext = null;
//    }

    /**
     * the queue will be created if it is null.
     */
    private void initVolley() {

        if (mReqQueue == null) {

            mReqQueue = TestVolley.newRequestQueue(mContext);
            mReqQueue.addRequestFinishedListener(mReqFinishLis);
        }
        VolleyLog.DEBUG = true;
    }

    /**
     * @return The Volley Request queue.
     */
    public static RequestQueue getRequestQueue() {

        return mReqQueue;
    }

    public static Cache getVolleyCache() {

        return mReqQueue == null ? null : mReqQueue.getCache();
    }

    private static RequestFinishedListener mReqFinishLis = new RequestFinishedListener() {

        @Override
        public void onRequestFinished(Request request) {

            if (LogMgr.isDebug())
                LogMgr.d("BaseApplication", "~~request finished. tag: " + request.getTag() + ", sequence number: " + request.getSequence());
        }
    };

    private static void releaseVolley() {

        if (mReqQueue != null) {

            mReqQueue.removeRequestFinishedListener(mReqFinishLis);
            mReqQueue.cancelAll(new RequestFilter() {

                @Override
                public boolean apply(Request<?> request) {

                    return true;
                }
            });
//            mReqQueue = null;
        }
    }

    protected static void release() {

        releaseVolley();
//        releaseContext();
    }
}
@@ -566,16 +566,69 @@
 lleyLog;
+%0Aimport com.facebook.drawee.backends.pipeline.Fresco;
 %0A%0A/**%0A *
@@ -935,33 +935,95 @@
     
-m
+init
 Context
- = getApplication
+();%0A        initVolley();%0A        initFresco();%0A    %7D%0A%0A    private void init
 Cont
@@ -1019,33 +1019,35 @@
 id initContext()
-;
+ %7B%0A
 %0A        initVol
@@ -1035,34 +1035,56 @@
  %7B%0A%0A        
-initVolley
+mContext = getApplicationContext
 ();%0A    %7D%0A%0A 
@@ -1148,32 +1148,108 @@
 Context;%0A    %7D%0A%0A
+    private static void releaseContext() %7B%0A%0A        mContext = null;%0A    %7D%0A%0A
     public stati
@@ -1740,92 +1740,8 @@
  %7D%0A%0A
-//    private static void releaseContext() %7B%0A//%0A//        mContext = null;%0A//    %7D%0A%0A
     
@@ -2035,32 +2035,105 @@
  = true;%0A    %7D%0A%0A
+    private void initFresco() %7B%0A%0A        Fresco.initialize(this);%0A    %7D%0A%0A
     /**%0A     * @
@@ -3087,16 +3087,48 @@
     %7D);%0A
+//            mReqQueue.stop();%0A
 //      
@@ -3164,24 +3164,101 @@
    %7D%0A    %7D%0A%0A
+    private static void releaseFresco() %7B%0A%0A        Fresco.shutDown();%0A    %7D%0A%0A
     protecte
@@ -3280,24 +3280,51 @@
 elease() %7B%0A%0A
+//        releaseFresco();%0A
         rele

把Fresco的初始化和release的调用放在BaseApplication里；整理代码