2024-11-26 08:38:12 -03:00
|
|
|
/*
|
2025-01-02 06:50:26 -03:00
|
|
|
* Copyright (c) 2025 Meshtastic LLC
|
2024-11-26 08:38:12 -03:00
|
|
|
*
|
|
|
|
|
* 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/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2022-09-04 22:52:40 -03:00
|
|
|
package com.geeksville.mesh.android
|
|
|
|
|
|
|
|
|
|
import android.app.Activity
|
|
|
|
|
import android.content.Context
|
2025-03-02 10:14:12 -05:00
|
|
|
import android.util.TypedValue
|
2022-09-04 22:52:40 -03:00
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-03-02 10:14:12 -05:00
|
|
|
|
|
|
|
|
// Converts SP to pixels.
|
|
|
|
|
fun Context.spToPx(sp: Float): Int =
|
|
|
|
|
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp, resources.displayMetrics).toInt()
|
2025-03-04 15:40:57 -05:00
|
|
|
|
|
|
|
|
// Converts DP to pixels.
|
|
|
|
|
fun Context.dpToPx(dp: Float): Int =
|
|
|
|
|
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, resources.displayMetrics).toInt()
|