diff --git a/.gitignore b/.gitignore index 0c7b8e5..fd507f2 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ local.properties .idea/workspace.xml .idea/libraries .idea/misc.xml -*.iml \ No newline at end of file +*.iml +.idea diff --git a/build.gradle b/build.gradle index 32ed3fc..1ea4bd0 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,6 @@ buildscript { } dependencies { classpath 'com.android.tools.build:gradle:2.3.0' - classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/gradle.properties b/gradle.properties index aac7c9b..6b1d55f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,17 +1,40 @@ # Project-wide Gradle settings. - # IDE (e.g. Android Studio) users: # Gradle settings configured through the IDE *will override* # any settings specified in this file. - # For more details on how to configure your build environment visit # http://www.gradle.org/docs/current/userguide/build_environment.html - # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. org.gradle.jvmargs=-Xmx1536m - # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true + +GROUP=com.liulishuo.engzo +VERSION_NAME=1.3.0-rc.0 + +POM_ARTIFACT_ID=lingo-recorder +POM_NAME=LingoRecorder +POM_DESCRIPTION=LingoRecorder +POM_PACKAGING=aar + +POM_URL=https://git.llsapp.com/android-hub/lingoRecorder +ISSUE_URL=https://git.llsapp.com/android-hub/lingoRecorder/issues +POM_SCM_URL=https://git.llsapp.com/android-hub/lingoRecorder +POM_SCM_CONNECTION=scm:git:git://git.llsapp.com/android-hub/lingoRecorder.git +POM_SCM_DEV_CONNECTION=scm:git:ssh://git.llsapp.com/android-hub/lingoRecorder.git + + +POM_LICENCE_NAME=The Apache Software License, Version 2.0 +POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt +POM_LICENCE_DIST=repo + +POM_DEVELOPER_ID=lingochamp +POM_DEVELOPER_NAME=LingoChamp, Inc. + +LLS_RELEASE_REPOSITORY_URL=http://m2.llsapp.com/repository/releases/ +LLS_SNAPSHOT_REPOSITORY_URL=http://m2.llsapp.com/repository/snapshots/ + +org.gradle.parallel=true diff --git a/gradle/mvn-push.gradle b/gradle/mvn-push.gradle new file mode 100644 index 0000000..9c15e5d --- /dev/null +++ b/gradle/mvn-push.gradle @@ -0,0 +1,235 @@ +/* + * Copyright 2013 Chris Banes + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +apply plugin: 'maven' +apply plugin: 'signing' +apply from: '../gradle/mvn-pushlocal.gradle' + +version = VERSION_NAME +group = GROUP + +def isReleaseBuild() { + return VERSION_NAME.contains("SNAPSHOT") == false +} + +def getReleaseRepositoryUrl() { + return hasProperty('LLS_RELEASE_REPOSITORY_URL') ? LLS_RELEASE_REPOSITORY_URL : + "https://oss.sonatype.org/service/local/staging/deploy/maven2/" +} + +def getSnapshotRepositoryUrl() { + return hasProperty('LLS_SNAPSHOT_REPOSITORY_URL') ? LLS_SNAPSHOT_REPOSITORY_URL : + "https://oss.sonatype.org/content/repositories/snapshots/" +} + +def getRepositoryUsername() { + File localFile = rootProject.file("local.properties") + if (localFile.exists()) { + Properties properties = new Properties() + properties.load(localFile.newDataInputStream()) + if (properties.getProperty('username') != null) return properties.getProperty('username') + } + + return hasProperty('LLS_RELEASE_REPOSITORY_URL') ? (hasProperty('LLS_M2_USER') ? LLS_M2_USER : ""): + (hasProperty('SONATYPE_NEXUS_USERNAME') ? SONATYPE_NEXUS_USERNAME : "") +} + +def getRepositoryPassword() { + File localFile = rootProject.file("local.properties") + if (localFile.exists()) { + Properties properties = new Properties() + properties.load(localFile.newDataInputStream()) + if (properties.getProperty('password') != null) return properties.getProperty('password') + } + + return hasProperty('LLS_RELEASE_REPOSITORY_URL')? (hasProperty('LLS_M2_PASSWORD') ? LLS_M2_PASSWORD : "") : + (hasProperty('SONATYPE_NEXUS_PASSWORD') ? SONATYPE_NEXUS_PASSWORD : "") +} + +afterEvaluate { project -> + uploadArchives { + repositories { + mavenDeployer { + beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } + + pom.groupId = GROUP + pom.artifactId = POM_ARTIFACT_ID + pom.version = VERSION_NAME + + repository(url: getReleaseRepositoryUrl()) { + authentication(userName: getRepositoryUsername(), password: getRepositoryPassword()) + } + snapshotRepository(url: getSnapshotRepositoryUrl()) { + authentication(userName: getRepositoryUsername(), password: getRepositoryPassword()) + } + + pom.project { + name POM_NAME + packaging POM_PACKAGING + description POM_DESCRIPTION + url POM_URL + + scm { + url POM_SCM_URL + connection POM_SCM_CONNECTION + developerConnection POM_SCM_DEV_CONNECTION + } + + licenses { + license { + name POM_LICENCE_NAME + url POM_LICENCE_URL + distribution POM_LICENCE_DIST + } + } + + developers { + developer { + id POM_DEVELOPER_ID + name POM_DEVELOPER_NAME + } + } + } + } + } + } + + signing { + required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") } + sign configurations.archives + } + + if (project.getPlugins().hasPlugin('com.android.application') || + project.getPlugins().hasPlugin('com.android.library')) { + task install(type: Upload, dependsOn: assemble) { + repositories.mavenInstaller { + configuration = configurations.archives + + pom.groupId = GROUP + pom.artifactId = POM_ARTIFACT_ID + pom.version = VERSION_NAME + + pom.project { + name POM_NAME + packaging POM_PACKAGING + description POM_DESCRIPTION + url POM_URL + + scm { + url POM_SCM_URL + connection POM_SCM_CONNECTION + developerConnection POM_SCM_DEV_CONNECTION + } + + licenses { + license { + name POM_LICENCE_NAME + url POM_LICENCE_URL + distribution POM_LICENCE_DIST + } + } + + developers { + developer { + id POM_DEVELOPER_ID + name POM_DEVELOPER_NAME + } + } + } + } + } + + task androidJavadocs(type: Javadoc) { + source = android.sourceSets.main.java.source + classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) + } + + task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) { + classifier = 'javadoc' + from androidJavadocs.destinationDir + } + + task androidSourcesJar(type: Jar) { + classifier = 'sources' + from android.sourceSets.main.java.source + } + } else { + install { + repositories.mavenInstaller { + pom.groupId = GROUP + pom.artifactId = POM_ARTIFACT_ID + pom.version = VERSION_NAME + + pom.project { + name POM_NAME + packaging POM_PACKAGING + description POM_DESCRIPTION + url POM_URL + + scm { + url POM_SCM_URL + connection POM_SCM_CONNECTION + developerConnection POM_SCM_DEV_CONNECTION + } + + licenses { + license { + name POM_LICENCE_NAME + url POM_LICENCE_URL + distribution POM_LICENCE_DIST + } + } + + developers { + developer { + id POM_DEVELOPER_ID + name POM_DEVELOPER_NAME + } + } + } + } + } + + task sourcesJar(type: Jar, dependsOn: classes) { + classifier = 'sources' + from sourceSets.main.allSource + } + + task javadocJar(type: Jar, dependsOn: javadoc) { + classifier = 'javadoc' + from javadoc.destinationDir + } + } + + if (JavaVersion.current().isJava8Compatible()) { + allprojects { + tasks.withType(Javadoc) { + options.addStringOption('Xdoclint:none', '-quiet') + } + } + } + + artifacts { + if (project.getPlugins().hasPlugin('com.android.application') || + project.getPlugins().hasPlugin('com.android.library')) { + archives androidSourcesJar + archives androidJavadocsJar + } else { + archives sourcesJar + archives javadocJar + } + } +} diff --git a/gradle/mvn-pushlocal.gradle b/gradle/mvn-pushlocal.gradle new file mode 100644 index 0000000..a7c371a --- /dev/null +++ b/gradle/mvn-pushlocal.gradle @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2018 LingoChamp Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +apply plugin: 'maven-publish' + +task sourceJar(type: Jar) { + from android.sourceSets.main.java.srcDirs + classifier "source" +} + +publishing { + publications { + logx(MavenPublication) { + groupId GROUP + artifactId POM_ARTIFACT_ID + version VERSION_NAME + artifact(sourceJar) + artifact("$buildDir/outputs/aar/${project.name}-release.aar") + + pom.withXml { + def dependenciesNode = asNode().appendNode('dependencies') + configurations.compile.allDependencies.each { + if (it.group != null + && (it.name != null || "unspecified" == it.name) + && it.version != null) { + def dependencyNode = dependenciesNode.appendNode('dependency') + dependencyNode.appendNode('groupId', it.group) + dependencyNode.appendNode('artifactId', it.name) + dependencyNode.appendNode('version', it.version) + } + } + } + } + } +} \ No newline at end of file diff --git a/library/build.gradle b/library/build.gradle index 8566dd3..c084a11 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -1,12 +1,9 @@ apply plugin: 'com.android.library' -apply plugin: 'com.github.dcendents.android-maven' - -group='com.github.lingochamp' ext { - PUBLISH_GROUP_ID = 'com.liulishuo.engzo' + group = 'com.liulishuo.engzo' + version = '1.3.0-rc.0' PUBLISH_ARTIFACT_ID = 'lingo-recorder' - PUBLISH_VERSION = '1.2.5' } android { @@ -42,4 +39,9 @@ dependencies { compile 'com.android.support:support-annotations:25.3.0' } -apply from: 'https://raw.githubusercontent.com/blundell/release-android-library/master/android-release-aar.gradle' +apply from: rootProject.file('gradle/mvn-push.gradle') + +tasks.withType(Javadoc).all { + enabled = false +} + diff --git a/library/src/main/java/com/liulishuo/engzo/lingorecorder/LingoRecorder.java b/library/src/main/java/com/liulishuo/engzo/lingorecorder/LingoRecorder.java index 0833e80..e120e30 100644 --- a/library/src/main/java/com/liulishuo/engzo/lingorecorder/LingoRecorder.java +++ b/library/src/main/java/com/liulishuo/engzo/lingorecorder/LingoRecorder.java @@ -7,6 +7,7 @@ import android.support.annotation.NonNull; import com.liulishuo.engzo.lingorecorder.processor.AudioProcessor; +import com.liulishuo.engzo.lingorecorder.processor.ProcessorProfilerWrapper; import com.liulishuo.engzo.lingorecorder.processor.WavProcessor; import com.liulishuo.engzo.lingorecorder.recorder.AndroidRecorder; import com.liulishuo.engzo.lingorecorder.recorder.IRecorder; @@ -61,7 +62,6 @@ public boolean isProcessing() { } /** - * * @deprecated use {@link #isProcessing()} instead */ @Deprecated @@ -149,7 +149,11 @@ public void setOnVolumeListener(OnVolumeListener onVolumeListener, IVolumeCalcul } public void put(String processorId, AudioProcessor processor) { - audioProcessorMap.put(processorId, processor); + if (ProcessorProfilerWrapper.profiler != null) { + audioProcessorMap.put(processorId, new ProcessorProfilerWrapper(processorId, processor)); + } else { + audioProcessorMap.put(processorId, processor); + } } public AudioProcessor remove(String processorId) { diff --git a/library/src/main/java/com/liulishuo/engzo/lingorecorder/processor/ProcessorProfilerWrapper.java b/library/src/main/java/com/liulishuo/engzo/lingorecorder/processor/ProcessorProfilerWrapper.java new file mode 100644 index 0000000..d74c77e --- /dev/null +++ b/library/src/main/java/com/liulishuo/engzo/lingorecorder/processor/ProcessorProfilerWrapper.java @@ -0,0 +1,77 @@ +package com.liulishuo.engzo.lingorecorder.processor; + +public class ProcessorProfilerWrapper implements AudioProcessor { + + public static Profiler profiler; + private AudioProcessor processor; + private String name; + + public ProcessorProfilerWrapper(String name, AudioProcessor processor) { + this.processor = processor; + this.name = name; + } + + @Override + public void start() throws Exception { + long startMethodStartTimeStamp = System.currentTimeMillis(); + processor.start(); + if (profiler != null) { + profiler.start( + name, + System.currentTimeMillis() - startMethodStartTimeStamp + ); + } + } + + @Override + public void flow(byte[] bytes, int size) throws Exception { + long flowMethodStartTimeStamp = System.currentTimeMillis(); + processor.flow(bytes, size); + if (profiler != null) { + profiler.flow( + name, + System.currentTimeMillis() - flowMethodStartTimeStamp + ); + } + } + + @Override + public boolean needExit() { + return processor.needExit(); + } + + @Override + public void end() throws Exception { + long endMethodStartTimeStamp = System.currentTimeMillis(); + processor.end(); + if (profiler != null) { + profiler.end( + name, + System.currentTimeMillis() - endMethodStartTimeStamp + ); + } + } + + @Override + public void release() { + long releaseMethodStartTimeStamp = System.currentTimeMillis(); + processor.release(); + if (profiler != null) { + profiler.release( + name, + System.currentTimeMillis() - releaseMethodStartTimeStamp + ); + } + } + + public interface Profiler { + + void start(String name, long cost); + + void flow(String name, long cost); + + void end(String name, long cost); + + void release(String name, long cost); + } +}