package com.nutrition.express.application;

import android.app.ActivityManager;
import android.app.Application;
import android.content.Context;
import android.graphics.Bitmap;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.WindowManager;

import com.facebook.cache.disk.DiskCacheConfig;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.imagepipeline.core.ImagePipelineConfig;
import com.nutrition.express.BuildConfig;
import com.nutrition.express.model.rest.RestClient;

import static android.content.ContentValues.TAG;

/**
 * Created by huang on 4/25/16.
 */
public class ExpressApplication extends Application {
    public static int width;
    public static int height;
    private static ExpressApplication application;
    private ImagePipelineConfig imagePipelineConfig;

    @Override
    public void onCreate() {
        super.onCreate();
        application = this;
        DiskCacheConfig cacheConfig = DiskCacheConfig.newBuilder(this)
                .setMaxCacheSize(300 * 1024 * 1024)
                .build();
        imagePipelineConfig = ImagePipelineConfig.newBuilder(this)
                .setMainDiskCacheConfig(cacheConfig)
                .setDownsampleEnabled(true)
                .setBitmapsConfig(Bitmap.Config.RGB_565)
                .build();
        Fresco.initialize(this, imagePipelineConfig);

        //init width and height
        DisplayMetrics dm = new DisplayMetrics();
        WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
        wm.getDefaultDisplay().getMetrics(dm);
        width = dm.widthPixels;
        height = dm.heightPixels;

        //init retrofit
        RestClient.getInstance().init(this);

        //information
        if (BuildConfig.DEBUG) {
            ActivityManager  am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
            Log.d(TAG, "onCreate: " + am.getMemoryClass());
            Log.d(TAG, "onCreate: " + am.getLargeMemoryClass());
            Log.d(TAG, "onCreate: " + Runtime.getRuntime().maxMemory());
        }
    }

    public static ExpressApplication getApplication() {
        return application;
    }

    public ImagePipelineConfig getImagePipelineConfig() {
        return imagePipelineConfig;
    }
}

@@ -2079,32 +2079,322 @@
        %7D%0A    %7D%0A%0A
+    @Override%0A    public void onLowMemory() %7B%0A        super.onLowMemory();%0A        Fresco.getImagePipeline().clearMemoryCaches();%0A    %7D%0A%0A    @Override%0A    public void onTrimMemory(int level) %7B%0A        super.onTrimMemory(level);%0A        Fresco.getImagePipeline().clearMemoryCaches();%0A    %7D%0A%0A
     public stati

handle low memory