This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
public extension CGFloat { | |
/** | |
Converts pixels to points based on the screen scale. For example, if you | |
call CGFloat(1).pixelsToPoints() on an @2x device, this method will return | |
0.5. | |
- parameter pixels: to be converted into points | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context | |
import android.content.Intent | |
import android.content.IntentFilter | |
import androidx.lifecycle.Lifecycle.Event.ON_DESTROY | |
import androidx.lifecycle.Lifecycle.Event.ON_START | |
import androidx.lifecycle.LifecycleObserver | |
import androidx.lifecycle.LifecycleOwner | |
import androidx.lifecycle.OnLifecycleEvent | |
import android.content.BroadcastReceiver as StockReceiver |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Put it in your Activity and it'll apply to all EditTexts including those within fragments within that activity | |
override fun dispatchTouchEvent(event: MotionEvent): Boolean { | |
if (event.action == MotionEvent.ACTION_DOWN) { | |
val v = currentFocus | |
if (v is EditText) { | |
val outRect = Rect() | |
v.getGlobalVisibleRect(outRect) | |
if (!outRect.contains(event.rawX.toInt(), event.rawY.toInt())) { | |
v.clearFocus() | |
val imm: InputMethodManager = |