feat: add action icons
This commit is contained in:
@@ -14,7 +14,7 @@ import androidx.recyclerview.widget.RecyclerView
|
||||
|
||||
interface Action {
|
||||
fun getLabel(): String
|
||||
fun getIcon(): String
|
||||
fun getIcon(): Int?
|
||||
fun execute(): Unit
|
||||
}
|
||||
|
||||
@@ -70,6 +70,7 @@ class DeviceListAdapter(
|
||||
deviceActions = view.findViewById(R.id.device_actions)
|
||||
}
|
||||
|
||||
@SuppressLint("RestrictedApi")
|
||||
fun bind(result: DeviceListEntry) {
|
||||
deviceNameView.text = result.name ?: "<N/A>"
|
||||
macAddressView.text = result.address
|
||||
@@ -90,13 +91,18 @@ class DeviceListAdapter(
|
||||
deviceActions.setOnClickListener {
|
||||
val popup = PopupMenu(context, deviceActions)
|
||||
result.getActions().forEach { action ->
|
||||
popup.menu.add(action.getLabel())
|
||||
.setOnMenuItemClickListener { menuItem ->
|
||||
action.execute()
|
||||
true
|
||||
}
|
||||
val menuItem = popup.menu.add(action.getLabel())
|
||||
menuItem.setOnMenuItemClickListener { item ->
|
||||
action.execute()
|
||||
true
|
||||
}
|
||||
val menuIcon = action.getIcon()
|
||||
if (menuIcon != null) {
|
||||
menuItem.setIcon(menuIcon)
|
||||
}
|
||||
}
|
||||
val inflater = popup.menuInflater
|
||||
popup.setForceShowIcon(true)
|
||||
inflater.inflate(R.menu.device_menu, popup.menu)
|
||||
popup.show()
|
||||
}
|
||||
|
||||
@@ -195,8 +195,8 @@ class KirbyDevice(
|
||||
return "Connect"
|
||||
}
|
||||
|
||||
override fun getIcon(): String {
|
||||
return ""
|
||||
override fun getIcon(): Int {
|
||||
return R.drawable.action_icon_connect
|
||||
}
|
||||
|
||||
override fun execute() {
|
||||
@@ -213,8 +213,8 @@ class KirbyDevice(
|
||||
return "Disconnect"
|
||||
}
|
||||
|
||||
override fun getIcon(): String {
|
||||
return ""
|
||||
override fun getIcon(): Int {
|
||||
return R.drawable.action_icon_disconnect
|
||||
}
|
||||
|
||||
override fun execute() {
|
||||
@@ -227,8 +227,8 @@ class KirbyDevice(
|
||||
return "Fetch Measurement"
|
||||
}
|
||||
|
||||
override fun getIcon(): String {
|
||||
TODO("Not yet implemented")
|
||||
override fun getIcon(): Int {
|
||||
return R.drawable.action_icon_fetch_measurement
|
||||
}
|
||||
|
||||
override fun execute() {
|
||||
@@ -242,8 +242,8 @@ class KirbyDevice(
|
||||
return "Subscribe"
|
||||
}
|
||||
|
||||
override fun getIcon(): String {
|
||||
return ""
|
||||
override fun getIcon(): Int {
|
||||
return R.drawable.action_icon_subscribe
|
||||
}
|
||||
|
||||
override fun execute() {
|
||||
@@ -261,8 +261,8 @@ class KirbyDevice(
|
||||
return "Unsubscribe"
|
||||
}
|
||||
|
||||
override fun getIcon(): String {
|
||||
return ""
|
||||
override fun getIcon(): Int {
|
||||
return R.drawable.action_icon_subscribe_disable
|
||||
}
|
||||
|
||||
override fun execute() {
|
||||
|
||||
@@ -121,6 +121,9 @@ class MainActivity : AppCompatActivity() {
|
||||
override fun onScanningStateChange(isScanning: Boolean) {
|
||||
runOnUiThread {
|
||||
binding.fab.setText(if (isScanning) "Stop Scan" else "Start Scan")
|
||||
binding.fab.setIconResource(
|
||||
if (isScanning) R.drawable.action_icon_disconnect else R.drawable.action_icon_scan
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -338,8 +341,8 @@ class DummyListEntry(override val address: String) : DeviceListEntry {
|
||||
return "Test action 1"
|
||||
}
|
||||
|
||||
override fun getIcon(): String {
|
||||
return ""
|
||||
override fun getIcon(): Int? {
|
||||
return R.drawable.action_icon_disconnect
|
||||
}
|
||||
|
||||
override fun execute() {
|
||||
@@ -350,8 +353,8 @@ class DummyListEntry(override val address: String) : DeviceListEntry {
|
||||
return "Test action 2"
|
||||
}
|
||||
|
||||
override fun getIcon(): String {
|
||||
return ""
|
||||
override fun getIcon(): Int? {
|
||||
return R.drawable.action_icon_connect
|
||||
}
|
||||
|
||||
override fun execute() {
|
||||
|
||||
5
app/src/main/res/drawable/action_icon_connect.xml
Normal file
5
app/src/main/res/drawable/action_icon_connect.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<vector android:height="24dp" android:tint="#000000"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M7,12l-2,-2 -2,2 2,2 2,-2zM17.71,7.71L12,2h-1v7.59L6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 11,14.41L11,22h1l5.71,-5.71 -4.3,-4.29 4.3,-4.29zM13,5.83l1.88,1.88L13,9.59L13,5.83zM14.88,16.29L13,18.17v-3.76l1.88,1.88zM19,10l-2,2 2,2 2,-2 -2,-2z"/>
|
||||
</vector>
|
||||
5
app/src/main/res/drawable/action_icon_disconnect.xml
Normal file
5
app/src/main/res/drawable/action_icon_disconnect.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<vector android:height="24dp" android:tint="#000000"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M13,5.83l1.88,1.88 -1.6,1.6 1.41,1.41 3.02,-3.02L12,2h-1v5.03l2,2v-3.2zM5.41,4L4,5.41 10.59,12 5,17.59 6.41,19 11,14.41V22h1l4.29,-4.29 2.3,2.29L20,18.59 5.41,4zM13,18.17v-3.76l1.88,1.88L13,18.17z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,5 @@
|
||||
<vector android:height="24dp" android:tint="#000000"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M7.41,8.59L12,13.17l4.59,-4.58L18,10l-6,6 -6,-6 1.41,-1.41z"/>
|
||||
</vector>
|
||||
5
app/src/main/res/drawable/action_icon_scan.xml
Normal file
5
app/src/main/res/drawable/action_icon_scan.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<vector android:autoMirrored="true" android:height="24dp"
|
||||
android:tint="#000000" android:viewportHeight="24"
|
||||
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M14.24,12.01l2.32,2.32c0.28,-0.72 0.44,-1.51 0.44,-2.33 0,-0.82 -0.16,-1.59 -0.43,-2.31l-2.33,2.32zM19.53,6.71l-1.26,1.26c0.63,1.21 0.98,2.57 0.98,4.02s-0.36,2.82 -0.98,4.02l1.2,1.2c0.97,-1.54 1.54,-3.36 1.54,-5.31 -0.01,-1.89 -0.55,-3.67 -1.48,-5.19zM15.71,7.71L10,2L9,2v7.59L4.41,5 3,6.41 8.59,12 3,17.59 4.41,19 9,14.41L9,22h1l5.71,-5.71 -4.3,-4.29 4.3,-4.29zM11,5.83l1.88,1.88L11,9.59L11,5.83zM12.88,16.29L11,18.17v-3.76l1.88,1.88z"/>
|
||||
</vector>
|
||||
5
app/src/main/res/drawable/action_icon_subscribe.xml
Normal file
5
app/src/main/res/drawable/action_icon_subscribe.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<vector android:height="24dp" android:tint="#000000"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M12,4L12,1L8,5l4,4L12,6c3.31,0 6,2.69 6,6 0,1.01 -0.25,1.97 -0.7,2.8l1.46,1.46C19.54,15.03 20,13.57 20,12c0,-4.42 -3.58,-8 -8,-8zM12,18c-3.31,0 -6,-2.69 -6,-6 0,-1.01 0.25,-1.97 0.7,-2.8L5.24,7.74C4.46,8.97 4,10.43 4,12c0,4.42 3.58,8 8,8v3l4,-4 -4,-4v3z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,5 @@
|
||||
<vector android:height="24dp" android:tint="#000000"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M10,6.35L10,4.26c-0.8,0.21 -1.55,0.54 -2.23,0.96l1.46,1.46c0.25,-0.12 0.5,-0.24 0.77,-0.33zM2.86,5.41l2.36,2.36C4.45,8.99 4,10.44 4,12c0,2.21 0.91,4.2 2.36,5.64L4,20h6v-6l-2.24,2.24C6.68,15.15 6,13.66 6,12c0,-1 0.25,-1.94 0.68,-2.77l8.08,8.08c-0.25,0.13 -0.5,0.25 -0.77,0.34v2.09c0.8,-0.21 1.55,-0.54 2.23,-0.96l2.36,2.36 1.27,-1.27L4.14,4.14 2.86,5.41zM20,4h-6v6l2.24,-2.24C17.32,8.85 18,10.34 18,12c0,1 -0.25,1.94 -0.68,2.77l1.46,1.46C19.55,15.01 20,13.56 20,12c0,-2.21 -0.91,-4.2 -2.36,-5.64L20,4z"/>
|
||||
</vector>
|
||||
@@ -33,12 +33,13 @@
|
||||
|
||||
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
|
||||
android:id="@+id/fab"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="150dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_marginEnd="@dimen/fab_margin"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:text='Scan'
|
||||
android:text='Start Scan'
|
||||
app:icon="@drawable/action_icon_scan"
|
||||
app:srcCompat="@android:drawable/stat_sys_data_bluetooth" />
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
Reference in New Issue
Block a user