Search in sources :

Example 26 with PreferenceManager

use of androidx.preference.PreferenceManager in project android_packages_apps_Settings by omnirom.

the class PaymentSettingsTest method isShowEmptyImage_hasNoVisiblePreference_returnTrue.

@Test
public void isShowEmptyImage_hasNoVisiblePreference_returnTrue() {
    final PaymentSettings paymentSettings = new PaymentSettings();
    final PreferenceManager preferenceManager = new PreferenceManager(mContext);
    final PreferenceScreen screen = preferenceManager.createPreferenceScreen(mContext);
    final Preference preference1 = new Preference(mContext);
    preference1.setVisible(false);
    screen.addPreference(preference1);
    final Preference preference2 = new Preference(mContext);
    screen.addPreference(preference2);
    preference2.setVisible(false);
    assertThat(paymentSettings.isShowEmptyImage(screen)).isTrue();
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) Preference(androidx.preference.Preference) PreferenceManager(androidx.preference.PreferenceManager) Test(org.junit.Test)

Example 27 with PreferenceManager

use of androidx.preference.PreferenceManager in project android_packages_apps_Settings by omnirom.

the class PhoneNumberPreferenceControllerTest method setup.

@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    mContext = spy(ApplicationProvider.getApplicationContext());
    mClipboardManager = (ClipboardManager) spy(mContext.getSystemService(CLIPBOARD_SERVICE));
    doReturn(mClipboardManager).when(mContext).getSystemService(CLIPBOARD_SERVICE);
    when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
    when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
    mController = spy(new PhoneNumberPreferenceController(mContext, "phone_number"));
    if (Looper.myLooper() == null) {
        Looper.prepare();
    }
    final PreferenceManager preferenceManager = new PreferenceManager(mContext);
    mScreen = preferenceManager.createPreferenceScreen(mContext);
    mPreference = spy(new Preference(mContext));
    mPreference.setKey(mController.getPreferenceKey());
    mPreference.setVisible(true);
    mScreen.addPreference(mPreference);
    final String categoryKey = "basic_info_category";
    mCategory = new PreferenceCategory(mContext);
    mCategory.setKey(categoryKey);
    mScreen.addPreference(mCategory);
    doReturn(mSubscriptionInfo).when(mController).getSubscriptionInfo(anyInt());
    doReturn(mSecondPreference).when(mController).createNewPreference(mContext);
}
Also used : Preference(androidx.preference.Preference) PreferenceCategory(androidx.preference.PreferenceCategory) PreferenceManager(androidx.preference.PreferenceManager) Before(org.junit.Before)

Example 28 with PreferenceManager

use of androidx.preference.PreferenceManager in project android_packages_apps_Settings by omnirom.

the class StorageSelectionPreferenceControllerTest method setUp.

@Before
public void setUp() throws Exception {
    if (Looper.myLooper() == null) {
        Looper.prepare();
    }
    mContext = ApplicationProvider.getApplicationContext();
    mStorageManager = mContext.getSystemService(StorageManager.class);
    mController = new StorageSelectionPreferenceController(mContext, PREFERENCE_KEY);
    final PreferenceManager preferenceManager = new PreferenceManager(mContext);
    final PreferenceScreen preferenceScreen = preferenceManager.createPreferenceScreen(mContext);
    final SettingsSpinnerPreference spinnerPreference = new SettingsSpinnerPreference(mContext);
    spinnerPreference.setKey(PREFERENCE_KEY);
    preferenceScreen.addPreference(spinnerPreference);
    mController.displayPreference(preferenceScreen);
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) StorageManager(android.os.storage.StorageManager) SettingsSpinnerPreference(com.android.settingslib.widget.SettingsSpinnerPreference) PreferenceManager(androidx.preference.PreferenceManager) Before(org.junit.Before)

Example 29 with PreferenceManager

use of androidx.preference.PreferenceManager in project android_packages_apps_Settings by omnirom.

the class MobileNetworkSwitchControllerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mContext = spy(ApplicationProvider.getApplicationContext());
    when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
    when(mSubscriptionManager.setSubscriptionEnabled(eq(mSubId), anyBoolean())).thenReturn(true);
    when(mSubscription.isEmbedded()).thenReturn(true);
    when(mSubscription.getSubscriptionId()).thenReturn(mSubId);
    // Most tests want to have 2 available subscriptions so that the switch bar will show.
    final SubscriptionInfo sub2 = mock(SubscriptionInfo.class);
    when(sub2.getSubscriptionId()).thenReturn(456);
    SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(mSubscription, sub2));
    final String key = "prefKey";
    mController = new MobileNetworkSwitchController(mContext, key);
    mController.init(mLifecycle, mSubscription.getSubscriptionId());
    if (Looper.myLooper() == null) {
        Looper.prepare();
    }
    mPreferenceManager = new PreferenceManager(mContext);
    mScreen = mPreferenceManager.createPreferenceScreen(mContext);
    mSwitchBar = new SettingsMainSwitchPreference(mContext);
    mSwitchBar.setKey(key);
    mScreen.addPreference(mSwitchBar);
    final LayoutInflater inflater = LayoutInflater.from(mContext);
    final View view = inflater.inflate(mSwitchBar.getLayoutResource(), new LinearLayout(mContext), false);
    final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(view);
    mSwitchBar.onBindViewHolder(holder);
}
Also used : SettingsMainSwitchPreference(com.android.settings.widget.SettingsMainSwitchPreference) LayoutInflater(android.view.LayoutInflater) SubscriptionInfo(android.telephony.SubscriptionInfo) PreferenceManager(androidx.preference.PreferenceManager) View(android.view.View) PreferenceViewHolder(androidx.preference.PreferenceViewHolder) LinearLayout(android.widget.LinearLayout) Before(org.junit.Before)

Example 30 with PreferenceManager

use of androidx.preference.PreferenceManager in project android_packages_apps_Settings by omnirom.

the class NetworkProviderWifiCallingPreferenceControllerTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    mContext = spy(ApplicationProvider.getApplicationContext());
    mCategoryController = new NetworkProviderWifiCallingPreferenceController(mContext, KEY_PREFERENCE_WFC_CATEGORY) {

        @Override
        protected NetworkProviderWifiCallingGroup createWifiCallingControllerForSub(Lifecycle lifecycle) {
            return mWifiCallingForSubController;
        }
    };
    if (Looper.myLooper() == null) {
        Looper.prepare();
    }
    mPreferenceManager = new PreferenceManager(mContext);
    mPreferenceScreen = mPreferenceManager.createPreferenceScreen(mContext);
    when(mPreferenceCategory.getKey()).thenReturn(KEY_PREFERENCE_WFC_CATEGORY);
    when(mPreferenceCategory.getPreferenceCount()).thenReturn(1);
    mPreferenceScreen.addPreference(mPreferenceCategory);
}
Also used : Lifecycle(com.android.settingslib.core.lifecycle.Lifecycle) PreferenceManager(androidx.preference.PreferenceManager) Before(org.junit.Before)

Aggregations

PreferenceManager (androidx.preference.PreferenceManager)87 Before (org.junit.Before)67 Preference (androidx.preference.Preference)23 PreferenceCategory (androidx.preference.PreferenceCategory)22 PreferenceScreen (androidx.preference.PreferenceScreen)19 Test (org.junit.Test)18 Lifecycle (com.android.settingslib.core.lifecycle.Lifecycle)15 Context (android.content.Context)5 LifecycleRegistry (androidx.lifecycle.LifecycleRegistry)5 ArrayList (java.util.ArrayList)5 NotificationChannel (android.app.NotificationChannel)4 ShortcutInfo (android.content.pm.ShortcutInfo)4 View (android.view.View)4 NotificationChannelGroup (android.app.NotificationChannelGroup)3 ConversationChannel (android.app.people.ConversationChannel)3 PackageInfo (android.content.pm.PackageInfo)3 PersistableBundle (android.os.PersistableBundle)3 BluetoothManager (android.bluetooth.BluetoothManager)2 SoftApConfiguration (android.net.wifi.SoftApConfiguration)2 WifiManager (android.net.wifi.WifiManager)2