Posts

SQL tutorial - row column transform

Image
In this case, I intend to introduce a complicated SQL query problem: row column transform. In the last chapter, about the fundamental SQL syntax , I used a MySQL sample database named sakila . In this tutorial, I still use it. transform rows to columns Task #1: Take table actor inside sakila for example, How to query the most popular last_names? let limit the condition to the last_names repeat at least more than 3 times. USE sakila ; SELECT last_name , COUNT ( first_NAME ) as size FROM actor GROUP BY last_name having size > 3; We got the result: + -----------+------+ | last_name | size | + -----------+------+ | KILMER | 5 | | NOLTE | 4 | | TEMPLE | 4 | + -----------+------+ Task #2: Convert above result from row to column format. + --------+-------+--------+ | KILMER | NOLTE | TEMPLE | + --------+-------+--------+ | 5 | 4 | 4 | + --------+-------+--------+ Use CASE WHEN an...

SQL Tutorial - SQL Syntax

Image
This is my learning notes about the SQL (based on  MySql ). As far as I known, Mysql was acquired by Oracle , whose mainly product is also the enterprise highly professional database, and the founder of the Mysql worried the future of the MySQL, then he started another open sourced database named MariaDB . I consider the Mysql and MariaDB the same thing, they even have the same command line tool name. And with no hesitate, I use MariaDB as the alternative to Mysql in the tutorial. Database Creation The operation of Database include Change, Create, Alter, Drop database. USE db_name ; CREATE DATABASE IF NOT EXIST db_name CHARACTER SET = utf - 8 ; ALTER DATABASE db_name CHARACTER SET = utf - 8 ; DROP DATABASE IF EXIST db_name ; Table Creation The basic composition of a database is its tables, table schema definition is the beginning stage in the database design. There is two import aspect in define a table schema, the column data types and the constric...

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 = ar...

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 l...

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 ite...

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...