Search in sources :

Example 16 with Sensor

use of android.hardware.Sensor in project PanoramaImageView by gjiazhe.

the class GyroscopeObserver method register.

public void register(Context context) {
    if (mSensorManager == null) {
        mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
    }
    Sensor mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
    mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_FASTEST);
    mLastTimestamp = 0;
    mRotateRadianY = mRotateRadianX = 0;
}
Also used : Sensor(android.hardware.Sensor)

Example 17 with Sensor

use of android.hardware.Sensor in project android_frameworks_base by DirtyUnicorns.

the class SensorPowerCalculator method calculateApp.

@Override
public void calculateApp(BatterySipper app, BatteryStats.Uid u, long rawRealtimeUs, long rawUptimeUs, int statsType) {
    // Process Sensor usage
    final SparseArray<? extends BatteryStats.Uid.Sensor> sensorStats = u.getSensorStats();
    final int NSE = sensorStats.size();
    for (int ise = 0; ise < NSE; ise++) {
        final BatteryStats.Uid.Sensor sensor = sensorStats.valueAt(ise);
        final int sensorHandle = sensorStats.keyAt(ise);
        final BatteryStats.Timer timer = sensor.getSensorTime();
        final long sensorTime = timer.getTotalTimeLocked(rawRealtimeUs, statsType) / 1000;
        switch(sensorHandle) {
            case BatteryStats.Uid.Sensor.GPS:
                app.gpsTimeMs = sensorTime;
                app.gpsPowerMah = (app.gpsTimeMs * mGpsPowerOn) / (1000 * 60 * 60);
                break;
            default:
                final int sensorsCount = mSensors.size();
                for (int i = 0; i < sensorsCount; i++) {
                    final Sensor s = mSensors.get(i);
                    if (s.getHandle() == sensorHandle) {
                        app.sensorPowerMah += (sensorTime * s.getPower()) / (1000 * 60 * 60);
                        break;
                    }
                }
                break;
        }
    }
}
Also used : BatteryStats(android.os.BatteryStats) Sensor(android.hardware.Sensor)

Example 18 with Sensor

use of android.hardware.Sensor in project weex-example by KalicyZhou.

the class ShakeDetector method start.

/**
   * Start listening for shakes.
   */
public void start(SensorManager manager) {
    Assertions.assertNotNull(manager);
    Sensor accelerometer = manager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    if (accelerometer != null) {
        mSensorManager = manager;
        mLastTimestamp = -1;
        mCurrentIndex = 0;
        mMagnitudes = new double[MAX_SAMPLES];
        mTimestamps = new long[MAX_SAMPLES];
        mSensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_UI);
    }
}
Also used : Sensor(android.hardware.Sensor)

Example 19 with Sensor

use of android.hardware.Sensor in project android_frameworks_base by AOSPA.

the class SensorPowerCalculator method calculateApp.

@Override
public void calculateApp(BatterySipper app, BatteryStats.Uid u, long rawRealtimeUs, long rawUptimeUs, int statsType) {
    // Process Sensor usage
    final SparseArray<? extends BatteryStats.Uid.Sensor> sensorStats = u.getSensorStats();
    final int NSE = sensorStats.size();
    for (int ise = 0; ise < NSE; ise++) {
        final BatteryStats.Uid.Sensor sensor = sensorStats.valueAt(ise);
        final int sensorHandle = sensorStats.keyAt(ise);
        final BatteryStats.Timer timer = sensor.getSensorTime();
        final long sensorTime = timer.getTotalTimeLocked(rawRealtimeUs, statsType) / 1000;
        switch(sensorHandle) {
            case BatteryStats.Uid.Sensor.GPS:
                app.gpsTimeMs = sensorTime;
                app.gpsPowerMah = (app.gpsTimeMs * mGpsPowerOn) / (1000 * 60 * 60);
                break;
            default:
                final int sensorsCount = mSensors.size();
                for (int i = 0; i < sensorsCount; i++) {
                    final Sensor s = mSensors.get(i);
                    if (s.getHandle() == sensorHandle) {
                        app.sensorPowerMah += (sensorTime * s.getPower()) / (1000 * 60 * 60);
                        break;
                    }
                }
                break;
        }
    }
}
Also used : BatteryStats(android.os.BatteryStats) Sensor(android.hardware.Sensor)

Example 20 with Sensor

use of android.hardware.Sensor in project android_frameworks_base by ResurrectionRemix.

the class SensorPowerCalculator method calculateApp.

@Override
public void calculateApp(BatterySipper app, BatteryStats.Uid u, long rawRealtimeUs, long rawUptimeUs, int statsType) {
    // Process Sensor usage
    final SparseArray<? extends BatteryStats.Uid.Sensor> sensorStats = u.getSensorStats();
    final int NSE = sensorStats.size();
    for (int ise = 0; ise < NSE; ise++) {
        final BatteryStats.Uid.Sensor sensor = sensorStats.valueAt(ise);
        final int sensorHandle = sensorStats.keyAt(ise);
        final BatteryStats.Timer timer = sensor.getSensorTime();
        final long sensorTime = timer.getTotalTimeLocked(rawRealtimeUs, statsType) / 1000;
        switch(sensorHandle) {
            case BatteryStats.Uid.Sensor.GPS:
                app.gpsTimeMs = sensorTime;
                app.gpsPowerMah = (app.gpsTimeMs * mGpsPowerOn) / (1000 * 60 * 60);
                break;
            default:
                final int sensorsCount = mSensors.size();
                for (int i = 0; i < sensorsCount; i++) {
                    final Sensor s = mSensors.get(i);
                    if (s.getHandle() == sensorHandle) {
                        app.sensorPowerMah += (sensorTime * s.getPower()) / (1000 * 60 * 60);
                        break;
                    }
                }
                break;
        }
    }
}
Also used : BatteryStats(android.os.BatteryStats) Sensor(android.hardware.Sensor)

Aggregations

Sensor (android.hardware.Sensor)34 SensorEventListener (android.hardware.SensorEventListener)5 SensorManager (android.hardware.SensorManager)5 BatteryStats (android.os.BatteryStats)5 SensorEvent (android.hardware.SensorEvent)4 Handler (android.os.Handler)2 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 Resources (android.content.res.Resources)1 ViewPager (android.support.v4.view.ViewPager)1 View (android.view.View)1 ViewTreeObserver (android.view.ViewTreeObserver)1 Window (android.view.Window)1 AdapterView (android.widget.AdapterView)1 TextView (android.widget.TextView)1 InjectView (butterknife.InjectView)1 BmobUser (cn.bmob.v3.BmobUser)1 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)1 MaterialMenuView (com.balysv.materialmenu.MaterialMenuView)1 SuperActivityToast (com.github.johnpersano.supertoasts.SuperActivityToast)1