BluetoothDevicePreference -> kt
This commit is contained in:
parent
bf5d0916ec
commit
bfb556bb20
1 changed files with 18 additions and 31 deletions
|
@ -1,35 +1,22 @@
|
||||||
package info.nightscout.androidaps.danar;
|
package info.nightscout.androidaps.danar
|
||||||
|
|
||||||
import android.bluetooth.*;
|
import kotlin.jvm.JvmOverloads
|
||||||
import android.content.Context;
|
import android.bluetooth.BluetoothAdapter
|
||||||
import androidx.preference.ListPreference;
|
import android.bluetooth.BluetoothDevice
|
||||||
import android.util.AttributeSet;
|
import android.bluetooth.BluetoothManager
|
||||||
|
import android.content.Context
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import androidx.preference.ListPreference
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
import java.util.Set;
|
class BluetoothDevicePreference @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : ListPreference(context, attrs) {
|
||||||
import java.util.Vector;
|
init {
|
||||||
|
val entries = Vector<CharSequence>()
|
||||||
public class BluetoothDevicePreference extends ListPreference {
|
(context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager?)?.adapter?.let { bta ->
|
||||||
|
for (dev in bta.bondedDevices)
|
||||||
public BluetoothDevicePreference(Context context, AttributeSet attrs) {
|
dev.name?.let { name -> entries.add(name) }
|
||||||
super(context, attrs);
|
|
||||||
|
|
||||||
BluetoothAdapter bta = BluetoothAdapter.getDefaultAdapter();
|
|
||||||
Vector<CharSequence> entries = new Vector<CharSequence>();
|
|
||||||
if (bta != null) {
|
|
||||||
Set<BluetoothDevice> pairedDevices = bta.getBondedDevices();
|
|
||||||
for (BluetoothDevice dev : pairedDevices) {
|
|
||||||
String name = dev.getName();
|
|
||||||
if(name != null) {
|
|
||||||
entries.add(name);
|
|
||||||
}
|
}
|
||||||
|
setEntries(entries.toTypedArray())
|
||||||
|
entryValues = entries.toTypedArray()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
setEntries(entries.toArray(new CharSequence[0]));
|
|
||||||
setEntryValues(entries.toArray(new CharSequence[0]));
|
|
||||||
}
|
|
||||||
|
|
||||||
public BluetoothDevicePreference(Context context) {
|
|
||||||
this(context, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue