Posts

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

Java Multi-Threading synchronization interview question

Image
The multi-threading synchronization questions always concentrate on a few keywords: wait, notify, notifyAll, synchronized, volatile. The following question is the hardest, I ever met. The thread t1 should print integer number from 1–52, the thread t2 should print character from A-Z, the question is how to let the final result to be 12A34B56C… by implement Printer class. (The Printer class is already finished by the way) public class Main { public static void main ( String [ ] args ) { System . out . println ( "Hello World!" ) ; Printer p = new Printer ( ) ; Thread t1 = new NumberPrinter ( p ) ; Thread t2 = new LetterPrinter ( p ) ; t1 . start ( ) ; t2 . start ( ) ; } } public class LetterPrinter extends Thread { private Printer p ; public LetterPrinter ( Printer p ) { this . p = p ; } public void run ( ) { for ( char c = 'A' ; c < = ...

Light-BLE Release Note

Image
About two years ago, I published my debugging toolkit in Android for Bluetooth LE development, after that, I left that field, wearable-BLE equipment development just quit that job and join a new one. And now at this moment, I quit the job again, to summarize my collections during the past two years. There are two keynotes: my skills sharper a lot at Android App development, second,  Light-BLE  was still my most popular project. During the past one year, there are at least four people contact me for debugs and more stable demos. Finally, I am here to announce the release of the beta-2 version of Light-BLE, it is actually be rewritten. This is the first version release note two years ago. http://zpcat.blogspot.com/2014/03/lightble-practical-app-tool-to-develop.html So, what was changed compared with the two years ago? 1. New Architecture I rewrite this project to compatible with the legendary MVP architecture, which decoupled the View and logical data layer, make...

Android Job Interview Questions

Image
In this post, I tried to wrote some Job interview questions, that I met during my Job interview journey. Yeah, some of the them are still so fresh, because I mess up them a lot. However, A sketch notebook is always better than a good memory, especially in the situation of the lack practice exercise. finalize function The finalize method is used in JVM’s GC collection. But, it was said that it never guaranteed to be called during the collection, that’s means unpredictable, so I guess why I should put the resource release code into an unpredictable method, still be puzzled. How to write a singleton and thread-safe class? Following is an ordinary Singleton class without thread-safe features. public class Singular { private static Singular sInstance ; private Singular ( ) { } public static Singular getInstance ( ) { if ( sInstance = = null ) { sInstance = new Singular ( ) ; } return sInstance ; ...

Dependency Injection in Android with Dagger 2

Image
Dependency Injection in Android with Dagger 2 Dagger’s Power Dagger 2 is the upgraded version of the original Square’s Dagger, designed for dependency injection(DI) technology for java. DI’s sensational ability is to decouple the dependency relationship between objects, clear the code, and also let developer focus to the functional classes. In the complex framework & architecture, DI becomes the standard component, like Spring. Similarly, If you wanna write agile and maintainable code in a large and long-term run Android project, Dagger should be an not so bad option. How to install codepath/android_guides Many Android apps rely on instantiating objects that often require other dependencies. For instance, a Twitter API… github.com The first step always to install Dagger 2, unfortunately, the  official document did not give any details in Android’s Gradle build environment. Yeah, Dagger is not just for Android, but for any Java Project. The good news is above...

ReactiveX Operations

Image
ReactiveX Operations Table of Contents Resources ReactiveX Operations Sample Source code 1 Resources http://reactivex.io/documentation/operators.html http://reactivex.io/tutorials.html https://github.com/ReactiveX/RxJava/wiki/Additional-Reading 2 ReactiveX Operations To understand ReactiveX, We must consider everything as a stream, after that, the operations of ReactiveX stream was so complicated, that we can trade them as a new language, which operates the stream. The ReactiveX's Official document classify its operations as following categories: Creating Observables Transforming Observables Filtering Observables Combining Observables Error Handling Operations Observable Utility Operators Conditional and Boolean Operators Mathematical and Aggregate Operators BackPressure Operators Connectable Observable Operators Operators to Convert Observables Beside above categories, ReactiveX also provides the strategy to practice those operation...