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

Commit c825bc8e authored by Daniel Sandler's avatar Daniel Sandler
Browse files

More descriptive summary for "Sleep Mode" pref.

It will either show "Off" or the name of the selected dream.

Also, move "When to sleep" out onto the visible part of the
action bar if there's room, making it much easier to discover.

Bug: 7320701
Change-Id: I1d4e2c17b764b8ee054dbb17c23f559d735e3450
parent 8e3f8d3a
Loading
Loading
Loading
Loading
+4 −5
Original line number Diff line number Diff line
@@ -284,11 +284,10 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
    }

    private void updateScreenSaverSummary() {
        int summaryResId = DreamSettings.getSummaryResource(getActivity());
        if (summaryResId > 0)
            mScreenSaverPreference.setSummary(summaryResId);
        else
            mScreenSaverPreference.setSummary("");
        if (mScreenSaverPreference != null) {
            mScreenSaverPreference.setSummary(
                    DreamSettings.getSummaryTextWithDreamName(getActivity()));
        }
    }

    private void updateWifiDisplaySummary() {
+17 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ServiceInfo;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
@@ -116,6 +117,22 @@ public class DreamBackend {
        }
    }

    public CharSequence getActiveDreamName() {
        ComponentName cn = getActiveDream();
        if (cn != null) {
            PackageManager pm = mContext.getPackageManager();
            try {
                ServiceInfo ri = pm.getServiceInfo(cn, 0);
                if (ri != null) {
                    return ri.loadLabel(pm);
                }
            } catch (PackageManager.NameNotFoundException exc) {
                return null; // uninstalled?
            }
        }
        return null;
    }

    public boolean isEnabled() {
        return getBoolean(SCREENSAVER_ENABLED);
    }
+12 −2
Original line number Diff line number Diff line
@@ -149,7 +149,7 @@ public class DreamSettings extends SettingsPreferenceFragment {
        // create "when to dream" overflow menu item
        MenuItem whenToDream = createMenuItem(menu,
                R.string.screensaver_settings_when_to_dream,
                MenuItem.SHOW_AS_ACTION_NEVER,
                MenuItem.SHOW_AS_ACTION_IF_ROOM,
                isEnabled,
                new Runnable() {
                    @Override
@@ -245,6 +245,16 @@ public class DreamSettings extends SettingsPreferenceFragment {
                : 0;
    }

    public static CharSequence getSummaryTextWithDreamName(Context context) {
        DreamBackend backend = new DreamBackend(context);
        boolean isEnabled = backend.isEnabled();
        if (!isEnabled) {
            return context.getString(R.string.screensaver_settings_summary_off);
        } else {
            return backend.getActiveDreamName();
        }
    }

    private void refreshFromBackend() {
        logd("refreshFromBackend()");
        mRefreshing = true;
@@ -306,7 +316,7 @@ public class DreamSettings extends SettingsPreferenceFragment {

            ImageView settingsButton = (ImageView) row.findViewById(android.R.id.button2);
            settingsButton.setVisibility(showSettings ? View.VISIBLE : View.INVISIBLE);
            settingsButton.setAlpha(dreamInfo.isActive ? 1f : 0.7f);
            settingsButton.setAlpha(dreamInfo.isActive ? 1f : 0.33f);
            settingsButton.setEnabled(dreamInfo.isActive);
            settingsButton.setOnClickListener(new OnClickListener(){
                @Override