Sunday, January 8, 2017

Move to Medium.com

On this new year of 2017, I decide to find a better blogging platform which support Markdown syntax, as it will be easier for me to blog with programming code.

Here is the new site: https://medium.com/fabiohub

Sunday, January 1, 2017

Retrofit 2 + AutoValueGson

Just try to use Google AutoValue on one of my existing open source project, the steps are basically as below.

Before Apply: A simple UserBean with GitHubService.

After Apply: It need to provide two libraries AutoValue & AutoValueGson, and the UserBean with @AutoValue annotation.

The full project can be found at GitHub.

Saturday, December 31, 2016

Chinese Locale in Android

When we talk about Chinese language globally, there are three major categories:
  • Simplified Chinese
  • Traditional Chinese
  • Chinese
Where Android is using Locale.SIMPLIFIED_CHINESE (Before Android 7.0: zh-rCN; After Android 7.0: zh-rCN_#Hans), Locale.TRADITIONAL_CHINESE (Before Android 7.0: zh-rTW; After Android 7.0: zh-rTW_#Hant) & Locale.CHINESE (Before & After Android 7.0: zh) to represent them.

Here come the problem, when a Hong Kong device which prefer to view in Traditional Chinese, which strings.xml resource will the Android mobile app use?

Before Android 7.0, Android could not always successfully match app and system locales.
User SettingsApp ResourcesResource Resolution
zh-rHKdefault (en)
zh-rCN
zh-rTW
zh
Try zh-rHK => Fail
Try zh => Success
Use zh
Starting in Android 7.0, Android is changing the way the system resolves resources.
User SettingsApp ResourcesResource Resolution
zh-rHK_#Hantdefault (en)
zh-rCN_#Hans
zh-rTW_#Hant
zh
Try zh-rHK_#Hant => Fail
Try zh-r_#Hant => Fail
Try children of zh-r_#Hant => zh-rTW_#Hant
Use zh-rTW#Hant
In order to support both before & after Android 7.0 devices, I believe the minimum resources needed to maintain will be:
  • en (English)
  • zh-rCN (Simplified Chinese)
  • zh-rTW (Traditional Chinese)
  • zh (Traditional Chinese)

Tuesday, December 27, 2016

repository

My first open source Android library - repository, which uses Repository Pattern to load xml or image contents from remote server, local file cache or memory cache.

It took me almost one year (commit history: Nov 22, 2015 - Dec 27, 2016) to:
1) develop it as an Android library
2) prepare a sample app to showcase how to use it
3) publish it to JCenter
4) ready to use for now.

It is quite challenging to develop a library when I compare it with mobile app development. I need to think from a developer point of view, how to code in a way that make them easy to understand.

Thanks to the open source community, I get to study a lot of source code from Square Picasso & Otto, learn from them on how to make a good Android library.
- use Singleton instance
- use Immutable object
- use Builder pattern

I wish one day in the future, someone else will be able to benefit from my contribution on this open source community as well.

Sunday, September 18, 2016

Renew Token

I use to be able to make renew token call successfully in single thread environment.
But when it come to multiple threads environment, the same code that I write is not work as expected.
Due to multiple threads are calling parallel, so it make renew token call fail on some of the threads.
A simple solution is try to delay other threads to wait for the new token return.

Sunday, August 28, 2016

Reverse AtomicFile

Last time when I'm using Picasso on one of my previous Android project, I use to think that the library have a bug, where it store corrupted image sometime.

I try to compare the final image size that was stored is same as the HTTP response size, to make sure no corrupted image been stored. But corrupted image still happen randomly, which make me feel like want to switch to use other caching library.

Recently when I'm troubleshooting a large PDF file download issue on my current project, I found out that the PDF file quite often been stored as a corrupted file as well.

After spend some time to look at the issue, I find out that is actually concurrent update problem, where I try to call read & write at the same time. So I try to add a ReverseAtomicFile.java to handle it.

It is just a reverse version of AtomicFile.java written by Android.

Sunday, May 1, 2016

One Button, Two Actions

I was so stunned when I saw the above UI during one of my project development recently.

One button with two actions? Round corner some more. >.<

I never see such a button in any mobile app before, it totally violent the Android app design guideline.

Anyway, I end up using a custom layout "one_button_two_actions.xml" to achieve it.