Search in sources :

Example 26 with MasterSwitchPreference

use of com.android.settings.widget.MasterSwitchPreference in project android_packages_apps_Settings by SudaMod.

the class AppNotificationSettings method populateSingleChannelPrefs.

private void populateSingleChannelPrefs(PreferenceCategory groupCategory, final NotificationChannel channel) {
    MasterSwitchPreference channelPref = new MasterSwitchPreference(getPrefContext());
    channelPref.setSwitchEnabled(mSuspendedAppsAdmin == null && isChannelBlockable(mAppRow.systemApp, channel) && isChannelConfigurable(channel));
    channelPref.setKey(channel.getId());
    channelPref.setTitle(channel.getName());
    channelPref.setChecked(channel.getImportance() != IMPORTANCE_NONE);
    channelPref.setSummary(getImportanceSummary(channel));
    Bundle channelArgs = new Bundle();
    channelArgs.putInt(AppInfoBase.ARG_PACKAGE_UID, mUid);
    channelArgs.putString(AppInfoBase.ARG_PACKAGE_NAME, mPkg);
    channelArgs.putString(Settings.EXTRA_CHANNEL_ID, channel.getId());
    Intent channelIntent = Utils.onBuildStartFragmentIntent(getActivity(), ChannelNotificationSettings.class.getName(), channelArgs, null, R.string.notification_channel_title, null, false, getMetricsCategory());
    channelPref.setIntent(channelIntent);
    channelPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object o) {
            boolean value = (Boolean) o;
            int importance = value ? IMPORTANCE_LOW : IMPORTANCE_NONE;
            channel.setImportance(importance);
            channel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE);
            channelPref.setSummary(getImportanceSummary(channel));
            mBackend.updateChannel(mPkg, mUid, channel);
            return true;
        }
    });
    groupCategory.addPreference(channelPref);
}
Also used : MasterSwitchPreference(com.android.settings.widget.MasterSwitchPreference) LayoutPreference(com.android.settings.applications.LayoutPreference) RestrictedSwitchPreference(com.android.settingslib.RestrictedSwitchPreference) MasterSwitchPreference(com.android.settings.widget.MasterSwitchPreference) FooterPreference(com.android.settingslib.widget.FooterPreference) Preference(android.support.v7.preference.Preference) Bundle(android.os.Bundle) Intent(android.content.Intent)

Example 27 with MasterSwitchPreference

use of com.android.settings.widget.MasterSwitchPreference in project platform_packages_apps_Settings by BlissRoms.

the class AppNotificationSettings method populateSingleChannelPrefs.

private void populateSingleChannelPrefs(PreferenceCategory groupCategory, final NotificationChannel channel) {
    MasterSwitchPreference channelPref = new MasterSwitchPreference(getPrefContext());
    channelPref.setSwitchEnabled(mSuspendedAppsAdmin == null && isChannelBlockable(mAppRow.systemApp, channel) && isChannelConfigurable(channel));
    channelPref.setKey(channel.getId());
    channelPref.setTitle(channel.getName());
    channelPref.setChecked(channel.getImportance() != IMPORTANCE_NONE);
    channelPref.setSummary(getImportanceSummary(channel));
    Bundle channelArgs = new Bundle();
    channelArgs.putInt(AppInfoBase.ARG_PACKAGE_UID, mUid);
    channelArgs.putString(AppInfoBase.ARG_PACKAGE_NAME, mPkg);
    channelArgs.putString(Settings.EXTRA_CHANNEL_ID, channel.getId());
    Intent channelIntent = Utils.onBuildStartFragmentIntent(getActivity(), ChannelNotificationSettings.class.getName(), channelArgs, null, R.string.notification_channel_title, null, false, getMetricsCategory());
    channelPref.setIntent(channelIntent);
    channelPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object o) {
            boolean value = (Boolean) o;
            int importance = value ? IMPORTANCE_LOW : IMPORTANCE_NONE;
            channel.setImportance(importance);
            channel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE);
            channelPref.setSummary(getImportanceSummary(channel));
            mBackend.updateChannel(mPkg, mUid, channel);
            return true;
        }
    });
    groupCategory.addPreference(channelPref);
}
Also used : MasterSwitchPreference(com.android.settings.widget.MasterSwitchPreference) LayoutPreference(com.android.settings.applications.LayoutPreference) RestrictedSwitchPreference(com.android.settingslib.RestrictedSwitchPreference) MasterSwitchPreference(com.android.settings.widget.MasterSwitchPreference) FooterPreference(com.android.settingslib.widget.FooterPreference) Preference(android.support.v7.preference.Preference) Bundle(android.os.Bundle) Intent(android.content.Intent)

Example 28 with MasterSwitchPreference

use of com.android.settings.widget.MasterSwitchPreference in project platform_packages_apps_Settings by BlissRoms.

the class WifiTetherPreferenceControllerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mLifecycle = new Lifecycle();
    FakeFeatureFactory.setupForTest(mFeatureFactoryContext);
    mPreference = new MasterSwitchPreference(RuntimeEnvironment.application);
    when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(mConnectivityManager);
    when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager);
    when(mScreen.findPreference(anyString())).thenReturn(mPreference);
    when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[] { "1", "2" });
    mController = new WifiTetherPreferenceController(mContext, mLifecycle);
}
Also used : MasterSwitchPreference(com.android.settings.widget.MasterSwitchPreference) Lifecycle(com.android.settingslib.core.lifecycle.Lifecycle) Before(org.junit.Before)

Example 29 with MasterSwitchPreference

use of com.android.settings.widget.MasterSwitchPreference in project platform_packages_apps_Settings by BlissRoms.

the class WifiTetherPreferenceControllerTest method start_wifiApOff_shouldSetInitialStateToOff.

@Test
public void start_wifiApOff_shouldSetInitialStateToOff() {
    when(mWifiManager.getWifiApState()).thenReturn(WifiManager.WIFI_AP_STATE_DISABLED);
    final BroadcastReceiver receiver = ReflectionHelpers.getField(mController, "mReceiver");
    final MasterSwitchPreference pref = mock(MasterSwitchPreference.class);
    when(mScreen.findPreference(anyString())).thenReturn(pref);
    mController.displayPreference(mScreen);
    mLifecycle.onStart();
    assertThat(ShadowWifiTetherSwitchBarController.onStartCalled).isTrue();
    verify(mContext).registerReceiver(eq(receiver), any(IntentFilter.class));
    verify(pref).setChecked(false);
}
Also used : IntentFilter(android.content.IntentFilter) MasterSwitchPreference(com.android.settings.widget.MasterSwitchPreference) BroadcastReceiver(android.content.BroadcastReceiver) Test(org.junit.Test)

Example 30 with MasterSwitchPreference

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

the class ChannelListPreferenceController method onGroupBlockStateChanged.

protected void onGroupBlockStateChanged(NotificationChannelGroup group) {
    if (group == null) {
        return;
    }
    PreferenceGroup groupGroup = mPreference.findPreference(group.getId());
    if (groupGroup != null) {
        if (group.isBlocked()) {
            List<Preference> toRemove = new ArrayList<>();
            int childCount = groupGroup.getPreferenceCount();
            for (int i = 0; i < childCount; i++) {
                Preference pref = groupGroup.getPreference(i);
                if (pref instanceof MasterSwitchPreference) {
                    toRemove.add(pref);
                }
            }
            for (Preference pref : toRemove) {
                groupGroup.removePreference(pref);
            }
        } else {
            final List<NotificationChannel> channels = group.getChannels();
            Collections.sort(channels, mChannelComparator);
            int N = channels.size();
            for (int i = 0; i < N; i++) {
                final NotificationChannel channel = channels.get(i);
                populateSingleChannelPrefs(groupGroup, channel, group.isBlocked());
            }
        }
    }
}
Also used : NotificationChannel(android.app.NotificationChannel) MasterSwitchPreference(com.android.settings.widget.MasterSwitchPreference) RestrictedSwitchPreference(com.android.settingslib.RestrictedSwitchPreference) SwitchPreference(androidx.preference.SwitchPreference) Preference(androidx.preference.Preference) MasterSwitchPreference(com.android.settings.widget.MasterSwitchPreference) ArrayList(java.util.ArrayList) PreferenceGroup(androidx.preference.PreferenceGroup)

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