Skip to content

Commit

Permalink
Update README.md, add javadoc, upgrade library version
Browse files Browse the repository at this point in the history
  • Loading branch information
markzhai committed Oct 4, 2015
1 parent e05ff54 commit 4fbcb3d
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Init
# Init [![Maven Central](https://maven-badges.herokuapp.com/maven-central/cn.zhaiyifan/init/badge.svg?style=flat)](https://maven-badges.herokuapp.com/maven-central/cn.zhaiyifan/init)
Init helps Android apps schedule initialization of application, with type, priority and multi-process, tidy magic code for every process, and improves efficiency of application start.

It is originally designed for application initialization, but not confined to that, it can be applied to any complex initialization procedure.
Expand All @@ -9,7 +9,7 @@ It is originally designed for application initialization, but not confined to th

```gradle
dependencies {
compile 'cn.zhaiyifan:init:1.0.0'
compile 'cn.zhaiyifan:init:1.0.1'
}
```

Expand Down
2 changes: 1 addition & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Init帮助Android应用调度初始化流程,囊括类型、优先级、多进

```gradle
dependencies {
compile 'cn.zhaiyifan:init:1.0.0'
compile 'cn.zhaiyifan:init:1.0.1'
}
```

Expand Down
4 changes: 2 additions & 2 deletions init/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
POM_NAME=Android Init Library
POM_ARTIFACT_ID=init
POM_PACKAGING=aar
VERSION_NAME=1.0.0
VERSION_CODE=1
VERSION_NAME=1.0.1
VERSION_CODE=2
GROUP=cn.zhaiyifan

POM_DESCRIPTION=Init helps Android apps schedule initialization of application, with type, priority and multi-process, tidy magic code for every process, and improves efficiency of application start.
Expand Down
21 changes: 19 additions & 2 deletions init/src/main/java/cn/zhaiyifan/appinit/ILog.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@
* Created by mark.zhai on 15/10/3.
*/
public interface ILog {
void info(String tag, String message);
void warn(String tag, String message);

/**
* Send an information level log message, used by time-related log.
*
* @param tag Used to identify the source of a log message. It usually identifies
* the class or activity where the log call occurs.
* @param msg The message you would like logged.
*/
void info(String tag, String msg);


/**
* Send an warning level log message, used by exception-related log.
*
* @param tag Used to identify the source of a log message. It usually identifies
* the class or activity where the log call occurs.
* @param msg The message you would like logged.
*/
void warn(String tag, String msg);
}
35 changes: 33 additions & 2 deletions init/src/main/java/cn/zhaiyifan/appinit/Init.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,27 @@
* Created by mark.zhai on 2015/10/2.
*/
public class Init {
private static final int THREAD_POOL_SIZE = 8;
private static final int DEFAULT_THREAD_POOL_SIZE = 8;

private static Map<String, Flow> sFlowMap = new HashMap<>();
private static Context sContext;
private static int mThreadPoolSize = DEFAULT_THREAD_POOL_SIZE;

/**
* Init with context.
*
* @param context application context
*/
public static void init(Context context) {
sContext = context;
}

/**
* Init with context and log class.
*
* @param context application context
* @param logProxy log class implements {@link ILog}
*/
public static void init(Context context, ILog logProxy) {
sContext = context;
LogImpl.setLogProxy(logProxy);
Expand All @@ -36,12 +48,22 @@ public static void addFlow(Map<String, Flow> flowMap) {

/**
* Get application context for process information, package usage.
*
* @return application context
*/
public static Context getContext() {
return sContext;
}

/**
* Set thread pool size used by tasks.
*
* @param size thread pool size, value less or equal than 0 will produce a cached thread pool.
*/
public static void setThreadPoolSize(int size) {
mThreadPoolSize = size;
}

public static Flow getFlow(String flowName) {
Flow flow = sFlowMap.get(flowName);
return flow != null ? flow : new Flow(flowName);
Expand Down Expand Up @@ -90,7 +112,16 @@ public static int getFlowStatus(String flowName) {
return flow != null ? flow.getFlowStatus() : Status.STATUS_UNKNOWN;
}

/**
* Get thread pool used internally by Init library.
*
* @return thread pool
*/
public static ExecutorService getThreadPool() {
return Executors.newFixedThreadPool(THREAD_POOL_SIZE);
if (mThreadPoolSize <= 0) {
return Executors.newCachedThreadPool();
} else {
return Executors.newFixedThreadPool(mThreadPoolSize);
}
}
}
17 changes: 17 additions & 0 deletions init/src/main/java/cn/zhaiyifan/appinit/Status.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,25 @@
* Created by mark.zhai on 2015/10/2.
*/
public class Status {

/**
* Unknown status
*/
public final static int STATUS_UNKNOWN = 0;

/**
* Pending for start status
*/
public final static int STATUS_PENDING_START = 1;

/**
* Executing status
*/
public final static int STATUS_EXECUTING = 0;

/**
* Done status
*/
public final static int STATUS_DONE = 0;

}

0 comments on commit 4fbcb3d

Please sign in to comment.