Office Hours — Today, February 16

Tuesday, February 14

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!
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
Is detecting Video Playing Events possible in android?
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
4:05 PM
Mark M.
second, I am not aware of any broadcasts for any particular video player
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
(Raza: please wait a moment, and I will get to you shortly)
Pavan: hence, I know of no way you can find out specifically about video playback events
there may well be some trick of which I am unaware
let me take Raza's question, and then I will come back to you
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
etc
Mark M.
any more than Twitter is
4:10 PM
Nitin S.
Hello
Mark M.
howdy, tunneling and Nitin!
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
you can do lots of prep work on a background thread
but you cannot modify a ListView itself from a background thread
which also means that you cannot modify an Adapter attached to a ListView from a background thread
tunneling
or even the adapter's ArrayList
exactly
Mark M.
well, you can modify the ArrayList directly, as the ArrayAdapter will be oblivious to those changes until you call notifyDataSetChanged()
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()
correct
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
you cannot update the ArrayList by means of methods on the ArrayAdapter
e.g., call add()/insert()/remove() on the ArrayList, not the ArrayAdapter
tunneling
ah
then call notifyDatasetChanged from the UI thread?
Mark M.
yes
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
Nitin: do you have a question?
tunneling
sure.. ill go check my code in the meanwhile
Nitin S.
yes..
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"?
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
so create a ListView with android:choiceMode="multipleChoice" and a suitable row layout
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.
thank you
Mark M.
Raza: best of luck with your inverter!
Nitin: you can use getAll() on SharedPreferences to get a Map, then perhaps sort the keys or something
Pavan: do you have another question?
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?
4:25 PM
tunneling
still looking at the same thing.. studying my old code
Mark M.
OK
Nitin: go ahead with your question
Nitin S.
View paste
HashMap<String, String> all = new HashMap<String, String>();
			all = (HashMap<String, String>) mypref.getAll();
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()
;
then, organize those keys (e.g., turn them into a sorted ArrayList via Collections.sort())
then, you could just wrap the resulting ArrayList in an ArrayAdapter, and have it do the preference lookup
to get the value
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.
4:30 PM
Mark M.
um, I thought that was what you asked about
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
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
tunneling: that should result in a ConcurrentModificationException or some such
tunneling
never got an exception.. i think it just blocks or gave crazy results
The setup is that I have MergeAdapter with 3 different Adapters that uses an ArrayList<CustomObject>
4:35 PM
tunneling
the number of CustomObjects in the ArrayList can be changed by a background thread
Nitin S.
Thanks Mark. Am done.
:)
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.
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()
courtesy of the final keyword, you can make sure that the Runnable has the right objects
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
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
		eldAdapter.clear();
		if (eld != null && eld.size() > 0) {
			for (int i = 0; i < eld.size(); i++) {
				eldAdapter.add(eld.get(i));
			}
		}
Mark M.
add(), insert(), and remove() work nicely, if that's your set of changes to make
what is eld?
tunneling
the ArrayList
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
you are better served making incremental changes on the ArrayAdapter where possible (add(), insert(), remove())
or, if nothing else, use clear(), then addAll()
oh, wait, addAll() is API Level 11
never mind that
still, normally, you just make incremental changes where possible
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
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
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
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
ok
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
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?
4:55 PM
Mark M.
well, that doesn't sound like Filter and Filterable
is this for the same activity that is using your MergeAdapter?
and, if so, is RED one ArrayList<CustomObject> and GREEN another one?
tunneling
no
Mark M.
ah, OK, never mind then
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
So each one of them have a state that can be On or Off.
I want the user to be able to swipe left to filter the list to only the Units that are On
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
start at all
5:00 PM
Mark M.
ah
that feels like a ViewPager with three ListViews
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
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
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

Tuesday, February 14

 

Office Hours

People in this transcript

  • Mark Murphy
  • Nitin Sethi
  • Pavan
  • Raza Rahil Hussain
  • tunneling