Android Development

Guowei Lv

11 minute read

Android custom view

In this post, we will be focusing on the Paint. Color The color in Paint has 3 parts: basic color, color filter and xfermode. Basic color There are 2 ways to set color in Paint: use setColor() and use Shader. Set color directly Two methods can be used: paint.setColor(Color.parseColor("#B90E83"); paint.setARGB(100, 255, 0, 0); There is no difference, pick whichever you like. Set color using Shader There are different types of Shader, let’s look them one by one.

Android Custom View 102 (Part I)

The basics of drawing stuff

Guowei Lv

4 minute read

Android custom view

If 101 is like a crash course, then this 102 will provide much more detail. In this 1st part, we focus on only one thing: how to draw things. Draw Color Draw the entire view with one color. public class DrawColorView extends View { … @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawColor(Color.YELLOW); } } Draw Circle Draw a circle on the view. Pay attention that all drawXXX() functions use pixel as unit.

Where to Put observeOn in Rxjava2

Where to put observeOn matters!

Guowei Lv

1 minute read

Me: Why I have put the observeOn(AndroidSchedulars.mainThread()) but still onNext() is NOT called in android main thread?! Rx Master: Show me your code. Me: Here you are my master. I just want to wait for 5 seconds then call an api: override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) fun networkObservable(): Observable<String> { return Observable.just("test").subscribeOn(Schedulers.io()) } Observable.timer(5, TimeUnit.SECONDS) .observeOn(AndroidSchedulers.mainThread()) .flatMap { _ -> networkObservable() } .subscribe(Consumer { Log.d("testtest", it) Log.d("testtest", Thread.

Android Design Pattern - Build a SOLID Image Loader

Develop a image loader guided by design patterns

Guowei Lv

6 minute read

SOLID Principles and Design Patterns play an important role in Android development. Lets take a look at how to design and implement an image loader step by step. This example comes from the book Android Source Code Design Patterns - Analysis and Practice. I also rewrote all the code from Java to Kotlin and made some bug fixes. Step 1: Make it work Requirement: Our first version of image loader will just use in-memory cache to cache images loaded from the Internet, we will ignore cache validation for now.

What the FlatMap?

Understand flatmap in RxJava

3 minute read

The operator flatmap in RxJava is a tough topic if you are not familiar with functional style. After reading all the articles and tutorials and even worked with RxJava for almost a year, I’m still not quite confident about it. I sure know how to and when to use it, but the understanding seems always shallow. Until I read the flatmap in the Structure and Interpretation of Computer Programs.