Countdown to App startup page and countdown to app startup

Source: Internet
Author: User

Countdown to App startup page and countdown to app startup

Reprinted please indicate the source: http://www.cnblogs.com/cnwutianhao/p/6753418.html

 

The sample code is written in RxJava + RxLifecycle + Data-Binding mode.

Example:

The implementation method is as follows:

1. import dependent Libraries

① RxJava: Reactive Extensions for the JVM

compile 'io.reactivex:rxjava:1.2.9'compile 'io.reactivex:rxandroid:1.2.1'

② RxLifecycle

compile 'com.trello:rxlifecycle:1.0'compile 'com.trello:rxlifecycle-components:1.0'

③ Data-Binding

dataBinding {    enabled = true}

 

2. code writing (key code)

① Custom interface View

public interface BaseView {    <T> LifecycleTransformer<T> bindToLife();}

 

② Create a Helper class for countdown

Public final class RxHelper {private RxHelper () {throw new AssertionError ();}/*** countdown */public static Observable <Integer> countdown (int time) {if (time <0) {time = 0;} final int countTime = time; return Observable. interval (0, 1, TimeUnit. SECONDS ). map (new Func1 <Long, Integer> () {@ Override public Integer call (Long increaseTime) {return countTime-increaseTime. intValue ();}}). take (countTime + 1 ). subscribeOn (Schedulers. io ()). unsubscribeOn (Schedulers. io ()). subscribeOn (AndroidSchedulers. mainThread ()). observeOn (AndroidSchedulers. mainThread ());}}

 

③ Custom method: Implement Asynchronous Loading

Private void init () {RxHelper. countdown (5 ). compose (this. <Integer> bindToLife ()). subscribe (new Subscriber <Integer> () {@ Override public void onCompleted () {doSkip () ;}@ Override public void onError (Throwable e) {doSkip ();} @ Override public void onNext (Integer integer) {mBinding. sbSkip. setText ("Skip" + integer );}});}

 

④ Custom method: Achieve redirection

private void doSkip() {    if (!mIsSkip) {        mIsSkip = true;        finish();        startActivity(new Intent(SplashActivity.this, MainActivity.class));        overridePendingTransition(R.anim.hold, R.anim.zoom_in_exit);    }}

 

⑤ Set the topic style to full screen

<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">    <item name="colorPrimary">@color/colorPrimary</item>    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>    <item name="colorAccent">@color/colorAccent</item>    <item name="android:windowFullscreen">true</item></style>

 

Demo download: Countdown to App startup page

 

Follow my Sina Weibo account and check for the yellow V certification to obtain the latest Android development information.

Focus on science and technology critics, learn about science and technology, innovation, education, and maximize human wisdom and imagination!

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.