├── .gitignore ├── README.md ├── alpha ├── .gitignore ├── AndroidManifest.xml ├── build.gradle ├── docs │ ├── allclasses-frame.html │ ├── allclasses-noframe.html │ ├── com │ │ └── tmall │ │ │ └── wireless │ │ │ └── alpha │ │ │ ├── AlphaLog.html │ │ │ ├── AlphaManager.html │ │ │ ├── AlphaUtils.html │ │ │ ├── Task.OnFinishedListener.html │ │ │ ├── Task.ProjectBuilder.html │ │ │ ├── Task.html │ │ │ ├── package-frame.html │ │ │ ├── package-summary.html │ │ │ └── package-tree.html │ ├── constant-values.html │ ├── deprecated-list.html │ ├── help-doc.html │ ├── index-files │ │ ├── index-1.html │ │ ├── index-10.html │ │ ├── index-11.html │ │ ├── index-12.html │ │ ├── index-2.html │ │ ├── index-3.html │ │ ├── index-4.html │ │ ├── index-5.html │ │ ├── index-6.html │ │ ├── index-7.html │ │ ├── index-8.html │ │ └── index-9.html │ ├── index.html │ ├── overview-tree.html │ ├── package-list │ ├── resources │ │ ├── background.gif │ │ ├── tab.gif │ │ ├── titlebar.gif │ │ └── titlebar_end.gif │ └── stylesheet.css ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── alibaba │ │ └── android │ │ └── alpha │ │ ├── AlphaConfig.java │ │ ├── AlphaLog.java │ │ ├── AlphaManager.java │ │ ├── AlphaUtils.java │ │ ├── ConfigParser.java │ │ ├── ExecuteMonitor.java │ │ ├── ITaskCreator.java │ │ ├── ListMultiMap.java │ │ ├── OnGetMonitorRecordCallback.java │ │ ├── OnProjectExecuteListener.java │ │ ├── Project.java │ │ ├── Task.java │ │ └── TaskFactory.java │ └── res │ └── values │ └── strings.xml ├── alpha_logo.png ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── sample ├── .gitignore ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── local.properties ├── proguard-rules.pro ├── sample-release.apk ├── sample.apk └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── tmall │ │ └── wireless │ │ └── alpha │ │ └── ApplicationTest.java │ └── main │ ├── AndroidManifest.xml │ ├── assets │ └── tasklist.xml │ ├── java │ └── com │ │ └── alibaba │ │ └── android │ │ └── alpha │ │ ├── ConfigTest.java │ │ ├── MainActivity.java │ │ └── MyLog.java │ └── res │ ├── layout │ └── activity_main.xml │ ├── menu │ └── menu_main.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /local.properties 3 | /.idea/ 4 | .DS_Store 5 | /build 6 | /captures 7 | *.iml 8 | target/ 9 | .classpath 10 | .project 11 | .settings/ 12 | sample/.idea 13 | 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![screenshot](/alpha_logo.png) 2 | 3 | # Alpha启动框架 4 | --- 5 | 6 | Alpha是一个基于PERT图构建的Android异步启动框架,它简单,高效,功能完善。 7 | 在应用启动的时候,我们通常会有很多工作需要做,为了提高启动速度,我们会尽可能让这些工作并发进行。但这些工作之间可能存在前后依赖的关系,所以我们又需要想办法保证他们执行顺序的正确性。Alpha就是为此而设计的,使用者只需定义好自己的task,并描述它依赖的task,将它添加到Project中。框架会自动并发有序地执行这些task,并将执行的结果抛出来。 8 | 由于Android应用支持多进程,所以Alpha支持为不同进程配置不同的启动模式。 9 | 10 | 11 | ### 接入Alpha 12 | 13 | ```groovy 14 | compile 'com.alibaba.android:alpha:1.0.0.1@aar' 15 | ``` 16 | 17 | 18 | ### 使用指南 19 | Alpha支持代码和配置文件的方式构建一个启动流程。 20 | #### 使用Java代码构建 21 | 22 | 1.实现自己的Task类。继承Task类,在run()函数中实现该Task需要做的事情。 23 | 24 | ```java 25 | public class SampleTask extends Task{ 26 | public SampleTask() { 27 | super("SampleTask"); 28 | } 29 | 30 | @Override 31 | public void run() { 32 | //do something, print a msg for example. 33 | Log.d(TAG, "run SampleTask"); 34 | } 35 | } 36 | ``` 37 | Task默认是在异步线程中执行的,如果这个Task需要在线程中执行,可以在构造函数中声明。 38 | 2.将Task组合成一个完整的Project。 39 | 可以用Task.ProjectBuilder依据各Task之间的依赖关系,将这些Task构建成一个完整的Project。 40 | 41 | ```java 42 | private Task createCommonTaskGroup() { 43 | Task a = new TaskA(); 44 | Task b = new TaskB(); 45 | Task c = new TaskC(); 46 | Task d = new TaskD(); 47 | Task e = new TaskE(); 48 | 49 | Project.Builder builder = new Project.Builder(); 50 | builder.add(a); 51 | builder.add(b).after(a); 52 | builder.add(c).after(a); 53 | builder.add(d).after(b, c); 54 | builder.add(e).after(a); 55 | Project group = builder.create(); 56 | 57 | return group; 58 | } 59 | 60 | ``` 61 | ProjectBuilder生成的Project本身可以作为一个Task嵌入到另外一个Project中。 62 | ```java 63 | private Task createCommonTaskGroup() { 64 | Task a = new TaskA(); 65 | Task b = new TaskB(); 66 | Task c = new TaskC(); 67 | Task d = new TaskD(); 68 | Task e = new TaskE(); 69 | 70 | Project.Builder builder = new Project.Builder(); 71 | builder.add(a); 72 | builder.add(b).after(a); 73 | builder.add(c).after(a); 74 | builder.add(d).after(b, c); 75 | builder.add(e).after(a); 76 | Project group = builder.create(); 77 | 78 | return group; 79 | } 80 | 81 | private void createProject() { 82 | Task group = createCommonTaskGroup(); 83 | Task f = new TaskF(); 84 | 85 | Project.Builder builder = new Project.Builder(); 86 | builder.add(group); 87 | builder.add(f); 88 | 89 | Project project = builder.create(); 90 | } 91 | ``` 92 | 3.为构建完成的Project配置对应的进程。 93 | 94 | ```java 95 | AlphaManager.getInstance(mContext).addProject(project); 96 | ``` 97 | 4.执行启动流程 98 | ```java 99 | AlphaManager.getInstance(mContext).start(); 100 | ``` 101 | 102 | #### 使用XML配置文件构建 103 | 1.在代码中实现自己的Task,这个和上面的一样。 104 | 2.在XML文件中描述整个Project。 105 | 106 | ```xml 107 | 108 | 110 | 115 | 116 | 120 | 121 | 126 | 127 | 132 | 133 | 136 | 137 | 138 | 139 | 140 | 141 | 146 | 147 | 152 | 153 | 154 | 155 | 156 | 157 | 159 | 163 | 164 | 168 | 169 | 174 | 175 | 179 | 180 | 181 | 182 | 183 | ``` 184 | 3.加载配置文件,这里我将该配置文件命名为tasklist.xml,并且放在asset中。 185 | 186 | ```java 187 | InputStream in = null; 188 | try { 189 | 190 | in = mContext.getAssets().open("tasklist.xml"); 191 | AlphaManager.getInstance(mContext).addProjectsViaFile(in); 192 | 193 | } catch (IOException ex) { 194 | ex.printStackTrace(); 195 | } finally { 196 | AlphaUtils.closeSafely(in); 197 | } 198 | ``` 199 | 4.执行启动流程 200 | 201 | ```java 202 | AlphaManager.getInstance(mContext).start(); 203 | ``` 204 | -------------------------------------------------------------------------------- /alpha/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /alpha/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /alpha/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Alibaba Group. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | apply plugin: 'com.android.library' 18 | apply plugin: 'maven-publish' 19 | apply plugin: 'com.jfrog.bintray' 20 | 21 | Properties properties = new Properties() 22 | properties.load(project.rootProject.file('local.properties').newDataInputStream()) 23 | def bintray_user = properties.getProperty('BINTRAY_USER') 24 | def bintray_key = properties.getProperty('BINTRAY_KEY') 25 | 26 | bintray { 27 | user = bintray_user 28 | key = bintray_key 29 | publish = true 30 | override = true 31 | publications = ['maven_android'] 32 | pkg { 33 | repo = 'maven' 34 | name = 'alpha' 35 | licenses = ['Apache-2.0'] 36 | vcsUrl = 'https://github.com/alibaba/alpha' 37 | 38 | version { 39 | name = '1.0.0.1' 40 | desc = 'A startup frameword for android app.' 41 | released = new Date() 42 | vcsTag = '1.0.0.0' 43 | } 44 | } 45 | } 46 | 47 | 48 | task sourcesJar(type: Jar) { 49 | from android.sourceSets.main.java.srcDirs 50 | classifier = 'sources' 51 | } 52 | 53 | 54 | publishing { 55 | publications { 56 | maven_android(MavenPublication) { 57 | groupId "com.alibaba.android" 58 | version "1.0.0.1" 59 | artifactId "alpha" 60 | artifact(sourcesJar) 61 | artifact("$buildDir/outputs/aar/alpha-release.aar") 62 | 63 | 64 | pom.withXml { 65 | def dependenciesNode = asNode().appendNode('dependencies') 66 | 67 | //Iterate over the compile dependencies (we don't want the test ones), adding a node for each 68 | configurations.compile.allDependencies.each { 69 | if (it.group != null && it.group != 'unspecified' && it.name != null && it.name != 'unspecified') { 70 | def dependencyNode = dependenciesNode.appendNode('dependency') 71 | dependencyNode.appendNode('groupId', it.group) 72 | dependencyNode.appendNode('artifactId', it.name) 73 | dependencyNode.appendNode('version', it.version) 74 | } 75 | } 76 | } 77 | } 78 | } 79 | } 80 | 81 | android { 82 | compileSdkVersion 22 83 | buildToolsVersion "22.0.1" 84 | 85 | defaultConfig { 86 | minSdkVersion 14 87 | targetSdkVersion 22 88 | versionCode 1 89 | versionName "1.0" 90 | } 91 | buildTypes { 92 | release { 93 | minifyEnabled false 94 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 95 | } 96 | } 97 | } 98 | 99 | dependencies { 100 | compile fileTree(dir: 'libs', include: ['*.jar']) 101 | // Unit testing dependencies 102 | // testCompile 'junit:junit:4.12' 103 | // // Set this dependency if you want to use Mockito 104 | // // Set this dependency if you want to use Hamcrest matching 105 | // androidTestCompile 'org.hamcrest:hamcrest-library:1.1' 106 | } 107 | -------------------------------------------------------------------------------- /alpha/docs/allclasses-frame.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 所有类 24 | 25 | 26 | 27 | 28 |

所有类

29 |
30 | 38 |
39 | 40 | 41 | -------------------------------------------------------------------------------- /alpha/docs/allclasses-noframe.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 所有类 24 | 25 | 26 | 27 | 28 |

所有类

29 |
30 | 38 |
39 | 40 | 41 | -------------------------------------------------------------------------------- /alpha/docs/com/tmall/wireless/alpha/Task.OnFinishedListener.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | Task.OnFinishedListener 24 | 25 | 26 | 27 | 28 | 34 | 37 | 38 |
39 | 40 | 41 | 42 | 43 | 51 |
52 | 94 | 95 | 96 |
97 |
com.tmall.wireless.alpha
98 |

接口 Task.OnFinishedListener

99 |
100 |
101 |
102 |
    103 |
  • 104 |
    105 |
    封闭类:
    106 |
    Task
    107 |
    108 |
    109 |
    110 |
    public static interface Task.OnFinishedListener
    111 |
    Project执行结束的回调。
    112 |
  • 113 |
114 |
115 |
116 |
    117 |
  • 118 | 119 |
      120 |
    • 121 | 122 | 123 |

      方法概要

      124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 135 | 136 |
      方法 
      限定符和类型方法和说明
      voidonStartUpFinished() 133 |
      Project执行结束时,调用该函数。
      134 |
      137 |
    • 138 |
    139 |
  • 140 |
141 |
142 |
143 |
    144 |
  • 145 | 146 |
      147 |
    • 148 | 149 | 150 |

      方法详细资料

      151 | 152 | 153 | 154 |
        155 |
      • 156 |

        onStartUpFinished

        157 |
        void onStartUpFinished()
        158 |
        Project执行结束时,调用该函数。
        159 | 注意:该回调函数在主线程中执行。
        160 |
      • 161 |
      162 |
    • 163 |
    164 |
  • 165 |
166 |
167 |
168 | 169 | 170 |
171 | 172 | 173 | 174 | 175 | 183 |
184 | 226 | 227 | 228 | 229 | -------------------------------------------------------------------------------- /alpha/docs/com/tmall/wireless/alpha/package-frame.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | com.tmall.wireless.alpha 24 | 25 | 26 | 27 | 28 |

com.tmall.wireless.alpha

29 |
30 |

接口

31 | 34 |

35 | 42 |
43 | 44 | 45 | -------------------------------------------------------------------------------- /alpha/docs/com/tmall/wireless/alpha/package-summary.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | com.tmall.wireless.alpha 24 | 25 | 26 | 27 | 28 | 34 | 37 | 38 |
39 | 40 | 41 | 42 | 43 | 51 |
52 | 79 | 80 |
81 |

程序包 com.tmall.wireless.alpha

82 |
83 |
84 | 146 |
147 | 148 |
149 | 150 | 151 | 152 | 153 | 161 |
162 | 189 | 190 | 191 | 192 | -------------------------------------------------------------------------------- /alpha/docs/com/tmall/wireless/alpha/package-tree.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | com.tmall.wireless.alpha 类分层结构 24 | 25 | 26 | 27 | 28 | 34 | 37 | 38 |
39 | 40 | 41 | 42 | 43 | 51 |
52 | 79 | 80 |
81 |

程序包com.tmall.wireless.alpha的分层结构

82 |
83 |
84 |

类分层结构

85 | 96 |

接口分层结构

97 | 100 |
101 | 102 |
103 | 104 | 105 | 106 | 107 | 115 |
116 | 143 | 144 | 145 | 146 | -------------------------------------------------------------------------------- /alpha/docs/constant-values.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 常量字段值 24 | 25 | 26 | 27 | 28 | 34 | 37 | 38 |
39 | 40 | 41 | 42 | 43 | 51 |
52 | 79 | 80 |
81 |

常量字段值

82 |

目录

83 | 86 |
87 |
88 | 89 | 90 |

com.tmall.*

91 | 178 |
179 | 180 |
181 | 182 | 183 | 184 | 185 | 193 |
194 | 221 | 222 | 223 | 224 | -------------------------------------------------------------------------------- /alpha/docs/deprecated-list.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 已过时的列表 24 | 25 | 26 | 27 | 28 | 34 | 37 | 38 |
39 | 40 | 41 | 42 | 43 | 51 |
52 | 79 | 80 |
81 |

已过时的 API

82 |

目录

83 |
84 | 85 |
86 | 87 | 88 | 89 | 90 | 98 |
99 | 126 | 127 | 128 | 129 | -------------------------------------------------------------------------------- /alpha/docs/help-doc.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | API 帮助 24 | 25 | 26 | 27 | 28 | 34 | 37 | 38 |
39 | 40 | 41 | 42 | 43 | 51 |
52 | 79 | 80 |
81 |

此 API 文档的组织方式

82 |
此 API (应用程序编程接口) 文档包含对应于导航栏中的项目的页面, 如下所述。
83 |
84 |
85 | 180 | 此帮助文件适用于使用标准 doclet 生成的 API 文档。
181 | 182 |
183 | 184 | 185 | 186 | 187 | 195 |
196 | 223 | 224 | 225 | 226 | -------------------------------------------------------------------------------- /alpha/docs/index-files/index-10.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | S - 索引 24 | 25 | 26 | 27 | 28 | 34 | 37 | 38 |
39 | 40 | 41 | 42 | 43 | 51 |
52 | 79 | 80 |
A C D E G I M O R S T W  81 | 82 | 83 |

S

84 |
85 |
SECONDARY_PROCESS_MODE - 类 中的静态变量com.tmall.wireless.alpha.AlphaManager
86 |
87 |
启动流程的模式,适用于所有非主进程
88 |
89 |
setOnFinishListener(Task.OnFinishedListener) - 类 中的方法com.tmall.wireless.alpha.Task.ProjectBuilder
90 |
91 |
设置Project执行结束的监听。
92 |
93 |
setProjectName(String) - 类 中的方法com.tmall.wireless.alpha.Task.ProjectBuilder
94 |
95 |
设置Project的名称。
96 |
97 |
start() - 类 中的方法com.tmall.wireless.alpha.AlphaManager
98 |
99 |
开始启动流程,这里会根据当前的进程执行合适的启动流程。
100 |
101 |
start() - 类 中的方法com.tmall.wireless.alpha.Task
102 |
103 |
执行当前Task的任务,这里会调用用户自定义的Task.run()
104 |
105 |
STATE_FINISHED - 类 中的静态变量com.tmall.wireless.alpha.Task
106 |
107 |
Task执行状态,Task已经执行完毕
108 |
109 |
STATE_IDLE - 类 中的静态变量com.tmall.wireless.alpha.Task
110 |
111 |
Task执行状态,Task尚未执行
112 |
113 |
STATE_RUNNING - 类 中的静态变量com.tmall.wireless.alpha.Task
114 |
115 |
Task执行状态,Task正在执行中
116 |
117 |
118 | A C D E G I M O R S T W 
119 | 120 |
121 | 122 | 123 | 124 | 125 | 133 |
134 | 161 | 162 | 163 | 164 | -------------------------------------------------------------------------------- /alpha/docs/index-files/index-11.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | T - 索引 24 | 25 | 26 | 27 | 28 | 34 | 37 | 38 |
39 | 40 | 41 | 42 | 43 | 51 |
52 | 79 | 80 |
A C D E G I M O R S T W  81 | 82 | 83 |

T

84 |
85 |
Task - com.tmall.wireless.alpha中的类
86 |
87 |
这个类将一个个关联的Task,组织成PERT网路图的方式进行执行。
88 |
89 |
Task(String) - 类 的构造器com.tmall.wireless.alpha.Task
90 |
91 |
构造Task对象,必须要传入name,便于确定当前是在哪一个任务中。
92 |
93 |
Task(String, boolean) - 类 的构造器com.tmall.wireless.alpha.Task
94 |
95 |
构造Task对象。
96 |
97 |
Task.OnFinishedListener - com.tmall.wireless.alpha中的接口
98 |
99 |
Project执行结束的回调。
100 |
101 |
Task.ProjectBuilder - com.tmall.wireless.alpha中的类
102 |
103 |
通过ProjectBuilder将多个Task组成一个Project
104 |
105 |
Task.ProjectBuilder() - 类 的构造器com.tmall.wireless.alpha.Task.ProjectBuilder
106 |
107 |
构建ProjectBuilder实例。
108 |
109 |
110 | A C D E G I M O R S T W 
111 | 112 |
113 | 114 | 115 | 116 | 117 | 125 |
126 | 153 | 154 | 155 | 156 | -------------------------------------------------------------------------------- /alpha/docs/index-files/index-12.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | W - 索引 24 | 25 | 26 | 27 | 28 | 34 | 37 | 38 |
39 | 40 | 41 | 42 | 43 | 51 |
52 | 79 | 80 |
A C D E G I M O R S T W  81 | 82 | 83 |

W

84 |
85 |
w(Exception) - 类 中的静态方法com.tmall.wireless.alpha.AlphaLog
86 |
 
87 |
88 | A C D E G I M O R S T W 
89 | 90 |
91 | 92 | 93 | 94 | 95 | 103 |
104 | 131 | 132 | 133 | 134 | -------------------------------------------------------------------------------- /alpha/docs/index-files/index-2.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | C - 索引 24 | 25 | 26 | 27 | 28 | 34 | 37 | 38 |
39 | 40 | 41 | 42 | 43 | 51 |
52 | 79 | 80 |
A C D E G I M O R S T W  81 | 82 | 83 |

C

84 |
85 |
closeSafely(Closeable) - 类 中的静态方法com.tmall.wireless.alpha.AlphaUtils
86 |
87 |
Close a Closeable object safely.
88 |
89 |
closeSafely(Cursor) - 类 中的静态方法com.tmall.wireless.alpha.AlphaUtils
90 |
91 |
Close a Cursor object safely.
92 |
93 |
com.tmall.wireless.alpha - 程序包 com.tmall.wireless.alpha
94 |
 
95 |
create() - 类 中的方法com.tmall.wireless.alpha.Task.ProjectBuilder
96 |
97 |
创建一个Project实例。
98 |
99 |
100 | A C D E G I M O R S T W 
101 | 102 |
103 | 104 | 105 | 106 | 107 | 115 |
116 | 143 | 144 | 145 | 146 | -------------------------------------------------------------------------------- /alpha/docs/index-files/index-3.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | D - 索引 24 | 25 | 26 | 27 | 28 | 34 | 37 | 38 |
39 | 40 | 41 | 42 | 43 | 51 |
52 | 79 | 80 |
A C D E G I M O R S T W  81 | 82 | 83 |

D

84 |
85 |
d(String, Object) - 类 中的静态方法com.tmall.wireless.alpha.AlphaLog
86 |
 
87 |
d(String, String, Object...) - 类 中的静态方法com.tmall.wireless.alpha.AlphaLog
88 |
 
89 |
d(String, Object...) - 类 中的静态方法com.tmall.wireless.alpha.AlphaLog
90 |
 
91 |
92 | A C D E G I M O R S T W 
93 | 94 |
95 | 96 | 97 | 98 | 99 | 107 |
108 | 135 | 136 | 137 | 138 | -------------------------------------------------------------------------------- /alpha/docs/index-files/index-4.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | E - 索引 24 | 25 | 26 | 27 | 28 | 34 | 37 | 38 |
39 | 40 | 41 | 42 | 43 | 51 |
52 | 79 | 80 |
A C D E G I M O R S T W  81 | 82 | 83 |

E

84 |
85 |
e(String, Object) - 类 中的静态方法com.tmall.wireless.alpha.AlphaLog
86 |
 
87 |
e(String, String, Object...) - 类 中的静态方法com.tmall.wireless.alpha.AlphaLog
88 |
 
89 |
90 | A C D E G I M O R S T W 
91 | 92 |
93 | 94 | 95 | 96 | 97 | 105 |
106 | 133 | 134 | 135 | 136 | -------------------------------------------------------------------------------- /alpha/docs/index-files/index-5.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | G - 索引 24 | 25 | 26 | 27 | 28 | 34 | 37 | 38 |
39 | 40 | 41 | 42 | 43 | 51 |
52 | 79 | 80 |
A C D E G I M O R S T W  81 | 82 | 83 |

G

84 |
85 |
getCurrentState() - 类 中的方法com.tmall.wireless.alpha.Task
86 |
87 |
查询当前该Task执行的状态。
88 |
89 |
getCurrProcessName(Context) - 类 中的静态方法com.tmall.wireless.alpha.AlphaUtils
90 |
 
91 |
getInstance(Context) - 类 中的静态方法com.tmall.wireless.alpha.AlphaManager
92 |
 
93 |
GLOBAL_TAG - 类 中的静态变量com.tmall.wireless.alpha.AlphaLog
94 |
 
95 |
96 | A C D E G I M O R S T W 
97 | 98 |
99 | 100 | 101 | 102 | 103 | 111 |
112 | 139 | 140 | 141 | 142 | -------------------------------------------------------------------------------- /alpha/docs/index-files/index-6.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | I - 索引 24 | 25 | 26 | 27 | 28 | 34 | 37 | 38 |
39 | 40 | 41 | 42 | 43 | 51 |
52 | 79 | 80 |
A C D E G I M O R S T W  81 | 82 | 83 |

I

84 |
85 |
i(String, Object) - 类 中的静态方法com.tmall.wireless.alpha.AlphaLog
86 |
 
87 |
isFinished() - 类 中的方法com.tmall.wireless.alpha.Task
88 |
89 |
判断当前Task已经完成,即状态是否是Task.STATE_FINISHED
90 |
91 |
isInMainProcess(Context) - 类 中的静态方法com.tmall.wireless.alpha.AlphaUtils
92 |
93 |
Check if current process is main process.
94 |
95 |
isProjectFinished() - 类 中的方法com.tmall.wireless.alpha.AlphaManager
96 |
97 |
判断当前进程的启动流程是否执行完成。
98 |
99 |
isRunning() - 类 中的方法com.tmall.wireless.alpha.Task
100 |
101 |
判断当前Task是否正在运行,即状态是否是Task.STATE_RUNNING
102 |
103 |
104 | A C D E G I M O R S T W 
105 | 106 |
107 | 108 | 109 | 110 | 111 | 119 |
120 | 147 | 148 | 149 | 150 | -------------------------------------------------------------------------------- /alpha/docs/index-files/index-7.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | M - 索引 24 | 25 | 26 | 27 | 28 | 34 | 37 | 38 |
39 | 40 | 41 | 42 | 43 | 51 |
52 | 79 | 80 |
A C D E G I M O R S T W  81 | 82 | 83 |

M

84 |
85 |
MAIN_PROCESS_MODE - 类 中的静态变量com.tmall.wireless.alpha.AlphaManager
86 |
87 |
启动流程的模式,适用于主进程
88 |
89 |
90 | A C D E G I M O R S T W 
91 | 92 |
93 | 94 | 95 | 96 | 97 | 105 |
106 | 133 | 134 | 135 | 136 | -------------------------------------------------------------------------------- /alpha/docs/index-files/index-8.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | O - 索引 24 | 25 | 26 | 27 | 28 | 34 | 37 | 38 |
39 | 40 | 41 | 42 | 43 | 51 |
52 | 79 | 80 |
A C D E G I M O R S T W  81 | 82 | 83 |

O

84 |
85 |
onEvent(int) - 类 中的方法com.tmall.wireless.alpha.AlphaManager
86 |
 
87 |
onStartUpFinished() - 接口 中的方法com.tmall.wireless.alpha.Task.OnFinishedListener
88 |
89 |
Project执行结束时,调用该函数。
90 |
91 |
92 | A C D E G I M O R S T W 
93 | 94 |
95 | 96 | 97 | 98 | 99 | 107 |
108 | 135 | 136 | 137 | 138 | -------------------------------------------------------------------------------- /alpha/docs/index-files/index-9.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | R - 索引 24 | 25 | 26 | 27 | 28 | 34 | 37 | 38 |
39 | 40 | 41 | 42 | 43 | 51 |
52 | 79 | 80 |
A C D E G I M O R S T W  81 | 82 | 83 |

R

84 |
85 |
run() - 类 中的方法com.tmall.wireless.alpha.Task
86 |
87 |
在其中实现该Task具体执行的逻辑。
88 |
89 |
90 | A C D E G I M O R S T W 
91 | 92 |
93 | 94 | 95 | 96 | 97 | 105 |
106 | 133 | 134 | 135 | 136 | -------------------------------------------------------------------------------- /alpha/docs/index.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 生成的文档 (无标题) 24 | 76 | 77 | 78 | 79 | 80 | 81 | <noscript> 82 | <div>您的浏览器已禁用 JavaScript。</div> 83 | </noscript> 84 | <h2>框架预警</h2> 85 | <p>请使用框架功能查看此文档。如果看到此消息, 则表明您使用的是不支持框架的 Web 客户机。链接到<a href="com/tmall/wireless/alpha/package-summary.html">非框架版本</a>。</p> 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /alpha/docs/overview-tree.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 类分层结构 24 | 25 | 26 | 27 | 28 | 34 | 37 | 38 |
39 | 40 | 41 | 42 | 43 | 51 |
52 | 79 | 80 |
81 |

所有程序包的分层结构

82 | 程序包分层结构: 83 | 86 |
87 |
88 |

类分层结构

89 | 100 |

接口分层结构

101 | 104 |
105 | 106 |
107 | 108 | 109 | 110 | 111 | 119 |
120 | 147 | 148 | 149 | 150 | -------------------------------------------------------------------------------- /alpha/docs/package-list: -------------------------------------------------------------------------------- 1 | com.tmall.wireless.alpha 2 | -------------------------------------------------------------------------------- /alpha/docs/resources/background.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alibaba/alpha/04fe7f22c469de66fed98c341334c954dfabafb2/alpha/docs/resources/background.gif -------------------------------------------------------------------------------- /alpha/docs/resources/tab.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alibaba/alpha/04fe7f22c469de66fed98c341334c954dfabafb2/alpha/docs/resources/tab.gif -------------------------------------------------------------------------------- /alpha/docs/resources/titlebar.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alibaba/alpha/04fe7f22c469de66fed98c341334c954dfabafb2/alpha/docs/resources/titlebar.gif -------------------------------------------------------------------------------- /alpha/docs/resources/titlebar_end.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alibaba/alpha/04fe7f22c469de66fed98c341334c954dfabafb2/alpha/docs/resources/titlebar_end.gif -------------------------------------------------------------------------------- /alpha/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/shangjie/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | -keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | public *; 17 | } 18 | -------------------------------------------------------------------------------- /alpha/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /alpha/src/main/java/com/alibaba/android/alpha/AlphaConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Alibaba Group. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.alibaba.android.alpha; 18 | 19 | import android.content.Context; 20 | 21 | import java.util.concurrent.ExecutorService; 22 | import java.util.concurrent.LinkedBlockingQueue; 23 | import java.util.concurrent.ThreadFactory; 24 | import java.util.concurrent.ThreadPoolExecutor; 25 | import java.util.concurrent.TimeUnit; 26 | import java.util.concurrent.atomic.AtomicInteger; 27 | 28 | /** 29 | *

Alpha的配置类

30 | * Created by zhangshuliang.zsl on 15/10/30. 31 | */ 32 | public class AlphaConfig { 33 | 34 | /** 35 | * 日志输出开关,默认是打开的 36 | */ 37 | private static boolean sIsLoggable = true; 38 | private static int sCoreThreadNum = Runtime.getRuntime().availableProcessors(); 39 | private static ThreadFactory sThreadFactory; 40 | private static ExecutorService sExecutor; 41 | private static int sWarningTime = 400; 42 | private static boolean sShowToastToAlarm = false; 43 | private static Context sContext; 44 | 45 | //============================================================================================== 46 | // PUBLIC API 47 | //============================================================================================== 48 | 49 | /** 50 | * 设置执行{@code task}的线程池的核心线程数,默认是CPU数。 51 | * 52 | * @param coreThreadNum 核心线程数 53 | */ 54 | public static void setCoreThreadNum(int coreThreadNum) { 55 | sCoreThreadNum = coreThreadNum; 56 | } 57 | 58 | /** 59 | * 设置执行{@code task}的线程池的{@code ThreadFactory},默认会有一个{@code ThreadFactory},将创建的 60 | * {@code Thread}命名为“Alpha Thread #num”。 61 | * 62 | * @param threadFactory 执行{@code task}的线程池的{@code ThreadFactory} 63 | */ 64 | public static void setThreadFactory(ThreadFactory threadFactory) { 65 | sThreadFactory = threadFactory; 66 | } 67 | 68 | /** 69 | * 设置执行{@code task}的线程池,默认线程池,核心线程池数是CPU数,缓存队列无穷大。包括核心线程在内,当线程空闲 70 | * 超过1分钟,会将线程释放。 71 | * 72 | * @param executorService 执行{@code task}的线程池 73 | */ 74 | public static void setExecutorService(ExecutorService executorService) { 75 | sExecutor = executorService; 76 | } 77 | 78 | /** 79 | * 设置日志输出开关,默认是打开的 80 | * @param isLoggable {@code true}开启日志,否则关闭日志。 81 | */ 82 | public static void setLoggable(boolean isLoggable) { 83 | sIsLoggable = isLoggable; 84 | } 85 | 86 | /** 87 | * 设置{@code task}执行时间的境界值,超过这个警戒值,则会通过toast来告警。默认值是400毫秒。 88 | * 89 | * @param warningTime {@code task}执行时间的境界值 90 | */ 91 | public static void setWarningTime(int warningTime) { 92 | sWarningTime = warningTime; 93 | } 94 | 95 | /** 96 | * 设置是否通过弹出toast来告警,默认值是{@code false}。 97 | * 98 | * @param context show toast需要Context实例。 99 | * @param showToastToAlarm {@code true}会弹出toast来告警,否则不会。 100 | */ 101 | public static void setShowToastToAlarm(Context context, boolean showToastToAlarm) { 102 | sContext = context; 103 | sShowToastToAlarm = showToastToAlarm; 104 | } 105 | 106 | 107 | //============================================================================================== 108 | // INNER API 109 | //============================================================================================== 110 | 111 | /*package*/ static boolean isLoggable() { 112 | return sIsLoggable; 113 | } 114 | 115 | /*package*/ static ThreadFactory getThreadFactory() { 116 | if (sThreadFactory == null) { 117 | sThreadFactory = getDefaultThreadFactory(); 118 | } 119 | 120 | return sThreadFactory; 121 | } 122 | 123 | /*package*/ static ExecutorService getExecutor() { 124 | if (sExecutor == null) { 125 | sExecutor = getDefaultExecutor(); 126 | } 127 | 128 | return sExecutor; 129 | } 130 | 131 | /*package*/ static int getWarmingTime() { 132 | return sWarningTime; 133 | } 134 | 135 | /*package*/ static boolean shouldShowToastToAlarm() { 136 | return sShowToastToAlarm; 137 | } 138 | 139 | /*package*/ static Context getContext() { 140 | return sContext; 141 | } 142 | 143 | 144 | private static ThreadFactory getDefaultThreadFactory() { 145 | ThreadFactory defaultFactory = new ThreadFactory() { 146 | private final AtomicInteger mCount = new AtomicInteger(1); 147 | 148 | public Thread newThread(Runnable r) { 149 | return new Thread(r, "Alpha Thread #" + mCount.getAndIncrement()); 150 | } 151 | }; 152 | 153 | return defaultFactory; 154 | } 155 | 156 | //============================================================================================== 157 | // PRIVATE METHOD 158 | //============================================================================================== 159 | 160 | private static ExecutorService getDefaultExecutor() { 161 | ThreadPoolExecutor executor = new ThreadPoolExecutor(sCoreThreadNum, sCoreThreadNum, 162 | 60L, TimeUnit.SECONDS, 163 | new LinkedBlockingQueue(), 164 | getThreadFactory()); 165 | executor.allowCoreThreadTimeOut(true); 166 | 167 | return executor; 168 | } 169 | } 170 | -------------------------------------------------------------------------------- /alpha/src/main/java/com/alibaba/android/alpha/AlphaLog.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Alibaba Group. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.alibaba.android.alpha; 18 | 19 | import android.util.Log; 20 | 21 | /** 22 | *

日志输出类,其函数和{@link Log}基本一致。

23 | * 24 | * Created by zhangshuliang.zsl on 15/8/24. 25 | */ 26 | public class AlphaLog { 27 | 28 | /** 29 | * 全局的日志过滤tag,{@code Alpha}库输出的日志,都可以用该tag过滤 30 | */ 31 | public static final String GLOBAL_TAG = "==ALPHA=="; 32 | 33 | public static void d(String tag, Object obj) { 34 | if (AlphaConfig.isLoggable()) { 35 | Log.d(tag, obj.toString()); 36 | } 37 | } 38 | 39 | public static void d(String tag, String msg, Object... args) { 40 | if (AlphaConfig.isLoggable()) { 41 | String formattedMsg = String.format(msg, args); 42 | Log.d(tag, formattedMsg); 43 | } 44 | } 45 | 46 | public static void d(String msg, Object... args) { 47 | d(GLOBAL_TAG, msg, args); 48 | } 49 | 50 | public static void e(String tag, Object obj) { 51 | if (AlphaConfig.isLoggable()) { 52 | Log.e(tag, obj.toString()); 53 | } 54 | } 55 | 56 | 57 | public static void e(String tag, String msg, Object... args) { 58 | if (AlphaConfig.isLoggable()) { 59 | String formattedMsg = String.format(msg, args); 60 | Log.e(tag, formattedMsg); 61 | } 62 | } 63 | 64 | 65 | public static void i(String tag, Object obj) { 66 | if (AlphaConfig.isLoggable()) { 67 | Log.i(tag, obj.toString()); 68 | } 69 | } 70 | 71 | public static void w(Exception e) { 72 | if (AlphaConfig.isLoggable()) { 73 | e.printStackTrace(); 74 | } 75 | } 76 | 77 | public static void print(Object msg) { 78 | d(GLOBAL_TAG, msg); 79 | } 80 | 81 | public static void print(String msg, Object... args) { 82 | d(GLOBAL_TAG, msg, args); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /alpha/src/main/java/com/alibaba/android/alpha/AlphaUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Alibaba Group. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.alibaba.android.alpha; 18 | 19 | import android.app.ActivityManager; 20 | import android.content.Context; 21 | import android.database.Cursor; 22 | import android.text.TextUtils; 23 | 24 | import java.io.Closeable; 25 | import java.io.FileInputStream; 26 | import java.util.Collections; 27 | import java.util.Comparator; 28 | import java.util.List; 29 | 30 | import static com.alibaba.android.alpha.AlphaManager.ALL_PROCESS_MODE; 31 | import static com.alibaba.android.alpha.AlphaManager.MAIN_PROCESS_MODE; 32 | import static com.alibaba.android.alpha.AlphaManager.SECONDARY_PROCESS_MODE; 33 | 34 | /** 35 | *

通用工具类。

36 | * 37 | * Created by zhangshuliang.zsl on 15/8/27. 38 | */ 39 | public class AlphaUtils { 40 | 41 | private static Comparator sTaskComparator = new Comparator() { 42 | @Override 43 | public int compare(Task lhs, Task rhs) { 44 | return lhs.getExecutePriority() - rhs.getExecutePriority(); 45 | } 46 | }; 47 | 48 | /** 49 | * 根据{@code task}的执行优先级,对其进行排序。 50 | * 51 | * @param tasks 需要排序的task列表 52 | */ 53 | public static void sort(List tasks) { 54 | if (tasks.size() <= 1) { 55 | return; 56 | } 57 | 58 | Collections.sort(tasks, sTaskComparator); 59 | } 60 | 61 | /** 62 | * Close a {@link Closeable} object safely. 63 | * 64 | * @param closeable Object to close. 65 | * @return True close successfully, false otherwise. 66 | */ 67 | public static boolean closeSafely(Closeable closeable) { 68 | 69 | if (closeable == null) { 70 | return false; 71 | } 72 | 73 | boolean ret = false; 74 | 75 | try { 76 | closeable.close(); 77 | ret = true; 78 | } catch (Exception e) { 79 | AlphaLog.w(e); 80 | } 81 | 82 | return ret; 83 | } 84 | 85 | 86 | /** 87 | * Close a {@link Cursor} object safely. 88 | * 89 | * @param cursor to close cursor 90 | * {@link Cursor} is not a {@link Closeable} until 4.1.1, so we should supply this method to 91 | * close {@link Cursor} beside {@link #closeSafely(Closeable)} 92 | * @return true is close successfully, false otherwise. 93 | */ 94 | public static boolean closeSafely(Cursor cursor) { 95 | if (cursor == null) { 96 | return false; 97 | } 98 | 99 | boolean ret = false; 100 | 101 | try { 102 | cursor.close(); 103 | ret = true; 104 | } catch (Exception e) { 105 | AlphaLog.w(e); 106 | } 107 | 108 | return ret; 109 | } 110 | 111 | private static String sProcessName; 112 | 113 | /** 114 | * @param context The context used to get process name. 115 | * @return Name of current process. 116 | */ 117 | public static String getCurrProcessName(Context context) { 118 | String name = getCurrentProcessNameViaLinuxFile(); 119 | 120 | if (TextUtils.isEmpty(name) && context != null) { 121 | name = getCurrentProcessNameViaActivityManager(context); 122 | } 123 | 124 | return name; 125 | } 126 | 127 | /** 128 | * Check if current process is main process. 129 | * 130 | * @param context The context used check if main process. 131 | * @return True if current process is main process, false otherwise. 132 | */ 133 | public static boolean isInMainProcess(Context context) { 134 | String mainProcessName = context.getPackageName(); 135 | String currentProcessName = getCurrProcessName(context); 136 | return mainProcessName != null && mainProcessName.equalsIgnoreCase(currentProcessName); 137 | } 138 | 139 | private static String getCurrentProcessNameViaLinuxFile() { 140 | int pid = android.os.Process.myPid(); 141 | String line = "/proc/" + pid + "/cmdline"; 142 | FileInputStream fis = null; 143 | String processName = null; 144 | byte[] bytes = new byte[1024]; 145 | int read = 0; 146 | 147 | try { 148 | fis = new FileInputStream(line); 149 | read = fis.read(bytes); 150 | } catch (Exception e) { 151 | AlphaLog.w(e); 152 | } finally { 153 | AlphaUtils.closeSafely(fis); 154 | } 155 | 156 | if (read > 0) { 157 | processName = new String(bytes, 0, read); 158 | processName = processName.trim(); 159 | } 160 | 161 | return processName; 162 | } 163 | 164 | private static String getCurrentProcessNameViaActivityManager(Context context) { 165 | if (context == null) { 166 | return null; 167 | } 168 | if (sProcessName != null) { 169 | return sProcessName; 170 | } 171 | int pid = android.os.Process.myPid(); 172 | ActivityManager mActivityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); 173 | if (mActivityManager == null) { 174 | return null; 175 | } 176 | List processes = mActivityManager.getRunningAppProcesses(); 177 | if (processes == null) { 178 | return null; 179 | } 180 | for (ActivityManager.RunningAppProcessInfo appProcess : processes) { 181 | if (appProcess != null && appProcess.pid == pid) { 182 | sProcessName = appProcess.processName; 183 | break; 184 | } 185 | } 186 | return sProcessName; 187 | } 188 | 189 | /** 190 | * 在{@link AlphaManager#addProject(Task, String)}中进行这个判断,只有进程名和当前进程相同,才有必要去持有该{@code Project}. 191 | * 192 | * @param context The context used to check process. 193 | * @param processName 需要配置启动{@code Project}的进程名 194 | * @return 进程名是否和当前进程名一致,符合返回{@code true},否则返回{@code false}。 195 | */ 196 | public static boolean isMatchProcess(Context context, String processName) { 197 | String currentProcessName = AlphaUtils.getCurrProcessName(context); 198 | return TextUtils.equals(processName, currentProcessName); 199 | } 200 | 201 | /** 202 | * 在{@link AlphaManager#addProject(Task, String)}中进行这个判断,只有当前进程命中指定的{@code mode},才有必要去持有该{@code 203 | * Project}. 204 | * 205 | * @param context The context used to check process. 206 | * @param mode 启动{@code Project}的模式 207 | * @return 当前进程是否符合该种模式,符合返回{@code true},否则返回{@code false}。 208 | */ 209 | public static boolean isMatchMode(Context context, int mode) { 210 | if (mode == ALL_PROCESS_MODE) { 211 | return true; 212 | } 213 | 214 | if (AlphaUtils.isInMainProcess(context) && mode == MAIN_PROCESS_MODE) { 215 | return true; 216 | } 217 | 218 | if (!AlphaUtils.isInMainProcess(context) && mode == SECONDARY_PROCESS_MODE) { 219 | return true; 220 | } 221 | 222 | return false; 223 | } 224 | 225 | 226 | } 227 | -------------------------------------------------------------------------------- /alpha/src/main/java/com/alibaba/android/alpha/ExecuteMonitor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Alibaba Group. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.alibaba.android.alpha; 18 | 19 | import android.os.Handler; 20 | import android.os.Looper; 21 | import android.widget.Toast; 22 | 23 | import java.util.HashMap; 24 | import java.util.Map; 25 | 26 | /** 27 | *

监控{@code Project}执行性能的类。会记录每一个{@code Task}执行时间,以及整个{@code Project}执行时间。

28 | * Created by zhangshuliang.zsl on 15/11/4. 29 | */ 30 | class ExecuteMonitor { 31 | private Map mExecuteTimeMap = new HashMap(); 32 | private long mStartTime; 33 | private long mProjectCostTime; 34 | private Handler mHandler; 35 | 36 | /** 37 | * 记录{@code task}执行时间。 38 | * 39 | * @param taskName {@code task}的名称 40 | * @param executeTime 执行的时间 41 | */ 42 | public synchronized void record(String taskName, long executeTime) { 43 | AlphaLog.d(AlphaLog.GLOBAL_TAG, "AlphaTask-->Startup task %s cost time: %s ms, in thread: %s", taskName, executeTime, Thread.currentThread().getName()); 44 | if (executeTime >= AlphaConfig.getWarmingTime()) { 45 | toastToWarn("AlphaTask %s run too long, cost time: %s", taskName, executeTime); 46 | } 47 | 48 | mExecuteTimeMap.put(taskName, executeTime); 49 | } 50 | 51 | /** 52 | * @return 已执行完的每个task的执行时间。 53 | */ 54 | public synchronized Map getExecuteTimeMap() { 55 | return mExecuteTimeMap; 56 | } 57 | 58 | /** 59 | * 在{@code Project}开始执行时打点,记录开始时间。 60 | */ 61 | public void recordProjectStart() { 62 | mStartTime = System.currentTimeMillis(); 63 | } 64 | 65 | /** 66 | * 在{@code Project}结束时打点,记录耗时。 67 | */ 68 | public void recordProjectFinish() { 69 | mProjectCostTime = System.currentTimeMillis() - mStartTime; 70 | AlphaLog.d("==ALPHA==", "tm start up cost time: %s ms", mProjectCostTime); 71 | } 72 | 73 | 74 | /** 75 | * @return {@code Project}执行时间。 76 | */ 77 | public long getProjectCostTime() { 78 | return mProjectCostTime; 79 | } 80 | 81 | /** 82 | * 通过弹出{@code toast}来告警。 83 | * 84 | * @param msg 告警内容 85 | * @param args format参数 86 | */ 87 | private void toastToWarn(final String msg, final Object... args) { 88 | if (AlphaConfig.shouldShowToastToAlarm()) { 89 | getHandler().post(new Runnable() { 90 | @Override 91 | public void run() { 92 | String formattedMsg; 93 | 94 | if (args == null) { 95 | formattedMsg = msg; 96 | } else { 97 | formattedMsg = String.format(msg, args); 98 | } 99 | 100 | Toast.makeText(AlphaConfig.getContext(), formattedMsg, Toast.LENGTH_SHORT).show(); 101 | } 102 | }); 103 | } 104 | } 105 | 106 | private Handler getHandler() { 107 | if (mHandler == null) { 108 | mHandler = new Handler(Looper.getMainLooper()); 109 | } 110 | 111 | return mHandler; 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /alpha/src/main/java/com/alibaba/android/alpha/ITaskCreator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Alibaba Group. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.alibaba.android.alpha; 18 | 19 | /** 20 | * Created by shangjie on 2018/10/19. 21 | */ 22 | 23 | public interface ITaskCreator { 24 | /** 25 | * 根据Task名称,创建Task实例。这个接口需要使用者自己实现。创建后的实例会被缓存起来。 26 | * @param taskName Task名称 27 | * @return Task实例 28 | */ 29 | public Task createTask(String taskName); 30 | } 31 | -------------------------------------------------------------------------------- /alpha/src/main/java/com/alibaba/android/alpha/ListMultiMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Alibaba Group. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.alibaba.android.alpha; 18 | 19 | import java.util.ArrayList; 20 | import java.util.HashMap; 21 | import java.util.List; 22 | import java.util.Map; 23 | 24 | /** 25 | *

在编码过程中,我们通常会有这样的需要{@code Map>}这样的数据结构,{@code ListMultiMap} 26 | * 就是对这类结构的封装,简化对它的使用。

27 | *

注意:目前{@code ListMultiMap}不是一个{@code Map}类型。

28 | * Created by zhangshuliang.zsl on 15/9/30. 29 | */ 30 | public class ListMultiMap { 31 | private HashMap> mInnerMap = new HashMap>(); 32 | private int mSize = 0; 33 | 34 | /** 35 | * 清除结构中的所有元素 36 | */ 37 | public void clear() { 38 | mInnerMap.clear(); 39 | mSize = 0; 40 | } 41 | 42 | /** 43 | * 判断是否包含某一个{@code key} 44 | * 45 | * @param key 需要判断的{@code key} 46 | * @return {@code true}如果{@code key}存在,否则返回{@code false}。 47 | */ 48 | public boolean containsKey(K key) { 49 | return mInnerMap.containsKey(key); 50 | } 51 | 52 | /** 53 | * 判断是否包含某一个{@code value} 54 | * 55 | * @param value 需要判断的{@code value} 56 | * @return {@code true}如果{@code value}存在,否则表示不存在。 57 | */ 58 | public boolean containsValue(V value) { 59 | for (Map.Entry> entry : mInnerMap.entrySet()) { 60 | List values = entry.getValue(); 61 | 62 | if (values != null && values.contains(value)) { 63 | return true; 64 | } 65 | } 66 | 67 | return false; 68 | } 69 | 70 | /** 71 | * 判断是否包含某一对key-value。 72 | * 73 | * @param key 需要判断的{@code key} 74 | * @param value 需要判断的{@code value} 75 | * @return {@code true}如果{@code value}存在,否则表示不存在。 76 | */ 77 | public boolean contains(K key, V value) { 78 | if (!containsKey(key)) { 79 | return false; 80 | } 81 | 82 | List list = get(key); 83 | 84 | if (list == null || list.isEmpty()) { 85 | return false; 86 | } 87 | 88 | return list.contains(value); 89 | } 90 | 91 | /** 92 | * 获取符合该{@code key}的所有{@code value}。 93 | * 94 | * @param key 指定的{@code key}。 95 | * @return 符合该{@code key}的所有{@code value}。 96 | */ 97 | public List get(K key) { 98 | return mInnerMap.get(key); 99 | } 100 | 101 | 102 | /** 103 | * 判断数据结构是否元素为空。 104 | * 105 | * @return {@code true}元素是空的,否则返回{@code false}。 106 | */ 107 | public boolean isEmpty() { 108 | return mSize <= 0; 109 | } 110 | 111 | 112 | /** 113 | * 将一对K-V值插入到数据结构中。 114 | * 115 | * @param key key 116 | * @param value value 117 | */ 118 | public void put(K key, V value) { 119 | if (mInnerMap.containsKey(key)) { 120 | List list = mInnerMap.get(key); 121 | list.add(value); 122 | } else { 123 | List list = new ArrayList(); 124 | list.add(value); 125 | mInnerMap.put(key, list); 126 | } 127 | 128 | mSize++; 129 | } 130 | 131 | 132 | /** 133 | * 移除该{@code key}所对应的所有{@code value} 134 | * 135 | * @param key 要删除的key 136 | * @return 返回删除的元素列表,若没有该key对应的元素,则返回null。 137 | */ 138 | public List remove(K key) { 139 | List list = mInnerMap.remove(key); 140 | 141 | if (list != null && !list.isEmpty()) { 142 | mSize -= list.size(); 143 | } 144 | 145 | return list; 146 | } 147 | 148 | /** 149 | * 移除该{@code key}所对应的{@code list}中的{@code value} 150 | * 151 | * @param key 要删除的key 152 | * @param value 要删除的{@code value} 153 | * @return 被删除的value,不包含该value,则返回null。 154 | */ 155 | public V remove(K key, V value) { 156 | List list = mInnerMap.get(key); 157 | V ret = null; 158 | 159 | if (list != null && !list.isEmpty()) { 160 | boolean isRemoved = list.remove(value); 161 | 162 | if (isRemoved) { 163 | mSize--; 164 | ret = value; 165 | } 166 | } 167 | 168 | return ret; 169 | } 170 | 171 | 172 | /** 173 | * 从所有{@code List}中删除指定{@code value}。 174 | * 175 | * @param value 要删除的{@code value} 176 | * @return 被删除的value,不包含该value,则返回null。 177 | */ 178 | public V removeValue(V value) { 179 | boolean contains = false; 180 | 181 | for (Map.Entry> entry : mInnerMap.entrySet()) { 182 | List values = entry.getValue(); 183 | 184 | if (values != null && values.contains(value)) { 185 | values.remove(value); 186 | contains = true; 187 | mSize--; 188 | } 189 | } 190 | 191 | return contains ? value : null; 192 | } 193 | 194 | 195 | /** 196 | * @return 数据结构中总共的{@code value}数。 197 | */ 198 | public int size() { 199 | return mSize; 200 | } 201 | 202 | /** 203 | * @return 将内容转换成字符串返回。 204 | */ 205 | public String toString() { 206 | return mInnerMap.toString(); 207 | } 208 | 209 | } 210 | -------------------------------------------------------------------------------- /alpha/src/main/java/com/alibaba/android/alpha/OnGetMonitorRecordCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Alibaba Group. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.alibaba.android.alpha; 18 | 19 | import java.util.Map; 20 | 21 | /** 22 | *

获取{@code Project}执行性能记录的回调

23 | * Created by zhangshuliang.zsl on 15/11/4. 24 | */ 25 | public interface OnGetMonitorRecordCallback { 26 | 27 | /** 28 | * 获取{@code task}执行的耗时。 29 | * @param result {@code task}执行的耗时。{@code key}是{@code task}名称,{@code value}是{@code task}执行耗时,单位是毫秒。 30 | */ 31 | public void onGetTaskExecuteRecord(Map result); 32 | 33 | /** 34 | * 获取整个{@code Project}执行耗时。 35 | * @param costTime 整个{@code Project}执行耗时。 36 | */ 37 | public void onGetProjectExecuteTime(long costTime); 38 | } 39 | -------------------------------------------------------------------------------- /alpha/src/main/java/com/alibaba/android/alpha/OnProjectExecuteListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Alibaba Group. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.alibaba.android.alpha; 18 | 19 | /** 20 | *

21 | * {@code Project}执行生命周期的回调。
22 | * 注意:回调接口要考虑线程安全问题。 23 | *

24 | * 25 | * Created by zhangshuliang.zsl on 15/9/30. 26 | */ 27 | public interface OnProjectExecuteListener { 28 | 29 | /** 30 | * 当{@code Project}开始执行时,调用该函数。
31 | * 注意:该回调函数在{@code Task}所在线程中回调,注意线程安全。 32 | */ 33 | public void onProjectStart(); 34 | 35 | 36 | /** 37 | * 当{@code Project}其中一个{@code Task}执行结束时,调用该函数。
38 | * 注意:该回调函数在{@code Task}所在线程中回调,注意线程安全。 39 | * 40 | * @param taskName 当前结束的{@code Task}名称 41 | */ 42 | public void onTaskFinish(String taskName); 43 | 44 | /** 45 | * 当{@code Project}执行结束时,调用该函数。
46 | * 注意:该回调函数在{@code Task}所在线程中回调,注意线程安全。 47 | */ 48 | public void onProjectFinish(); 49 | } 50 | -------------------------------------------------------------------------------- /alpha/src/main/java/com/alibaba/android/alpha/TaskFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Alibaba Group. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.alibaba.android.alpha; 18 | 19 | import java.util.HashMap; 20 | import java.util.Map; 21 | 22 | /** 23 | * Created by shangjie on 2018/10/19. 24 | */ 25 | 26 | public final class TaskFactory { 27 | private Map mTasks = new HashMap<>(); 28 | private ITaskCreator mTaskCreator; 29 | 30 | public TaskFactory(ITaskCreator creator) { 31 | mTaskCreator = creator; 32 | } 33 | 34 | public synchronized Task getTask(String taskName) { 35 | Task task = mTasks.get(taskName); 36 | 37 | if (task != null) { 38 | return task; 39 | } 40 | 41 | task = mTaskCreator.createTask(taskName); 42 | 43 | if (task == null) { 44 | throw new IllegalArgumentException("Create task fail, there is no task corresponding to the task name. Make sure you have create a task instance in TaskCreator."); 45 | } 46 | 47 | mTasks.put(taskName, task); 48 | return task; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /alpha/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | Alpha 19 | 20 | -------------------------------------------------------------------------------- /alpha_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alibaba/alpha/04fe7f22c469de66fed98c341334c954dfabafb2/alpha_logo.png -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | mavenLocal() 6 | jcenter() 7 | maven { 8 | url 'https://maven.google.com/' 9 | name 'Google' 10 | } 11 | } 12 | dependencies { 13 | classpath 'com.android.tools.build:gradle:3.0.1' 14 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3' 15 | } 16 | } 17 | 18 | allprojects { 19 | repositories { 20 | mavenLocal() 21 | jcenter() 22 | maven { 23 | url 'https://maven.google.com/' 24 | name 'Google' 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alibaba/alpha/04fe7f22c469de66fed98c341334c954dfabafb2/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Oct 22 14:21:04 CST 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Alibaba Group. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | apply plugin: 'com.android.application' 18 | 19 | android { 20 | compileSdkVersion 22 21 | buildToolsVersion "22.0.1" 22 | 23 | defaultConfig { 24 | applicationId "com.alibaba.android.alpha" 25 | minSdkVersion 14 26 | targetSdkVersion 22 27 | versionCode 1 28 | versionName "1.0" 29 | } 30 | buildTypes { 31 | release { 32 | minifyEnabled true 33 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 34 | } 35 | } 36 | } 37 | 38 | dependencies { 39 | compile fileTree(dir: 'libs', include: ['*.jar']) 40 | compile 'com.android.support:appcompat-v7:22.2.0' 41 | // compile project(':alpha') 42 | compile ('com.alibaba.android:alpha:1.0.0.1@aar') 43 | } 44 | -------------------------------------------------------------------------------- /sample/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alibaba/alpha/04fe7f22c469de66fed98c341334c954dfabafb2/sample/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /sample/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Aug 24 18:04:39 CST 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip 7 | -------------------------------------------------------------------------------- /sample/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /sample/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /sample/local.properties: -------------------------------------------------------------------------------- 1 | ## This file is automatically generated by Android Studio. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must *NOT* be checked into Version Control Systems, 5 | # as it contains information specific to your local configuration. 6 | # 7 | # Location of the SDK. This is only used by Gradle. 8 | # For customization when using a Version Control System, please read the 9 | # header note. 10 | #Fri Aug 24 18:04:37 CST 2018 11 | ndk.dir=/Users/shangjie/Library/Android/sdk/ndk-bundle 12 | sdk.dir=/Users/shangjie/Library/Android/sdk 13 | -------------------------------------------------------------------------------- /sample/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/shangjie/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | #-keepattributes Keep 19 | -keep class com.wireless.wireless.alpha.Keep extends java.lang.annotation.Annotation { *; } 20 | -keep interface * extends java.lang.annotation.Annotation { *; } 21 | -keepattributes *Annotation* 22 | -keepattributes *com.wireless.wireless.alpha.Keep* 23 | #-keepclasseswithmembers class * { @com.wireless.wireless.alpha.Keep *; } 24 | #-keep @com.wireless.wireless.alpha.Keep class * { *; } 25 | #-keepclasseswithmembers class * { @com.wireless.wireless.alpha.Keep ; } 26 | #-keepclasseswithmembers class * { @com.wireless.wireless.alpha.Keep ; } 27 | -keepclasseswithmembers class * { @com.wireless.wireless.alpha.Keep (...); } -------------------------------------------------------------------------------- /sample/sample-release.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alibaba/alpha/04fe7f22c469de66fed98c341334c954dfabafb2/sample/sample-release.apk -------------------------------------------------------------------------------- /sample/sample.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alibaba/alpha/04fe7f22c469de66fed98c341334c954dfabafb2/sample/sample.apk -------------------------------------------------------------------------------- /sample/src/androidTest/java/com/tmall/wireless/alpha/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Alibaba Group. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.tmall.wireless.alpha; 18 | 19 | import android.app.Application; 20 | import android.test.ApplicationTestCase; 21 | 22 | /** 23 | * Testing Fundamentals 24 | */ 25 | public class ApplicationTest extends ApplicationTestCase { 26 | public ApplicationTest() { 27 | super(Application.class); 28 | } 29 | } -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 20 | 21 | 26 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /sample/src/main/assets/tasklist.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 20 | 24 | 25 | 29 | 30 | 35 | 36 | 41 | 42 | 45 | 46 | 47 | 48 | 49 | 50 | 55 | 56 | 61 | 62 | 63 | 64 | 65 | 66 | 68 | 71 | 72 | 76 | 77 | 82 | 83 | 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /sample/src/main/java/com/alibaba/android/alpha/ConfigTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Alibaba Group. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.alibaba.android.alpha; 18 | 19 | import android.content.Context; 20 | import android.util.Log; 21 | 22 | import java.util.Map; 23 | 24 | /** 25 | * Created by zhangshuliang.zsl on 15/8/24. 26 | */ 27 | 28 | public class ConfigTest { 29 | private static final String TAG = "StartUpConfig"; 30 | private Context mContext; 31 | 32 | private OnProjectExecuteListener mOnProjectExecuteListener; 33 | 34 | public ConfigTest(Context context) { 35 | mContext = context; 36 | } 37 | 38 | public void start() { 39 | config(); 40 | MyLog.e("==ALPHA==", "start -->" + System.currentTimeMillis()); 41 | AlphaManager.getInstance(mContext).start(); 42 | } 43 | 44 | public void setOnProjectExecuteListener(OnProjectExecuteListener listener) { 45 | mOnProjectExecuteListener = listener; 46 | } 47 | 48 | 49 | private void config() { 50 | 51 | 52 | Project.Builder builder = new Project.Builder().withTaskCreator(new MyTaskCreator()); 53 | builder.add(TASK_A); 54 | builder.add(TASK_B).after(TASK_A); 55 | builder.add(TASK_C).after(TASK_A); 56 | builder.add(TASK_D).after(TASK_B, TASK_C); 57 | builder.setProjectName("innerGroup"); 58 | 59 | builder.setOnProjectExecuteListener(new OnProjectExecuteListener() { 60 | @Override 61 | public void onProjectStart() { 62 | MyLog.print("project start"); 63 | } 64 | 65 | @Override 66 | public void onTaskFinish(String taskName) { 67 | MyLog.print("project task finish: %s", taskName); 68 | } 69 | 70 | @Override 71 | public void onProjectFinish() { 72 | MyLog.print("project finish."); 73 | } 74 | }); 75 | 76 | builder.setOnGetMonitorRecordCallback(new OnGetMonitorRecordCallback() { 77 | @Override 78 | public void onGetTaskExecuteRecord(Map result) { 79 | MyLog.print("monitor result: %s", result); 80 | } 81 | 82 | @Override 83 | public void onGetProjectExecuteTime(long costTime) { 84 | MyLog.print("monitor time: %s", costTime); 85 | } 86 | }); 87 | 88 | Project group = builder.create(); 89 | 90 | group.addOnTaskFinishListener(new Task.OnTaskFinishListener() { 91 | @Override 92 | public void onTaskFinish(String taskName) { 93 | MyLog.print("task group finish"); 94 | } 95 | }); 96 | 97 | 98 | builder.add(TASK_E); 99 | builder.add(group).after(TASK_E); 100 | builder.setOnGetMonitorRecordCallback(new OnGetMonitorRecordCallback() { 101 | @Override 102 | public void onGetTaskExecuteRecord(Map result) { 103 | MyLog.print("monitor result: %s", result); 104 | } 105 | 106 | @Override 107 | public void onGetProjectExecuteTime(long costTime) { 108 | MyLog.print("monitor time: %s", costTime); 109 | } 110 | }); 111 | 112 | if (mOnProjectExecuteListener != null) { 113 | builder.setOnProjectExecuteListener(mOnProjectExecuteListener); 114 | } 115 | 116 | AlphaManager.getInstance(mContext).addProject(builder.create()); 117 | 118 | // try { 119 | // AlphaManager.getInstance(mContext).addProjectsViaFile(mContext.getAssets().open("tasklist.xml")); 120 | // } catch (Exception e) { 121 | // AlphaLog.w(e); 122 | // } 123 | 124 | } 125 | 126 | private static final String TASK_A = "TaskA"; 127 | private static final String TASK_B = "TaskB"; 128 | private static final String TASK_C = "TaskC"; 129 | private static final String TASK_D = "TaskD"; 130 | private static final String TASK_E = "TaskE"; 131 | private static final String TASK_F = "TaskF"; 132 | private static final String TASK_G = "TaskG"; 133 | public static class MyTaskCreator implements ITaskCreator { 134 | @Override 135 | public Task createTask(String taskName) { 136 | Log.d("==ALPHA==", taskName); 137 | switch (taskName) { 138 | case TASK_A: 139 | return new TaskA(); 140 | case TASK_B: 141 | return new TaskB(); 142 | case TASK_C: 143 | return new TaskC(); 144 | case TASK_D: 145 | return new TaskD(); 146 | case TASK_E: 147 | return new TaskE(); 148 | case TASK_F: 149 | return new TaskF(); 150 | case TASK_G: 151 | return new TaskG(); 152 | } 153 | 154 | return null; 155 | } 156 | } 157 | 158 | public static class TaskA extends Task { 159 | public TaskA() { 160 | super(TASK_A); 161 | } 162 | 163 | @Override 164 | public void run() { 165 | MyLog.d(TAG, "run task A in " + Thread.currentThread().getName()); 166 | 167 | 168 | } 169 | } 170 | 171 | public static class TaskB extends Task { 172 | public TaskB() { 173 | super(TASK_B); 174 | setExecutePriority(9); 175 | } 176 | 177 | @Override 178 | public void run() { 179 | try { 180 | Thread.sleep(1000); 181 | } catch (Exception e) { 182 | e.printStackTrace(); 183 | } 184 | 185 | MyLog.d(TAG, "run task B in " + Thread.currentThread().getName()); 186 | } 187 | } 188 | 189 | 190 | public static class TaskC extends Task { 191 | public TaskC() { 192 | super(TASK_C); 193 | setExecutePriority(1); 194 | } 195 | 196 | @Override 197 | public void run() { 198 | MyLog.d(TAG, "run task C in " + Thread.currentThread().getName()); 199 | } 200 | } 201 | 202 | 203 | public static class TaskD extends Task { 204 | public TaskD() { 205 | super(TASK_D); 206 | } 207 | 208 | @Override 209 | public void run() { 210 | MyLog.d(TAG, "run task D in " + Thread.currentThread().getName()); 211 | } 212 | } 213 | 214 | public static class TaskE extends Task { 215 | public TaskE() { 216 | super(TASK_E, true); 217 | } 218 | 219 | @Override 220 | public void run() { 221 | MyLog.d(TAG, "run task E in " + Thread.currentThread().getName()); 222 | } 223 | } 224 | 225 | public static class TaskF extends Task { 226 | public TaskF() { 227 | super(TASK_F); 228 | } 229 | 230 | @Override 231 | public void run() { 232 | MyLog.d(TAG, "run task F in " + Thread.currentThread().getName()); 233 | } 234 | } 235 | 236 | public static class TaskG extends Task { 237 | public TaskG() { 238 | super(TASK_G); 239 | } 240 | 241 | @Override 242 | public void run() { 243 | try { 244 | Thread.sleep(2000); 245 | } catch (Exception e) { 246 | e.printStackTrace(); 247 | } 248 | 249 | MyLog.d(TAG, "run task G in " + Thread.currentThread().getName()); 250 | } 251 | } 252 | 253 | 254 | 255 | } 256 | -------------------------------------------------------------------------------- /sample/src/main/java/com/alibaba/android/alpha/MainActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Alibaba Group. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.alibaba.android.alpha; 18 | 19 | import android.os.Bundle; 20 | import android.os.Handler; 21 | import android.os.Looper; 22 | import android.support.v7.app.ActionBarActivity; 23 | import android.text.method.ScrollingMovementMethod; 24 | import android.view.Menu; 25 | import android.view.MenuItem; 26 | import android.widget.TextView; 27 | import com.alibaba.android.alphasample.R; 28 | 29 | 30 | public class MainActivity extends ActionBarActivity { 31 | 32 | @Override 33 | protected void onCreate(Bundle savedInstanceState) { 34 | super.onCreate(savedInstanceState); 35 | setContentView(R.layout.activity_main); 36 | final TextView text = (TextView) findViewById(R.id.task_log); 37 | text.setMovementMethod(new ScrollingMovementMethod()); 38 | ConfigTest test = new ConfigTest(getApplicationContext()); 39 | test.setOnProjectExecuteListener(new OnProjectExecuteListener() { 40 | @Override 41 | public void onProjectStart() { 42 | 43 | } 44 | 45 | @Override 46 | public void onTaskFinish(String taskName) { 47 | 48 | } 49 | 50 | @Override 51 | public void onProjectFinish() { 52 | new Handler(Looper.getMainLooper()).post(new Runnable() { 53 | @Override 54 | public void run() { 55 | text.setText(MyLog.getLogString()); 56 | } 57 | }); 58 | } 59 | }); 60 | test.start(); 61 | } 62 | 63 | @Override 64 | public boolean onCreateOptionsMenu(Menu menu) { 65 | // Inflate the menu; this adds items to the action bar if it is present. 66 | getMenuInflater().inflate(R.menu.menu_main, menu); 67 | return true; 68 | } 69 | 70 | @Override 71 | public boolean onOptionsItemSelected(MenuItem item) { 72 | // Handle action bar item clicks here. The action bar will 73 | // automatically handle clicks on the Home/Up button, so long 74 | // as you specify a parent activity in AndroidManifest.xml. 75 | int id = item.getItemId(); 76 | 77 | //noinspection SimplifiableIfStatement 78 | if (id == R.id.action_settings) { 79 | return true; 80 | } 81 | 82 | return super.onOptionsItemSelected(item); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /sample/src/main/java/com/alibaba/android/alpha/MyLog.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Alibaba Group. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.alibaba.android.alpha; 18 | 19 | import android.util.Log; 20 | 21 | /** 22 | *

日志输出类,其函数和{@link Log}基本一致。

23 | * 24 | * Created by zhangshuliang.zsl on 15/8/24. 25 | */ 26 | public class MyLog { 27 | 28 | /** 29 | * 全局的日志过滤tag,{@code Alpha}库输出的日志,都可以用该tag过滤 30 | */ 31 | public static final String GLOBAL_TAG = "==ALPHA=="; 32 | 33 | private static StringBuilder mLogString = new StringBuilder(); 34 | 35 | public static void d(String tag, Object obj) { 36 | Log.d(tag, obj.toString()); 37 | mLogString.append(obj.toString()).append("\n"); 38 | } 39 | 40 | public static synchronized String getLogString() { 41 | return mLogString.toString(); 42 | } 43 | 44 | public static synchronized void d(String tag, String msg, Object... args) { 45 | String formattedMsg = String.format(msg, args); 46 | mLogString.append(formattedMsg).append("\n"); 47 | Log.d(tag, formattedMsg); 48 | } 49 | 50 | public static void e(String tag, Object obj) { 51 | Log.e(tag, obj.toString()); 52 | mLogString.append(obj.toString()).append("\n"); 53 | } 54 | 55 | public static void print(Object msg) { 56 | d(GLOBAL_TAG, msg); 57 | } 58 | 59 | public static void print(String msg, Object... args) { 60 | d(GLOBAL_TAG, msg, args); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 27 | 28 | 32 | 33 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /sample/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 21 | 25 | 26 | -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alibaba/alpha/04fe7f22c469de66fed98c341334c954dfabafb2/sample/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alibaba/alpha/04fe7f22c469de66fed98c341334c954dfabafb2/sample/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alibaba/alpha/04fe7f22c469de66fed98c341334c954dfabafb2/sample/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alibaba/alpha/04fe7f22c469de66fed98c341334c954dfabafb2/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 21 | 64dp 22 | 23 | -------------------------------------------------------------------------------- /sample/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 16dp 20 | 16dp 21 | 22 | -------------------------------------------------------------------------------- /sample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | Alpha 19 | 20 | Task执行日志 21 | Settings 22 | 23 | -------------------------------------------------------------------------------- /sample/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':sample', ':alpha' 2 | --------------------------------------------------------------------------------