2018-06-07 16:44:43 +02:00
|
|
|
package net.osmand.telegram.utils
|
2018-06-05 21:51:08 +02:00
|
|
|
|
2018-06-09 11:20:21 +02:00
|
|
|
import android.Manifest
|
2018-06-05 21:51:08 +02:00
|
|
|
import android.app.Activity
|
|
|
|
import android.content.Context
|
2018-06-09 11:20:21 +02:00
|
|
|
import android.content.pm.PackageManager
|
2018-06-05 21:51:08 +02:00
|
|
|
import android.content.res.Configuration
|
2018-06-09 11:20:21 +02:00
|
|
|
import android.support.v4.app.ActivityCompat
|
2018-06-05 21:51:08 +02:00
|
|
|
import android.view.View
|
|
|
|
import android.view.inputmethod.InputMethodManager
|
|
|
|
|
|
|
|
object AndroidUtils {
|
|
|
|
|
|
|
|
private fun isHardwareKeyboardAvailable(context: Context): Boolean {
|
|
|
|
return context.resources.configuration.keyboard != Configuration.KEYBOARD_NOKEYS
|
|
|
|
}
|
|
|
|
|
|
|
|
fun softKeyboardDelayed(view: View) {
|
|
|
|
view.post {
|
|
|
|
if (!isHardwareKeyboardAvailable(view.context)) {
|
|
|
|
val imm = view.context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager?
|
|
|
|
imm?.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fun hideSoftKeyboard(activity: Activity, input: View?) {
|
|
|
|
val inputMethodManager = activity.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager?
|
|
|
|
if (inputMethodManager != null) {
|
|
|
|
if (input != null) {
|
|
|
|
val windowToken = input.windowToken
|
|
|
|
if (windowToken != null) {
|
|
|
|
inputMethodManager.hideSoftInputFromWindow(windowToken, 0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-06-09 11:20:21 +02:00
|
|
|
|
|
|
|
fun isLocationPermissionAvailable(context: Context): Boolean {
|
|
|
|
return ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
|
|
|
|
}
|
2018-06-05 21:51:08 +02:00
|
|
|
}
|