Office Hours — Today, June 25

Tuesday, June 23

Jun 25
8:25 AM
Mark M.
has entered the room
Mark M.
turned on guest access
marekdef
has entered the room
Mark M.
hello, markedef!
how can I help you today?
marekdef
Hi Mark
on the last chat you mentioned accessibility is important
I was wondering how can I test if the app is accessible
Mark M.
turn on Talkback and try using it with your eyes closed :-)
(though I'm not completely joking there...)
Kai H.
has entered the room
marekdef
because if you remember I have my custom keyboard and a custom TextField that displays a price
Mark M.
among other things, Google has an app ("Accessibility Scanner") that can help identify accessibility issues
8:30 AM
Mark M.
(BTW, hello Kai -- I will be with you shortly!)
Kai H.
Hello everythone
Mark M.
marekdef: yes, and I was concerned about accessibility with respect to the custom keyboard
marekdef
I think the keyboard is accessible beceause is built on top of TextFields but my custom price tag is FrameLayout with EditText covered by another FrameLayout
just wanted to check if blind person could read the price
Leora
has entered the room
Mark M.
my guess is they will not
but I have not had to do that sort of thing very recently, so I am not completely certain
(BTW, hello Leora -- I will be with you shortly!)
marekdef
allright will check the scanner app
Mark M.
so, turn on Talkback and see if you get announcements from your EditText
Leora
hi Mark! sure thing
Mark M.
also, set up a Bluetooth keyboard and make sure that you support text input, both in terms of numbers and in terms of arrow keys for navigation
if you can get both of those working, you should be in decent shape
also, I think there are firms out there that help with accessibility testing, if your firm is interested in getting specific professional input on your... ummm... custom specific professional form of input :-)
let me take questions from the others, and I will come back to you a bit later
Kai: you were next, so... how can I help you today?
marekdef
sure
8:35 AM
Kai H.
I was wondering how to implement different layouts for different screens sizes properly, especially given a ListItem with ConstraintLayout
Mark M.
that's a little abstract... in general, you decide at what size you want to switch strategies, and then set up a layout resource directory for that size
Kai H.
Given this listitem
I want it to have both the highlight bar and the "action buttons" (dots on the right) in one screen width, only the action buttons in another and neither highlight bar nor action buttions in a third.
Mark M.
you have two choices: handle that with layout resource directories, or handle that in code
with layout resource directories, you would have res/layout/, res/layout-swXXXdp/, and res/layout-swYYYdp/
Kai H.
I did make three variants with w420dp, w420dp-large and layout
Mark M.
I strongly recommend changing w420dp-large to something else, based purely on a dimension
Kai H.
So that is still the proper approach? Just have three layout variants?
Mark M.
that is one possibility
the other is to mark those widgets as having visibility of View.GONE by one means or another
Kai H.
Thing is that I had it that way but for some reason I didn't get the results I was looking for. Also, we have a two-pane view for tablets which still works with -large and I wanted it to adhere to that
8:40 AM
Mark M.
I really don't recommend using -large anymore
that's a 2011 sort of thing
and you are even more at the mercy of device manufacturers than usual if you use it
use w420dp and another wNNNdp, for some other value of NNN
Kai H.
I kinda needed to as I needed the listitem to change at the same time as two-pane would come up, which is coupled to -large atm. When refactoring I could change that.
Mark M.
tactically, if you want to use it, go ahead -- it's just something that would worry me
Kai H.
It worries me too, but at the time being, I kinda had to do it that way.
Mark M.
in general, I can't really help with "I didn't get the results I was looking for", as I don't know enough details
Kai H.
Short of taking the time to find out how the app should look on different devices and refactor large
But I think that answers my question. I wanted to know if I was going in the proper direction.
Mark M.
your revisions are minor enough that I would consider having just one layout and either use integer resources to change visibility of those widgets or change their visibility in code
but, three layouts is certainly reasonable, particularly if you anticipate more substantial changes down the road
let me take questions from the others, and I will return to you in a bit
Kai H.
How readable would that be?
Mark M.
Leora: your turn! how can I help you today?
Kai H.
I haven't thought about integer resources so far, but sounds like an interesting approach.
Leora
Having some trouble converting my code from java to kotlin
8:45 AM
Leora
specifically, I have a lib module and an app module
interface INav in lib, singleton class Nav that implements INav, and class NavA from app that extends Nav
I get the correct Nav class when I initialize some stuff using custom Application classes
In java it worked great! even when i had a function called from the singleton Nav class, it was directed to the overridden function in NavA class. perfect
in kotlin, I made the singleton class using object Nav
but the function called from the Nav object calls it's own function, instead of redirecting to the overriden function in NavA
phew that's it
8:50 AM
Mark M.
I'm surprised that NavA can exist -- I didn't think you could subclass an object
Leora
hahaha
object NavigationST : INavigation by Navigation{}
:)
Mark M.
but, isn't Navigation itself an object?
Leora
yup
i thought that's how i get a singleton class in kotlin...?
Mark M.
yes, but I guess I had not realized it could be used this way
Leora
is my pattern messed up?
Mark M.
you said that it is not working, so ¯\_(ツ)_/¯
Leora
how can i define a navigation base class and override some methods of it depending which app subclasses it?
Mark M.
well, on the whole, I would try to minimize the use of the Kotlin object keyword
ideally, you would be using dependency inversion (Dagger, Koin, etc.)
Leora
i should be using?
Mark M.
personally, I use Koin, as it is very easy to set up -- I use it in quite a few of my books
but, let's skip that for now and say that you still need to use object
Leora
which book? I downloaded all of them
ok
8:55 AM
Mark M.
my intro to DI is in *Elements of Android Jetpack*, I use it in *Exploring Android* in the back third of the book, and many of samples in the other *Elements* books use it
Leora
ok i'll check it out
Mark M.
anyway, you might consider having your base implementation be a regular class, and use objects for leaves of your hierarchy, rather than trying to use one object as a property delegate for another
it is possible that there is a way to get that to work, but I have never tried it, and it makes my stomach queasy
Leora
interesting...until you said queasy
Mark M.
the "queasy" was with reference to the property delegate approach
Leora
i'm sorry, which is that?
Mark M.
I would see if the library can have the base class implementing the interface, and different modules can create subclasses of that as singleton objects as needed
object NavigationST : INavigation by Navigation{} // by is the keyword to set up a property delegate
Leora
ooooh
9:00 AM
Mark M.
if Navigation is an object, you now have an object whose implementation is backed by another object
Leora
how would the subclass define itself? object NavigationST : Navigation()
?
Mark M.
(I so wish this chat supported Markdown for backticks-as-code)
let's suppose that in this revised approach, you still have INavigation, and Navigation is a base class, not an object
then yes, object NavigationST : Navigation()
Leora
ok, thanks Mark, I'll try it :)
Mark M.
let me take questions from the others, and I should be able to get back to you before the chat ends
marekdef: back to you! do you have another question?
marekdef: do you have another question?
9:05 AM
Mark M.
marekdef: if you come up with another question, let me know
9:05 AM
Mark M.
in the meantime...
Kai: back to you! do you have another question?
Kai H.
Yes. I want the background of a listitem to look a certain way after it had been clicked. I am quite confused after trying to find out how to do it.
Mark M.
I think the typical approach is to use a StateListDrawable for the background, where you have different background for normal an activated
Kai H.
I tried that with checked, but it never got activated.
Mark M.
checked AFAIK is only really there for CompoundButton
activated as a state exists for all views
and it is not used by the framework itself for anything, so our uses of it will not conflict with something else
so, if you use the activated state, you should have better luck
Kai H.
I didn't know that. We used "pressed" and "activated" at a lot of points
Mark M.
pressed as a state should get triggered while the user is sending touch events to the view
Kai H.
A listitem is "activated" after a long press or a press on the "action button" in our app.
If you would short press it or press the action button again, its state goes back to... dunno :D
Mark M.
let's go back to "I want the background of a listitem to look a certain way after it had been clicked"
is this a transient thing (i.e., it reverts to normal after 500ms), or a permanent thing?
and, if it is a permanent thing, doesn't this conflict with the long-press thing?
Kai H.
Permanent
It denotes the item that has been selected last
9:10 AM
Mark M.
and that is something different than the long-click?
Kai H.
The long press brings up action mode (and you can actually press other items and add them to the selection after having pressed one with long-click).
If you short-click it, you just choose it, but don't invoke action mode.
Mark M.
your graphic designer and I are not going to get along
at most, I would do one or the other of those
Kai H.
And it gets a highlight bar atm, but the graphic desiners want another background too
So would I, after having understood what they want.
Mark M.
you'll probably just have to manage that yourself in code
keep track of which one is "selected" and manually swap the backgrounds
Kai H.
I just wanted to clear up my confusion on how to do the selection thing properly on the technical side.
Mark M.
basically, "activated" gives us one application-level UI state that we can leverage, but only one
you're using that for something else
so, this "last selected" state is going to have to be manually tracked
Kai H.
I think that is what I wanted to know.
I guess the usualy states for a normal app would be state_pressed, state_activated and none?
Mark M.
yes, though most of those have framework uses (e.g., the framework switches between normal and pressed)
Kai H.
pressed on clicking something, activated after it has been clicked and none otherwise?
Mark M.
activated is there for application use, and so you can decide if/when a view is activated or not
in your case, you are using that for something else, and I do not recall there being another application-centric state
everything else (pressed, disabled, etc.) are used by the system
and will have ramifications beyond the background
Kai H.
It's good that the framework "uses" the pressed state, as it is something you get automatically.
9:15 AM
Mark M.
yes, and the original vision was that *all* states would be framework-managed
activated was an afterthought, added in API Level 11
and I'm grateful for it
Kai H.
But you could always change the colors for the states?
Mark M.
sure
Kai H.
And "activated" you can actually "grab" as an event, is that what was added in API Level 11?
Mark M.
it's not an event
it's a state that you set yourself, via setActivated()
it's just not one that anything in the framework should be using and setting automatically
and it's not one that the framework will react to, other than for your own purposes (e.g., StateListDrawable)
Kai H.
So before API Level 11 there where not states that could be set by oneself
Mark M.
you could set something like disabled, but then that has other impacts, such as disabling user input
Kai H.
And they added that to give a generic and controllable state besides the framework used ones
Mark M.
correct
Kai H.
I see
Mark M.
let me take questions from the others, and I might be able to get back to you before the chat ends
Leora: back to you! do you have another question?
Leora
yes, but also to say your suggestion of changing the base Nav to class and NavA to object worked!!!
Mark M.
oh, cool
Leora
it's now pointing to the correct methods
totally cool thanks!
Mark M.
you're welcom!
Leora
quick question but looks like a bug
Mark M.
er, welcome!
Leora
registerForActivityResult is suddenly showing up 'unrecognized'
9:20 AM
Leora
red, error
View paste
and the import androidx.activity.result.ActivityResult
 is grey
but the code compiles and runs fine
any idea?
Mark M.
since that stuff is still in alpha IIRC, are you sure that both modules are using that alpha version of androidx.activity or androidx.fragment
Leora
i had it in the library module as api and not implementation
that usualyy takes care of the imports of the app module
Mark M.
agreed, that sounds fine
Leora
but after the error i added the dependencies to the app gradle as well
error persists [insert eye roll here]
Kai H.
If I have something like this, I first click on the elephant in the top right to sync gradle. If that didn't work I restart the IDE
Mark M.
hmmm... there's always Build > Clean Project, and running a Gradle dependency report to confirm you are using the alpha
Leora
did all, even invalidate caches/restart
Mark M.
but, given that this is compiling, it might just be an IDE bug
9:25 AM
Mark M.
what version of Android Studio are you using?
Leora
ok probably
ahhh maybe cause i DARED to try the beta 4.1
i felt i could handle it hahaha
Mark M.
it's not you, it's the beta
Leora
thats what they all say :)
btw i only need the androidx.activity OR androidx.fargment?
not both?
Mark M.
AFAIK, you need whichever one(s) you are using -- so, if you are calling registerForActivityResult() in an activity, you need androidx.activity
Leora
ok thanks
Mark M.
this is just based off of a quick skim of the docs -- I haven't played with these APIs yet
Leora
and thanks Kai for the suggestion - love your name!
ok, i've been feelin bleeding edge
Mark M.
if anyone has any last questions, fire away!
Leora
Thanks so much Mark, a pleasure as always
Kai H.
None for 1 minute :D
What is the airspeed of an unladen swallow? ;-)
Leora
hahaha
9:30 AM
Mark M.
is that an African or European swallow?
Kai H.
*sproing*
aaaaahhhhh....
Mark M.
but, alas, that's a wrap for today's chat
the next one is Saturday at 4pm US Eastern
marekdef
thank you all
Kai H.
Have a good time everyone
Mark M.
have a pleasant day, and stay healthy!
marekdef
has left the room
Kai H.
has left the room
Leora
has left the room
Mark M.
turned off guest access

Tuesday, June 23

 

Office Hours

People in this transcript

  • Kai Hatje
  • Leora
  • marekdef
  • Mark Murphy

Files in this transcript