Skip to content

Instantly share code, notes, and snippets.

View nightwolf738's full-sized avatar

Night Wolf nightwolf738

View GitHub Profile
@nightwolf738
nightwolf738 / focusAndShowKeyboardBySquareEditedByEgemenHamutcu.kt
Created June 3, 2021 23:38
My final solution to show Android keyboard thanks to Helios Alonso and Square team
fun View.focusAndShowKeyboard(tryAgain: Boolean = true) {
/**
* This is to be called when the window already has focus.
*/
fun View.showTheKeyboardNow() {
if (isFocused) {
post {
// We still post the call, just in case we are being notified of the windows focus
// but InputMethodManager didn't get properly setup yet.
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
@nightwolf738
nightwolf738 / focusAndShowKeyboardBySquare.kt
Created June 3, 2021 23:03
An extension function provided by Helios Alonso from Square
fun View.focusAndShowKeyboard() {
/**
* This is to be called when the window already has focus.
*/
fun View.showTheKeyboardNow() {
if (isFocused) {
post {
// We still post the call, just in case we are being notified of the windows focus
// but InputMethodManager didn't get properly setup yet.
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
@nightwolf738
nightwolf738 / BitmapExtension.kt
Created March 20, 2019 12:32
Masking bitmap with given destinationImage. Useful for masking ImageViews
fun Bitmap.maskWith(destinationImage: Bitmap, mode: PorterDuff.Mode): Bitmap {
val result = this.copy(Bitmap.Config.ARGB_8888, true)
val canvas = Canvas(result)
val paint = Paint()
canvas.drawBitmap(destinationImage, 0f, 0f, paint)
paint.xfermode = PorterDuffXfermode(mode)
canvas.drawBitmap(this, 0f, 0f, paint)