// Path: AutoLayout/autolayout/src/main/java/im/quar/autolayout/ScaleAdapter.java
// public interface ScaleAdapter {
//     float adapt(float scale, int screenWidth, int screenHeight);
// }
// 
// Path: AutoLayout/autolayout/src/main/java/im/quar/autolayout/utils/ScreenUtils.java
// public class ScreenUtils {
//     public static int[] getRealScreenSize(Context context) {
// 
//         int[] size = new int[2];
// 
//         WindowManager w = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
//         Display d = w.getDefaultDisplay();
//         DisplayMetrics metrics = new DisplayMetrics();
//         d.getMetrics(metrics);
// 
//         // since SDK_INT = 1;
//         int widthPixels = metrics.widthPixels;
//         int heightPixels = metrics.heightPixels;
//         // includes window decorations (statusbar bar/menu bar)
//         if (Build.VERSION.SDK_INT >= 14 && Build.VERSION.SDK_INT < 17) {
//             try {
//                 widthPixels = (Integer) Display.class.getMethod("getRawWidth").invoke(d);
//                 heightPixels = (Integer) Display.class.getMethod("getRawHeight").invoke(d);
//             } catch (Exception ignored) {
//             }
//         } else if (Build.VERSION.SDK_INT >= 17) {// includes window decorations (statusbar bar/menu bar)
//             Point realSize = new Point();
//             d.getRealSize(realSize);
//             widthPixels = realSize.x;
//             heightPixels = realSize.y;
//         }
// 
//         size[0] = widthPixels;
//         size[1] = heightPixels;
//         return size;
//     }
// 
// 
//     public static double getDevicePhysicalSize(Context context) {
//         int[] size = getRealScreenSize(context);
//         DisplayMetrics dm = context.getResources().getDisplayMetrics();
//         double x = Math.pow(size[0] / dm.xdpi, 2);
//         double y = Math.pow(size[1] / dm.ydpi, 2);
// 
//         return Math.sqrt(x + y);
//     }
// }


import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import im.quar.autolayout.ScaleAdapter;
import im.quar.autolayout.utils.ScreenUtils;
package im.quar.autolayout.config;



/**
 * Created by DTHeaven on 15/11/18.
 */
public class AutoLayoutConfig {

    private static AutoLayoutConfig sInstance;

    private static final String KEY_DESIGN_WIDTH = "design_width";
    private static final String KEY_DESIGN_HEIGHT = "design_height";

    private int mScreenWidth;
    private int mScreenHeight;

    private int mDesignWidth;
    private int mDesignHeight;

    private float mScale;

    private AutoLayoutConfig() {
    }

    public static void init(Context context) {
        init(context, new DefaultScaleAdapter(context));
    }

    public static void init(Context context, ScaleAdapter scaleAdapter) {
        if (sInstance == null) {
            sInstance = new AutoLayoutConfig();
            sInstance.initInternal(context, scaleAdapter);
        }
    }

    public static AutoLayoutConfig getInstance() {
        if (sInstance == null) {
            throw new IllegalStateException("Must init before using.");
        }
        return sInstance;
    }

    private void initInternal(Context context, ScaleAdapter scaleAdapter) {
        getMetaData(context);
        checkParams();

// Path: AutoLayout/autolayout/src/main/java/im/quar/autolayout/ScaleAdapter.java
// public interface ScaleAdapter {
//     float adapt(float scale, int screenWidth, int screenHeight);
// }
// 
// Path: AutoLayout/autolayout/src/main/java/im/quar/autolayout/utils/ScreenUtils.java
// public class ScreenUtils {
//     public static int[] getRealScreenSize(Context context) {
// 
//         int[] size = new int[2];
// 
//         WindowManager w = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
//         Display d = w.getDefaultDisplay();
//         DisplayMetrics metrics = new DisplayMetrics();
//         d.getMetrics(metrics);
// 
//         // since SDK_INT = 1;
//         int widthPixels = metrics.widthPixels;
//         int heightPixels = metrics.heightPixels;
//         // includes window decorations (statusbar bar/menu bar)
//         if (Build.VERSION.SDK_INT >= 14 && Build.VERSION.SDK_INT < 17) {
//             try {
//                 widthPixels = (Integer) Display.class.getMethod("getRawWidth").invoke(d);
//                 heightPixels = (Integer) Display.class.getMethod("getRawHeight").invoke(d);
//             } catch (Exception ignored) {
//             }
//         } else if (Build.VERSION.SDK_INT >= 17) {// includes window decorations (statusbar bar/menu bar)
//             Point realSize = new Point();
//             d.getRealSize(realSize);
//             widthPixels = realSize.x;
//             heightPixels = realSize.y;
//         }
// 
//         size[0] = widthPixels;
//         size[1] = heightPixels;
//         return size;
//     }
// 
// 
//     public static double getDevicePhysicalSize(Context context) {
//         int[] size = getRealScreenSize(context);
//         DisplayMetrics dm = context.getResources().getDisplayMetrics();
//         double x = Math.pow(size[0] / dm.xdpi, 2);
//         double y = Math.pow(size[1] / dm.ydpi, 2);
// 
//         return Math.sqrt(x + y);
//     }
// }


// Path: AutoLayout/autolayout/src/main/java/im/quar/autolayout/config/AutoLayoutConfig.java
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import im.quar.autolayout.ScaleAdapter;
import im.quar.autolayout.utils.ScreenUtils;

package im.quar.autolayout.config;



/**
 * Created by DTHeaven on 15/11/18.
 */
public class AutoLayoutConfig {

    private static AutoLayoutConfig sInstance;

    private static final String KEY_DESIGN_WIDTH = "design_width";
    private static final String KEY_DESIGN_HEIGHT = "design_height";

    private int mScreenWidth;
    private int mScreenHeight;

    private int mDesignWidth;
    private int mDesignHeight;

    private float mScale;

    private AutoLayoutConfig() {
    }

    public static void init(Context context) {
        init(context, new DefaultScaleAdapter(context));
    }

    public static void init(Context context, ScaleAdapter scaleAdapter) {
        if (sInstance == null) {
            sInstance = new AutoLayoutConfig();
            sInstance.initInternal(context, scaleAdapter);
        }
    }

    public static AutoLayoutConfig getInstance() {
        if (sInstance == null) {
            throw new IllegalStateException("Must init before using.");
        }
        return sInstance;
    }

    private void initInternal(Context context, ScaleAdapter scaleAdapter) {
        getMetaData(context);
        checkParams();

        int[] size = ScreenUtils.getRealScreenSize(context);