Android Open Source - android-uds Battery






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.model;
/*  w w  w. j ava  2 s.com*/
import java.util.HashMap;
import java.util.Map;

import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;

public class Battery implements Monitorable {
  public final static String NAME = "Battery";
  private Map<String, Float> values;
  
  private Context context;
  
  public Battery( Context context ) {
    this.context = context;
    values = new HashMap<String, Float>();
  }

  @Override
  public void updateData() {
    Intent battery = context.registerReceiver( null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED) );
    Bundle extras = battery.getExtras();
    
    for( String s : extras.keySet() )
      if( !s.contains( "icon" ) )
        try {
          float f = (Integer) extras.get( s );
          
          values.put( "Battery "+s, f );
        } catch( Exception e ) {}
    
  }
  
  @Override
  public String getName() {
    return NAME;
  }

  @Override
  public Map<String, Float> values() {
    return values;
  }

  @Override
  public boolean registerListener() {
    // nothing to register
    return false;
  }

  @Override
  public void unregisterListener() {}

}




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