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.

Sunday, April 24, 2016

Switch Statement

It shows just one of the operations that might depend on the type of employee.

There are several problems with this function.

First, it's large, and when new employee types are added, it will grow.
Second, it very clearly does more than one thing.
Third, it violates the Single Responsibility Principle (SRP) because there is more than one reason for it to change.
Fourth, it violates the Open Closed Principle (OCP) because it must change whenever new types are added.

But possibly the worst problem with this function is that there are an unlimited number of other functions that will have the same structure.
For example we could have:
  • isPayday(Employee e);
  • deliverPay(Employee e, Money pay);

The solution to this problem is to bury the switch statement in the basement of an abstract factory, and never let anyone see it.

The factory will use the switch statement to create appropriate instance of the derivatives of employee, and the various functions, such as calculatePay, isPayday and deliverPay will be dispatched polymorphically through the employee interface.

Friday, April 20, 2012

Android Dynamic Spinner

The spinner object on android development really give me a big headache. First I face the OnItemSelectedListener event handler gets called every time it been set. And then I face the same event handler gets called when a spinner selection is changed programmatically.

Finally I manage to write a dynamic spinner example to work correctly.

Tuesday, March 13, 2012

How do I submit a Chinese characters in Struts?


The Chinese characters "UTF-8" encoding not able to work with the above code. The magic trick is on the "TilesRequestProcessor", change
< controller processorClass="org.apache.struts.tiles.TilesRequestProcessor" / >
to
< controller processorClass="com.fabiolee.struts.tiles.RequestProcessor" / >
in the "struts-config.xml" and add in the below class "RequestProcessor.java".

Then it will work nicely.

Thursday, September 8, 2011

Facebook Page Tab Height Scrollbar

If the body content of a html page to be added as a facebook page tab is longer than the usual facebook page height, we want to remove the vertical scrollbar and show the complete html page, here is a simple solution:

Saturday, March 1, 2008

div height error on IE6

IE6 again, "height.html" is an example code of div height error on IE6.

This code running no problem on IE7 & Firefox, but when it reach IE6, the height change to 20px.

Same case as my previous post, I look for Mr Google again. This time I get some post said:
1) IE6 height will have some white space if image is smaller then 12px, we need to set line-height to 0px.
2) IE6 height will have some white space if image is smaller then 20px, we need to set line-height to 0px & set a smaller font-size.

So, my code end up like "height_ie6_fix.html".

Finally, it work perfectly on IE6, IE7 & Firefox browsers.