Back to project page android_device.
The source code is released under:
[Apache License](http://www.apache.org/licenses/): Version 2.0, January 2004 =============== ## TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION ## ### 1. Definitions. ### "License" sha...
If you think the Android project android_device listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/* * ================================================================================================= * Copyright (C) 2013 - 2014 Martin Albedinsky [Wolf-ITechnologies] * ================================================================================================= * Licensed under the Apache License, Version 2.0 or later (further "License" only). * ------------------------------------------------------------------------------------------------- * You may use this file only in compliance with the License. More details and copy of this License * you may obtain at/*w ww . jav a 2s . c o m*/ * * http://www.apache.org/licenses/LICENSE-2.0 * * You can redistribute, modify or publish any part of the code written within this file but as it * is described in the License, the software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES or CONDITIONS OF ANY KIND. * * See the License for the specific language governing permissions and limitations under the License. * ================================================================================================= */ package com.wit.android.device; import android.content.BroadcastReceiver; import android.content.Context; import android.content.IntentFilter; import android.os.BatteryManager; import android.support.annotation.NonNull; import com.wit.android.device.receiver.BatteryHealthReceiver; import com.wit.android.device.receiver.BatteryPluggedStateReceiver; import com.wit.android.device.receiver.BatteryStatusReceiver; import com.wit.android.device.receiver.BroadcastProcessor; /** * <h3>Interface Overview</h3> * todo: description * <h3>Listening for battery changes:</h3> * <pre> * public class HomeActivity extends Activity { * * // Battery status listener. * private final Battery.OnStatusListener STATUS_LISTENER = new Battery.OnStatusListener() { * * @Override * public void onStatusChange(Battery battery, Context context) { * // Handle here permanent battery status changes. * } * } * * // Battery health status listener. * private final Battery.OnHealthListener HEALTH_LISTENER = new Battery.OnHealthListener() { * * @Override * public void onHealthChange(Battery battery, boolean isLow, Context context) { * if (isLow) { * // Handle here battery health LOW status. * } else { * // Handle here battery health OK status. * } * } * } * * // Battery plugged state listener. * private final Battery.OnPluggedStateListener PLUGGED_STATE_LISTENER = new Battery.OnPluggedStateListener() { * * @Override * public void onPluggedStateChange(Battery battery, boolean plugged, Context context) { * // Handle here battery charging (connected/disconnected) status. * } * } * * // Device battery wrapper. * private Battery mBattery; * * @Override * protected void onCreate(Bundle savedInstanceState) { * super.onCreate(savedInstanceState); * * // ... initializations * * // Get the battery wrapper implementation. * this.mBattery = AndroidDevice.getInstance(this).getBattery(); * // Register battery listeners to handle battery status changes. * mBattery.registerOnBatteryListener(STATUS_LISTENER); * mBattery.registerOnBatteryListener(HEALTH_LISTENER); * mBattery.registerOnBatteryListener(PLUGGED_STATE_LISTENER); * * // Register only needed receivers. * mBattery.registerBatteryReceiver(this, Battery.RECEIVER_BATTERY_STATUS); * mBattery.registerBatteryReceiver(this, Battery.RECEIVER_BATTERY_HEALTH); * mBattery.registerBatteryReceiver(this, Battery.RECEIVER_BATTERY_PLUGGED_STATE); * // ... or * mBattery.registerAllBatteryReceivers(this); * * // ... other interesting stuffs * } * * @Override * protected void onDestroy() { * super.onDestroy(); * * // Un-register on battery listeners. * mBattery.unregisterOnBatteryListener(STATUS_LISTENER); * mBattery.unregisterOnBatteryListener(HEALTH_LISTENER); * mBattery.unregisterOnBatteryListener(PLUGGED_STATE_LISTENER); * * // Un-register all registered receivers. * mBattery.unregisterBatteryReceiver(this, Battery.RECEIVER_BATTERY_STATUS); * mBattery.unregisterBatteryReceiver(this, Battery.RECEIVER_BATTERY_HEALTH); * mBattery.unregisterBatteryReceiver(this, Battery.RECEIVER_BATTERY_PLUGGED_STATE); * // ... or * mBattery.unregisterAllBatteryReceivers(this); * } * } * </pre> * * @author Martin Albedinsky */ public interface Battery extends BroadcastProcessor { /** * Constants =================================================================================== */ /** * The id of {@link com.wit.android.device.receiver.BatteryStatusReceiver} copied from * {@link com.wit.android.device.receiver.BatteryStatusReceiver#RECEIVER_ID}. */ public static final int RECEIVER_BATTERY_STATUS = BatteryStatusReceiver.RECEIVER_ID; /** * The id of {@link com.wit.android.device.receiver.BatteryHealthReceiver} copied from * {@link com.wit.android.device.receiver.BatteryHealthReceiver#RECEIVER_ID}. */ public static final int RECEIVER_BATTERY_HEALTH = BatteryHealthReceiver.RECEIVER_ID; /** * The id of {@link com.wit.android.device.receiver.BatteryPluggedStateReceiver} copied from * {@link com.wit.android.device.receiver.BatteryPluggedStateReceiver#RECEIVER_ID}. */ public static final int RECEIVER_BATTERY_PLUGGED_STATE = BatteryPluggedStateReceiver.RECEIVER_ID; /** * Default value of the battery health indicating <b>LOW</b> level. * <p> * Constant value: <b>15</b> */ public static final int HEALTH_LOW_LEVEL = 15; /** * Default value of the battery health indicating <b>OK</b> level. * <p> * Constant value: <b>20</b> */ public static final int HEALTH_OK_LEVEL = 20; /** * Enums ======================================================================================= */ /** * <h3>Enum Overview</h3> * Represents status of an Android device's battery. * * @author Martin Albedinsky * @see #resolve(int) */ public enum BatteryStatus { /** * Status indicating that the current Android device's battery is in unknown state. * <p> * From {@link android.os.BatteryManager#BATTERY_STATUS_UNKNOWN} */ UNKNOWN(BatteryManager.BATTERY_STATUS_UNKNOWN), /** * Status indicating that the current Android device's battery is currently being charging. * <p> * From {@link BatteryManager#BATTERY_STATUS_CHARGING} */ CHARGING(BatteryManager.BATTERY_STATUS_CHARGING), /** * Status indicating that the current Android device's battery is currently being discharging. * <p> * From {@link BatteryManager#BATTERY_STATUS_DISCHARGING} */ DISCHARGING(BatteryManager.BATTERY_STATUS_DISCHARGING), /** * Status indicating that the current Android device's battery is in idle state. * <p> * From {@link BatteryManager#BATTERY_STATUS_NOT_CHARGING} */ NOT_CHARGING(BatteryManager.BATTERY_STATUS_NOT_CHARGING), /** * Status indicating that the current Android device's battery is currently fully charged. * <p> * From {@link BatteryManager#BATTERY_STATUS_FULL} */ FULL(BatteryManager.BATTERY_STATUS_FULL); /** * The flag provided by {@link android.os.BatteryManager} for this battery status. */ public final int systemConstant; /** * Creates a new instance of BatteryStatus with the given BatteryManager flag. * * @param flag Id of status as flag provided by {@link android.os.BatteryManager}. */ private BatteryStatus(int flag) { this.systemConstant = flag; } /** * Resolves an instance of BatteryStatus according to the given <var>systemConstant</var> * from the current set of BatteryStatus values. * * @param systemConstant An id ({@link #systemConstant}) of the desired status to resolve. * @return Resolved battery status instance or {@link BatteryStatus#UNKNOWN} * if there is no battery status with the requested constant. */ @NonNull public static BatteryStatus resolve(int systemConstant) { for (BatteryStatus status : BatteryStatus.values()) { if (status.systemConstant == systemConstant) { return status; } } return UNKNOWN; } } /** * <h3>Enum Overview</h3> * Represents plugged state of an Android device's battery. * <p> * See {@link android.os.BatteryManager} for the plugged states supported from the * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1 API level 17} and higher. * * @author Martin Albedinsky * @see #resolve(int) */ public enum BatteryPluggedState { /** * State indicating that the battery plugged state is unknown due to some error or the current battery * data are unavailable. * <p> * <i>Constant value:</i> <b>-1</b> */ UNKNOWN(-1), /** * <p>D * State indicating that the battery isn't connected to any power source. * <p> * <i>Constant value:</i> <b>0</b> */ NOT_PLUGGED(0), /** * State indicating that the battery is connected to AC adapter. * <p> * From {@link BatteryManager#BATTERY_PLUGGED_AC} */ AC(BatteryManager.BATTERY_PLUGGED_AC), /** * State indicating that the battery is connected to USB cable. * <p> * From {@link BatteryManager#BATTERY_PLUGGED_USB} */ USB(BatteryManager.BATTERY_PLUGGED_USB), /** * State indicating that the battery is connected to wireless power source. * <p> * From {@link BatteryManager#BATTERY_PLUGGED_WIRELESS} * * @since {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1 API level 17} */ WIRELESS(4); /** * The flag provided by {@link android.os.BatteryManager} for this battery plugged state. */ public final int systemConstant; /** * Creates a new instance of BatteryPluggedState with the given BatteryManager flag. * * @param flag Id of status as flag provided by {@link android.os.BatteryManager}. */ private BatteryPluggedState(int flag) { this.systemConstant = flag; } /** * Resolves an instance of BatteryPluggedState according to the given <var>systemConstant</var> * from the current set of BatteryPluggedState values. * * @param systemConstant An id ({@link #systemConstant}) of the desired plugged state to resolve. * @return Resolved battery plugged state instance or {@link BatteryPluggedState#UNKNOWN} * if there is no battery plugged state with the requested constant. */ @NonNull public static BatteryPluggedState resolve(int systemConstant) { for (BatteryPluggedState state : BatteryPluggedState.values()) { if (state.systemConstant == systemConstant) { return state; } } return UNKNOWN; } } /** * <h3>Enum Overview</h3> * Represents health status of an Android device's battery. * <p> * See {@link android.os.BatteryManager} for the health statuses supported from the * {@link android.os.Build.VERSION_CODES#HONEYCOMB API level 11} and higher. * * @author Martin Albedinsky * @see #resolve(int) */ public enum BatteryHealth { /** * State indicating that the battery health state is unknown due to some error or the current * battery data are unavailable. * <p> * From {@link BatteryManager#BATTERY_HEALTH_UNKNOWN} * * @since {@link android.os.Build.VERSION_CODES#HONEYCOMB API level 11} */ UNKNOWN(BatteryManager.BATTERY_HEALTH_UNKNOWN), /** * State indicating that the battery health is good. * <p> * From {@link BatteryManager#BATTERY_HEALTH_GOOD} */ GOOD(BatteryManager.BATTERY_HEALTH_GOOD), /** * State indicating that the battery is overhead. * <p> * From {@link BatteryManager#BATTERY_HEALTH_OVERHEAT} */ OVERHEAT(BatteryManager.BATTERY_HEALTH_OVERHEAT), /** * State indicating that the battery is dead. * <p> * From {@link BatteryManager#BATTERY_HEALTH_DEAD} */ DEAD(BatteryManager.BATTERY_HEALTH_DEAD), /** * State indicating that the battery is over-voltage. * <p> * From {@link BatteryManager#BATTERY_HEALTH_OVER_VOLTAGE} */ OVER_VOLTAGE(BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE), /** * State indicating that there occurs some unspecified failure when trying to determine battery * health state. * <p> * From {@link BatteryManager#BATTERY_HEALTH_UNSPECIFIED_FAILURE} */ UNSPECIFIED_FAILURE(BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE), /** * State indicating that the battery is cold. * <p> * From {@link BatteryManager#BATTERY_HEALTH_UNKNOWN} * * @since {@link android.os.Build.VERSION_CODES#HONEYCOMB API level 11} */ COLD(BatteryManager.BATTERY_HEALTH_COLD); /** * The flag provided by {@link android.os.BatteryManager} for this battery health state. */ public final int systemConstant; /** * Creates a new instance of BatteryHealth with the given BatteryManager flag. * * @param flag Id of status as flag provided by {@link android.os.BatteryManager}. */ private BatteryHealth(int flag) { this.systemConstant = flag; } /** * Resolves an instance of BatteryHealth according to the given <var>systemConstant</var> from * the current set of BatteryHealth values. * * @param systemConstant An id ({@link #systemConstant}) of the desired health to resolve. * @return Resolved battery health instance or {@link BatteryHealth#UNKNOWN} * if there is no battery health with the requested constant. */ @NonNull public static BatteryHealth resolve(int systemConstant) { for (BatteryHealth health : BatteryHealth.values()) { if (health.systemConstant == systemConstant) { return health; } } return UNKNOWN; } } /** * <h3>Enum Overview</h3> * Represents technology of an Android device's battery. * * @author Martin Albedinsky * @see #resolve(String) */ public enum BatteryTechnology { /** * Indicates that the current Android device's battery technology can't be parsed by the tagged * name provided by {@link android.os.BatteryManager} or the current battery data are unavailable. * <ul> * <li><i>Tag:</i> <b>unknown</b></li> * <li><i>Original name:</i> <b>unknown</b></li> * </ul> */ UNKNOWN("unknown", "unknown"), /** * <b>Lithium Ion</b> battery technology. * <ul> * <li><i>Tag:</i> <b>Li-ion</b></li> * <li><i>Original name:</i> <b>Li-ion</b></li> * </ul> */ Li_ion("Li-ion", "Li-ion"), /** * <b>Lithium Polymer</b> battery technology. * <ul> * <li><i>Tag:</i> <b>Li-poly</b></li> * <li><i>Original name:</i> <b>Li-poly</b></li> * </ul> */ Li_poly("Li-poly", "Li-poly"), /** * <b>Silver Zinc</b> battery technology. * <ul> * <li><i>Tag:</i> <b>AgZn</b></li> * <li><i>Original name:</i> <b>Ag-Zn</b></li> * </ul> */ Ag_Zn("AgZn", "Ag-Zn"), /** * <b>Nickel Zinc</b> battery technology. * <ul> * <li><i>Tag:</i> <b>NiZn</b></li> * <li><i>Original name:</i> <b>Ni-Zn</b></li> * </ul> */ Ni_Zn("NiZn", "Ni-Zn"), /** * <b>Nickel Metal Hydrid</b> battery technology. * <ul> * <li><i>Tag:</i> <b>NiMH</b></li> * <li><i>Original name:</i> <b>Ni-MH</b></li> * </ul> */ Ni_MH("NiMH", "Ni-MH"), /** * <b>LEAD ACID</b> battery technology. * <ul> * <li><i>Tag:</i> <b>?</b></li> * <li><i>Original name:</i> <b>LEAD-ACID</b></li> * </ul> */ // todo: LEAD_ACID("?", "LEAD-ACID"), /** * <b>Nickel Cadmium</b> battery technology. * <ul> * <li><i>Tag:</i> <b>NiCd</b></li> * <li><i>Original name:</i> <b>Ni-Cd</b></li> * </ul> */ Ni_Cd("NiCd", "Ni-Cd"); /** * The tag name provided by {@link android.os.BatteryManager} for this battery technology. */ public final String tagName; /** * Original name of this battery technology. Can be used to present this technology by its * name in an Android application's UI. */ public final String originalName; /** * Creates a new instance of BatteryTechnology with the given BatteryManager tag and original * name. * * @param tagName Tag of this technology provided by {@link android.os.BatteryManager}. * @param origName Original name of this technology. */ private BatteryTechnology(String tagName, String origName) { this.tagName = tagName; this.originalName = origName; } /** * Resolves an instance of BatteryTechnology according to the given <var>tagName</var> from the * current set of BatteryTechnology values. * * @param tagName The name ({@link #tagName}) of the desired battery technology to resolve. * @return Resolved battery technology instance or {@link BatteryTechnology#UNKNOWN} * if there is no battery technology with the requested tag. */ @NonNull public static BatteryTechnology resolve(@NonNull String tagName) { for (BatteryTechnology tech : BatteryTechnology.values()) { if (tech.tagName.equalsIgnoreCase(tagName)) { return tech; } } return UNKNOWN; } } /** * Methods ===================================================================================== */ /** * Registers all battery receivers to receive all possible battery states for the given context. * * @param context Current activity or application context. * @see #unregisterAllBatteryReceivers(android.content.Context) * @see #registerBatteryReceiver(android.content.Context, int) */ public void registerAllBatteryReceivers(@NonNull Context context); /** * Registers single battery receiver for the given context. * * @param context Current activity or application context. * @param receiverId One of {@link #RECEIVER_BATTERY_STATUS}, {@link #RECEIVER_BATTERY_HEALTH}, * {@link #RECEIVER_BATTERY_PLUGGED_STATE} ids of the receiver to register. * @see #registerAllBatteryReceivers(android.content.Context) */ public void registerBatteryReceiver(@NonNull Context context, int receiverId); /** * Un-registers all battery receivers from the given context. * * @param context Context in which were all battery receivers registered before. * @see #registerAllBatteryReceivers(android.content.Context) * @see #unregisterBatteryReceiver(android.content.Context, int) */ public void unregisterAllBatteryReceivers(@NonNull Context context); /** * Un-registers single battery receiver from the given context. * * @param context Context in which was battery receiver registered before. * @param receiverId The id of battery receiver to un-register. One of {@link #RECEIVER_BATTERY_STATUS}, * {@link #RECEIVER_BATTERY_HEALTH}, {@link #RECEIVER_BATTERY_PLUGGED_STATE}. */ public void unregisterBatteryReceiver(@NonNull Context context, int receiverId); /** * Called to dispatch message that one of the registered {@link Battery.BatteryBroadcastReceiver} * was currently unregistered. This should be called immediately after successful un-registration * of battery receiver with the specified <var>receiverId</var>. * * @param receiverId The id of the battery receiver which was un-registered. One of {@link #RECEIVER_BATTERY_STATUS}, * {@link #RECEIVER_BATTERY_HEALTH}, {@link #RECEIVER_BATTERY_PLUGGED_STATE}. */ public void dispatchBatteryReceiverUnregistered(int receiverId); /** * Returns flag indicating whether the battery receiver with the specified <var>receiverId</var> * is currently registered or not. * * @param receiverId The id of the battery receiver. One of {@link #RECEIVER_BATTERY_STATUS}, * {@link #RECEIVER_BATTERY_HEALTH}, {@link #RECEIVER_BATTERY_PLUGGED_STATE}. * @return {@code True} if battery receiver is registered, {@code false} otherwise. */ public boolean isBatteryReceiverRegistered(int receiverId); /** * Registers a callback to be invoked when some of the battery states changes. * * @param listener Callback to register. One of {@link com.wit.android.device.Battery.OnStatusListener}, * {@link com.wit.android.device.Battery.OnHealthListener}, * {@link com.wit.android.device.Battery.OnPluggedStateListener}. * @see #unregisterOnBatteryListener(Battery.BatteryListener) */ public void registerOnBatteryListener(@NonNull BatteryListener listener); /** * Un-registers the given battery listener callback. * * @param listener Callback to un-register. * @see #registerOnBatteryListener(Battery.BatteryListener) */ public void unregisterOnBatteryListener(@NonNull BatteryListener listener); /** * Returns the current strength of life of this Android device's battery. * * @return The value of strength in the range {@code [0, 100]} or negative number if * the current battery data are unavailable. */ public int getStrength(); /** * Returns the current status of this Android device's battery. * * @return One of {@link BatteryStatus} values or {@link BatteryStatus#UNKNOWN BatteryStatus.UNKNOWN} if the current * battery data are unavailable. */ @NonNull public BatteryStatus getStatus(); /** * Returns the current plugged state of this Android device's battery. * * @return One of {@link BatteryPluggedState} values or {@link BatteryPluggedState#UNKNOWN BatteryPluggedState.UNKNOWN} * if the current battery data are unavailable. */ @NonNull public BatteryPluggedState getPluggedState(); /** * Returns the current health of this Android device's battery. * * @return One of {@link BatteryHealth} values or {@link BatteryHealth#UNKNOWN BatteryHealth.UNKNOWN} * if the current battery data are unavailable. */ @NonNull public BatteryHealth getHealth(); /** * Returns the technology of this Android device's battery. * * @return One of {@link BatteryTechnology} values or {@link BatteryTechnology#UNKNOWN BatteryTechnology.UNKNOWN} * if technology can't be parsed due to unknown technology tag name or if the current battery data * are unavailable. */ @NonNull public BatteryTechnology getTechnology(); /** * Returns the current temperature of this Android device's battery. * * @return Current temperature in degree <b>Centigrade</b> (C) or negative number if the current * battery data are unavailable. */ public float getTemperature(); /** * Returns the current voltage of this Android device's battery. * * @return Current voltage in <b>milli-Volts</b> (mV) or negative number if current voltage is * unknown or the current battery data are unavailable. */ public int getVoltage(); /** * Returns flag indicating whether this Android device's battery is currently being charging or not. * <p> * This is similar to {@link #isPlugged()} but here is checked the battery current status. * * @return {@code True} if battery is currently being charging * (status == {@link BatteryStatus#CHARGING BatteryStatus.CHARGING} || {@link BatteryStatus#FULL BatteryStatus.FULL}), * {@code false} otherwise. * @see #isPlugged() */ public boolean isCharging(); /** * Returns flag indicating whether this Android device's battery is currently plugged to some * power source or not. * <p> * This is similar to {@link #isCharging()} but here is checked the battery current plugged state. * * @return {@code True} if battery is plugged to some power source, {@code false} otherwise. * @see #getPluggedState() * @see #isCharging() */ public boolean isPlugged(); /** * Returns flag indicating whether the current strength of this Android device's battery is below * the <b>LOW</b> ({@link #getHealthLowLevel()}) level value or not. * * @return {@code True} if the current strength is less then or equal to the current <b>LOW</b> * level value, {@code false} otherwise. * @see #getStrength() * @see #getHealth() */ public boolean isLow(); /** * Sets value of the battery health <b>LOW</b> level. This value will be used to determine whether * the battery health change should be fired for {@link com.wit.android.device.Battery.OnHealthListener} * with {@code true} flag for {@code isLow} parameter. * <p> * <b>Note</b> that this level is checked only in case of received intent for * {@link com.wit.android.device.receiver.BatteryStatusReceiver} which must be registered. * * @param level Level from the range {@code [0, 100]}. * @see #getHealthLowLevel() * @see #registerBatteryReceiver(android.content.Context, int) */ public void setHealthLowLevel(int level); /** * Returns value of the battery current health <b>LOW</b> level. * * @return The value of <b>LOW</b> level in the range {@code [0, 100]}. * @see #setHealthLowLevel(int) * @see #isLow() */ public int getHealthLowLevel(); /** * Sets value of the battery health <b>OK</b> level. This value will be used to determine whether * the battery health change should be fired for {@link com.wit.android.device.Battery.OnHealthListener} * with {@code false} flag for {@code isLow} parameter. * <p> * <b>Note</b> that this level is checked only in case of received intent for * {@link com.wit.android.device.receiver.BatteryStatusReceiver} which must be registered. * * @param level Level from the range {@code [0, 100]}. * @see #getHealthOkLevel() * @see #registerBatteryReceiver(android.content.Context, int) */ public void setHealthOkLevel(int level); /** * Returns value of the battery current health <b>OK</b> level. * * @return The value of <b>OK</b> level in the range {@code [0, 100]}. * @see #setHealthOkLevel(int) */ public int getHealthOkLevel(); /** * Inner classes =============================================================================== */ /** * <h3>Class Overview</h3> * Base battery status receiver. * * @author Martin Albedinsky */ public static abstract class BatteryBroadcastReceiver extends BroadcastReceiver { /** * Implementation in subclass should return new intent filter specific for its receiver action. * * @return New intent filter. */ @NonNull public abstract IntentFilter newIntentFilter(); } /** * Listeners =================================================================================== */ /** * <h3>Class Overview</h3> * todo: description * * @author Martin Albedinsky */ public static abstract class SimpleListener implements OnStatusListener, OnPluggedStateListener, OnHealthListener { /** */ @Override public void onHealthChange(@NonNull Battery battery, boolean isLow, @NonNull Context context) { } /** */ @Override public void onPluggedStateChange(@NonNull Battery battery, boolean plugged, @NonNull Context context) { } /** */ @Override public void onStatusChange(@NonNull Battery battery, @NonNull Context context) { } } /** * Parent battery listener. Only for internal purpose. */ static interface BatteryListener { } /** * <h3>Interface Overview</h3> * Callback to receive battery status changes. * * @author Martin Albedinsky */ public static interface OnStatusListener extends BatteryListener { /** * Invoked whenever the status change of this Android device's battery occurs. * <p> * <b>Note</b>, that there need to be registered {@link com.wit.android.device.receiver.BatteryStatusReceiver}, * for example by {@link #registerBatteryReceiver(android.content.Context, int)} with * {@link #RECEIVER_BATTERY_STATUS} to receive this callback. * * @param battery Battery wrapper with actual data. * @param context Current application context. */ public void onStatusChange(@NonNull Battery battery, @NonNull Context context); } /** * <h3>Interface Overview</h3> * Callback to receive battery plugged state changes. * * @author Martin Albedinsky */ public static interface OnPluggedStateListener extends BatteryListener { /** * Invoked whenever the plugged state of this Android device's battery changes. * <p> * <b>Note</b>, that there need to be registered {@link com.wit.android.device.receiver.BatteryPluggedStateReceiver}, * for example by {@link #registerBatteryReceiver(android.content.Context, int)} with * {@link #RECEIVER_BATTERY_PLUGGED_STATE} to receive this callback. * * @param battery Battery wrapper with actual data. * @param plugged {@code True} if battery is plugged to some power source, {@code false} * otherwise. * @param context Current application context. */ public void onPluggedStateChange(@NonNull Battery battery, boolean plugged, @NonNull Context context); } /** * <h3>Interface Overview</h3> * Callback to receive battery health (LOW/OK) changes. * * @author Martin Albedinsky */ public static interface OnHealthListener extends BatteryListener { /** * Invoked whenever the current strength of this Android device's battery comes from the <b>OK</b> * level to the <b>LOW</b> one or other way, from the <b>LOW</b> level to the <b>OK</b> one. * <p> * <b>Note</b>, that there need to be registered {@link com.wit.android.device.receiver.BatteryHealthReceiver}, * for example by {@link #registerBatteryReceiver(android.content.Context, int)} with * {@link #RECEIVER_BATTERY_HEALTH} to receive this callback. * * @param battery Battery wrapper with actual data. * @param isLow {@code True} if the current strength of this Android device's battery is * <b>LOW</b>, {@code false} otherwise. * @param context Current application context. * @see #setHealthLowLevel(int) * @see #setHealthOkLevel(int) */ public void onHealthChange(@NonNull Battery battery, boolean isLow, @NonNull Context context); } }