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

Commit e5a84b2e authored by John Spurlock's avatar John Spurlock
Browse files

Settings: Minimal refactor to support new dreams api.

Fix breaking changes to the dreams api.  Master toggle
and multiple dreams support in Settings will be done in
a subsequent change.

Bug:7028665
Change-Id: Ia56dd00ec50323fbba06473b1747e5015a3f1898
parent 395f5f70
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@

package com.android.settings;

import static android.provider.Settings.Secure.SCREENSAVER_COMPONENT;
import static android.provider.Settings.Secure.SCREENSAVER_COMPONENTS;

import android.app.AlertDialog;
import android.content.Context;
@@ -79,7 +79,9 @@ public class DreamComponentPreference extends Preference {
        IDreamManager dm = IDreamManager.Stub.asInterface(
                ServiceManager.getService("dreams"));
        try {
            cn = dm.getDreamComponent();
            ComponentName[] dreams = dm.getDreamComponents();
            if (dreams != null && dreams.length > 0)
                cn = dreams[0];
        } catch (RemoteException ex) { }

        if (cn == null) {
@@ -226,7 +228,8 @@ public class DreamComponentPreference extends Preference {
                        IDreamManager dm = IDreamManager.Stub.asInterface(
                                ServiceManager.getService("dreams"));
                        try {
                            dm.setDreamComponent(cn);
                            ComponentName[] dreams = { cn };
                            dm.setDreamComponents(dreams);
                        } catch (RemoteException ex) {
                            // too bad, so sad, oh mom, oh dad
                        }
+11 −3
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.settings;

import static android.provider.Settings.Secure.SCREENSAVER_ENABLED;
import static android.provider.Settings.Secure.SCREENSAVER_ACTIVATE_ON_DOCK;
import static android.provider.Settings.Secure.SCREENSAVER_ACTIVATE_ON_SLEEP;

import android.app.ActionBar;
import android.app.Activity;
@@ -53,7 +54,7 @@ public class DreamSettings extends SettingsPreferenceFragment {
    private static final String KEY_COMPONENT = "screensaver_component";
    private static final String KEY_TEST = "test";

    private static final int DEFAULT_SLEEP = 0;
    private static final int DEFAULT_SLEEP = 1;
    private static final int DEFAULT_DOCK = 1;

    private ActivationSetting mActivateOnSleep;
@@ -72,7 +73,7 @@ public class DreamSettings extends SettingsPreferenceFragment {
        mTestPref = findPreference(KEY_TEST);

        mActivateOnSleep = new ActivationSetting(getActivity(),
                SCREENSAVER_ENABLED, DEFAULT_SLEEP,
                SCREENSAVER_ACTIVATE_ON_SLEEP, DEFAULT_SLEEP,
                (CheckBoxPreference) findPreference(KEY_ACTIVATE_ON_SLEEP));
        mActivateOnDock = new ActivationSetting(getActivity(),
                SCREENSAVER_ACTIVATE_ON_DOCK, DEFAULT_DOCK,
@@ -81,7 +82,7 @@ public class DreamSettings extends SettingsPreferenceFragment {

    public static boolean isScreenSaverActivatedOnSleep(Context context) {
        return 0 != Settings.Secure.getInt(
                    context.getContentResolver(), SCREENSAVER_ENABLED, DEFAULT_SLEEP);
                    context.getContentResolver(), SCREENSAVER_ACTIVATE_ON_SLEEP, DEFAULT_SLEEP);
    }

    public static boolean isScreenSaverActivatedOnDock(Context context) {
@@ -101,6 +102,13 @@ public class DreamSettings extends SettingsPreferenceFragment {
    public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
        mActivateOnSleep.onClick(preference);
        mActivateOnDock.onClick(preference);

        // FIXME: infer enabled (until the next rev of the dream settings ui)
        boolean enabled = mActivateOnSleep.isSelected() || mActivateOnDock.isSelected();
        Settings.Secure.putInt(getActivity().getContentResolver(),
                SCREENSAVER_ENABLED,
                enabled ? 1 : 0);

        refreshDependents();
        return super.onPreferenceTreeClick(preferenceScreen, preference);
    }
+4 −1
Original line number Diff line number Diff line
@@ -36,7 +36,10 @@ public class DreamTesterPreference extends Preference {
    protected void onClick() {
        IDreamManager dm = IDreamManager.Stub.asInterface(ServiceManager.getService("dreams"));
        try {
            ComponentName cn = dm.getDreamComponent();
            ComponentName[] dreams = dm.getDreamComponents();
            if (dreams == null || dreams.length == 0)
                return;
            ComponentName cn = dreams[0];
            Log.v(TAG, "DreamComponent cn=" + cn);
            dm.testDream(cn);
        } catch (RemoteException ex) {