Search in sources :

Example 11 with MyLog

use of uk.co.yahoo.p1rpp.calendartrigger.MyLog in project CalendarTrigger by rparkins999.

the class MuteService method StartStepCounter.

// FIXME can we use a similar power saving trick as accelerometer?
// return true if step counter is now running
private boolean StartStepCounter(int classNum) {
    if (PrefsManager.getStepCount(this) == PrefsManager.STEP_COUNTER_IDLE) {
        SensorManager sensorManager = (SensorManager) getSystemService(Activity.SENSOR_SERVICE);
        Sensor sensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER, true);
        if (sensor == null) {
            // if we can't get a wakeup step counter, try without
            sensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
            if (sensor == null) {
                // no step counter at all
                return false;
            }
        }
        if (sensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL)) {
            new MyLog(this, "Step counter activated for class ".concat(PrefsManager.getClassName(this, classNum)));
            if (sensor.isWakeUpSensor()) {
                PrefsManager.setStepCount(this, PrefsManager.STEP_COUNTER_WAKEUP);
            } else {
                PrefsManager.setStepCount(this, PrefsManager.STEP_COUNTER_WAKE_LOCK);
                lock();
            }
            return true;
        } else {
            // could not activate step counter
            return false;
        }
    } else {
        // already starting it for another class
        return true;
    }
}
Also used : SensorManager(android.hardware.SensorManager) MyLog(uk.co.yahoo.p1rpp.calendartrigger.MyLog) Sensor(android.hardware.Sensor)

Aggregations

MyLog (uk.co.yahoo.p1rpp.calendartrigger.MyLog)11 NotificationManager (android.app.NotificationManager)3 SensorManager (android.hardware.SensorManager)3 TargetApi (android.annotation.TargetApi)2 Notification (android.app.Notification)2 PendingIntent (android.app.PendingIntent)2 Intent (android.content.Intent)2 Cursor (android.database.Cursor)2 Sensor (android.hardware.Sensor)2 AlarmManager (android.app.AlarmManager)1 ContentProviderOperation (android.content.ContentProviderOperation)1 PackageManager (android.content.pm.PackageManager)1 Criteria (android.location.Criteria)1 Location (android.location.Location)1 LocationManager (android.location.LocationManager)1 AudioManager (android.media.AudioManager)1 PowerManager (android.os.PowerManager)1 DateFormat (java.text.DateFormat)1 ArrayList (java.util.ArrayList)1 CalendarProvider (uk.co.yahoo.p1rpp.calendartrigger.calendar.CalendarProvider)1