Merge "Use a different wallpaper fragment title from the preference item."

This commit is contained in:
Amith Yamasani
2011-07-27 10:56:23 -07:00
committed by Android (Google) Code Review
9 changed files with 98 additions and 53 deletions

View File

@@ -1542,6 +1542,8 @@
<string name="screen_timeout_summary">Screen turns off automatically after <xliff:g id="timeout_description">%1$s</xliff:g></string> <string name="screen_timeout_summary">Screen turns off automatically after <xliff:g id="timeout_description">%1$s</xliff:g></string>
<!-- Wallpaper settings title [CHAR LIMIT=30] --> <!-- Wallpaper settings title [CHAR LIMIT=30] -->
<string name="wallpaper_settings_title">Wallpaper</string> <string name="wallpaper_settings_title">Wallpaper</string>
<!-- Wallpaper settings fragment title [CHAR LIMIT=30] -->
<string name="wallpaper_settings_fragment_title">Select wallpaper from</string>
<!-- Display settings screen, trigger for screen saver options --> <!-- Display settings screen, trigger for screen saver options -->
<string name="dream_settings_title">Android Dreams</string> <string name="dream_settings_title">Android Dreams</string>
<!-- Display settings screen, summary for screen saver options --> <!-- Display settings screen, summary for screen saver options -->
@@ -2739,6 +2741,8 @@ found in the list of installed applications.</string>
<string name="power_usage_summary">What has been using the battery</string> <string name="power_usage_summary">What has been using the battery</string>
<!-- Message to show when battery usage data is not available [CHAR LIMIT=30] --> <!-- Message to show when battery usage data is not available [CHAR LIMIT=30] -->
<string name="power_usage_not_available">Battery usage data not available</string> <string name="power_usage_not_available">Battery usage data not available</string>
<!-- Display the battery level and status [CHAR_LIMIT=30] -->
<string name="power_usage_level_and_status">Battery level <xliff:g id="level">%1$s</xliff:g> - <xliff:g id="status">%2$s</xliff:g></string>
<!-- Battery usage since unplugged --> <!-- Battery usage since unplugged -->
<string name="battery_since_unplugged">Battery use since unplugged</string> <string name="battery_since_unplugged">Battery use since unplugged</string>
<!-- Battery usage since user reset the stats --> <!-- Battery usage since user reset the stats -->

View File

@@ -17,4 +17,9 @@
<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"
android:key="app_list"> android:key="app_list">
<Preference
style="?android:attr/preferenceInformationStyle"
android:key="battery_status"
android:persistent="false"
/>
</PreferenceScreen> </PreferenceScreen>

View File

@@ -15,6 +15,6 @@
--> -->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/wallpaper_settings_title"> android:title="@string/wallpaper_settings_fragment_title">
</PreferenceScreen> </PreferenceScreen>

View File

@@ -90,26 +90,7 @@ public class BatteryInfo extends Activity {
+ getString(R.string.battery_info_temperature_units)); + getString(R.string.battery_info_temperature_units));
mTechnology.setText("" + intent.getStringExtra("technology")); mTechnology.setText("" + intent.getStringExtra("technology"));
int status = intent.getIntExtra("status", BatteryManager.BATTERY_STATUS_UNKNOWN); mStatus.setText(Utils.getBatteryStatus(getResources(), intent));
String statusString;
if (status == BatteryManager.BATTERY_STATUS_CHARGING) {
statusString = getString(R.string.battery_info_status_charging);
if (plugType > 0) {
statusString = statusString + " " + getString(
(plugType == BatteryManager.BATTERY_PLUGGED_AC)
? R.string.battery_info_status_charging_ac
: R.string.battery_info_status_charging_usb);
}
} else if (status == BatteryManager.BATTERY_STATUS_DISCHARGING) {
statusString = getString(R.string.battery_info_status_discharging);
} else if (status == BatteryManager.BATTERY_STATUS_NOT_CHARGING) {
statusString = getString(R.string.battery_info_status_not_charging);
} else if (status == BatteryManager.BATTERY_STATUS_FULL) {
statusString = getString(R.string.battery_info_status_full);
} else {
statusString = getString(R.string.battery_info_status_unknown);
}
mStatus.setText(statusString);
switch (plugType) { switch (plugType) {
case 0: case 0:

View File

@@ -28,7 +28,9 @@ import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle; import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity; import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@@ -534,6 +536,17 @@ public class Settings extends PreferenceActivity implements ButtonBarHandler {
} }
} }
@Override
public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
// Override the fragment title for Wallpaper settings
CharSequence title = pref.getTitle();
if (pref.getFragment().equals(WallpaperTypeSettings.class.getName())) {
title = getString(R.string.wallpaper_settings_fragment_title);
}
startPreferencePanel(pref.getFragment(), pref.getExtras(), 0, title, null, 0);
return true;
}
@Override @Override
public void setListAdapter(ListAdapter adapter) { public void setListAdapter(ListAdapter adapter) {
if (mHeaders == null) { if (mHeaders == null) {

View File

@@ -27,6 +27,7 @@ import android.content.res.Resources.NotFoundException;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import android.net.LinkProperties; import android.net.LinkProperties;
import android.os.BatteryManager;
import android.os.Bundle; import android.os.Bundle;
import android.os.SystemProperties; import android.os.SystemProperties;
import android.preference.Preference; import android.preference.Preference;
@@ -330,4 +331,38 @@ public class Utils {
return new Locale(brokenDownLocale[0], brokenDownLocale[1], brokenDownLocale[2]); return new Locale(brokenDownLocale[0], brokenDownLocale[1], brokenDownLocale[2]);
} }
} }
public static String getBatteryPercentage(Intent batteryChangedIntent) {
int level = batteryChangedIntent.getIntExtra("level", 0);
int scale = batteryChangedIntent.getIntExtra("scale", 100);
return String.valueOf(level * 100 / scale) + "%";
}
public static String getBatteryStatus(Resources res, Intent batteryChangedIntent) {
final Intent intent = batteryChangedIntent;
int plugType = intent.getIntExtra("plugged", 0);
int status = intent.getIntExtra("status", BatteryManager.BATTERY_STATUS_UNKNOWN);
String statusString;
if (status == BatteryManager.BATTERY_STATUS_CHARGING) {
statusString = res.getString(R.string.battery_info_status_charging);
if (plugType > 0) {
statusString = statusString
+ " "
+ res.getString((plugType == BatteryManager.BATTERY_PLUGGED_AC)
? R.string.battery_info_status_charging_ac
: R.string.battery_info_status_charging_usb);
}
} 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;
}
} }

View File

@@ -16,13 +16,14 @@
package com.android.settings; package com.android.settings;
import android.app.Activity;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.os.Bundle;
import android.preference.Preference; import android.preference.Preference;
import android.preference.PreferenceScreen;
import java.util.List; import java.util.List;
@@ -32,7 +33,6 @@ public class WallpaperTypeSettings extends SettingsPreferenceFragment {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.wallpaper_settings); addPreferencesFromResource(R.xml.wallpaper_settings);
populateWallpaperTypes(); populateWallpaperTypes();
} }
@@ -43,6 +43,8 @@ public class WallpaperTypeSettings extends SettingsPreferenceFragment {
List<ResolveInfo> rList = pm.queryIntentActivities(intent, List<ResolveInfo> rList = pm.queryIntentActivities(intent,
PackageManager.MATCH_DEFAULT_ONLY); PackageManager.MATCH_DEFAULT_ONLY);
final PreferenceScreen parent = getPreferenceScreen();
parent.setOrderingAsAdded(false);
// Add Preference items for each of the matching activities // Add Preference items for each of the matching activities
for (ResolveInfo info : rList) { for (ResolveInfo info : rList) {
Preference pref = new Preference(getActivity()); Preference pref = new Preference(getActivity());
@@ -53,7 +55,7 @@ public class WallpaperTypeSettings extends SettingsPreferenceFragment {
CharSequence label = info.loadLabel(pm); CharSequence label = info.loadLabel(pm);
if (label == null) label = info.activityInfo.packageName; if (label == null) label = info.activityInfo.packageName;
pref.setTitle(label); pref.setTitle(label);
getPreferenceScreen().addPreference(pref); parent.addPreference(pref);
} }
} }
} }

View File

@@ -157,33 +157,8 @@ public class Status extends PreferenceActivity {
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
String action = intent.getAction(); String action = intent.getAction();
if (Intent.ACTION_BATTERY_CHANGED.equals(action)) { if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
mBatteryLevel.setSummary(Utils.getBatteryPercentage(intent));
int level = intent.getIntExtra("level", 0); mBatteryStatus.setSummary(Utils.getBatteryStatus(getResources(), intent));
int scale = intent.getIntExtra("scale", 100);
mBatteryLevel.setSummary(String.valueOf(level * 100 / scale) + "%");
int plugType = intent.getIntExtra("plugged", 0);
int status = intent.getIntExtra("status", BatteryManager.BATTERY_STATUS_UNKNOWN);
String statusString;
if (status == BatteryManager.BATTERY_STATUS_CHARGING) {
statusString = getString(R.string.battery_info_status_charging);
if (plugType > 0) {
statusString = statusString + " " + getString(
(plugType == BatteryManager.BATTERY_PLUGGED_AC)
? R.string.battery_info_status_charging_ac
: R.string.battery_info_status_charging_usb);
}
} else if (status == BatteryManager.BATTERY_STATUS_DISCHARGING) {
statusString = getString(R.string.battery_info_status_discharging);
} else if (status == BatteryManager.BATTERY_STATUS_NOT_CHARGING) {
statusString = getString(R.string.battery_info_status_not_charging);
} else if (status == BatteryManager.BATTERY_STATUS_FULL) {
statusString = getString(R.string.battery_info_status_full);
} else {
statusString = getString(R.string.battery_info_status_unknown);
}
mBatteryStatus.setSummary(statusString);
} }
} }
}; };

View File

@@ -16,10 +16,14 @@
package com.android.settings.fuelgauge; package com.android.settings.fuelgauge;
import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.hardware.SensorManager; import android.hardware.SensorManager;
import android.os.BatteryStats; import android.os.BatteryStats;
import android.os.BatteryStats.Uid; import android.os.BatteryStats.Uid;
import android.os.BatteryManager;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
@@ -64,6 +68,9 @@ public class PowerUsageSummary extends PreferenceFragment implements Runnable {
private static final String TAG = "PowerUsageSummary"; private static final String TAG = "PowerUsageSummary";
private static final String KEY_APP_LIST = "app_list";
private static final String KEY_BATTERY_STATUS = "battery_status";
private static final int MENU_STATS_TYPE = Menu.FIRST; private static final int MENU_STATS_TYPE = Menu.FIRST;
private static final int MENU_STATS_REFRESH = Menu.FIRST + 1; private static final int MENU_STATS_REFRESH = Menu.FIRST + 1;
@@ -76,6 +83,7 @@ public class PowerUsageSummary extends PreferenceFragment implements Runnable {
private final List<BatterySipper> mBluetoothSippers = new ArrayList<BatterySipper>(); private final List<BatterySipper> mBluetoothSippers = new ArrayList<BatterySipper>();
private PreferenceGroup mAppListGroup; private PreferenceGroup mAppListGroup;
private Preference mBatteryStatusPref;
private int mStatsType = BatteryStats.STATS_SINCE_CHARGED; private int mStatsType = BatteryStats.STATS_SINCE_CHARGED;
@@ -96,7 +104,23 @@ public class PowerUsageSummary extends PreferenceFragment implements Runnable {
private ArrayList<BatterySipper> mRequestQueue = new ArrayList<BatterySipper>(); private ArrayList<BatterySipper> mRequestQueue = new ArrayList<BatterySipper>();
private Thread mRequestThread; private Thread mRequestThread;
private boolean mAbort; private boolean mAbort;
private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
String batteryLevel = com.android.settings.Utils.getBatteryPercentage(intent);
String batteryStatus = com.android.settings.Utils.getBatteryStatus(getResources(),
intent);
String batterySummary = context.getResources().getString(
R.string.power_usage_level_and_status, batteryLevel, batteryStatus);
mBatteryStatusPref.setTitle(batterySummary);
}
}
};
@Override @Override
public void onCreate(Bundle icicle) { public void onCreate(Bundle icicle) {
super.onCreate(icicle); super.onCreate(icicle);
@@ -108,7 +132,8 @@ public class PowerUsageSummary extends PreferenceFragment 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 = (PreferenceGroup) findPreference("app_list"); mAppListGroup = (PreferenceGroup) findPreference(KEY_APP_LIST);
mBatteryStatusPref = mAppListGroup.findPreference(KEY_BATTERY_STATUS);
mPowerProfile = new PowerProfile(getActivity()); mPowerProfile = new PowerProfile(getActivity());
setHasOptionsMenu(true); setHasOptionsMenu(true);
} }
@@ -117,6 +142,8 @@ public class PowerUsageSummary extends PreferenceFragment implements Runnable {
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
mAbort = false; mAbort = false;
getActivity().registerReceiver(mBatteryInfoReceiver,
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
refreshStats(); refreshStats();
} }
@@ -126,6 +153,7 @@ public class PowerUsageSummary extends PreferenceFragment implements Runnable {
mAbort = true; mAbort = true;
} }
mHandler.removeMessages(MSG_UPDATE_NAME_ICON); mHandler.removeMessages(MSG_UPDATE_NAME_ICON);
getActivity().unregisterReceiver(mBatteryInfoReceiver);
super.onPause(); super.onPause();
} }
@@ -335,6 +363,8 @@ public class PowerUsageSummary extends PreferenceFragment implements Runnable {
mBluetoothSippers.clear(); mBluetoothSippers.clear();
mAppListGroup.setOrderingAsAdded(false); mAppListGroup.setOrderingAsAdded(false);
mBatteryStatusPref.setOrder(-2);
mAppListGroup.addPreference(mBatteryStatusPref);
BatteryHistoryPreference hist = new BatteryHistoryPreference(getActivity(), mStats); BatteryHistoryPreference hist = new BatteryHistoryPreference(getActivity(), mStats);
hist.setOrder(-1); hist.setOrder(-1);
mAppListGroup.addPreference(hist); mAppListGroup.addPreference(hist);