Office Hours — Today, February 23

Thursday, February 12

Feb 23
8:50 AM
Mark M.
has entered the room
Mark M.
turned on guest access
8:55 AM
EGHDK
has entered the room
Mark M.
hello, EGHDK
how can I help you today?
Tom
has entered the room
Mark M.
hello, Tom!
Tom
Hi Mark!
good morning
Mark M.
Tom: EGHDK got in first, so I'll take a question from him first, then I'll circle back to you
Tom
Ok
EGHDK
Hey Mark, quickish question I guess. I tried using your camera library. Works great for what I need, but I noticed a weird issue. Seems like on Samsung devices when I take a picture while on a phone call (with my headset) the camera shutter and my phone call, came through on the actual phone speaker, the shutter ended, and the call went back to my headset. Ideas?
Mark M.
beats me
I am not doing anything myself in the library with respect to audio
other than asking the camera to play the shutter sound
and AFAIK that doesn't include any information about where and how to play the shutter sound, or even what the shutter sound *is*
IIRC, I have hooks in there for you to handle shutter sounds yourself, in which case you can always try doing something independently
EGHDK
Gotcha. I tried on other devices, and no issue. Seems to be a samsung issue. That's possible... right?
Mark M.
oh, sure
9:00 AM
Mark M.
the camera behavior is very device-specific
:: insert string of profanities here ::
EGHDK
Okay, so last question regarding this... then I'm out. How would I change the sound. I have my own camerahost extending simplecamerahost.
Mark M.
see the link that I pasted into the chat a moment ago
EGHDK
But do I simply ovverride getShutterCallback()?
Mark M.
yes
and return your own Camera.ShutterCallback
and in there, do whatever you want
EGHDK
what is my own though? Camera.ShutterCallback is abstract...?
Mark M.
it's either an interface or an abstract class
EGHDK
Sorry I was just confused when I tried return new Camera.ShutterCallback
Mark M.
it's an interface
create your own class implementing the interface
EGHDK
Okay, so is there any class that implements it already, that might be a member of SimpleCameraHost that I can just return?
Mark M.
and in there, you will have an onShutter() method that is called, where you can do something (e.g., play back a Michael Bay 'splosion sound)
EGHDK
Okay, so I'll create my own class. Gotcha! Thanks.
Mark M.
Tom: your turn! do you have a question?
EGHDK
I've never worked with a method that returned an interface before (at least knowinlgy) thanks. That makes sense. See ya later mark.
Tom
I do! It's concerning a small app I made to help get my head around the SQLite database chapter in the Omnibus
9:05 AM
Tom
What it does is read the rows from the Browser history and Browser.BOOKMARKS_URI, and that works fine, but I have an issue when I try to write to it
Mark M.
um, that would be using a ContentProvider, not SQLite directly
which is fine, of course
Tom
I store a bunch of presets in a DatabaseHelper, and then copy them to the browser history
Venkat
has entered the room
Mark M.
ah, ok
(BTW, hello, Venkat -- I will be with you shortly!)
Venkat
Hi Mark :-)
Tom
The problem is that, even though it shows in my app that everything has copied correctly..when I load up the browser, the history is untouched. Strangely though, the entries I've copied DO show up in the search bar if I being to type them in. I wondered whther you had some ideas on why this might be?
Johnny
has entered the room
Mark M.
(BTW, hello, Johnny -- I will be with you after Venkat!)
Tom: it's possible that the browser is caching the bookmarks
Johnny
Hi Mark, thank you
Mark M.
try swiping the browser off of the recent tasks list, then restart it
Tom
I gave that a try - the ones I wrote in there never appear. Another thing though is that if I write them as bookmarks, rather than history entries, then they do appear as bookmarks in the browser.
Mark M.
:: shrug ::
that behavior is up to whoever wrote that browser
9:10 AM
Mark M.
if this is the classic AOSP Browser app, you're welcome to poke through its source code and see what it does
let me take questions from the others, and I will be back with you in a bit
Venkat: your turn! do you have a question?
Tom
Ok
Venkat
View paste
I have a question about using NDK with Android Studio / Gradle.
In my local.properties file, I have something like:
ndk.dir=/path/to/ndk

and in build.gradle, I have a task for NDK, something like:
commandLine 'ndk-build', '-C', file('src/main').absolutePath
and I get a compile error - ndk-build not found
If I change it to:
View paste
in build.gradle to include the complete path for ndk-build, like 
commandLine '/path/to/ndk/ndk-build', '-C', file('src/main').absolutePath
it comiples correctly
Mark M.
that makes sense
ndk.dir is not going to be used by Gradle's commandLine directive
Gradle has no idea about a local.properties file, let alone an ndk.dir property in there
Venkat
ok, then that explains things
Mark M.
that is for ndk-build itself, and for the nascent ndk closure in the Gradle for Android plugin
Venkat
Thats all from me today.
Mark M.
if you put /path/to/ndk in your $PATH, you could avoid the duplication
or, you could read in local.properties yourself in the Gradle script, grab ndk.dir, and use it to build up the first parameter to commandLine
Venkat
in one of the gradle files?
Mark M.
well, by $PATH, I meant the PATH environment variable in your development OS
Venkat
ok
Will also research a bit about grabbing from local.properties
Mark M.
in my book, I have an example of reading a custom properties file and using that to automatically set the versionCode
9:15 AM
Mark M.
reading in local.properties would work much the same, except that you would not be modifying the file
Johnny: your turn! do you have a question?
Johnny
Yep, I was wondering what's the best way to check if an alarm/timer should go off without wasting a lot of CPU cycles
Mark M.
what do you mean by "check if an alarm/timer should go off"?
Johnny
So I compare the current time in milliseconds to a stored one
and I want to check if the current time is greater than the stored one
Mark M.
is the alarm/timer only relevant while your app is in the foreground? or should it go off even if your app is in the background (or gone)?
Johnny
Actually, I was wondering what's the difference since in one area of my app I would need it constantly running in the background, and another when the user is in the activity and there's a textview that counts down the timer
So both
Mark M.
why do you think that you "need it constantly running in the background"?
9:20 AM
EGHDK
has left the room
Mark M.
in the background, doesn't it only matter if you get control at the proper time?
Johnny
Oh it's a reminder app, so I'm assuming I'm going to have to wake the CPU pretty often, unless there's a way to set specific times..
yeah you're right
Mark M.
for the background stuff, use AlarmManager
teach it the nearest event
when it gives you control, issue the reminder, plus tell AlarmManager to give you control for the next event
there is a chapter on AlarmManager in the book to show the basics
while you have an activity in the foreground that wants to show some sort of time-remaining counter, use a postDelayed() "loop"
call postDelayed() on a Runnable
that Runnable updates the counter, then schedules itself to run again via postDelayed()
Johnny
Ah right. Just to also confirm, I shouldn't use JobScheduler pre-lollipop right
Mark M.
correct, if for no other reason than it is inexact, and reminders usually need to be exact
I have an example of a postDelayed() loop in the book as well
9:25 AM
Johnny
For postDelayed() do I set the delay amount?
9:25 AM
Johnny
ah ok I'll check that out
Mark M.
yes, that's the second parameter to postDelayed()
so, postDelayed(yourRunnable, 1000) runs the Runnable around 1000 milliseconds from now
it's not millisecond-level precise, though -- you use it for approximate timing and giving you control on the main application thread to update your UI
the actual UI update would be based off of a better calculation (e.g., how much time is remaining on the countdown?)
let me take questions from the others, and I will be back with you in a bit
Tom: your turn! do you have another question?
Tom
Hey Mark, no, just more of the same
Johnny
Thank you Mark, that's all from me
Johnny
has left the room
Mark M.
Tom: "just more of the same"?
Tom
I'm trying to figure out where to put my attention next to figure out why the browser history isn't updating in the default Browser
Mark M.
well, again, that depends upon what "the default Browser" is
there is the AOSP Browser, there is Chrome, there is Samsung's "Internet" browser, etc.
Tom
Yea - I'm testing on a Nexus 7 with Chrome
Mark M.
well, Chrome is closed source
and there is no requirement that Chrome use that ContentProvider for anything, let alone everything
Tom
I see
9:30 AM
Tom
Quick question in that case in the Browser class there is a method called "updateVisitedHistory()", which produces same results to my app
do you happen to know whether this is more targeted towards people who are developing their own app? As it's unlikely to work with any Android browser based on my tests
own browser**
Mark M.
I cannot say what Google had in mind
I can say that system-supplied ContentProviders are an *available* facility, but usually not a *mandatory* facility
Tom
I understand
Mark M.
or, to put it another way, if I were writing a Web browser, there's no way in $DEITY's green Earth that I would be using this provider
Tom
Ha! That doesn't sound encouraging
Mark M.
as I don't think that anything exposed by this provider ought to be exposed to arbitrary third party apps
and some browser makers probably have the same attitude
Tom
I'm surprised in a way though, because there are quite a few popular "history cleaner" apps available in the play store, that profess to be able to wipe a browser's history - I would have assumed that if the history can be wiped, it can also be added to
Mark M.
that presumes that the "history cleaner" apps do what they claim to
there's no question that they can wipe out what is in this provider
9:35 AM
Mark M.
that will not affect all browsers for all data, though, as some browsers will have their history data stored elsewhere
to put it another way, if I wrote a browser app, and a "history cleaner" app could clean my app's browser history, that's a security flaw in my app that I need to fix
unless I specifically put the history into this provider
and in that case, I should be slapped with a trout
Tom
Haha
Mark M.
fortunately, I have not written a browser, and so no actual trout were harmed
let me take a question from Venkat, and I can come back to you in a bit
Tom
Glad to hear it - well, that certainly makes sense, although it's a bit disappointing
Mark M.
Venkat: your turn! do you have another question?
Tom
Of course
Venkat
Do I have to create a task for NDK build? I have an Android.mk in the jni folder and I was expecting the build system to pick that up automatically and run ndk-build
but it does not
Mark M.
Gradle for Android definitely does not integrate with ndk-build
Gradle for Android has an ndk closure that replaces ndk-build
but it also replaces the makefiles
and is not especially sophisticated
and therefore is slated for significant change
Venkat
I have the ndk closure in my build.gradle
so can I still need to create a task?
Mark M.
no, you do not need a task then
however, Gradle for Android will not be using ndk-build
it will do its own NDK build process
9:40 AM
Venkat
hmm ... and it is not compatible with Android.mk?
Mark M.
it ignores Android.mk
Venkat
ok, got it
Mark M.
at least, AFAIK
Venkat
that is what I am seeing
Mark M.
it's all kinda hazy, and it's on the tools team's plate to make it better
Venkat
I found the chapter you were referring for custom properties file, will look into it
thanks, Mark
Mark M.
you are very welcome
Tom: back to you -- do you have another question?
Venkat
has left the room
Tom
No, thank you Mark
9:50 AM
Guy W.
has entered the room
Guy W.
Hello
Mark M.
hello, Guy!
Guy: Tom is out of questions, so it's your turn -- do you have a question?
Guy W.
OK
I making a screenshot of a webview and saving it
I'll post the code
9:55 AM
Guy W.
I want to add an overlay to the image
where should i code it before the asynctask or in the doInBackground method?
Mark M.
Guy: the chat is nearly over -- can you please ask your question?
you could do it in either place
Guy W.
thanks
Mark M.
there's nothing directly affecting the UI, and so doing it in doInBackground() should be safe
and it saves doing that work on the main application thread
Guy W.
graet. :)
thank you
have a ncie day
nice
10:00 AM
Mark M.
that's a wrap for today's chat
the transcript will be posted to http://commonsware.com/office-hours/ shortly
Guy W.
cool
Mark M.
the next chat is tomorrow at 4pm US Eastern
have a pleasant day!
Guy W.
:-)
Tom
has left the room
Guy W.
has left the room
Mark M.
turned off guest access

Thursday, February 12

 

Office Hours

People in this transcript

  • EGHDK
  • Guy West
  • Johnny
  • Mark Murphy
  • Tom
  • Venkat