Modularize some map-related files (#3154)

This commit is contained in:
Phil Oliver 2025-09-19 19:12:26 -04:00 committed by GitHub
parent 00ee0db78a
commit 8b2e1e8b02
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 62 additions and 36 deletions

View file

@ -19,28 +19,17 @@ package com.geeksville.mesh.android
import android.app.Activity
import android.content.Context
import android.util.TypedValue
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()
// / 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
// / 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
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as? InputMethodManager
imm?.hideSoftInputFromWindow(v.windowToken, 0)
}
}
// Converts SP to pixels.
fun Context.spToPx(sp: Float): Int =
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp, resources.displayMetrics).toInt()
// Converts DP to pixels.
fun Context.dpToPx(dp: Float): Int =
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, resources.displayMetrics).toInt()