Skip to content

Commit

Permalink
fix: Lock focus on AdChoices icon
Browse files Browse the repository at this point in the history
  • Loading branch information
echoy-harmonicinc committed Nov 23, 2023
1 parent 8120c17 commit 3db8ee7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import android.view.ViewTreeObserver
import android.widget.ImageButton
import android.widget.ImageView
import android.widget.RelativeLayout
import androidx.core.view.contains
import com.bumptech.glide.Glide
import com.github.harmonicinc.clientsideadtracking.R
import com.google.android.tv.ads.AdsControlsManager
Expand Down Expand Up @@ -128,9 +129,6 @@ class AdChoiceManager(
}
}

imageButton.setOnFocusChangeListener { view, b ->
view.alpha = if (b) 0.5f else 1f
}
imageButton.viewTreeObserver.addOnGlobalFocusChangeListener(onTvFocusChangeListener)

adChoiceView!!.addView(imageButton, relativeLayoutParams)
Expand All @@ -142,8 +140,8 @@ class AdChoiceManager(

private val onTvFocusChangeListener =
ViewTreeObserver.OnGlobalFocusChangeListener { oldV, newV ->
if (oldV == imageButton && newV != null) {
oldV?.requestFocus()
if (oldV != null && adChoiceView?.contains(oldV) == true && newV != null && adChoiceView?.contains(newV) == false) {
oldV.requestFocus()
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/main/res/drawable/adchoices_selector.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/adchoices_border" />
<item android:state_focused="true" android:drawable="@drawable/adchoices_border" />
<item android:drawable="@android:color/transparent" />
</selector>

0 comments on commit 3db8ee7

Please sign in to comment.