|
@@ -0,0 +1,305 @@
|
|
|
|
|
+package com.sheep.gamegroup.module.guide;
|
|
|
|
|
+
|
|
|
|
|
+import android.app.Activity;
|
|
|
|
|
+import android.content.Context;
|
|
|
|
|
+import android.content.SharedPreferences;
|
|
|
|
|
+import android.graphics.Canvas;
|
|
|
|
|
+import android.graphics.Color;
|
|
|
|
|
+import android.graphics.DashPathEffect;
|
|
|
|
|
+import android.graphics.Paint;
|
|
|
|
|
+import android.graphics.RectF;
|
|
|
|
|
+import android.support.constraint.solver.widgets.Rectangle;
|
|
|
|
|
+import android.util.Log;
|
|
|
|
|
+import android.view.Gravity;
|
|
|
|
|
+import android.view.View;
|
|
|
|
|
+import android.view.ViewGroup;
|
|
|
|
|
+import android.view.animation.AlphaAnimation;
|
|
|
|
|
+import android.view.animation.Animation;
|
|
|
|
|
+import android.widget.TextView;
|
|
|
|
|
+import android.widget.Toast;
|
|
|
|
|
+
|
|
|
|
|
+import com.app.hubert.guide.NewbieGuide;
|
|
|
|
|
+import com.app.hubert.guide.core.Builder;
|
|
|
|
|
+import com.app.hubert.guide.core.Controller;
|
|
|
|
|
+import com.app.hubert.guide.listener.OnGuideChangedListener;
|
|
|
|
|
+import com.app.hubert.guide.listener.OnHighlightDrewListener;
|
|
|
|
|
+import com.app.hubert.guide.listener.OnLayoutInflatedListener;
|
|
|
|
|
+import com.app.hubert.guide.listener.OnPageChangedListener;
|
|
|
|
|
+import com.app.hubert.guide.model.GuidePage;
|
|
|
|
|
+import com.app.hubert.guide.model.HighLight;
|
|
|
|
|
+import com.app.hubert.guide.model.HighlightOptions;
|
|
|
|
|
+import com.app.hubert.guide.model.RelativeGuide;
|
|
|
|
|
+import com.kfzs.duanduan.cardview.ScreenUtil;
|
|
|
|
|
+import com.sheep.gamegroup.event.BigEvent;
|
|
|
|
|
+import com.sheep.gamegroup.greendao.DDProviderHelper;
|
|
|
|
|
+import com.sheep.gamegroup.module.game.fragment.FgtGameCenter;
|
|
|
|
|
+import com.sheep.gamegroup.module.home.fragment.FgtHome;
|
|
|
|
|
+import com.sheep.gamegroup.module.home.fragment.FgtMainHeader;
|
|
|
|
|
+import com.sheep.gamegroup.util.DataUtil;
|
|
|
|
|
+import com.sheep.gamegroup.util.Jump2View;
|
|
|
|
|
+import com.sheep.gamegroup.view.activity.ActMain;
|
|
|
|
|
+import com.sheep.gamegroup.view.fragment.FgtPersonalCenter;
|
|
|
|
|
+import com.sheep.gamegroup.view.fragment.FgtSmallSheep;
|
|
|
|
|
+import com.sheep.jiuyan.samllsheep.R;
|
|
|
|
|
+
|
|
|
|
|
+import org.greenrobot.eventbus.EventBus;
|
|
|
|
|
+import org.xutils.common.util.LogUtil;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.Arrays;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+
|
|
|
|
|
+import static com.sheep.gamegroup.event.EventTypes.GUIDE_NEXT_NEXT;
|
|
|
|
|
+
|
|
|
|
|
+public class NewbieGuideHelper {
|
|
|
|
|
+
|
|
|
|
|
+ private final static String TAG = "NewbieGuide";
|
|
|
|
|
+
|
|
|
|
|
+ public final static int GUIDE_HOME = 0;
|
|
|
|
|
+ public final static int GUIDE_GAME = 1;
|
|
|
|
|
+ public final static int GUIDE_USER = 2;
|
|
|
|
|
+ public final static int GUIDE_FAQ = 3;
|
|
|
|
|
+
|
|
|
|
|
+ private Activity mActivity;
|
|
|
|
|
+ private Animation enterAnimation;
|
|
|
|
|
+ private Animation exitAnimation;
|
|
|
|
|
+
|
|
|
|
|
+ public NewbieGuideHelper(Activity mActivity) {
|
|
|
|
|
+ this.mActivity = mActivity;
|
|
|
|
|
+ enterAnimation = new AlphaAnimation(0f, 1f);
|
|
|
|
|
+ enterAnimation.setDuration(300);
|
|
|
|
|
+ enterAnimation.setFillAfter(true);
|
|
|
|
|
+
|
|
|
|
|
+ exitAnimation = new AlphaAnimation(1f, 0f);
|
|
|
|
|
+ exitAnimation.setDuration(300);
|
|
|
|
|
+ exitAnimation.setFillAfter(true);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void show(int type) {
|
|
|
|
|
+ String label = DataUtil.getInstance().getUserId()+ "_page_" + type;
|
|
|
|
|
+ if (isShowed(label)) return;
|
|
|
|
|
+ showed(label);
|
|
|
|
|
+ List<GuidePage> pages = null;
|
|
|
|
|
+ if (type == GUIDE_HOME) {
|
|
|
|
|
+ pages = Arrays.asList(getPage1(), getPage2(), getPage3(), getPage4());
|
|
|
|
|
+ } else if (type == GUIDE_USER) {
|
|
|
|
|
+ pages = Arrays.asList(getPage5(), getPage6());
|
|
|
|
|
+ } else if (type == GUIDE_FAQ) {
|
|
|
|
|
+ pages = Arrays.asList(getPage7());
|
|
|
|
|
+ } else if (type == GUIDE_GAME) {
|
|
|
|
|
+ pages = Arrays.asList(getPage8(), getPage9(), getPage10());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ Builder builder = NewbieGuide.with(mActivity)
|
|
|
|
|
+ .setLabel(label)//设置引导层标示区分不同引导层,必传!否则报错
|
|
|
|
|
+ .setOnGuideChangedListener(new OnGuideChangedListener() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onShowed(Controller controller) {
|
|
|
|
|
+ LogUtil.i(TAG + " onShowed: ");
|
|
|
|
|
+ //引导层显示
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onRemoved(Controller controller) {
|
|
|
|
|
+ Log.e(TAG, "NewbieGuide onRemoved: ");
|
|
|
|
|
+ if (type == GUIDE_HOME) {
|
|
|
|
|
+ Jump2View.getInstance().goPersonnalCenterView(mActivity, null);
|
|
|
|
|
+ } else if (type == GUIDE_USER) {
|
|
|
|
|
+ FgtPersonalCenter.scrollToBottom(mActivity);
|
|
|
|
|
+ } else if (type == GUIDE_FAQ) {
|
|
|
|
|
+ EventBus.getDefault().post(new BigEvent(GUIDE_NEXT_NEXT));
|
|
|
|
|
+ mActivity.finish();
|
|
|
|
|
+ } else if (type == GUIDE_GAME) {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ .setOnPageChangedListener(new OnPageChangedListener() {
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onPageChanged(int page) {
|
|
|
|
|
+ //引导页切换,page为当前页位置,从0开始
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ .alwaysShow(true);//是否每次都显示引导层,默认false,只显示一次
|
|
|
|
|
+ for (GuidePage page : pages) {
|
|
|
|
|
+ builder.addGuidePage(page);
|
|
|
|
|
+ }
|
|
|
|
|
+ builder.show();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private GuidePage getPage1() {
|
|
|
|
|
+ RelativeGuide relativeGuide = new RelativeGuide(R.layout.newbie_guide_1, Gravity.RIGHT, 0) {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void offsetMargin(MarginInfo marginInfo, ViewGroup viewGroup, View view) {
|
|
|
|
|
+ marginInfo.leftMargin -= ScreenUtil.dip2px(mActivity, 30);
|
|
|
|
|
+ marginInfo.topMargin += ScreenUtil.dip2px(mActivity, 20);
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ return GuidePage.newInstance()//创建一个实例
|
|
|
|
|
+ .addHighLightWithOptions(ActMain.tabBtn1.get(), HighLight.Shape.CIRCLE, new HighlightOptions.Builder().useMaxSize(false).build())
|
|
|
|
|
+ .addHighLightWithOptions(FgtSmallSheep.listRef.get(), HighLight.Shape.OVAL, new HighlightOptions.Builder().setRelativeGuide(relativeGuide).useMaxSize(false).setOffsetWidth(0.25f).setOffsetHeight(0.5f).build())
|
|
|
|
|
+ .setEnterAnimation(enterAnimation)//进入动画
|
|
|
|
|
+ .setExitAnimation(exitAnimation);//退出动画
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private GuidePage getPage2() {
|
|
|
|
|
+ RelativeGuide relativeGuide1 = new RelativeGuide(R.layout.newbie_guide_2_1, Gravity.RIGHT, 0) {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void offsetMargin(MarginInfo marginInfo, ViewGroup viewGroup, View view) {
|
|
|
|
|
+ marginInfo.leftMargin -= ScreenUtil.dip2px(mActivity, 70);
|
|
|
|
|
+ marginInfo.topMargin -= ScreenUtil.dip2px(mActivity, 40);
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ RelativeGuide relativeGuide2 = new RelativeGuide(R.layout.newbie_guide_2_2, Gravity.LEFT, 0) {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void offsetMargin(MarginInfo marginInfo, ViewGroup viewGroup, View view) {
|
|
|
|
|
+ marginInfo.rightMargin -= ScreenUtil.dip2px(mActivity, 40);
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ RelativeGuide relativeGuide3 = new RelativeGuide(R.layout.newbie_guide_2_3, Gravity.TOP, 0) {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void offsetMargin(MarginInfo marginInfo, ViewGroup viewGroup, View view) {
|
|
|
|
|
+ marginInfo.bottomMargin -= ScreenUtil.dip2px(mActivity, 8);
|
|
|
|
|
+ marginInfo.leftMargin += ScreenUtil.dip2px(mActivity, 50);
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ return GuidePage.newInstance()//创建一个实例
|
|
|
|
|
+ .addHighLightWithOptions(ActMain.tabBtn1.get(), HighLight.Shape.CIRCLE, new HighlightOptions.Builder().setRelativeGuide(relativeGuide3).useMaxSize(false).build())
|
|
|
|
|
+ .addHighLightWithOptions(FgtMainHeader.msgRef.get(), HighLight.Shape.CIRCLE, new HighlightOptions.Builder().setRelativeGuide(relativeGuide2).useMaxSize(true).build())
|
|
|
|
|
+ .addHighLightWithOptions(FgtHome.newsRef.get(), HighLight.Shape.OVAL, new HighlightOptions.Builder().setRelativeGuide(relativeGuide1).useMaxSize(false).setOffsetLeft(0.2f).setOffsetWidth(0.6f).build())
|
|
|
|
|
+ .setEnterAnimation(enterAnimation)//进入动画
|
|
|
|
|
+ .setExitAnimation(exitAnimation);//退出动画;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private GuidePage getPage3() {
|
|
|
|
|
+ RelativeGuide relativeGuide = new RelativeGuide(R.layout.newbie_guide_3_1, Gravity.RIGHT, 0) {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void offsetMargin(MarginInfo marginInfo, ViewGroup viewGroup, View view) {
|
|
|
|
|
+ marginInfo.leftMargin -= ScreenUtil.dip2px(mActivity, 50);
|
|
|
|
|
+ marginInfo.topMargin -= ScreenUtil.dip2px(mActivity, 4);
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ return GuidePage.newInstance()//创建一个实例
|
|
|
|
|
+ .addHighLightWithOptions(ActMain.tabBtn1.get(), HighLight.Shape.CIRCLE, new HighlightOptions.Builder().useMaxSize(false).build())
|
|
|
|
|
+ .addHighLightWithOptions(FgtMainHeader.faceRef.get(), HighLight.Shape.CIRCLE, new HighlightOptions.Builder().setRelativeGuide(relativeGuide).useMaxSize(true).build())
|
|
|
|
|
+ .setLayoutRes(R.layout.newbie_guide_3_2)
|
|
|
|
|
+ .setEnterAnimation(enterAnimation)//进入动画
|
|
|
|
|
+ .setExitAnimation(exitAnimation);//退出动画
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private GuidePage getPage4() {
|
|
|
|
|
+ RelativeGuide relativeGuide = new RelativeGuide(R.layout.newbie_guide_4, Gravity.LEFT, 0) {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void offsetMargin(MarginInfo marginInfo, ViewGroup viewGroup, View view) {
|
|
|
|
|
+ marginInfo.rightMargin -= ScreenUtil.dip2px(mActivity, 20);
|
|
|
|
|
+ marginInfo.topMargin += ScreenUtil.dip2px(mActivity, 10);
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ int round = ScreenUtil.dip2px(mActivity, 20);
|
|
|
|
|
+ return GuidePage.newInstance()//创建一个实例
|
|
|
|
|
+ .addHighLightWithOptions(ActMain.tabBtn1.get(), HighLight.Shape.CIRCLE, new HighlightOptions.Builder().useMaxSize(false).build())
|
|
|
|
|
+ .addHighLightWithOptions(FgtHome.meetRef.get(), HighLight.Shape.ROUND_RECTANGLE, round, 0, new HighlightOptions.Builder().setRelativeGuide(relativeGuide).build())
|
|
|
|
|
+ .setEnterAnimation(enterAnimation)//进入动画
|
|
|
|
|
+ .setExitAnimation(exitAnimation);//退出动画
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private GuidePage getPage5() {
|
|
|
|
|
+ RelativeGuide relativeGuide = new RelativeGuide(R.layout.newbie_guide_5, Gravity.BOTTOM, 0) {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void offsetMargin(MarginInfo marginInfo, ViewGroup viewGroup, View view) {
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ return GuidePage.newInstance()//创建一个实例
|
|
|
|
|
+ .addHighLightWithOptions(FgtPersonalCenter.myMoneyRef.get(), HighLight.Shape.RECTANGLE, new HighlightOptions.Builder().setRelativeGuide(relativeGuide).build())
|
|
|
|
|
+ .setEnterAnimation(enterAnimation)//进入动画
|
|
|
|
|
+ .setExitAnimation(exitAnimation);//退出动画
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private GuidePage getPage6() {
|
|
|
|
|
+ RelativeGuide relativeGuide = new RelativeGuide(R.layout.newbie_guide_6, Gravity.TOP, 0) {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void offsetMargin(MarginInfo marginInfo, ViewGroup viewGroup, View view) {
|
|
|
|
|
+ marginInfo.bottomMargin -= ScreenUtil.dip2px(mActivity, 100);
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ return GuidePage.newInstance()//创建一个实例
|
|
|
|
|
+ .addHighLightWithOptions(FgtPersonalCenter.accountDetailRef.get(), HighLight.Shape.RECTANGLE, new HighlightOptions.Builder().setRelativeGuide(relativeGuide).build())
|
|
|
|
|
+ .setEnterAnimation(enterAnimation)//进入动画
|
|
|
|
|
+ .setExitAnimation(exitAnimation);//退出动画
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private GuidePage getPage7() {
|
|
|
|
|
+ RelativeGuide relativeGuide = new RelativeGuide(R.layout.newbie_guide_7, Gravity.TOP, 0);
|
|
|
|
|
+ return GuidePage.newInstance()//创建一个实例
|
|
|
|
|
+ .addHighLightWithOptions(FgtPersonalCenter.fagRef.get(), HighLight.Shape.RECTANGLE, new HighlightOptions.Builder().setRelativeGuide(relativeGuide).build())
|
|
|
|
|
+ .setEnterAnimation(enterAnimation)//进入动画
|
|
|
|
|
+ .setExitAnimation(exitAnimation);//退出动画
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private GuidePage getPage8() {
|
|
|
|
|
+ RelativeGuide relativeGuide1 = new RelativeGuide(R.layout.newbie_guide_8_1, Gravity.BOTTOM, 0) {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void offsetMargin(MarginInfo marginInfo, ViewGroup viewGroup, View view) {
|
|
|
|
|
+ marginInfo.topMargin -= ScreenUtil.dip2px(mActivity, 40);
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ RelativeGuide relativeGuide2 = new RelativeGuide(R.layout.newbie_guide_8_2, Gravity.BOTTOM, 0) {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void offsetMargin(MarginInfo marginInfo, ViewGroup viewGroup, View view) {
|
|
|
|
|
+ marginInfo.leftMargin -= ScreenUtil.dip2px(mActivity, 43);
|
|
|
|
|
+ marginInfo.topMargin -= ScreenUtil.dip2px(mActivity, 36);
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ return GuidePage.newInstance()//创建一个实例
|
|
|
|
|
+ .addHighLightWithOptions(ActMain.tabBtn2.get(), HighLight.Shape.CIRCLE, new HighlightOptions.Builder().useMaxSize(false).build())
|
|
|
|
|
+ .addHighLightWithOptions(FgtMainHeader.downloadRef.get(), HighLight.Shape.CIRCLE, new HighlightOptions.Builder().setRelativeGuide(relativeGuide2).build())
|
|
|
|
|
+ .addHighLightWithOptions(FgtGameCenter.getTab(0), HighLight.Shape.OVAL, new HighlightOptions.Builder().setRelativeGuide(relativeGuide1).build())
|
|
|
|
|
+ .setLayoutRes(R.layout.newbie_guide_8_3)
|
|
|
|
|
+ .setEnterAnimation(enterAnimation)//进入动画
|
|
|
|
|
+ .setExitAnimation(exitAnimation);//退出动画
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private GuidePage getPage9() {
|
|
|
|
|
+ RelativeGuide relativeGuide = new RelativeGuide(R.layout.newbie_guide_9, Gravity.BOTTOM, 0) {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void offsetMargin(MarginInfo marginInfo, ViewGroup viewGroup, View view) {
|
|
|
|
|
+ marginInfo.topMargin -= ScreenUtil.dip2px(mActivity, 40);
|
|
|
|
|
+ marginInfo.leftMargin -= ScreenUtil.dip2px(mActivity, 50);
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ return GuidePage.newInstance()//创建一个实例
|
|
|
|
|
+ .addHighLightWithOptions(ActMain.tabBtn2.get(), HighLight.Shape.CIRCLE, new HighlightOptions.Builder().useMaxSize(false).build())
|
|
|
|
|
+ .addHighLightWithOptions(FgtGameCenter.getTab(1), HighLight.Shape.OVAL, new HighlightOptions.Builder().setRelativeGuide(relativeGuide).build())
|
|
|
|
|
+ .setEnterAnimation(enterAnimation)//进入动画
|
|
|
|
|
+ .setExitAnimation(exitAnimation);//退出动画
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private GuidePage getPage10() {
|
|
|
|
|
+ RelativeGuide relativeGuide = new RelativeGuide(R.layout.newbie_guide_10, Gravity.LEFT, 0) {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void offsetMargin(MarginInfo marginInfo, ViewGroup viewGroup, View view) {
|
|
|
|
|
+ marginInfo.topMargin -= ScreenUtil.dip2px(mActivity, 50);
|
|
|
|
|
+ marginInfo.rightMargin -= ScreenUtil.dip2px(mActivity, 80);
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ return GuidePage.newInstance()//创建一个实例
|
|
|
|
|
+ .addHighLightWithOptions(ActMain.tabBtn2.get(), HighLight.Shape.CIRCLE, new HighlightOptions.Builder().useMaxSize(false).build())
|
|
|
|
|
+ .addHighLightWithOptions(FgtGameCenter.getTab(3), HighLight.Shape.OVAL, new HighlightOptions.Builder().setRelativeGuide(relativeGuide).build())
|
|
|
|
|
+ .setEnterAnimation(enterAnimation)//进入动画
|
|
|
|
|
+ .setExitAnimation(exitAnimation);//退出动画
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private boolean isShowed(String page) {
|
|
|
|
|
+ SharedPreferences sp = mActivity.getSharedPreferences("newbie_guide", Context.MODE_PRIVATE);
|
|
|
|
|
+ return sp.getBoolean(page, false);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void showed(String page) {
|
|
|
|
|
+ SharedPreferences sp = mActivity.getSharedPreferences("newbie_guide", Context.MODE_PRIVATE);
|
|
|
|
|
+ SharedPreferences.Editor editor = sp.edit();
|
|
|
|
|
+ editor.putBoolean("page", true);
|
|
|
|
|
+ editor.commit();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|