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

Commit 3bc3238c authored by Danny Baumann's avatar Danny Baumann
Browse files

Remove SystemSettingSwitchPreference.

We should not introduce one-off UI patterns when there are plenty of
examples where the same usage pattern (a feature on its own
PreferenceScreen with a global enable switch in the action bar) is
handled differently everywhere else (e.g. daydream, cast display,
blacklist). This makes for inconsistent UX.
Also, there are discoverability issues: As there's no other case of a
preference with an embedded control widget opening another preference
screen, users won't expect to find another screen behind it.
Additionally - but entirely subjective - the control looks plain ugly,
as the preference padding is too large for the large switch.

Change-Id: I61284e961babefa3748102b05055fb1d03b079b0
parent ee1d08fd
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -318,8 +318,8 @@

    <!-- Heads Up -->
    <string name="category_heads_up">Heads up</string>
    <string name="summary_heads_up">Pop-up notifications</string>
    <string name="title_heads_up_enabled">Enable heads up</string>
    <string name="summary_heads_up_enabled">Pop-up notifications are enabled</string>
    <string name="summary_heads_up_disabled">Pop-up notifications are disabled</string>
    <string name="add_heads_up_package">Add app</string>
    <string name="add_heads_up_dnd_summary">Don\'t show heads up in these applications</string>
    <string name="add_heads_up_blacklist_summary">Don\'t show heads up from these applications</string>
+2 −3
Original line number Diff line number Diff line
@@ -31,11 +31,10 @@
            android:fragment="com.android.settings.quicksettings.QuickSettings"
            android:title="@string/quick_settings_panel_title" />

    <com.android.settings.cyanogenmod.SystemSettingSwitchPreference
    <Preference
            android:key="heads_up_enabled"
            android:fragment="com.android.settings.headsup.HeadsUpSettings"
            android:title="@string/category_heads_up"
            android:summary="@string/summary_heads_up" />
            android:title="@string/category_heads_up" />

    <PreferenceCategory
        android:title="@string/category_quick_access" >
+7 −10
Original line number Diff line number Diff line
@@ -26,8 +26,6 @@ import android.provider.Settings;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;

import com.android.settings.cyanogenmod.SystemSettingSwitchPreference;

public class NotificationDrawer extends SettingsPreferenceFragment implements
        Preference.OnPreferenceChangeListener {
    private static final String TAG = "NotificationDrawer";
@@ -35,17 +33,15 @@ public class NotificationDrawer extends SettingsPreferenceFragment implements
    private static final String UI_COLLAPSE_BEHAVIOUR = "notification_drawer_collapse_on_dismiss";

    private ListPreference mCollapseOnDismiss;
    private SystemSettingSwitchPreference mSwitchPreference;
    private Preference mHeadsUp;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        addPreferencesFromResource(R.xml.notification_drawer);
        PreferenceScreen prefScreen = getPreferenceScreen();

        mSwitchPreference = (SystemSettingSwitchPreference)
                findPreference(Settings.System.HEADS_UP_NOTIFICATION);
        mHeadsUp = findPreference(Settings.System.HEADS_UP_NOTIFICATION);

        // Notification drawer
        int collapseBehaviour = Settings.System.getInt(getContentResolver(),
@@ -60,10 +56,11 @@ public class NotificationDrawer extends SettingsPreferenceFragment implements
    @Override
    public void onResume() {
        super.onResume();
        boolean headsUpEnabled = Settings.System.getIntForUser(
                getActivity().getContentResolver(),
                Settings.System.HEADS_UP_NOTIFICATION, 0, UserHandle.USER_CURRENT) == 1;
        mSwitchPreference.setChecked(headsUpEnabled);

        boolean headsUpEnabled = Settings.System.getInt(
                getContentResolver(), Settings.System.HEADS_UP_NOTIFICATION, 0) == 1;
        mHeadsUp.setSummary(headsUpEnabled
                ? R.string.summary_heads_up_enabled : R.string.summary_heads_up_disabled);
    }

    public boolean onPreferenceChange(Preference preference, Object objValue) {
+0 −75
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 The CyanogenMod 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.
 */

package com.android.settings.cyanogenmod;

import android.content.Context;
import android.preference.SwitchPreference;
import android.provider.Settings;
import android.util.AttributeSet;


public class SystemSettingSwitchPreference extends SwitchPreference {

    public SystemSettingSwitchPreference(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public SystemSettingSwitchPreference(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public SystemSettingSwitchPreference(Context context) {
        super(context, null);
    }

    @Override
    protected boolean persistBoolean(boolean value) {
        if (shouldPersist()) {
            if (value == getPersistedBoolean(!value)) {
                // It's already there, so the same as persisting
                return true;
            }

            Settings.System.putInt(getContext().getContentResolver(), getKey(), value ? 1 : 0);
            return true;
        }
        return false;
    }

    @Override
    protected boolean getPersistedBoolean(boolean defaultReturnValue) {
        if (!shouldPersist()) {
            return defaultReturnValue;
        }

        return Settings.System.getInt(getContext().getContentResolver(),
                getKey(), defaultReturnValue ? 1 : 0) != 0;
    }

    @Override
    protected boolean isPersisted() {
        // Using getString instead of getInt so we can simply check for null
        // instead of catching an exception. (All values are stored as strings.)
        return Settings.System.getString(getContext().getContentResolver(), getKey()) != null;
    }

    @Override
    protected void onClick() {
        // Do nothing
        //super.onClick();
    }
}
+2 −4
Original line number Diff line number Diff line
@@ -279,8 +279,7 @@ public class HeadsUpSettings extends SettingsPreferenceFragment
            throws PackageManager.NameNotFoundException {
        PackageInfo info = mPackageManager.getPackageInfo(pkg.name,
                PackageManager.GET_META_DATA);
        Preference pref =
                new Preference(getActivity());
        Preference pref = new Preference(getActivity());

        pref.setKey(pkg.name);
        pref.setTitle(info.applicationInfo.loadLabel(mPackageManager));
@@ -353,8 +352,7 @@ public class HeadsUpSettings extends SettingsPreferenceFragment
                mBlacklistPackageList = value;
            }
        }
        Settings.System.putString(getContentResolver(),
                setting, value);
        Settings.System.putString(getContentResolver(), setting, value);
    }

    @Override