Bug on Parade

It turns out that Android 1.5 (Cupcake) has a bug in the ImageView class. The bug prevents the setImageMatrix() method from working when the ImageView is in "matrix" mode, which is pretty ironic if you think about it.

Unfortunately, there is no complete list of bugs, so figuring out this was a bug in Android (as opposed to a bug in our code or a misunderstanding of how something works) took a bit of sleuthing. In case you find yourself in a similar situation, here are the steps that I went through:

1. My first suspect was the new code we just added: the WrapMo-tionEvent and EclairMotionEvent classes. I put in a few logging statements to verify events were being handled correctly and the transformation matrix was created correctly. They turned up no problems, so I began to suspect something was wrong with the ImageView class or matrix manipulation.

2. Next, I checked the release notes4 for each version of Android to see whether there were any breaking changes mentioned that

4. http://cl.android.com/sdk/RELEASENOTES.html

might affect the ImageView class. Breaking changes are updates that cause code that was working to stop working, or vice versa. I didn't find any that seemed related.

3. Then I searched the Android bug database5 for the keywords ImageView and matrix. Unfortunately, the public bug database is incomplete because Google keeps its own private list of bugs, so I didn't find anything.

4. Next, I searched all the Android Developer Forums6 to see whether anybody else was having the same problem. The groups all have search forms of their own, but the quickest and most accurate way to search the forums is just to use the Google search engine and search the entire Web. Using the same keywords (ImageView and matrix), I found a posting from 2009 that looked exactly the same. Unfortunately, there was no follow-up or workaround posted, but I knew I was on the right track.

5. Finally, I went to the source.7 With a few exceptions, all the code for Android is available in a public repository online. I had a clue about where the source to the ImageView class was located in the source tree because one of the earlier searches had revealed the path name. It was in the platform/frameworks/base.git project, under the core/java/widget directory. I opened the history using the repository's web interface.8 And there it was, a change made on July 30, 2009, with the comment: "Fix a bug in ImageView: The drawing matrix is not updated when setlmageMatrix is called." This bug fix was performed in between the Cupcake and Donut versions of Android, which explained why the problem happened in 1.5 but not in 1.6.

In almost all cases, you'll be able to find a solution without resorting to reading the Android source code. But it's nice to know it's there if you need it. By studying the code and trying a few things, I was able to create a workaround for the bug.

5. http://b.android.com

6. http://d.android.com/resources/community-groups.html

7. http://source.android.com

8. https://android.git.kernel.org/?p=platform/frameworks/base.git;a=history;f=core/java/android/widget/ImageView.java

Add these lines to the end of the onCreate() method in the Touch class:

Download Touchv2/src/org/example/touch/Touch.java

@Override public void onCreate(Bundle savedlnstanceState) { // ...

// Work around a Cupcake bug matrix.setTranslate(1f, 1f); view.setlmageMatrix(matrix);

By running the program in the emulator using various versions of Android, you can verify that this fixes the problem in Android 1.5 and doesn't break anything in later versions. Once your program is working with different versions of Android, you should try it at different screen sizes as well.

0 0

Post a comment