package com.iab.omid.library.mmadbridge.d; import android.content.Context; import android.content.res.Resources; import android.graphics.Point; import android.os.Build; import android.view.WindowManager; import com.iab.omid.library.mmadbridge.b.c; import com.iab.omid.library.mmadbridge.walking.a; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; public class b { static float a = Resources.getSystem().getDisplayMetrics().density; private static WindowManager b; private static String[] c = {"x", "y", "width", "height"}; /* access modifiers changed from: private */ public static class a { final float a; final float b; a(float f, float f2) { this.a = f; this.b = f2; } } static float a(int i) { return ((float) i) / a; } public static JSONObject a(int i, int i2, int i3, int i4) { JSONObject jSONObject = new JSONObject(); try { jSONObject.put("x", (double) a(i)); jSONObject.put("y", (double) a(i2)); jSONObject.put("width", (double) a(i3)); jSONObject.put("height", (double) a(i4)); } catch (JSONException e) { c.a("Error with creating viewStateObject", e); } return jSONObject; } public static void a(Context context) { if (context != null) { a = context.getResources().getDisplayMetrics().density; b = (WindowManager) context.getSystemService("window"); } } public static void a(JSONObject jSONObject) { a b2 = b(jSONObject); try { jSONObject.put("width", (double) b2.a); jSONObject.put("height", (double) b2.b); } catch (JSONException e) { e.printStackTrace(); } } public static void a(JSONObject jSONObject, a.C0075a aVar) { c a2 = aVar.a(); JSONArray jSONArray = new JSONArray(); for (String str : aVar.b()) { jSONArray.put(str); } try { jSONObject.put("isFriendlyObstructionFor", jSONArray); jSONObject.put("friendlyObstructionClass", a2.b()); jSONObject.put("friendlyObstructionPurpose", a2.c()); jSONObject.put("friendlyObstructionReason", a2.d()); } catch (JSONException e) { c.a("Error with setting friendly obstruction", e); } } public static void a(JSONObject jSONObject, Boolean bool) { try { jSONObject.put("hasWindowFocus", bool); } catch (JSONException e) { c.a("Error with setting not visible reason", e); } } public static void a(JSONObject jSONObject, String str) { try { jSONObject.put("adSessionId", str); } catch (JSONException e) { c.a("Error with setting ad session id", e); } } public static void a(JSONObject jSONObject, String str, Object obj) { try { jSONObject.put(str, obj); } catch (NullPointerException | JSONException e) { c.a("JSONException during JSONObject.put for name [" + str + "]", e); } } public static void a(JSONObject jSONObject, JSONObject jSONObject2) { try { JSONArray optJSONArray = jSONObject.optJSONArray("childViews"); if (optJSONArray == null) { optJSONArray = new JSONArray(); jSONObject.put("childViews", optJSONArray); } optJSONArray.put(jSONObject2); } catch (JSONException e) { e.printStackTrace(); } } private static boolean a(JSONArray jSONArray, JSONArray jSONArray2) { if (jSONArray == null && jSONArray2 == null) { return true; } return (jSONArray == null || jSONArray2 == null || jSONArray.length() != jSONArray2.length()) ? false : true; } private static a b(JSONObject jSONObject) { float f; float f2 = 0.0f; if (Build.VERSION.SDK_INT < 17) { JSONArray optJSONArray = jSONObject.optJSONArray("childViews"); if (optJSONArray != null) { int length = optJSONArray.length(); float f3 = 0.0f; for (int i = 0; i < length; i++) { JSONObject optJSONObject = optJSONArray.optJSONObject(i); if (optJSONObject != null) { double optDouble = optJSONObject.optDouble("x"); double optDouble2 = optJSONObject.optDouble("y"); double optDouble3 = optJSONObject.optDouble("width"); double optDouble4 = optJSONObject.optDouble("height"); f2 = Math.max(f2, (float) (optDouble + optDouble3)); f3 = Math.max(f3, (float) (optDouble2 + optDouble4)); } } f = f3; return new a(f2, f); } } else if (b != null) { Point point = new Point(0, 0); b.getDefaultDisplay().getRealSize(point); f2 = a(point.x); f = a(point.y); return new a(f2, f); } f = 0.0f; return new a(f2, f); } public static void b(JSONObject jSONObject, String str) { try { jSONObject.put("notVisibleReason", str); } catch (JSONException e) { c.a("Error with setting not visible reason", e); } } public static boolean b(JSONObject jSONObject, JSONObject jSONObject2) { if (jSONObject == null && jSONObject2 == null) { return true; } return jSONObject != null && jSONObject2 != null && c(jSONObject, jSONObject2) && e(jSONObject, jSONObject2) && d(jSONObject, jSONObject2) && f(jSONObject, jSONObject2) && g(jSONObject, jSONObject2); } private static boolean c(JSONObject jSONObject, JSONObject jSONObject2) { String[] strArr = c; for (String str : strArr) { if (jSONObject.optDouble(str) != jSONObject2.optDouble(str)) { return false; } } return true; } private static boolean d(JSONObject jSONObject, JSONObject jSONObject2) { return Boolean.valueOf(jSONObject.optBoolean("hasWindowFocus")).equals(Boolean.valueOf(jSONObject2.optBoolean("hasWindowFocus"))); } private static boolean e(JSONObject jSONObject, JSONObject jSONObject2) { return jSONObject.optString("adSessionId", "").equals(jSONObject2.optString("adSessionId", "")); } private static boolean f(JSONObject jSONObject, JSONObject jSONObject2) { JSONArray optJSONArray = jSONObject.optJSONArray("isFriendlyObstructionFor"); JSONArray optJSONArray2 = jSONObject2.optJSONArray("isFriendlyObstructionFor"); if (optJSONArray == null && optJSONArray2 == null) { return true; } if (!a(optJSONArray, optJSONArray2)) { return false; } for (int i = 0; i < optJSONArray.length(); i++) { if (!optJSONArray.optString(i, "").equals(optJSONArray2.optString(i, ""))) { return false; } } return true; } private static boolean g(JSONObject jSONObject, JSONObject jSONObject2) { JSONArray optJSONArray = jSONObject.optJSONArray("childViews"); JSONArray optJSONArray2 = jSONObject2.optJSONArray("childViews"); if (optJSONArray == null && optJSONArray2 == null) { return true; } if (!a(optJSONArray, optJSONArray2)) { return false; } for (int i = 0; i < optJSONArray.length(); i++) { if (!b(optJSONArray.optJSONObject(i), optJSONArray2.optJSONObject(i))) { return false; } } return true; } }