android 引导图engine类封装
2016-03-21 15:05
477 查看
暂时做的是全局点击区域,如果要做那种热点点击区域也是可以的哈,给我一个填充器就能产生一个view,既然能产生一个view,那么也就能产生一个引导.....附上我的原创封装代码:
GuidePageEngine.java<pre style="font-family: 宋体; font-size: 12pt; background-color: rgb(255, 255, 255);"><pre name="code" class="java">import android.app.Activity; import android.util.Log; import android.view.View; import android.view.ViewGroup; import android.view.ViewParent; import android.widget.FrameLayout; import android.widget.ImageView; import com.meimi.youganjue.interf.INotify; import java.util.ArrayList; /** * Created by luozheng on 16/1/14. */ public class GuidePageEngine { private static final String TAG = "GuidePageEngine"; private int nextResouceIndex =0; private ArrayList<Integer> lists; private Activity activity; int currentLayoutId; private INotify iNotify; private ImageView currentGuideImage; private ViewParent viewParent; /** * * @param activity 当前 * @param currentLayoutId 当前布局的顶级id * @param lists 引导图片集合 * @param iNotify 引导完毕的通知 */ public void init(final Activity activity,int currentLayoutId,ArrayList<Integer> lists,INotify iNotify){ this.activity =activity; this.lists =lists; this.currentLayoutId=currentLayoutId; this.iNotify =iNotify; } public void guide() { View view = activity.getWindow().getDecorView().findViewById(currentLayoutId); if(view==null){ new RuntimeException("找不到id对应的view,请给当前布局文件的顶级节点添加id为你传递过来的id"); } viewParent = view.getParent(); if (viewParent instanceof FrameLayout) { final FrameLayout frameLayout = (FrameLayout) viewParent; if (nextResouceIndex <lists.size()) {//设置了引导图片 currentGuideImage = new ImageView(activity); FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.FILL_PARENT); currentGuideImage.setLayoutParams(params); currentGuideImage.setScaleType(ImageView.ScaleType.CENTER_CROP); currentGuideImage.setImageResource(lists.get(nextResouceIndex)); currentGuideImage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { nextResouceIndex++; frameLayout.removeView(v); guide(); } }); frameLayout.addView(currentGuideImage);//添加引导图片 } else { //已经完毕了 Log.i(TAG,"引导完毕"); currentGuideImage=null; iNotify.onNotify(null); // SPUtils.setValue(getApplicationContext(), ParamConstant.STR_FIRST_RUN, false);//设为已引导 } }else{ Log.i(TAG,"无法引导! viewParent:"+ viewParent); } } /** * 当不小心弹出了引导但是要关闭 */ public void canelGuide(){ if(currentGuideImage!=null && viewParent!=null && currentGuideImage.getParent()!=null && viewParent instanceof ViewGroup){ ((ViewGroup) viewParent).removeView(currentGuideImage); currentGuideImage=null; } } public boolean guideIsShow(){ return currentGuideImage!=null; } }INotify.java 其实就是个回调接口
package space.qssq.interfaces;/*** Created by luozheng on 15/12/2.*/public interface INotify<T> {void onNotify(T param);}用法:第一步:给那个用的activity的顶级加一个id,其实你也可以给一个android 根id,叫啥来着,R.id.content_view???反正都可以的,只要不是线性布局等影响显示就好了.下面是直接添加图片资源id了。也就是你每给添加一个id,它都会new一个图片...
if(SPUtils.getValue(this, ParamConstant.SP_GUIDE_7_8_ChatActivity,false)){//sp的判断不用说了吧..<strong> GuidePageEngine guidePageEngine=new GuidePageEngine();</strong>ArrayList<Integer> listGuide=new ArrayList<>();listGuide.add(R.drawable.guide_7_friend);listGuide.add(R.drawable.guide_8_gift);guidePageEngine.init(ConversationActivity.this, R.id.my_content_view, listGuide, new INotify() {@Overridepublic void onNotify(Object o) {
//执行完毕了SPUtils.setValue(MainActivity.this,ParamConstant.SP_GUIDE_7_8_ChatActivity,true);}});}能用图片肯定直接给布局文件也是可以的,修改engine为直接读取布局资源,inflate一个view然后add进去就行了一样的道理..不过我们公司的太懒直接给整个屏幕的引导图片.
相关文章推荐
- android支付宝支付流程
- Google cardBoard Android API (六):DistortionRenderer
- Android动画 interpolator的用法
- Google cardBoard Android API (五):Distortion
- [原创]Android Lollipop (5.0) 原生代码 Settings 首页加载逻辑分析
- Android 动画机制 之 视图动画
- Android屏幕适配全攻略(最权威的官方适配指导)
- Android图片加载缓存框架Glide
- Google cardBoard Android API (四):Constants
- Google cardBoard Android API (三):CardboardView
- android ARM 汇编学习 —— hello world
- Fragment提交transaction导致state loss异常
- 获取svn版本号并替换AndroidManifest
- android 6.0权限管理特性
- Google cardBoard Android API (二):CardboardDeviceParams
- Android防止按钮被多次点击
- android SharedPreferences工具类
- android全屏和取消全屏 旋转屏幕
- 简单学习Android Socket的使用方法
- 自学Android第一步