Android Open Source - InfoWallpaper Battery Data Collector






From Project

Back to project page InfoWallpaper.

License

The source code is released under:

MIT License

If you think the Android project InfoWallpaper 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.andreashedin.infowallpaper;
/*w w w . jav a  2s .  c  om*/
import android.content.Intent;
import android.os.BatteryManager;

public class BatteryDataCollector extends DataCollector {

  private static final String BATTERY_STATUS = "#bb";
  private static final String BATTERY_TEMPERATURE_C = "#btc";
  private static final String BATTERY_TEMPERATURE_F = "#btf";
  private float mBatteryStatus = 0.0f;
  private int mTemperatureC = 0;
  private int mTemperatureF = 0;
  //private boolean mCharging = false;
  
  BatteryDataCollector(LiveInfoWallpaper parent) {
    super(parent);
  }
  
  static String getSampleText(String str) {
    return str.replace(BATTERY_STATUS, "00").replace(BATTERY_TEMPERATURE_C, "00").replace(BATTERY_TEMPERATURE_F, "00");
  }
  
  @Override
  void update(Object object) {
    Intent intent = (Intent)object;
    
    int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
    int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
    mTemperatureC = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, -1);
    mTemperatureC /= 10;
    mTemperatureF = mTemperatureC * 9 / 5 + 32;
    //int charging = intent.getIntExtra("plugged", -1);
    
    if(level >= 0 && scale >= 0) {
      mBatteryStatus = (level * 100) / scale;
    }
//    if(charging == 0) {
//      mCharging = false;
//    }
//    else {
//      mCharging = true;
//    }
  }

  @Override
  String updateInfoString(String string, boolean numbersAsText) {
    String number = "";
    
    if(numbersAsText == false)
      number = String.valueOf((int)(mBatteryStatus + 0.5f));
    else
      number = getNumberAsText((int)(mBatteryStatus + 0.5f));
    
    String str = string.replace(BATTERY_STATUS, number);
    
    if(numbersAsText == false)
      number = String.valueOf(mTemperatureC);
    else
      number = getNumberAsText(mTemperatureC);
    
    str = str.replace(BATTERY_TEMPERATURE_C, number);
    
    if(numbersAsText == false)
      number = String.valueOf(mTemperatureF);
    else
      number = getNumberAsText(mTemperatureF);
    
    str = str.replace(BATTERY_TEMPERATURE_F, number);
    
    return str;
  }
  
  public static boolean contains(String str) {
    if(str.contains(BATTERY_STATUS))
      return true;
    else if(str.contains(BATTERY_TEMPERATURE_C))
      return true;
    else if(str.contains(BATTERY_TEMPERATURE_F))
      return true;
    
    return false;
  }
}




Java Source Code List

com.andreashedin.general.ColorPickerDialog.java
com.andreashedin.general.CustomizeInfoDialog.java
com.andreashedin.general.EnterStringDialog.java
com.andreashedin.general.PickItemDialog.java
com.andreashedin.general.PositionInfosDialog.java
com.andreashedin.general.SelectConfigurationDialog.java
com.andreashedin.general.TextSizeDialog.java
com.andreashedin.general.WeatherSettingsDialog.java
com.andreashedin.infowallpaper.Background.java
com.andreashedin.infowallpaper.BatteryDataCollector.java
com.andreashedin.infowallpaper.ColorHandler.java
com.andreashedin.infowallpaper.ConfigHandler.java
com.andreashedin.infowallpaper.CurrentSongDataCollector.java
com.andreashedin.infowallpaper.DataCollector.java
com.andreashedin.infowallpaper.DateTimeDataCollector.java
com.andreashedin.infowallpaper.DisplayValuePair.java
com.andreashedin.infowallpaper.InfoData.java
com.andreashedin.infowallpaper.InfoItem.java
com.andreashedin.infowallpaper.LiveInfoSettings.java
com.andreashedin.infowallpaper.LiveInfoWallpaper.java
com.andreashedin.infowallpaper.PhoneStatusDataCollector.java
com.andreashedin.infowallpaper.Phone.java
com.andreashedin.infowallpaper.SaveLoadData.java
com.andreashedin.infowallpaper.Screen.java
com.andreashedin.infowallpaper.WeatherDataCollector.java
com.andreashedin.infowallpaper.WeatherHandler.java