| Jun 27 |  3:50 PM | 
| Mark M. | has entered the room | 
| Mark M. | turned on guest access | 
| Jun 27 |  3:55 PM | 
| Kai H. | has entered the room | 
| Kai H. | Hello | 
| Mark M. | hello, Kai! | 
| Mark M. | how can I help you today? | 
| Kai H. | By answering a question mayb? | 
| Mark M. | I can try | 
| Kai H. | I noticed that we have some reusable custom views in our app and was wondering if that is still best practice. | 
| Mark M. | truly reusable ones are fine, if you need them | 
| Mark M. | the biggest anti-pattern is having business logic tied up as a custom view (e.g., BillingDetailsView) | 
| Jun 27 |  4:00 PM | 
| Mark M. | but, if you have a bit of UI that needs custom logic (e.g., text layout beyond what you can easily accomplish with TextView), that's a fine reason for a custom view | 
| Kai H. | We have a view that provides a label for either a TextView or an EditText. | 
| Mark M. | that's not intrinsically bad | 
| Mark M. | the main reason we try to avoid custom views is that they are seriously annoying to write and maintain | 
| Mark M. | custom attributes, recycling the TypedAsset thingy, no lifecycle awareness, etc. | 
| Kai H. | I have already noticed the point about maintenance ;-) | 
| Kai H. | What way would you go for the View I mentioned? | 
| Mark M. | that is difficult to answer, as while I know its role, I do not know whether the implementation needs to be a custom view or not | 
| Mark M. | in my current main customer's project, we have a BadgeView | 
| Jun 27 |  4:05 PM | 
| Kai H. | Neither do I. I just noticed the point about the maintainability you mentioned. | 
| Jun 27 |  4:05 PM | 
| Mark M. | in the end, it is text with a background, and in theory could be handled with just a TextView | 
| Mark M. | in our case, there are just enough idiosyncrasies in the way that text needs to get rendered that we were better served creating a custom view for it | 
| Mark M. | if we could have gotten away with it, some sort of BadgePresenter might have been a more maintainable solution -- hand it the TextView, and it handles any formatting beyond what we could specify in a layout | 
| Kai H. | I guess I'll have to ask the original coder on why this View needs to exist. | 
| Mark M. | in the end, it's Android's implementation that makes custom views the sort of thing we minimize -- other UI toolkits, including Jetpack Compose, are far friendlier about this sort of thing | 
| Kai H. | I have kind of a follow up question: I am tasked in changing the script font and script color for the whole app. The custom view is giving me quite the trouble with that (besides CheckBoxes, RadioButtons and such). | 
| Kai H. | I'd like to know if changing the font and color is "a good idea"/feasible and how to best go about it. | 
| Mark M. | ideally, that sort of thing gets driven by style resources | 
| Mark M. | so, you declare in the style "gimme this look" and have all the widgets get the look from the style | 
| Mark M. | for all the framework widgets, that's not too bad, whether using style or android:textAppearance (for the case of fonts) | 
| Jun 27 |  4:10 PM | 
| Mark M. | for custom views, if they are not subclasses of something that is style-aware (e.g., subclass of TextView), you'll have to have some code in the view itself to help with this | 
| Kai H. | When you say "driven by style resources", you don't mean a Theme? | 
| Kai H. | Because it sounds like I'd have to applay the style to each widget manually. | 
| Kai H. | Which would be a hell of a lot of work. | 
| Mark M. | sorry, I was speaking a bit more generally | 
| Mark M. | and I wasn't sure what the scope was for your changes | 
| Kai H. | I have read up about styles and themes and such, but I have some open questions about it and wonder what the best general approach would be. | 
| Mark M. | if it is literally every widget, then a theme would be a fine choice | 
| Kai H. | Our UX handed me a font and a text color and told me that is what the app should use from now on ;-) | 
| Mark M. | if it is most widgets, then a theme would be a fine choice, where you use styles for the non-confirming widget | 
| Kai H. | What do you mean by non-confirming widget? | 
| Mark M. | sorry, that was supposed to be "non-conforming" | 
| Mark M. | if the answer is not "all widgets use this font", then by definition, some widgets are not using this font -- those "some widgets" are not conforming to the font choice | 
| Jun 27 |  4:15 PM | 
| Kai H. | Like the custom view that we use does. | 
| Mark M. | well, in this case, I think you *want* it to use that font, but it isn't | 
| Kai H. | Exactly. It extends "LinearLayout" btw :D | 
| Mark M. | I was more referring to the case where you are using 2+ fonts across the app: one font perhaps dominant but with others used in specific areas | 
| Kai H. | Oh ok. I guess we'll have only one font for the whole app (for the time being). | 
| Mark M. | right, so in your case, specifying that font in a theme, and using that theme for all your activities, is a fine choice | 
| Mark M. | and you just need to hammer the custom view until it honors that theme's choices | 
| Kai H. | So I would handle the font-setting in the custom views source code, I guess. How would I handle things like CheckBoxes, RadioButtons and such? They don't pick up the general "android:fontFamily" and "fontFamily". | 
| Kai H. | I found that they might pick up other settings, but I find that a little strange. | 
| Mark M. | "They don't pick up the general "android:fontFamily" and "fontFamily"." -- they should, as they extend TextView | 
| Jun 27 |  4:20 PM | 
| Kai H. | Thinking back, what they actually didn't pick up was the color. I am not sure about the font atm. | 
| Mark M. | android:textColor should also be honored by CompoundButton, as that is handled by TextView | 
| Jun 27 |  4:25 PM | 
| Kai H. | For some reason it isn't at several places. | 
| Mark M. | ¯\_(ツ)_/¯ | 
| Jun 27 |  4:30 PM | 
| Kai H. | I rechecked, neither color nor Font are picked up by RadioButtons. CheckBoxes pick it up. | 
| Kai H. | Is it common to change the font for a whole app? Or is it rather not done? | 
| Mark M. | in terms of the actual font itself, it is fairly uncommon | 
| Mark M. | up until three years ago, when font resources were introduced, it was a serious pain in the posterior | 
| Jun 27 |  4:35 PM | 
| Mark M. | it also raises challenges for internationalization (do you have all the right glyphs?) | 
| Mark M. | and, it increases the app size, by however big the font resource is | 
| Mark M. | (unless you are using a font provider and are downloading the font on the fly, which raises its own concerns) | 
| Mark M. | but, designers love their custom fonts, and so now that it is not completely insane to implement it, I expect that it is more common than it had been | 
| Kai H. | I am pondering pushing back on that request by our designers. | 
| Kai H. | As we seem to have a couple of places that are troublesome for either font or color or both. | 
| Jun 27 |  4:40 PM | 
| Kai H. | And it could be more trouble than it's worth to implement it. It would require a lot of testing too, to make sure it's picked up everywhere in the app. | 
| Mark M. | I am surprised that you are having as much trouble as you are with the color | 
| Mark M. | fonts are relatively new; colors have been with us in Android since the outset | 
| Kai H. | I am surprised too | 
| Mark M. | and I guarantee you that RadioButton honors colors from some sources, as otherwise we could not have light and dark themes | 
| Kai H. | The question is which sources those are | 
| Mark M. | now, for some things, due to historical Android baggage, you might need duplicate attributes in your style/theme resources | 
| Mark M. | so, for example, if you were trying android:textColor, also add textColor (no XML namespace prefix), and see if you have more luck | 
| Kai H. | I did that for fontFamily, but with textColor Android Studio colors it red and tells me "cannot resolve symbol" | 
| Mark M. | OK, are you sure that these RadioButtons are not specifying their color multiple ways? For example, if you have android:textColor in the actual <RadioButton> XML element, that replaces what is in a theme | 
| Jun 27 |  4:45 PM | 
| Kai H. | Actually looking that up right now, because I wasn't sure | 
| Kai H. | But it's good to know that "it should work". | 
| Mark M. | also, you may need to consider a StateListDrawable: https://stackoverflow.com/a/54899138/115145 | 
| Kai H. | As I can search in other places than I would otherwise | 
| Mark M. | |
| Mark M. | that's the go-to article on the prioritization system for colors for text | 
| Kai H. | Oh, the CheckButtons seem to be added programmatically somehow.  | 
| Mark M. | ah, then you would need to tweak the Java/Kotlin that is creating them and ensure they pick up your desired color | 
| Kai H. | I wonder why they are not in the layout file and where they are created. | 
| Kai H. | :D | 
| Mark M. | sometimes, that's done if there are a dynamic number of them | 
| Mark M. | for example, the number of checkboxes is derived from a Web service response or the number of records in a database table or something | 
| Kai H. | (I meant to say RadioButtons, not CheckButtons) | 
| Kai H. | There seem to be several different cases for the CheckButtons. | 
| Jun 27 |  4:50 PM | 
| Kai H. | I wish I had comments in my code, telling me why things are there and what they mean :D | 
| Kai H. | But now I have a path going forward. Set the color and font in the theme and then work through all the places where it's not picked up, finding out why. | 
| Kai H. | And custom views, set the color in the source code. | 
| Kai H. | For CheckBoxes and RadioButtons, either set in source code or... I dunno yet. | 
| Mark M. | usually, you can specify the style or theme to use in code | 
| Mark M. | |
| Mark M. | eh, crap, the section link didn't jump to the right spot | 
| Kai H. | One thing that baffles me a bit is our CheckBoxes not picking up the text color. They seem to be ordinary, with no style applied. | 
| Jun 27 |  4:55 PM | 
| Mark M. | are they defined in a layout resource or are they constructed programmatically? | 
| Kai H. | They are in a layout resource | 
| Kai H. | <CheckBox ... android:text=".." android:textSize="..." ... /> | 
| sudokai | has entered the room | 
| Mark M. | how is the layout resource used? | 
| Kai H. | View v = inflater.inflate(..., container, false); | 
| Mark M. | hello, sudokai! the chat is almost over -- do you have a quick question? | 
| Kai H. | Hi sudokai | 
| Mark M. | Kai: how are you obtaining your LayoutInflater? | 
| Mark M. | if the answer is LayoutInflater.from(), try getting it from the activity by calling getLayoutInflater() | 
| sudokai | Hi | 
| sudokai | I'll come next time | 
| Kai H. | It's being passed down in "onCreateView" of a Fragment | 
| Mark M. | sudokai: OK, sounds good! | 
| Mark M. | Kai: OK, that seems normal | 
| Mark M. | I ask because a common "my theme isn't working" cause is because somebody used the wrong Context, such as for getting a LayoutInflater | 
| Kai H. | Yes. "It should work" :D | 
| Mark M. | you always want a LayoutInflater from the activity for UI stuff, so it will pick up that activity's theme and apply it | 
| Mark M. | in your case, you should be OK on that front | 
| Kai H. | Ok | 
| Jun 27 |  5:00 PM | 
| Mark M. | any last quick questions? | 
| Mark M. | OK, then, that's a wrap for today's chat | 
| Kai H. | Damn :D | 
| Mark M. | next one is Tuesday at 8:30am US Eastern | 
| Kai H. | Thanks for the session | 
| Kai H. | And have a good time | 
| Mark M. | you too! | 
| Kai H. | has left the room  | 
| sudokai | has left the room  | 
| Mark M. | turned off guest access | 
