ARouter类做了对_ARouter类的简单封装。从而使得内部接口方法不对外暴露, 对开发者也显的简单。
ARouter类包含以下功能,基本上也是ARouter框架的功能
/**
* Init, it must be call before used router.
*/
public static void init(Application application) {
if (!hasInit) {
logger = _ARouter.logger;
_ARouter.logger.info(Consts.TAG, "ARouter init start.");
hasInit = _ARouter.init(application);
if (hasInit) {
_ARouter.afterInit();
}
_ARouter.logger.info(Consts.TAG, "ARouter init over.");
}
}
protected Object navigation(final Context context, final Postcard postcard, final int requestCode, final NavigationCallback callback) {
try {
LogisticsCenter.completion(postcard);
} catch (NoRouteFoundException ex) {
logger.warning(Consts.TAG, ex.getMessage());
if (debuggable()) {
// Show friendly tips for user.
runInMainThread(new Runnable() {
@Override
public void run() {
Toast.makeText(mContext, "There's no route matched!\n" +
" Path = [" + postcard.getPath() + "]\n" +
" Group = [" + postcard.getGroup() + "]", Toast.LENGTH_LONG).show();
}
});
}
if (null != callback) {
callback.onLost(postcard);
} else { // No callback for this invoke, then we use the global degrade service.
DegradeService degradeService = ARouter.getInstance().navigation(DegradeService.class);
if (null != degradeService) {
degradeService.onLost(context, postcard);
}
}
return null;
}
public static void setLogger(ILogger userLogger) {
_ARouter.setLogger(userLogger);
}
public interface ILogger {
boolean isShowLog = false;
boolean isShowStackTrace = false;
String defaultTag = Consts.TAG;
void showLog(boolean isShowLog);
void showStackTrace(boolean isShowStackTrace);
void debug(String tag, String message);
void info(String tag, String message);
void warning(String tag, String message);
void error(String tag, String message);
void monitor(String message);
boolean isMonitorMode();
String getDefaultTag();
}
public class DefaultPoolExecutor extends ThreadPoolExecutor {
// Thread args
private static final int CPU_COUNT = Runtime.getRuntime().availableProcessors();
private static final int INIT_THREAD_COUNT = CPU_COUNT + 1;
private static final int MAX_THREAD_COUNT = INIT_THREAD_COUNT;
private static final long SURPLUS_THREAD_LIFE = 30L;
private static DefaultPoolExecutor instance;
public static DefaultPoolExecutor getInstance() {
if (null == instance) {
synchronized (DefaultPoolExecutor.class) {
if (null == instance) {
instance = new DefaultPoolExecutor(
INIT_THREAD_COUNT,
MAX_THREAD_COUNT,
SURPLUS_THREAD_LIFE,
TimeUnit.SECONDS,
new ArrayBlockingQueue<Runnable>(64),
new DefaultThreadFactory());
}
}
}
return instance;
}
/**
* Build the roadmap, draw a postcard.
*
* @param path Where you go.
*/
public Postcard build(String path) {
return _ARouter.getInstance().build(path);
}
/**
* Build the roadmap, draw a postcard.
*
* @param path Where you go.
* @param group The group of path.
*/
@Deprecated
public Postcard build(String path, String group) {
return _ARouter.getInstance().build(path, group);
}
/**
* Build the roadmap, draw a postcard.
*
* @param url the path
*/
public Postcard build(Uri url) {
return _ARouter.getInstance().build(url);
}
/**
* Launch the navigation by type
*
* @param service interface of service
* @param <T> return type
* @return instance of service
*/
public <T> T navigation(Class<? extends T> service) {
return _ARouter.getInstance().navigation(service);
}
/**
* Inject params and services.
*/
public void inject(Object thiz) {
_ARouter.inject(thiz);
}
以上是ARouter类的功能性介绍。