Search in sources :

Example 31 with PreferenceScreen

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

the class DashboardFragment method updatePreferenceStatesInParallel.

/**
 * Use parallel method to update state of each preference managed by PreferenceController.
 */
@VisibleForTesting
// the thumb sliding of the toggle button.
void updatePreferenceStatesInParallel() {
    final PreferenceScreen screen = getPreferenceScreen();
    final Collection<List<AbstractPreferenceController>> controllerLists = mPreferenceControllers.values();
    final List<ControllerFutureTask> taskList = new ArrayList<>();
    for (List<AbstractPreferenceController> controllerList : controllerLists) {
        for (AbstractPreferenceController controller : controllerList) {
            final ControllerFutureTask task = new ControllerFutureTask(new ControllerTask(controller, screen, mMetricsFeatureProvider, getMetricsCategory()), null);
            taskList.add(task);
            ThreadUtils.postOnBackgroundThread(task);
        }
    }
    for (ControllerFutureTask task : taskList) {
        try {
            task.get();
        } catch (InterruptedException | ExecutionException e) {
            Log.w(TAG, task.getController().getPreferenceKey() + " " + e.getMessage());
        }
    }
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) AbstractPreferenceController(com.android.settingslib.core.AbstractPreferenceController) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ExecutionException(java.util.concurrent.ExecutionException) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 32 with PreferenceScreen

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

the class PublicVolumeSettings method update.

public void update() {
    if (!isVolumeValid()) {
        getActivity().finish();
        return;
    }
    getActivity().setTitle(mStorageManager.getBestVolumeDescription(mVolume));
    final Context context = getActivity();
    final PreferenceScreen screen = getPreferenceScreen();
    screen.removeAll();
    if (mVolume.isMountedReadable()) {
        addPreference(mSummary);
        final File file = mVolume.getPath();
        final long totalBytes = file.getTotalSpace();
        final long freeBytes = file.getFreeSpace();
        final long usedBytes = totalBytes - freeBytes;
        final Formatter.BytesResult result = Formatter.formatBytes(getResources(), usedBytes, 0);
        mSummary.setTitle(TextUtils.expandTemplate(getText(R.string.storage_size_large), result.value, result.units));
        mSummary.setSummary(getString(R.string.storage_volume_used, Formatter.formatFileSize(context, totalBytes)));
        mSummary.setPercent(usedBytes, totalBytes);
    }
    if (mVolume.getState() == VolumeInfo.STATE_UNMOUNTED) {
        addPreference(mMount);
    }
    if (!mVolume.isMountedReadable()) {
        mUnmount.setVisibility(View.GONE);
    }
    addPreference(mFormatPublic);
    if (mDisk.isAdoptable() && mIsPermittedToAdopt) {
        addPreference(mFormatPrivate);
    }
}
Also used : Context(android.content.Context) PreferenceScreen(androidx.preference.PreferenceScreen) Formatter(android.text.format.Formatter) File(java.io.File)

Example 33 with PreferenceScreen

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

the class MagnificationSettingsFragmentTest method setup.

@Before
public void setup() {
    mContext.setTheme(R.style.Theme_AppCompat);
    mFragment = spy(new MagnificationSettingsFragment());
    mScreen = new PreferenceScreen(mContext, null);
    doReturn(mContext).when(mFragment).getContext();
    doReturn(mScreen).when(mFragment).getPreferenceScreen();
    doReturn(mock(FragmentManager.class, Answers.RETURNS_DEEP_STUBS)).when(mFragment).getChildFragmentManager();
}
Also used : FragmentManager(androidx.fragment.app.FragmentManager) PreferenceScreen(androidx.preference.PreferenceScreen) Before(org.junit.Before)

Example 34 with PreferenceScreen

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

the class WifiCallingSettingsForSub method updateButtonWfcMode.

private void updateButtonWfcMode(boolean wfcEnabled, int wfcMode, int wfcRoamingMode) {
    mButtonWfcMode.setSummary(getWfcModeSummary(wfcMode));
    mButtonWfcMode.setEnabled(wfcEnabled && mEditableWfcMode);
    // mButtonWfcRoamingMode.setSummary is not needed; summary is just selected value.
    mButtonWfcRoamingMode.setEnabled(wfcEnabled && mEditableWfcRoamingMode);
    final PreferenceScreen preferenceScreen = getPreferenceScreen();
    final boolean updateAddressEnabled = (getCarrierActivityIntent() != null);
    if (wfcEnabled) {
        if (mEditableWfcMode) {
            preferenceScreen.addPreference(mButtonWfcMode);
        } else {
            // Don't show WFC (home) preference if it's not editable.
            preferenceScreen.removePreference(mButtonWfcMode);
        }
        if (mEditableWfcRoamingMode && !mUseWfcHomeModeForRoaming) {
            preferenceScreen.addPreference(mButtonWfcRoamingMode);
        } else {
            // Don't show WFC roaming preference if it's not editable.
            preferenceScreen.removePreference(mButtonWfcRoamingMode);
        }
        if (updateAddressEnabled) {
            preferenceScreen.addPreference(mUpdateAddress);
        } else {
            preferenceScreen.removePreference(mUpdateAddress);
        }
    } else {
        preferenceScreen.removePreference(mButtonWfcMode);
        preferenceScreen.removePreference(mButtonWfcRoamingMode);
        preferenceScreen.removePreference(mUpdateAddress);
    }
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen)

Example 35 with PreferenceScreen

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

the class WifiP2pSettings method onResume.

@Override
public void onResume() {
    super.onResume();
    mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION);
    mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION);
    mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
    mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION);
    mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_DISCOVERY_CHANGED_ACTION);
    mIntentFilter.addAction(WifiP2pManager.ACTION_WIFI_P2P_PERSISTENT_GROUPS_CHANGED);
    final PreferenceScreen preferenceScreen = getPreferenceScreen();
    if (mWifiP2pManager != null && initChannel()) {
        // Register receiver after make sure channel exist
        getActivity().registerReceiver(mReceiver, mIntentFilter);
        mWifiP2pManager.requestPeers(mChannel, WifiP2pSettings.this);
        mWifiP2pManager.requestDeviceInfo(mChannel, WifiP2pSettings.this);
        mIsIgnoreInitConnectionInfoCallback = false;
        mWifiP2pManager.requestNetworkInfo(mChannel, networkInfo -> {
            mWifiP2pManager.requestConnectionInfo(mChannel, wifip2pinfo -> {
                if (!mIsIgnoreInitConnectionInfoCallback) {
                    if (networkInfo.isConnected()) {
                        if (DBG) {
                            Log.d(TAG, "Connected");
                        }
                    } else if (!mLastGroupFormed) {
                        // Find peers when p2p doesn't connected.
                        startSearch();
                    }
                    mLastGroupFormed = wifip2pinfo.groupFormed;
                }
            });
        });
    }
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen)

Aggregations

PreferenceScreen (androidx.preference.PreferenceScreen)244 Preference (androidx.preference.Preference)81 Test (org.junit.Test)60 Context (android.content.Context)36 PreferenceManager (androidx.preference.PreferenceManager)36 ContentResolver (android.content.ContentResolver)25 PreferenceCategory (androidx.preference.PreferenceCategory)24 Bundle (android.os.Bundle)20 ArrayList (java.util.ArrayList)20 SwitchPreference (androidx.preference.SwitchPreference)19 Resources (android.content.res.Resources)18 Before (org.junit.Before)17 ListPreference (androidx.preference.ListPreference)14 PackageManager (android.content.pm.PackageManager)13 PreferenceGroup (androidx.preference.PreferenceGroup)13 ApplicationInfo (android.content.pm.ApplicationInfo)9 VisibleForTesting (androidx.annotation.VisibleForTesting)9 List (java.util.List)9 UserManager (android.os.UserManager)8 StorageItemPreference (com.android.settings.deviceinfo.StorageItemPreference)8