How does Android implement the control timing function elegantly

Not much nonsense, today I recommend TimingX, an open source tool for Android multi-component synchronization timing.

TimingX is a tool class for Android multi-component synchronization timing, which is implemented using Handler.

In the project, we often have timing needs, which is expressed as the timing from 00:00, that is, the format of minutes and seconds. TimingX is used for timing, it currently does not support countdown, but if you have this requirement, you can easily implement it.

project address

Gitee: Timingx , I think it's cool to use, please don't be stingy with your Start!
Also welcome everyone to visit my personal blog: Thatcher Li , to share high-quality original technical articles.

Basic usage

  1. The use of TimingX is very simple. The source code of the entire class is less than 200 lines. When a control needs to display timing, only the following code can be added to the timing control group.
TimingX.builder().add(view);
复制代码
  1. start the timer
TimingX.builder().start();
复制代码

If you don’t want to separate adding to the timing control group and starting timing into two lines of code, TimingX also supports chained calls

TimingX.builder().add(view).start();
复制代码

Note that once the call start()method after all add to the control of the control group have started counting their time is the same.

  1. Stop timing
TimingX.builder().stop();
复制代码
  1. Destroy the Handler to avoid memory leaks

When you do not need a timer, such as exit Activityor Fragmentremember their onDestroy()calling in life-cycle approach

TimingX.builder().destroy();
复制代码

getStatus() method

The public method, this method can get the current timing status, start/pause. Many times you will use it to process your own business logic.

to sum up

If you have a better idea, and the current functions cannot meet your business needs, you can leave me a message. Or if you encounter a problem during use, you can mention it issue. At the same time, you can contribute source code to extend this type of functionality.

This article  has been included in the open source project: https://github.com/Android-Alvin/Android-LearningNotes , which contains self-learning programming routes in different directions, interview question collection/face sutras, and a series of technical articles, etc. The resources are continuously being updated …

Guess you like

Origin blog.csdn.net/weixin_43901866/article/details/113623989