Android Open Source - xiaomi-miband-android Battery






From Project

Back to project page xiaomi-miband-android.

License

The source code is released under:

GNU General Public License

If you think the Android project xiaomi-miband-android 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.motioncoding.miband.model;
/* w ww.j  a  v a  2 s.  c om*/
import java.util.Calendar;

public class Battery {
  public int mBatteryLevel;
  public int mCycles;
  public Calendar mLastCharged;
  public Status mStatus;

  public static Battery fromByte(byte[] b) {
    Battery battery = new Battery();
    battery.mBatteryLevel = b[0];
    battery.mStatus = Status.fromByte(b[9]);
    battery.mLastCharged = Calendar.getInstance();
    
    battery.mLastCharged.set(Calendar.YEAR, b[1]+2000);
    battery.mLastCharged.set(Calendar.MONTH, b[2]);
    battery.mLastCharged.set(Calendar.DATE, b[3]);
    
    battery.mLastCharged.set(Calendar.HOUR_OF_DAY, b[4]);
    battery.mLastCharged.set(Calendar.MINUTE, b[5]);
    battery.mLastCharged.set(Calendar.SECOND, b[6]);
    
    battery.mCycles = 0xffff & (0xff & b[7] | (0xff & b[8]) << 8);
    return battery;
  }
  
  @Override
  public String toString() {
    return String.format("Level: %s Cycles: %s State: %s Last Charged: %s", mBatteryLevel, mCycles, mStatus.toString(), mLastCharged.toString());
  }

  static enum Status {
    LOW, FULL, CHARGING, NOT_CHARGING;

    public static Status fromByte(byte b) {
      switch (b) {
      case 1:
        return LOW;
      case 2:
        return CHARGING;
      case 3:
        return FULL;
      case 4:
        return NOT_CHARGING;

      default:
        return null;
      }
    }
  }
}




Java Source Code List

com.motioncoding.debugging.L.java
com.motioncoding.miband.MiActivity.java
com.motioncoding.miband.MiLeParamsActivity.java
com.motioncoding.miband.MiOverviewActivity.java
com.motioncoding.miband.model.Battery.java
com.motioncoding.miband.model.LeParams.java
com.motioncoding.miband.model.MiBand.java
com.motioncoding.miband.view.ColorPickerDialog.java