翰林优商.apk(点击下载) / d.java


package com.kwad.sdk.core.g;

import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import com.kwad.sdk.components.DevelopMangerComponents;
import com.kwad.sdk.components.c;
import com.kwad.sdk.core.e.b;
import com.umeng.analytics.pro.am;
import java.util.Random;

public final class d {
    private volatile boolean bbU = true;
    private float bcc;
    private b bcd;
    private a bce;

    /* access modifiers changed from: package-private */
    public class a implements SensorEventListener {
        private Random acH;
        private final float[] bcf = {0.0f, 0.0f, 9.8f};
        private boolean bcg = false;
        private final float[] bch = {0.0f, 0.0f, 0.0f};

        public a() {
            if (((DevelopMangerComponents) c.g(DevelopMangerComponents.class)) != null) {
                this.bcg = false;
            }
        }

        private void Oe() {
            if (this.acH == null) {
                this.acH = new Random();
            }
            if (this.acH.nextInt(100) == 1) {
                a(this.bcf);
            }
        }

        private void a(float[] fArr) {
            b(fArr);
            float f = fArr[0];
            float f2 = fArr[1];
            float f3 = fArr[2];
            double sqrt = Math.sqrt((double) ((f * f) + (f2 * f2) + (f3 * f3)));
            if (d.this.bbU && sqrt >= ((double) d.this.bcc) && d.this.bcd != null) {
                d.this.bbU = false;
                d.this.bcd.d(sqrt);
            }
        }

        private void b(float[] fArr) {
            float[] fArr2 = this.bch;
            fArr[0] = (fArr[0] * 0.6f) + (fArr2[0] * 0.39999998f);
            fArr[1] = (fArr[1] * 0.6f) + (fArr2[1] * 0.39999998f);
            fArr[2] = (fArr[2] * 0.6f) + (fArr2[2] * 0.39999998f);
            System.arraycopy(fArr, 0, fArr2, 0, 3);
        }

        public final void onAccuracyChanged(Sensor sensor, int i) {
        }

        public final void onSensorChanged(SensorEvent sensorEvent) {
            a(sensorEvent.values);
            if (this.bcg) {
                Oe();
            }
        }
    }

    public d(float f) {
        if (f <= 0.0f) {
            this.bcc = 5.0f;
        } else {
            this.bcc = f;
        }
    }

    public final void I(float f) {
        this.bcc = f;
    }

    public final synchronized void Oa() {
        this.bbU = true;
    }

    public final void a(b bVar) {
        this.bcd = bVar;
    }

    public final void bB(Context context) {
        if (context == null) {
            b.d("ShakeDetector", "startDetect context is null");
            return;
        }
        SensorManager sensorManager = (SensorManager) context.getSystemService(am.ac);
        Sensor defaultSensor = sensorManager.getDefaultSensor(10);
        if (defaultSensor == null) {
            b bVar = this.bcd;
            if (bVar != null) {
                bVar.cc();
            }
            b.d("ShakeDetector", "startDetect default linear acceleration is null");
            return;
        }
        if (this.bce == null) {
            this.bce = new a();
        }
        sensorManager.registerListener(this.bce, defaultSensor, 2);
    }

    public final synchronized void bC(Context context) {
        if (context != null) {
            if (this.bce != null) {
                ((SensorManager) context.getSystemService(am.ac)).unregisterListener(this.bce);
                this.bce = null;
            }
        }
    }
}