Android Open Source - GreenerGasPedal Edit Prefs Activity






From Project

Back to project page GreenerGasPedal.

License

The source code is released under:

GNU General Public License

If you think the Android project GreenerGasPedal 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

/**
 * //  www . ja  va  2  s .co  m
 */
package name.nanek.greenerpedal.activity;

import name.nanek.greenerpedal.R;
import name.nanek.greenerpedal.activity.support.APISafeKeyguardHider;
import name.nanek.greenerpedal.activity.support.Prefs;
import name.nanek.greenerpedal.activity.support.ScreenLock;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceActivity;

/**
 * @author Lance Nanek
 *
 */
public class EditPrefsActivity extends PreferenceActivity {

  private Preference manualTiltCorrection;
  
  private ScreenLock lock;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    lock = new ScreenLock(this, "GreenerPedal " + getClass().getSimpleName());
    APISafeKeyguardHider.hideKeyguard(this);
    
    addPreferencesFromResource(R.xml.preferences);
    
    String preferenceKeyManualTiltCorrection = getString(R.string.preferenceKeyManualTiltCorrection);    
    manualTiltCorrection = getPreferenceManager().findPreference(preferenceKeyManualTiltCorrection);

    // Disable manual tilt correction when automatic is checked.
    String preferenceKeyAutomaticTiltCorrection = getString(R.string.preferenceKeyAutomaticTiltCorrection);
    Preference automaticTiltCorrection = getPreferenceManager().findPreference(preferenceKeyAutomaticTiltCorrection);
    automaticTiltCorrection.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
      @Override
      public boolean onPreferenceChange(Preference preference, Object newValue) {

        Boolean automaticTiltCorrectionValue = (Boolean) newValue;
        manualTiltCorrection.setEnabled(!automaticTiltCorrectionValue);  
        
        return true;
      }
    });    

    // Update screen lock when keep screen on setting changed.
    String preferenceKeyKeepScreenOn = getString(R.string.preferenceKeyKeepScreenOn);
    Preference keepScreenOn = getPreferenceManager().findPreference(preferenceKeyKeepScreenOn);
    keepScreenOn.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
      @Override
      public boolean onPreferenceChange(Preference preference, Object newValue) {
        Boolean keepScreenOnValue = (Boolean) newValue;
        lock.update(keepScreenOnValue);
        
        return true;
      }
    });        

    // Constrain sensitivity values.
    String preferenceKeySensitivty = getString(R.string.preferenceKeySensitivity);
    Preference sensitivity = getPreferenceManager().findPreference(preferenceKeySensitivty);
    sensitivity.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
      @Override
      public boolean onPreferenceChange(Preference preference, Object newValue) {
        float newSensitivity = Float.parseFloat((String) newValue);

        if ( newSensitivity < 0 ) {
          Prefs prefs = new Prefs(EditPrefsActivity.this);
          prefs.updateSensitivty(0);
          return false;
        }

        if ( newSensitivity > 1.0 ) {
          Prefs prefs = new Prefs(EditPrefsActivity.this);
          prefs.updateSensitivty(1.0f);
          return false;
        }

        return true;
      }
    });  
  }

  private void setOnClickListener(final int keyId, final OnPreferenceClickListener finishClickListener) {
    String preferenceKeyReturnToApp = getString(keyId);  
    Preference returnToApp = getPreferenceManager().findPreference(preferenceKeyReturnToApp);
    returnToApp.setOnPreferenceClickListener(finishClickListener);
  }

  @Override
  protected void onStart() {
    super.onStart();
    
    //Keep screen on even if we're paused.
    Prefs prefs = new Prefs(EditPrefsActivity.this);
    lock.update(prefs);
  }

  @Override
  protected void onStop() {
    super.onStop();
    lock.release();
  }
  
  @Override
  protected void onResume() {
    super.onResume();

    Prefs prefs = new Prefs(this);
    manualTiltCorrection.setEnabled(!prefs.automaticTiltCorrection);  
  }
  
}




Java Source Code List

name.nanek.greenerpedal.GreenerPedalApp.java
name.nanek.greenerpedal.activity.DisplayReadingsActivity.java
name.nanek.greenerpedal.activity.EditPrefsActivity.java
name.nanek.greenerpedal.activity.GraphAndShareActivity.java
name.nanek.greenerpedal.activity.support.APISafeKeyguardHider.java
name.nanek.greenerpedal.activity.support.BitmapUtil.java
name.nanek.greenerpedal.activity.support.LogLine.java
name.nanek.greenerpedal.activity.support.LowPassFilter.java
name.nanek.greenerpedal.activity.support.MessageOnlyFormatter.java
name.nanek.greenerpedal.activity.support.Prefs.java
name.nanek.greenerpedal.activity.support.ScreenLock.java
name.nanek.greenerpedal.activity.support.Sensors.java
name.nanek.greenerpedal.activity.support.ShareUtil.java
name.nanek.greenerpedal.activity.support.Trigger.java
name.nanek.greenerpedal.activity.support.TriggersResult.java
name.nanek.greenerpedal.activity.support.Views.java
name.nanek.greenerpedal.db.model.Reading.java
name.nanek.greenerpedal.db.model.dao.DataHelper.java
name.nanek.greenerpedal.db.model.dao.ReadingDao.java
name.nanek.greenerpedal.db.model.dao.support.DateUtil.java
name.nanek.greenerpedal.db.model.dao.support.DbUtil.java