package com.epson.mobilephone.common.guide;

import android.app.Activity;
import android.content.Context;
import android.graphics.Point;
import android.util.TypedValue;
import android.view.Display;

public class Utils {
    public static int LAYOUT_MEARGIN = 32;
    public static int WEBVIEW_300DP_SIZE = 300;
    public static int WEBVIEW_500DP_SIZE = 500;

    public static int getWebViewDP(Activity activity, Context context) {
        float pxtodp = pxtodp(getDisplaySize(activity).x, context);
        float pxtodp2 = pxtodp(getDisplaySize(activity).y, context);
        if (pxtodp2 == 0.0f || pxtodp == 0.0f) {
            return WEBVIEW_300DP_SIZE;
        }
        if (pxtodp2 < pxtodp) {
            int i = (int) ((pxtodp2) * 0.7d);
            int i2 = WEBVIEW_500DP_SIZE;
            return i < LAYOUT_MEARGIN + i2 ? i : i2;
        }
        int i3 = (int) ((pxtodp) * 0.7d);
        int i4 = WEBVIEW_500DP_SIZE;
        return i3 < LAYOUT_MEARGIN + i4 ? i3 : i4;
    }

    public static Point getDisplaySize(Activity activity) {
        Display defaultDisplay = activity.getWindowManager().getDefaultDisplay();
        Point point = new Point();
        defaultDisplay.getSize(point);
        return point;
    }

    public static float pxtodp(int i, Context context) {
        return ((float) i) / context.getResources().getDisplayMetrics().density;
    }

    public static float dptopx(int i, Context context) {
        return TypedValue.applyDimension(1, (float) i, context.getResources().getDisplayMetrics());
    }
}
