Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Stefan Zabka
Companion App Android
Commits
36061730
Commit
36061730
authored
Aug 21, 2019
by
Andreas Schildbach
Browse files
ScannerFragment.kt: Status bar, showing bonding state.
parent
3c5580b1
Pipeline
#2596
failed with stage
in 4 minutes and 20 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/de/ccc/events/badge/card10/scanner/ScannerFragment.kt
View file @
36061730
...
...
@@ -35,6 +35,8 @@ import android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
androidx.fragment.app.Fragment
import
androidx.lifecycle.Observer
import
androidx.lifecycle.ViewModelProviders
import
androidx.recyclerview.widget.LinearLayoutManager
import
de.ccc.events.badge.card10.CARD10_BLUETOOTH_MAC_PREFIX
import
de.ccc.events.badge.card10.R
...
...
@@ -44,6 +46,7 @@ class ScannerFragment : Fragment() {
lateinit
var
bluetoothAdapter
:
BluetoothAdapter
val
listAdapter
=
ScannerListAdapter
({
device
:
Device
->
deviceClicked
(
device
)
})
val
viewModel
:
ScannerViewModel
by
lazy
{
ViewModelProviders
.
of
(
this
).
get
(
ScannerViewModel
::
class
.
java
)
}
val
callback
=
object
:
ScanCallback
()
{
override
fun
onScanResult
(
callbackType
:
Int
,
result
:
ScanResult
)
{
...
...
@@ -67,13 +70,18 @@ class ScannerFragment : Fragment() {
override
fun
onReceive
(
context
:
Context
,
intent
:
Intent
)
{
val
bondState
=
intent
.
extras
!!
.
getInt
(
BluetoothDevice
.
EXTRA_BOND_STATE
)
val
device
=
intent
.
extras
!!
.
getParcelable
(
BluetoothDevice
.
EXTRA_DEVICE
)
as
BluetoothDevice
?
System
.
out
.
println
(
"=== onReceive ${intent.action} ${if (bondState == BluetoothDevice.BOND_NONE) "
NONE
" else if (bondState == BluetoothDevice.BOND_BONDING) "
BONDING
" else if (bondState == BluetoothDevice.BOND_BONDED) "
BONDED
" else bondState} ${device}"
)
viewModel
.
status
.
value
=
if
(
bondState
==
BluetoothDevice
.
BOND_NONE
)
"NONE"
else
if
(
bondState
==
BluetoothDevice
.
BOND_BONDING
)
"BONDING"
else
if
(
bondState
==
BluetoothDevice
.
BOND_BONDED
)
"BONDED"
else
null
System
.
out
.
println
(
"=== onReceive ${intent.action} ${viewModel.status.value} ${device}"
)
listAdapter
.
notifyDataSetChanged
()
}
}
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
viewModel
.
status
.
observe
(
this
,
Observer
{
text
->
scanner_status
.
text
=
text
})
activity
?.
registerReceiver
(
receiver
,
IntentFilter
(
BluetoothDevice
.
ACTION_BOND_STATE_CHANGED
))
bluetoothAdapter
=
BluetoothAdapter
.
getDefaultAdapter
();
for
(
device
in
bluetoothAdapter
.
bondedDevices
.
filter
{
...
...
app/src/main/java/de/ccc/events/badge/card10/scanner/ScannerViewModel.kt
0 → 100644
View file @
36061730
/*
* Copyright by the original author or authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package
de.ccc.events.badge.card10.scanner
import
androidx.lifecycle.MutableLiveData
import
androidx.lifecycle.ViewModel
class
ScannerViewModel
:
ViewModel
()
{
val
status
=
MutableLiveData
<
String
>()
}
\ No newline at end of file
app/src/main/res/layout/scanner_fragment.xml
View file @
36061730
<?xml version="1.0" encoding="utf-8"?>
<
androidx.recyclerview.widget.RecyclerView
android
:id=
"@+id/scanner_device_list
"
<
LinearLayout
xmlns:
android
=
"http://schemas.android.com/apk/res/android
"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
xmlns:android=
"http://schemas.android.com/apk/res/android"
/>
android:orientation=
"vertical"
android:layout_gravity=
"center_horizontal"
android:padding=
"16dp"
>
<androidx.recyclerview.widget.RecyclerView
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:id=
"@+id/scanner_device_list"
android:layout_weight=
"1"
android:layout_width=
"match_parent"
android:layout_height=
"0px"
/>
<TextView
android:id=
"@+id/scanner_status"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
/>
</LinearLayout>
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment