Search in sources :

Example 31 with MasterSwitchPreference

use of com.android.settings.widget.MasterSwitchPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ChannelListPreferenceController method populateSingleChannelPrefs.

protected Preference populateSingleChannelPrefs(PreferenceGroup parent, final NotificationChannel channel, final boolean groupBlocked) {
    MasterSwitchPreference channelPref = new MasterSwitchPreference(mContext);
    channelPref.setSwitchEnabled(mAdmin == null && isChannelBlockable(channel) && isChannelConfigurable(channel) && !groupBlocked);
    channelPref.setIcon(null);
    if (channel.getImportance() > IMPORTANCE_LOW) {
        channelPref.setIcon(getAlertingIcon());
    }
    channelPref.setIconSize(MasterSwitchPreference.ICON_SIZE_SMALL);
    channelPref.setKey(channel.getId());
    channelPref.setTitle(channel.getName());
    channelPref.setSummary(NotificationBackend.getSentSummary(mContext, mAppRow.sentByChannel.get(channel.getId()), false));
    channelPref.setChecked(channel.getImportance() != IMPORTANCE_NONE);
    Bundle channelArgs = new Bundle();
    channelArgs.putInt(AppInfoBase.ARG_PACKAGE_UID, mAppRow.uid);
    channelArgs.putString(AppInfoBase.ARG_PACKAGE_NAME, mAppRow.pkg);
    channelArgs.putString(Settings.EXTRA_CHANNEL_ID, channel.getId());
    channelArgs.putBoolean(ARG_FROM_SETTINGS, true);
    channelPref.setIntent(new SubSettingLauncher(mContext).setDestination(ChannelNotificationSettings.class.getName()).setArguments(channelArgs).setTitleRes(R.string.notification_channel_title).setSourceMetricsCategory(SettingsEnums.NOTIFICATION_APP_NOTIFICATION).toIntent());
    channelPref.setOnPreferenceChangeListener((preference, o) -> {
        boolean value = (Boolean) o;
        int importance = value ? IMPORTANCE_LOW : IMPORTANCE_NONE;
        channel.setImportance(importance);
        channel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE);
        MasterSwitchPreference channelPref1 = (MasterSwitchPreference) preference;
        channelPref1.setIcon(null);
        if (channel.getImportance() > IMPORTANCE_LOW) {
            channelPref1.setIcon(getAlertingIcon());
        }
        toggleBehaviorIconState(channelPref1.getIcon(), importance != IMPORTANCE_NONE);
        mBackend.updateChannel(mAppRow.pkg, mAppRow.uid, channel);
        return true;
    });
    if (parent.findPreference(channelPref.getKey()) == null) {
        parent.addPreference(channelPref);
    }
    return channelPref;
}
Also used : MasterSwitchPreference(com.android.settings.widget.MasterSwitchPreference) SubSettingLauncher(com.android.settings.core.SubSettingLauncher) Bundle(android.os.Bundle)

Aggregations

MasterSwitchPreference (com.android.settings.widget.MasterSwitchPreference)31 BroadcastReceiver (android.content.BroadcastReceiver)12 IntentFilter (android.content.IntentFilter)12 Test (org.junit.Test)12 Before (org.junit.Before)11 Bundle (android.os.Bundle)7 RestrictedSwitchPreference (com.android.settingslib.RestrictedSwitchPreference)7 Intent (android.content.Intent)6 Preference (android.support.v7.preference.Preference)6 LayoutPreference (com.android.settings.applications.LayoutPreference)6 Lifecycle (com.android.settingslib.core.lifecycle.Lifecycle)6 FooterPreference (com.android.settingslib.widget.FooterPreference)6 PreferenceViewHolder (android.support.v7.preference.PreferenceViewHolder)5 View (android.view.View)5 Switch (android.widget.Switch)5 MasterSwitchController (com.android.settings.widget.MasterSwitchController)5 NotificationChannel (android.app.NotificationChannel)1 SwitchPreference (android.support.v14.preference.SwitchPreference)1 Preference (androidx.preference.Preference)1 PreferenceGroup (androidx.preference.PreferenceGroup)1