Skip to content

Instantly share code, notes, and snippets.

@uznomis
Last active February 3, 2020 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save uznomis/da8e5e893e469f38406d2101577b4492 to your computer and use it in GitHub Desktop.
Save uznomis/da8e5e893e469f38406d2101577b4492 to your computer and use it in GitHub Desktop.
Impoving LibreOffice Android Viewer -- A Google Summer of Code Project
*Overview*
LibreOffice is a modern Free & Open Source Office suite, one of the largest open source projects, and used by millions of users worldwide. LibreOffice works nicely on Android these days, but there are still many things to improve and fix. My work during this project is focused on adding new features to LibreOffice Android Viewer and solving most annoying bugs for it.
*Toolchains*
Then main tool I used is Android Studio, the official IDE from Google for developing Android apps. The programming language is primarily Java, some XML, and some C++. The version control tool I used is git and code review through Gerrit.
*Main tasks*
1. Presentation mode
I export the presentation as a SVG file and then show it in a WebView. The SVG support of WebView is strongly related to Android version of the running device. Pre-KitKat Android doesn't have this support because the default WebView engine is not chrome yet. So, I did an alert dialog for pre-KitKat Android phones and copy the link to system clipboard. Then the user can go to Chrome or Firefox and load the file manually.
#Patches: https://gerrit.libreoffice.org/38006
2. Calc UI
Header info can be retrieved with a LOKit call and the JNI functions are already implemented before I started. The challenge here is how to add headers to Calc UI. I decided to add 2 independent Views left and top and only show them when user opens Calc files. The drawing of headers is achieved by CanvasElement. Basically, whenever there is a refresh on the headers, we draw the headers on the left and top views one by one. The result turned out to be quite neat and quick. The tricky part involves calculating the size of the headers in pixels and also adapt them when the user pans and zooms. The zooming is problematic just like in LOOL, in which the retrieved header info doesn't match what's showing on the main GL view. So, we decided to fix the zoom to 1x and DPI to 96 to work around. Someone who knows LO very well should tackle this issue.
After the headers started to work, I implemented selecting cells and rows/columns. They are implemented differently, since cells are on the main GL view and rows/columns are supposed to relate to the top and left header views. The selection involves emitting calls to LOKit and listening to callbacks from LOKit. A lot of details should be considered. Luckily, now they work pretty nicely.
After the selection worked, I went on and implemented address bar and formula bar, which was quite simple.
Finally, I implemented insert/delete/hide/show/adjust width/height, which were straightforward but required a lot of care and caution.
#Patches: https://gerrit.libreoffice.org/38936; https://gerrit.libreoffice.org/39694; https://gerrit.libreoffice.org/40684; https://gerrit.libreoffice.org/40842
3. Ability to load password-protected documents
Android Viewer was not able to load password protected documents because the proper JNI functions didn't exist. I tried to implement this functionality and found out that in Android Viewer actually only the LO Document instance is implemented. However, in order to provide password, we need to implement the LO Office instance which takes the password. So, I implemented the messageRetrieved and the bindMessageCallback and so on, for LO Office instance as Android JNI. And of course password related JNI functions came afterwards. This task was pretty challenging since I never did C++ programming before. I had to learn by mimicking other parts of the code, which worked well.
#Patches: https://gerrit.libreoffice.org/40458/
*Full list of features added*
1. Ability to load password-protected documents: https://gerrit.libreoffice.org/40458/
2. Auto-updated page number information in text documents: https://gerrit.libreoffice.org/36178/
3. Interactive spreadsheet UI with row/column headers: https://gerrit.libreoffice.org/38936; https://gerrit.libreoffice.org/39694
4. Header related functions e.g. insert/delete/hide/show/optimal width or height in spreadsheet UI: https://gerrit.libreoffice.org/40684
5. Address and formula bars in spreadsheet UI: https://gerrit.libreoffice.org/40842
6. Presentation Mode in slideshow documents: https://gerrit.libreoffice.org/38006
7. Developer Mode for sending UNO commands in the app without debugging tool: https://gerrit.libreoffice.org/37045
8. Ability for user to double tap to zoom in and out: https://gerrit.libreoffice.org/36164
9. Ability to insert pictures from taking photos, choosing local images, downloading cloud images (Google photos, Dropbox, etc.) with an option to compress the image or not: https://gerrit.libreoffice.org/41150
*Full list of bugs solved and other patches*
1. Top part unreachable with soft keyboard open: https://gerrit.libreoffice.org/35721
2. Fix typo: inticator -> indicator: https://gerrit.libreoffice.org/36103
3. Fix typo: 'forgeround' in multiple files: https://gerrit.libreoffice.org/36154
4. Restrict zoom to page width: https://gerrit.libreoffice.org/35308
5. Android Viewer doesn't focus on the word you search: https://gerrit.libreoffice.org/35715
6. Android Viewer does not show page count: https://gerrit.libreoffice.org/36178/
7. Android Viewer does not switch edit mode to view: https://gerrit.libreoffice.org/36541
8. Disable 'parts' in text documents: https://gerrit.libreoffice.org/36538
9. Fix appbar invisible on lower version: https://gerrit.libreoffice.org/36950
10. Fix behavior of double tap zoom in and out: https://gerrit.libreoffice.org/37046
11. Update zoom constraints with device rotate: https://gerrit.libreoffice.org/37847
12. Fix windowSoftInputMode: https://gerrit.libreoffice.org/40686
13. Fix “Even internal links are treated as hyperlinks”: https://gerrit.libreoffice.org/40947
14. Correct typo of class name: https://gerrit.libreoffice.org/39832
15. Fix crash after save dialog: https://gerrit.libreoffice.org/39847
16. Correct LOK Enums: https://gerrit.libreoffice.org/39831
17. Add LOKit Enums to Document.java: https://gerrit.libreoffice.org/39375
18. appbar invisible on lower version: https://gerrit.libreoffice.org/36950
19. Clean up util func with Calc dev: https://gerrit.libreoffice.org/41372
20. Calc cannot zoom due DPI fixed to 96 (work in progress): https://gerrit.libreoffice.org/40697
*Related links*
1. Proposal page: https://summerofcode.withgoogle.com/projects/#5462728836644864
2. My code patches: https://gerrit.libreoffice.org/#/q/owner:%22Ximeng+Zu+%253Cuznomis%2540yahoo.com%253E%22
3. Beta app to test: http://dev-builds.libreoffice.org/daily/master/Android-ARM@24-Bytemark-Hosting/current/
4. LibreOffice homepage: https://www.libreoffice.org/
5. TDF homepage: https://www.documentfoundation.org/
6. Ideas page for LibreOffice Android Viewer: https://wiki.documentfoundation.org/Development/GSoC/Ideas#LibreOffice_for_Android
7. LibreOffice 6.0 release notes with my contributions: https://wiki.documentfoundation.org/ReleaseNotes/6.0#Android
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment