Merge "Minor UI tweakings" into klp-dev
diff --git a/res/layout/location_list_no_item.xml b/res/layout/location_list_no_item.xml
new file mode 100644
index 0000000..864b2e4
--- /dev/null
+++ b/res/layout/location_list_no_item.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2013 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.
+-->
+
+<!-- text that appears when the recent app list is empty -->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:minHeight="?android:attr/listPreferredItemHeight"
+ android:gravity="center_vertical"
+ android:paddingEnd="?android:attr/scrollbarSize"
+ android:background="?android:attr/selectableItemBackground" >
+
+ <RelativeLayout
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_marginStart="15dip"
+ android:layout_marginEnd="6dip"
+ android:layout_marginTop="6dip"
+ android:layout_marginBottom="6dip"
+ android:layout_weight="1">
+
+ <TextView android:id="@+android:id/title"
+ android:gravity="center"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:singleLine="true"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:ellipsize="marquee"
+ android:fadingEdge="horizontal" />
+
+ </RelativeLayout>
+
+</LinearLayout>
+
diff --git a/res/values/strings.xml b/res/values/strings.xml
index b49d929..71cedef 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2377,8 +2377,8 @@
<string name="location_mode_location_off_title">Location off</string>
<!-- [CHAR LIMIT=30] Location settings screen, sub category for recent location requests -->
<string name="location_category_recent_location_requests">Recent location requests</string>
- <!-- [CHAR LIMIT=30] Location settings screen, displayed when there's no recent app accessing location -->
- <string name="location_no_recent_apps">No recent apps</string>
+ <!-- Location settings screen, displayed when there's no recent app accessing location -->
+ <string name="location_no_recent_apps">No apps have requested location in the last 15 minutes.</string>
<!-- [CHAR LIMIT=30] Location settings screen, sub category for location services -->
<string name="location_category_location_services">Location services</string>
<!-- [CHAR LIMIT=30] Location settings screen, recent location requests high battery use-->
diff --git a/res/xml/location_settings.xml b/res/xml/location_settings.xml
index e646cab..83b80b1 100644
--- a/res/xml/location_settings.xml
+++ b/res/xml/location_settings.xml
@@ -16,10 +16,7 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/location_settings_title">
- <PreferenceScreen
- android:title="Under Construction"
- android:summary="This page is under construction and everything here is expected to be broken for a while. Keep calm and carry on!" />
- <PreferenceScreen
+ <Preference
android:key="location_mode"
android:title="@string/location_mode_title"
android:summary="@string/location_mode_location_off_title" />
diff --git a/src/com/android/settings/location/LocationSettings.java b/src/com/android/settings/location/LocationSettings.java
index 4970d37..4e54107 100644
--- a/src/com/android/settings/location/LocationSettings.java
+++ b/src/com/android/settings/location/LocationSettings.java
@@ -52,9 +52,7 @@
private Switch mSwitch;
private boolean mValidListener;
- private PreferenceScreen mLocationMode;
- private PreferenceCategory mRecentLocationRequests;
- private PreferenceCategory mLocationServices;
+ private Preference mLocationMode;
private BatteryStatsHelper mStatsHelper;
@@ -125,7 +123,7 @@
addPreferencesFromResource(R.xml.location_settings);
root = getPreferenceScreen();
- mLocationMode = (PreferenceScreen) root.findPreference(KEY_LOCATION_MODE);
+ mLocationMode = root.findPreference(KEY_LOCATION_MODE);
mLocationMode.setOnPreferenceClickListener(
new Preference.OnPreferenceClickListener() {
@Override
@@ -140,25 +138,31 @@
final PreferenceManager preferenceManager = getPreferenceManager();
- mRecentLocationRequests =
+ PreferenceCategory categoryRecentLocationRequests =
(PreferenceCategory) root.findPreference(KEY_RECENT_LOCATION_REQUESTS);
RecentLocationApps recentApps = new RecentLocationApps(activity, mStatsHelper);
- List<Preference> recentLocationRequests = recentApps.getAppList(preferenceManager);
+ List<Preference> recentLocationRequests = recentApps.getAppList();
if (recentLocationRequests.size() > 0) {
- addPreferencesSorted(recentLocationRequests, mRecentLocationRequests);
+ addPreferencesSorted(recentLocationRequests, categoryRecentLocationRequests);
} else {
// If there's no item to display, add a "No recent apps" item.
- PreferenceScreen screen = preferenceManager.createPreferenceScreen(activity);
- screen.setTitle(R.string.location_no_recent_apps);
- screen.setSelectable(false);
- screen.setEnabled(false);
- mRecentLocationRequests.addPreference(screen);
+ Preference banner = new Preference(activity);
+ banner.setLayoutResource(R.layout.location_list_no_item);
+ banner.setTitle(R.string.location_no_recent_apps);
+ banner.setSelectable(false);
+ banner.setEnabled(false);
+ categoryRecentLocationRequests.addPreference(banner);
}
- mLocationServices = (PreferenceCategory) root.findPreference(KEY_LOCATION_SERVICES);
- List<Preference> locationServices = SettingsInjector.getInjectedSettings(
- activity, preferenceManager);
- addPreferencesSorted(locationServices, mLocationServices);
+ PreferenceCategory categoryLocationServices =
+ (PreferenceCategory) root.findPreference(KEY_LOCATION_SERVICES);
+ List<Preference> locationServices = SettingsInjector.getInjectedSettings(activity);
+ if (locationServices.size() > 0) {
+ addPreferencesSorted(locationServices, categoryLocationServices);
+ } else {
+ // If there's no item to display, remove the whole category.
+ root.removePreference(categoryLocationServices);
+ }
// Only show the master switch when we're not in multi-pane mode, and not being used as
// Setup Wizard.
@@ -206,7 +210,6 @@
boolean enabled = (mode != Settings.Secure.LOCATION_MODE_OFF);
mLocationMode.setEnabled(enabled);
- mLocationServices.setEnabled(enabled);
if (enabled != mSwitch.isChecked()) {
// set listener to null so that that code below doesn't trigger onCheckedChanged()
diff --git a/src/com/android/settings/location/RecentLocationApps.java b/src/com/android/settings/location/RecentLocationApps.java
index cbf8351..23e6dcf 100644
--- a/src/com/android/settings/location/RecentLocationApps.java
+++ b/src/com/android/settings/location/RecentLocationApps.java
@@ -24,8 +24,6 @@
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
-import android.preference.PreferenceManager;
-import android.preference.PreferenceScreen;
import android.util.Log;
import com.android.settings.R;
@@ -93,22 +91,21 @@
}
}
- private PreferenceScreen createRecentLocationEntry(
- PreferenceManager preferenceManager,
+ private Preference createRecentLocationEntry(
Drawable icon,
CharSequence label,
boolean isHighBattery,
Preference.OnPreferenceClickListener listener) {
- PreferenceScreen screen = preferenceManager.createPreferenceScreen(mActivity);
- screen.setIcon(icon);
- screen.setTitle(label);
+ Preference pref = new Preference(mActivity);
+ pref.setIcon(icon);
+ pref.setTitle(label);
if (isHighBattery) {
- screen.setSummary(R.string.location_high_battery_use);
+ pref.setSummary(R.string.location_high_battery_use);
} else {
- screen.setSummary(R.string.location_low_battery_use);
+ pref.setSummary(R.string.location_low_battery_use);
}
- screen.setOnPreferenceClickListener(listener);
- return screen;
+ pref.setOnPreferenceClickListener(listener);
+ return pref;
}
/**
@@ -140,7 +137,7 @@
* Fills a list of applications which queried location recently within
* specified time.
*/
- public List<Preference> getAppList(PreferenceManager preferenceManager) {
+ public List<Preference> getAppList() {
// Retrieve Uid-based battery blaming info and generate a package to BatterySipper HashMap
// for later faster looking up.
mStatsHelper.refreshStats();
@@ -169,9 +166,9 @@
long now = System.currentTimeMillis();
for (AppOpsManager.PackageOps ops : appOps) {
BatterySipperWrapper wrapper = sipperMap.get(ops.getUid());
- PreferenceScreen screen = getScreenFromOps(preferenceManager, now, ops, wrapper);
- if (screen != null) {
- prefs.add(screen);
+ Preference pref = getPreferenceFromOps(now, ops, wrapper);
+ if (pref != null) {
+ prefs.add(pref);
}
}
@@ -179,19 +176,17 @@
}
/**
- * Creates a PreferenceScreen entry for the given PackageOps.
+ * Creates a Preference entry for the given PackageOps.
*
* This method examines the time interval of the PackageOps first. If the PackageOps is older
* than the designated interval, this method ignores the PackageOps object and returns null.
*
* When the PackageOps is fresh enough, if the package has a corresponding battery blaming entry
- * in the Uid-based battery sipper list, this method returns a PreferenceScreen pointing to the
- * Uid battery blaming page. If the package doesn't have a battery sipper entry (typically
- * shouldn't happen), this method returns a PreferenceScreen pointing to the App Info page for
- * that package.
+ * in the Uid-based battery sipper list, this method returns a Preference pointing to the Uid
+ * battery blaming page. If the package doesn't have a battery sipper entry (typically shouldn't
+ * happen), this method returns a Preference pointing to the App Info page for that package.
*/
- private PreferenceScreen getScreenFromOps(
- PreferenceManager preferenceManager,
+ private Preference getPreferenceFromOps(
long now,
AppOpsManager.PackageOps ops,
BatterySipperWrapper wrapper) {
@@ -224,7 +219,7 @@
// The package is fresh enough, continue.
- PreferenceScreen screen = null;
+ Preference pref = null;
if (wrapper != null) {
// Contains sipper. Link to Battery Blaming page.
@@ -233,8 +228,7 @@
if (!wrapper.used()) {
BatterySipper sipper = wrapper.batterySipper();
sipper.loadNameAndIcon();
- screen = createRecentLocationEntry(
- preferenceManager,
+ pref = createRecentLocationEntry(
sipper.getIcon(),
sipper.getLabel(),
highBattery,
@@ -249,8 +243,7 @@
try {
ApplicationInfo appInfo = mPackageManager.getApplicationInfo(
packageName, PackageManager.GET_META_DATA);
- screen = createRecentLocationEntry(
- preferenceManager,
+ pref = createRecentLocationEntry(
mPackageManager.getApplicationIcon(appInfo),
mPackageManager.getApplicationLabel(appInfo),
highBattery,
@@ -260,6 +253,6 @@
}
}
- return screen;
+ return pref;
}
}
diff --git a/src/com/android/settings/location/SettingsInjector.java b/src/com/android/settings/location/SettingsInjector.java
index 0b7c172..41cd869 100644
--- a/src/com/android/settings/location/SettingsInjector.java
+++ b/src/com/android/settings/location/SettingsInjector.java
@@ -31,8 +31,6 @@
import android.os.Message;
import android.os.Messenger;
import android.preference.Preference;
-import android.preference.PreferenceManager;
-import android.preference.PreferenceScreen;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
@@ -240,14 +238,13 @@
* TODO: extract InjectedLocationSettingGetter that returns an iterable over
* InjectedSetting objects, so that this class can focus on UI
*/
- public static List<Preference> getInjectedSettings(Context context,
- PreferenceManager preferenceManager) {
+ public static List<Preference> getInjectedSettings(Context context) {
Iterable<InjectedSetting> settings = getSettings(context);
ArrayList<Preference> prefs = new ArrayList<Preference>();
StatusLoader loader = null;
for (InjectedSetting setting : settings) {
- Preference pref = addServiceSetting(context, prefs, setting, preferenceManager);
+ Preference pref = addServiceSetting(context, prefs, setting);
Intent intent = createUpdatingIntent(context, pref, setting, loader);
loader = new StatusLoader(context, intent, loader);
}
@@ -263,22 +260,21 @@
/**
* Adds an injected setting to the root with status "Loading...".
*/
- private static PreferenceScreen addServiceSetting(Context context,
- List<Preference> prefs, InjectedSetting info, PreferenceManager preferenceManager) {
-
- PreferenceScreen screen = preferenceManager.createPreferenceScreen(context);
- screen.setTitle(info.title);
- screen.setSummary(R.string.location_loading_injected_setting);
+ private static Preference addServiceSetting(
+ Context context, List<Preference> prefs, InjectedSetting info) {
+ Preference pref = new Preference(context);
+ pref.setTitle(info.title);
+ pref.setSummary(R.string.location_loading_injected_setting);
PackageManager pm = context.getPackageManager();
Drawable icon = pm.getDrawable(info.packageName, info.iconId, null);
- screen.setIcon(icon);
+ pref.setIcon(icon);
Intent settingIntent = new Intent();
settingIntent.setClassName(info.packageName, info.settingsActivity);
- screen.setIntent(settingIntent);
+ pref.setIntent(settingIntent);
- prefs.add(screen);
- return screen;
+ prefs.add(pref);
+ return pref;
}
/**