xUtils源码阅读(1)- x
来源:互联网 发布:淘宝客服怎么应对客户 编辑:程序博客网 时间:2024/06/11 23:50
这次阅读xUtils我们从上到下的方式读。
先看看这个这么另类的类x吧。
很简单,就是对整个项目的一个整体功能的总括。
共包括四部分:
1、数据库
2、Http访问
3、图片管理
4、view注入
5、任务管理(以上各项在执行的时候都要包装成一个个的任务执行)
源码:
/** * Created by wyouflf on 15/6/10. * 任务控制中心, http, image, db, view注入等接口的入口. * 需要在在application的onCreate中初始化: x.Ext.init(this); */public final class x {//静态类,其方法都是静态的。 private x() {//防止构造对象 } public static boolean isDebug() {//是否要debug return Ext.debug; } public static Application app() {//获取当前的Application if (Ext.app == null) { try { // 在IDE进行布局预览时使用 Class<?> renderActionClass = Class.forName("com.android.layoutlib.bridge.impl.RenderAction"); Method method = renderActionClass.getDeclaredMethod("getCurrentContext"); Context context = (Context) method.invoke(null); Ext.app = new MockApplication(context); } catch (Throwable ignored) { throw new RuntimeException("please invoke x.Ext.init(app) on Application#onCreate()" + " and register your Application in manifest."); } } return Ext.app; } public static TaskController task() {//所使用的任务管理器 return Ext.taskController; } public static HttpManager http() {//所使用的http管理器 if (Ext.httpManager == null) { HttpManagerImpl.registerInstance(); } return Ext.httpManager; } public static ImageManager image() {//所使用的image管理器 if (Ext.imageManager == null) { ImageManagerImpl.registerInstance(); } return Ext.imageManager; } public static ViewInjector view() {//所使用的view注入器 if (Ext.viewInjector == null) { ViewInjectorImpl.registerInstance(); } return Ext.viewInjector; } public static DbManager getDb(DbManager.DaoConfig daoConfig) {//数据库管理器 return DbManagerImpl.getInstance(daoConfig); } public static class Ext {//内部类,同时也是配置类,各个关键部件的引用管理类 private static boolean debug; private static Application app; private static TaskController taskController; private static HttpManager httpManager; private static ImageManager imageManager; private static ViewInjector viewInjector; private Ext() { } static { TaskControllerImpl.registerInstance(); // 默认信任所有https域名 HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() { @Override public boolean verify(String hostname, SSLSession session) { return true; } }); } public static void init(Application app) { if (Ext.app == null) { Ext.app = app; } } public static void setDebug(boolean debug) { Ext.debug = debug; } public static void setTaskController(TaskController taskController) { if (Ext.taskController == null) { Ext.taskController = taskController; } } public static void setHttpManager(HttpManager httpManager) { Ext.httpManager = httpManager; } public static void setImageManager(ImageManager imageManager) { Ext.imageManager = imageManager; } public static void setViewInjector(ViewInjector viewInjector) { Ext.viewInjector = viewInjector; } } private static class MockApplication extends Application { public MockApplication(Context baseContext) { this.attachBaseContext(baseContext);//绑定到特定的baseContext } }}
0 0
- xUtils源码阅读(1)- x
- xUtils源码阅读(3)-ImageManagerImpl
- xUtils源码阅读(4)-MemCacheKey
- xUtils源码阅读(5)-ReuseableBitmapDrawable
- xUtils源码阅读(6)-AsyncDrawable
- xUtils源码阅读(7)-GitDrawable
- xUtils源码阅读(8)-ImageDecoder
- xUtils源码阅读(2)-ImageManager
- Cocos2d-x源码阅读1 UI树1(第一次系统而有成效的阅读源码的感悟)
- xUtils源码分析系列1
- 根据源码解析xUtils 3.x数据库update操作
- cocos2d-x 3.1.1源码阅读过程的注释
- VODemo源码阅读(1)
- struts1源码阅读(1)
- struts1源码阅读(1)
- Spring 源码阅读(1)
- DispatcherServlet 源码阅读(1)
- sqlalchemy源码阅读(1)
- android清除缓存会将数据库清除吗?
- cannot determine loading status from unexperted alert open
- 云计算的三种服务模式:IaaS,PaaS和SaaS
- RabbitMq、ActiveMq、ZeroMq、kafka之间的比较,资料汇总
- iOS 拖Xib的时候 显示 Could not insert new outlet connection
- xUtils源码阅读(1)- x
- 1.3_Android Training 学习笔记_兼容不同的设备
- Android开发,appcompat-v7:24.2.1的Theme.AppCompat.Light主题下更改普通Button的颜色
- USACO2014Open Silver Dueling GPSs
- ring3-NtMapViewOfSection注入
- ReactiveCocoa框架菜鸟入门(一)——CocoaPods添加ReactiveCocoa
- ServletContext方法
- Java设计模式
- RANSAC算法详解