Skip to content

Instantly share code, notes, and snippets.

@akexorcist
Last active October 8, 2021 00:14
Show Gist options
  • Save akexorcist/33c20f85bb23d9884b380f7b02d32e7f to your computer and use it in GitHub Desktop.
Save akexorcist/33c20f85bb23d9884b380f7b02d32e7f to your computer and use it in GitHub Desktop.

Revisions

  1. akexorcist revised this gist Oct 8, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion GroupFocusableEditText.kt
    Original file line number Diff line number Diff line change
    @@ -27,7 +27,7 @@ class GroupFocusableEditText : AppCompatEditText {
    override fun getGlobalVisibleRect(r: Rect?, globalOffset: Point?): Boolean {
    val result = super.getGlobalVisibleRect(r, globalOffset)
    getFocusableGroupLayout()?.let { view ->
    view.getGlobalVisibleRect(parentRect)
    view.getGlobalVisibleRect(parentRect, globalOffset)
    r?.bottom = parentRect.bottom
    }
    return result
  2. akexorcist revised this gist Oct 7, 2021. No changes.
  3. akexorcist revised this gist Oct 7, 2021. 1 changed file with 16 additions and 2 deletions.
    18 changes: 16 additions & 2 deletions GroupFocusableEditText.kt
    Original file line number Diff line number Diff line change
    @@ -6,6 +6,8 @@ import android.view.View
    import androidx.appcompat.widget.AppCompatEditText

    class GroupFocusableEditText : AppCompatEditText {
    private var parentRect = Rect()

    constructor(context: Context) : super(context)
    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
    @@ -17,7 +19,6 @@ class GroupFocusableEditText : AppCompatEditText {
    override fun getFocusedRect(r: Rect?) {
    super.getFocusedRect(r)
    getFocusableGroupLayout()?.let { view ->
    val parentRect = Rect()
    view.getFocusedRect(parentRect)
    r?.bottom = parentRect.bottom
    }
    @@ -26,13 +27,26 @@ class GroupFocusableEditText : AppCompatEditText {
    override fun getGlobalVisibleRect(r: Rect?, globalOffset: Point?): Boolean {
    val result = super.getGlobalVisibleRect(r, globalOffset)
    getFocusableGroupLayout()?.let { view ->
    val parentRect = Rect()
    view.getGlobalVisibleRect(parentRect)
    r?.bottom = parentRect.bottom
    }
    return result
    }

    override fun requestRectangleOnScreen(rectangle: Rect?): Boolean {
    val result = super.requestRectangleOnScreen(rectangle)
    getFocusableGroupLayout()?.let { view ->
    parentRect.set(
    0,
    0,
    view.width,
    view.height
    )
    view.requestRectangleOnScreen(parentRect, true)
    }
    return result
    }

    private fun getFocusableGroupLayout(): GroupFocusableLayout? {
    var viewParent = parent
    while (viewParent is View) {
  4. akexorcist revised this gist Oct 6, 2021. No changes.
  5. akexorcist revised this gist Oct 6, 2021. No changes.
  6. akexorcist revised this gist Oct 6, 2021. No changes.
  7. akexorcist revised this gist Oct 6, 2021. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions GroupFocusableEditText.kt
    Original file line number Diff line number Diff line change
    @@ -14,11 +14,10 @@ class GroupFocusableEditText : AppCompatEditText {
    defStyleAttr
    )

    private val parentRect: Rect = Rect()

    override fun getFocusedRect(r: Rect?) {
    super.getFocusedRect(r)
    getFocusableGroupLayout()?.let { view ->
    val parentRect = Rect()
    view.getFocusedRect(parentRect)
    r?.bottom = parentRect.bottom
    }
    @@ -27,6 +26,7 @@ class GroupFocusableEditText : AppCompatEditText {
    override fun getGlobalVisibleRect(r: Rect?, globalOffset: Point?): Boolean {
    val result = super.getGlobalVisibleRect(r, globalOffset)
    getFocusableGroupLayout()?.let { view ->
    val parentRect = Rect()
    view.getGlobalVisibleRect(parentRect)
    r?.bottom = parentRect.bottom
    }
  8. akexorcist created this gist Oct 5, 2021.
    46 changes: 46 additions & 0 deletions GroupFocusableEditText.kt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    import android.content.Context
    import android.graphics.Point
    import android.graphics.Rect
    import android.util.AttributeSet
    import android.view.View
    import androidx.appcompat.widget.AppCompatEditText

    class GroupFocusableEditText : AppCompatEditText {
    constructor(context: Context) : super(context)
    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
    context,
    attrs,
    defStyleAttr
    )

    private val parentRect: Rect = Rect()

    override fun getFocusedRect(r: Rect?) {
    super.getFocusedRect(r)
    getFocusableGroupLayout()?.let { view ->
    view.getFocusedRect(parentRect)
    r?.bottom = parentRect.bottom
    }
    }

    override fun getGlobalVisibleRect(r: Rect?, globalOffset: Point?): Boolean {
    val result = super.getGlobalVisibleRect(r, globalOffset)
    getFocusableGroupLayout()?.let { view ->
    view.getGlobalVisibleRect(parentRect)
    r?.bottom = parentRect.bottom
    }
    return result
    }

    private fun getFocusableGroupLayout(): GroupFocusableLayout? {
    var viewParent = parent
    while (viewParent is View) {
    if (viewParent is GroupFocusableLayout) {
    return viewParent
    }
    viewParent = (viewParent as View).parent
    }
    return null
    }
    }
    13 changes: 13 additions & 0 deletions GroupFocusableLayout.kt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    import android.content.Context
    import android.util.AttributeSet
    import android.widget.FrameLayout

    class GroupFocusableLayout : FrameLayout {
    constructor(context: Context) : super(context)
    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
    context,
    attrs,
    defStyleAttr
    )
    }