Search in sources :

Example 76 with Preference

use of androidx.preference.Preference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class WifiSettings method updateAccessPointPreferences.

private void updateAccessPointPreferences() {
    // in case state has changed
    if (!mWifiManager.isWifiEnabled()) {
        return;
    }
    // AccessPoints are sorted by the WifiTracker
    final List<AccessPoint> accessPoints = mWifiTracker.getAccessPoints();
    if (isVerboseLoggingEnabled()) {
        Log.i(TAG, "updateAccessPoints called for: " + accessPoints);
    }
    boolean hasAvailableAccessPoints = false;
    mStatusMessagePreference.setVisible(false);
    mConnectedAccessPointPreferenceCategory.setVisible(true);
    mAccessPointsPreferenceCategory.setVisible(true);
    cacheRemoveAllPrefs(mAccessPointsPreferenceCategory);
    int index = configureConnectedAccessPointPreferenceCategory(accessPoints) ? 1 : 0;
    int numAccessPoints = accessPoints.size();
    for (; index < numAccessPoints; index++) {
        AccessPoint accessPoint = accessPoints.get(index);
        // Ignore access points that are out of range.
        if (accessPoint.isReachable()) {
            String key = accessPoint.getKey();
            hasAvailableAccessPoints = true;
            LongPressAccessPointPreference pref = (LongPressAccessPointPreference) getCachedPreference(key);
            if (pref != null) {
                pref.setOrder(index);
                continue;
            }
            LongPressAccessPointPreference preference = createLongPressAccessPointPreference(accessPoint);
            preference.setKey(key);
            preference.setOrder(index);
            if (mOpenSsid != null && mOpenSsid.equals(accessPoint.getSsidStr()) && (accessPoint.getSecurity() != AccessPoint.SECURITY_NONE && accessPoint.getSecurity() != AccessPoint.SECURITY_OWE)) {
                if (!accessPoint.isSaved() || isDisabledByWrongPassword(accessPoint)) {
                    onPreferenceTreeClick(preference);
                    mOpenSsid = null;
                }
            }
            mAccessPointsPreferenceCategory.addPreference(preference);
            accessPoint.setListener(WifiSettings.this);
            preference.refresh();
        }
    }
    removeCachedPrefs(mAccessPointsPreferenceCategory);
    mAddWifiNetworkPreference.setOrder(index);
    mAccessPointsPreferenceCategory.addPreference(mAddWifiNetworkPreference);
    setAdditionalSettingsSummaries();
    if (!hasAvailableAccessPoints) {
        setProgressBarVisible(true);
        Preference pref = new Preference(getPrefContext());
        pref.setSelectable(false);
        pref.setSummary(R.string.wifi_empty_list_wifi_on);
        pref.setOrder(index++);
        pref.setKey(PREF_KEY_EMPTY_WIFI_LIST);
        mAccessPointsPreferenceCategory.addPreference(pref);
    } else {
        // Continuing showing progress bar for an additional delay to overlap with animation
        getView().postDelayed(mHideProgressBarRunnable, 1700);
    }
}
Also used : AccessPointPreference(com.android.settingslib.wifi.AccessPointPreference) DataUsagePreference(com.android.settings.datausage.DataUsagePreference) Preference(androidx.preference.Preference) AccessPoint(com.android.settingslib.wifi.AccessPoint) AccessPoint(com.android.settingslib.wifi.AccessPoint)

Example 77 with Preference

use of androidx.preference.Preference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DeveloperPreference method onBindViewHolder.

@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
    super.onBindViewHolder(holder);
    mViewHolder = holder;
    if (donateLink != null) {
        final OnClickListener openDonate = new OnClickListener() {

            @Override
            public void onClick(View v) {
                Uri donateURL = Uri.parse(donateLink);
                final Intent intent = new Intent(Intent.ACTION_VIEW, donateURL);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
                getContext().startActivity(intent);
            }
        };
        donateButton.setOnClickListener(openDonate);
    } else {
        donateButton.setVisibility(View.GONE);
    }
    final OnPreferenceClickListener opengplus = new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            if (gplusName != null) {
                Uri gplusURL = Uri.parse("https://plus.google.com/+" + gplusName);
                final Intent intent = new Intent(Intent.ACTION_VIEW, gplusURL);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
                getContext().startActivity(intent);
            }
            if (twitterName != null) {
                Uri twitterURL = Uri.parse("https://twitter.com/" + twitterName);
                final Intent intent = new Intent(Intent.ACTION_VIEW, twitterURL);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
                getContext().startActivity(intent);
            }
            return true;
        }
    };
    // changed to clicking the preference to open gplus
    // it was a hit or miss to click the gplus icon
    this.setOnPreferenceClickListener(opengplus);
    UrlImageViewHelper.setUrlDrawable(this.photoView, getGravatarUrl(devEmail), R.drawable.ic_null, UrlImageViewHelper.CACHE_DURATION_ONE_WEEK);
    if (gplusName == null)
        gplusButton.setVisibility(View.INVISIBLE);
    devName.setText(nameDev);
}
Also used : Preference(androidx.preference.Preference) OnClickListener(android.view.View.OnClickListener) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) Uri(android.net.Uri)

Example 78 with Preference

use of androidx.preference.Preference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class SettingsPreferenceFragmentTest method removePreference_nested_shouldRemove.

@Test
public void removePreference_nested_shouldRemove() {
    final String key = "test_key";
    final PreferenceScreen mScreen = spy(new PreferenceScreen(mContext, null));
    when(mScreen.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
    final PreferenceCategory nestedCategory = new ProgressCategory(mContext);
    final Preference preference = new Preference(mContext);
    preference.setKey(key);
    preference.setPersistent(false);
    mScreen.addPreference(nestedCategory);
    nestedCategory.addPreference(preference);
    assertThat(mFragment.removePreference(mScreen, key)).isTrue();
    assertThat(nestedCategory.getPreferenceCount()).isEqualTo(0);
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) PreferenceCategory(androidx.preference.PreferenceCategory) Preference(androidx.preference.Preference) PreferenceManager(androidx.preference.PreferenceManager) Test(org.junit.Test)

Example 79 with Preference

use of androidx.preference.Preference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class SettingsPreferenceFragmentTest method removePreference_flat_shouldRemove.

@Test
public void removePreference_flat_shouldRemove() {
    final String key = "test_key";
    final PreferenceScreen mScreen = spy(new PreferenceScreen(mContext, null));
    when(mScreen.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
    final Preference preference = mock(Preference.class);
    when(preference.getKey()).thenReturn(key);
    mScreen.addPreference(preference);
    assertThat(mFragment.removePreference(mScreen, key)).isTrue();
    assertThat(mScreen.getPreferenceCount()).isEqualTo(0);
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) Preference(androidx.preference.Preference) PreferenceManager(androidx.preference.PreferenceManager) Test(org.junit.Test)

Example 80 with Preference

use of androidx.preference.Preference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class RecentAppsPreferenceControllerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    final Context context = spy(RuntimeEnvironment.application);
    when(context.getApplicationContext()).thenReturn(context);
    ReflectionHelpers.setStaticField(ApplicationsState.class, "sInstance", mAppState);
    doReturn(mUserManager).when(context).getSystemService(Context.USER_SERVICE);
    doReturn(mPackageManager).when(context).getPackageManager();
    when(mUserManager.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[] {});
    final View appEntitiesHeaderView = LayoutInflater.from(context).inflate(R.layout.app_entities_header, null);
    final Preference dividerPreference = new Preference(context);
    final LayoutPreference recentAppsPreference = spy(new LayoutPreference(context, appEntitiesHeaderView));
    mController = spy(new RecentAppsPreferenceController(context, "test_key"));
    mController.setFragment(mFragment);
    mController.mAppEntitiesController = mock(AppEntitiesHeaderController.class);
    mController.mRecentAppsPreference = recentAppsPreference;
    mController.mDivider = dividerPreference;
    when(mScreen.findPreference(RecentAppsPreferenceController.KEY_DIVIDER)).thenReturn(dividerPreference);
    when(mScreen.findPreference("test_key")).thenReturn(recentAppsPreference);
    when(recentAppsPreference.findViewById(R.id.app_entities_header)).thenReturn(appEntitiesHeaderView);
}
Also used : Context(android.content.Context) LayoutPreference(com.android.settingslib.widget.LayoutPreference) LayoutPreference(com.android.settingslib.widget.LayoutPreference) Preference(androidx.preference.Preference) AppEntitiesHeaderController(com.android.settingslib.widget.AppEntitiesHeaderController) View(android.view.View) Before(org.junit.Before)

Aggregations

Preference (androidx.preference.Preference)863 Test (org.junit.Test)343 Before (org.junit.Before)164 Intent (android.content.Intent)81 PreferenceScreen (androidx.preference.PreferenceScreen)81 NotificationChannel (android.app.NotificationChannel)77 SwitchPreference (androidx.preference.SwitchPreference)75 RestrictedSwitchPreference (com.android.settingslib.RestrictedSwitchPreference)69 Context (android.content.Context)60 ArrayList (java.util.ArrayList)50 NotificationBackend (com.android.settings.notification.NotificationBackend)45 ListPreference (androidx.preference.ListPreference)43 PreferenceCategory (androidx.preference.PreferenceCategory)40 Tile (com.android.settingslib.drawer.Tile)40 PreferenceManager (androidx.preference.PreferenceManager)39 Activity (android.app.Activity)27 UserHandle (android.os.UserHandle)27 FooterPreference (com.android.settingslib.widget.FooterPreference)27 PackageManager (android.content.pm.PackageManager)26 Bundle (android.os.Bundle)24