Apr 9 | 8:50 AM |
Mark M. | has entered the room |
Mark M. | turned on guest access |
Apr 9 | 8:55 AM |
Anurag S. | has entered the room |
Mark M. |
hello, Anurag!
|
Mark M. |
how can I help you today?
|
Anurag S. |
View paste
(3 more lines)
|
Mark M. |
I think that there are older iText implementations that work on Android and work with Java 7
|
Mark M. |
my guess is that you will run out of memory, no matter what you use
|
bill | has entered the room |
Anurag S. |
Yes, correct.
|
Mark M. |
(BTW, hello bill! I'll be with you shortly!)
|
bill |
Hello Mark
|
Mark M. |
personally, I would have the work be done on a server, if possible
|
Anurag S. |
https://developers.itextpdf.com/itextg-android dosen't works.
|
Anurag S. |
Yes, I thought so but the requirement is as such to work in offline.
|
Apr 9 | 9:00 AM |
Mark M. |
you could try PdfDocument in Android 5.0+, but that's really designed for Android's printing framework, not for creating arbitrary PDFs
|
Mark M. |
with regards to iText, try iText 5, instead of iText 7
|
Mark M. |
also, bear in mind that iText is licensed under the GPL
|
Anurag S. |
So any other alternative approach?
|
Anurag S. |
Yes.
|
Mark M. |
than those? none that I know of, though there are probably some commercial libraries floating around
|
Anurag S. |
As pointed above iText 5 dosen't compiles
|
Mark M. |
your original question was for iText 7
|
Mark M. |
https://itextpdf.com/itext-7-core is iText 7
|
Anurag S. |
It's not found on maven
|
Anurag S. |
Yes
|
Mark M. |
then perhaps compile from source, or ask the iText people where it moved to
|
Anurag S. |
Itried both with 5 and 7. It is not working.
|
Anurag S. |
Ok
|
Anurag S. |
Is it possible to generate html or render those images with text and image in an android view?
|
Mark M. |
let me take a question from Bill, and I'll return to you in a bit
|
Mark M. |
Bill: your turn! do you have a question?
|
Anurag S. |
Sure
|
Anurag S. |
Thanks
|
bill |
View paste
|
Mark M. |
for a minSdkVersion of 21, I would just use JobScheduler
|
Apr 9 | 9:05 AM |
Mark M. |
well, actually, not with that window
|
Mark M. |
take that back
|
Mark M. |
you'd probably need to use AlarmManager and setWindow()
|
Mark M. |
the problem with JobScheduler is that you have limited control over actual timing
|
Mark M. |
with AlarmManager, you would need to implement rescheduling yourself
|
bill |
I am afraid that if I use periodic timing there would be sliding outside the time window
|
bill |
With periodic timing I mean every 24 hours
|
Mark M. |
schedule it for, say, 21:15 or 21:30, somewhere close to the start of the window
|
Mark M. |
validate in the BroadcastReceiver that you got control in the desired window, rescheduling if not
|
bill |
I understand.
|
Mark M. |
alternatively, use none of these solutions, and have the server send an FCM high-priority message to ask the device to do its work
|
Mark M. |
that's supposed to break through even Doze mode, though I haven't tried it
|
bill |
Ok, good point
|
bill |
I want to be a possibility to wake the device
|
Mark M. |
I'm assuming that the work to be done requires Internet access, given your reference to the server
|
Apr 9 | 9:10 AM |
Mark M. |
AlarmManager, JobScheduler, and FCM messages can wake the device
|
bill |
One last question. evernote has something to offer me better than the JobScheduler
|
Mark M. |
their library simply wraps around JobScheduler and AlarmManager
|
Mark M. |
it's a nice library, particularly if you want JobScheduler semantics on Android 4.4 and older
|
Mark M. |
if you like their API better, feel free to use it
|
bill |
As I said our minSDKApi is 21.
|
Mark M. |
however, it does not change the underlying limitations of AlarmManager and JobScheduler, particularly with respect to things like Doze mode
|
Mark M. |
that's why I did not suggest using their library
|
Mark M. |
IMHO, the value of that library falls a fair bit once you have a minSdkVersion of 21 or higher
|
Mark M. |
but, again, if you like the library for other reasons, use it
|
Mark M. |
let me switch back to Anurag for a while, and I'll return to you shortly
|
Mark M. |
Anurag: your turn! do you have another question?
|
bill |
Ok. I want time to study your answers
|
Anurag S. |
Is it possible to generate html or render those images with text and image in an android view?
|
Mark M. |
Anurag: you can certainly generate HTML
|
Mark M. |
I have a few sample apps in the book that do that, using the jMustache template library
|
Apr 9 | 9:15 AM |
Mark M. |
you can certainly create a layout that shows text and images
|
Mark M. |
however, if your end objective is a PDF, your primary options of getting a PDF from those things would be the Android printing framework
|
Mark M. |
which is designed for printing
|
Mark M. |
any PDF that comes out of that process *should* be general-purpose, but I get nervous when developers count on that
|
Anurag S. |
Images will be placed on external storage. So, using the jMustache template library would it be possible to access those images and render the htm in a webview?
|
Mark M. |
sure
|
Mark M. |
call getAbsolutePath() on the File object pointing to the image, and use the resulting value in the HTML for the src attribute on an <img> tag
|
Mark M. |
you'll need permission to work with external storage, but presumably you already have that
|
Anurag S. |
Ok. So could I create an html file using jMustache template library on external storage and using Android printing framework save it as pdf?
|
Anurag S. |
Like chrome has an option.
|
Mark M. |
you can print an HTML document with WebView
|
Apr 9 | 9:20 AM |
Mark M. |
the WebView API (createPrintDocumentAdapter()) is not designed to create a standalone PDF
|
Anurag S. |
Ok
|
Anurag S. |
So what about generating htlm using jMustache template library and then using another third party library for converting html to pdf from the application itself?
|
Mark M. |
I am not aware of one that works on Android
|
Mark M. |
on a server, you could use Prince XML (commercial) or wkhtml2pdf (open source)
|
Mark M. |
but I'm not aware of either of those being an on-device option
|
Anurag S. |
Fine.
|
Mark M. |
let me take another question from Bill, and I will return to you shortly
|
Mark M. |
Bill: your turn! do you have another question?
|
Anurag S. |
Itried using PdfDocument in Android 5.0 but it's slow while rendering. It uses canvas. Out of Memory is another issue with it. Morover I need to play in pixes to place text and calculate overflowing or wrapping of text. etc.
|
Anurag S. |
OK
|
Apr 9 | 9:25 AM |
bill |
For today I think I have not other question. Maybe tomorrow on the some issue. Thanks a lot.
|
Mark M. |
OK, if you come up with another one while you are still here, let me know
|
Mark M. |
meanwhile...
|
Mark M. |
Anurag: back to you!
|
Anurag S. |
I tried using PdfDocument in Android 5.0 but it's slow while rendering. It uses canvas. Out of Memory is another issue with it. Morover I need to play in pixes to place text and calculate overflowing or wrapping of text. etc.
|
bill |
OK Mark. Thanks a lot again!!!
|
Mark M. |
(Bill: you're welcome!)
|
Mark M. |
Anurag: mostly, the Canvas-based approach seems to be designed to print a layout that you may already have set up on-screen
|
Mark M. |
eventually, Android will need better PDF generation options
|
Mark M. |
probably via a third-party library
|
Mark M. |
though, for many use cases (albeit perhaps not yours), server-side PDF generation is fine and greatly increases your flexibility
|
Anurag S. |
Yes, I completely agree with you. But the problem is end user captures n number of picture and need to see report immediately. Uploading all those images to server will take time.
|
Mark M. |
what will be done with the report, after the user sees it?
|
Mark M. |
in other words, does the report *have* to be a PDF?
|
Apr 9 | 9:30 AM |
Mark M. |
perhaps the on-device representation is in HTML, and you ship a ZIP with the HTML+images up to the server for PDF generation
|
Anurag S. |
I think this would be much better..
|
Anurag S. |
Client needs to signature the document or pdf.
|
Mark M. |
one commercial library in this space is PDFjet: http://pdfjet.com/java/index.html
|
Mark M. |
I have not tried it
|
Anurag S. |
So generating html will also not throw out of memory exception I guess because it will contain only path to images and some kbs of text.
|
Mark M. |
correct
|
Mark M. |
assuming that your text is not huge, of course
|
Anurag S. |
This design approach seems to work.
|
Anurag S. |
Text is just some question and answers
|
Anurag S. |
So createing this zip of around 300mb. Will it be fine?
|
Anurag S. |
100 images of 3mb each
|
Andre R. | has entered the room |
Mark M. |
if you mean in terms of OutOfMemoryError, if you use ZipOutputStream, I think that you will be OK
|
Andre R. |
Good Morning
|
Anurag S. |
Yes, OK.
|
Apr 9 | 9:35 AM |
Mark M. |
let me take a question from Andre, and I'll return to you in a little bit
|
Mark M. |
Andre: hi! do you have a question?
|
Anurag S. |
Sure, Mark.
|
Andre R. |
Can you take a look at this question ? https://stackoverflow.com/questions/49690010/ho...
|
Mark M. |
yes, I saw that when you posted it
|
Andre R. |
What do you think of the approach ?
|
Andre R. |
Is there anything I should be aware of, regarding memory leaks ?
|
Mark M. |
nothing in importaBkpObservable() seems like it would represent a leak, if that's what you mean
|
Mark M. |
assuming that Room is happy after the backup operation, this seems OK
|
Andre R. |
I would like to know if it is sufficient to assign null to the Room database instance ?
|
Mark M. |
well, Room doesn't know anything about that
|
Apr 9 | 9:40 AM |
Mark M. |
if you are asking whether in your business logic that suffices, probably, though you should ensure there is no race condition with something else trying to use that INSTANCE
|
Mark M. |
part of what I need to spend some time on is seeing how well Room deals with close() on a database, in terms of its background InvalidationTracker
|
Mark M. |
unfortunately, other work has been getting in the way of my spending time on that subject... :-(
|
Andre R. |
I am creating again my activities and calling another instance for them, I don't know what is happening to the former instance. Is it going to be garbage collected ?
|
Mark M. |
if nothing else has a lingering reference to it, yes
|
Mark M. |
in principle, once you call close(), Room is responsible for removing any of its references (e.g., terminate the InvalidationTracker thread)
|
Mark M. |
if Room does that, and you do not have any references to it in your own code, it will (eventually) get garbage-collected
|
Apr 9 | 9:45 AM |
Mark M. |
so, if you are not seeing leaks, and Room is happy with the new instance, you should be in decent shape
|
Andre R. |
Ok. So the risk is if Room doesn't make its job before I request another instance of it ?
|
Mark M. |
I do not know what "if Room doesn't make its job" means, sorry
|
Andre R. |
Like closing the database and terminate the invalidation tracker ?
|
Mark M. |
if they are doing it correctly, it should be synchronous as part of close()
|
Mark M. |
but, again, this is an area that I want to research further
|
Andre R. |
Ok. I will keep my eyes open. Thank you.
|
Mark M. |
also, it's open source, so you can do what I'll (eventually) do, which is to look at what close() does and see if there are any signs of potential synchronization issues
|
Mark M. |
I'll also be bugging Google to better document the rules around close()
|
Apr 9 | 9:50 AM |
Mark M. |
as this is an area that really needs explicit guarantees written into the JavaDocs
|
Mark M. |
at least, IMHO
|
Mark M. |
OK, free-for-all for the last 10 minutes -- if anyone has a question, go ahead, and I'll try to keep up :-)
|
Anurag S. |
View paste
|
Andre R. | has left the room |
Mark M. |
Anurag: if you are using a separate process for uploads, you will need to use a system broadcast (e.g., sendBroadcast() on Context), as event bus/RxJava options are all in-process
|
Anurag S. |
Ok
|
Anurag S. |
What do you think about using this design approach?
|
Mark M. |
personally, I try to avoid extra processes
|
Mark M. |
a JobIntentService, in the main process, should be sufficient here
|
Mark M. |
extra processes for *really* long-lived stuff (e.g., runs for hours) may be a good tradeoff for the user
|
Anurag S. |
OK
|
Apr 9 | 9:55 AM |
Anurag S. |
What about using https://github.com/zeroturnaround/zt-zip instead of ZipOutputStream?
|
Mark M. |
I have not used it
|
Mark M. |
the key for your case is the stream
|
Mark M. |
to avoid OutOfMemoryErrors
|
Anurag S. |
Sure
|
Mark M. |
you would need to look at the code of that library to see whether ZipUtil.pack() and stuff use streams or not
|
Mark M. |
probably, they do
|
Mark M. |
in which case, that library has a nice convenient API
|
Anurag S. |
I will try to implement and share the update or ask question if stuck.
|
Anurag S. |
Thankyou, Mark you have been of great help! Thankyou, for your precious time! Take care Mark :-)!
|
Mark M. |
you're welcome!
|
Anurag S. |
How to bookmark this conversation?
|
Mark M. |
I will be posting the transcript to https://commonsware.com/office-hours/ shortly after the chat ends
|
Mark M. |
so, there will be a 2018-04-09 entry there in a bit
|
Anurag S. |
Ok Thank you :-)
|
Apr 9 | 10:00 AM |
Mark M. |
that's a wrap for today's chat
|
Mark M. |
the next chat is tomorrow at 4pm US Eastern
|
Mark M. |
have a pleasant day!
|
Anurag S. | has left the room |
bill | has left the room |
Mark M. | turned off guest access |