MVP模式
来源:互联网 发布:拉圈圈助手源码 编辑:程序博客网 时间:2024/06/06 17:09
View: 对应于Activity,负责View的绘制以及与用户交互
Model :依然是业务逻辑和实体模型
Presenter: 负责完成View于Model间的交互
view 部分:
SplashView代码:
public interface SplashView { void navigateToHomePage(); void animateBackgroundImage(Animation animation); void initView(int resourceId);}
MainActivity代码:
package com.xl.test.view;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.view.animation.Animation;import android.widget.ImageView;import android.widget.Toast;import com.xl.test.R;import com.xl.test.presenter.Presenter;import com.xl.test.presenter.SplashPresenterImpl;import butterknife.BindView;import butterknife.ButterKnife;public class MainActivity extends AppCompatActivity implements SplashView { @BindView(R.id.splash_image) ImageView splashImage; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButterKnife.bind(this); Presenter presenter = new SplashPresenterImpl(this, this); presenter.initialized(); } @Override public void navigateToHomePage() { Toast.makeText(this, "结束", 1).show(); } @Override public void animateBackgroundImage(Animation animation) { splashImage.startAnimation(animation); } @Override public void initView(int resourceId) { splashImage.setImageResource(resourceId); }}
model部分:
SplashInteractor代码:
package com.xl.test.model;import android.content.Context;import android.view.animation.Animation;/** * Created by hushendian on 2017/7/19. */public interface SplashInteractor { int getBackgroundImageResID(); Animation getBackgroudImageAnimation(Context context);}
SplashInteraatorImpl代码:
package com.xl.test.model;import android.content.Context;import android.view.animation.Animation;import android.view.animation.AnimationUtils;import com.xl.test.R;/** * Created by hushendian on 2017/7/19. */public class SplashInteractorImpl implements SplashInteractor { @Override public int getBackgroundImageResID() { return R.mipmap.morning; } @Override public Animation getBackgroudImageAnimation(Context context) { return AnimationUtils.loadAnimation(context, R.anim.splash); }}
presenter部分:
Presenter代码:
package com.xl.test.presenter;/** * Created by hushendian on 2017/7/19. */public interface Presenter { void initialized();}
SplashPresenterImpl代码:
package com.xl.test.presenter;import android.content.Context;import android.view.animation.Animation;import com.xl.test.model.SplashInteractorImpl;import com.xl.test.view.SplashView;/** * Created by hushendian on 2017/7/19. */public class SplashPresenterImpl implements Presenter { Context mContext; SplashView mSplashView; SplashInteractorImpl mSplashInteractor; public SplashPresenterImpl(Context context, SplashView splashView) { if (null == splashView) { throw new IllegalArgumentException("Constructor's parameters must not be Null"); } mContext = context; mSplashView = splashView; mSplashInteractor = new SplashInteractorImpl(); } @Override public void initialized() { mSplashView.initView(mSplashInteractor.getBackgroundImageResID()); Animation animation = mSplashInteractor.getBackgroudImageAnimation(mContext); animation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { mSplashView.navigateToHomePage(); } @Override public void onAnimationRepeat(Animation animation) { } }); mSplashView.animateBackgroundImage(animation); }}
github地址:https://github.com/hushendian/GitWork.git
阅读全文
0 0
- MVP模式
- MVP模式
- MVP模式
- MVP模式
- MVP模式
- MVP模式
- MVP模式
- mvp模式
- MVP模式
- mvp模式
- MVP模式
- MVP模式
- mvp模式
- MVP模式
- mvp模式
- MVP模式
- mvp模式
- MVP模式
- jdbc batch批量处理与非批量的比较
- 计算排列组合程序片段
- vue2.0使用swiper组件实现轮播
- 设计一个算法,计算出n阶乘中尾部零的个数
- 24. Swap Nodes in Pairs
- MVP模式
- excel入门,如何玩转excel,你早该这么玩Excel笔记10
- iOS常用第三方库大全
- 赋予某个用户拥有dba(超级管理员权限)
- 解决Dagger2与ButterKnife冲突
- spring与mybatis三种整合方法
- debian系统下安装ssh
- bootstrap datepicker使用中遇到的小问题
- SPOJ 1557 Can you answer these queries II(离线处理+线段树求历史最大)