am a55ae92a: Remove isCustomized() check as the API is not used for now.

Merge commit 'a55ae92a132325e9307f291c455b1148d0bff3cf'

* commit 'a55ae92a132325e9307f291c455b1148d0bff3cf':
  Remove isCustomized() check as the API is not used for now.
  Remove LAUNCHER category from VPN settings activity's intent filter.
  Improve power control widget GUI.
  Minor UI improvements and showing of unplugged duration.
  Make the Settings side of the date format settings more locale-aware.
This commit is contained in:
Hung-ying Tyan
2009-06-14 21:12:57 -07:00
committed by The Android Open Source Project
27 changed files with 170 additions and 120 deletions

View File

@@ -115,9 +115,8 @@
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<action android:name="android.net.vpn.SETTINGS" /> <action android:name="android.net.vpn.SETTINGS" />
<action android:name="android.net.vpn.INSTALL_PROFILE" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.VOICE_LAUNCH" />
</intent-filter> </intent-filter>
</activity> </activity>
@@ -190,6 +189,7 @@
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<action android:name="com.android.settings.SOUND_SETTINGS" /> <action android:name="com.android.settings.SOUND_SETTINGS" />
<action android:name="com.android.settings.DISPLAY_SETTINGS" /> <action android:name="com.android.settings.DISPLAY_SETTINGS" />
<action android:name="android.settings.DISPLAY_SETTINGS" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.VOICE_LAUNCH" /> <category android:name="android.intent.category.VOICE_LAUNCH" />
</intent-filter> </intent-filter>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 98 B

After

Width:  |  Height:  |  Size: 152 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 873 B

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 701 B

After

Width:  |  Height:  |  Size: 847 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 930 B

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 696 B

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 749 B

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 871 B

After

Width:  |  Height:  |  Size: 885 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -27,8 +27,9 @@
android:textStyle="bold" android:textStyle="bold"
android:singleLine="true" android:singleLine="true"
android:layout_alignParentLeft="true" android:layout_alignParentLeft="true"
android:layout_marginBottom="2dip" android:layout_marginBottom="4dip"
android:layout_marginTop="2dip" /> android:layout_marginTop="4dip"
android:layout_marginLeft="4dip" />
<TextView <TextView
android:id="@+id/value" android:id="@+id/value"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@@ -37,7 +38,7 @@
android:textAppearance="?android:attr/textAppearanceMedium" android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="normal" android:textStyle="normal"
android:singleLine="true" android:singleLine="true"
android:layout_marginBottom="2dip" android:layout_marginBottom="4dip"
android:layout_marginTop="2dip" android:layout_marginTop="4dip"
android:layout_marginRight="4dip"/> android:layout_marginRight="10dip"/>
</RelativeLayout> </RelativeLayout>

View File

@@ -96,6 +96,7 @@
<TextView <TextView
android:id="@+id/controls_section_title" android:id="@+id/controls_section_title"
style="?android:attr/listSeparatorTextViewStyle" style="?android:attr/listSeparatorTextViewStyle"
android:layout_marginTop="6dip"
android:text="@string/controls_subtitle" /> android:text="@string/controls_subtitle" />
<RelativeLayout <RelativeLayout
@@ -130,6 +131,7 @@
<TextView <TextView
android:id="@+id/packages_section_title" android:id="@+id/packages_section_title"
style="?android:attr/listSeparatorTextViewStyle" style="?android:attr/listSeparatorTextViewStyle"
android:layout_marginTop="6dip"
android:text="@string/packages_subtitle" /> android:text="@string/packages_subtitle" />
<LinearLayout <LinearLayout

View File

@@ -36,25 +36,13 @@
/> />
<ImageButton <ImageButton
android:id="@+id/btn_brightness" android:id="@+id/btn_bluetooth"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:layout_marginLeft="3dip" android:layout_marginLeft="3dip"
android:layout_marginRight="3dip" android:layout_marginRight="3dip"
android:background="@drawable/widget_btn" android:background="@drawable/widget_btn"
android:layout_gravity="center_horizontal" android:layout_gravity="center_horizontal"
/>
<ImageButton
android:id="@+id/btn_sync"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginLeft="3dip"
android:layout_marginRight="3dip"
android:background="@drawable/widget_btn"
android:layout_gravity="center_horizontal"
/> />
<ImageButton <ImageButton
@@ -65,17 +53,26 @@
android:layout_marginRight="3dip" android:layout_marginRight="3dip"
android:background="@drawable/widget_btn" android:background="@drawable/widget_btn"
android:layout_gravity="center_horizontal" android:layout_gravity="center_horizontal"
/> />
<ImageButton <ImageButton
android:id="@+id/btn_bluetooth" android:id="@+id/btn_sync"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:layout_marginLeft="3dip" android:layout_marginLeft="3dip"
android:layout_marginRight="3dip" android:layout_marginRight="3dip"
android:background="@drawable/widget_btn" android:background="@drawable/widget_btn"
android:layout_gravity="center_horizontal" android:layout_gravity="center_horizontal"
/> />
<ImageButton
android:id="@+id/btn_brightness"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginLeft="3dip"
android:layout_marginRight="3dip"
android:background="@drawable/widget_btn"
android:layout_gravity="center_horizontal"
/>
</LinearLayout> </LinearLayout>

View File

@@ -39,18 +39,12 @@
<item>All</item> <item>All</item>
</string-array> </string-array>
<!-- There is a setting to control the format of dates displayed throughout the system. This is in the Date & Time Settings screen. Unfortunately, these cannot be changed at all. --> <skip /> <!-- There is a setting to control the format of dates displayed throughout the system. This is in the Date & Time Settings screen. These will be adjusted to use punctuation appropriate to the user's locale. -->
<!-- Do not translate. This is fed directly to the formatter. --> <string-array name="date_format_values" translatable="false">
<string-array name="date_format_values"> <!-- The blank item means to use whatever the locale calls for. -->
<!-- Do not translate. This is fed directly to the formatter. --> <item></item>
<item>MM-dd-yyyy</item> <item>MM-dd-yyyy</item>
<!-- Do not translate. This is fed directly to the formatter. -->
<item>dd-MM-yyyy</item> <item>dd-MM-yyyy</item>
<!-- Do not translate. This is fed directly to the formatter. -->
<item>MMM d, yyyy</item>
<!-- Do not translate. This is fed directly to the formatter. -->
<item>d-MMM-yyyy</item>
<!-- Do not translate. This is fed directly to the formatter. -->
<item>yyyy-MM-dd</item> <item>yyyy-MM-dd</item>
</string-array> </string-array>

View File

@@ -243,6 +243,10 @@
<!-- Do not translate. Used as the value for a setting. --> <!-- Do not translate. Used as the value for a setting. -->
<string name="default_date_format"><xliff:g id="default_date_format">MM/dd/yyyy</xliff:g></string> <string name="default_date_format"><xliff:g id="default_date_format">MM/dd/yyyy</xliff:g></string>
<!-- The option in the date-format picker for using the normal format
called for by the user's locale. -->
<string name="normal_date_format">Normal (<xliff:g id="date" example="12-31-2009">%s</xliff:g>)</string>
<!-- Label of preview text when tweaking font size --> <!-- Label of preview text when tweaking font size -->
<string name="display_preview_label">Preview:</string> <string name="display_preview_label">Preview:</string>
<!-- Label for chosen font size --> <!-- Label for chosen font size -->
@@ -1528,13 +1532,13 @@ found in the list of installed applications.</string>
<string name="battery_history_starts">Starts: <xliff:g id="starts">%1$d</xliff:g></string> <string name="battery_history_starts">Starts: <xliff:g id="starts">%1$d</xliff:g></string>
<!-- Used to show an amount of time in the form "d days, h hours, m minutes, s seconds" in BatteryHistory --> <!-- Used to show an amount of time in the form "d days, h hours, m minutes, s seconds" in BatteryHistory -->
<string name="battery_history_days"><xliff:g id="days">%1$d</xliff:g> d, <xliff:g id="hours">%2$d</xliff:g> h, <xliff:g id="minutes">%3$d</xliff:g> m, <xliff:g id="seconds">%4$d</xliff:g> s</string> <string name="battery_history_days"><xliff:g id="days">%1$d</xliff:g>d <xliff:g id="hours">%2$d</xliff:g>h <xliff:g id="minutes">%3$d</xliff:g>m <xliff:g id="seconds">%4$d</xliff:g>s</string>
<!-- Used to show an amount of time in the form "h hours, m minutes, s seconds" in BatteryHistory --> <!-- Used to show an amount of time in the form "h hours, m minutes, s seconds" in BatteryHistory -->
<string name="battery_history_hours"><xliff:g id="hours">%1$d</xliff:g> h, <xliff:g id="minutes">%2$d</xliff:g> m, <xliff:g id="seconds">%3$d</xliff:g> s</string> <string name="battery_history_hours"><xliff:g id="hours">%1$d</xliff:g>h <xliff:g id="minutes">%2$d</xliff:g>m <xliff:g id="seconds">%3$d</xliff:g>s</string>
<!-- Used to show an amount of time in the form "m minutes, s seconds" in BatteryHistory --> <!-- Used to show an amount of time in the form "m minutes, s seconds" in BatteryHistory -->
<string name="battery_history_minutes"><xliff:g id="minutes">%1$d</xliff:g> m, <xliff:g id="seconds">%2$d</xliff:g> s</string> <string name="battery_history_minutes"><xliff:g id="minutes">%1$d</xliff:g>m <xliff:g id="seconds">%2$d</xliff:g>s</string>
<!-- Used to show an amount of time in the form "s seconds" in BatteryHistory --> <!-- Used to show an amount of time in the form "s seconds" in BatteryHistory -->
<string name="battery_history_seconds"><xliff:g id="seconds">%1$d</xliff:g>s</string> <string name="battery_history_seconds"><xliff:g id="seconds">%1$d</xliff:g>s</string>
@@ -1630,6 +1634,8 @@ found in the list of installed applications.</string>
<string name="battery_since_unplugged">Battery usage since unplugged</string> <string name="battery_since_unplugged">Battery usage since unplugged</string>
<!-- Battery usage since user reset the stats --> <!-- Battery usage since user reset the stats -->
<string name="battery_since_reset">Battery usage since reset</string> <string name="battery_since_reset">Battery usage since reset</string>
<!-- Battery usage duration -->
<string name="battery_stats_duration">Usage duration - <xliff:g id="time">%1$s</xliff:g></string>
<!-- CPU awake time title --> <!-- CPU awake time title -->
<string name="awake">Device awake time</string> <string name="awake">Device awake time</string>
<!-- Wifi on time --> <!-- Wifi on time -->
@@ -1794,5 +1800,5 @@ found in the list of installed applications.</string>
<string name="vpn_settings_category">VPN</string> <string name="vpn_settings_category">VPN</string>
<string name="vpn_settings_title">VPN</string> <string name="vpn_settings_title">VPN</string>
<string name="vpn_settings_summary">Set up and manage VPN configurations, connections</string> <string name="vpn_settings_summary">Set up &amp; manage VPN configurations, connections</string>
</resources> </resources>

View File

@@ -16,5 +16,6 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/battery_since_unplugged"> android:title="@string/battery_since_unplugged">
<PreferenceCategory
android:key="app_list"/>
</PreferenceScreen> </PreferenceScreen>

View File

@@ -87,19 +87,25 @@ public class DateTimeSettings
mDatePref = findPreference("date"); mDatePref = findPreference("date");
mDateFormat = (ListPreference) findPreference(KEY_DATE_FORMAT); mDateFormat = (ListPreference) findPreference(KEY_DATE_FORMAT);
int currentFormatIndex = -1;
String [] dateFormats = getResources().getStringArray(R.array.date_format_values); String [] dateFormats = getResources().getStringArray(R.array.date_format_values);
String [] formattedDates = new String[dateFormats.length]; String [] formattedDates = new String[dateFormats.length];
String currentFormat = getDateFormat(); String currentFormat = getDateFormat();
// Initialize if DATE_FORMAT is not set in the system settings // Initialize if DATE_FORMAT is not set in the system settings
// This can happen after a factory reset (or data wipe) // This can happen after a factory reset (or data wipe)
if (currentFormat == null) { if (currentFormat == null) {
currentFormat = getResources().getString(R.string.default_date_format); currentFormat = "";
setDateFormat(currentFormat);
} }
for (int i = 0; i < formattedDates.length; i++) { for (int i = 0; i < formattedDates.length; i++) {
formattedDates[i] = DateFormat.format(dateFormats[i], mDummyDate).toString(); String formatted =
if (currentFormat.equals(dateFormats[i])) currentFormatIndex = i; DateFormat.getDateFormatForSetting(this, dateFormats[i]).
format(mDummyDate.getTime());
if (dateFormats[i].length() == 0) {
formattedDates[i] = getResources().
getString(R.string.normal_date_format, formatted);
} else {
formattedDates[i] = formatted;
}
} }
mDateFormat.setEntries(formattedDates); mDateFormat.setEntries(formattedDates);
@@ -314,6 +320,10 @@ public class DateTimeSettings
} }
private void setDateFormat(String format) { private void setDateFormat(String format) {
if (format.length() == 0) {
format = null;
}
Settings.System.putString(getContentResolver(), Settings.System.DATE_FORMAT, format); Settings.System.putString(getContentResolver(), Settings.System.DATE_FORMAT, format);
} }

View File

@@ -163,12 +163,12 @@ public class SecuritySettings extends PreferenceActivity {
PreferenceScreen vpnPreferences = getPreferenceManager() PreferenceScreen vpnPreferences = getPreferenceManager()
.createPreferenceScreen(this); .createPreferenceScreen(this);
vpnPreferences.setTitle(R.string.vpn_settings_category); vpnPreferences.setTitle(R.string.vpn_settings_title);
vpnPreferences.setSummary(R.string.vpn_settings_summary);
vpnPreferences.setIntent(new VpnManager(this).createSettingsActivityIntent()); vpnPreferences.setIntent(new VpnManager(this).createSettingsActivityIntent());
PreferenceCategory vpnCat = new PreferenceCategory(this); PreferenceCategory vpnCat = new PreferenceCategory(this);
vpnCat.setTitle(R.string.vpn_settings_title); vpnCat.setTitle(R.string.vpn_settings_category);
vpnCat.setSummary(R.string.vpn_settings_summary);
root.addPreference(vpnCat); root.addPreference(vpnCat);
vpnCat.addPreference(vpnPreferences); vpnCat.addPreference(vpnPreferences);

View File

@@ -51,8 +51,8 @@ public class PowerUsageDetail extends Activity implements Button.OnClickListener
public static final int ACTION_DISPLAY_SETTINGS = 1; public static final int ACTION_DISPLAY_SETTINGS = 1;
public static final int ACTION_WIFI_SETTINGS = 2; public static final int ACTION_WIFI_SETTINGS = 2;
public static final int ACTION_BLUETOOTH_SETTINGS = 3; public static final int ACTION_BLUETOOTH_SETTINGS = 3;
public static final int ACTION_FORCE_STOP = 4; public static final int ACTION_WIRELESS_SETTINGS = 4;
public static final int ACTION_UNINSTALL = 5; public static final int ACTION_APP_DETAILS = 6;
public static final int USAGE_SINCE_UNPLUGGED = 1; public static final int USAGE_SINCE_UNPLUGGED = 1;
public static final int USAGE_SINCE_RESET = 2; public static final int USAGE_SINCE_RESET = 2;
@@ -66,10 +66,6 @@ public class PowerUsageDetail extends Activity implements Button.OnClickListener
public static final String EXTRA_DETAIL_VALUES = "values"; public static final String EXTRA_DETAIL_VALUES = "values";
public static final String EXTRA_DRAIN_TYPE = "drainType"; public static final String EXTRA_DRAIN_TYPE = "drainType";
private static final int SECONDS_PER_MINUTE = 60;
private static final int SECONDS_PER_HOUR = 60 * 60;
private static final int SECONDS_PER_DAY = 24 * 60 * 60;
private static final boolean DEBUG = true; private static final boolean DEBUG = true;
private String mTitle; private String mTitle;
private double mPercentage; private double mPercentage;
@@ -135,10 +131,10 @@ public class PowerUsageDetail extends Activity implements Button.OnClickListener
switch (mTypes[i]) { switch (mTypes[i]) {
case R.string.usage_type_data_recv: case R.string.usage_type_data_recv:
case R.string.usage_type_data_send: case R.string.usage_type_data_send:
value = formatBytes(mValues[i]); value = Utils.formatBytes(this, mValues[i]);
break; break;
default: default:
value = formatTime(mValues[i]); value = Utils.formatElapsedTime(this, mValues[i]);
} }
ViewGroup item = (ViewGroup) inflater.inflate(R.layout.power_usage_detail_item_text, ViewGroup item = (ViewGroup) inflater.inflate(R.layout.power_usage_detail_item_text,
null); null);
@@ -165,15 +161,12 @@ public class PowerUsageDetail extends Activity implements Button.OnClickListener
startActivity(new Intent(Settings.ACTION_DISPLAY_SETTINGS)); startActivity(new Intent(Settings.ACTION_DISPLAY_SETTINGS));
break; break;
case ACTION_WIFI_SETTINGS: case ACTION_WIFI_SETTINGS:
startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS)); startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
break; break;
case ACTION_BLUETOOTH_SETTINGS: case ACTION_BLUETOOTH_SETTINGS:
startActivity(new Intent(Settings.ACTION_BLUETOOTH_SETTINGS)); startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
break; break;
case ACTION_FORCE_STOP: case ACTION_APP_DETAILS:
killProcesses();
break;
case ACTION_UNINSTALL:
Intent intent = new Intent(Intent.ACTION_VIEW); Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClass(this, InstalledAppDetails.class); intent.setClass(this, InstalledAppDetails.class);
intent.putExtra("com.android.settings.ApplicationPkgName", mPackages[0]); intent.putExtra("com.android.settings.ApplicationPkgName", mPackages[0]);
@@ -199,18 +192,17 @@ public class PowerUsageDetail extends Activity implements Button.OnClickListener
if (uid == 0 || !isSystem) { if (uid == 0 || !isSystem) {
switch (mDrainType) { switch (mDrainType) {
case APP: case APP:
label1 = getString(R.string.battery_action_stop); //label1 = getString(R.string.battery_action_stop);
label2 = getString(R.string.battery_action_app_details); label2 = getString(R.string.battery_action_app_details);
mAction1 = ACTION_FORCE_STOP; mAction2 = ACTION_APP_DETAILS;
mAction2 = ACTION_UNINSTALL;
break; break;
case SCREEN: case SCREEN:
//label2 = getString(R.string.battery_action_display); label2 = getString(R.string.battery_action_display);
//mAction2 = ACTION_DISPLAY_SETTINGS; mAction2 = ACTION_DISPLAY_SETTINGS;
break; break;
case WIFI: case WIFI:
label2 = getString(R.string.battery_action_wifi); label2 = getString(R.string.battery_action_wifi);
mAction2 = ACTION_WIFI_SETTINGS; mAction2 = ACTION_WIRELESS_SETTINGS;
break; break;
case BLUETOOTH: case BLUETOOTH:
//label2 = getString(R.string.battery_action_bluetooth); //label2 = getString(R.string.battery_action_bluetooth);
@@ -291,44 +283,4 @@ public class PowerUsageDetail extends Activity implements Button.OnClickListener
} }
} }
} }
private String formatTime(double millis) {
StringBuilder sb = new StringBuilder();
int seconds = (int) Math.floor(millis / 1000);
int days = 0, hours = 0, minutes = 0;
if (seconds > SECONDS_PER_DAY) {
days = seconds / SECONDS_PER_DAY;
seconds -= days * SECONDS_PER_DAY;
}
if (seconds > SECONDS_PER_HOUR) {
hours = seconds / SECONDS_PER_HOUR;
seconds -= hours * SECONDS_PER_HOUR;
}
if (seconds > SECONDS_PER_MINUTE) {
minutes = seconds / SECONDS_PER_MINUTE;
seconds -= minutes * SECONDS_PER_MINUTE;
}
if (days > 0) {
sb.append(getString(R.string.battery_history_days, days, hours, minutes, seconds));
} else if (hours > 0) {
sb.append(getString(R.string.battery_history_hours, hours, minutes, seconds));
} else if (minutes > 0) {
sb.append(getString(R.string.battery_history_minutes, minutes, seconds));
} else {
sb.append(getString(R.string.battery_history_seconds, seconds));
}
return sb.toString();
}
private String formatBytes(double bytes) {
// TODO: I18N
if (bytes > 1000 * 1000) {
return String.format("%.2f MB", ((int) (bytes / 1000)) / 1000f);
} else if (bytes > 1024) {
return String.format("%.2f KB", ((int) (bytes / 10)) / 100f);
} else {
return String.format("%d bytes", (int) bytes);
}
}
} }

View File

@@ -100,7 +100,7 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable {
addPreferencesFromResource(R.xml.power_usage_summary); addPreferencesFromResource(R.xml.power_usage_summary);
mBatteryInfo = IBatteryStats.Stub.asInterface( mBatteryInfo = IBatteryStats.Stub.asInterface(
ServiceManager.getService("batteryinfo")); ServiceManager.getService("batteryinfo"));
mAppListGroup = getPreferenceScreen(); mAppListGroup = (PreferenceGroup) findPreference("app_list");
mPowerProfile = new PowerProfile(this); mPowerProfile = new PowerProfile(this);
} }
@@ -108,7 +108,7 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable {
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
mAbort = false; mAbort = false;
updateAppsList(); refreshStats();
} }
@Override @Override
@@ -207,18 +207,18 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable {
} else { } else {
mStatsType = BatteryStats.STATS_TOTAL; mStatsType = BatteryStats.STATS_TOTAL;
} }
updateAppsList(); refreshStats();
return true; return true;
case MENU_STATS_REFRESH: case MENU_STATS_REFRESH:
mStats = null; mStats = null;
updateAppsList(); refreshStats();
return true; return true;
default: default:
return false; return false;
} }
} }
private void updateAppsList() { private void refreshStats() {
if (mStats == null) { if (mStats == null) {
load(); load();
} }
@@ -263,12 +263,19 @@ public class PowerUsageSummary extends PreferenceActivity implements Runnable {
} }
} }
private void updateStatsPeriod(long duration) {
String durationString = Utils.formatElapsedTime(this, duration / 1000);
String label = getString(R.string.battery_stats_duration, durationString);
mAppListGroup.setTitle(label);
}
private void processAppUsage() { private void processAppUsage() {
SensorManager sensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE); SensorManager sensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
final int which = mStatsType; final int which = mStatsType;
final double powerCpuNormal = mPowerProfile.getAveragePower(PowerProfile.POWER_CPU_NORMAL); final double powerCpuNormal = mPowerProfile.getAveragePower(PowerProfile.POWER_CPU_NORMAL);
final double averageCostPerByte = getAverageDataCost(); final double averageCostPerByte = getAverageDataCost();
long uSecTime = mStats.computeBatteryRealtime(SystemClock.elapsedRealtime(), which) * 1000; long uSecTime = mStats.computeBatteryRealtime(SystemClock.elapsedRealtime() * 1000, which);
updateStatsPeriod(uSecTime);
SparseArray<? extends Uid> uidStats = mStats.getUidStats(); SparseArray<? extends Uid> uidStats = mStats.getUidStats();
final int NU = uidStats.size(); final int NU = uidStats.size();
for (int iu = 0; iu < NU; iu++) { for (int iu = 0; iu < NU; iu++) {

View File

@@ -0,0 +1,84 @@
/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.fuelgauge;
import android.content.Context;
import com.android.settings.R;
/**
* Contains utility functions for formatting elapsed time and consumed bytes
*/
public class Utils {
private static final int SECONDS_PER_MINUTE = 60;
private static final int SECONDS_PER_HOUR = 60 * 60;
private static final int SECONDS_PER_DAY = 24 * 60 * 60;
/**
* Returns elapsed time for the given millis, in the following format:
* 2d 5h 40m 29s
* @param context the application context
* @param millis the elapsed time in milli seconds
* @return the formatted elapsed time
*/
public static String formatElapsedTime(Context context, double millis) {
StringBuilder sb = new StringBuilder();
int seconds = (int) Math.floor(millis / 1000);
int days = 0, hours = 0, minutes = 0;
if (seconds > SECONDS_PER_DAY) {
days = seconds / SECONDS_PER_DAY;
seconds -= days * SECONDS_PER_DAY;
}
if (seconds > SECONDS_PER_HOUR) {
hours = seconds / SECONDS_PER_HOUR;
seconds -= hours * SECONDS_PER_HOUR;
}
if (seconds > SECONDS_PER_MINUTE) {
minutes = seconds / SECONDS_PER_MINUTE;
seconds -= minutes * SECONDS_PER_MINUTE;
}
if (days > 0) {
sb.append(context.getString(R.string.battery_history_days,
days, hours, minutes, seconds));
} else if (hours > 0) {
sb.append(context.getString(R.string.battery_history_hours, hours, minutes, seconds));
} else if (minutes > 0) {
sb.append(context.getString(R.string.battery_history_minutes, minutes, seconds));
} else {
sb.append(context.getString(R.string.battery_history_seconds, seconds));
}
return sb.toString();
}
/**
* Formats data size in KB, MB, from the given bytes.
* @param context the application context
* @param bytes data size in bytes
* @return the formatted size such as 4.52 MB or 245 KB or 332 bytes
*/
public static String formatBytes(Context context, double bytes) {
// TODO: I18N
if (bytes > 1000 * 1000) {
return String.format("%.2f MB", ((int) (bytes / 1000)) / 1000f);
} else if (bytes > 1024) {
return String.format("%.2f KB", ((int) (bytes / 10)) / 100f);
} else {
return String.format("%d bytes", (int) bytes);
}
}
}

View File

@@ -58,8 +58,6 @@ class L2tpIpsecEditor extends SingleServerEditor {
String result = super.validate(c); String result = super.validate(c);
if (result != null) { if (result != null) {
return result; return result;
} else if (mProfile.isCustomized()) {
return null;
} else if (Util.isNullOrEmpty(mUserkey.getValue())) { } else if (Util.isNullOrEmpty(mUserkey.getValue())) {
return c.getString(R.string.vpn_error_userkey_not_selected); return c.getString(R.string.vpn_error_userkey_not_selected);
} else if (Util.isNullOrEmpty(mUserCertificate.getValue())) { } else if (Util.isNullOrEmpty(mUserCertificate.getValue())) {

View File

@@ -50,11 +50,9 @@ class SingleServerEditor implements VpnProfileEditor {
//@Override //@Override
public String validate(Context c) { public String validate(Context c) {
return (mProfile.isCustomized() return (Util.isNullOrEmpty(mServerName.getText())
? null
: (Util.isNullOrEmpty(mServerName.getText())
? c.getString(R.string.vpn_error_server_name_empty) ? c.getString(R.string.vpn_error_server_name_empty)
: null)); : null);
} }
/** /**