Search in sources :

Example 31 with RadioButtonPreference

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

the class UsbDefaultFragment method refresh.

private void refresh(long functions) {
    final PreferenceScreen screen = getPreferenceScreen();
    for (long option : UsbDetailsFunctionsController.FUNCTIONS_MAP.keySet()) {
        final RadioButtonPreference pref = screen.findPreference(UsbBackend.usbFunctionsToString(option));
        if (pref != null) {
            final boolean isSupported = mUsbBackend.areFunctionsSupported(option);
            pref.setEnabled(isSupported);
            if (isSupported) {
                if (functions == UsbManager.FUNCTION_NCM) {
                    pref.setChecked(UsbManager.FUNCTION_RNDIS == option);
                } else {
                    pref.setChecked(functions == option);
                }
            }
        }
    }
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) RadioButtonPreference(com.android.settingslib.widget.RadioButtonPreference)

Example 32 with RadioButtonPreference

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

the class UsbDetailsDataRoleController method makeRadioPreference.

private RadioButtonPreference makeRadioPreference(String key, int titleId) {
    RadioButtonPreference pref = new RadioButtonPreference(mPreferenceCategory.getContext());
    pref.setKey(key);
    pref.setTitle(titleId);
    pref.setOnClickListener(this);
    mPreferenceCategory.addPreference(pref);
    return pref;
}
Also used : RadioButtonPreference(com.android.settingslib.widget.RadioButtonPreference)

Example 33 with RadioButtonPreference

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

the class UsbDetailsFunctionsController method onRadioButtonClicked.

@Override
public void onRadioButtonClicked(RadioButtonPreference preference) {
    final long function = UsbBackend.usbFunctionsFromString(preference.getKey());
    final long previousFunction = mUsbBackend.getCurrentFunctions();
    if (DEBUG) {
        Log.d(TAG, "onRadioButtonClicked() function : " + function + ", toString() : " + UsbManager.usbFunctionsToString(function) + ", previousFunction : " + previousFunction + ", toString() : " + UsbManager.usbFunctionsToString(previousFunction));
    }
    if (function != previousFunction && !Utils.isMonkeyRunning() && !isClickEventIgnored(function, previousFunction)) {
        mPreviousFunction = previousFunction;
        // Update the UI in advance to make it looks smooth
        final RadioButtonPreference prevPref = (RadioButtonPreference) mProfilesContainer.findPreference(UsbBackend.usbFunctionsToString(mPreviousFunction));
        if (prevPref != null) {
            prevPref.setChecked(false);
            preference.setChecked(true);
        }
        if (function == UsbManager.FUNCTION_RNDIS || function == UsbManager.FUNCTION_NCM) {
            // We need to have entitlement check for usb tethering, so use API in
            // TetheringManager.
            mTetheringManager.startTethering(TetheringManager.TETHERING_USB, new HandlerExecutor(mHandler), mOnStartTetheringCallback);
        } else {
            mUsbBackend.setCurrentFunctions(function);
        }
    }
}
Also used : HandlerExecutor(android.os.HandlerExecutor) RadioButtonPreference(com.android.settingslib.widget.RadioButtonPreference)

Example 34 with RadioButtonPreference

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

the class UsbDetailsFunctionsController method refresh.

@Override
protected void refresh(boolean connected, long functions, int powerRole, int dataRole) {
    if (DEBUG) {
        Log.d(TAG, "refresh() connected : " + connected + ", functions : " + functions + ", powerRole : " + powerRole + ", dataRole : " + dataRole);
    }
    if (!connected || dataRole != DATA_ROLE_DEVICE) {
        mProfilesContainer.setEnabled(false);
    } else {
        // Functions are only available in device mode
        mProfilesContainer.setEnabled(true);
    }
    RadioButtonPreference pref;
    for (long option : FUNCTIONS_MAP.keySet()) {
        int title = FUNCTIONS_MAP.get(option);
        pref = getProfilePreference(UsbBackend.usbFunctionsToString(option), title);
        // Only show supported options
        if (mUsbBackend.areFunctionsSupported(option)) {
            if (isAccessoryMode(functions)) {
                pref.setChecked(UsbManager.FUNCTION_MTP == option);
            } else if (functions == UsbManager.FUNCTION_NCM) {
                pref.setChecked(UsbManager.FUNCTION_RNDIS == option);
            } else {
                pref.setChecked(functions == option);
            }
        } else {
            mProfilesContainer.removePreference(pref);
        }
    }
}
Also used : RadioButtonPreference(com.android.settingslib.widget.RadioButtonPreference)

Example 35 with RadioButtonPreference

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

the class OptimizedPreferenceControllerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mController = new OptimizedPreferenceController(RuntimeEnvironment.application, UID, PACKAGE_NAME);
    mPreference = new RadioButtonPreference(RuntimeEnvironment.application);
    mController.mBatteryOptimizeUtils = mockBatteryOptimizeUtils;
}
Also used : RadioButtonPreference(com.android.settingslib.widget.RadioButtonPreference) Before(org.junit.Before)

Aggregations

RadioButtonPreference (com.android.settingslib.widget.RadioButtonPreference)52 Test (org.junit.Test)27 Before (org.junit.Before)8 DefaultAppInfo (com.android.settingslib.applications.DefaultAppInfo)6 PreferenceScreen (androidx.preference.PreferenceScreen)5 CandidateInfo (com.android.settingslib.widget.CandidateInfo)3 Preference (androidx.preference.Preference)2 PreferenceCategory (androidx.preference.PreferenceCategory)2 Lifecycle (com.android.settingslib.core.lifecycle.Lifecycle)2 FooterPreference (com.android.settingslib.widget.FooterPreference)2 AppOpsManager (android.app.AppOpsManager)1 SettingsEnums (android.app.settings.SettingsEnums)1 Context (android.content.Context)1 Intent (android.content.Intent)1 ApplicationInfo (android.content.pm.ApplicationInfo)1 PackageManager (android.content.pm.PackageManager)1 Resources (android.content.res.Resources)1 Drawable (android.graphics.drawable.Drawable)1 BatteryStats (android.os.BatteryStats)1 Bundle (android.os.Bundle)1