Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
AR-Support in Handcrafted Manufacturing
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Greisa Ajdini
AR-Support in Handcrafted Manufacturing
Commits
013553e1
Commit
013553e1
authored
2 years ago
by
Greisa Ajdini
Browse files
Options
Downloads
Patches
Plain Diff
nearest beacon setup
parent
27ad13a5
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/src/main/java/com/tooz/woodz/BaseActivity.kt
+36
-17
36 additions, 17 deletions
app/src/main/java/com/tooz/woodz/BaseActivity.kt
app/src/main/java/com/tooz/woodz/MainActivity.kt
+10
-10
10 additions, 10 deletions
app/src/main/java/com/tooz/woodz/MainActivity.kt
with
46 additions
and
27 deletions
app/src/main/java/com/tooz/woodz/BaseActivity.kt
+
36
−
17
View file @
013553e1
...
@@ -4,19 +4,19 @@ import android.Manifest
...
@@ -4,19 +4,19 @@ import android.Manifest
import
android.app.Activity
import
android.app.Activity
import
android.app.AlertDialog
import
android.app.AlertDialog
import
android.bluetooth.BluetoothAdapter
import
android.bluetooth.BluetoothAdapter
import
android.bluetooth.BluetoothDevice
import
android.bluetooth.BluetoothManager
import
android.bluetooth.BluetoothManager
import
android.bluetooth.le.ScanCallback
import
android.bluetooth.le.ScanCallback
import
android.bluetooth.le.ScanFilter
import
android.bluetooth.le.ScanResult
import
android.bluetooth.le.ScanResult
import
android.bluetooth.le.ScanSettings
import
android.bluetooth.le.ScanSettings
import
android.content.Context
import
android.content.Context
import
android.content.Intent
import
android.content.Intent
import
android.content.pm.PackageManager
import
android.content.pm.PackageManager
import
android.os.Build
import
android.os.Build
import
androidx.appcompat.app.AppCompatActivity
import
android.os.Bundle
import
android.util.Log
import
android.widget.Toast
import
android.widget.Toast
import
androidx.activity.result.contract.ActivityResultContracts
import
androidx.activity.result.contract.ActivityResultContracts
import
androidx.appcompat.app.AppCompatActivity
import
androidx.core.app.ActivityCompat
import
androidx.core.app.ActivityCompat
import
androidx.core.content.ContextCompat
import
androidx.core.content.ContextCompat
import
org.altbeacon.beacon.BeaconManager
import
org.altbeacon.beacon.BeaconManager
...
@@ -26,7 +26,11 @@ private const val LOCATION_PERMISSION_REQUEST_CODE = 2
...
@@ -26,7 +26,11 @@ private const val LOCATION_PERMISSION_REQUEST_CODE = 2
abstract
class
BaseActivity
:
AppCompatActivity
()
{
abstract
class
BaseActivity
:
AppCompatActivity
()
{
private
var
addresses
=
arrayOf
(
"AC:23:3F:88:10:51"
,
"AC:23:3F:88:10:53"
,
"AC:23:3F:88:10:57"
)
private
var
beaconManager
:
BeaconManager
?
=
null
private
var
beaconManager
:
BeaconManager
?
=
null
private
var
filters
:
MutableList
<
ScanFilter
>
=
mutableListOf
()
private
val
scanResults
=
mutableListOf
<
ScanResult
>()
var
nearestBeacon
:
BluetoothDevice
?
=
null
private
var
isScanning
=
false
private
var
isScanning
=
false
...
@@ -43,13 +47,9 @@ abstract class BaseActivity : AppCompatActivity() {
...
@@ -43,13 +47,9 @@ abstract class BaseActivity : AppCompatActivity() {
bluetoothManager
.
adapter
bluetoothManager
.
adapter
}
}
val
isLocationPermissionGranted
private
val
isLocationPermissionGranted
get
()
=
hasPermission
(
Manifest
.
permission
.
ACCESS_FINE_LOCATION
)
get
()
=
hasPermission
(
Manifest
.
permission
.
ACCESS_FINE_LOCATION
)
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
}
override
fun
onResume
()
{
override
fun
onResume
()
{
super
.
onResume
()
super
.
onResume
()
if
(
checkPermissions
())
{
if
(
checkPermissions
())
{
...
@@ -86,7 +86,11 @@ abstract class BaseActivity : AppCompatActivity() {
...
@@ -86,7 +86,11 @@ abstract class BaseActivity : AppCompatActivity() {
if
(
isLocationPermissionGranted
)
{
if
(
isLocationPermissionGranted
)
{
return
return
}
}
if
(!
ActivityCompat
.
shouldShowRequestPermissionRationale
(
this
,
Manifest
.
permission
.
ACCESS_FINE_LOCATION
)){
if
(!
ActivityCompat
.
shouldShowRequestPermissionRationale
(
this
,
Manifest
.
permission
.
ACCESS_FINE_LOCATION
)
)
{
val
alertDialogBuilder
=
AlertDialog
.
Builder
(
this
)
val
alertDialogBuilder
=
AlertDialog
.
Builder
(
this
)
alertDialogBuilder
.
setTitle
(
R
.
string
.
location_permission_alert_title
)
alertDialogBuilder
.
setTitle
(
R
.
string
.
location_permission_alert_title
)
alertDialogBuilder
.
setMessage
(
R
.
string
.
location_permission_alert_message
)
alertDialogBuilder
.
setMessage
(
R
.
string
.
location_permission_alert_message
)
...
@@ -103,23 +107,38 @@ abstract class BaseActivity : AppCompatActivity() {
...
@@ -103,23 +107,38 @@ abstract class BaseActivity : AppCompatActivity() {
private
val
scanCallback
=
object
:
ScanCallback
()
{
private
val
scanCallback
=
object
:
ScanCallback
()
{
override
fun
onScanResult
(
callbackType
:
Int
,
result
:
ScanResult
)
{
override
fun
onScanResult
(
callbackType
:
Int
,
result
:
ScanResult
)
{
Log
.
i
(
"ScanCallBack"
,
result
.
device
.
toString
())
scanResults
.
add
(
result
)
with
(
result
.
device
)
{
scanResults
.
sortByDescending
{
it
.
rssi
}
Log
.
i
(
"ScanCallback"
,
"Found BLE device! Name: ${name ?: "
Unnamed
"}, address: $address $"
)
nearestBeacon
=
scanResults
[
0
].
device
}
// Log.i("ScanCallback",scanResults[0].toString())
// with(result.device) {
// Log.i(
// "ScanCallback",
// "Found BLE device! Name: ${name ?: "Unnamed"}, address: $address ${result.rssi} $"
// )
// }
}
}
}
}
private
fun
doBleScan
()
{
private
fun
doBleScan
()
{
//todo delete
//todo delete
Toast
.
makeText
(
this
,
"heyyyyy"
,
Toast
.
makeText
(
Toast
.
LENGTH_SHORT
).
show
()
this
,
"hey"
,
Toast
.
LENGTH_SHORT
).
show
()
scanResults
.
clear
()
for
(
i
in
addresses
.
indices
)
{
val
filter
=
ScanFilter
.
Builder
().
setDeviceAddress
(
addresses
[
i
]).
build
()
filters
.
add
(
filter
)
}
bleScanner
.
startScan
(
filters
,
scanSettings
,
scanCallback
)
isScanning
=
true
isScanning
=
true
bleScanner
.
startScan
(
null
,
scanSettings
,
scanCallback
)
}
}
fun
Context
.
hasPermission
(
permissionType
:
String
):
Boolean
{
private
fun
Context
.
hasPermission
(
permissionType
:
String
):
Boolean
{
return
ContextCompat
.
checkSelfPermission
(
this
,
permissionType
)
==
return
ContextCompat
.
checkSelfPermission
(
this
,
permissionType
)
==
PackageManager
.
PERMISSION_GRANTED
PackageManager
.
PERMISSION_GRANTED
}
}
...
...
This diff is collapsed.
Click to expand it.
app/src/main/java/com/tooz/woodz/MainActivity.kt
+
10
−
10
View file @
013553e1
...
@@ -25,12 +25,12 @@ class MainActivity : BaseActivity() {
...
@@ -25,12 +25,12 @@ class MainActivity : BaseActivity() {
val
navHostFragment
=
supportFragmentManager
val
navHostFragment
=
supportFragmentManager
.
findFragmentById
(
R
.
id
.
nav_fragment
)
as
NavHostFragment
.
findFragmentById
(
R
.
id
.
nav_fragment
)
as
NavHostFragment
navController
=
navHostFragment
.
navController
navController
=
navHostFragment
.
navController
val
bottomNavigationView
=
findViewById
<
BottomNavigationView
val
bottomNavigationView
=
findViewById
<
BottomNavigationView
>(
R
.
id
.
bottom_navigation_view
)
>(
R
.
id
.
bottom_navigation_view
)
setupActionBarWithNavController
(
navController
)
setupActionBarWithNavController
(
navController
)
bottomNavigationView
.
setupWithNavController
(
navController
)
bottomNavigationView
.
setupWithNavController
(
navController
)
val
mOnNavigationItemSelectedListener
=
BottomNavigationView
.
OnNavigationItemSelectedListener
{
item
->
val
mOnNavigationItemSelectedListener
=
BottomNavigationView
.
OnNavigationItemSelectedListener
{
item
->
when
(
item
.
itemId
)
{
when
(
item
.
itemId
)
{
R
.
id
.
camera
->
{
R
.
id
.
camera
->
{
val
intent
=
Intent
(
this
,
BarcodeScannerActivity
::
class
.
java
)
val
intent
=
Intent
(
this
,
BarcodeScannerActivity
::
class
.
java
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment