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

感谢大神: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
 * 

* 邮箱:[email protected] */ 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() { @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() { @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 } }); } }

你可能感兴趣的:(框架整理系列二十八(新手引导))