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

Commit ab63fd3c authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Remove dead code

Test: try to search 'gentle'
Fixes: 135640138
Change-Id: If03703e59f77206da08fc80e88bb986f821c18fe
parent 242ff568
Loading
Loading
Loading
Loading
+0 −57
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2019 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.
-->

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
                  xmlns:settings="http://schemas.android.com/apk/res-auto"
                  android:title="@string/gentle_notifications_title"
                  android:key="gentle_notification_settings">

        <com.android.settingslib.widget.LayoutPreference
            android:key="gentle_notifications_drawable"
            android:title="@string/summary_placeholder"
            android:layout="@layout/drawable_layout"
            settings:controller="com.android.settings.notification.GentleDrawablePreferenceController"
            android:selectable="false"
            android:order="1"
            settings:allowDividerBelow="true"
            android:persistent="false" />

        <Preference
            android:key="gentle_notifications_footer"
            android:title="@string/gentle_notifications_education"
            android:order="2"
            android:icon="@drawable/ic_info_outline_24"
            style="?attr/footerPreferenceStyle"
            settings:allowDividerAbove="true"
            android:clickable="false"
            android:selectable="false" />

        <PreferenceCategory
            android:key="gentle_notifications_settings"
            android:title="@string/gentle_notifications_also_display"
            android:order="3">
                <SwitchPreference
                    android:key="silent_icons"
                    android:title="@string/gentle_notifications_display_status"
                    settings:controller="com.android.settings.notification.SilentStatusBarPreferenceController" />

                <SwitchPreference
                    android:key="lock_screen"
                    android:title="@string/gentle_notifications_display_lock"
                    settings:controller="com.android.settings.notification.SilentLockscreenPreferenceController" />
        </PreferenceCategory>

</PreferenceScreen>
+0 −81
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 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.
 */

package com.android.settings.notification;

import android.content.Context;
import android.provider.Settings;
import android.widget.ImageView;

import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settingslib.widget.LayoutPreference;

import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;

public class GentleDrawablePreferenceController extends BasePreferenceController {

    @VisibleForTesting
    static final int ON = 1;

    private NotificationBackend mBackend;

    public GentleDrawablePreferenceController(Context context, String preferenceKey) {
        super(context, preferenceKey);
        mBackend = new NotificationBackend();
    }

    @VisibleForTesting
    void setBackend(NotificationBackend backend) {
        mBackend = backend;
    }

    @Override
    public void updateState(Preference preference) {
        LayoutPreference pref = (LayoutPreference) preference;
        boolean showOnLockscreen = showOnLockscreen();
        boolean showOnStatusBar = showOnStatusBar();

        ImageView view = pref.findViewById(R.id.drawable);

        if (showOnLockscreen) {
            if (showOnStatusBar) {
                view.setImageResource(R.drawable.gentle_notifications_shade_status_lock);
            } else {
                view.setImageResource(R.drawable.gentle_notifications_shade_lock);
            }
        } else if (showOnStatusBar) {
            view.setImageResource(R.drawable.gentle_notifications_shade_status);
        } else {
            view.setImageResource(R.drawable.gentle_notifications_shade);
        }
    }

    @Override
    public int getAvailabilityStatus() {
        return AVAILABLE;
    }

    private boolean showOnLockscreen() {
        return Settings.Secure.getInt(mContext.getContentResolver(),
                Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, ON) == ON;
    }

    private boolean showOnStatusBar() {
        return !mBackend.shouldHideSilentStatusBarIcons(mContext);
    }
}
+0 −74
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 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.
 */

package com.android.settings.notification;

import android.app.settings.SettingsEnums;
import android.content.Context;
import android.provider.SearchIndexableResource;

import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.search.SearchIndexable;

import java.util.Arrays;
import java.util.List;

@SearchIndexable
public class GentleNotificationSettings extends DashboardFragment {
    private static final String TAG = "GentleNotiSettings";

    @Override
    public int getMetricsCategory() {
        return SettingsEnums.GENTLE_NOTIFICATIONS_SCREEN;
    }

    @Override
    protected String getLogTag() {
        return TAG;
    }

    @Override
    protected int getPreferenceScreenResId() {
        return R.xml.gentle_notification_settings;
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);

        use(SilentStatusBarPreferenceController.class).setListener(
                shown -> updatePreferenceStates());

        use(SilentLockscreenPreferenceController.class).setListener(
                shown -> updatePreferenceStates());
    }

    /**
     * For Search.
     */
    public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
            new BaseSearchIndexProvider() {
                @Override
                public List<SearchIndexableResource> getXmlResourcesToIndex(
                        Context context, boolean enabled) {
                    final SearchIndexableResource sir = new SearchIndexableResource(context);
                    sir.xmlResId = R.xml.gentle_notification_settings;
                    return Arrays.asList(sir);
                }
            };
}
+0 −70
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 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.
 */

package com.android.settings.notification;

import static android.provider.Settings.Secure.NOTIFICATION_NEW_INTERRUPTION_MODEL;

import android.content.Context;
import android.os.UserHandle;
import android.provider.Settings;

import com.android.settings.core.TogglePreferenceController;

import com.google.common.annotations.VisibleForTesting;

public class SilentLockscreenPreferenceController extends TogglePreferenceController {

    private static final String KEY = "lock_screen";
    private Listener mListener;

    public SilentLockscreenPreferenceController(Context context) {
        super(context, KEY);
    }

    @Override
    public boolean isChecked() {
        return Settings.Secure.getInt(mContext.getContentResolver(),
                Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 1) == 1;
    }

    @Override
    public boolean setChecked(boolean isChecked) {
        Settings.Secure.putInt(mContext.getContentResolver(),
                Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, isChecked ? 1 : 0);
        if (mListener != null) {
            mListener.onChange(isChecked);
        }
        return true;
    }

    @Override
    public int getAvailabilityStatus() {
        return Settings.Secure.getInt(
                mContext.getContentResolver(), NOTIFICATION_NEW_INTERRUPTION_MODEL, 1) != 0
                ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
    }

    public void setListener(Listener listener) {
        mListener = listener;
    }

    interface Listener {
        void onChange(boolean shown);
    }
}

+0 −77
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 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.
 */

package com.android.settings.notification;

import static android.provider.Settings.Secure.NOTIFICATION_NEW_INTERRUPTION_MODEL;

import android.content.Context;
import android.os.UserHandle;
import android.provider.Settings;

import com.android.settings.core.TogglePreferenceController;

import com.google.common.annotations.VisibleForTesting;

public class SilentStatusBarPreferenceController extends TogglePreferenceController {

    private static final String KEY = "silent_icons";
    private static final int MY_USER_ID = UserHandle.myUserId();
    private NotificationBackend mBackend;
    private Listener mListener;

    public SilentStatusBarPreferenceController(Context context) {
        super(context, KEY);
        mBackend = new NotificationBackend();
    }

    @VisibleForTesting
    void setBackend(NotificationBackend backend) {
        mBackend = backend;
    }

    @Override
    public boolean isChecked() {
        return !mBackend.shouldHideSilentStatusBarIcons(mContext);
    }

    @Override
    public boolean setChecked(boolean isChecked) {
        mBackend.setHideSilentStatusIcons(!isChecked);
        if (mListener != null) {
            mListener.onChange(isChecked);
        }
        return true;
    }

    @Override
    public int getAvailabilityStatus() {
        return Settings.Secure.getInt(
                mContext.getContentResolver(), NOTIFICATION_NEW_INTERRUPTION_MODEL, 1) != 0
                ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
    }

    public void setListener(Listener listener) {
        mListener = listener;
    }

    interface Listener {
        void onChange(boolean shown);
    }

}

Loading