Search in sources :

Example 36 with CachedBluetoothDevice

use of com.android.settingslib.bluetooth.CachedBluetoothDevice in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class BluetoothDevicesSlice method getConnectedBluetoothDevices.

@VisibleForTesting
List<CachedBluetoothDevice> getConnectedBluetoothDevices() {
    final List<CachedBluetoothDevice> bluetoothDeviceList = new ArrayList<>();
    // If Bluetooth is disable, skip to get the Bluetooth devices.
    if (!BluetoothAdapter.getDefaultAdapter().isEnabled()) {
        Log.i(TAG, "Cannot get Bluetooth devices, Bluetooth is disabled.");
        return bluetoothDeviceList;
    }
    // Get the Bluetooth devices from LocalBluetoothManager.
    final LocalBluetoothManager bluetoothManager = com.android.settings.bluetooth.Utils.getLocalBtManager(mContext);
    if (bluetoothManager == null) {
        Log.i(TAG, "Cannot get Bluetooth devices, Bluetooth is unsupported.");
        return bluetoothDeviceList;
    }
    final Collection<CachedBluetoothDevice> cachedDevices = bluetoothManager.getCachedDeviceManager().getCachedDevicesCopy();
    // Get all connected devices and sort them.
    return cachedDevices.stream().filter(device -> device.getDevice().isConnected()).sorted(COMPARATOR).collect(Collectors.toList());
}
Also used : CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice) ArrayList(java.util.ArrayList) LocalBluetoothManager(com.android.settingslib.bluetooth.LocalBluetoothManager) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Example 37 with CachedBluetoothDevice

use of com.android.settingslib.bluetooth.CachedBluetoothDevice in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class BluetoothDeviceUpdater method addPreference.

/**
 * Add the {@link Preference} that represents the {@code cachedDevice}
 */
protected void addPreference(CachedBluetoothDevice cachedDevice) {
    final BluetoothDevice device = cachedDevice.getDevice();
    if (!mPreferenceMap.containsKey(device)) {
        BluetoothDevicePreference btPreference = new BluetoothDevicePreference(mPrefContext, cachedDevice, true);
        btPreference.setOnGearClickListener(mDeviceProfilesListener);
        if (this instanceof Preference.OnPreferenceClickListener) {
            btPreference.setOnPreferenceClickListener((Preference.OnPreferenceClickListener) this);
        }
        mPreferenceMap.put(device, btPreference);
        mDevicePreferenceCallback.onDeviceAdded(btPreference);
    }
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice) GearPreference(com.android.settings.widget.GearPreference) Preference(androidx.preference.Preference)

Example 38 with CachedBluetoothDevice

use of com.android.settingslib.bluetooth.CachedBluetoothDevice in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class BluetoothDeviceUpdater method launchDeviceDetails.

/**
 * Get {@link CachedBluetoothDevice} from {@link Preference} and it is used to init
 * {@link SubSettingLauncher} to launch {@link BluetoothDeviceDetailsFragment}
 */
protected void launchDeviceDetails(Preference preference) {
    final CachedBluetoothDevice device = ((BluetoothDevicePreference) preference).getBluetoothDevice();
    if (device == null) {
        return;
    }
    final Bundle args = new Bundle();
    args.putString(BluetoothDeviceDetailsFragment.KEY_DEVICE_ADDRESS, device.getDevice().getAddress());
    new SubSettingLauncher(mFragment.getContext()).setDestination(BluetoothDeviceDetailsFragment.class.getName()).setArguments(args).setTitleRes(R.string.device_details_title).setSourceMetricsCategory(mFragment.getMetricsCategory()).launch();
}
Also used : CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice) SubSettingLauncher(com.android.settings.core.SubSettingLauncher) Bundle(android.os.Bundle)

Example 39 with CachedBluetoothDevice

use of com.android.settingslib.bluetooth.CachedBluetoothDevice in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ConnectedBluetoothDeviceUpdater method addPreference.

@Override
protected void addPreference(CachedBluetoothDevice cachedDevice) {
    super.addPreference(cachedDevice);
    final BluetoothDevice device = cachedDevice.getDevice();
    if (mPreferenceMap.containsKey(device)) {
        final BluetoothDevicePreference btPreference = (BluetoothDevicePreference) mPreferenceMap.get(device);
        btPreference.setOnGearClickListener(null);
        btPreference.hideSecondTarget(true);
        btPreference.setOnPreferenceClickListener((Preference p) -> {
            launchDeviceDetails(p);
            return true;
        });
    }
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice) Preference(androidx.preference.Preference)

Example 40 with CachedBluetoothDevice

use of com.android.settingslib.bluetooth.CachedBluetoothDevice in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DevicePickerFragment method onDeviceBondStateChanged.

public void onDeviceBondStateChanged(CachedBluetoothDevice cachedDevice, int bondState) {
    BluetoothDevice device = cachedDevice.getDevice();
    if (!device.equals(mSelectedDevice)) {
        return;
    }
    if (bondState == BluetoothDevice.BOND_BONDED) {
        sendDevicePickedIntent(device);
        finish();
    } else if (bondState == BluetoothDevice.BOND_NONE) {
        enableScanning();
    }
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice)

Aggregations

CachedBluetoothDevice (com.android.settingslib.bluetooth.CachedBluetoothDevice)85 BluetoothDevice (android.bluetooth.BluetoothDevice)29 LocalBluetoothManager (com.android.settingslib.bluetooth.LocalBluetoothManager)29 CachedBluetoothDeviceManager (com.android.settingslib.bluetooth.CachedBluetoothDeviceManager)14 VisibleForTesting (com.android.internal.annotations.VisibleForTesting)13 DialogInterface (android.content.DialogInterface)7 OnClickListener (android.view.View.OnClickListener)7 MapProfile (com.android.settingslib.bluetooth.MapProfile)7 Intent (android.content.Intent)3 VisibleForTesting (androidx.annotation.VisibleForTesting)3 Preference (androidx.preference.Preference)2 LocalBluetoothProfile (com.android.settingslib.bluetooth.LocalBluetoothProfile)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 IntentFilter (android.content.IntentFilter)1 Bundle (android.os.Bundle)1 ListBuilder (androidx.slice.builders.ListBuilder)1 SubSettingLauncher (com.android.settings.core.SubSettingLauncher)1 GearPreference (com.android.settings.widget.GearPreference)1 PbapServerProfile (com.android.settingslib.bluetooth.PbapServerProfile)1