Android Open Source - activity-tracker Settings Helper






From Project

Back to project page activity-tracker.

License

The source code is released under:

MIT License

If you think the Android project activity-tracker listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.hopto.mjancola.utility;
/*from www .  jav  a2s . c o  m*/
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

public class SettingsHelper
{
    private static final String NONE = "NONE";
    private long   stopThresholdMS;
    private long   activityChangeThresholdMS;
    private double minSpeed;
    private long minDurationMS;
    private int activityChangePercent;

    public long getStopThresholdMS()
    {
        return stopThresholdMS;
    }

    public long getActivityChangeThresholdMS()
    {
        return activityChangeThresholdMS;
    }

    public double getMinSpeedMetersPerSecond()
    {
        return minSpeed;
    }

    public long getMinDurationMS()
    {
        return minDurationMS;
    }

    public int getActivityChangePercent()
    {
        return activityChangePercent;
    }

    public static final String STOP_THRESHOLD_MS            = "prefStopThresholdMin";
    public static final String ACTIVITY_CHANGE_THRESHOLD_MS = "prefActivityChangeThresholdSec";
    public static final String MIN_SPEED_METERS_PER_SECOND  = "prefMinSpeedMetersPerSecond";
    public static final String MIN_DURATION_MS              = "prefMinDurationMin";
    public static final String ACTIVITY_CHANGE_PERCENT      = "prefActivityChangePercent";

    private static final String DEFAULT_STOP_THRESHOLD_MS            = "180000";  // 3 minutes
    private static final String DEFAULT_ACTIVITY_CHANGE_THRESHOLD_MS = "20000";  // 20 seconds
    private static final String DEFAULT_MIN_SPEED_METERS_PER_SECOND  = ".89407776";
    private static final String DEFAULT_MIN_DURATION_MS              = "60000"; // 1 minutes
    private static final String DEFAULT_ACTIVITY_CHANGE_PERCENT      = "90";

    private static SettingsHelper instance;
    private static Context        context;

    // hide constructor
    private SettingsHelper()
    {
    }

    public void update()
    {
        // get values from shared preferences
        SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences( context );

        String temp = getAndPersist( sharedPrefs, STOP_THRESHOLD_MS, DEFAULT_STOP_THRESHOLD_MS );
        stopThresholdMS = (Long.valueOf( temp ));  // 3 minutes

        temp = getAndPersist( sharedPrefs, ACTIVITY_CHANGE_THRESHOLD_MS, DEFAULT_ACTIVITY_CHANGE_THRESHOLD_MS );
        activityChangeThresholdMS = Long.valueOf(temp);

        temp = getAndPersist( sharedPrefs, MIN_SPEED_METERS_PER_SECOND, DEFAULT_MIN_SPEED_METERS_PER_SECOND );
        minSpeed = Double.valueOf(temp);

        temp = getAndPersist( sharedPrefs, MIN_DURATION_MS, DEFAULT_MIN_DURATION_MS );
        minDurationMS = (Long.valueOf(temp));

        temp = getAndPersist( sharedPrefs, ACTIVITY_CHANGE_PERCENT, DEFAULT_ACTIVITY_CHANGE_PERCENT );
        activityChangePercent = Integer.valueOf(temp);

    }

    private String getAndPersist( SharedPreferences sharedPrefs, String key, String def )
    {
        String temp = sharedPrefs.getString( key, NONE);
        if (temp.equals(NONE))
        {
            // use and persist our defaults
            temp = def;
            SharedPreferences.Editor editor = sharedPrefs.edit();
            editor.putString( key, temp );
            editor.commit();
        }
        return temp;
    }

    public static SettingsHelper getInstance(Context contextHandle)
    {
        if ( instance == null )
        {
            context = contextHandle;
            instance = new SettingsHelper();
        }
        instance.update();

        return instance;
    }
}




Java Source Code List

org.hopto.mjancola.ActivityTrackerApplication.java
org.hopto.mjancola.activity.ActivityRecognitionActivity.java
org.hopto.mjancola.activity.ActivityTracker.java
org.hopto.mjancola.activity.DemoDetailsList.java
org.hopto.mjancola.activity.DemoDetails.java
org.hopto.mjancola.activity.EditWorkoutDAOActivity.java
org.hopto.mjancola.activity.FeatureView.java
org.hopto.mjancola.activity.LegalInfoActivity.java
org.hopto.mjancola.activity.ListWorkoutsActivity.java
org.hopto.mjancola.activity.MyLocationDemoActivity.java
org.hopto.mjancola.activity.SpeedActivity.java
org.hopto.mjancola.activity.UserSettingsActivity.java
org.hopto.mjancola.adapter.WorkoutDAOAdapter.java
org.hopto.mjancola.fragment.EditWorkoutDAOFragment.java
org.hopto.mjancola.model.DataPoint.java
org.hopto.mjancola.model.GenericMovement.java
org.hopto.mjancola.model.GenericWorkout.java
org.hopto.mjancola.model.LearningMode.java
org.hopto.mjancola.model.MyMovement.java
org.hopto.mjancola.model.WorkoutTotal.java
org.hopto.mjancola.model.WorkoutType.java
org.hopto.mjancola.model.Workout.java
org.hopto.mjancola.service.ActivityRecognitionService.java
org.hopto.mjancola.service.MovementListenerService.java
org.hopto.mjancola.service.MovementTrackerService.java
org.hopto.mjancola.utility.Converter.java
org.hopto.mjancola.utility.MySQLiteHelper.java
org.hopto.mjancola.utility.SettingsHelper.java
org.hopto.mjancola.utility.WorkoutDAO.java
org.hopto.mjancola.utility.WorkoutDataSource.java