Android Open Source - Steering-Wheel-Interface Steering Wheel Interface Settings






From Project

Back to project page Steering-Wheel-Interface.

License

The source code is released under:

Copyright 2013 Kristoffer Smith and other contributors http://theksmith.com/ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation...

If you think the Android project Steering-Wheel-Interface 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.theksmith.steeringwheelinterface;
/* w  w w  . ja  v a2s.c  om*/
import com.theksmith.steeringwheelinterface.R;

import android.app.Activity;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;


/**
 * A simple settings screen (the app's only UI).
 * 
 * @author Kristoffer Smith <kristoffer@theksmith.com>
 */
public class SteeringWheelInterfaceSettings extends PreferenceFragment {
  protected Activity mParentActivity;
  
  
  @Override
  public void onAttach(Activity activity){
    super.onAttach(activity);
    mParentActivity = activity;    
  }

  
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    
    addPreferencesFromResource(R.xml.pref_general);

    //actions (prefs acting only as buttons)
    Preference exit = findPreference("action_exit");
    exit.setOnPreferenceClickListener(mExitOnClickListener);      
    
    //for preference types with string values
    bindStringPreferenceSummaryToValue(findPreference("scantool_baud"));
    bindStringPreferenceSummaryToValue(findPreference("scantool_device_number"));
    bindStringPreferenceSummaryToValue(findPreference("scantool_monitor_command"));
    bindStringPreferenceSummaryToValue(findPreference("scantool_protocol"));
  }
  
  
  protected OnPreferenceClickListener mExitOnClickListener = new OnPreferenceClickListener() {    
    @Override
    public boolean onPreferenceClick(Preference preference) {
      mParentActivity.finish();
      return false;
    }
  };
  
  
  protected void bindStringPreferenceSummaryToValue(Preference preference) {
    preference.setOnPreferenceChangeListener(mStringPreferenceChangeListener);

    mStringPreferenceChangeListener.onPreferenceChange(
        preference,
        PreferenceManager.getDefaultSharedPreferences(preference.getContext()).getString(preference.getKey(), ""));
  }

  
  protected OnPreferenceChangeListener mStringPreferenceChangeListener = new Preference.OnPreferenceChangeListener() {
    @Override
    public boolean onPreferenceChange(Preference preference, Object value) {
      String stringValue = value.toString();
      
      if (preference instanceof ListPreference) {
        ListPreference list = (ListPreference)preference;
        stringValue = (String)list.getEntries()[list.findIndexOfValue(stringValue)];
      }
      
      preference.setSummary(stringValue);
      
      return true;
    }
  };
}




Java Source Code List

com.hoho.android.usbserial.BuildInfo.java
com.hoho.android.usbserial.driver.CdcAcmSerialDriver.java
com.hoho.android.usbserial.driver.CommonUsbSerialDriver.java
com.hoho.android.usbserial.driver.Cp2102SerialDriver.java
com.hoho.android.usbserial.driver.FtdiSerialDriver.java
com.hoho.android.usbserial.driver.UsbId.java
com.hoho.android.usbserial.driver.UsbSerialDriver.java
com.hoho.android.usbserial.driver.UsbSerialProber.java
com.hoho.android.usbserial.driver.UsbSerialRuntimeException.java
com.hoho.android.usbserial.util.HexDump.java
com.hoho.android.usbserial.util.SerialInputOutputManager.java
com.theksmith.steeringwheelinterface.ButtonActions.java
com.theksmith.steeringwheelinterface.ElmInterface.java
com.theksmith.steeringwheelinterface.SteeringWheelInterfaceActivity.java
com.theksmith.steeringwheelinterface.SteeringWheelInterfaceService.java
com.theksmith.steeringwheelinterface.SteeringWheelInterfaceSettings.java