Office Hours — Today, November 14

Monday, November 10

Nov 14
8:50 AM
Mark M.
has entered the room
8:55 AM
Mark M.
turned on guest access
9:00 AM
Craig D.
has entered the room
Mark M.
hello, Craig!
how can I help you today?
Craig D.
Hi. My Commonsware subscription ends in early December. How can I renew it?
Mark M.
and use one of the "Subscribe!" options
those work for renewals as well as for new accounts
Craig D.
Good. Thanks!
I also have a question about setting up SSL and OAuth to work with an Android client that communicates with a REST web service. Do you know any good examples of that?
9:05 AM
Mark M.
not the OAuth part
I'm sure there are examples
but I haven't used it personally
and so I do not know of any resources off the top of my head
Craig D.
Does your book cover SSL?
Mark M.
yes
there's a dedicated chapter on it
Craig D.
Good. I'll take a look. Are there other Auth schemes that you cover?
Mark M.
no, I do not get into authentication
BTW, the SSL chapter starts on page 1943 of Version 6.1's PDF
Craig D.
I just found it. I haven't gotten that far in the book. Sorry.
Mark M.
no worries
I used to have it as part of the Internet chapter
Craig D.
It's a great resource, though.
Mark M.
but that chapter was getting mighty big
glad you like it!
9:10 AM
Mark M.
if you have other questions, go right ahead -- it's a quiet chat room :-)
Craig D.
Not right now outside of the OAuth one. I haven't found a good example online. Please consider adding it to a future edition.
Mark M.
OK, though it's not going to be there any time soon
Craig D.
OK. I
9:15 AM
Craig D.
I'm very glad you modernized the parts of the book that used Action Bar Sherlock.
Mark M.
ActionBarSherlock was the right move at the time
but, yes, the examples needed to move on
Craig D.
Here's another question: What is the advantage of using a ListActivity over using a ListView in a regular activity (or Fragment)?
Mark M.
minor code simplification (setListAdapter(), onListItemClick())
and you can skip the activity layout, if it would just be a ListView
beyond that, not much
Craig D.
Thanks. I am 'at work' on my other computer, so my attention will be diverted at times.
9:20 AM
Mark M.
no worries -- chime in if you have a question
9:55 AM
Craig D.
has left the room
10:00 AM
Mark M.
turned off guest access
10:10 AM
Mark M.
has left the room
3:50 PM
Mark M.
has entered the room
Mark M.
turned on guest access
4:00 PM
EGHDK
has entered the room
Mark M.
hello, EGHDK!
how can I help you today?
EGHDK
Hey Mark, so I have a particular case I'd like your advice on. I have an app on the play store, and I was working recently with a school to get this app on their tablets. I recommended them using some kind of more robust process then this, but since its a small number of devices (5 to be exact) they want to just manually load the apk onto each.
Again, this is fine and won't take much work, but the thing that we have settup is that they want a special token to know that when the devices check in online that they are one of the 5 devices.
But they also want the apk to get the updates pushed from google play.
So this is my solution and let me know if it sounds reasonable.
4:05 PM
Ryan M.
has entered the room
EGHDK
I want to put a txt file in the raw directory.
that contains the token.
Mark M.
(hello, Ryan -- I will be with you shortly!)
EGHDK
Then when making a network request I just check to see if that file exists.
The only issue is if I update through google play, won't I override that file?
Mark M.
correct
EGHDK
Gah.
Mark M.
mostly because it is not a file
it is an entry in the ZIP archive that is the APK
EGHDK
So is there anyway to put something in this apk that I'll be able to use as a token or something? That will persistantly stay there?
Mark M.
strictly speaking, no
there's nothing stopping you from copying the value out of the raw resource to a file on internal storage, though
that will survive an upgrade (though whether the upgrade will work from the Play Store, I can't say)
it won't survive an uninstall-and-reinstall cycle
EGHDK
It doesn't have to survive uninstall.
Just an upgrade.
But I would have to copy the value on first opening of the application right?
Mark M.
that'd be a likely time
technically, it just has to be before the first upgrade
let me take a question from Ryan, and I'll be back with you shortly
Ryan: your turn! do you have a question?
4:10 PM
EGHDK
Is there a broadcast that I can use when my app has been installed?
No problem.
Mark M.
(EGHDK: not that you receive, but you'd just look to see if your file exists, and if not, see if the raw resource exists and copy it)
EGHDK
I have a lot of little questions regarding this so I'm fine to wait. Hahaha.
Ryan M.
Hey loving the book so far. I am stuck on Tutorial 13, Prefs. Saving chapter position isn't working for me.
Mark M.
what specifically is not working?
Ryan M.
If I scroll to a different chapter after checking the preference, back out of the app then open it again it goes back to the first page.
mfrag.getPrefs() always returns null
Mark M.
just so that I can give you appropriate links, are you using the Android Studio instructions or the Eclipse instructions?
Ryan M.
Android Studio
Getting the same behavior with the code on GitHub for this chapter as well.
Mark M.
well, that I can't explain
you can see the code where the preferences are being set
4:15 PM
Mark M.
there's no scenario in which the book itself can be seen without the preferences being loaded
out of curiosity, what Android OS version are you testing this on?
Ryan M.
KitKat
Mark M.
that should be fine, other than screen rotation if you're using the emulator
do you have the line that I linked to in your code?
Ryan M.
That prefs reference is being set correctly in the run() method, however in onPause() back in the Activity, mfrag.getPrefs() is returning null which bypasses setting the position
Mark M.
sounds like a timing issue
there's no question that I'm not dotting all the i's and crossing all the t's in the tutorial (let alone the regular samples)
if onPause() is called before that first line of run() completes, the preferences would not be available
I'll work on improving this portion of the tutorials in some future book update
in the meantime, it's probably not something you're doing wrong, so I wouldn't worry about it
4:20 PM
Ryan M.
Cool. Is there a better place for setting prefs in the ModelFragment other than the thread's run()?
Mark M.
well, ideally, we want to load the SharedPreferences in a background thread, as that involves disk I/O
the problem is where I'm using the SharedPreferences
I should be doing that work in setupPager() or something like that
Ryan M.
Gotcha. I can try that or add some Thread.sleep and see if that helps
Mark M.
let me take a question from EGHDK, and I'll be back with you shortly
EGHDK: your turn! do you have another question?
EGHDK
Yeah, I think I might do on boot completed reciever and take that files value and save it somewhere.
Now the question is where?
Do you think a sharedPref might be the easiest.
Mark M.
boot-completed is a lousy time, simply because devices do not usually get rebooted
SharedPreferences or a simple file on internal storage seem like likely candidates
though bear in mind that your *production public app* needs this logic too
otherwise, when the app gets updated, your validation goes goes *poof*
EGHDK
Can I put it in internal sotrage but thats private to the app?
4:25 PM
Mark M.
er, that should have been "validation code goes *poof*"
internal storage is private to the app by definition
EGHDK
Oh. Whats the api for that again?
Mark M.
getFilesDir(), or the combination of openInputStream() and openOutputStream()
EGHDK
Basically I might copy or move the file from RAW to my internal storage... private to the app. Then is should persist.
Julius
has entered the room
Mark M.
correct
(hello, Julius -- I will be with you shortly!)
Julius
(no hurry I need to compose my question - hi all :) )
EGHDK
Okay cool. So getFilesDir is private and persists?
Mark M.
yes
EGHDK
Great. Thanks.
Mark M.
Julius: you haven't had a shot yet so... do you have a question?
Julius
just composing, happy to wait fo rnow
Mark M.
OK
Ryan: your turn! do you have a question?
Ryan M.
Someone else can go, I am trying some different things :-)
Mark M.
OK
EGHDK: back to you -- do you have another question?
EGHDK
Dang. I had a good question. But forgot it.
4:30 PM
Mark M.
I had an answer for it, but I forgot that too
4:30 PM
Julius
lol
EGHDK
lol
Julius
ok I'll go for it now although I'm not perfectly prepared
Mark M.
Julius: go right ahead
Julius
I'm trying to save a document to PDF
I would like to use the approach in your book to create the document using the curly braces and HTML.
but I don't want to print the document
I would like to save it to a file
When I use the prepPrintWebView
it creates an adapter for printing
which makes sense. :)
just wondering if it's possible to use the same preparation to generate the PDF, but not print it to a printer
just save to an outputstream
(Hope that made sense)
Mark M.
I don't know of any way to accomplish that
4:35 PM
Julius
OK - then I have another question when it comes around on the guitar
Mark M.
ideally, the WebView-to-PDF path would be more directly exposed, in addition to rolling through the adapter
guitar?
Julius
(oh sorry Alice's Restaurant gag)
just in case someone else wants to go ahead with a question I can wait :)
EGHDK
Can't remember my question. Figures. I'm out for today. See you next time Mark.
Mark M.
ok, see you later!
at this point, we can go free-for-all -- if anyone has a question, go ahead
Julius
View paste (15 more lines)
ok - I can save a document to PDF using the following:

		// create a new document
		PdfDocument document = new PdfDocument();

		// crate a page description
		PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(595, 842, 1).create();

		// start a page
		PdfDocument.Page page = document.startPage(pageInfo);

		//		View content = getActivity().findViewById(android.R.id.content);
		View content = getContentView();


...
Mark M.
right, but that implies drawing to a Canvas
Julius
yeah absolutely
This makes an A4 size document which is cool.
Mark M.
though now that I think about it, having WebView draw to your own Canvas should be possible
Julius
My trouble is that the content on the canvas doesn't appear scaled and in the right place
Mark M.
I'm doing that in my mirroring code in CWAC-Layout
Julius
(yeah I wondered about that too)
I think the problem I'm having is that the Canvas is much larger than the "print area"
4:40 PM
Julius
lots more pixels potentially (dpi)
Mark M.
I'm not much of a low-level Canvas guy
Julius
I'm just wondering if I can make a layout that places content on it scaled differently from the device
nah me neither!
but you know _everything_
ok I'll have a bit more of a tinker
Mark M.
I'm confused by your "Canvas is much larger than the print area" statement
Julius
it feels like it's so close to wokring
Mark M.
the Canvas *is* the print area
you're getting it from the PdfDocument.Page
Julius
I'm getting things cut off
Mark M.
you'd need to scale the WebView to be the right size
Julius
yeah I probably don't understand it properly
ok
Mark M.
I assume that this WebView is not actually on the screen, but rather is a background-y thing you're using for printing... right?
Julius
so I would use pixels for that
yeah I believe that is how it works
originally in that upload I was just using the display
ok I'll try the scaling
thank you very much for talking it through with me
Mark M.
in that case, I'd try to figure out how to size the WebView such that it was the same size as your target Canvas
you could take a look at my mirroring code in CWAC-Layout (also reviewed in the book)
Julius
ok I'll give that a look.
Mark M.
in my case, it's bitmaps, where auto-scaling happens a bit more
but it might trigger some ideas
Julius
There was a time when I read the entire book every time it came out, but then there was just too much!
4:45 PM
Mark M.
the table of contents shows the sections that changed or were added
and the changebars in those sections show the paragraphs and stuff that changed
Julius
I see - great
ok thanks again - I'll leave you to your day (or night)
bye all, hope you get all your things going
Julius
has left the room
Mark M.
if anyone has any questions, go ahead
4:50 PM
EGHDK
has left the room
Ryan M.
has left the room
4:55 PM
Mark M.
turned off guest access

Monday, November 10

 

Office Hours

People in this transcript

  • Craig Doremus
  • EGHDK
  • Julius
  • Mark Murphy
  • Ryan McPherson

Files in this transcript