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
|
Mark M. |
how can I help you today?
|
Refael O. |
ok i'll shoot :)
|
Refael O. |
View paste
|
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
|
Mark M. |
(BTW, hello, Ramsey -- I will be with you shortly!)
|
Ramsey e. |
Fab thanks
|
May 21 | 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"
|
Mark M. |
it's also newer, and has some features that LocationManager lacks
|
Mark M. |
the implementation can be more efficient
|
Mark M. |
as the Play Services one takes into account the accelerometer and such to try to minimize power consumption
|
Mark M. |
in terms of the getting location fixes periodically, both location APIs offer getting location updates delivered to you via a PendingIntent
|
Mark M. |
however, I have not tried those
|
Mark M. |
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
|
Mark M. |
an everlasting service should not be necessary; AlarmManager or JobScheduler (Android 5.0+) would be more efficient
|
Mark M. |
at least in terms of system RAM efficiency
|
Refael O. |
hmm one more thing,
|
May 21 | 7:35 PM |
Refael O. |
if I run a service and the phone goes sleep mode, does my service stops?
|
May 21 | 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
|
Mark M. |
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. | |
Mark M. |
(hello, Haoyu -- I will be with you in a bit, after Ramsey!)
|
Mark M. |
don't use a Timer
|
Mark M. |
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
|
Mark M. |
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. | |
Mark M. |
return 0.0f from maxPictureCleanupHeapUsage()
|
Mark M. |
and that will block the cleanup work, including the rotation based on the EXIF headers
|
Ramsey e. |
ah wow that's simple
|
Ramsey e. |
thanks
|
Refael O. |
View paste
|
Mark M. |
Refael: you are very welcome
|
Mark M. |
Haoyu: your turn! do you have a question?
|
Haoyu H. |
yes
|
Haoyu H. |
I have some buttons throughout my app, that I want to check if the current user is logged in first, before executing
|
May 21 | 7:40 PM |
Haoyu H. |
ex: they have to be logged in to favorite a product
|
Haoyu H. | |
Haoyu H. |
This is my current implementation
|
Haoyu H. |
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
|
Haoyu H. |
so, I launch the activity that handles the login
|
Haoyu H. |
but the onActivityResult can only be received from the fragment/ activity that has the View which contains my OnClickListener
|
Haoyu H. |
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
|
Mark M. |
it is a listener
|
Mark M. |
it is not a controller
|
Haoyu H. |
ok, then what is a better way to proceed?
|
Haoyu H. |
as in, I want some OnClickListeners on various buttons
|
Haoyu H. |
that require a user first login
|
Haoyu H. |
before actually doing the OnClick stuff
|
Mark M. |
IMHO, that right there is the source of your problem
|
May 21 | 7:45 PM |
Haoyu H. |
yep
|
Haoyu H. |
but I am not sure how to handle it in a clean way
|
Haoyu H. |
do you have any ideas?
|
Mark M. |
the problem is in the "before actually doing the OnClick stuff"
|
Mark M. |
saying that you want to start an authentication activity if needed, on those button clicks, is fine
|
Mark M. |
but, the user does not have to log in
|
Mark M. |
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
|
Mark M. |
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
|
Mark M. |
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
|
Haoyu H. |
but there are multiple pages to the login screen which was why i was hesitant to do so
|
May 21 | 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
|
Mark M. |
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)
|
Mark M. |
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
|
Mark M. |
let me take questions from the others, and I will be back with you in a bit
|
Mark M. |
Refael: do you have another question?
|
Haoyu H. |
ok
|
Mark M. |
OK...
|
Mark M. |
Ramsey: do you have another question?
|
Ramsey e. |
I do!
|
Ramsey e. |
I'm returning 0.0f in maxPictureHeapUsage
|
Ramsey e. |
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
|
May 21 | 7:55 PM |
Mark M. |
let's get a bit deeper into your symptoms
|
Ramsey e. |
sorry - the phone accessibilty setting
|
Ramsey e. |
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
|
Ramsey e. |
ie it flips it 90 degs clockwise
|
Ramsey e. |
from what the preview show
|
Ramsey e. |
s
|
Mark M. |
is this the front-facing camera or the rear-facing camera?
|
Ramsey e. |
The particular activity is portrait only
|
Ramsey e. |
rear
|
Ramsey e. |
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
|
Ramsey e. |
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)
|
Ramsey e. |
yes
|
Mark M. |
OK
|
Mark M. |
ImageView does not pay attention to EXIF headers
|
Mark M. |
you may want to use some tools that let you look at the EXIF headers and see if there is an orientation header
|
May 21 | 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
|
Mark M. |
however, it only does that if it thinks that it has enough RAM to do so, as rotating photos is very memory-intensive
|
Mark M. |
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
|
Mark M. |
to be honest, I have never played with my library with a portrait-only activity
|
Mark M. |
and so it's entirely possible that there are bugs related to that
|
Mark M. |
but you'll want to try to see what the orientation header is, if there is one
|
Ramsey e. |
Hm OK
|
Ramsey e. |
so I should be looking for the exif headers then
|
Mark M. |
yes
|
Mark M. |
let me take a question from Haoyu, and I will be back with you in a bit
|
Mark M. |
Haoyu: your turn! do you have another question?
|
Ramsey e. |
thanks mark
|
Haoyu H. |
yes
|
Haoyu H. |
actually no
|
Haoyu H. |
i will think more on it
|
Haoyu H. |
and prolly ask next week
|
Haoyu H. |
thanks
|
May 21 | 8:05 PM |
Mark M. |
OK
|
Mark M. |
Ramsey: back to you, then!
|
Ramsey e. |
I'm just investigating the exif headers first
|
Ramsey e. |
I think another issue might be related to it
|
Mark M. |
OK
|
Mark M. |
if either of you come up with a question, just chime in
|
May 21 | 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
|
Mark M. |
the SurfaceView is for previews
|
May 21 | 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
|
Mark M. |
the picture aspect ratio may not match the visible portion of the preview aspect ratio, for one
|
Ramsey e. |
Ah that's useful
|
Ramsey e. |
so is that why you have the method getPictureSize
|
Mark M. |
yes
|
Mark M. |
there is no requirement that the picture size and preview size have much relationship to one another
|
Mark M. |
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
|
Mark M. |
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
|
Mark M. |
I use the preview for centering the picture
|
Ramsey e. |
Or snapchat for example
|
Mark |