Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 08a4c33a authored by Lifu Tang's avatar Lifu Tang
Browse files

Minor UI tweakings

* Changed PreferenceScreen to Preference.

* Adjusted the "No recent app" message layout.

* No "Location services" category when empty.

* Removed "Under Construction" finally, hooray!

Change-Id: I83fd1d7a1b0235ad21b3a5c54542e937b60b3940
parent 25518c3b
Loading
Loading
Loading
Loading
+47 −0
Original line number Diff line number Diff line
<?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>
+2 −2
Original line number Diff line number Diff line
@@ -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-->
+1 −4
Original line number Diff line number Diff line
@@ -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" />
+20 −17
Original line number Diff line number Diff line
@@ -52,9 +52,7 @@ public class LocationSettings extends LocationSettingsBase

    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 @@ public class LocationSettings extends LocationSettingsBase
        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,26 +138,32 @@ public class LocationSettings extends LocationSettingsBase

        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);
        }

        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);
        }

        mLocationServices = (PreferenceCategory) root.findPreference(KEY_LOCATION_SERVICES);
        List<Preference> locationServices = SettingsInjector.getInjectedSettings(
                activity, preferenceManager);
        addPreferencesSorted(locationServices, mLocationServices);

        // Only show the master switch when we're not in multi-pane mode, and not being used as
        // Setup Wizard.
        if (activity.onIsHidingHeaders() || !activity.onIsMultiPane()) {
@@ -206,7 +210,6 @@ public class LocationSettings extends LocationSettingsBase

        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()
+21 −28
Original line number Diff line number Diff line
@@ -24,8 +24,6 @@ import android.graphics.drawable.Drawable;
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 @@ public class RecentLocationApps {
        }
    }

    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 @@ public class RecentLocationApps {
     * 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 @@ public class RecentLocationApps {
        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 @@ public class RecentLocationApps {
    }

    /**
     * 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 @@ public class RecentLocationApps {

        // 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 @@ public class RecentLocationApps {
            if (!wrapper.used()) {
                BatterySipper sipper = wrapper.batterySipper();
                sipper.loadNameAndIcon();
                screen = createRecentLocationEntry(
                        preferenceManager,
                pref = createRecentLocationEntry(
                        sipper.getIcon(),
                        sipper.getLabel(),
                        highBattery,
@@ -249,8 +243,7 @@ public class RecentLocationApps {
            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 @@ public class RecentLocationApps {
            }
        }

        return screen;
        return pref;
    }
}
Loading