Jun 30 | 8:25 AM |
Mark M. | has entered the room |
Mark M. | turned on guest access |
Marek D. | has entered the room |
Mark M. |
hello, Marek!
|
Mark M. |
how can I help you today?
|
Marek D. |
hello :)
|
Marek D. |
you know I have this custom keyboard ...
|
Marek D. |
1st question loosely related
|
Marek D. |
if I read attributes from xml
|
Marek D. |
obtainStyledAttributesm then getString on TypedArray
|
Marek D. |
the linter gives me warning to recycle this array
|
Marek D. |
what would be the best way to do it
|
Marek D. |
try {} finally { ta.recycle}
|
Marek D. |
there is ktx extension use
|
Marek D. | |
Marek D. |
which does not do finally
|
Mark M. |
did you check the implementation?
|
Jun 30 | 8:30 AM |
Mark M. |
yeah, they didn't use try/finally: https://androidx.tech/artifacts/core/core-ktx/1...
|
Mark M. |
that's disappointing
|
Marek D. |
there is an issue but closed
|
Marek D. | |
Mark M. |
of your two choices, I would be happier with the try/finally one
|
Marek D. |
I understand that exception there is a serious bug, so maybe is better to crash the app
|
Marek D. |
but you always can catch it higher
|
Mark M. |
but then use() is pointless
|
Mark M. |
because you still need to manually recycle() the TypedArray
|
Mark M. |
(in the finally block)
|
Marek D. |
right
|
Marek D. |
and if I have multiple values to read from TypedArray
|
Jun 30 | 8:35 AM |
Marek D. |
I wonder If I should wrap each call to tpedArray.get*
|
Mark M. |
well, you do not have to rely on the return value from use()
|
Mark M. |
I would put all of them in a single try block, with a finally that recycles
|
Marek D. |
well if some attribute is not read correctly I guess the whole view is not usable
|
Mark M. |
yes, but then the answer is to gracefully exit the activity/fragment that is using it, not crash the app
|
Mark M. |
though, in that case, the try/finally would need to reside somewhere else
|
Mark M. |
this is one of the reasons why I'm not a fan of custom views -- there are too many levels of indirection
|
Leora | has entered the room |
Mark M. |
which makes this sort of exception handling difficult
|
Mark M. |
let me take a question from Leora, and I will return to you in a bit
|
Mark M. |
Leora: hi! how can I help you today?
|
Marek D. |
go ahead
|
Leora |
Hiya Mark!
|
Leora |
I was wondering which is faster
|
Jun 30 | 8:40 AM |
Leora |
to have a regular txt file, parse it once into a hashmap, and then look up the values by key
|
Leora |
or xml string file and search for the string
|
Kai H. | has entered the room |
Kai H. |
Hi everyone
|
Leora |
Hi Kai!
|
Mark M. |
Leora: I do not understand the second one -- do you mean literally searching an XML string? or do you mean parsing the XML like you were proposing to do for the text file?
|
Mark M. |
(BTW, hello Kai!)
|
Leora |
literally searching for the R.string.x
|
Mark M. |
but, then, how would you get the corresponding value? manually grab it out of some MatchResult from a regex?
|
Leora |
i don't understand
|
Mark M. |
it looks like you are trying to find the value associated with a key
|
Mark M. |
leastways, that is what your first scenario was ("look up the values by key")
|
Leora |
ahhh sorry i got confused
|
Leora |
the xml option is an array of strings
|
Jun 30 | 8:45 AM |
Mark M. |
then, what are you looking for in the array? just a boolean of whether the string exists? are you looking for an index into the array? something else?
|
Leora |
so i pull the array and have a for loop to find the string
|
Mark M. |
so, you are parsing the XML
|
Leora |
only if it's found in the list yes
|
Leora |
yes
|
Mark M. |
in your original scenario, you parsed the text file once and held onto the results for multiple lookups (as I understood it)
|
Mark M. |
is that what you are doing in the XML scenario as well? or are you proposing re-reading the XML each time you need to do a lookup?
|
Leora |
let's say i do that once as well
|
Mark M. |
in that case, the two variables are: how efficient is the parsing, and how efficient is your resulting data structure
|
Leora |
:)
|
Mark M. |
using either data representation (plain text vs. XML), you should be able to organize the results into a data structure that works well for whatever your lookup needs are
|
Mark M. |
there is nothing intrinsic about XML parsing, for example, that says you need to live with some inconvenient data structure in the end
|
Mark M. |
so for "how efficient is your resulting data structure", they should be equivalent, because they should be the same data structure
|
Jun 30 | 8:50 AM |
Mark M. |
in terms of whether parsing a plain text file vs. XML is faster, you would need to benchmark that
|
Leora |
ok thanks Mark
|
Mark M. |
I can see arguments either way
|
Mark M. |
sorry that I did not have a clearer answer for you!
|
Leora |
ok then i won't worry about it :)
|
Mark M. |
let me take questions from the others, and I will come back to you in a bit
|
Leora |
that WAS clear
|
Mark M. |
Kai: over to you! how can I help you today?
|
Kai H. |
If Marek has a question atm, I would let him go first
|
Mark M. |
he was in first, so he already had his first question
|
Kai H. |
Ok
|
Mark M. |
I can still switch back to him if you like, but you are next in rotation
|
Marek D. |
I have question :)
|
Kai H. |
What is the current approach to multi pane ui?
|
Mark M. |
you mean like the master-detail pattern?
|
Kai H. |
I guess?
|
Kai H. |
Opening a new Fragment on the phone but show the Fragment "in-place" on a Tablet
|
Mark M. |
see the images here: https://stackoverflow.com/questions/11773433/an...
|
Kai H. |
That is what I mean
|
Mark M. |
(they aren't the greatest, but they are what is coming up quick in a Web search)
|
Kai H. |
Yes :D
|
Mark M. |
Google has been backing away from that pattern, mostly because they want a seamless UI transition for resizeable windows (e.g., on Chrome OS)
|
Kai H. |
Would you still have different layouts for the different cases and then simply decide in code which way to go?
|
Kai H. |
Oh, ok
|
Kai H. |
The app I'm maintaining relies heavily on that for tablet :D
|
Mark M. |
and, IMHO, there is nothing wrong with it
|
Jun 30 | 8:55 AM |
Kai H. |
A list on the left, Details on the right.
|
Kai H. |
I agree. It seems quite sensible, given the screen space. I actually prefer our app on the tablet for that reason.
|
Kai H. |
Less switching back and forth between screens.
|
Mark M. |
I agree with Google's concern about resizeable windows, but that's just not a case that developers care much about, on the whole
|
Mark M. |
the classic approach to master-detail involved layout resources for the different screen sizes
|
Mark M. |
so, for example, suppose it is at 800dp current width when you want to switch from "phone UI" to "tablet UI"
|
Mark M. |
in res/layout/, you would have a layout for the activity that had a pane for a single fragment
|
Mark M. |
in res/layout-w800dp/, you would have the same layout, with panes for two fragments
|
Kai H. |
Ok, so that still holds
|
Kai H. |
And then decide in the code which one to load?
|
Mark M. |
in Java/Kotlin, after inflating the layout, you would see whether you have the second pane, and react accordingly, both for the initial screen population and then what happens when the user clicks on a list item
|
Mark M. |
while the code is older, I have a chapter on this in *The Busy Coder's Guide* that goes through a number of implementation approaches
|
Mark M. |
(and, that chapter will still use "master-detail" as the name, for historical reasons, though we really need to come up with another term for that...)
|
Kai H. |
So I guess our app is still current in that regard. I was just wondering if something more "automagic" has come along in the meantime, where you don't need to differentiate in code how to load your second pane.
|
Mark M. |
nope
|
Mark M. |
it's possible that the Navigation component has some stuff to simplify this
|
Kai H. |
I actually had a look into busy coders guide for that :)
|
Jun 30 | 9:00 AM |
Kai H. |
Heh, we are quite a bit away from using something as modern as that ;-)
|
Mark M. |
let me take questions from the others, and I will come back to you a bit later
|
Kai H. |
I guess that answers my question. Thanks.
|
Mark M. |
Marek: back to you! I think you said that you had another question!
|
Marek D. |
yes, I would like to have autoSizeTextType behavior
|
Marek D. |
in EditText
|
Mark M. |
I have not tried that, but since EditText extends from TextView, I would have hoped that "it just works"
|
Marek D. |
unfortunately :\
|
Mark M. |
what are the results? is it basing the font size based on the initial EditText contents?
|
Marek D. |
I also want singleLine behavor
|
Marek D. |
I am wonder how can I share screenshot
|
Marek D. |
the EditText goes into multilinemode
|
Mark M. |
in the column on the right, towards the bottom, there is "Upload a file"
|
Marek D. |
ok I see it
|
Marek D. | |
Marek D. |
it seems my screenshot software has the possibility
|
Mark M. |
in terms of the multiple lines, do you have android:maxLines="1" in the <EditText> element?
|
Marek D. | |
Jun 30 | 9:05 AM |
Marek D. |
View paste
|
Mark M. |
that feels like a bug
|
Mark M. |
I can see autosize not working dynamically based on text entry, but it should not somehow break the line count limits
|
Marek D. |
View paste
|
Mark M. |
well, that's disappointing
|
Marek D. |
View paste
|
Marek D. |
I just noticed that
|
Marek D. |
but since I want single line
|
Marek D. |
I guess textMultiLine is not needed
|
Mark M. |
I have not needed that for single-line input in the past, but perhaps I am mis-remembering
|
Marek D. |
Ok I guess I need to find a library for that
|
Mark M. |
if you mean autosize for EditText, you can try
|
Mark M. |
I suspect that you will be out of luck
|
Marek D. |
unless maxLines lines is a big
|
Marek D. |
bug
|
Mark M. |
if you remove the autoSize* attributes, does the single-line behavior work?
|
Marek D. |
no it does not
|
Jun 30 | 9:10 AM |
Mark M. |
that's very strange
|
Marek D. | |
Marek D. |
inputType=text
|
Marek D. |
solves it
|
Marek D. |
so now it has singleline behaviour
|
Mark M. |
OK, that matches my experience
|
Mark M. |
but I do not have a solution for you for autosize -- sorry!
|
Marek D. |
sure no problem
|
Marek D. |
I pass the token
|
Marek D. |
(for the next person)
|
Mark M. |
next in our "token ring" is Leora... Leora: do you have another question?
|
Leora |
yes, follow up to before and layout q
|
Leora |
so in the case i need to look up a string from the resources, i assume it is more expensive than searching for the key-value from a hashmap?
|
Mark M. |
by "look up a string from the resources", do you just mean getString(R.string.whatever)? or do you mean something else?
|
Leora |
yes getString
|
Mark M. |
resources are cached by the framework
|
Mark M. |
I do not know the details of exactly how string resources get cached
|
Leora |
oh!
|
Mark M. |
but there should not be incremental I/O for additional getString() calls
|
Leora |
oh nice
|
Mark M. |
so, unless you are doing thousands of these things, I suspect that speed is not going to be a major deciding factor
|
Leora |
ok cool
|
Leora |
may i ask the layout q?
|
Jun 30 | 9:15 AM |
Mark M. |
if it's quick, go ahead
|
Leora |
I have a bottom toolbar i built with constraintLayout
|
Leora |
it goes past the left and right boundaries of the screen on a few devices
|
Leora |
a
|
Leora |
as in, the left and right icons are cut off
|
Kai H. |
I don't have anymore questions btw, so she can have the remaining time if it comes to me
|
Mark M. |
(Kai: OK!)
|
Leora |
i advised with someone who said they hate constraint (don't feel the reason for it), and told me to put it in linearLayout
|
Leora |
LL works perfectly of course
|
Mark M. |
then CL could handle it, but there was something off in your constraints, most likely
|
Leora |
but i've come to love constraintLayout and feel like I'm not 'getting' something if it doesn't work
|
Leora |
like what? it's a very basic bottom bar, match-parent width, fixed height
|
Mark M. |
how are the icons set up? if the bar itself is a CL, did you set up a chain for those icons?
|
Leora |
yes
|
Mark M. |
OK, then I am really surprised that the chain somehow went over the CL boundaries
|
Mark M. |
you said that the bar is "match-parent width" -- what is the bar inside of?
|
Leora |
View paste
(5 more lines)
|
Mark M. |
I am guessing that you are using <include> to pull that into another layout
|
Jun 30 | 9:20 AM |
Leora |
it's inside a frameLayout with math-parent
|
Leora |
since it is loaded dynamically
|
Leora |
(switched out at runtime per lite or full)
|
Leora |
the frameLayout is part is inside CL
|
Mark M. |
so, you are inflating this toolBarLayout yourself via a LayoutInflater?
|
Leora |
yes
|
Mark M. |
do you have a device that reproduces the problem? or is this just coming from reports from users?
|
Leora |
emulators yes
|
Mark M. |
then I would check to make sure that the LayoutInflater logic is working as expected and that its FrameLayout container is also working as expected (not overflowing the screen)
|
Leora |
hmmm
|
Mark M. |
neither of those would explain why a LinearLayout works where the ConstraintLayout does not
|
Leora |
right
|
Mark M. |
but it would be where I would look for debugging purposes, at least as a starting point
|
Leora |
most pixels it looks perfect
|
Mark M. |
rolling back to the advice that you were given, LL has a worse reputation than is warranted
|
Mark M. |
so IMHO if you wanted to use a LL here, that should be fine
|
Mark M. |
but a CL should be able to handle the situation, and if it cannot, that is probably a bug
|
Leora |
ok, but how can i check if FL is overflowing? i need to have images in it....
|
Mark M. |
Layout Inspector in Studio would be one possibility
|
Jun 30 | 9:25 AM |
Leora |
i used to love LL, just trying to be a good ANdroid soldier as usual
|
Mark M. |
or, toggle on the view-bounds stuff in Developer Options to draw boxes around everything
|
Mark M. |
the problems with LL come in when you have lots of them in a scrolling container
|
Leora |
hmmm ok
|
Mark M. |
for a fixed-position toolbar, LL's performance issues won't be a problem
|
Leora |
i see
|
Leora |
great I'll test away then Mark
|
Leora |
Thank you!
|
Mark M. |
OK, we're running out of chat time -- if anyone has any final questions, fire away!
|
Kai H. |
Why does my AlertDialog title have a low contrast on some Samsung devices? :D
|
Mark M. |
only on some devices? your activity theme should be controlling that, assuming you are creating the AlertDialog using an Activity as your Context
|
Kai H. |
Hm ok
|
Kai H. |
Thanks :D
|
Leora |
Have a great day everyone!
|
Marek D. |
thank you for the chat
|
Kai H. |
Same
|
Jun 30 | 9:30 AM |
Mark M. |
OK, that's a wrap for the chat, then!
|
Mark M. |
next one is Thursday in the 7:30pm US Eastern slot
|
Mark M. |
have a pleasant day, and stay healthy!
|
Marek D. | has left the room |
Leora | has left the room |
Kai H. | has left the room |
Mark M. | turned off guest access |