美文网首页
框架整理系列二十八(新手引导)

框架整理系列二十八(新手引导)

作者: I_Gisvity | 来源:发表于2017-08-04 16:30 被阅读0次

感谢大神:https://github.com/TakuSemba/Spotlight

GuidUtil.java

import android.app.Activity;
import android.view.View;
import android.view.animation.DecelerateInterpolator;

import com.blankj.utilcode.util.SPUtils;
import com.takusemba.spotlight.OnSpotlightEndedListener;
import com.takusemba.spotlight.OnSpotlightStartedListener;
import com.takusemba.spotlight.SimpleTarget;
import com.takusemba.spotlight.Spotlight;

import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.functions.Consumer;
import io.reactivex.functions.Function;
import io.reactivex.schedulers.Schedulers;

/**
 * 作者:IGisvity on 2017/8/4 15:57
 * <p>
 * 邮箱:double0zhou@126.com
 */

public class GuidUtil {
    public static void addGuid(final Activity activity, final View view, final String title, final String description) {
        final String viewTag = activity.getClass().getSimpleName() + view.getId();
        if (SPUtils.getInstance().getBoolean(viewTag, false))
            return;
        Flowable.just(view)
                .map(new Function<View, SimpleTarget>() {
                    @Override
                    public SimpleTarget apply(@NonNull View v) throws Exception {
                        Thread.sleep(1000);
                        SimpleTarget thirdTarget = new SimpleTarget.Builder(activity)
                                .setTitle(title)
                                .setDescription(description)
                                .setPoint(v)
                                .setRadius(view.getWidth()>0?(view.getWidth()>view.getHeight()?view.getWidth()/2:view.getHeight()/2):100)
                                .build();
                        return thirdTarget;
                    }
                })
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<SimpleTarget>() {
                    @Override
                    public void accept(@NonNull SimpleTarget simpleTarget) throws Exception {
                        Spotlight.with(activity)
                                .setDuration(800L) // duration of Spotlight emerging and disappearing in ms
                                .setAnimation(new DecelerateInterpolator(2f)) // animation of Spotlight
                                .setTargets(simpleTarget) // set targets. see below for more info
                                .setOnSpotlightStartedListener(new OnSpotlightStartedListener() { // callback when Spotlight starts
                                    @Override
                                    public void onStarted() {
//                                        Toast.makeText(LoginActivity.this, "spotlight is started", Toast.LENGTH_SHORT).show();
                                    }
                                })
                                .setOnSpotlightEndedListener(new OnSpotlightEndedListener() { // callback when Spotlight ends
                                    @Override
                                    public void onEnded() {
//                                        Toast.makeText(LoginActivity.this, "spotlight is ended", Toast.LENGTH_SHORT).show();
                                        SPUtils.getInstance().put(viewTag, true);
                                    }
                                })
                                .start(); // start Spotlight
                    }
                });

    }
}



相关文章

网友评论

      本文标题:框架整理系列二十八(新手引导)

      本文链接:https://www.haomeiwen.com/subject/qefblxtx.html