高亮指导层,温馨的提示界面,优雅的提示方式 !直接用即可,首次亮相!

来源:互联网 发布:js e.target.result 编辑:程序博客网 时间:2024/04/30 21:26

惯例:先上图后说话,谢谢各位伙伴的支持! 有你们是我的福分!

             欢迎一起讨论,学习,QQ:732258496  微信:18725684434


一、在activity中调用方法

<span style="font-size:12px;"> HighLightGuidePage highLightGuidePage = new HighLightGuidePage(ctx);                    highLightGuidePage.addHighLightByCircleTargeView(mTitleBarFragment.getOpBtn(), R.layout.view_team_member_guide_page,                            getResources().getColor(R.color.orange), new HighLightGuidePage.OnPosCallback() {                                @Override                                public void getPos(float rightMargin, float bottomMargin, RectF rectF, HighLightGuidePage.MarginInfo marginInfo) {                                }                            });                    highLightGuidePage.setClickCallback(new HighLightGuidePage.OnClickCallback() {                        @Override                        public void onClick() {                            SPUtil.putBoolean(Constants.GuidePage.SP_TEAMMEMBERHALLACTIVITY_IS_WATCH_GUIDE_PAGE, false);                        }                    });                    highLightGuidePage.show();</span>
二、高亮层公共类

<span style="font-size:12px;">public class HighLightGuidePage {    public static class ViewPosInfo {        public int layoutId = -1;        public RectF rectF;        public MarginInfo marginInfo;        public View view;        public OnPosCallback onPosCallback;        public boolean isCircleTip = false;        public int circleDashLineColor = android.R.color.transparent;    }    public static class MarginInfo {        public float topMargin;        public float leftMargin;        public float rightMargin;        public float bottomMargin;    }    public static interface OnPosCallback {        void getPos(float rightMargin, float bottomMargin, RectF rectF, MarginInfo marginInfo);    }    public static interface OnClickCallback {        void onClick();    }    private View mAnchor;    private List<ViewPosInfo> mViewRects;    private Context mContext;    private HightLightView mHightLightView;    private OnClickCallback clickCallback;    private boolean intercept = true;    private boolean shadow = true;    private int maskColor = 0xCC000000;    public HighLightGuidePage(Context context) {        mContext = context;        mViewRects = new ArrayList<ViewPosInfo>();        mAnchor = ((Activity) mContext).findViewById(android.R.id.content);    }    public HighLightGuidePage anchor(View anchor) {        mAnchor = anchor;        return this;    }    public HighLightGuidePage intercept(boolean intercept) {        this.intercept = intercept;        return this;    }    public HighLightGuidePage shadow(boolean shadow) {        this.shadow = shadow;        return this;    }    public HighLightGuidePage maskColor(int maskColor) {        this.maskColor = maskColor;        return this;    }    public HighLightGuidePage addHighLight(int viewId, int decorLayoutId, OnPosCallback onPosCallback) {        ViewGroup parent = (ViewGroup) mAnchor;        View view = parent.findViewById(viewId);        addHighLight(view, decorLayoutId, onPosCallback);        return this;    }    public void updateInfo() {        ViewGroup parent = (ViewGroup) mAnchor;        for (HighLightGuidePage.ViewPosInfo viewPosInfo : mViewRects) {            RectF rect = getRectF(parent, viewPosInfo.view);//            if (!rect.equals(viewPosInfo.rectF))//TODO bug dismissed...fc...            if (rect != null) {                viewPosInfo.rectF = rect;                viewPosInfo.onPosCallback.getPos(parent.getWidth() - rect.right, parent.getHeight() - rect.bottom, rect, viewPosInfo.marginInfo);            }        }    }    public HighLightGuidePage addHighLight(int decorLayoutId, OnPosCallback onPosCallback) {        addHighLight(null, decorLayoutId, onPosCallback);        return this;    }    public HighLightGuidePage addHighLight(View view, int decorLayoutId, OnPosCallback onPosCallback) {        ViewGroup parent = (ViewGroup) mAnchor;        RectF rect = getRectF(parent, view);        ViewPosInfo viewPosInfo = new ViewPosInfo();        viewPosInfo.layoutId = decorLayoutId;        viewPosInfo.rectF = rect;        viewPosInfo.view = view;        if (onPosCallback == null && decorLayoutId != -1) {            throw new IllegalArgumentException("onPosCallback can not be null.");        }        MarginInfo marginInfo = new MarginInfo();        marginInfo.topMargin = mAnchor.getTop();        if (onPosCallback != null && rect != null) {            marginInfo.topMargin = rect.top + rect.height();//默认在view的下面            onPosCallback.getPos(parent.getWidth() - rect.right, parent.getHeight() - rect.bottom, rect, marginInfo);        }        viewPosInfo.marginInfo = marginInfo;        viewPosInfo.onPosCallback = onPosCallback;        mViewRects.add(viewPosInfo);        return this;    }    public HighLightGuidePage addHighLightByCircleTargeView(int viewId, int decorLayoutId, int circleDashLineColor, OnPosCallback onPosCallback) {        ViewGroup parent = (ViewGroup) mAnchor;        View view = parent.findViewById(viewId);        addHighLightByCircleTargeView(view, decorLayoutId, circleDashLineColor, onPosCallback);        return this;    }    public HighLightGuidePage addHighLightByCircleTargeView(View view, int decorLayoutId, int circleDashLineColor, OnPosCallback onPosCallback) {        ViewGroup parent = (ViewGroup) mAnchor;        RectF rect = getRectF(parent, view);        ViewPosInfo viewPosInfo = new ViewPosInfo();        viewPosInfo.circleDashLineColor = circleDashLineColor;        viewPosInfo.isCircleTip = true;        viewPosInfo.layoutId = decorLayoutId;        viewPosInfo.rectF = rect;        viewPosInfo.view = view;        if (onPosCallback == null && decorLayoutId != -1) {            throw new IllegalArgumentException("onPosCallback can not be null.");        }        MarginInfo marginInfo = new MarginInfo();        marginInfo.topMargin = mAnchor.getTop();        if (onPosCallback != null && rect != null) {            marginInfo.topMargin = rect.top + rect.height();//默认在view的下面            onPosCallback.getPos(parent.getWidth() - rect.right, parent.getHeight() - rect.bottom, rect, marginInfo);        }        viewPosInfo.marginInfo = marginInfo;        viewPosInfo.onPosCallback = onPosCallback;        mViewRects.add(viewPosInfo);        return this;    }    public HighLightGuidePage addHighLightByCircleTargeView(int viewId, int decorLayoutId, OnPosCallback onPosCallback) {        addHighLightByCircleTargeView(viewId, decorLayoutId, 0, onPosCallback);        return this;    }    public HighLightGuidePage addHighLightByCircleTargeView(View view, int decorLayoutId, OnPosCallback onPosCallback) {        addHighLightByCircleTargeView(view, decorLayoutId, 0, onPosCallback);        return this;    }    private RectF getRectF(View parent, View view) {        Rect rect = ViewUtils.getLocationInView(parent, view);        if (rect == null) {            return null;        }        return new RectF(rect);    }    // 一个场景可能有多个步骤的高亮。一个步骤完成之后再进行下一个步骤的高亮    // 添加点击事件,将每次点击传给应用逻辑    public HighLightGuidePage setClickCallback(OnClickCallback clickCallback) {        this.clickCallback = clickCallback;        return this;    }    public void show() {        if (mHightLightView != null) return;        HightLightView hightLightView = new HightLightView(mContext, this, maskColor, shadow, mViewRects);        if (mAnchor.getClass().getSimpleName().equals("FrameLayout")) {            ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams                    (ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);            ((ViewGroup) mAnchor).addView(hightLightView, ((ViewGroup) mAnchor).getChildCount(), lp);        } else {            FrameLayout frameLayout = new FrameLayout(mContext);            ViewGroup parent = (ViewGroup) mAnchor.getParent();            parent.removeView(mAnchor);            parent.addView(frameLayout, mAnchor.getLayoutParams());            ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams                    (ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);            frameLayout.addView(mAnchor, lp);            frameLayout.addView(hightLightView);        }        if (intercept) {            hightLightView.setOnClickListener(new View.OnClickListener() {                @Override                public void onClick(View v) {                    remove();                    if (clickCallback != null) {                        clickCallback.onClick();                    }                }            });        }        mHightLightView = hightLightView;    }    public void remove() {        if (mHightLightView == null) return;        ViewGroup parent = (ViewGroup) mHightLightView.getParent();        if (parent instanceof RelativeLayout || parent instanceof FrameLayout) {            parent.removeView(mHightLightView);        } else {            parent.removeView(mHightLightView);            View origin = parent.getChildAt(0);            ViewGroup graParent = (ViewGroup) parent.getParent();            graParent.removeView(parent);            graParent.addView(origin, parent.getLayoutParams());        }        mHightLightView = null;    }}</span>





0 0