├── app-kotlin
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── values
│ │ │ ├── strings.xml
│ │ │ ├── colors.xml
│ │ │ └── styles.xml
│ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-anydpi-v26
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.xml
│ │ ├── layout
│ │ │ └── activity_main.xml
│ │ ├── drawable-v24
│ │ │ └── ic_launcher_foreground.xml
│ │ └── drawable
│ │ │ └── ic_launcher_background.xml
│ │ ├── AndroidManifest.xml
│ │ └── kotlin
│ │ └── com
│ │ └── github
│ │ └── pwittchen
│ │ └── rxbattery
│ │ └── app
│ │ └── MainActivity.kt
├── proguard-rules.pro
└── build.gradle
├── library
├── .gitignore
├── gradle.properties
├── src
│ ├── main
│ │ ├── AndroidManifest.xml
│ │ └── kotlin
│ │ │ └── com
│ │ │ └── github
│ │ │ └── pwittchen
│ │ │ └── rxbattery
│ │ │ └── library
│ │ │ ├── state
│ │ │ ├── Plugged.kt
│ │ │ ├── Status.kt
│ │ │ └── Health.kt
│ │ │ ├── BatteryState.kt
│ │ │ └── RxBattery.kt
│ └── test
│ │ └── kotlin
│ │ └── com
│ │ └── github
│ │ └── pwittchen
│ │ └── rxbattery
│ │ └── library
│ │ └── RxBatteryTest.kt
├── proguard-rules.pro
├── build.gradle
└── detekt.yml
├── settings.gradle
├── logo.png
├── .github
└── FUNDING.yml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── config
├── quality
│ ├── lint
│ │ └── lint.xml
│ ├── checkstyle
│ │ ├── suppressions.xml
│ │ └── checkstyle.xml
│ ├── findbugs
│ │ └── findbugs-filter.xml
│ └── pmd
│ │ └── pmd-ruleset.xml
└── quality.gradle
├── .editorconfig
├── .travis.yml
├── gradle.properties
├── .gitignore
├── CHANGELOG.md
├── RELEASING.md
├── CONTRIBUTING.md
├── gradlew.bat
├── maven_push.gradle
├── README.md
├── gradlew
└── LICENSE
/app-kotlin/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app-kotlin', ':library'
2 |
--------------------------------------------------------------------------------
/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pwittchen/RxBattery/HEAD/logo.png
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | github: [pwittchen]
2 | custom: ['https://paypal.me/pwittchen']
3 |
--------------------------------------------------------------------------------
/library/gradle.properties:
--------------------------------------------------------------------------------
1 | POM_NAME=rxbattery
2 | POM_ARTIFACT_ID=rxbattery
3 | POM_PACKAGING=aar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pwittchen/RxBattery/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app-kotlin/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | app-kotlin
3 |
4 |
--------------------------------------------------------------------------------
/app-kotlin/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pwittchen/RxBattery/HEAD/app-kotlin/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app-kotlin/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pwittchen/RxBattery/HEAD/app-kotlin/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app-kotlin/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pwittchen/RxBattery/HEAD/app-kotlin/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app-kotlin/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pwittchen/RxBattery/HEAD/app-kotlin/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app-kotlin/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pwittchen/RxBattery/HEAD/app-kotlin/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app-kotlin/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pwittchen/RxBattery/HEAD/app-kotlin/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app-kotlin/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pwittchen/RxBattery/HEAD/app-kotlin/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app-kotlin/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pwittchen/RxBattery/HEAD/app-kotlin/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app-kotlin/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pwittchen/RxBattery/HEAD/app-kotlin/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app-kotlin/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pwittchen/RxBattery/HEAD/app-kotlin/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/config/quality/lint/lint.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.1-bin.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/app-kotlin/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app-kotlin/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app-kotlin/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/config/quality/checkstyle/suppressions.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/app-kotlin/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | [*.{kt,kts}]
2 | # possible values: number (e.g. 2), "unset" (makes ktlint ignore indentation completely)
3 | indent_size=2
4 | # possible values: number (e.g. 2), "unset"
5 | continuation_indent_size=2
6 | # true (recommended) / false
7 | insert_final_newline=unset
8 | # possible values: number (e.g. 120) (package name, imports & comments are ignored), "off"
9 | # it's automatically set to 100 on `ktlint --android ...` (per Android Kotlin Style Guide)
10 | max_line_length=off
--------------------------------------------------------------------------------
/config/quality/findbugs/findbugs-filter.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: android
2 |
3 | android:
4 | components:
5 | - tools
6 | - tools
7 | - platform-tools
8 | - build-tools-28
9 | - android-28
10 | - extra-android-support
11 | - extra-android-m2repository
12 | licenses:
13 | - android-sdk-license-5be876d5
14 | - android-sdk-license-c81a61d9
15 | - 'android-sdk-preview-license-.+'
16 | - 'android-sdk-license-.+'
17 | - 'google-gdk-license-.+'
18 |
19 | install:
20 | - true
21 |
22 | before_install:
23 | - yes | sdkmanager "platforms;android-27"
24 |
25 | jdk: oraclejdk8
26 |
27 | script:
28 | - ./gradlew clean build test check
29 |
30 | cache:
31 | directories:
32 | - $HOME/.m2
33 |
--------------------------------------------------------------------------------
/app-kotlin/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app-kotlin/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/library/src/main/kotlin/com/github/pwittchen/rxbattery/library/state/Plugged.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2018 Piotr Wittchen
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 | package com.github.pwittchen.rxbattery.library.state
17 |
18 | enum class Plugged {
19 | AC,
20 | USB,
21 | WIRELESS,
22 | UNKNOWN
23 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | VERSION_NAME=0.1.0
2 | VERSION_CODE=2
3 | GROUP=com.github.pwittchen
4 |
5 | POM_DESCRIPTION=Android library monitoring battery of the device with RxJava and RxKotlin
6 | POM_URL=https://github.com/pwittchen/RxBattery
7 | POM_SCM_URL=https://github.com/pwittchen/RxBattery
8 | POM_SCM_CONNECTION=scm:git@github.com:pwittchen/RxBattery.git
9 | POM_SCM_DEV_CONNECTION=scm:git@github.com:pwittchen/RxBattery.git
10 | POM_LICENCE_NAME=The Apache Software License, Version 2.0
11 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
12 | POM_LICENCE_DIST=repo
13 | POM_DEVELOPER_ID=pwittchen
14 | POM_DEVELOPER_NAME=Piotr Wittchen
15 |
16 | org.gradle.daemon=true
17 | org.gradle.jvmargs=-XX:MaxPermSize=1024m -XX:+CMSClassUnloadingEnabled -XX:+HeapDumpOnOutOfMemoryError -Xmx2048m -XX:MaxHeapSize=2048
18 |
19 | android.useAndroidX=true
20 | android.enableJetifier=true
--------------------------------------------------------------------------------
/library/src/main/kotlin/com/github/pwittchen/rxbattery/library/state/Status.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2018 Piotr Wittchen
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 | package com.github.pwittchen.rxbattery.library.state
17 |
18 | enum class Status {
19 | CHARGING,
20 | DISCHARGING,
21 | FULL,
22 | NOT_CHARGING,
23 | UNKNOWN
24 | }
--------------------------------------------------------------------------------
/app-kotlin/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
21 |
22 |
--------------------------------------------------------------------------------
/library/src/main/kotlin/com/github/pwittchen/rxbattery/library/state/Health.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2018 Piotr Wittchen
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 | package com.github.pwittchen.rxbattery.library.state
17 |
18 | enum class Health {
19 | COLD,
20 | DEAD,
21 | GOOD,
22 | OVERHEAT,
23 | OVER_VOLTAGE,
24 | UNKNOWN,
25 | UNSPECIFIED_FAILURE
26 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # Intellij
36 | *.iml
37 | .idea/workspace.xml
38 | .idea/tasks.xml
39 | .idea/gradle.xml
40 | .idea/dictionaries
41 | .idea/libraries
42 |
43 | # Keystore files
44 | *.jks
45 |
46 | # External native build folder generated in Android Studio 2.2 and later
47 | .externalNativeBuild
48 |
49 | # Google Services (e.g. APIs or Firebase)
50 | google-services.json
51 |
52 | # Freeline
53 | freeline.py
54 | freeline/
55 | freeline_project_description.json
56 |
--------------------------------------------------------------------------------
/library/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 /home/piotr/Development/android/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 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | CHANGELOG
2 | =========
3 |
4 | v. 0.1.0
5 | --------
6 | *21 Aug 2018*
7 |
8 | - **additions**
9 | - added the following enums: `Status`, `Plugged`, `Health`
10 | - added the following methods to `BatteryState` data class:
11 | - `fun status(): Status { ... }`
12 | - `fun plugged(): Plugged { ... }`
13 | - `fun health(): Health { ... }`
14 | - added `@JvmStatic` annotation to `fun observe(context: Context): Flowable` method in `RxBattery` class in order to call static method from Java modules without need to explicitly call `Companion` object
15 | - added KotlinX to sample Kotlin app
16 | - added project logo created by @Yasujizr
17 | - **updates**
18 | - fixed typo in const val in `RxBattery` class
19 | - **API-breaking change**: In `BatteryState` data class, renamed variable `status` to `statusCode`, `plugged` to `pluggedCode` and `health` to `healthCode`
20 | - **removals**
21 | - **API-breaking change**: Removed `RxBatteryFactory` class
22 |
23 | v. 0.0.1
24 | --------
25 | *17 Aug 2018*
26 |
27 | The first release of the library.
28 |
--------------------------------------------------------------------------------
/RELEASING.md:
--------------------------------------------------------------------------------
1 | Releasing Guidelines
2 | ====================
3 |
4 | In order to release new version of the library, we need to perform the following operations:
5 | - create new release issue on GitHub
6 | - prepare release notes and put them to the issue
7 | - checkout to the `master` branch
8 | - bump library version (`VERSION_NAME` and `VERSION_CODE`) in `gradle.properties` file
9 | - commit and push the changes
10 | - run command: `./gradlew uploadArchives`
11 | - go to the https://oss.sonatype.org website
12 | - log in to Sonatype
13 | - go to "Staging Repositories" and sort by last "Updated" date and time
14 | - close and release artifact
15 | - copy `library/build/docs/javadoc` directory
16 | - checkout to `gh-pages` branch
17 | - remove old JavaDoc and paste new, generated JavaDoc there
18 | - commit and push changes
19 | - wait for the Maven Sync (up to 48 hours)
20 | - when sync is done, checkout to the `master` branch
21 | - update `CHANGELOG.md` file with new release version, current date and release notes
22 | - bump library version in "Download" section in `README.md` file
23 | - create new tagged GitHub release with name the same as `VERSION_NAME` from `gradle.properties` and release notes
--------------------------------------------------------------------------------
/app-kotlin/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 |
5 | android {
6 | compileSdkVersion rootProject.ext.compileSdkVersion
7 | buildToolsVersion rootProject.ext.buildToolsVersion
8 |
9 | defaultConfig {
10 | multiDexEnabled true
11 | applicationId "com.github.pwittchen.rxbattery.app"
12 | minSdkVersion rootProject.ext.minSdkVersion
13 | targetSdkVersion rootProject.ext.compileSdkVersion
14 | versionCode 1
15 | versionName "1.0"
16 | }
17 |
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 | sourceSets {
25 | androidTest.java.srcDirs += "src/androidTest/kotlin"
26 | main.java.srcDirs += "src/main/kotlin"
27 | test.java.srcDirs += "src/test/kotlin"
28 | }
29 |
30 | compileOptions {
31 | sourceCompatibility JavaVersion.VERSION_1_8
32 | targetCompatibility JavaVersion.VERSION_1_8
33 | }
34 | }
35 |
36 | dependencies {
37 | implementation project(':library')
38 | implementation deps.kotlinstdlib
39 | implementation deps.appcompatv7
40 | implementation deps.constraintlayout
41 | }
42 |
43 | buildscript {
44 | repositories {
45 | mavenCentral()
46 | jcenter()
47 | google()
48 | maven {
49 | url 'https://plugins.gradle.org/m2/'
50 | }
51 | }
52 |
53 | dependencies {
54 | classpath deps.kotlinx
55 | }
56 | }
--------------------------------------------------------------------------------
/config/quality.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'checkstyle'
2 | apply plugin: 'pmd'
3 |
4 | // Add dependencies to the 'check' gradle task.
5 | check.dependsOn 'checkstyle', 'pmd', 'lint', 'detektCheck'
6 |
7 | checkstyle {
8 | toolVersion = "6.0"
9 | }
10 |
11 | task checkstyle(type: Checkstyle) {
12 | configFile file("${project.rootDir}/config/quality/checkstyle/checkstyle.xml")
13 | configProperties.checkstyleSuppressionsPath =
14 | file("${project.rootDir}/config/quality/checkstyle/suppressions.xml").absolutePath
15 | source 'src'
16 | include '**/*.java'
17 | include '**/*.kt'
18 | exclude '**/gen/**'
19 | classpath = files()
20 | }
21 |
22 | task pmd(type: Pmd) {
23 | ignoreFailures = false
24 | ruleSetFiles = files("${project.rootDir}/config/quality/pmd/pmd-ruleset.xml")
25 | ruleSets = []
26 |
27 | source 'src'
28 | include '**/*.java'
29 | include '**/*.kt'
30 | exclude '**/gen/**'
31 |
32 | reports {
33 | xml.enabled = false
34 | html.enabled = true
35 | xml {
36 | destination file("$project.buildDir/reports/pmd/pmd.xml")
37 | }
38 | html {
39 | destination file("$project.buildDir/reports/pmd/pmd.html")
40 | }
41 | }
42 | }
43 |
44 | android {
45 | lintOptions {
46 | abortOnError false
47 | xmlReport false
48 | htmlReport true
49 | lintConfig file("${project.rootDir}/config/quality/lint/lint.xml")
50 | htmlOutput file("$project.buildDir/reports/lint/lint-result.html")
51 | xmlOutput file("$project.buildDir/reports/lint/lint-result.xml")
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/config/quality/pmd/pmd-ruleset.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 | Custom ruleset for Android application
8 |
9 | .*/R.java
10 | .*/gen/.*
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | Contributing guidelines
2 | =======================
3 |
4 | Looking for help?
5 | -----------------
6 |
7 | You have the following options:
8 | - Check out documentation in `README.md` file and read it carefully. It covers almost everything what is important.
9 | - Browse JavaDoc at http://pwittchen.github.io/RxBattery/
10 | - [Ask the question on StackOverlow](http://stackoverflow.com/questions/ask?tags=rxbattery).
11 | - Provide detailed information about your problem and environment and then ask the question in the new GitHub issue here.
12 |
13 | Found a bug?
14 | ------------
15 |
16 | Provide detailed steps to reproduce and make sure this bug is not related to your custom project or environment.
17 | Ideally, create Pull Request with failing unit test (or more tests).
18 |
19 | Want a few feature or improvement?
20 | ----------------------------------
21 |
22 | This is tiny library, so I would avoid overcomplicating it, but if you think a new feature
23 | would be useful and make this project better, then create a new issue.
24 | After that, we can discuss it and work on a Pull Request.
25 |
26 | Want to create a Pull Request?
27 | ------------------------------
28 |
29 | Before creating new Pull Request, please create a new issue and discuss the problem.
30 | If we agree that PR will be reasonable solution, then fork repository, create a separate branch
31 | and work on a feature or bug-fix on this branch. When you're done, make sure that project passes
32 | static code analysis verification with `./gradlew check` command. Moreover, format your code according to
33 | [SquareAndroid](https://github.com/square/java-code-styles) Java Code Styles.
34 | When you performed more commits than one, squash them into one within a single PR (you can use http://rebaseandsqua.sh/ website).
35 | Make sure that your commit message is descriptive enough. If not, then use `git commit --amend` command and change it.
--------------------------------------------------------------------------------
/app-kotlin/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app-kotlin/src/main/kotlin/com/github/pwittchen/rxbattery/app/MainActivity.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2018 Piotr Wittchen
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 | package com.github.pwittchen.rxbattery.app
17 |
18 | import android.os.Bundle
19 | import androidx.appcompat.app.AppCompatActivity
20 | import com.github.pwittchen.rxbattery.library.RxBattery
21 | import io.reactivex.android.schedulers.AndroidSchedulers
22 | import io.reactivex.disposables.Disposable
23 | import io.reactivex.schedulers.Schedulers
24 | import kotlinx.android.synthetic.main.activity_main.textView
25 |
26 | class MainActivity : AppCompatActivity() {
27 |
28 | private var batteryDisposable: Disposable? = null
29 |
30 | override fun onCreate(savedInstanceState: Bundle?) {
31 | super.onCreate(savedInstanceState)
32 | setContentView(R.layout.activity_main)
33 | }
34 |
35 | override fun onResume() {
36 | super.onResume()
37 | batteryDisposable = RxBattery.observe(this)
38 | .subscribeOn(Schedulers.io())
39 | .observeOn(AndroidSchedulers.mainThread())
40 | .subscribe {
41 | textView.text = String.format(
42 | "info: %s, status: %s, plugged: %s, health: %s",
43 | it.toString(), it.status(), it.plugged(), it.health()
44 | )
45 | }
46 | }
47 |
48 | override fun onPause() {
49 | super.onPause()
50 | if (batteryDisposable != null && batteryDisposable?.isDisposed!!) {
51 | batteryDisposable?.dispose()
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/library/src/test/kotlin/com/github/pwittchen/rxbattery/library/RxBatteryTest.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2018 Piotr Wittchen
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 | package com.github.pwittchen.rxbattery.library
17 |
18 | import android.content.BroadcastReceiver
19 | import android.content.Context
20 | import android.content.Intent
21 | import com.google.common.truth.Truth.assertThat
22 | import io.reactivex.FlowableEmitter
23 | import org.junit.Test
24 | import org.mockito.ArgumentMatchers.any
25 | import org.mockito.Mockito.mock
26 | import org.mockito.Mockito.verify
27 |
28 | class RxBatteryTest {
29 |
30 | @Test fun shouldCreateBroadcastReceiver() {
31 | // given
32 | val emitter = mock(FlowableEmitter::class.java)
33 |
34 | // when
35 | val broadcastReceiver: BroadcastReceiver = RxBattery.createBroadcastReceiver(
36 | emitter as FlowableEmitter
37 | )
38 |
39 | // then
40 | assertThat(broadcastReceiver).isNotNull()
41 | }
42 |
43 | @Test fun shouldCallOnNextAfterReceivingData() {
44 | // given
45 | val emitter = mock(FlowableEmitter::class.java)
46 | val context: Context = mock(Context::class.java)
47 | val intent: Intent = mock(Intent::class.java)
48 |
49 | val broadcastReceiver: BroadcastReceiver = RxBattery.createBroadcastReceiver(
50 | emitter as FlowableEmitter
51 | )
52 |
53 | // when
54 | broadcastReceiver.onReceive(context, intent)
55 |
56 | // then
57 | verify(emitter).onNext(any(BatteryState::class.java))
58 | }
59 | }
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android'
4 | apply plugin: 'kotlin-android-extensions'
5 | apply plugin: 'io.gitlab.arturbosch.detekt'
6 | apply plugin: 'org.jetbrains.dokka'
7 | apply from: '../config/quality.gradle'
8 | apply from: '../maven_push.gradle'
9 |
10 | android {
11 | compileSdkVersion rootProject.ext.compileSdkVersion
12 | buildToolsVersion rootProject.ext.buildToolsVersion
13 |
14 | defaultConfig {
15 | multiDexEnabled true
16 | minSdkVersion rootProject.ext.minSdkVersion
17 | targetSdkVersion rootProject.ext.compileSdkVersion
18 | versionCode 1
19 | versionName "1.0"
20 | }
21 |
22 | buildTypes {
23 | release {
24 | minifyEnabled false
25 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
26 | }
27 |
28 | debug {
29 | minifyEnabled false
30 | testCoverageEnabled true
31 | }
32 | }
33 |
34 | sourceSets {
35 | androidTest.java.srcDirs += "src/androidTest/kotlin"
36 | main.java.srcDirs += "src/main/kotlin"
37 | test.java.srcDirs += "src/test/kotlin"
38 | }
39 |
40 | packagingOptions {
41 | exclude 'LICENSE.txt'
42 | exclude 'META-INF/LICENSE.txt'
43 | }
44 |
45 | lintOptions {
46 | abortOnError false
47 | }
48 |
49 | compileOptions {
50 | sourceCompatibility JavaVersion.VERSION_1_8
51 | targetCompatibility JavaVersion.VERSION_1_8
52 | }
53 | }
54 |
55 | detekt {
56 | version = rootProject.ext.detektVersion
57 | profile("main") {
58 | input = "$projectDir"
59 | config = "$projectDir/detekt.yml"
60 | filters = ".*test.*,.*/resources/.*,.*/tmp/.*"
61 | }
62 | }
63 |
64 | dokka {
65 | outputFormat = 'html'
66 | outputDirectory = "$buildDir/javadoc"
67 | }
68 |
69 | dependencies {
70 | api deps.rxjava2
71 | api deps.rxandroid2
72 | api deps.rxkotlin2
73 | implementation deps.supportannotations
74 | testImplementation deps.junit
75 | testImplementation deps.truth
76 | testImplementation deps.robolectric
77 | testImplementation deps.mockitokotlin
78 | testImplementation deps.mockitocore
79 | }
80 |
81 | buildscript {
82 | repositories {
83 | mavenCentral()
84 | jcenter()
85 | google()
86 | maven {
87 | url 'https://plugins.gradle.org/m2/'
88 | }
89 | }
90 |
91 | dependencies {
92 | classpath deps.detekt
93 | classpath deps.dokka
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/library/src/main/kotlin/com/github/pwittchen/rxbattery/library/BatteryState.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2018 Piotr Wittchen
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 | package com.github.pwittchen.rxbattery.library
17 |
18 | import android.os.BatteryManager
19 | import com.github.pwittchen.rxbattery.library.state.Health
20 | import com.github.pwittchen.rxbattery.library.state.Plugged
21 | import com.github.pwittchen.rxbattery.library.state.Status
22 | import com.github.pwittchen.rxbattery.library.state.Status.NOT_CHARGING
23 |
24 | data class BatteryState(
25 | val statusCode: Int,
26 | val pluggedCode: Int,
27 | val healthCode: Int,
28 | val level: Int,
29 | val temperature: Int,
30 | val voltage: Int
31 | ) {
32 |
33 | fun status(): Status {
34 | return when (statusCode) {
35 | BatteryManager.BATTERY_STATUS_CHARGING -> Status.CHARGING
36 | BatteryManager.BATTERY_STATUS_DISCHARGING -> Status.DISCHARGING
37 | BatteryManager.BATTERY_STATUS_FULL -> Status.FULL
38 | BatteryManager.BATTERY_STATUS_NOT_CHARGING -> NOT_CHARGING
39 | else -> Status.UNKNOWN
40 | }
41 | }
42 |
43 | fun plugged(): Plugged {
44 | return when (pluggedCode) {
45 | BatteryManager.BATTERY_PLUGGED_AC -> Plugged.AC
46 | BatteryManager.BATTERY_PLUGGED_USB -> Plugged.USB
47 | BatteryManager.BATTERY_PLUGGED_WIRELESS -> Plugged.WIRELESS
48 | else -> Plugged.UNKNOWN
49 | }
50 | }
51 |
52 | fun health(): Health {
53 | return when (healthCode) {
54 | BatteryManager.BATTERY_HEALTH_COLD -> Health.COLD
55 | BatteryManager.BATTERY_HEALTH_DEAD -> Health.DEAD
56 | BatteryManager.BATTERY_HEALTH_GOOD -> Health.GOOD
57 | BatteryManager.BATTERY_HEALTH_OVERHEAT -> Health.OVERHEAT
58 | BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE -> Health.OVER_VOLTAGE
59 | BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE -> Health.UNSPECIFIED_FAILURE
60 | else -> Health.UNKNOWN
61 | }
62 | }
63 | }
--------------------------------------------------------------------------------
/library/src/main/kotlin/com/github/pwittchen/rxbattery/library/RxBattery.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2018 Piotr Wittchen
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 | package com.github.pwittchen.rxbattery.library
17 |
18 | import android.content.BroadcastReceiver
19 | import android.content.Context
20 | import android.content.Intent
21 | import android.content.IntentFilter
22 | import android.os.BatteryManager
23 | import io.reactivex.BackpressureStrategy.BUFFER
24 | import io.reactivex.Flowable
25 | import io.reactivex.FlowableEmitter
26 |
27 | class RxBattery {
28 | companion object {
29 | const val UNKNOWN = -1
30 |
31 | @JvmStatic fun observe(context: Context): Flowable {
32 |
33 | var receiver: BroadcastReceiver? = null
34 |
35 | return Flowable.create({ emitter ->
36 | receiver = createBroadcastReceiver(emitter)
37 | context.registerReceiver(receiver, IntentFilter(Intent.ACTION_BATTERY_CHANGED))
38 | }, BUFFER)
39 | .doOnCancel { context.unregisterReceiver(receiver) }
40 | }
41 |
42 | fun createBroadcastReceiver(emitter: FlowableEmitter): BroadcastReceiver {
43 | return object : BroadcastReceiver() {
44 | override fun onReceive(
45 | context: Context?,
46 | intent: Intent?
47 | ) {
48 | if (intent == null) {
49 | return
50 | }
51 |
52 | val status: Int = intent.getIntExtra(BatteryManager.EXTRA_STATUS, UNKNOWN)
53 | val plugged: Int = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, UNKNOWN)
54 | val health: Int = intent.getIntExtra(BatteryManager.EXTRA_HEALTH, UNKNOWN)
55 | val level: Int = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, UNKNOWN)
56 | val temperature: Int = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, UNKNOWN)
57 | val voltage: Int = intent.getIntExtra(BatteryManager.EXTRA_VOLTAGE, UNKNOWN)
58 |
59 | emitter.onNext(BatteryState(status, plugged, health, level, temperature, voltage))
60 | }
61 | }
62 | }
63 | }
64 | }
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto init
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto init
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :init
68 | @rem Get command-line arguments, handling Windows variants
69 |
70 | if not "%OS%" == "Windows_NT" goto win9xME_args
71 |
72 | :win9xME_args
73 | @rem Slurp the command line arguments.
74 | set CMD_LINE_ARGS=
75 | set _SKIP=2
76 |
77 | :win9xME_args_slurp
78 | if "x%~1" == "x" goto execute
79 |
80 | set CMD_LINE_ARGS=%*
81 |
82 | :execute
83 | @rem Setup the command line
84 |
85 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
86 |
87 | @rem Execute Gradle
88 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
89 |
90 | :end
91 | @rem End local scope for the variables with windows NT shell
92 | if "%ERRORLEVEL%"=="0" goto mainEnd
93 |
94 | :fail
95 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
96 | rem the _cmd.exe /c_ return code!
97 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
98 | exit /b 1
99 |
100 | :mainEnd
101 | if "%OS%"=="Windows_NT" endlocal
102 |
103 | :omega
104 |
--------------------------------------------------------------------------------
/maven_push.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Chris Banes
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: 'maven'
18 | apply plugin: 'signing'
19 |
20 | def isReleaseBuild() {
21 | return VERSION_NAME.contains("SNAPSHOT") == false
22 | }
23 |
24 | def getReleaseRepositoryUrl() {
25 | return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL
26 | : "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
27 | }
28 |
29 | def getSnapshotRepositoryUrl() {
30 | return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL
31 | : "https://oss.sonatype.org/content/repositories/snapshots/"
32 | }
33 |
34 | def getRepositoryUsername() {
35 | return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : ""
36 | }
37 |
38 | def getRepositoryPassword() {
39 | return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : ""
40 | }
41 |
42 | afterEvaluate { project ->
43 | uploadArchives {
44 | repositories {
45 | mavenDeployer {
46 | beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
47 |
48 | pom.groupId = GROUP
49 | pom.artifactId = POM_ARTIFACT_ID
50 | pom.version = VERSION_NAME
51 |
52 | repository(url: getReleaseRepositoryUrl()) {
53 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
54 | }
55 | snapshotRepository(url: getSnapshotRepositoryUrl()) {
56 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
57 | }
58 |
59 | pom.project {
60 | name POM_NAME
61 | packaging POM_PACKAGING
62 | description POM_DESCRIPTION
63 | url POM_URL
64 |
65 | scm {
66 | url POM_SCM_URL
67 | connection POM_SCM_CONNECTION
68 | developerConnection POM_SCM_DEV_CONNECTION
69 | }
70 |
71 | licenses {
72 | license {
73 | name POM_LICENCE_NAME
74 | url POM_LICENCE_URL
75 | distribution POM_LICENCE_DIST
76 | }
77 | }
78 |
79 | developers {
80 | developer {
81 | id POM_DEVELOPER_ID
82 | name POM_DEVELOPER_NAME
83 | }
84 | }
85 | }
86 | }
87 | }
88 | }
89 |
90 | signing {
91 | required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") }
92 | sign configurations.archives
93 | }
94 |
95 | task androidJavadocs(type: Javadoc) {
96 | source = android.sourceSets.main.java.srcDirs
97 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
98 | failOnError = false
99 | }
100 |
101 | task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
102 | classifier = 'javadoc'
103 | from androidJavadocs.destinationDir
104 | }
105 |
106 | task androidSourcesJar(type: Jar) {
107 | classifier = 'sources'
108 | from android.sourceSets.main.java.sourceFiles
109 | }
110 |
111 | artifacts {
112 | archives androidSourcesJar
113 | archives androidJavadocsJar
114 | }
115 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 | RxBattery [](https://travis-ci.org/pwittchen/RxBattery) 
4 | =========
5 | Android library monitoring battery state of the device with RxJava and RxKotlin
6 |
7 | Contents
8 | --------
9 |
10 | - [Usage](#usage)
11 | - [Examples](#examples)
12 | - [Download](#download)
13 | - [Tests](#tests)
14 | - [Code style](#code-style)
15 | - [Static code analysis](#static-code-analysis)
16 | - [JavaDoc](#javadoc)
17 | - [Changelog](#changelog)
18 | - [Releasing](#releasing)
19 | - [References](#references)
20 | - [Credits](#credits)
21 | - [License](#license)
22 |
23 | Usage
24 | -----
25 |
26 | In the **Kotlin** application, you can use library as follows:
27 |
28 | ```kotlin
29 | RxBattery
30 | .observe(context)
31 | .subscribeOn(Schedulers.io())
32 | .observeOn(AndroidSchedulers.mainThread())
33 | .subscribe { textView.text = it.toString() }
34 | ```
35 |
36 | In the **Java** application, you can use library as follows:
37 |
38 | ```java
39 | RxBattery
40 | .observe(context)
41 | .subscribeOn(Schedulers.io())
42 | .observeOn(AndroidSchedulers.mainThread())
43 | .subscribe(batteryState -> {
44 | textView.setText(batteryState.toString());
45 | });
46 | ```
47 |
48 | `BatteryState` data class looks as follows:
49 |
50 | ```kotlin
51 | data class BatteryState(
52 | val statusCode: Int,
53 | val pluggedCode: Int,
54 | val healthCode: Int,
55 | val level: Int,
56 | val temperature: Int,
57 | val voltage: Int,
58 | ) {
59 | fun status(): Status { ... }
60 | fun plugged(): Plugged { ... }
61 | fun health(): Health { ... }
62 | }
63 | ```
64 |
65 | All `Integer` values returned by `BatteryState` object are reflected in constants of [`BatteryManager`](https://developer.android.com/reference/android/os/BatteryManager) class from the Android SDK. Enums `Status`, `Plugged` and `Health` represents battery state translated from integer codes from `BatteryManager` class.
66 |
67 | Examples
68 | --------
69 |
70 | Exemplary Kotlin application is located in `app-kotlin` directory.
71 |
72 | Download
73 | --------
74 |
75 | You can depend on the library through Gradle:
76 |
77 | ```groovy
78 | dependencies {
79 | implementation 'com.github.pwittchen:rxbattery:0.1.0'
80 | }
81 | ```
82 |
83 | Tests
84 | -----
85 |
86 | Tests are available in `library/src/test/kotlin/` directory and can be executed on JVM without any emulator or Android device from Android Studio or CLI with the following command:
87 |
88 | ```
89 | ./gradlew test
90 | ```
91 |
92 | Code style
93 | ----------
94 |
95 | Code style used in the project is called `SquareAndroid` from Java Code Styles repository by Square available at: https://github.com/square/java-code-styles.
96 |
97 | Static code analysis
98 | --------------------
99 |
100 | Static code analysis runs Checkstyle, FindBugs, PMD, Lint, KtLint and Detekt. It can be executed with command:
101 |
102 | ```
103 | ./gradlew check
104 | ```
105 |
106 | Reports from analysis are generated in `library/build/reports/` directory.
107 |
108 | JavaDoc
109 | -------
110 |
111 | Documentation can be generated as follows:
112 |
113 | ```
114 | ./gradlew dokka
115 | ```
116 |
117 | Output will be generated in `library/build/javadoc`
118 |
119 | JavaDoc can be viewed on-line at https://pwittchen.github.io/RxBattery/library/
120 |
121 | Changelog
122 | ---------
123 |
124 | See [CHANGELOG.md](https://github.com/pwittchen/RxBattery/blob/master/CHANGELOG.md) file.
125 |
126 | Releasing
127 | ---------
128 |
129 | See [RELEASING.md](https://github.com/pwittchen/RxBattery/blob/master/RELEASING.md) file.
130 |
131 | References
132 | ----------
133 | - https://developer.android.com/training/monitoring-device-state/index.html
134 | - https://developer.android.com/training/monitoring-device-state/battery-monitoring.html
135 | - https://developer.android.com/reference/android/os/BatteryManager
136 | - https://developer.android.com/studio/profile/battery-historian.html
137 | - https://stackoverflow.com/questions/3291655/get-battery-level-and-state-in-android
138 | - https://stackoverflow.com/questions/25932677/proper-optimized-way-to-monitor-battery-level-in-android
139 | - https://stackoverflow.com/questions/32608505/broadcast-receiver-monitoring-the-battery-level-and-charging-state
140 | - https://github.com/jaredsburrows/android-gradle-kotlin-app-template
141 | - http://wittchen.io/2018/08/19/writing-my-first-library-in-kotlin/
142 |
143 | Credits
144 | -------
145 |
146 | Logo of the project was created by [@Yasujizr](https://github.com/Yasujizr).
147 |
148 | License
149 | -------
150 |
151 | Copyright 2018 Piotr Wittchen
152 |
153 | Licensed under the Apache License, Version 2.0 (the "License");
154 | you may not use this file except in compliance with the License.
155 | You may obtain a copy of the License at
156 |
157 | http://www.apache.org/licenses/LICENSE-2.0
158 |
159 | Unless required by applicable law or agreed to in writing, software
160 | distributed under the License is distributed on an "AS IS" BASIS,
161 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
162 | See the License for the specific language governing permissions and
163 | limitations under the License.
164 |
--------------------------------------------------------------------------------
/config/quality/checkstyle/checkstyle.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
--------------------------------------------------------------------------------
/app-kotlin/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
11 |
16 |
21 |
26 |
31 |
36 |
41 |
46 |
51 |
56 |
61 |
66 |
71 |
76 |
81 |
86 |
91 |
96 |
101 |
106 |
111 |
116 |
121 |
126 |
131 |
136 |
141 |
146 |
151 |
156 |
161 |
166 |
171 |
172 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 | # Determine the Java command to use to start the JVM.
86 | if [ -n "$JAVA_HOME" ] ; then
87 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
88 | # IBM's JDK on AIX uses strange locations for the executables
89 | JAVACMD="$JAVA_HOME/jre/sh/java"
90 | else
91 | JAVACMD="$JAVA_HOME/bin/java"
92 | fi
93 | if [ ! -x "$JAVACMD" ] ; then
94 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
95 |
96 | Please set the JAVA_HOME variable in your environment to match the
97 | location of your Java installation."
98 | fi
99 | else
100 | JAVACMD="java"
101 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
102 |
103 | Please set the JAVA_HOME variable in your environment to match the
104 | location of your Java installation."
105 | fi
106 |
107 | # Increase the maximum file descriptors if we can.
108 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
109 | MAX_FD_LIMIT=`ulimit -H -n`
110 | if [ $? -eq 0 ] ; then
111 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
112 | MAX_FD="$MAX_FD_LIMIT"
113 | fi
114 | ulimit -n $MAX_FD
115 | if [ $? -ne 0 ] ; then
116 | warn "Could not set maximum file descriptor limit: $MAX_FD"
117 | fi
118 | else
119 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
120 | fi
121 | fi
122 |
123 | # For Darwin, add options to specify how the application appears in the dock
124 | if $darwin; then
125 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
126 | fi
127 |
128 | # For Cygwin or MSYS, switch paths to Windows format before running java
129 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
130 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
131 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
132 | JAVACMD=`cygpath --unix "$JAVACMD"`
133 |
134 | # We build the pattern for arguments to be converted via cygpath
135 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
136 | SEP=""
137 | for dir in $ROOTDIRSRAW ; do
138 | ROOTDIRS="$ROOTDIRS$SEP$dir"
139 | SEP="|"
140 | done
141 | OURCYGPATTERN="(^($ROOTDIRS))"
142 | # Add a user-defined pattern to the cygpath arguments
143 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
144 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
145 | fi
146 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
147 | i=0
148 | for arg in "$@" ; do
149 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
150 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
151 |
152 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
153 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
154 | else
155 | eval `echo args$i`="\"$arg\""
156 | fi
157 | i=`expr $i + 1`
158 | done
159 | case $i in
160 | 0) set -- ;;
161 | 1) set -- "$args0" ;;
162 | 2) set -- "$args0" "$args1" ;;
163 | 3) set -- "$args0" "$args1" "$args2" ;;
164 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
165 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
166 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
167 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
168 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
169 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
170 | esac
171 | fi
172 |
173 | # Escape application args
174 | save () {
175 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
176 | echo " "
177 | }
178 | APP_ARGS=`save "$@"`
179 |
180 | # Collect all arguments for the java command, following the shell quoting and substitution rules
181 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
182 |
183 | exec "$JAVACMD" "$@"
184 |
--------------------------------------------------------------------------------
/library/detekt.yml:
--------------------------------------------------------------------------------
1 | autoCorrect: true
2 | failFast: false
3 |
4 | test-pattern: # Configure exclusions for test sources
5 | active: true
6 | patterns: # Test file regexes
7 | - '.*/test/.*'
8 | - '.*Test.kt'
9 | - '.*Spec.kt'
10 | exclude-rule-sets:
11 | - 'comments'
12 | exclude-rules:
13 | - 'NamingRules'
14 | - 'WildcardImport'
15 | - 'MagicNumber'
16 | - 'MaxLineLength'
17 | - 'LateinitUsage'
18 | - 'StringLiteralDuplication'
19 | - 'SpreadOperator'
20 | - 'TooManyFunctions'
21 |
22 | build:
23 | warningThreshold: 5
24 | failThreshold: 10
25 | weights:
26 | complexity: 2
27 | formatting: 1
28 | LongParameterList: 1
29 | comments: 1
30 |
31 | processors:
32 | active: true
33 | exclude:
34 | # - 'FunctionCountProcessor'
35 | # - 'PropertyCountProcessor'
36 | # - 'ClassCountProcessor'
37 | # - 'PackageCountProcessor'
38 | # - 'KtFileCountProcessor'
39 |
40 | console-reports:
41 | active: true
42 | exclude:
43 | # - 'ProjectStatisticsReport'
44 | # - 'ComplexityReport'
45 | # - 'NotificationReport'
46 | # - 'FindingsReport'
47 | # - 'BuildFailureReport'
48 |
49 | output-reports:
50 | active: true
51 | exclude:
52 | # - 'PlainOutputReport'
53 | # - 'XmlOutputReport'
54 |
55 | comments:
56 | active: true
57 | CommentOverPrivateFunction:
58 | active: false
59 | CommentOverPrivateProperty:
60 | active: false
61 | UndocumentedPublicClass:
62 | active: false
63 | searchInNestedClass: true
64 | searchInInnerClass: true
65 | searchInInnerObject: true
66 | searchInInnerInterface: true
67 | UndocumentedPublicFunction:
68 | active: false
69 |
70 | complexity:
71 | active: true
72 | LongParameterList:
73 | active: true
74 | threshold: 5
75 | LongMethod:
76 | active: true
77 | threshold: 20
78 | LargeClass:
79 | active: true
80 | threshold: 150
81 | ComplexInterface:
82 | active: false
83 | threshold: 10
84 | includeStaticDeclarations: false
85 | ComplexMethod:
86 | active: true
87 | threshold: 10
88 | StringLiteralDuplication:
89 | active: false
90 | threshold: 2
91 | ignoreAnnotation: true
92 | excludeStringsWithLessThan5Characters: true
93 | ignoreStringsRegex: '$^'
94 | MethodOverloading:
95 | active: false
96 | threshold: 5
97 | NestedBlockDepth:
98 | active: true
99 | threshold: 3
100 | TooManyFunctions:
101 | active: true
102 | thresholdInFiles: 10
103 | thresholdInClasses: 10
104 | thresholdInInterfaces: 10
105 | thresholdInObjects: 10
106 | thresholdInEnums: 10
107 | ComplexCondition:
108 | active: true
109 | threshold: 3
110 | LabeledExpression:
111 | active: false
112 |
113 | empty-blocks:
114 | active: true
115 | EmptyCatchBlock:
116 | active: true
117 | EmptyClassBlock:
118 | active: true
119 | EmptyDefaultConstructor:
120 | active: true
121 | EmptyDoWhileBlock:
122 | active: true
123 | EmptyElseBlock:
124 | active: true
125 | EmptyFinallyBlock:
126 | active: true
127 | EmptyForBlock:
128 | active: true
129 | EmptyFunctionBlock:
130 | active: true
131 | EmptyIfBlock:
132 | active: true
133 | EmptyInitBlock:
134 | active: true
135 | EmptyKtFile:
136 | active: true
137 | EmptySecondaryConstructor:
138 | active: true
139 | EmptyWhenBlock:
140 | active: true
141 | EmptyWhileBlock:
142 | active: true
143 |
144 | exceptions:
145 | active: true
146 | TooGenericExceptionCaught:
147 | active: true
148 | exceptions:
149 | - ArrayIndexOutOfBoundsException
150 | - Error
151 | - Exception
152 | - IllegalMonitorStateException
153 | - NullPointerException
154 | - IndexOutOfBoundsException
155 | - RuntimeException
156 | - Throwable
157 | ExceptionRaisedInUnexpectedLocation:
158 | active: false
159 | methodNames: 'toString,hashCode,equals,finalize'
160 | TooGenericExceptionThrown:
161 | active: true
162 | exceptions:
163 | - Error
164 | - Exception
165 | - NullPointerException
166 | - Throwable
167 | - RuntimeException
168 | NotImplementedDeclaration:
169 | active: false
170 | PrintStackTrace:
171 | active: false
172 | InstanceOfCheckForException:
173 | active: false
174 | ThrowingExceptionsWithoutMessageOrCause:
175 | active: false
176 | exceptions: 'IllegalArgumentException,IllegalStateException,IOException'
177 | ReturnFromFinally:
178 | active: false
179 | ThrowingExceptionFromFinally:
180 | active: false
181 | ThrowingExceptionInMain:
182 | active: false
183 | RethrowCaughtException:
184 | active: false
185 | ThrowingNewInstanceOfSameException:
186 | active: false
187 | SwallowedException:
188 | active: false
189 |
190 | performance:
191 | active: true
192 | ForEachOnRange:
193 | active: true
194 | SpreadOperator:
195 | active: true
196 | UnnecessaryTemporaryInstantiation:
197 | active: true
198 |
199 | potential-bugs:
200 | active: true
201 | DuplicateCaseInWhenExpression:
202 | active: true
203 | EqualsAlwaysReturnsTrueOrFalse:
204 | active: false
205 | EqualsWithHashCodeExist:
206 | active: true
207 | IteratorNotThrowingNoSuchElementException:
208 | active: false
209 | IteratorHasNextCallsNextMethod:
210 | active: false
211 | UselessPostfixExpression:
212 | active: false
213 | InvalidLoopCondition:
214 | active: false
215 | WrongEqualsTypeParameter:
216 | active: false
217 | ExplicitGarbageCollectionCall:
218 | active: true
219 | LateinitUsage:
220 | active: false
221 | excludeAnnotatedProperties: ""
222 | ignoreOnClassesPattern: ""
223 | UnconditionalJumpStatementInLoop:
224 | active: false
225 | UnreachableCode:
226 | active: true
227 | UnsafeCallOnNullableType:
228 | active: false
229 | UnsafeCast:
230 | active: false
231 |
232 | style:
233 | active: true
234 | CollapsibleIfStatements:
235 | active: false
236 | ReturnCount:
237 | active: true
238 | max: 2
239 | excludedFunctions: "equals"
240 | ThrowsCount:
241 | active: true
242 | max: 2
243 | NewLineAtEndOfFile:
244 | active: false
245 | WildcardImport:
246 | active: true
247 | excludeImports: 'java.util.*,kotlinx.android.synthetic.*'
248 | MaxLineLength:
249 | active: true
250 | maxLineLength: 120
251 | excludePackageStatements: false
252 | excludeImportStatements: false
253 | EqualsNullCall:
254 | active: false
255 | ForbiddenComment:
256 | active: true
257 | values: 'TODO:,FIXME:,STOPSHIP:'
258 | ForbiddenImport:
259 | active: false
260 | imports: ''
261 | FunctionOnlyReturningConstant:
262 | active: false
263 | ignoreOverridableFunction: true
264 | excludedFunctions: 'describeContents'
265 | SpacingBetweenPackageAndImports:
266 | active: false
267 | LoopWithTooManyJumpStatements:
268 | active: false
269 | maxJumpCount: 1
270 | MemberNameEqualsClassName:
271 | active: false
272 | ignoreOverriddenFunction: true
273 | VariableNaming:
274 | active: true
275 | variablePattern: '[a-z][A-Za-z0-9]*'
276 | privateVariablePattern: '(_)?[a-z][A-Za-z0-9]*'
277 | VariableMinLength:
278 | active: false
279 | minimumVariableNameLength: 1
280 | VariableMaxLength:
281 | active: false
282 | maximumVariableNameLength: 64
283 | TopLevelPropertyNaming:
284 | active: true
285 | constantPattern: '[A-Z][_A-Z0-9]*'
286 | propertyPattern: '[a-z][A-Za-z\d]*'
287 | privatePropertyPattern: '(_)?[a-z][A-Za-z0-9]*'
288 | ObjectPropertyNaming:
289 | active: true
290 | propertyPattern: '[A-Za-z][_A-Za-z0-9]*'
291 | PackageNaming:
292 | active: true
293 | packagePattern: '^[a-z]+(\.[a-z][a-z0-9]*)*$'
294 | ClassNaming:
295 | active: true
296 | classPattern: '[A-Z$][a-zA-Z0-9$]*'
297 | EnumNaming:
298 | active: true
299 | enumEntryPattern: '^[A-Z$][a-zA-Z_$]*$'
300 | FunctionNaming:
301 | active: true
302 | functionPattern: '^([a-z$][a-zA-Z$0-9]*)|(`.*`)$'
303 | FunctionMaxLength:
304 | active: false
305 | maximumFunctionNameLength: 30
306 | FunctionMinLength:
307 | active: false
308 | minimumFunctionNameLength: 3
309 | ForbiddenClassName:
310 | active: false
311 | forbiddenName: ''
312 | SafeCast:
313 | active: true
314 | UnnecessaryAbstractClass:
315 | active: false
316 | UnnecessaryParentheses:
317 | active: false
318 | UnnecessaryInheritance:
319 | active: false
320 | UtilityClassWithPublicConstructor:
321 | active: false
322 | OptionalAbstractKeyword:
323 | active: true
324 | OptionalWhenBraces:
325 | active: false
326 | OptionalReturnKeyword:
327 | active: false
328 | OptionalUnit:
329 | active: false
330 | ProtectedMemberInFinalClass:
331 | active: false
332 | SerialVersionUIDInSerializableClass:
333 | active: false
334 | MagicNumber:
335 | active: true
336 | ignoreNumbers: '-1,0,1,2'
337 | ignoreHashCodeFunction: false
338 | ignorePropertyDeclaration: false
339 | ignoreConstantDeclaration: true
340 | ignoreCompanionObjectPropertyDeclaration: true
341 | ignoreAnnotation: false
342 | ignoreNamedArgument: true
343 | ignoreEnums: false
344 | ModifierOrder:
345 | active: true
346 | DataClassContainsFunctions:
347 | active: false
348 | conversionFunctionPrefix: 'to'
349 | UseDataClass:
350 | active: false
351 | UnusedImports:
352 | active: false
353 | ExpressionBodySyntax:
354 | active: false
355 | NestedClassesVisibility:
356 | active: false
357 | RedundantVisibilityModifierRule:
358 | active: false
359 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------