Merge "Move some battery stuff to SettingsLib"
This commit is contained in:
@@ -88,7 +88,6 @@ import com.android.internal.util.UserIcons;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
@@ -96,7 +95,8 @@ import java.util.Locale;
|
||||
|
||||
import static android.content.Intent.EXTRA_USER;
|
||||
|
||||
public final class Utils {
|
||||
public final class Utils extends com.android.settingslib.Utils {
|
||||
|
||||
private static final String TAG = "Settings";
|
||||
|
||||
/**
|
||||
@@ -262,21 +262,6 @@ public final class Utils {
|
||||
}
|
||||
}
|
||||
|
||||
/** Formats the ratio of amount/total as a percentage. */
|
||||
public static String formatPercentage(long amount, long total) {
|
||||
return formatPercentage(((double) amount) / total);
|
||||
}
|
||||
|
||||
/** Formats an integer from 0..100 as a percentage. */
|
||||
public static String formatPercentage(int percentage) {
|
||||
return formatPercentage(((double) percentage) / 100.0);
|
||||
}
|
||||
|
||||
/** Formats a double from 0.0..1.0 as a percentage. */
|
||||
private static String formatPercentage(double percentage) {
|
||||
return NumberFormat.getPercentInstance().format(percentage);
|
||||
}
|
||||
|
||||
public static boolean isBatteryPresent(Intent batteryChangedIntent) {
|
||||
return batteryChangedIntent.getBooleanExtra(BatteryManager.EXTRA_PRESENT, true);
|
||||
}
|
||||
@@ -285,44 +270,6 @@ public final class Utils {
|
||||
return formatPercentage(getBatteryLevel(batteryChangedIntent));
|
||||
}
|
||||
|
||||
public static int getBatteryLevel(Intent batteryChangedIntent) {
|
||||
int level = batteryChangedIntent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
|
||||
int scale = batteryChangedIntent.getIntExtra(BatteryManager.EXTRA_SCALE, 100);
|
||||
return (level * 100) / scale;
|
||||
}
|
||||
|
||||
public static String getBatteryStatus(Resources res, Intent batteryChangedIntent) {
|
||||
final Intent intent = batteryChangedIntent;
|
||||
|
||||
int plugType = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0);
|
||||
int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS,
|
||||
BatteryManager.BATTERY_STATUS_UNKNOWN);
|
||||
String statusString;
|
||||
if (status == BatteryManager.BATTERY_STATUS_CHARGING) {
|
||||
int resId;
|
||||
if (plugType == BatteryManager.BATTERY_PLUGGED_AC) {
|
||||
resId = R.string.battery_info_status_charging_ac;
|
||||
} else if (plugType == BatteryManager.BATTERY_PLUGGED_USB) {
|
||||
resId = R.string.battery_info_status_charging_usb;
|
||||
} else if (plugType == BatteryManager.BATTERY_PLUGGED_WIRELESS) {
|
||||
resId = R.string.battery_info_status_charging_wireless;
|
||||
} else {
|
||||
resId = R.string.battery_info_status_charging;
|
||||
}
|
||||
statusString = res.getString(resId);
|
||||
} else if (status == BatteryManager.BATTERY_STATUS_DISCHARGING) {
|
||||
statusString = res.getString(R.string.battery_info_status_discharging);
|
||||
} else if (status == BatteryManager.BATTERY_STATUS_NOT_CHARGING) {
|
||||
statusString = res.getString(R.string.battery_info_status_not_charging);
|
||||
} else if (status == BatteryManager.BATTERY_STATUS_FULL) {
|
||||
statusString = res.getString(R.string.battery_info_status_full);
|
||||
} else {
|
||||
statusString = res.getString(R.string.battery_info_status_unknown);
|
||||
}
|
||||
|
||||
return statusString;
|
||||
}
|
||||
|
||||
public static void forcePrepareCustomPreferencesList(
|
||||
ViewGroup parent, View child, ListView list, boolean ignoreSidePadding) {
|
||||
list.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
|
||||
|
Reference in New Issue
Block a user