Posts

Showing posts from 2016

Linking native Libraries in Android App

Image
ABI ABI , shorts for Application Binary Interface, is a concept combine the ARM architecture and Instructure set by some formal definition. According to the official document , android support 7 kinds of ABIs, if we want our app to support more android devices, we should package all 7 kinds of ABIs binaries to the package, in this case, it is a linking library. The advantage of this full package is that it can compatible with more devices, the disadvantage is that it enlarged the package size. Also in some situation, the linking library is provided by the third party, missing some ABI types. Then we should use the custom way to implement this app. How get current device's ABI? # ro . product . cpu . abi and ro . product . cpu . abi2 are obsolete , # use ro . product . cpu . abilist instead . ro . product . cpu . abi = armeabi - v7a ro . product . cpu . abi2 = armeabi ro . product . cpu . abilist = armeabi - v7a , armeabi ro . product . cpu . abilist32 = armeabi - v7

Memory Management in Android

Image
Memory in JVM One of the benefits of JVM is the isolation of memory from the host OS, so that if there are some errors in the JVM, the influence is only limited to current JVM process. Actually, the memory in a JVM can be separated to many functional parts, for the simplicity, Heap, and Stack. The Heap is this article's target, Out of Memory Error When the Heap size running to its limitation, the out of Memory Error throws, and the process will crash. It is really easy to repeat this Error, and just write codes to allocate memory repeatedly. while (true) { byte [ ] twn = new byte [ ( int ) ( 1024 L * 1024 L * 20 ) ] ; mLists . add ( twn ) ; } If you write some cache or Memory management app, then it is really the critic part to manage the memory. There are many reasons to trigger this error, serious memory leak or memory limitation, so how to enlarge the memory limitation. java -Xmx:1024m -Xms:512m This is the common way for  a general java command line p

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

2D Graphic Drawing by Pixels in Html5, Android and IOS platform

Image
In the last  post , I introduced the 2D Graphic Drawing in Html5 and android canvas, it is the basic skills if you want running into GUI programming fields, they have the similar drawing API, once you got familiar and fluent in one platform, you will be a master of another GUI platforms in a short time. And why we must learn this 2D graphic drawing API? In Html5 canvas, game developing is the most common scenario to use canvas drawing API, and in Android and IOS platform, if you want to make a custom view or widget, then here we are the 2D drawing show, the difference is that Android is operating those drawing API on a canvas, while the IOS is drawing in a Graphic Context. Again, in the last  example , I learned an example how to drawing custom clock widget in Html5 Canvas, then I ported this widget into Android platform, just the same widget but running in different native platforms. I just enjoy this, and I am looking forward the IOS version of clock widget is my next movement

Learning IOS programming with Swift

Image
I already spent more than three months to learning programming in IOS, my first learning resources are the on-line courses in  Udemy , most of them are so silly that I just learned how to use the visual programming toolkit, Xcode. After leaving the help the storyboard, I still can not start a project. In the really IOS project, the storyboard and Xib visual interface not permitted at a real project. All the layout and views are organized programming in code. Then, I purchased the famous IOS book, Programming IOS 9: Dive deep into views, view controllers, and Frameworks. It tokens me $30 dollars in Amazon’s market, but I tell you It worth every coin. this is an excellent book. I can do IOS programming now, although still at the junior stage. During my learning progress, I found out the Apple’s on-line office document so sucks. I can not figure out where to get started. As an Android developer, I learned everything I need from its office website. What I just did is to downloading

Learning CSS

Image
CSS layout There are three kinds of layouts: Normal flow Layout, Float Layout, Absolute Position Layout. To understand those three kinds of layouts, the key point is to understand two concepts: normal document flow and box model. Normal document flow is the default way of arranging the HTML element from top to bottom or left to right in order without overflow and overlap by the value of the property, display. And the Box model means every HTML element is wrapped in a box, controlled by the properties: margin, padding, border, background. Normal flow layout is the whole layout in a single document flow, according to the normal document flow, the element’s layout behave in a normal way, top to bottom and left to right. Float layout is to use property float by its value left, right or none. The keynote is the float property only affect nearby elements’ layout, in order to erase that effect, there are two ways to eliminate that floating effect. clear : both ; // another w

Android Animations

Image
This article is intended to collect and summarize the topic of Animations in Android. In order to reach an excellent UX design, it is necessary to employ Android’s animation API to improve the details of the UI. Before the details of the Android Animation, I want to recollect the history of Android’s evolvement in Animation API. Before the Android 3.0, it is a wild time, the uncivilized Animation packages dominate the wild field, it is the android.view.animation package. Then the property animator appears at Android 3.0 release, the property Animator is much advanced than Animation, it can animate not only the visible view properties but also any values by ValueAnimator, it is the android.animation.Animator package, much more details can be read from the following sections. Besides the universal Animator, another ViewGroup animation API appeared at Android 3.0, it is the LayoutTransition which was used to animate the layout change event. Then, at Android 3.2, we can animate F

Custom 2D Drawing in Android and Html5 Canvas

Image
Recently, I attended an online MOOC course about  html5 canvas drawing . I was surprised how simple of its  drawing API , which has the power to create awesome UI effect. I summarize the 2D drawing API as two fields: regular shape drawing API and transformation API. As for 2D shape drawing in html5 Canvas there are following limited properties and functions: beginPath, endPath, fillStyle, strokeStyle, stroke, fill, fillRect, moveTo, lineTo, arc, font, fillText, strokeText, createLinearGradient, createRadialGradient, addColorStop, drawImage, bezierCurveTo, quadraticCurveTo. To sum up, the above 2D drawing API can do following jobs. moving a point; drawing a line; drawing an arc or circle; drawing a bezier curve; make a path; stroke along the path; fill the closed path with image, colors, gradient effect or patterns; Then, we count the transformation APIs: save, restore, translate, rotate, scale, transform. No need any more illustrations, is it? The transform one ma