Remove USB scan button from main activity
This commit is contained in:
@@ -17,9 +17,7 @@ import android.nfc.tech.IsoDep
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.provider.Settings
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.animation.AccelerateDecelerateInterpolator
|
||||
import android.widget.Button
|
||||
import android.widget.LinearLayout
|
||||
@@ -33,8 +31,6 @@ import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.core.view.updatePadding
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import kotlinx.coroutines.*
|
||||
|
||||
@@ -46,7 +42,6 @@ class MainActivity : AppCompatActivity() {
|
||||
private lateinit var statusText: TextView
|
||||
private lateinit var connectionType: TextView
|
||||
private lateinit var resultText: TextView
|
||||
private lateinit var btnScanUsb: Button
|
||||
private lateinit var btnDeviceInfo: Button
|
||||
private lateinit var btnListCredentials: Button
|
||||
private lateinit var btnChangePin: Button
|
||||
@@ -137,7 +132,6 @@ class MainActivity : AppCompatActivity() {
|
||||
statusText = findViewById(R.id.statusText)
|
||||
connectionType = findViewById(R.id.connectionType)
|
||||
resultText = findViewById(R.id.resultText)
|
||||
btnScanUsb = findViewById(R.id.btnScanUsb)
|
||||
btnDeviceInfo = findViewById(R.id.btnDeviceInfo)
|
||||
btnListCredentials = findViewById(R.id.btnListCredentials)
|
||||
btnChangePin = findViewById(R.id.btnChangePin)
|
||||
@@ -157,7 +151,6 @@ class MainActivity : AppCompatActivity() {
|
||||
registerReceiver(usbPermissionReceiver, filter)
|
||||
}
|
||||
|
||||
btnScanUsb.setOnClickListener { scanForUsbDevices() }
|
||||
btnDeviceInfo.setOnClickListener { getDeviceInfo() }
|
||||
btnListCredentials.setOnClickListener { listCredentials() }
|
||||
btnChangePin.setOnClickListener { showChangePinDialog() }
|
||||
@@ -313,28 +306,6 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun scanForUsbDevices() {
|
||||
val devices = usbManager.deviceList.values
|
||||
.filter { UsbTransport.isFidoDevice(it) }
|
||||
|
||||
if (devices.isEmpty()) {
|
||||
AlertDialog.Builder(this)
|
||||
.setTitle(getString(R.string.no_devices_title))
|
||||
.setMessage(getString(R.string.no_devices_message))
|
||||
.setPositiveButton(getString(R.string.ok), null)
|
||||
.show()
|
||||
return
|
||||
}
|
||||
|
||||
if (devices.size == 1) {
|
||||
handleUsbDevice(devices.first())
|
||||
return
|
||||
}
|
||||
|
||||
// Show device selection dialog
|
||||
showDeviceSelectionDialog(devices)
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for already-plugged USB FIDO devices and connect if found.
|
||||
* Only connects if there's exactly one device and we're not already connected.
|
||||
@@ -359,25 +330,6 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun showDeviceSelectionDialog(devices: Collection<UsbDevice>) {
|
||||
val dialogView = layoutInflater.inflate(R.layout.dialog_usb_devices, null)
|
||||
val recyclerView = dialogView.findViewById<RecyclerView>(R.id.deviceList)
|
||||
|
||||
val dialog = AlertDialog.Builder(this)
|
||||
.setTitle(getString(R.string.select_security_key))
|
||||
.setView(dialogView)
|
||||
.setNegativeButton(getString(R.string.cancel), null)
|
||||
.create()
|
||||
|
||||
recyclerView.layoutManager = LinearLayoutManager(this)
|
||||
recyclerView.adapter = UsbDeviceAdapter(devices.toList()) { device ->
|
||||
dialog.dismiss()
|
||||
handleUsbDevice(device)
|
||||
}
|
||||
|
||||
dialog.show()
|
||||
}
|
||||
|
||||
private fun requestUsbPermission(device: UsbDevice) {
|
||||
usbPermissionRequested = true
|
||||
|
||||
@@ -1162,37 +1114,3 @@ class MainActivity : AppCompatActivity() {
|
||||
private const val PREF_USE_NUMERIC_KEYBOARD = "use_numeric_keyboard"
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* RecyclerView adapter for USB device selection
|
||||
*/
|
||||
class UsbDeviceAdapter(
|
||||
private val devices: List<UsbDevice>,
|
||||
private val onSelect: (UsbDevice) -> Unit
|
||||
) : RecyclerView.Adapter<UsbDeviceAdapter.ViewHolder>() {
|
||||
|
||||
class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||
val name: TextView = view.findViewById(R.id.deviceName)
|
||||
val info: TextView = view.findViewById(R.id.deviceInfo)
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
val view = LayoutInflater.from(parent.context)
|
||||
.inflate(R.layout.item_usb_device, parent, false)
|
||||
return ViewHolder(view)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
val device = devices[position]
|
||||
val context = holder.itemView.context
|
||||
holder.name.text = device.productName ?: context.getString(R.string.unknown_device)
|
||||
holder.info.text = context.getString(
|
||||
R.string.device_info_format,
|
||||
String.format("%04X", device.vendorId),
|
||||
String.format("%04X", device.productId)
|
||||
)
|
||||
holder.itemView.setOnClickListener { onSelect(device) }
|
||||
}
|
||||
|
||||
override fun getItemCount() = devices.size
|
||||
}
|
||||
|
||||
@@ -57,13 +57,6 @@
|
||||
android:gravity="center"
|
||||
android:textColor="?android:attr/textColorSecondary" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnScanUsb"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:text="Scan for USB Devices" />
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/noDevicesText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="No USB devices found"
|
||||
android:visibility="gone"
|
||||
android:gravity="center"
|
||||
android:padding="16dp" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/deviceList"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -1,23 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="12dp"
|
||||
android:background="?attr/selectableItemBackground">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/deviceName"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/deviceInfo"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="12sp"
|
||||
android:textColor="#666666" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -89,10 +89,7 @@
|
||||
<string name="security_key_detected">Security key detected</string>
|
||||
<string name="nfc_error">NFC Error: %1$s</string>
|
||||
<string name="usb_error">USB Error: %1$s</string>
|
||||
<string name="no_devices_title">No Devices Found</string>
|
||||
<string name="no_devices_message">No FIDO security keys detected.\n\nMake sure your security key is plugged in.</string>
|
||||
<string name="ok">OK</string>
|
||||
<string name="select_security_key">Select Security Key</string>
|
||||
<string name="connecting_usb">Connecting to USB device…</string>
|
||||
<string name="using_nfc">Using NFC</string>
|
||||
<string name="using_usb">Using USB</string>
|
||||
@@ -241,8 +238,6 @@
|
||||
<string name="btn_show_device_status">Show Device Status</string>
|
||||
<string name="btn_list_credentials">List Saved Credentials</string>
|
||||
<string name="btn_change_pin">Change PIN</string>
|
||||
<string name="unknown_device">Unknown Device</string>
|
||||
<string name="device_info_format">VID: %1$s, PID: %2$s</string>
|
||||
|
||||
<!-- Credentials Dialog -->
|
||||
<string name="credentials_dialog_title">Stored Credentials</string>
|
||||
|
||||
Reference in New Issue
Block a user