本文整理匯總了Java中android.os.BatteryManager.BATTERY_STATUS_NOT_CHARGING屬性的典型用法代碼示例。如果您正苦於以下問題:Java BatteryManager.BATTERY_STATUS_NOT_CHARGING屬性的具體用法?Java BatteryManager.BATTERY_STATUS_NOT_CHARGING怎麽用?Java BatteryManager.BATTERY_STATUS_NOT_CHARGING使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類android.os.BatteryManager
的用法示例。
在下文中一共展示了BatteryManager.BATTERY_STATUS_NOT_CHARGING屬性的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setStatus
private void setStatus(int statusValue) {
String status;
switch (statusValue) {
case BatteryManager.BATTERY_STATUS_CHARGING:
status = getString(R.string.battery_status_charging);
break;
case BatteryManager.BATTERY_STATUS_DISCHARGING:
status = getString(R.string.battery_status_discharging);
break;
case BatteryManager.BATTERY_STATUS_FULL:
status = getString(R.string.battery_status_full);
break;
case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
status = getString(R.string.battery_status_not_charging);
break;
case BatteryManager.BATTERY_STATUS_UNKNOWN:
default:
status = getString(R.string.battery_status_unknown);
}
mViewStatus.setValue(status);
mBatteryInfo.setStatus(status);
}
示例2: isCharging
/**
* Method to check if the device is charging.
*
* @return Returns true if device is either charging or full, false otherwise
*/
private boolean isCharging() {
try {
Intent batteryIntent = mContext.getApplicationContext().registerReceiver(null,
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
if (batteryIntent != null) {
int batteryPowerStatus = batteryIntent.getIntExtra(BatteryManager.EXTRA_STATUS, 0);
switch (batteryPowerStatus) {
case BatteryManager.BATTERY_STATUS_CHARGING:
case BatteryManager.BATTERY_STATUS_FULL:
return true;
case BatteryManager.BATTERY_STATUS_UNKNOWN:
case BatteryManager.BATTERY_STATUS_DISCHARGING:
case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
default:
return false;
}
}
} catch (Exception e) {
Log.e(TAG, "Exception occurred while isCharging: " + e);
}
return false;
}
示例3: translateBatteryStatus
public static String translateBatteryStatus(int batteryStatus) {
switch (batteryStatus) {
case BatteryManager.BATTERY_STATUS_CHARGING:
return "CHARGING";
case BatteryManager.BATTERY_STATUS_DISCHARGING:
return "DISCHARGING";
case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
return "NOT CHARGING";
case BatteryManager.BATTERY_STATUS_FULL:
return "FULL";
case BatteryManager.BATTERY_STATUS_UNKNOWN:
return "STATUS UNKNOWN";
default:
return "UNKNOWN (" + batteryStatus + ")";
}
}
示例4: getBatteryStatusText
/** Get readable battery status */
private String getBatteryStatusText(int status) {
String statusString = getString(R.string.unknown);
switch (status) {
case BatteryManager.BATTERY_STATUS_UNKNOWN:
statusString = getString(R.string.unknown);
break;
case BatteryManager.BATTERY_STATUS_CHARGING:
statusString = getString(R.string.charging);
break;
case BatteryManager.BATTERY_STATUS_DISCHARGING:
statusString = getString(R.string.discharging);
break;
case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
statusString = getString(R.string.not_charging);
break;
case BatteryManager.BATTERY_STATUS_FULL:
statusString = getString(R.string.full);
break;
}
return statusString;
}
示例5: getBatteryInfo
private void getBatteryInfo() {
if (fabBatteryCharging != null) {
if (deviceStatus == BatteryManager.BATTERY_STATUS_CHARGING) {
fabBatteryCharging.setVisibility(View.VISIBLE);
fabBatteryCharging.setImageResource(R.drawable.ic_battery);
}
if (deviceStatus == BatteryManager.BATTERY_STATUS_DISCHARGING) {
fabBatteryCharging.setVisibility(View.GONE);
}
if (deviceStatus == BatteryManager.BATTERY_STATUS_FULL) {
fabBatteryCharging.setVisibility(View.GONE);
}
if (deviceStatus == BatteryManager.BATTERY_STATUS_UNKNOWN) {
fabBatteryCharging.setVisibility(View.GONE);
}
if (deviceStatus == BatteryManager.BATTERY_STATUS_NOT_CHARGING) {
fabBatteryCharging.setVisibility(View.GONE);
}
}
final Handler handler = new Handler();
final Runnable runnable = new Runnable() {
int counter = 0;
@Override
public void run() {
try {
if (counter <= level) {
progressBar.setProgress(counter);
progressBar.postDelayed(this, 10000);
counter++;
handler.postDelayed(this, 20);
} else {
handler.removeCallbacks(this);
}
} catch (NullPointerException e) {
e.printStackTrace();
}
}
};
handler.postDelayed(runnable, 20);
tvBatteryTemperature.setText("".concat(String.valueOf(temperature)));
if (Validation.isRequiredField(technology)) {
tvBatteryType.setText("".concat(technology));
}
tvBatteryVoltage.setText("".concat(String.valueOf(voltage)));
tvBatteryScale.setText("".concat(String.valueOf(scale)));
tvBatteryLevel.setText("".concat(String.valueOf(level)).concat("%"));
if (health == 1) {
tvBatteryHealth.setText(mResources.getString(R.string.unknown));
} else if (health == 2) {
tvBatteryHealth.setText(mResources.getString(R.string.good));
} else if (health == 3) {
tvBatteryHealth.setText(mResources.getString(R.string.over_heated));
} else if (health == 4) {
tvBatteryHealth.setText(mResources.getString(R.string.dead));
} else if (health == 5) {
tvBatteryHealth.setText(mResources.getString(R.string.over_voltage));
} else if (health == 6) {
tvBatteryHealth.setText(mResources.getString(R.string.failed));
} else {
tvBatteryHealth.setText(mResources.getString(R.string.cold));
}
if (plugged == 1) {
tvPowerSource.setText(mResources.getString(R.string.ac_power));
} else {
tvPowerSource.setText(mResources.getString(R.string.battery));
}
}
示例6: getStatus
/**
* Method to resolve the battery status
*/
private void getStatus() {
if (DEBUG) {
MyLog.i(CLS_NAME, "getStatus");
}
if (batteryIntent != null) {
final SaiyResources sr = new SaiyResources(mContext, sl);
final int status = batteryIntent.getIntExtra(BatteryManager.EXTRA_STATUS,
BatteryManager.BATTERY_STATUS_UNKNOWN);
switch (status) {
case BatteryManager.BATTERY_STATUS_CHARGING:
int plugged = batteryIntent.getIntExtra(BatteryManager.EXTRA_PLUGGED,
BatteryManager.BATTERY_STATUS_UNKNOWN);
switch (plugged) {
case BatteryManager.BATTERY_PLUGGED_AC:
setStatusResponse(sr.getString(ai.saiy.android.R.string.ac_charging));
break;
case BatteryManager.BATTERY_PLUGGED_USB:
setStatusResponse(sr.getString(ai.saiy.android.R.string.usb_charging));
break;
default:
setStatusResponse(sr.getString(ai.saiy.android.R.string.charging));
break;
}
break;
case BatteryManager.BATTERY_STATUS_DISCHARGING:
setStatusResponse(sr.getString(ai.saiy.android.R.string.discharging));
break;
case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
setStatusResponse(sr.getString(ai.saiy.android.R.string.discharging));
break;
case BatteryManager.BATTERY_STATUS_FULL:
setStatusResponse(sr.getString(ai.saiy.android.R.string.fully_charged));
break;
case BatteryManager.BATTERY_STATUS_UNKNOWN:
setStatusResponse(sr.getString(ai.saiy.android.R.string.currently_indeterminable));
break;
default:
setStatusResponse(sr.getString(ai.saiy.android.R.string.currently_indeterminable));
break;
}
sr.reset();
} else {
if (DEBUG) {
MyLog.w(CLS_NAME, "batteryIntent: null");
}
setAccessFailure();
}
}
示例7: onReceive
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_BATTERY_CHANGED)
&& mIv_battery != null) {
//得到係統當前電量
int level = intent.getIntExtra("level", 0);
int status = intent.getIntExtra("status", 0);
boolean chargingFlag = false;
switch (status) {
case BatteryManager.BATTERY_STATUS_CHARGING:
//充電中
chargingFlag = true;
break;
case BatteryManager.BATTERY_STATUS_DISCHARGING:
//放電中
chargingFlag = false;
break;
case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
//未充電
chargingFlag = false;
break;
case BatteryManager.BATTERY_STATUS_FULL:
//電量滿
chargingFlag = false;
mIv_battery.setImageResource(R.mipmap.battery_full);
break;
}
if (level == 100) {
if (chargingFlag) {
mIv_battery.setImageResource(R.mipmap.battery_charging_full);
} else {
mIv_battery.setImageResource(R.mipmap.battery_full);
}
} else if (level >= 90 && level < 100) {
if (chargingFlag) {
mIv_battery.setImageResource(R.mipmap.battery_charging_90);
} else {
mIv_battery.setImageResource(R.mipmap.battery_90);
}
} else if (level >= 80 && level < 90) {
if (chargingFlag) {
mIv_battery.setImageResource(R.mipmap.battery_charging_80);
} else {
mIv_battery.setImageResource(R.mipmap.battery_80);
}
} else if (level >= 60 && level < 80) {
if (chargingFlag) {
mIv_battery.setImageResource(R.mipmap.battery_charging_60);
} else {
mIv_battery.setImageResource(R.mipmap.battery_60);
}
} else if (level >= 50 && level < 60) {
if (chargingFlag) {
mIv_battery.setImageResource(R.mipmap.battery_charging_50);
} else {
mIv_battery.setImageResource(R.mipmap.battery_50);
}
} else if (level >= 30 && level < 50) {
if (chargingFlag) {
mIv_battery.setImageResource(R.mipmap.battery_charging_30);
} else {
mIv_battery.setImageResource(R.mipmap.battery_30);
}
} else if (level >= 20 && level < 30) {
if (chargingFlag) {
mIv_battery.setImageResource(R.mipmap.battery_charging_20);
} else {
mIv_battery.setImageResource(R.mipmap.battery_20);
}
} else if (level < 20) {
if (chargingFlag) {
mIv_battery.setImageResource(R.mipmap.battery_charging_20);
} else {
mIv_battery.setImageResource(R.mipmap.battery_alert);
}
}
}
}