Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Styles won't change Title text and Button highlight animator colour in Introductory Overlay #102

Open
mehdi-satei opened this issue Jan 25, 2021 · 0 comments

Comments

@mehdi-satei
Copy link

mehdi-satei commented Jan 25, 2021

According to the documentation, Cast Introductory overlay is customisable via Styles.

<item name="castIntroOverlayStyle">@style/CustomCastIntroOverlay</item>
<style name="CustomCastIntroOverlay" parent="CastIntroOverlay">
    <item name="castButtonTextAppearance">@style/TextAppearance.CustomCastIntroOverlay.Button</item>
    <item name="castTitleTextAppearance">@style/TextAppearance.CustomCastIntroOverlay.Title</item>
</style>
<style name="TextAppearance.CustomCastIntroOverlay.Button" parent="android:style/TextAppearance">
    <item name="android:textColor">#FFFFFF</item>
</style>
<style name="TextAppearance.CustomCastIntroOverlay.Title"parent="android:style/TextAppearance.Large">
    <item name="android:textColor">#FFFFFF</item>
</style>

However, no matter what colour you put in the styles, the TitleText and Cast Button overlay colour (the one surrounding the button) does not change.

This is reproducible in the sample code also.

The only way I managed to solve this issue was to add a manual work-around like this:

                    val overlay = IntroductoryOverlay.Builder(this@CastActivity, it)
                        .setTitleText("title text")
                        .setOverlayColor(R.color.XX)
                        .setSingleTime()
                        .build()

                    overlay.show()

                    // A hack to change colors. Note that the color of button itself is changed in the Styles
                    (overlay as? ViewGroup)?.apply {
                        // Title text color
                        findViewById<TextView>(R.id.cast_featurehighlight_help_text_header_view)?.setTextColor(R.color.XX)
                        // The highlight color surrounding the button
                        findViewById<View>(R.id.cast_featurehighlight_view).apply {
                            try {
                                val classFields = this::class.java.declaredFields
                                for (classField in classFields) {
                                    // Getting class member that is InnerZoneDrawable
                                    if (classField.type.toString().contains("InnerZoneDrawable", true)) {
                                        classField.isAccessible = true
                                        // Get an object of this class member, convert it to Drawable, and apply color filter
                                        val innerZoneDrawable = classField.get(this)
                                        (innerZoneDrawable as Drawable).apply {
                                            colorFilter = PorterDuffColorFilter(R.color.XX, PorterDuff.Mode.SRC_IN)
                                        }

                                        // Now for the circle animator, we need to access Paint variables inside InnerZoneDrawable and apply color filter
                                        val innerZoneClassFields = innerZoneDrawable.javaClass.declaredFields

                                        for (innerZoneClassField in innerZoneClassFields) {
                                            if (innerZoneClassField.type == Paint::class.java) {
                                                innerZoneClassField.isAccessible = true
                                                (innerZoneClassField.get(innerZoneDrawable) as Paint).apply {
                                                    colorFilter = PorterDuffColorFilter(R.color.XX, PorterDuff.Mode.SRC_IN)
                                                }
                                            }
                                        }
                                    }
                                }
                            } catch (e: Exception) {
                                Timber.w(e)
                            }
                        }
                    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant