Simply way to make your android code beautiful
来源:互联网 发布:天谕sabar捏脸数据图女 编辑:程序博客网 时间:2024/05/17 23:49
1. Think about the way that your can write your activity as below
@ScreenLayoutRes(R.layout.activity_login)public class MyActivity extends XXXActivity { @DataCenter MyDataCenter dc = MyDataCenter.getInstance(); @ActionCenter MyActionCenter ac = MyActionCenter.getInstance();}
2. Write your data center
public class MyDataCenter { private static MyDataCenter instance; @Presenter(MyActivity.class) @BindOnView(R.id.user) User user; @Presenter(MyActivity.class) @BindOnView(R.id.user_list) List<User> users; private MyDataCenter() { user = new User(0); users = new ArrayList<>(); for (int i=0; i<10; i++) { users.add(new User(i+1)); } } public static MyDataCenter getInstance() { if (instance == null) { instance = new MyDataCenter(); } return instance; }}
3. Write your action center
public class MyActionCenter { private static MyActionCenter instance; @ActionHost(R.id.user) UserAction userAction; @ActionHost(R.id.go) TestButtonAction buttonAction; private MyActionCenter() {} public static MyActionCenter getInstance() { if (instance == null) { instance = new MyActionCenter(); } return instance; }}
3.1 implement your UserAction & TestButtonAction
public class UserAction extends CommonAction { @Action(ActionType.CLICK) @Override public void doo(Map<ActionParamsType, Object> params) { List omp = (List) params.get(ActionParamsType.ORIGIN_METHOD_PARAMS); Log.i("OMG_DEBUG", "You just clicked on : " + omp.get(0)); }}public class TestButtonAction extends CommonAction { @Action(ActionType.CLICK) @Override public void doo(Map<ActionParamsType, Object> params) { Toast.makeText((Context) params.get(ActionParamsType.ACTIVITY), "hello world", Toast.LENGTH_LONG).show(); }}
4. Finally, define you User class
public class User { @ShowOnView(R.id.tv_username) String name = "BetterWorld"; @ShowOnView(R.id.tv_age) int age = 23; public User(int i) { name += i; } @Override public String toString() { return "[" + name + ", " + age+ "]"; }}
5. At last, if you want to use this, please let me know. :)
You are welcomed to comment on this page..
0 0
- Simply way to make your android code beautiful
- 10 ways to make your code more Testable
- 10 Ways to Make Your Code More Testable
- 10 Ways to Make Your Code More Testable
- Way to Clean Code
- |Make Positive Thinking Your Way of Thinking_2694
- How to make order summary more beautiful?
- Retrospective--The Way To Make Things Better
- An Easy Way to Make a Treemap
- The Canonical Way to Update Your System
- 《Present Your Way To The Top》
- The best way to improve your listening
- How To Make Bootanimation (Base on Android Source Code)
- How to improve quality and syntax of your Android code
- Way to Android
- The best way to delete code
- Beautiful Code
- How to make your spec professional
- 别以为真懂Openstack: 虚拟机创建的50个步骤和100个知识点
- quartz集群
- codeforces-546D-Soldier and Number Game【思维】(求质因子个数)
- 【GDOI2017模拟8.11】选择
- 机器学习入门读书笔记四(k-近邻算法 kNN) 下
- Simply way to make your android code beautiful
- mysql主从复制和读写分离
- Android开发之基于RecyclerView通用适配打造城市导航列表
- PAT甲级练习题A1020. Tree Traversals (25)
- 消息推送
- 【JZOJ 4694】【HDU 5283】火神的鱼
- 图像局部特征点检测算法综述
- jquery效果
- RxJava新手入门之三 关于事件转换之单对单map和单对多转换flatmap