Back to project page rfcx-guardian-android.
The source code is released under:
Apache License
If you think the Android project rfcx-guardian-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.
package org.rfcx.guardian.device; // w ww . j a va 2 s . co m import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.BatteryManager; public class DeviceState { public int serviceSamplesPerMinute = 60; // Battery private int batteryLevel; private int batteryScale; private int batteryTemperature; private boolean batteryDisCharging; private boolean batteryCharged; private void setBatteryLevel(int batteryLevel) { this.batteryLevel = batteryLevel; } private void setBatteryScale(int batteryScale) { this.batteryScale = batteryScale; } private void setBatteryTemperature(int batteryTemperature) { this.batteryTemperature = batteryTemperature; } private void setBatteryDisCharging(int batteryStatus) { this.batteryDisCharging = (batteryStatus == BatteryManager.BATTERY_STATUS_DISCHARGING); } private void setBatteryCharged(int batteryStatus) { this.batteryCharged = (batteryStatus == BatteryManager.BATTERY_STATUS_FULL); } public int getBatteryPercent() { return Math.round(100 * this.batteryLevel / (float) this.batteryScale); } public boolean isBatteryDisCharging() { return this.batteryDisCharging; } public boolean isBatteryCharged() { return this.batteryCharged; } public int getBatteryTemperature() { return batteryTemperature; } public void setBatteryState(Context context, Intent intent) { if (intent == null) intent = context.getApplicationContext().registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); setBatteryLevel(intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1)); setBatteryScale(intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1)); setBatteryDisCharging(intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1)); setBatteryCharged(intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1)); setBatteryTemperature(Math.round(intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, -1)/10)); } // Light Sensor private int lightLevel; public void setLightLevel(int lightLevel) { this.lightLevel = lightLevel; } public int getLightLevel() { return lightLevel; } }