Mark M. | has entered the room |
Mark M. | turned off guest access |
Mark M. | turned on guest access |
Feb 16 | 4:00 PM |
Pavan | has entered the room |
Pavan |
Hi
|
Mark M. |
howdy, Pavan!
|
Mark M. |
how can I help you today?
|
Pavan |
Doing good how about you?
|
Mark M. |
a little short on sleep, otherwise OK
|
Pavan |
good. okay here is my question
|
Pavan |
Is detecting Video Playing Events possible in android?
|
Pavan |
for the default player
|
Mark M. |
first, there is no single "default player"
|
Pavan |
if my question is vague let me explain it a little bit
|
Feb 16 | 4:05 PM |
Mark M. |
second, I am not aware of any broadcasts for any particular video player
|
Feb 16 | 4:05 PM |
Raza R. | has entered the room |
Pavan |
Yes I have checked the source code and I have come to conclusion ( atleast on ICS) that MediaPlayer is called
|
Raza R. |
hello everyone
|
Mark M. |
howdy, Raza
|
Pavan |
Hmm So if I want to build some kind of logger which can log these events, Can I do it? If so do you have any suggestions
|
Mark M. |
Pavan: while MediaPlayer is the core of most (if
not all) video players on Android, I am not aware that it has any
documented broadcast Intents or other cross-process event messages
|
Raza R. |
Murphy, It's high time you should include API access tutorial in books
|
Mark M. |
moreover, MediaPlayer is frequently modified, so you cannot even rely upon certain LogCat messages showing up
|
Mark M. |
(Raza: please wait a moment, and I will get to you shortly)
|
Mark M. |
Pavan: hence, I know of no way you can find out specifically about video playback events
|
Mark M. |
there may well be some trick of which I am unaware
|
Mark M. |
let me take Raza's question, and then I will come back to you
|
Mark M. |
Raza: my books cover all sorts of APIs. What is your specific concern?
|
Pavan |
You have started writing Vidtry, may I know why you have scrapped the project ?
|
tunneling | has entered the room |
Raza R. |
google api java client
|
Mark M. |
Raza: I will probably cover that sometime this year
|
Nitin S. | has entered the room |
Mark M. |
however, it's not really part of Android
|
Raza R. |
As i've to access many google service like calendar, G+, docs, graphs
|
Raza R. |
etc
|
Mark M. |
any more than Twitter is
|
Feb 16 | 4:10 PM |
Nitin S. |
Hello
|
Mark M. |
howdy, tunneling and Nitin!
|
Mark M. |
busy room today
|
tunneling |
greetings
|
Mark M. |
tunneling: do you have a question?
|
Nitin S. |
yeah..
|
Raza R. |
many indians are here
|
Nitin S. |
I do..
|
Mark M. |
(Nitin: tunneling beat you here by a few seconds, so I will take tunneling's question, then it will be your turn)
|
tunneling |
yea, i was hoping to discuss a pattern for dynamically updating a listview
|
Nitin S. |
No issue
|
tunneling |
not on the UI thread
|
Mark M. |
well, technically, that's not possible
|
Mark M. |
you can do lots of prep work on a background thread
|
Mark M. |
but you cannot modify a ListView itself from a background thread
|
Mark M. |
which also means that you cannot modify an Adapter attached to a ListView from a background thread
|
tunneling |
or even the adapter's ArrayList
|
tunneling |
exactly
|
Mark M. |
well, you can modify the ArrayList directly, as
the ArrayAdapter will be oblivious to those changes until you call
notifyDataSetChanged()
|
Mark M. |
but you would need to call notifyDataSetChanged() on the main application thread
|
tunneling |
Using the MergeAdapter, I update the ArrayList of
one of the Adapters, and get an exception.. about updating the contents
of the Adapter off the UI thread...
|
Mark M. |
so, for example, if you use an AsyncTask, you
would do as much as you can in doInBackground(), before triggering the
UI work in onPostExecute()
|
Mark M. |
correct
|
Feb 16 | 4:15 PM |
tunneling |
so I'm a little confused, are you saying I can or can't manipulate the ArrayList from the background thread?
|
Mark M. |
you can update the ArrayList directly, via methods on ArrayList, AFAIK
|
Mark M. |
you cannot update the ArrayList by means of methods on the ArrayAdapter
|
Mark M. |
e.g., call add()/insert()/remove() on the ArrayList, not the ArrayAdapter
|
tunneling |
ah
|
tunneling |
then call notifyDatasetChanged from the UI thread?
|
Mark M. |
yes
|
Mark M. |
basically, calling, say, add() on the adapter triggers an immediate notifyDataSetChanged() call
|
tunneling |
right.. ok
|
Mark M. |
let me take questions from the others, and I'll swing back to you in a bit
|
Mark M. |
Nitin: do you have a question?
|
tunneling |
sure.. ill go check my code in the meanwhile
|
Nitin S. |
yes..
|
Nitin S. |
Can we display all the key value pairs in SharedPreferences along with the check boxes?
|
Mark M. |
what do you mean by "along with the check boxes"?
|
Feb 16 | 4:20 PM |
Nitin S. |
I mean I want to populate a row in a ListView with the key value and a check box.
|
Mark M. |
OK
|
Mark M. |
so create a ListView with android:choiceMode="multipleChoice" and a suitable row layout
|
Mark M. |
create a subclass of BaseAdapter that can wrap around the SharedPreferences
|
Raza R. |
ok guyz my inverter about to die. Will catch Murphy in next Office hours.
|
Nitin S. |
ok. I'll try that.
|
Nitin S. |
thank you
|
Mark M. |
Raza: best of luck with your inverter!
|
Mark M. |
Nitin: you can use getAll() on SharedPreferences to get a Map, then perhaps sort the keys or something
|
Mark M. |
Pavan: do you have another question?
|
Mark M. |
Raza: if you are still here, do you have another question?
|
Nitin S. |
Can I put two lines of code here as I have a question on that?
|
Mark M. |
(Nitin: hold on, I will get back to you again shortly)
|
Nitin S. |
ok
|
Mark M. |
tunneling: do you have another question?
|
Feb 16 | 4:25 PM |
tunneling |
still looking at the same thing.. studying my old code
|
Mark M. |
OK
|
Mark M. |
Nitin: go ahead with your question
|
Nitin S. |
View paste
|
Mark M. |
I think that needs to be Map<String, ?>
|
Nitin S. |
on the 2nd line, the eclipse complains of unchecked cast?
|
Mark M. |
right
|
Nitin S. |
sorry, i didn't get you.
|
Mark M. |
rather than that, do Set<String> keys=mypref.getAll().keySet()
|
Mark M. |
;
|
Mark M. |
then, organize those keys (e.g., turn them into a sorted ArrayList via Collections.sort())
|
Mark M. |
then, you could just wrap the resulting ArrayList in an ArrayAdapter, and have it do the preference lookup
|
Mark M. |
to get the value
|
Mark M. |
though, if you want a real checklist, you would
more iterate over the ArrayList, check each preference value, and use
that with setItemChecked() on the ListView
|
Nitin S. |
ok.. noted. Actually, this is not related to the display of preferences.
|
Feb 16 | 4:30 PM |
Mark M. |
um, I thought that was what you asked about
|
Mark M. |
oh, wait, you mean your second question was not tied to the ListView?
|
Nitin S. |
I need to get the Map only to use containsValue() method in the Map
|
Nitin S. |
Yes.
|
Mark M. |
OK, declare it as Map<String, ?> then
|
Nitin S. |
Okay. Thanks.
|
Mark M. |
if anyone has any other questions, chime in
|
tunneling |
I think my problem is accessing the ArrayList while it could be getting updated.
|
Nitin S. |
The cast too would need to have the '?'. Is it?
|
Mark M. |
Nitin: Yes
|
Mark M. |
tunneling: that should result in a ConcurrentModificationException or some such
|
tunneling |
never got an exception.. i think it just blocks or gave crazy results
|
tunneling |
The setup is that I have MergeAdapter with 3 different Adapters that uses an ArrayList<CustomObject>
|
Feb 16 | 4:35 PM |
tunneling |
the number of CustomObjects in the ArrayList can be changed by a background thread
|
Nitin S. |
Thanks Mark. Am done.
|
Nitin S. |
:)
|
tunneling |
I think I was trying to
"handler.post(updateAdapter();" from the background thread.. but before
the updateAdapter() method could complete, the background thread changed
the contents of the ArrayList
|
Mark M. |
can't you just update the ArrayList then during your post() operation?
|
tunneling |
hmm.. maybe so.
|
tunneling |
I need to think about how to pass the CustomObject to the ArrayList with the post() operation.
|
Mark M. |
perhaps think of it more as having the thing that already has the CustomObject be the one that calls post()
|
Mark M. |
courtesy of the final keyword, you can make sure that the Runnable has the right objects
|
Feb 16 | 4:40 PM |
Pavan |
Mark: Could I register a receiver to some other
broadcast event which might indirectly tell me that the video is
currently playing or not Or you say that currently there is no other way
to do it?
|
Raza R. | has left the room |
Mark M. |
Pavan: I know of no broadcast that could help you here
|
Pavan |
okay
|
Pavan |
thanks
|
tunneling |
for some reason, i adopted some code a while back
for updating the Adapter where you .clear the adapter, then iterate over
the ArrayList and add everything back.. is that necessary?
|
Mark M. |
not normally
|
tunneling |
View paste
|
Mark M. |
add(), insert(), and remove() work nicely, if that's your set of changes to make
|
Mark M. |
what is eld?
|
tunneling |
the ArrayList
|
Feb 16 | 4:45 PM |
Mark M. |
that's not the ArrayList that the ArrayAdapter is using, then
|
tunneling |
so I've always ran that bit of code on the UI thread when there have been changes
|
Mark M. |
clear() would wipe out the contents of both
|
Mark M. |
you are better served making incremental changes on the ArrayAdapter where possible (add(), insert(), remove())
|
Mark M. |
or, if nothing else, use clear(), then addAll()
|
Mark M. |
oh, wait, addAll() is API Level 11
|
Mark M. |
never mind that
|
Mark M. |
still, normally, you just make incremental changes where possible
|
Mark M. |
I'd only clear() and start over if there might be more substantive changes (e.g., re-sort)
|
tunneling |
Ok, so I'll try that approach. If that Adapter is contained in the MergeAdapter, do I need to do anything extra?
|
Mark M. |
no
|
Mark M. |
at least, not that I can think of
|
tunneling |
Ok, wasn't sure if the changes would automatically propogate up
|
Mark M. |
they should -- I think I added that logic to MergeAdapter
|
Mark M. |
if not, that's a bug on my side
|
tunneling |
ok, I'll let you know if it doesn't
|
Pavan | has left the room |
Feb 16 | 4:50 PM |
Nitin S. | has left the room |
tunneling |
I'll make some changes to my code, and try the things we've discussed.
|
Mark M. |
OK
|
tunneling |
Do you have time for one more quick one?
|
Mark M. |
9 minutes worth of time! :-)
|
tunneling |
Ok, so another topic I am interested in is Filtering my list based on a field of the CustomObject
|
Mark M. |
I have done very little with Filterable
|
tunneling |
I have seen a few examples where the Filtering is done based on text, but wasn't quite sure how to build a custom filter
|
tunneling |
ok
|
tunneling |
I think I just need to look at the source and try to figure out what needs to be overridden
|
Mark M. |
well, filters are driven by strings that the user enters
|
Mark M. |
how you elect to apply those strings is up to you
|
tunneling |
essentially I want to show a full list of
CustomObjects... then on a swipe left, show on the ones that are RED, or
on a swipe right, show only the ones that are GREEN. Maybe I should
just rebuild the entire list?
|
Feb 16 | 4:55 PM |
Mark M. |
well, that doesn't sound like Filter and Filterable
|
Mark M. |
is this for the same activity that is using your MergeAdapter?
|
Mark M. |
and, if so, is RED one ArrayList<CustomObject> and GREEN another one?
|
tunneling |
no
|
Mark M. |
ah, OK, never mind then
|
Mark M. |
but, in the end, I suspect you will either have to
rebuild the list or maintain multiple ListViews that you are really
swiping between
|
tunneling |
basically all of the CustomObjects in the
MergeAdapter have a color, but they have a different unique property
that determines their Adapter (e.g. Weight)
|
Mark M. |
OK
|
tunneling |
I laugh at myself trying to talk in generic object terms.. for my app it would be a list of what are called Units
|
Mark M. |
let's see... red and green... various different weights... this is a Christmas ornament organizer app, right? :-)
|
tunneling |
Units consist of Lights, Outputs, and Flags
|
tunneling |
So each one of them have a state that can be On or Off.
|
tunneling |
I want the user to be able to swipe left to filter the list to only the Units that are On
|
tunneling |
Right for only the Units that are Off
|
Mark M. |
how do they get back to the original full roster? you are running out of axes
|
tunneling |
on <- all -> off
|
tunneling |
start at all
|
Feb 16 | 5:00 PM |
Mark M. |
ah
|
Mark M. |
that feels like a ViewPager with three ListViews
|
Mark M. |
handles the swiping for you
|
tunneling |
have you played around with the google+ app?
|
Mark M. |
nope, I'm not a G+ member
|
tunneling |
ok.. do you have the new google music app?
|
Mark M. |
but, I'm betting G+ uses ViewPager, if they have a similar sort of horizontal-swipe-between-lists feature
|
Mark M. |
if by "new" you mean "the one that came out a couple of months ago", then yes
|
tunneling |
not sure what version it's on.. but from the listviews of ARTIST, ALBUMS, SONGS....
|
Mark M. |
I am 99% certain that is a ViewPager
|
tunneling |
you can do the swipe thing and it goes from one list to the next.. i'll study up on the ViewPager
|
Mark M. |
it's in the Android Support package
|
tunneling |
nice.
|
Mark M. |
I have not yet covered it in the books, but it will be there as part of The Big Book Reboot
|
tunneling |
ok
|
Mark M. |
the new app for the tutorials is a mini EPUB reader, which uses ViewPager to flip between chapters
|
tunneling |
yea.. im thinking their header tabs must be in a different fragment
|
Mark M. |
perhaps not a fragment per se, but it is outside the ViewPager itself
|
tunneling |
ok.. great.. I'll give that a try.
|
Mark M. |
anyway, that's a wrap for today's chat
|
tunneling |
ok
|
Mark M. |
next one is Tuesday at 7:30pm Eastern
|
tunneling |
may.. that goes by too fast
|
Feb 16 | 5:05 PM |
Mark M. |
have a pleasant day!
|
tunneling |
thanks for your time!
|
tunneling | has left the room |
Mark M. | turned off guest access |