mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
More map modularization (#3319)
This commit is contained in:
parent
bc114c618a
commit
51fa634e11
28 changed files with 145 additions and 146 deletions
|
|
@ -1,35 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2025 Meshtastic LLC
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.geeksville.mesh.android
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.Toast
|
||||
|
||||
// / show a toast
|
||||
fun Context.toast(message: CharSequence) = Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
|
||||
|
||||
// / Utility function to hide the soft keyboard per stack overflow
|
||||
fun Activity.hideKeyboard() {
|
||||
// Check if no view has focus:
|
||||
currentFocus?.let { v ->
|
||||
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as? InputMethodManager
|
||||
imm?.hideSoftInputFromWindow(v.windowToken, 0)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,75 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2025 Meshtastic LLC
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.geeksville.mesh.android
|
||||
|
||||
import android.Manifest
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import android.location.LocationManager
|
||||
import android.os.Build
|
||||
import androidx.core.content.ContextCompat
|
||||
|
||||
/** Checks if the device has a GPS receiver. */
|
||||
fun Context.hasGps(): Boolean {
|
||||
val lm = getSystemService(Context.LOCATION_SERVICE) as? LocationManager
|
||||
return lm?.allProviders?.contains(LocationManager.GPS_PROVIDER) == true
|
||||
}
|
||||
|
||||
/** Checks if the device has a GPS receiver and it is currently disabled. */
|
||||
fun Context.gpsDisabled(): Boolean {
|
||||
val lm = getSystemService(Context.LOCATION_SERVICE) as? LocationManager ?: return false
|
||||
return if (lm.allProviders.contains(LocationManager.GPS_PROVIDER)) {
|
||||
!lm.isProviderEnabled(LocationManager.GPS_PROVIDER)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the list of Bluetooth permissions that are currently missing. Internal helper for
|
||||
* [hasBluetoothPermission].
|
||||
*
|
||||
* For Android S (API 31) and above, this includes [Manifest.permission.BLUETOOTH_SCAN] and
|
||||
* [Manifest.permission.BLUETOOTH_CONNECT]. For older versions, it includes [Manifest.permission.ACCESS_FINE_LOCATION]
|
||||
* as it is required for Bluetooth scanning.
|
||||
*
|
||||
* @return Array of missing Bluetooth permission strings. Empty if all are granted.
|
||||
*/
|
||||
private fun Context.getBluetoothPermissions(): Array<String> {
|
||||
val requiredPermissions = mutableListOf<String>()
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
requiredPermissions.add(Manifest.permission.BLUETOOTH_SCAN)
|
||||
requiredPermissions.add(Manifest.permission.BLUETOOTH_CONNECT)
|
||||
} else {
|
||||
// ACCESS_FINE_LOCATION is required for Bluetooth scanning on pre-S devices.
|
||||
requiredPermissions.add(Manifest.permission.ACCESS_FINE_LOCATION)
|
||||
}
|
||||
return requiredPermissions
|
||||
.filter { ContextCompat.checkSelfPermission(this, it) != PackageManager.PERMISSION_GRANTED }
|
||||
.toTypedArray()
|
||||
}
|
||||
|
||||
/** Checks if all necessary Bluetooth permissions have been granted. */
|
||||
fun Context.hasBluetoothPermission(): Boolean = getBluetoothPermissions().isEmpty()
|
||||
|
||||
/** @return true if the user already has location permission (ACCESS_FINE_LOCATION). */
|
||||
fun Context.hasLocationPermission(): Boolean {
|
||||
val perms = listOf(Manifest.permission.ACCESS_FINE_LOCATION)
|
||||
return perms.all { ContextCompat.checkSelfPermission(this, it) == PackageManager.PERMISSION_GRANTED }
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue