Mark M. | has entered the room |
Mark M. | turned on guest access |
Feb 7 | 4:00 PM |
Aron | has entered the room |
Mark M. |
howdy, Aro
|
Mark M. |
er, Aron
|
Ben K. | has entered the room |
Aron |
Hello!
|
Ben K. |
Hello
|
Mark M. |
howdy, Ben
|
Aron |
Is it just to write out the question here or is there some sort of turn system?
|
Mark M. |
Aron: do you have a question
|
Aron |
Sure do! 1 sec
|
Aron |
I got a question regarding the calendar on
Android. As of version 4.0 there is a calender provider API that allows
one to perform query, insert and update on calendars/events/etc.
|
Aron |
I am planning to use this API for a "room booking app", which will be used on a tablet outside of meetingrooms.
|
Aron |
One of the things this app needs to do is to see
if the room is currently booked or not. As people can book the room over
the web (Google Apps) I need to continuously check if the room is
available or not and update the status accordingly.
|
Aron |
The implementation I have think about implementing
is to have a service running that checks against the calendar every 5
seconds (and the calender uses push-notifications automatically by
Android if I'm not mistaken).
|
Aron |
My question to you is simply, is there any way to
see when there has been an update to an event/calendar without having to
check every few seconds. For example is there some sort of "broadcast
message" sent out by the calendar everytime it syncs(gets info pushed to
it)?
|
Aron |
Appreciate any thought on this. :) Thanks for a great service.
|
Mark M. |
register a ContentObserver
|
Feb 7 | 4:05 PM |
Aron |
Could you elaborate a little bit, I'm still kind
of a newbie on Android. I can use contentobserver to see when the
calendar has been updated?
|
Mark M. |
yes
|
Mark M. |
(sorry, I'm on an emergency phone call right now)
|
Aron |
No problems, you can write here when you got the time! (i will read the API for contentobserver meanwhile)
|
Mark M. |
OK, call over for now
|
Mark M. |
you can register a ContentObserver to be notified when there is a change to some piece of content, represented by a Uir
|
Mark M. |
er, Uri
|
Aron |
okay. So I can be told for example if a database has been updated
|
Mark M. |
right
|
Aron |
which URI should I use for the calendar?
|
Mark M. |
um, I don't know
|
Mark M. |
the one you are querying on, presumably
|
Mark M. |
or, the one for an individual event, if you want it scoped to a single event
|
Mark M. |
the catch with a ContentObserver is that you have to be running
|
Mark M. |
it's not like AlarmManager, which works even when your app is not running
|
Aron |
Ah
|
Mark M. |
personally, I would not "continuously check", but rather check only while the app is running
|
Feb 7 | 4:10 PM |
Mark M. |
unless you are trying to implement some sort of alert mechanism
|
Mark M. |
in which case, polling is pretty much your only option that I can see
|
Aron |
View paste
|
Mark M. |
that would tell you about changes to which calendars are subscribed
|
Mark M. |
it might tell you about changes within those calendars, but I cannot be sure
|
Mark M. |
you may need the Uri for a specific calendar, the one containing the room bookings that you are monitoring
|
Aron |
does it tell me what changes or just that "there are changes"?
|
Mark M. |
just that the data was changed
|
Mark M. |
you would query the ContentProvider to get the
updated information, then determine if the change is something that
matters to you
|
Aron |
Ah!
|
Aron |
That's perfect then, will probably work much better than polling all the time
|
Mark M. |
let me take a question from Ben, and I'll be back with you shortly
|
Mark M. |
Ben: do you have a question?
|
Ben K. |
Yes, I am using an AlarmManager with you WakefulIntentService
|
Ben K. |
Can I have multiple subclasses and alarms?
|
Mark M. |
you should not need multiple subclasses
|
Mark M. |
you can certainly have multiple alarms
|
Ben K. |
So in order to tell which alarm is triggering I can add extras to the intent?
|
Mark M. |
that's a likely solution
|
Feb 7 | 4:15 PM |
Ben K. |
Ok
|
Mark M. |
make sure you use unique request codes when you create your PendingIntents
|
Mark M. |
(second parameter on getBroadcast(), etc.)
|
Ben K. |
Ok
|
Mark M. |
you'd use one PendingIntent per distinct alarm, routed to your BroadcastReceiver
|
Ben K. |
right
|
Mark M. |
the receiver would turn around and use the same Intent for sendWakefulWork(), to pass along the extras
|
Mark M. |
Aron: do you have another question?
|
Aron |
I think I'm good for now. Still unsure about how the classes work but that is my own job to learn. :) Thanks for the help!
|
Mark M. |
OK
|
Mark M. |
Ben: do you have another question?
|
EGHDK | has entered the room |
Mark M. |
howdy, EGHDK!
|
Feb 7 | 4:20 PM |
Mark M. |
EGHDK: do you have a question?
|
Feb 7 | 4:20 PM |
Ben K. |
I don't have another question right now, I'm just going to hang out
|
Mark M. |
Ben: OK, no problem
|
EGHDK |
Hey Mark, I'm trying to get an imageView to move
from it's location (bottom of the screen) towards the top on the screen,
while holding down on a button. So when the button is being pressed
down, it moves up and will stop at the top, but if you let go, it slowly
moves back down to it's original position. I'm just kinda stuck on how
to go about this. I've successfully gotten a button press that moves an
image view up, but I don't know how to move the posiition up while the
button is being pressed. As of right now, it just goes up one it's
clicked. Sorry if it's a bit confusing.
|
Mark M. |
I guess I
|
Mark M. |
er
|
Mark M. |
I guess I'm not sure what your specific question is
|
EGHDK |
Well now it goes onClick move up this much.
|
Mark M. |
you'd need to manage low-level touch events on the button for this, as there is no concept of "button being pressed" in Android
|
Mark M. |
onClick() will not help you for your problem
|
Mark M. |
in fact, a Button may not be the right solution
|
EGHDK |
onLongClick?
|
EGHDK |
lol
|
EGHDK |
How about an imageview that "behaves" like a button? And reacts to "onTouch"?
|
Mark M. |
probably you will need to create your own custom
subclass of something, where you handle the onTouchEvent() call, as you
may need to manage the background states yourself
|
EGHDK |
onTouch move x amount up.
|
Feb 7 | 4:25 PM |
Mark M. |
something like that, yes
|
EGHDK |
Okay, so that sounds reasonable. How do I handle "notOnTouch" move x amount down?
|
Mark M. |
use an animation, presumably
|
EGHDK |
Well, I've been using animation to move the imageView up right now.
|
Mark M. |
right
|
Mark M. |
you'd run a separate animation to move it down
|
Mark M. |
where "down" would be "all the way", presumably
|
EGHDK |
How would the separate down animation be started?
|
EGHDK |
It should ideally be started when you remove your finger from the "button"
|
Mark M. |
hence, when onTouchEvent() indicates that the user has lifted their finger, start the down animation
|
Mark M. |
bear in mind that I haven't done anything much
like what you're describing, so I am taking educated guesses -- more or
less what I'd start trying if I had to do it
|
EGHDK |
Yes, but your educated guess is worth a lot more to me than my educated guess. heh
|
Feb 7 | 4:30 PM |
EGHDK |
Okay, so stupid question. Is there any tutorial on reading documentation?
|
EGHDK |
I'm still pretty new to java (IMO) so when I go to read android docs, I get confused more than anything else.
|
Mark M. |
um
|
Mark M. |
well
|
Mark M. |
not really
|
Mark M. |
I mean, the "right" answer is for you to get more comfortable with Java, JavaDocs, etc., whether inside or outside of Android
|
Mark M. |
but we still haven't invented the microSD->brain interface
|
Mark M. |
so you can't just put the Java card behind your right ear and absorb it
|
Mark M. |
nor do we have Matrix-style "I know kung fu" technology
|
Mark M. |
:-)
|
EGHDK |
Not yet.
|
EGHDK |
So let me use this example. Because it's had me stuck for the longest.
|
EGHDK |
Let's say I wanted to perform a toast message.
|
EGHDK |
I go to d.android.com
|
EGHDK |
I type in toast, and see android.widget.toast. I click on that. And I go down to...
|
EGHDK |
Public Methods
|
Feb 7 | 4:35 PM |
EGHDK |
and I see "Make a standard toast that just contains a text view."
|
EGHDK |
So I figure, this is what I want to use. But then I start to create the toast. Toast.makeText(this, "myToast", LENGTH_LONG);
|
EGHDK |
But length long doesn't work.
|
Mark M. |
that is a static data member on the Toast class
|
EGHDK |
It has to be Toast.LENGTH_LONG. But I don't see that anywhere.
|
Mark M. |
LENGTH_LONG is defined on that very page
|
Mark M. | |
Mark M. |
(or, use Ctrl+F to search within the page in your Web browser)
|
EGHDK |
Exactly! It says "Show the view or text notification for a long period of time."
|
Mark M. |
public static final int LENGTH_LONG
|
EGHDK |
I guess to all comes down to me still not fully understanding "static"
|
Mark M. |
and that's a fairly fundamental Java construct
|
Mark M. |
with corollaries in most major OO programming languages
|
Mark M. | |
Mark M. |
that blog post lists a number of Java topics that Android developers need to know
|
Mark M. |
fifth bullet down is "Static and instance scope", pointing here: http://en.wikibooks.org/wiki/Java_Programming/U...
|
Feb 7 | 4:40 PM |
Ben K. |
I've got another question
|
Mark M. |
Ben: go ahead
|
Ben K. |
I have this code:
|
Ben K. |
View paste
|
Ben K. |
do I add the extras to the Intent i?
|
Mark M. |
um
|
Mark M. |
is SkootCommandService supposed to be the WakefulIntentService?
|
Ben K. |
yes
|
Mark M. |
then you're using WakefulIntentService wrong
|
Ben K. |
Ok
|
Mark M. |
for WakefulIntentService, you need to use a
*broadcast* PendingIntent, routing to a BroadcastReceiver that can turn
around and call sendWakefulWork() on WakefulIntentService
|
Mark M. |
this is covered in the book in the chapter on AlarmManager
|
Mark M. |
it is also covered in the README to the cwac-wakeful GitHub repo
|
Feb 7 | 4:45 PM |
Mark M. |
EGHDK: back to you, if you have another question or a follow-up on your earlier one
|
Feb 7 | 4:50 PM |
Mark M. |
if anyone has any questions, chime in
|
Ben K. |
I've changed the getService to getBroadcast and mirrored your example from the book
|
Ben K. |
Where do I add the extras?
|
Mark M. |
you have two choices
|
Mark M. |
1. add them in the BroadcastReceiver
|
Mark M. |
2. add them to the Intent used in the
getBroadcast() PendingIntent, in which case you need your
BroadcastReceiver to pass those same extras along to the service
|
Ben K. |
so the intent won't automatically keep the extras
|
Ben K. |
?
|
Ben K. |
I just need to pass in the same intent right
|
Mark M. |
one flavor of sendWakefulWork() takes an Intent
|
Mark M. |
that Intent needs to have the extras
|
Mark M. |
how the extras get there is up to you
|
Ben K. |
I see
|
Mark M. |
for example, in my option #2, you could use the copy constructor to create an Intent for use with sendWakefulWork()
|
Ben K. |
If I place the extras in the intent used in
getBroadcast(), that intent will return in onReceive, and I can just
pass in that intent to sendWakefulWork?
|
Mark M. |
or possibly just use the original Intent passed to onReceive(), without copying it
|
Mark M. |
the Intent for sendWakefulWork() needs to identify the service
|
Mark M. |
your Intent received in onReceive() identifies the BroadcastReceiver
|
Mark M. |
so, you'd need to call setComponent() to change it
|
Ben K. |
Ok
|
Feb 7 | 4:55 PM |
Ben K. |
Is there anything else I need to do?
|
Mark M. |
that is difficult for me to answer
|
Ben K. |
Ok
|
Mark M. |
at the end of the day, the Intent passed to
sendWakefulWork() must identify the service that is your
WakefulIntentService and contain whatever extras you want
|
Mark M. |
how you get to that point is up to you
|
Ben K. |
k thanks for your time1
|
Mark M. |
any last questions?
|
EGHDK |
Thanks for the resources. I will have some work
cut out for me this weekend. Can't believe I never stumbled upon your
blog posts. Thanks. I'm outta here. Have a good night. I don't think the
storm is supposed to hit you too hard right Mark? I'm in NJ, way too
many emergency alert text messages. hahaha
|
Mark M. |
6-8 inches here, I think
|
Mark M. |
no, 6-12
|
EGHDK |
Stay warm. See ya at the next office hours
|
Mark M. |
which are tomorrow at 10am Eastern
|
Feb 7 | 5:00 PM |
Mark M. |
the transcript of this chat will be archived at http://commonsware.com/office-hours/ shortly
|
Mark M. |
this concludes today's chat -- have a pleasant day, all!
|
Aron | has left the room |
Ben K. | has left the room |
EGHDK | has left the room |
Mark M. | turned off guest access |