Office Hours — Today, May 21

Tuesday, May 19

May 21
7:25 PM
Mark M.
has entered the room
Mark M.
turned on guest access
Refael O.
has entered the room
Refael O.
Hey there Mark :D
Mark M.
hello, Refael
how can I help you today?
Refael O.
ok i'll shoot :)
View paste
well, I'm working on a cenrtain project right now, and I need to check my user phones location approx every 10-15 minutes, and sent the current geo points to my server.
so basically, I wanted to get your opinion on how to approach this, which way would be best to achieve that goal, also considering battery consumption, I've never took a real dive into location services, i'd really appreciate it if you could point me to the right directions :)
Ramsey e.
has entered the room
Mark M.
well, you have two choices: Android's LocationManager, and the fused location API from the Play Services SDK
(BTW, hello, Ramsey -- I will be with you shortly!)
Ramsey e.
Fab thanks
7:30 PM
Mark M.
Refael: of the two, the Play Services API is nicer, but it makes you dependent upon Play Services and so makes it difficult for you to ship your app anywhere other than the Play Store
Ramsey e.
1. You are a legend. Thank you for your magnificent book & all your work on Android - has been so significant.
Refael O.
by nicer, you mean "better" in performance/efficient or you mean easier to work with?
Mark M.
um, more as "a bit more flexible"
it's also newer, and has some features that LocationManager lacks
the implementation can be more efficient
as the Play Services one takes into account the accelerometer and such to try to minimize power consumption
in terms of the getting location fixes periodically, both location APIs offer getting location updates delivered to you via a PendingIntent
however, I have not tried those
I have not done something akin to what you are describing in a few years
Refael O.
hmmm, so assume I'm using the play services API, how should I reach my desired goal? run an infinite service that takes a location check every 10 minutes?
Mark M.
at that time, I used a Service and AlarmManager
an everlasting service should not be necessary; AlarmManager or JobScheduler (Android 5.0+) would be more efficient
at least in terms of system RAM efficiency
Refael O.
hmm one more thing,
7:35 PM
Refael O.
if I run a service and the phone goes sleep mode, does my service stops?
7:35 PM
Mark M.
well, the CPU "stops"
Refael O.
by sleep mode i mean that the user not touching his phone for few minutes
Mark M.
which means your process and its threads freeze in place until the CPU is moved out of sleep mode again
this means during the window while you are trying to get a GPS fix, you will probably need a WakeLock
Haoyu H.
has entered the room
Haoyu H.
Hi
Mark M.
but you do *not* want to keep a WakeLock on all the time, as your users will attack you with torches and pitchforks for draining their battery
Refael O.
View paste
but will my service know its time to Wakeup?
my timer still runs while in sleep mode?
Mark M.
(hello, Haoyu -- I will be with you in a bit, after Ramsey!)
don't use a Timer
use AlarmManager and an ELAPSED_REALTIME_WAKEUP alarm
Refael O.
okie got it !
Mark M.
let me take questions from the others, and I will be back with you in a bit
Ramsey: your turn! thanks for the kind words earlier in the chat! do you have a question?
Ramsey e.
Thanks Mark. I know you said you are going to rewrite cwac-camera at some point. However, I'm just trying to figure some things out for something I'm working on now. So: I'm currently extending SimpleCameraHost and overriding saveImage(PictureTransaction, Bitmap). Works nicely when the phone is in portrait. However when I take the picture with the phone on its side the bitmap rotates (presumably to compensate?) How can I stop it from rotating? Is it a case of extending CameraView?
Mark M.
return 0.0f from maxPictureCleanupHeapUsage()
and that will block the cleanup work, including the rotation based on the EXIF headers
Ramsey e.
ah wow that's simple
thanks
Refael O.
View paste
thanks Mark i think that gave me enough ideas to play with for a day or two, if I won't manage with that i'll come back next week for a few more question after I played with it a little :)
as always, you're awesome. thanks!
Mark M.
Refael: you are very welcome
Haoyu: your turn! do you have a question?
Haoyu H.
yes
I have some buttons throughout my app, that I want to check if the current user is logged in first, before executing
7:40 PM
Haoyu H.
ex: they have to be logged in to favorite a product
This is my current implementation
but what is the best way to capture the finished activity and then proceed with the onClick functionality?
Mark M.
I do not know what you mean by "capture the finished activity" or "proceed with the onClick functionality"
Haoyu H.
since I am starting the Authentication activity from somewhere that is not an activity / fragment
so, I launch the activity that handles the login
but the onActivityResult can only be received from the fragment/ activity that has the View which contains my OnClickListener
so how does my OnClickListener above know when the login is complete?
Mark M.
IMHO, it should neither know nor care when the login is complete
it is a listener
it is not a controller
Haoyu H.
ok, then what is a better way to proceed?
as in, I want some OnClickListeners on various buttons
that require a user first login
before actually doing the OnClick stuff
Mark M.
IMHO, that right there is the source of your problem
7:45 PM
Haoyu H.
yep
but I am not sure how to handle it in a clean way
do you have any ideas?
Mark M.
the problem is in the "before actually doing the OnClick stuff"
saying that you want to start an authentication activity if needed, on those button clicks, is fine
but, the user does not have to log in
and, they are now in another activity
Haoyu H.
yes, so there needs to be a way to know the user did not finish the auth activity
Mark M.
so, *if* they log in, *then* they need to go back and click the button again
an answer of "well, we're going to do what the user clicked anyway, even though the user didn't log in for 20 minutes and now forgets why she logged in" is not a good answer
so, I would start by considering using something lighter weight than an activity for the login, like a fragment or something, that you can do *right in the original activity*
Haoyu H.
ya, that was my consideration as well
but there are multiple pages to the login screen which was why i was hesitant to do so
7:50 PM
Mark M.
then don't attempt to follow through on what the button click was for, and have them click the button again once authenticated
you might use a badge or something on the button as an indicator that they will need to log in when clicking it (e.g., a lock or something)
so they know what to expect
Haoyu H.
ok
Mark M.
but if you are going to steer the user far away from the original activity, don't try doing something in that original activity once the user isn't there anymore and hasn't been there for this lengthy login process
let me take questions from the others, and I will be back with you in a bit
Refael: do you have another question?
Haoyu H.
ok
Mark M.
OK...
Ramsey: do you have another question?
Ramsey e.
I do!
I'm returning 0.0f in maxPictureHeapUsage
But the bitmap still seems to be rotating
Mark M.
that's surprising
Ramsey e.
Is it useful to know that auto-rotate is off?
Mark M.
I don't know what you mean by "auto-rotate" in this context
7:55 PM
Mark M.
let's get a bit deeper into your symptoms
Ramsey e.
sorry - the phone accessibilty setting
but actually that setting doesn't seem to affect it
Mark M.
when you take a picture in portrait mode, what orientation is the photo coming out as?
Ramsey e.
portrait
Mark M.
when you take a picture in landscape mode, what orientation is the photo coming out as?
Ramsey e.
if i rotate the phone 90 degs anti clockwise it comes out portrait
ie it flips it 90 degs clockwise
from what the preview show
s
Mark M.
is this the front-facing camera or the rear-facing camera?
Ramsey e.
The particular activity is portrait only
rear
although it's the same with front
Mark M.
and how are you determining the orientation of the photo? are you opening it in an image editor or something?
Ramsey e.
ah
I display the photo ontop of the preview
Mark M.
meaning that you are using an ImageView?
Ramsey e.
(I'm actually applying a mask to the photo so you can see behind)
yes
Mark M.
OK
ImageView does not pay attention to EXIF headers
you may want to use some tools that let you look at the EXIF headers and see if there is an orientation header
8:00 PM
Refael O.
has left the room
Mark M.
what my image cleanup work does is see if there is such a header, and if so, rotate the image and save it without the header, for things like ImageView that do not pay attention to EXIF headers
however, it only does that if it thinks that it has enough RAM to do so, as rotating photos is very memory-intensive
if you are now return 0.0f for the fraction of heap space to use, that means that I am not adjusting the image
Ramsey e.
I'm wondering if it's my perception of what portrait should be
Mark M.
so it is whatever the camera hardware gives me
to be honest, I have never played with my library with a portrait-only activity
and so it's entirely possible that there are bugs related to that
but you'll want to try to see what the orientation header is, if there is one
Ramsey e.
Hm OK
so I should be looking for the exif headers then
Mark M.
yes
let me take a question from Haoyu, and I will be back with you in a bit
Haoyu: your turn! do you have another question?
Ramsey e.
thanks mark
Haoyu H.
yes
actually no
i will think more on it
and prolly ask next week
thanks
8:05 PM
Mark M.
OK
Ramsey: back to you, then!
Ramsey e.
I'm just investigating the exif headers first
I think another issue might be related to it
Mark M.
OK
if either of you come up with a question, just chime in
8:15 PM
Ramsey e.
so it turns out the exif headers don't contain any info about the orientation
Mark M.
OK
Ramsey e.
When a photo is captured is the bitmap just what appears on the SurfaceView?
Mark M.
the SurfaceView has nothing to do with photo capture
the SurfaceView is for previews
8:20 PM
Ramsey e.
right but does it display what will be captured in the photo?
Haoyu H.
has left the room
Mark M.
not really
the picture aspect ratio may not match the visible portion of the preview aspect ratio, for one
Ramsey e.
Ah that's useful
so is that why you have the method getPictureSize
Mark M.
yes
there is no requirement that the picture size and preview size have much relationship to one another
and that's as much the camera hardware as anything else
Ramsey e.
so in theory I could take the size of the visible position of the preview and set that to be the picture size
Mark M.
unlikely
the size of your preview window is unlikely to match any available picture size
Ramsey e.
OK so with the main android camera app when you snap a picture it seems to match what was on the preview right?
Mark M.
I haven't paid close attention
I use the preview for centering the picture
Ramsey e.
Or snapchat for example
Mark