Posts

Showing posts from October, 2016

Rendering fragments in Adapters

Image
Fragments in Adapters This is a black magic that I met recently, There is an Adapter pattern in Android, which bonds the data and View together, but what if the data part is a bunch of fragments. Can we render fragments in Adapters? After doing some research and experiments, the answer is: Fragments can be rendered in Adapters in some conditions. ListView .vs. RecyclerView When comes to Adapter pattern in Android, there are two kinds of Adapters, AdapterView, and RecyclerView, while the AdapterView is an abstract class, its most famous representative is the ListView. What’s the difference between ListView and RecyclerView? ListView is the child of AdapterView, while RecyclerView is inherited from ViewGroup. I think that’s the biggest inherent difference. RecyclerView is also considered as the replacement for the ListView, it is invited in lollipop age, and with some benefits inside: ViewHolder pattern inside; decoupling the item layout manager; isolated item decorat

Android Unit Test

Image
Espresso Espresso is the newest testing framework for Android, also it is not so fresh anymore, I guess it appears in Lollipop time. According to the  official document , it can write concise, beautiful, and reliable Android UI tests. @Test public void greeterSaysHello() { onView ( withId ( R . id . name_field ) ) . perform ( typeText ( "Steve" ) ) ; onView ( withId ( R . id . greet_button ) ) . perform ( click ( ) ) ; onView ( withText ( "Hello Steve!" ) ) . check ( matches ( isDisplayed ( ) ) ) ; } Apparently, it’s concise and beautiful syntax comes from the functional coding styles, whether it is reliable, I can not get the conclusion from the above syntax. I think it is the replacement of the deprecated  Instrumentation TestCase , so it should be much advanced than the older one. And according to the  Chui-Ki Chen’s presentation , it does automatic synchronization of test action with app UI, which is the big breakthrough

2D Graphic Transformation

Image
In the past posts, I already write articles about  2D graphic drawing API , and also an article about the black magic of the  Bitmap operations . In this post, I try to write something about graphic transformation. As far as I know there are only four transformation APIs, including translate, scale, rotate and matrix. Also, all the platforms have same transformation APIs, if it is a GUI framework. Those four APIs just like a formula, if you understand them in Android, then you have the ability to do programming in IOS and Html5. The translate, scale and rotate are much more usually used and understandable, the difficult is the matrix, it is the general and mathematic representation of all the transformations in a more powerful way. What’s more, in the past  post , I just used the graphic drawing API directly in coding, actually, it is not enough for making a performance customized UI graphic. The more common case is alway drawing by both the drawing API and graphic transformatio