Android Open Source - android-uds Preferences Activity






From Project

Back to project page android-uds.

License

The source code is released under:

MIT License

If you think the Android project android-uds 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.imazlwifu.uds;
/*from  w w w. j a v a 2  s  .  c  o m*/
import org.imazlwifu.uds.model.Monitorable;

import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceActivity;
import android.preference.PreferenceGroup;

/**
 * 
 * 
 * @author Sascha Eiteneuer
 *
 */
public class PreferencesActivity extends PreferenceActivity {
  private PreferenceGroup prefGroup;
  
  @SuppressWarnings( "deprecation" )
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    
    addPreferencesFromResource( R.xml.preferences );
    
    /*
     * saving remote address in LibConfig and giving feedback
     */
    findPreference( "remote_address" ).setOnPreferenceChangeListener( new OnPreferenceChangeListener() {
      @Override
      public boolean onPreferenceChange(Preference preference, Object newValue) {
        if( LibConfig.instance.setRemoteAddress( (String) newValue ) )        
          return true;
        else {
          Util.longToast( getApplicationContext(), "invalid address" );
          
          return false;
        }
      }
    } );
    
    /*
     * adding monitorables to preferences
     */
    prefGroup = (PreferenceGroup) findPreference( "monitored" );
    
    if( LibConfig.instance.getMonitorables().size() > 0 ) {
      CheckBoxPreference pref;
      
      for( Monitorable m : LibConfig.instance.getMonitorables() ) {
        pref = createCheckBox( m );
        prefGroup.addPreference( pref );
      }
      
      getPreferenceScreen().addPreference( prefGroup );
    }
  }
  
  private CheckBoxPreference createCheckBox( final Monitorable m ) {
    CheckBoxPreference pref = new CheckBoxPreference( this );
    
    pref.setTitle( Util.clipObjectID( m.getName() ) );
    pref.setChecked( LibConfig.instance.getPreference( m ) );
    pref.setOrder( Preference.DEFAULT_ORDER );
    
    pref.setOnPreferenceClickListener( new OnPreferenceClickListener() {
      @Override
      public boolean onPreferenceClick(Preference preference) {
        boolean currentValue = LibConfig.instance.getPreference( m );
        
        LibConfig.instance.putDefaultMonitorable( m, !currentValue );
        
        return true;
      }
    } );
    
    return pref;
  }
  
  
}




Java Source Code List

org.imazlwifu.uds.DataService.java
org.imazlwifu.uds.LibConfig.java
org.imazlwifu.uds.PreferencesActivity.java
org.imazlwifu.uds.UDS.java
org.imazlwifu.uds.UIActivity.java
org.imazlwifu.uds.Util.java
org.imazlwifu.uds.ipc.AlarmReceiver.java
org.imazlwifu.uds.ipc.PublishingDataReceiver.java
org.imazlwifu.uds.ipc.ServiceStarter.java
org.imazlwifu.uds.ipc.ServiceTerminator.java
org.imazlwifu.uds.model.Battery.java
org.imazlwifu.uds.model.Monitorable.java
org.imazlwifu.uds.model.MonitoredSensor.java
org.imazlwifu.uds.rpc.DataPublisher.java
org.imazlwifu.uds.rpc.HTTPRemoteConnection.java
org.imazlwifu.uds.rpc.RemoteConnection.java