Search in sources :

Example 66 with FooterPreference

use of com.android.settingslib.widget.FooterPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DeviceAdminListPreferenceController method refreshUI.

private void refreshUI() {
    if (mPreferenceGroup == null) {
        return;
    }
    if (mFooterPreferenceMixin != null) {
        final FooterPreference footer = mFooterPreferenceMixin.createFooterPreference();
        footer.setTitle(R.string.no_device_admins);
        footer.setVisible(mAdmins.isEmpty());
    }
    final Map<String, FilterTouchesSwitchPreference> preferenceCache = new ArrayMap<>();
    final Context prefContext = mPreferenceGroup.getContext();
    final int childrenCount = mPreferenceGroup.getPreferenceCount();
    for (int i = 0; i < childrenCount; i++) {
        final Preference pref = mPreferenceGroup.getPreference(i);
        if (!(pref instanceof FilterTouchesSwitchPreference)) {
            continue;
        }
        final FilterTouchesSwitchPreference appSwitch = (FilterTouchesSwitchPreference) pref;
        preferenceCache.put(appSwitch.getKey(), appSwitch);
    }
    for (DeviceAdminListItem item : mAdmins) {
        final String key = item.getKey();
        FilterTouchesSwitchPreference pref = preferenceCache.remove(key);
        if (pref == null) {
            pref = new FilterTouchesSwitchPreference(prefContext);
            mPreferenceGroup.addPreference(pref);
        }
        bindPreference(item, pref);
    }
    for (FilterTouchesSwitchPreference unusedCacheItem : preferenceCache.values()) {
        mPreferenceGroup.removePreference(unusedCacheItem);
    }
}
Also used : Context(android.content.Context) FilterTouchesSwitchPreference(com.android.settings.widget.FilterTouchesSwitchPreference) SwitchPreference(androidx.preference.SwitchPreference) FilterTouchesSwitchPreference(com.android.settings.widget.FilterTouchesSwitchPreference) Preference(androidx.preference.Preference) FooterPreference(com.android.settingslib.widget.FooterPreference) ArrayMap(android.util.ArrayMap) FooterPreference(com.android.settingslib.widget.FooterPreference)

Example 67 with FooterPreference

use of com.android.settingslib.widget.FooterPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class PremiumSmsAccess method updatePrefs.

private void updatePrefs(ArrayList<AppEntry> apps) {
    if (apps == null)
        return;
    setEmptyText(R.string.premium_sms_none);
    setLoading(false, true);
    final PreferenceScreen screen = getPreferenceScreen();
    screen.removeAll();
    screen.setOrderingAsAdded(true);
    for (int i = 0; i < apps.size(); i++) {
        final PremiumSmsPreference smsPreference = new PremiumSmsPreference(apps.get(i), getPrefContext());
        smsPreference.setOnPreferenceChangeListener(this);
        screen.addPreference(smsPreference);
    }
    if (apps.size() != 0) {
        FooterPreference footer = new FooterPreference(getPrefContext());
        footer.setTitle(R.string.premium_sms_warning);
        screen.addPreference(footer);
    }
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) FooterPreference(com.android.settingslib.widget.FooterPreference)

Example 68 with FooterPreference

use of com.android.settingslib.widget.FooterPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class BluetoothDetailsMacAddressControllerTest method macAddress.

@Test
public void macAddress() {
    showScreen(mController);
    FooterPreference footer = (FooterPreference) mScreen.findPreference(mController.getPreferenceKey());
    assertThat(footer.getTitle().toString()).endsWith(mDeviceConfig.getAddress());
}
Also used : FooterPreference(com.android.settingslib.widget.FooterPreference) Test(org.junit.Test)

Example 69 with FooterPreference

use of com.android.settingslib.widget.FooterPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class EnterpriseDisclosurePreferenceController method addEnterpriseDisclosure.

private void addEnterpriseDisclosure() {
    final CharSequence disclosure = getDisclosure();
    if (disclosure == null) {
        return;
    }
    final FooterPreference enterpriseDisclosurePreference = mFooterPreferenceMixin.createFooterPreference();
    enterpriseDisclosurePreference.setSelectable(false);
    enterpriseDisclosurePreference.setTitle(disclosure);
    mScreen.addPreference(enterpriseDisclosurePreference);
}
Also used : FooterPreference(com.android.settingslib.widget.FooterPreference)

Example 70 with FooterPreference

use of com.android.settingslib.widget.FooterPreference in project android_packages_apps_Settings by omnirom.

the class AdvancedPowerUsageDetailTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mContext = spy(RuntimeEnvironment.application);
    when(mContext.getPackageName()).thenReturn("foo");
    mFeatureFactory = FakeFeatureFactory.setupForTest();
    mMetricsFeatureProvider = mFeatureFactory.metricsFeatureProvider;
    mFragment = spy(new AdvancedPowerUsageDetail());
    doReturn(mContext).when(mFragment).getContext();
    doReturn(mActivity).when(mFragment).getActivity();
    doReturn(SUMMARY).when(mFragment).getString(anyInt());
    doReturn(APP_LABEL).when(mBundle).getString(nullable(String.class));
    when(mFragment.getArguments()).thenReturn(mBundle);
    doReturn(mLoaderManager).when(mFragment).getLoaderManager();
    when(mFeatureFactory.powerUsageFeatureProvider.isChartGraphEnabled(mContext)).thenReturn(true);
    ShadowEntityHeaderController.setUseMock(mEntityHeaderController);
    doReturn(mEntityHeaderController).when(mEntityHeaderController).setRecyclerView(nullable(RecyclerView.class), nullable(Lifecycle.class));
    doReturn(mEntityHeaderController).when(mEntityHeaderController).setButtonActions(anyInt(), anyInt());
    doReturn(mEntityHeaderController).when(mEntityHeaderController).setIcon(nullable(Drawable.class));
    doReturn(mEntityHeaderController).when(mEntityHeaderController).setIcon(nullable(ApplicationsState.AppEntry.class));
    doReturn(mEntityHeaderController).when(mEntityHeaderController).setLabel(nullable(String.class));
    doReturn(mEntityHeaderController).when(mEntityHeaderController).setLabel(nullable(String.class));
    doReturn(mEntityHeaderController).when(mEntityHeaderController).setLabel(nullable(ApplicationsState.AppEntry.class));
    doReturn(mEntityHeaderController).when(mEntityHeaderController).setSummary(nullable(String.class));
    when(mBatteryEntry.getUid()).thenReturn(UID);
    when(mBatteryEntry.getLabel()).thenReturn(APP_LABEL);
    when(mBatteryEntry.getTimeInBackgroundMs()).thenReturn(BACKGROUND_TIME_MS);
    when(mBatteryEntry.getTimeInForegroundMs()).thenReturn(FOREGROUND_TIME_MS);
    mBatteryEntry.iconId = ICON_ID;
    mFragment.mHeaderPreference = mHeaderPreference;
    mFragment.mState = mState;
    mFragment.enableTriState = true;
    mFragment.mBatteryUtils = new BatteryUtils(RuntimeEnvironment.application);
    mFragment.mBatteryOptimizeUtils = mBatteryOptimizeUtils;
    mAppEntry.info = mock(ApplicationInfo.class);
    mTestActivity = spy(new SettingsActivity());
    doReturn(mPackageManager).when(mTestActivity).getPackageManager();
    doReturn(mPackageManager).when(mActivity).getPackageManager();
    doReturn(mAppOpsManager).when(mTestActivity).getSystemService(Context.APP_OPS_SERVICE);
    mBatteryUtils = spy(new BatteryUtils(mContext));
    doReturn(FOREGROUND_SERVICE_TIME_US).when(mBatteryUtils).getForegroundServiceTotalTimeUs(any(BatteryStats.Uid.class), anyLong());
    final ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
    Answer<Void> callable = invocation -> {
        mBundle = captor.getValue().getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
        System.out.println("mBundle = " + mBundle);
        return null;
    };
    doAnswer(callable).when(mActivity).startActivityAsUser(captor.capture(), nullable(UserHandle.class));
    doAnswer(callable).when(mActivity).startActivity(captor.capture());
    mForegroundPreference = new Preference(mContext);
    mBackgroundPreference = new Preference(mContext);
    mFooterPreference = new FooterPreference(mContext);
    mRestrictedPreference = new RadioButtonPreference(mContext);
    mOptimizePreference = new RadioButtonPreference(mContext);
    mUnrestrictedPreference = new RadioButtonPreference(mContext);
    mFragment.mForegroundPreference = mForegroundPreference;
    mFragment.mBackgroundPreference = mBackgroundPreference;
    mFragment.mFooterPreference = mFooterPreference;
    mFragment.mRestrictedPreference = mRestrictedPreference;
    mFragment.mOptimizePreference = mOptimizePreference;
    mFragment.mUnrestrictedPreference = mUnrestrictedPreference;
}
Also used : AppOpsManager(android.app.AppOpsManager) Bundle(android.os.Bundle) PackageManager(android.content.pm.PackageManager) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) ArgumentMatchers.nullable(org.mockito.ArgumentMatchers.nullable) MetricsFeatureProvider(com.android.settingslib.core.instrumentation.MetricsFeatureProvider) Drawable(android.graphics.drawable.Drawable) ShadowActivityManager(com.android.settings.testutils.shadow.ShadowActivityManager) MockitoAnnotations(org.mockito.MockitoAnnotations) ReflectionHelpers(org.robolectric.util.ReflectionHelpers) AppUtils(com.android.settingslib.applications.AppUtils) Mockito.doAnswer(org.mockito.Mockito.doAnswer) After(org.junit.After) RecyclerView(androidx.recyclerview.widget.RecyclerView) Mockito.doReturn(org.mockito.Mockito.doReturn) R(com.android.settings.R) EXTRA_SHOW_FRAGMENT_ARGUMENTS(com.android.settings.SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS) RuntimeEnvironment(org.robolectric.RuntimeEnvironment) FooterPreference(com.android.settingslib.widget.FooterPreference) RobolectricTestRunner(org.robolectric.RobolectricTestRunner) SettingsActivity(com.android.settings.SettingsActivity) EntityHeaderController(com.android.settings.widget.EntityHeaderController) ApplicationInfo(android.content.pm.ApplicationInfo) ShadowEntityHeaderController(com.android.settings.testutils.shadow.ShadowEntityHeaderController) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Context(android.content.Context) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) LayoutPreference(com.android.settingslib.widget.LayoutPreference) Mock(org.mockito.Mock) Pair(android.util.Pair) RunWith(org.junit.runner.RunWith) Config(org.robolectric.annotation.Config) Intent(android.content.Intent) Mockito.spy(org.mockito.Mockito.spy) LoaderManager(androidx.loader.app.LoaderManager) FragmentActivity(androidx.fragment.app.FragmentActivity) Answer(org.mockito.stubbing.Answer) ArgumentCaptor(org.mockito.ArgumentCaptor) UserHandle(android.os.UserHandle) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) Before(org.junit.Before) Answers(org.mockito.Answers) SettingsEnums(android.app.settings.SettingsEnums) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) ApplicationsState(com.android.settingslib.applications.ApplicationsState) Truth.assertThat(com.google.common.truth.Truth.assertThat) InstantAppDataProvider(com.android.settingslib.applications.instantapps.InstantAppDataProvider) Preference(androidx.preference.Preference) Mockito.verify(org.mockito.Mockito.verify) FakeFeatureFactory(com.android.settings.testutils.FakeFeatureFactory) RadioButtonPreference(com.android.settingslib.widget.RadioButtonPreference) BatteryStats(android.os.BatteryStats) Lifecycle(com.android.settingslib.core.lifecycle.Lifecycle) Lifecycle(com.android.settingslib.core.lifecycle.Lifecycle) Drawable(android.graphics.drawable.Drawable) ApplicationInfo(android.content.pm.ApplicationInfo) Intent(android.content.Intent) FooterPreference(com.android.settingslib.widget.FooterPreference) LayoutPreference(com.android.settingslib.widget.LayoutPreference) Preference(androidx.preference.Preference) RadioButtonPreference(com.android.settingslib.widget.RadioButtonPreference) UserHandle(android.os.UserHandle) RecyclerView(androidx.recyclerview.widget.RecyclerView) FooterPreference(com.android.settingslib.widget.FooterPreference) SettingsActivity(com.android.settings.SettingsActivity) RadioButtonPreference(com.android.settingslib.widget.RadioButtonPreference) Before(org.junit.Before)

Aggregations

FooterPreference (com.android.settingslib.widget.FooterPreference)84 Test (org.junit.Test)22 Before (org.junit.Before)18 Intent (android.content.Intent)17 Preference (androidx.preference.Preference)10 View (android.view.View)8 PreferenceScreen (androidx.preference.PreferenceScreen)7 NotificationChannel (android.app.NotificationChannel)6 NotificationChannelGroup (android.app.NotificationChannelGroup)6 Preference (android.support.v7.preference.Preference)6 PreferenceCategory (android.support.v7.preference.PreferenceCategory)6 TextView (android.widget.TextView)6 LayoutPreference (com.android.settings.applications.LayoutPreference)6 MasterSwitchPreference (com.android.settings.widget.MasterSwitchPreference)6 RestrictedSwitchPreference (com.android.settingslib.RestrictedSwitchPreference)6 Context (android.content.Context)3 Drawable (android.graphics.drawable.Drawable)2 SpannableString (android.text.SpannableString)2 Pair (android.util.Pair)2 VisibleForTesting (androidx.annotation.VisibleForTesting)2