/* Copyright (c) 2014 Andrea Zoli. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file. */

package it.inaf.android;

import android.app.Application;
import android.content.Context;

import com.android.volley.RequestQueue;
import com.android.volley.VolleyLog;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.Volley;

public class INAF extends Application {

    public static RequestQueue requestQueue;
    public static ImageLoader imageLoader;

    private static Context mContext;
    private static BitmapLruCache mBitmapCache;

    @Override
    public void onCreate() {
        super.onCreate();

        mContext = this;

        requestQueue = Volley.newRequestQueue(mContext, null);
        imageLoader = new ImageLoader(requestQueue, getBitmapCache());
        VolleyLog.setTag("MyAppTag");
        // http://stackoverflow.com/a/17035814
        imageLoader.setBatchedResponseDelay(0);
    }

    public static BitmapLruCache getBitmapCache() {
        if (mBitmapCache == null) {
            // The cache size will be measured in kilobytes rather than
            // number of items. See http://developer.android.com/training/displaying-bitmaps/cache-bitmap.html
            int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
            int cacheSize = maxMemory / 8;  //Use 1/8th of the available memory for this memory cache.
            mBitmapCache = new BitmapLruCache(cacheSize);
        }
        return mBitmapCache;
    }
}

@@ -246,16 +246,190 @@
 Context;
+%0Aimport android.graphics.Point;%0Aimport android.os.Build;%0Aimport android.util.Log;%0Aimport android.view.Display;%0Aimport android.view.Surface;%0Aimport android.view.WindowManager;
 %0A%0Aimport
@@ -805,16 +805,113 @@
 Cache;%0A%0A
+    public static int width;%0A    public static int height;%0A    public static float aspectRatio;%0A%0A
     @Ove
@@ -1217,16 +1217,16 @@
 7035814%0A
-
         
@@ -1264,16 +1264,928 @@
 elay(0);
+%0A%0A        WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);%0A        Display display = wm.getDefaultDisplay();%0A        Point size = new Point();%0A        if(Build.VERSION.SDK_INT %3E= Build.VERSION_CODES.HONEYCOMB_MR2) %7B%0A            display.getSize(size);%0A            width = size.x;%0A            height = size.y;%0A        %7D%0A        else %7B%0A            width = display.getWidth();  // deprecated%0A            height = display.getHeight();  // deprecated%0A        %7D%0A        int r = display.getRotation();%0A        if(r == Surface.ROTATION_90 %7C%7C r == Surface.ROTATION_270) %7B%0A            int tmp = width;%0A            width = height;%0A            height = tmp;%0A        %7D%0A%0A        if(width %3E height)%0A            aspectRatio = width / (float)height;%0A        else%0A            aspectRatio = height / (float)width;%0A%0A        Log.i(%22Info%22, %22Width: %22 + width + %22 Height: %22 + height + %22Aspect Ratio: %22 + aspectRatio);
 %0A    %7D%0A%0A

Add width, height and aspect ratio calculation.