package e.c.d.x;

import android.graphics.Point;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;
import android.view.MotionEvent;
import e.c.d.x.c;
import e.c.d.x.d;
import e.c.d.x.e;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/* JADX INFO: compiled from: SDKTouch.java */
/* JADX INFO: loaded from: classes.dex */
public class f {

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private static f f800d;
    private e a;
    private Map<String, e.c.d.x.a> b = new HashMap();

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private Map<String, e.c.d.x.b> f801c = new HashMap();

    /* JADX INFO: compiled from: SDKTouch.java */
    class a extends d.a {
        final /* synthetic */ e.c.d.x.a a;

        a(e.c.d.x.a aVar) {
            this.a = aVar;
        }

        @Override // e.c.d.x.d
        public void C(String str, int i2, int i3) throws RemoteException {
            g gVar = new g();
            gVar.c(i2);
            gVar.a(i3);
            gVar.b(f.this.c(str));
            this.a.a(gVar);
        }
    }

    /* JADX INFO: compiled from: SDKTouch.java */
    class b extends c.a {
        final /* synthetic */ e.c.d.x.b a;

        b(f fVar, e.c.d.x.b bVar) {
            this.a = bVar;
        }

        @Override // e.c.d.x.c
        public void b(MotionEvent motionEvent) throws RemoteException {
            this.a.b(motionEvent);
        }
    }

    private f() {
    }

    public static f b() {
        if (f800d == null) {
            f800d = new f();
        }
        return f800d;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public List<Point> c(String str) {
        String[] strArrSplit = str.split(",");
        ArrayList arrayList = new ArrayList();
        for (String str2 : strArrSplit) {
            String[] strArrSplit2 = str2.split("-");
            arrayList.add(new Point(Integer.parseInt(strArrSplit2[0]), Integer.parseInt(strArrSplit2[1])));
        }
        return arrayList;
    }

    private boolean d() {
        IBinder iBinderF = e.c.d.r.b.c.g().f("opensdk_socketTouch");
        if (iBinderF == null) {
            return false;
        }
        this.a = e.a.U(iBinderF);
        return true;
    }

    public void e() {
        Log.i("SDKTouch", "reConnect: ");
        Map<String, e.c.d.x.a> map = this.b;
        if (map != null && !map.isEmpty()) {
            for (String str : this.b.keySet()) {
                f(str, this.b.get(str));
            }
        }
        Map<String, e.c.d.x.b> map2 = this.f801c;
        if (map2 == null || map2.isEmpty()) {
            return;
        }
        for (String str2 : this.f801c.keySet()) {
            g(str2, this.f801c.get(str2));
        }
    }

    public boolean f(String str, e.c.d.x.a aVar) {
        Log.d("SDKTouch", "registerCallBack: " + str);
        boolean zD = d();
        e eVar = this.a;
        if (eVar != null) {
            try {
                eVar.h(str, new a(aVar));
                if (this.b != null) {
                    this.b.put(str, aVar);
                }
            } catch (RemoteException e2) {
                Log.e("SDKTouch", "registerCallBack: ", e2);
            }
        }
        return zD && this.a != null;
    }

    public boolean g(String str, e.c.d.x.b bVar) {
        Log.d("SDKTouch", "registerTouchEventCallBack: " + str);
        boolean zD = d();
        e eVar = this.a;
        if (eVar != null) {
            try {
                eVar.E(str, new b(this, bVar));
                if (this.f801c != null) {
                    this.f801c.put(str, bVar);
                }
            } catch (RemoteException e2) {
                Log.e("SDKTouch", "registerCallBack: ", e2);
            }
        }
        return zD && this.a != null;
    }
}
