Office Hours — Today, June 18

Tuesday, June 16

Jun 18
7:25 PM
Mark M.
has entered the room
Mark M.
turned on guest access
Marek D.
has entered the room
Mark M.
hello, Marek
how can I help you today?
Marek D.
hello Mark, thank you for the offer :)
I have an app that is used to buy things i.e. lunch-es
our designer wishes to have onscreen keyboard
7:30 PM
Marek D.
so 12 buttons 0-9 , backspace
I tried Constraint layout to build the things
1st solution is chains
(the keyboard needs dividers as well)
dividers is View with background
looks pretty ok imo :)
2nd solution is Constraint with guidelines
3rd solution is linear layout and backgrounds that build the grid/dividers
so 1 has East South 9-patch
2 has ESW
building those layouts was bit of a challenge
but what I have is quite a lot of buttons
so I have button0.setOnClickListener, button1.setOnClickListener ...
so reviewers are not fond of it and they suggest a recycler view
with GridLayout manager
the challange here is that there is nothing recycled
Mark M.
unless the keyboard is going to have thousands of keys, with scrolling, do not use a RecyclerView
7:35 PM
Mark M.
you add overhead and complexity for no value
Marek D.
agree here
the other challenge is the size of the recycler
to build the cells I need to know the height of it
before I add the buttons to the recycler
Mark M.
if it helps, you can point the reviewers to this chat's transcript and show that I said: don't use a RecyclerViwe
(er, RecyclerView)
Marek D.
yes it will be useful I hope :D
Mark M.
it is really the wrong solution here
of your four approaches, you presented them in about the order I would recommend, with the best one first
Marek D.
ok, next question
I am expecting a question why I choose the 1st approach :)
again the transcript could be a winning argument
Mark M.
the first two are fairly close, and the choice might depend a bit on what the designer wants, particularly for different screen sizes
Marek D.
but if I could somehow measure performance ?
dunno, inflate it 100 times ?
Mark M.
why?
7:40 PM
Marek D.
well I could say this layout performs the best
Mark M.
if you had hundreds of these keyboards in a scrolling container, then perhaps rendering performance would be a metric to worry about
AFAIK, you have just one
Marek D.
agree
Mark M.
if so, I wouldn't worry about that much
the two ConstraintLayout approaches might perform a bit better than the LinearLayout one
Marek D.
ok but this question is more general
Mark M.
but all should have rendering speeds measured in microseconds
Marek D.
if I have two layouts to choose
which to prefer
Mark M.
unless you have lots of them in a scrolling container, performance is unlikely to be a problem
Marek D.
I was developing from 2.1 and I have a tendency to use Linears everywhere
but younger devs say Google says use Constraint :)
Mark M.
LinearLayout got a bad reputation, but again, it was mostly when they were used for complex rows in a ListView
and they had to get rendered and re-rendered and re-re-re-rendered a lot
Marek D.
ok makes sense
Mark M.
ConstraintLayout is also more flexible, so I would lean towards it for new development
Marek D.
if we can return to the keyboard question
keyboard matter
the keyboard is for the price
to enter the price
7:45 PM
Marek D.
the design gave me no hints (I just saw a full price) how to format the price when is being entered
so if I want to put 123.45
View paste
I do spans /1/.00
/12/.00
/123/.00
/123./00
/123.0/0
/123.00/
I display it in a textview
did I broke the chat ?
Mark M.
no
Marek D.
ok nvmd
but the designer wants a blinking cursos
cursor (single)
do you have any hints how to create this cursor effect
/ indicated a bold span previously, forgot to mention that
and of course I forgot the cents
View paste
/123.4/0
/123.45/
Mark M.
well, to be completely honest, your designer and I are not really going to get along
from an accessibility standpoint, the right answer is to just use an EditText
Marek D.
then I cannot use this chat transcript :D
7:50 PM
Mark M.
sorry, but I get fairly grumpy when designers value aesthetics over accessibility
since you are more likely to get sued or fined by a government for accessibility violations than for having boring aesthetics
Marek D.
was not aware
Mark M.
I do not know what the market your app is in, and what the regulations are where you live and distribute the app
but, this is the sort of thing that probably should get reviewed by legal counsel
but, let's pretend that the attorney says the plan is fine, or management does not want to research the point
Marek D.
well I could use edittext
but I think there is a reason they prefer onscreenkeyboard
Mark M.
for abled people, it is possible that an on-screen keyboard is a more efficient solution
Marek D.
1. looks nicer
2. I happen to find screens where keyboard does not open
I don't have particular example at the moment
but I had <EditText><requestFocus/>
and for some reason, for some device the keyboard was not being displayed
Mark M.
yes, sometimes you have to use InputMethodManager to convince the keyboard to appear
Marek D.
and the ET was focused
Mark M.
it's annoying
7:55 PM
Marek D.
so you need to unfocus and focus by hand
never knew how to use it properly (IMM)
if I use edit text for displaying the price
I need to make it disabled
then I do not have blinking cursor, right?
Mark M.
I forget, but I suspect that you are correct
Marek D.
and if I use the edittext enabled then I might have two keyboards
Mark M.
yes
so, you have a few options that I can think of
Marek D.
I am not sure If I have enough mana to convince everyone to use ET
or enough charisma
Mark M.
yes, I'm focusing now on how to implement your blinking cursor
Marek D.
I am all ears
Mark M.
option 1: find a character that looks like a Cursor, put it in your Spanned wrapped in a ForegroundColorSpan, and try calling updateDrawState() periodically to achieve the blinking effect
8:00 PM
Marek D.
123|.00
Mark M.
effectively, yes
option 2: use an image in your Spanned via an ImageSpan, and see if you can animate it via changing color filters or tints or something to make it appear to come and go
option 3: have two TextView widgets wrapped around an ImageView, where the ImageView is your cursor and you animate it using normal animation stuff
Marek D.
thank you very useful
View paste
do you think this has sense as well: FrameLayout with EditText + TextView 
ET has transparent text and cursor non transparent and same text as TV (I could use disabled ET for that as well)
Mark M.
that might work
Marek D.
allright will try them all
Mark M.
a variation on that theme would be to have an EditText that is behind something transparent, so the user cannot tap on it to bring up the system keyboard
Marek D.
yes
Mark M.
then, so long as you suppress the system keyboard at the outset, it probably will not appear
8:05 PM
Marek D.
allright moving to last question
Keyboard is a separate component in reality
i want to keep it dumb
the PriceTag as I call it has the logic
of formatting the price
+ interpreting the keyboard
like not allowing more digits after cents
double commas etc
so keyboard is a custom view
it has listeners for the keyboard presses
the Fragment that holds the view
passes the messages to something
at the moment this something is a viewmodel
let's call it PriceTagViewModel
and it sends formatted string as live data
I am wondering if LiveData makes sense here
this is not async thing
and formatting is pretty fast
Mark M.
no, but LiveData primarily is a reactive thing
we happen to use it for async work, but that does not mean that all LiveData uses should be for async work
for example, in shared viewmodels (such as between two fragments), you might use LiveData as a means of getting values from one fragment to another
8:10 PM
Mark M.
I cannot really say whether you need LiveData here -- that would depend on who is using the formatted string and whether it needs to react to changes in real time
if it does, then LiveData is a reasonable choice, particularly if the project is in Java
Marek D.
is kotlin
Mark M.
you could use coroutines stuff like StateFlow then, if you wanted, or stick with LiveData
Marek D.
I was just wondering it this pseudo code would make more sense. priceTagTextView.text = priceTag.append(1)
where priceTag is a viewmodel (but could be just any object)
so all methods of this object would return immediately the result of manipulation of the price
Mark M.
¯\_(ツ)_/¯
Marek D.
:)
ok many thanks for the chat
Mark M.
it is difficult for me to provide that level of advice, as I do not know your code
Marek D.
I understand
I just don't like that people put LD everywhere
8:15 PM
Marek D.
because Google says LD is the king
Mark M.
LiveData is fine for cases where the supplier of data cannot have a reference to the consumer of that data, such as a viewmodel not having a reference to a fragment
so, you would not use LiveData (usually) to have a fragment get data *to* a viewmodel, because it is perfectly fine for a fragment to have a reference to its viewmodel
LiveData, in the end, is a lifecycle-aware value holder with a set of observers
in other words, it is a callback system with a great marketing budget
ansh s.
has entered the room
Marek D.
for me LD is a kind of event bus
Mark M.
it happens to solve the viewmodel -> fragment problem fairly nicely
ansh s.
Hi mark
Marek D.
+ redelivery of the last value
Mark M.
Marek: let me try to take a question from Ansh, before the chat is over -- if there is time, I will swing back to you
Marek D.
sure
Mark M.
Ansh: hi! how can I help you today?
8:20 PM
ansh s.
Nothing much, you can go on talking to marek (Hi btw) . I saw your time and came to say a hi. hope you are doing fine and safe, its been long since i came here. Also I was able to figure out the issue with my DB Problem(From the community ) . turns out we don't have to set the foriegn key constraint on the relation table
Mark M.
ah, OK -- I haven't played with M:N relations in Room recently, and I forgot
ansh s.
View paste (3 more lines)
check this out:


@Entity(
        tableName = "item_cat_relation",
        primaryKeys = ["cat_id", "item_id"],
        indices = [Index("cat_id"), Index("item_id")]
//        , foreignKeys = [
//            ForeignKey(entity = MenuCategory::class, parentColumns = ["cat_id"], childColumns = ["cat_id"],onDelete =ForeignKey.NO_ACTION),
//            ForeignKey(entity = MenuItem::class, parentColumns = ["item_id"], childColumns = ["item_id"],onDelete =ForeignKey.NO_ACTION)
//        ]
)
data class ItemCategoryRelation(
        val cat_id: String,  //warning(?) :exact names as parent columns
        val item_id: String
...
Mark M.
my apologies for not thinking of that in the forum thread!
ansh s.
No worries.But i think this has been in your book too. you might want to update that
Marek D.
View paste
Hi Ansh.
I will be leaving. 
Thank you Mark!
Mark M.
ah, but you have foreign keys from the other tables to the ItemCategoryRelation, right?
Marek: you're welcome!
ansh s.
Although my guess was just randomly commenting out the code, and you are the boss of things , can you explain what is happenning ?
no i don't have any other relations, room is figuring out on its own
Mark M.
yeah, I was just looking at those and cross-checking with my book samples
give me one minute for some research
8:25 PM
Mark M.
hmmm...
ansh s.
sure. does my initial query about keeping the same column names still holds true?
Mark M.
well, I thought my comment there was correct
now I am going to need to spend some time and try to see what is going on
ansh s.
oh ok :)
Also i am not sure about this, but i think room's debug libs have a bug
Mark M.
it wouldn't be the first time :-)
but, let me poke at this a bit and I'll try to respond back to your forum post this weekend
ansh s.
hehe. as you said , when i tested my code with activity, it ran fine, but this code is still not producing any outputs in the instrumentation test
sure
BtW , How are things in the US ? are you safe and healthy?
Mark M.
AFAIK, yes :-)
I hope things are OK with you as well!
ansh s.
yeah. I would have graduated this year if covid didn't happenned
8:30 PM
Mark M.
sorry to hear that!
ansh s.
Hey i wanted to know how can i check about the expiry of my subscribtion
i mean when do i have to renew it? i wanted to know that
Mark M.
log in, click the Renew option in the nav bar
under the "Renew!" headline will be your expiration date
ansh s.
oh ok, found that, thanks
Well i will be going now. nice talking to you
Mark M.
likewise!
the next chat is Thursday at 4pm US Eastern
ansh s.
has left the room
Mark M.
the transcript for this chat will appear at https://commonsware.com/office-hours/ shortly
Marek D.
has left the room
Mark M.
turned off guest access

Tuesday, June 16

 

Office Hours

People in this transcript

  • ansh sachdeva
  • Marek Defecinski
  • Mark Murphy