Android Open Source - shiftknob-android Settings Activity






From Project

Back to project page shiftknob-android.

License

The source code is released under:

Copyright (c) 2013 Ford Motor Company All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are me...

If you think the Android project shiftknob-android 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 com.openxc.shiftindicator;
/*  ww  w . ja v  a 2  s .  c  om*/
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.util.Log;

public class SettingsActivity extends PreferenceActivity implements 
            SharedPreferences.OnSharedPreferenceChangeListener{

    public static final String KEY_PREF_OPERATION_MODE = "pref_operation_mode";
    public static final String KEY_PREF_SHIFT_POINT = "pref_shift_point";
    public static final String KEY_PREF_CALCULATION = "pref_calculation_mode";
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.settings);
        updatePreferenceScreen();
    }

    @Override
    public void onSharedPreferenceChanged(SharedPreferences sharedPref, String key) {
        // TODO Auto-generated method stub
        if (key.equals(KEY_PREF_OPERATION_MODE)) {
            Preference shiftPointPref = findPreference(KEY_PREF_SHIFT_POINT);
            Preference algorithmPref = findPreference(KEY_PREF_CALCULATION);
            if (sharedPref.getBoolean(key, false)) {
                shiftPointPref.setEnabled(true);
                algorithmPref.setEnabled(false);
            } else {
                shiftPointPref.setEnabled(false);
                algorithmPref.setEnabled(true);
            }
           
        } else if (key.equals(KEY_PREF_SHIFT_POINT)) {
            Preference shiftPointPref = findPreference(KEY_PREF_SHIFT_POINT);
            shiftPointPref.setSummary(sharedPref.getString(KEY_PREF_SHIFT_POINT, "")+" RPM");
            int shiftPoint = Integer.parseInt(sharedPref.getString(KEY_PREF_SHIFT_POINT, ""));
            MainActivity.setShiftPoint(shiftPoint);
        }
    }
    
    public void updatePreferenceScreen() {
        SharedPreferences operationPref = findPreference(KEY_PREF_OPERATION_MODE).getSharedPreferences();
        Preference shiftPointPref = findPreference(KEY_PREF_SHIFT_POINT);
        Preference algorithmPref = findPreference(KEY_PREF_CALCULATION);
        if (operationPref.getBoolean(KEY_PREF_OPERATION_MODE, false)) {
            shiftPointPref.setEnabled(true);
            algorithmPref.setEnabled(false);
        } else {
            shiftPointPref.setEnabled(false);
            algorithmPref.setEnabled(true);
        }
        shiftPointPref.setSummary(operationPref.getString(KEY_PREF_SHIFT_POINT, "")+" RPM");
    }
    
    @Override
    protected void onResume() {
        super.onResume();
        getPreferenceScreen().getSharedPreferences()
                .registerOnSharedPreferenceChangeListener(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        getPreferenceScreen().getSharedPreferences()
                .unregisterOnSharedPreferenceChangeListener(this);
    }
}




Java Source Code List

com.openxc.shiftindicator.ArduinoHardware.java
com.openxc.shiftindicator.JsonBuilder.java
com.openxc.shiftindicator.MainActivity.java
com.openxc.shiftindicator.SettingsActivity.java
com.openxc.shiftindicator.ShiftRecommendation.java