├── lib
├── consumer-rules.pro
├── proguard-rules.pro
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── values-night
│ │ │ └── styles.xml
│ │ ├── drawable-hdpi
│ │ │ ├── ic_notification.png
│ │ │ └── ic_notification_customized.png
│ │ ├── drawable-mdpi
│ │ │ ├── ic_notification.png
│ │ │ └── ic_notification_customized.png
│ │ ├── drawable-xhdpi
│ │ │ ├── ic_notification.png
│ │ │ └── ic_notification_customized.png
│ │ ├── drawable-xxhdpi
│ │ │ ├── ic_notification.png
│ │ │ └── ic_notification_customized.png
│ │ ├── values
│ │ │ ├── ic_bubble_adaptive_background.xml
│ │ │ ├── dimens.xml
│ │ │ ├── colors.xml
│ │ │ ├── ic_bubble_adaptive_customized_background.xml
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ │ ├── drawable-v26
│ │ │ ├── ic_bubble_adaptive.xml
│ │ │ ├── ic_bubble_adaptive_customized.xml
│ │ │ └── ic_bubble_adaptive_foreground.xml
│ │ ├── drawable
│ │ │ ├── ic_scroll_top_top.xml
│ │ │ ├── ic_close.xml
│ │ │ ├── ic_delete_logs.xml
│ │ │ ├── ic_bubble_legacy_customized.xml
│ │ │ ├── ic_bubble_adaptive_customized_foreground.xml
│ │ │ ├── ic_bubble_legacy.xml
│ │ │ ├── ic_notification.xml
│ │ │ └── button_bubble_fab_state_list.xml
│ │ ├── values-v23
│ │ │ └── styles.xml
│ │ ├── values-v29
│ │ │ └── styles.xml
│ │ ├── values-v27
│ │ │ └── styles.xml
│ │ ├── drawable-anydpi-v24
│ │ │ ├── ic_notification_customized.xml
│ │ │ └── ic_notification.xml
│ │ └── layout
│ │ │ ├── list_item_log.xml
│ │ │ └── activity_bubble.xml
│ │ ├── java
│ │ └── com
│ │ │ └── hiking
│ │ │ └── bubblelogger
│ │ │ ├── screen
│ │ │ ├── BubbleViewModel.kt
│ │ │ ├── BubbleListAdapter.kt
│ │ │ └── BubbleActivity.kt
│ │ │ ├── extension
│ │ │ ├── EditTextExtension.kt
│ │ │ └── ActivityExtensions.kt
│ │ │ ├── BubbleDataHelper.kt
│ │ │ ├── viewholder
│ │ │ └── LogViewHolder.kt
│ │ │ └── BubbleLogger.kt
│ │ └── AndroidManifest.xml
└── build.gradle
├── example
├── proguard-rules.pro
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── values-night
│ │ │ └── styles.xml
│ │ ├── mipmap-hdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── values
│ │ │ ├── ic_launcher_background.xml
│ │ │ ├── lorem.xml
│ │ │ ├── colors.xml
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ │ ├── values-v27
│ │ │ └── styles.xml
│ │ ├── mipmap-anydpi-v26
│ │ │ └── ic_launcher.xml
│ │ ├── drawable
│ │ │ └── ic_launcher_foreground.xml
│ │ └── layout
│ │ │ └── activity_main.xml
│ │ ├── ic_launcher-playstore.png
│ │ ├── java
│ │ └── com
│ │ │ └── hiking
│ │ │ └── bubblelogger
│ │ │ └── example
│ │ │ ├── extension
│ │ │ ├── FloatExtensions.kt
│ │ │ └── ActivityExtensions.kt
│ │ │ ├── MainViewModel.kt
│ │ │ └── MainActivity.kt
│ │ └── AndroidManifest.xml
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .idea
├── codeStyles
│ ├── codeStyleConfig.xml
│ └── Project.xml
├── runConfigurations.xml
└── compiler.xml
├── .travis.yml
├── .gitignore
├── gradle.properties
├── gradlew.bat
├── README.md
└── gradlew
/lib/consumer-rules.pro:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/lib/proguard-rules.pro:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/example/proguard-rules.pro:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/lib/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/example/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name='android-bubble-logger'
2 | include ':example'
3 | include ':lib'
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hiking93/android-bubble-logger/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/example/src/main/res/values-night/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/lib/src/main/res/values-night/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/example/src/main/ic_launcher-playstore.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hiking93/android-bubble-logger/HEAD/example/src/main/ic_launcher-playstore.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hiking93/android-bubble-logger/HEAD/example/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hiking93/android-bubble-logger/HEAD/example/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hiking93/android-bubble-logger/HEAD/example/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hiking93/android-bubble-logger/HEAD/example/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hiking93/android-bubble-logger/HEAD/example/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/lib/src/main/res/drawable-hdpi/ic_notification.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hiking93/android-bubble-logger/HEAD/lib/src/main/res/drawable-hdpi/ic_notification.png
--------------------------------------------------------------------------------
/lib/src/main/res/drawable-mdpi/ic_notification.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hiking93/android-bubble-logger/HEAD/lib/src/main/res/drawable-mdpi/ic_notification.png
--------------------------------------------------------------------------------
/lib/src/main/res/drawable-xhdpi/ic_notification.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hiking93/android-bubble-logger/HEAD/lib/src/main/res/drawable-xhdpi/ic_notification.png
--------------------------------------------------------------------------------
/lib/src/main/res/drawable-xxhdpi/ic_notification.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hiking93/android-bubble-logger/HEAD/lib/src/main/res/drawable-xxhdpi/ic_notification.png
--------------------------------------------------------------------------------
/example/src/main/res/values/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #006AA6
4 |
--------------------------------------------------------------------------------
/lib/src/main/res/drawable-hdpi/ic_notification_customized.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hiking93/android-bubble-logger/HEAD/lib/src/main/res/drawable-hdpi/ic_notification_customized.png
--------------------------------------------------------------------------------
/lib/src/main/res/drawable-mdpi/ic_notification_customized.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hiking93/android-bubble-logger/HEAD/lib/src/main/res/drawable-mdpi/ic_notification_customized.png
--------------------------------------------------------------------------------
/lib/src/main/res/drawable-xhdpi/ic_notification_customized.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hiking93/android-bubble-logger/HEAD/lib/src/main/res/drawable-xhdpi/ic_notification_customized.png
--------------------------------------------------------------------------------
/lib/src/main/res/drawable-xxhdpi/ic_notification_customized.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hiking93/android-bubble-logger/HEAD/lib/src/main/res/drawable-xxhdpi/ic_notification_customized.png
--------------------------------------------------------------------------------
/lib/src/main/res/values/ic_bubble_adaptive_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #424242
4 |
--------------------------------------------------------------------------------
/.idea/codeStyles/codeStyleConfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/lib/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 6dp
4 | 12dp
5 |
--------------------------------------------------------------------------------
/lib/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #8000
4 | #dfff
5 |
--------------------------------------------------------------------------------
/lib/src/main/res/values/ic_bubble_adaptive_customized_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #E91E63
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | zipStoreBase=GRADLE_USER_HOME
4 | zipStorePath=wrapper/dists
5 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: android
2 | jdk: oraclejdk8
3 | android:
4 | components:
5 | - platform-tools
6 | - build-tools-30.0.0
7 | - android-30
8 | before_install:
9 | - chmod +x gradlew
10 | - yes | sdkmanager "platforms;android-30"
--------------------------------------------------------------------------------
/example/src/main/res/values-v27/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/lib/src/main/java/com/hiking/bubblelogger/screen/BubbleViewModel.kt:
--------------------------------------------------------------------------------
1 | package com.hiking.bubblelogger.screen
2 |
3 | import androidx.lifecycle.ViewModel
4 | import com.hiking.bubblelogger.BubbleDataHelper
5 |
6 | internal class BubbleViewModel : ViewModel() {
7 |
8 | val logs = BubbleDataHelper.logs
9 | }
--------------------------------------------------------------------------------
/example/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/lib/src/main/res/drawable-v26/ic_bubble_adaptive.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/lib/src/main/res/drawable-v26/ic_bubble_adaptive_customized.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/lib/src/main/res/drawable/ic_scroll_top_top.xml:
--------------------------------------------------------------------------------
1 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/lib/src/main/res/values-v23/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/lib/src/main/res/drawable/ic_close.xml:
--------------------------------------------------------------------------------
1 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/lib/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/lib/src/main/res/values-v29/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/lib/src/main/res/values-v27/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/lib/src/main/res/drawable/ic_delete_logs.xml:
--------------------------------------------------------------------------------
1 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/lib/src/main/res/drawable/ic_bubble_legacy_customized.xml:
--------------------------------------------------------------------------------
1 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/lib/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Bubble Logger
3 | Scroll to top
4 | Clear all logs
5 | Reset filter
6 | Filter items
7 | No logs.
8 | No match.
9 |
10 |
--------------------------------------------------------------------------------
/example/src/main/java/com/hiking/bubblelogger/example/extension/FloatExtensions.kt:
--------------------------------------------------------------------------------
1 | package com.hiking.bubblelogger.example.extension
2 |
3 | import android.content.Context
4 | import kotlin.math.roundToInt
5 |
6 | /**
7 | * Convert dp to pixels (float value).
8 | */
9 | fun Float.dpToPx(context: Context) = this * context.resources.displayMetrics.density
10 |
11 | /**
12 | * Convert dp to pixels and round to integer.
13 | */
14 | fun Float.dpToPxSize(context: Context) = dpToPx(context).roundToInt()
--------------------------------------------------------------------------------
/lib/src/main/java/com/hiking/bubblelogger/extension/EditTextExtension.kt:
--------------------------------------------------------------------------------
1 | package com.hiking.bubblelogger.extension
2 |
3 | import android.app.Activity
4 | import android.view.inputmethod.InputMethodManager
5 | import android.widget.EditText
6 |
7 | /**
8 | * Clear focus of the [EditText] and hide IME.
9 | */
10 | fun EditText.clearFocusAndHideIme() {
11 | clearFocus()
12 | (context.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager)
13 | .hideSoftInputFromWindow(windowToken, 0)
14 | }
--------------------------------------------------------------------------------
/example/src/main/res/values/lorem.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
4 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/lib/src/main/res/drawable/ic_bubble_adaptive_customized_foreground.xml:
--------------------------------------------------------------------------------
1 |
8 |
13 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/lib/src/main/res/drawable/ic_bubble_legacy.xml:
--------------------------------------------------------------------------------
1 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/lib/src/main/res/drawable-anydpi-v24/ic_notification_customized.xml:
--------------------------------------------------------------------------------
1 |
7 |
11 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/example/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #009688
4 | #00675b
5 | #2196f3
6 | #0069c0
7 | #4db6ac
8 | #82e9de
9 | #64b5f6
10 | #9be7ff
11 | #8000
12 | #dfff
13 | #416275
14 |
15 |
--------------------------------------------------------------------------------
/example/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Bubble Logger Example
3 | Title
4 | Message
5 | Sample Title
6 | This is a sample message.
7 | Send to bubble
8 | @string/app_name
9 | Channel for bubble logger popup.
10 | Generate random logs
11 | Customized style
12 |
13 |
--------------------------------------------------------------------------------
/lib/src/main/java/com/hiking/bubblelogger/extension/ActivityExtensions.kt:
--------------------------------------------------------------------------------
1 | package com.hiking.bubblelogger.extension
2 |
3 | import android.app.Activity
4 | import android.os.Build
5 | import android.view.View
6 |
7 | /**
8 | * Set system decor for edge-to-edge UI.
9 | */
10 | fun Activity.applyEdgeToEdge() {
11 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
12 | window.setDecorFitsSystemWindows(true)
13 | } else {
14 | window.decorView.apply {
15 | @Suppress("DEPRECATION")
16 | systemUiVisibility = systemUiVisibility or
17 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
18 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
19 | }
20 | }
21 | }
--------------------------------------------------------------------------------
/example/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
11 |
12 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/example/src/main/java/com/hiking/bubblelogger/example/extension/ActivityExtensions.kt:
--------------------------------------------------------------------------------
1 | package com.hiking.bubblelogger.example.extension
2 |
3 | import android.app.Activity
4 | import android.os.Build
5 | import android.view.View
6 |
7 | /**
8 | * Set system decor for edge-to-edge UI.
9 | */
10 | fun Activity.applyEdgeToEdge() {
11 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
12 | window.setDecorFitsSystemWindows(true)
13 | } else {
14 | window.decorView.apply {
15 | @Suppress("DEPRECATION")
16 | systemUiVisibility = systemUiVisibility or
17 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
18 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
19 | }
20 | }
21 | }
--------------------------------------------------------------------------------
/example/src/main/res/drawable/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
8 |
11 |
14 |
17 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/lib/src/main/res/drawable/ic_notification.xml:
--------------------------------------------------------------------------------
1 |
8 |
11 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/lib/src/main/res/drawable/button_bubble_fab_state_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
4 |
8 |
9 | -
10 |
14 |
15 |
--------------------------------------------------------------------------------
/lib/src/main/res/drawable-v26/ic_bubble_adaptive_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/lib/src/main/res/drawable-anydpi-v24/ic_notification.xml:
--------------------------------------------------------------------------------
1 |
7 |
11 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 | *.aab
5 |
6 | # Files for the ART/Dalvik VM
7 | *.dex
8 |
9 | # Java class files
10 | *.class
11 |
12 | # Generated files
13 | bin/
14 | gen/
15 | out/
16 | release/
17 |
18 | # Gradle files
19 | .gradle/
20 | build/
21 |
22 | # Local configuration file (sdk path, etc)
23 | local.properties
24 |
25 | # Proguard folder generated by Eclipse
26 | proguard/
27 |
28 | # Log Files
29 | *.log
30 |
31 | # Android Studio captures folder
32 | captures/
33 |
34 | # IntelliJ
35 | *.iml
36 | .idea/workspace.xml
37 | .idea/tasks.xml
38 | .idea/gradle.xml
39 | .idea/assetWizardSettings.xml
40 | .idea/dictionaries
41 | .idea/libraries
42 | .idea/caches
43 | .idea/jarRepositories.xml
44 | .idea/modules.xml
45 | .idea/misc.xml
46 | .idea/navEditor.xml
47 |
48 | # macOS files
49 | .DS_Store
50 |
51 | # External native build folder generated in Android Studio 2.2 and later
52 | .externalNativeBuild
53 |
54 | # Version control
55 | vcs.xml
--------------------------------------------------------------------------------
/lib/src/main/java/com/hiking/bubblelogger/BubbleDataHelper.kt:
--------------------------------------------------------------------------------
1 | package com.hiking.bubblelogger
2 |
3 | import androidx.lifecycle.MutableLiveData
4 | import kotlinx.coroutines.Dispatchers
5 | import kotlinx.coroutines.GlobalScope
6 | import kotlinx.coroutines.launch
7 |
8 | internal object BubbleDataHelper {
9 |
10 | data class Log(
11 | val id: Long,
12 | val title: CharSequence?,
13 | val message: CharSequence,
14 | val timestamp: Long
15 | )
16 |
17 | val logs = MutableLiveData?>()
18 |
19 | fun log(title: CharSequence?, message: CharSequence) {
20 | GlobalScope.launch(Dispatchers.Main) {
21 | val log = Log(
22 | id = System.nanoTime(),
23 | title = title,
24 | message = message,
25 | timestamp = System.currentTimeMillis()
26 | )
27 | logs.apply { value = (value?.let { it + log } ?: listOf(log)) }
28 | }
29 | }
30 |
31 | fun clearLogs() {
32 | logs.value = null
33 | }
34 | }
--------------------------------------------------------------------------------
/lib/src/main/res/layout/list_item_log.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
17 |
18 |
25 |
26 |
32 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 | # Kotlin code style for this project: "official" or "obsolete":
21 | kotlin.code.style=official
22 |
--------------------------------------------------------------------------------
/example/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 |
5 | android {
6 | compileSdkVersion 30
7 |
8 | defaultConfig {
9 | applicationId "com.hiking.bubblelogger.example"
10 | minSdkVersion 21
11 | targetSdkVersion 30
12 | versionCode 2
13 | versionName "1.0.1"
14 | }
15 |
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),
20 | 'proguard-rules.pro'
21 | }
22 | }
23 |
24 | compileOptions {
25 | sourceCompatibility JavaVersion.VERSION_1_8
26 | targetCompatibility JavaVersion.VERSION_1_8
27 | }
28 |
29 | kotlinOptions {
30 | jvmTarget = "1.8"
31 | }
32 | }
33 |
34 | dependencies {
35 | implementation fileTree(dir: 'libs', include: ['*.jar'])
36 | implementation project(':lib')
37 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
38 | implementation 'androidx.activity:activity-ktx:1.1.0'
39 | implementation 'androidx.appcompat:appcompat:1.1.0'
40 | implementation 'androidx.core:core-ktx:1.3.0'
41 | implementation 'com.google.android.material:material:1.1.0-rc02'
42 | }
43 |
--------------------------------------------------------------------------------
/lib/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 |
5 | android {
6 | compileSdkVersion 30
7 |
8 | defaultConfig {
9 | minSdkVersion 21
10 | targetSdkVersion 30
11 | versionCode 2
12 | versionName "1.0.1"
13 | consumerProguardFiles 'consumer-rules.pro'
14 | }
15 |
16 | buildTypes {
17 | release {
18 | minifyEnabled true
19 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),
20 | 'proguard-rules.pro'
21 | }
22 | }
23 |
24 | compileOptions {
25 | sourceCompatibility JavaVersion.VERSION_1_8
26 | targetCompatibility JavaVersion.VERSION_1_8
27 | }
28 |
29 | kotlinOptions {
30 | jvmTarget = "1.8"
31 | }
32 | }
33 |
34 | ext {
35 | coroutinesVersion = '1.3.6'
36 | }
37 |
38 | dependencies {
39 | implementation fileTree(dir: 'libs', include: ['*.jar'])
40 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
41 | implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion"
42 | implementation 'androidx.activity:activity-ktx:1.1.0'
43 | implementation 'androidx.appcompat:appcompat:1.1.0'
44 | implementation 'androidx.core:core-ktx:1.3.0'
45 | implementation 'com.google.android.material:material:1.1.0-rc02'
46 | }
47 |
--------------------------------------------------------------------------------
/lib/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
12 |
13 |
17 |
18 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/example/src/main/java/com/hiking/bubblelogger/example/MainViewModel.kt:
--------------------------------------------------------------------------------
1 | package com.hiking.bubblelogger.example
2 |
3 | import android.content.Context
4 | import androidx.lifecycle.ViewModel
5 | import androidx.lifecycle.viewModelScope
6 | import kotlinx.coroutines.Job
7 | import kotlinx.coroutines.delay
8 | import kotlinx.coroutines.launch
9 |
10 | /**
11 | * [ViewModel] for [MainActivity].
12 | */
13 | class MainViewModel : ViewModel() {
14 |
15 | var demoLogListener: ((title: String, message: String) -> Unit)? = null
16 |
17 | private var demoJob: Job? = null
18 |
19 | /**
20 | * Update demo mode state.
21 | *
22 | * @param context Context for resources.
23 | * @param isEnabled Set demo mode enabled or not.
24 | */
25 | fun updateDemoMode(context: Context, isEnabled: Boolean) {
26 | demoJob?.cancel()
27 | if (!isEnabled) return
28 | val loremText = context.getString(R.string.lorem_paragraph)
29 | demoJob = viewModelScope.launch {
30 | while (true) {
31 | demoLogListener?.invoke(
32 | generateLoremTextClip(loremText, maxLength = 10),
33 | generateLoremTextClip(loremText)
34 | )
35 | delay((300L..1000L).random())
36 | }
37 | }
38 | }
39 |
40 | private fun generateLoremTextClip(
41 | loremText: String,
42 | maxLength: Int? = null
43 | ): String {
44 | val startIndex = (0..loremText.length / 2).random()
45 | val randomRange =
46 | (startIndex + 10)..(maxLength?.let { startIndex + 10 + it } ?: loremText.length)
47 | val endIndex = randomRange.random()
48 | return loremText.substring(startIndex, endIndex).trim()
49 | }
50 | }
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/example/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
24 |
25 |
28 |
29 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/lib/src/main/java/com/hiking/bubblelogger/viewholder/LogViewHolder.kt:
--------------------------------------------------------------------------------
1 | package com.hiking.bubblelogger.viewholder
2 |
3 | import android.graphics.Typeface
4 | import android.text.SpannableStringBuilder
5 | import android.text.Spanned
6 | import android.text.style.StyleSpan
7 | import android.text.style.UnderlineSpan
8 | import android.view.LayoutInflater
9 | import android.view.View
10 | import android.view.ViewGroup
11 | import androidx.recyclerview.widget.RecyclerView
12 | import com.hiking.bubblelogger.R
13 | import kotlinx.android.synthetic.main.list_item_log.view.*
14 | import java.text.DateFormat
15 | import java.util.*
16 |
17 | /**
18 | * [RecyclerView.ViewHolder] for a log in the bubble.
19 | */
20 | class LogViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
21 |
22 | companion object {
23 |
24 | private val dateFormat = DateFormat.getDateTimeInstance()
25 |
26 | /**
27 | * Create an instance of [LogViewHolder].
28 | */
29 | fun create(parent: ViewGroup) = LogViewHolder(
30 | LayoutInflater.from(parent.context)
31 | .inflate(R.layout.list_item_log, parent, false)
32 | )
33 | }
34 |
35 | private val titleTextView = itemView.titleTextView
36 | private val contentTextView = itemView.contentTextView
37 | private val timeTextView = itemView.timeTextView
38 |
39 | /**
40 | * Bind data to this [LogViewHolder].
41 | * @param title Title of the log.
42 | * @param content Content of the log.
43 | * @param timestamp Timestamp of the log.
44 | * @param filterStrings Filter strings for text highlighting.
45 | */
46 | fun bind(
47 | title: CharSequence?,
48 | content: CharSequence,
49 | timestamp: Long,
50 | filterStrings: List
51 | ) {
52 | titleTextView.apply {
53 | visibility = if (title == null) View.GONE else View.VISIBLE
54 | text = title.highlightedWith(filterStrings)
55 | }
56 | contentTextView.text = content.highlightedWith(filterStrings)
57 | timeTextView.text = dateFormat.format(Date(timestamp))
58 | }
59 |
60 | private fun CharSequence?.highlightedWith(
61 | filterStrings: List
62 | ) = SpannableStringBuilder(this).apply {
63 | for (filterString in filterStrings) {
64 | val startIndex = indexOf(filterString).let { if (it == -1) null else it } ?: continue
65 | val endIndex = startIndex + filterString.length
66 | setSpan(
67 | StyleSpan(Typeface.BOLD),
68 | startIndex,
69 | endIndex,
70 | Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
71 | )
72 | setSpan(
73 | UnderlineSpan(),
74 | startIndex,
75 | endIndex,
76 | Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
77 | )
78 | }
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Android Bubble Logger
2 |
3 | [](https://travis-ci.org/hiking93/android-bubble-logger)
4 | [](https://jitpack.io/#hiking93/android-bubble-logger)
5 | [](https://www.codacy.com/manual/hiking93/android-bubble-logger?utm_source=github.com&utm_medium=referral&utm_content=hiking93/android-bubble-logger&utm_campaign=Badge_Grade)
6 | [](https://codeclimate.com/github/hiking93/android-bubble-logger/maintainability)
7 |
8 | A tool to display logs within a floating bubble.
9 |
10 | 
11 |
12 | ## Features
13 |
14 | * Display logs within a floating bubble.
15 | * Filter items with mulitiple keywords.
16 | * System dark mode support of Android 10+.
17 |
18 | ## Requirements
19 |
20 | To display logs in a bubble, you need Android version that supports [Bubble API](https://developer.android.com/guide/topics/ui/bubbles).
21 |
22 | * Android 11 or later
23 | * Android 10 with Bubbles enabled in developer settings.
24 |
25 | ## Screenshots
26 |
27 | 
28 | 
29 | 
30 |
31 | ## Add Dependency
32 |
33 | Add it in your root build.gradle at the end of repositories:
34 |
35 | ```groovy
36 | allprojects {
37 | repositories {
38 | ...
39 | maven { url 'https://jitpack.io' }
40 | }
41 | }
42 | ```
43 |
44 | Then add the dependency:
45 |
46 | ```groovy
47 | dependencies {
48 | implementation 'com.github.hiking93:android-bubble-logger:latestVersion'
49 | }
50 | ```
51 |
52 | ## Usage
53 |
54 | To add a log in the bubble:
55 |
56 | ```kotlin
57 | BubbleLogger.log(
58 | context = context,
59 | title = title,
60 | message = message,
61 | notificationId = NOTIFICATION_ID,
62 | notificationChannelId = CHANNEL_ID_BUBBLE_LOGGER
63 | )
64 | ```
65 |
66 | See [example project](https://github.com/hiking93/android-bubble-logger/tree/master/example) for full usage example.
67 |
68 | ## License
69 |
70 | ```lang-none
71 | Copyright Hsingchien Cheng
72 |
73 | Licensed under the Apache License, Version 2.0 (the "License");
74 | you may not use this file except in compliance with the License.
75 | You may obtain a copy of the License at
76 |
77 | http://www.apache.org/licenses/LICENSE-2.0
78 |
79 | Unless required by applicable law or agreed to in writing, software
80 | distributed under the License is distributed on an "AS IS" BASIS,
81 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
82 | See the License for the specific language governing permissions and
83 | limitations under the License.
84 | ```
85 |
--------------------------------------------------------------------------------
/example/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
16 |
17 |
23 |
24 |
25 |
30 |
31 |
38 |
39 |
45 |
46 |
53 |
54 |
59 |
60 |
67 |
68 |
69 |
74 |
75 |
82 |
83 |
84 |
90 |
91 |
92 |
93 |
--------------------------------------------------------------------------------
/lib/src/main/java/com/hiking/bubblelogger/BubbleLogger.kt:
--------------------------------------------------------------------------------
1 | package com.hiking.bubblelogger
2 |
3 | import android.app.PendingIntent
4 | import android.content.Context
5 | import android.content.Intent
6 | import android.os.Build
7 | import androidx.annotation.Dimension
8 | import androidx.annotation.DrawableRes
9 | import androidx.annotation.Keep
10 | import androidx.core.app.NotificationCompat
11 | import androidx.core.app.NotificationManagerCompat
12 | import androidx.core.app.Person
13 | import androidx.core.graphics.drawable.IconCompat
14 | import com.hiking.bubblelogger.screen.BubbleActivity
15 |
16 | /**
17 | * Main library class for bubble logger.
18 | */
19 | @Keep
20 | object BubbleLogger {
21 |
22 | /**
23 | * Add a log to bubble.
24 | *
25 | * @param context Context for the bubble notification.
26 | * @param title The title text of the og.
27 | * @param message The message text of the log.
28 | * @param notificationId The ID for the bubble notification.
29 | * @param notificationChannelId The channel ID for the bubble notification.
30 | * @param adaptiveBubbleIconResource
31 | * Adaptive icon resource for Android 11 (R, API 30) or later.
32 | * @param legacyBubbleIconResource Legacy icon resource for Android 10 (Q, API 29).
33 | * @param notificationIconResource Icon resource for bubble notification.
34 | */
35 | fun log(
36 | context: Context,
37 | title: CharSequence?,
38 | message: CharSequence,
39 | notificationId: Int,
40 | notificationChannelId: String,
41 | @Dimension(unit = Dimension.DP) desiredHeight: Int = 640,
42 | @DrawableRes adaptiveBubbleIconResource: Int = R.drawable.ic_bubble_adaptive,
43 | @DrawableRes legacyBubbleIconResource: Int = R.drawable.ic_bubble_legacy,
44 | @DrawableRes notificationIconResource: Int = R.drawable.ic_notification
45 | ) {
46 | BubbleDataHelper.log(title, message)
47 | val target = Intent(context, BubbleActivity::class.java)
48 | val bubbleIntent =
49 | PendingIntent.getActivity(context, 0, target, PendingIntent.FLAG_UPDATE_CURRENT)
50 | val bubbleIcon = IconCompat.createWithResource(
51 | context,
52 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) adaptiveBubbleIconResource
53 | else legacyBubbleIconResource
54 | )
55 | val bubbleMetadata =
56 | NotificationCompat.BubbleMetadata.Builder()
57 | .setIcon(bubbleIcon)
58 | .setIntent(bubbleIntent)
59 | .setDesiredHeight(desiredHeight)
60 | .build()
61 | val notificationTitle = title ?: context.getString(R.string.bubble_logger)
62 | val bot = Person.Builder()
63 | .setIcon(bubbleIcon)
64 | .setBot(true)
65 | .setName(notificationTitle)
66 | .setImportant(true)
67 | .build()
68 | val builder = NotificationCompat.Builder(context, notificationChannelId)
69 | .setStyle(
70 | NotificationCompat.MessagingStyle(bot)
71 | .setConversationTitle(notificationTitle)
72 | .addMessage(
73 | NotificationCompat.MessagingStyle.Message(
74 | message, System.currentTimeMillis(), bot
75 | )
76 | )
77 | )
78 | .setContentTitle(notificationTitle)
79 | .setContentText(message)
80 | .setSmallIcon(notificationIconResource)
81 | .setBubbleMetadata(bubbleMetadata)
82 | NotificationManagerCompat.from(context).notify(notificationId, builder.build())
83 | }
84 | }
--------------------------------------------------------------------------------
/lib/src/main/res/layout/activity_bubble.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
17 |
18 |
27 |
28 |
38 |
39 |
50 |
51 |
60 |
61 |
62 |
63 |
67 |
68 |
74 |
75 |
83 |
84 |
97 |
98 |
99 |
--------------------------------------------------------------------------------
/lib/src/main/java/com/hiking/bubblelogger/screen/BubbleListAdapter.kt:
--------------------------------------------------------------------------------
1 | package com.hiking.bubblelogger.screen
2 |
3 | import android.view.ViewGroup
4 | import androidx.recyclerview.widget.DiffUtil
5 | import androidx.recyclerview.widget.RecyclerView
6 | import com.hiking.bubblelogger.BubbleDataHelper
7 | import com.hiking.bubblelogger.viewholder.LogViewHolder
8 |
9 | internal class BubbleListAdapter : RecyclerView.Adapter() {
10 |
11 | companion object {
12 | const val TYPE_LOG = 0
13 | }
14 |
15 | sealed class Item {
16 |
17 | data class Log(
18 | val log: BubbleDataHelper.Log
19 | ) : Item() {
20 | var filterStrings: List? = null
21 | }
22 | }
23 |
24 | var items: List- ? = null
25 | set(value) {
26 | field = value
27 | updateDisplayItems()
28 | }
29 |
30 | var displayItems: List
- ? = null
31 | private set(newItems) {
32 | val oldItems = field
33 | field = newItems
34 | DiffUtil.calculateDiff(object : DiffUtil.Callback() {
35 |
36 | override fun getOldListSize() = oldItems?.size ?: 0
37 |
38 | override fun getNewListSize() = newItems?.size ?: 0
39 |
40 | override fun areItemsTheSame(
41 | oldItemPosition: Int,
42 | newItemPosition: Int
43 | ): Boolean {
44 | val oldItem = oldItems!![oldItemPosition]
45 | val newItem = newItems!![newItemPosition]
46 | if (oldItem::class != newItem::class) return false
47 | return when (newItem) {
48 | is Item.Log -> newItem.log.id == (oldItem as Item.Log).log.id
49 | }
50 | }
51 |
52 | override fun areContentsTheSame(
53 | oldItemPosition: Int,
54 | newItemPosition: Int
55 | ): Boolean {
56 | val oldItem = oldItems!![oldItemPosition]
57 | return when (val newItem = newItems!![newItemPosition]) {
58 | is Item.Log -> {
59 | oldItem as Item.Log
60 | newItem.filterStrings == filterStrings &&
61 | newItem.log.title == oldItem.log.title &&
62 | newItem.log.message == oldItem.log.message &&
63 | newItem.log.timestamp == oldItem.log.timestamp
64 | }
65 | }
66 | }
67 | }).dispatchUpdatesTo(this)
68 | }
69 | var filterStrings: List = emptyList()
70 | set(value) {
71 | field = value
72 | updateDisplayItems()
73 | }
74 |
75 | private fun updateDisplayItems() {
76 | val filterText = filterStrings
77 | displayItems = if (filterText.isEmpty()) items
78 | else {
79 | val regex = filterStrings.joinToString(
80 | separator = "",
81 | prefix = ".*",
82 | postfix = ".*"
83 | ) {
84 | "(?=.*$it)"
85 | }.toRegex()
86 | items?.filter {
87 | when (it) {
88 | is Item.Log -> {
89 | val log = it.log
90 | "${log.title?.toString()?.plus(" ") ?: ""}${log.message}".matches(regex)
91 | }
92 | }
93 | }
94 | }
95 | }
96 |
97 | override fun getItemCount() = displayItems?.size ?: 0
98 |
99 | override fun getItemViewType(position: Int) = when (displayItems!![position]) {
100 | is Item.Log -> TYPE_LOG
101 | }
102 |
103 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = when (viewType) {
104 | TYPE_LOG -> LogViewHolder.create(parent)
105 | else -> throw IllegalStateException("Unknown view holder for type $viewType.")
106 | }
107 |
108 | override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
109 | when (val item = displayItems!![position]) {
110 | is Item.Log -> {
111 | (holder as LogViewHolder).bind(
112 | title = item.log.title,
113 | content = item.log.message,
114 | timestamp = item.log.timestamp,
115 | filterStrings = filterStrings
116 | )
117 | item.filterStrings = filterStrings
118 | }
119 | }
120 | }
121 | }
--------------------------------------------------------------------------------
/example/src/main/java/com/hiking/bubblelogger/example/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.hiking.bubblelogger.example
2 |
3 | import android.app.NotificationChannel
4 | import android.app.NotificationManager
5 | import android.os.Build
6 | import android.os.Bundle
7 | import android.view.inputmethod.EditorInfo
8 | import androidx.activity.viewModels
9 | import androidx.annotation.RequiresApi
10 | import androidx.appcompat.app.AppCompatActivity
11 | import androidx.core.app.NotificationManagerCompat
12 | import androidx.core.graphics.Insets
13 | import androidx.core.view.ViewCompat
14 | import androidx.core.view.WindowInsetsCompat
15 | import androidx.core.view.updatePadding
16 | import com.hiking.bubblelogger.BubbleLogger
17 | import com.hiking.bubblelogger.example.extension.applyEdgeToEdge
18 | import com.hiking.bubblelogger.example.extension.dpToPxSize
19 | import kotlinx.android.synthetic.main.activity_main.*
20 |
21 | /**
22 | * Homepage of the example app.
23 | */
24 | class MainActivity : AppCompatActivity() {
25 |
26 | companion object {
27 | const val CHANNEL_ID_BUBBLE_LOGGER = "CHANNEL_ID_BUBBLE_LOGGER"
28 | const val NOTIFICATION_ID = 8000
29 | }
30 |
31 | private val viewModel: MainViewModel by viewModels()
32 |
33 | override fun onCreate(savedInstanceState: Bundle?) {
34 | super.onCreate(savedInstanceState)
35 | setContentView(R.layout.activity_main)
36 | setupWindow()
37 | setupViews()
38 | setupViewModel()
39 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
40 | createNotificationChannel()
41 | }
42 | }
43 |
44 | override fun onDestroy() {
45 | viewModel.demoLogListener = null
46 | super.onDestroy()
47 | }
48 |
49 | private fun setupWindow() {
50 | applyEdgeToEdge()
51 | ViewCompat.setOnApplyWindowInsetsListener(rootLayout) { v, insets ->
52 | rootLayout.updatePadding(
53 | left = insets.systemWindowInsetLeft,
54 | right = insets.systemWindowInsetRight
55 | )
56 | contentLayout.updatePadding(
57 | bottom = insets.systemWindowInsetBottom + 16f.dpToPxSize(v.context)
58 | )
59 | WindowInsetsCompat.Builder(insets)
60 | .setSystemWindowInsets(Insets.of(0, insets.systemWindowInsetTop, 0, 0))
61 | .build()
62 | }
63 | }
64 |
65 | private fun setupViews() {
66 | demoSwitch.setOnCheckedChangeListener { v, isChecked ->
67 | viewModel.updateDemoMode(v.context, isChecked)
68 | }
69 | sendButton.setOnClickListener { logMessageFromEditTexts() }
70 | messageEditText.setOnEditorActionListener { _, actionId, _ ->
71 | when (actionId) {
72 | EditorInfo.IME_ACTION_SEND -> {
73 | logMessageFromEditTexts()
74 | true
75 | }
76 | else -> false
77 | }
78 | }
79 | }
80 |
81 | private fun setupViewModel() {
82 | viewModel.demoLogListener = { title, message -> logMessage(title, message) }
83 | }
84 |
85 | @RequiresApi(Build.VERSION_CODES.Q)
86 | private fun createNotificationChannel() {
87 | NotificationManagerCompat.from(this).createNotificationChannel(
88 | NotificationChannel(
89 | CHANNEL_ID_BUBBLE_LOGGER,
90 | getString(R.string.notification_channel_name),
91 | NotificationManager.IMPORTANCE_HIGH
92 | ).apply {
93 | setAllowBubbles(true)
94 | setSound(null, null)
95 | enableLights(false)
96 | enableVibration(false)
97 | description = getString(R.string.notification_channel_description)
98 | }
99 | )
100 | }
101 |
102 | private fun logMessageFromEditTexts() {
103 | val title = titleEditText.text?.toString()
104 | val message = messageEditText.text?.toString() ?: return
105 | logMessage(title, message)
106 | }
107 |
108 | private fun logMessage(title: CharSequence?, message: CharSequence) {
109 | if (customizedStyleSwitch.isChecked) {
110 | BubbleLogger.log(
111 | context = this,
112 | title = title,
113 | message = message,
114 | notificationId = NOTIFICATION_ID,
115 | notificationChannelId = CHANNEL_ID_BUBBLE_LOGGER,
116 | desiredHeight = 360,
117 | adaptiveBubbleIconResource = R.drawable.ic_bubble_adaptive_customized,
118 | legacyBubbleIconResource = R.drawable.ic_bubble_legacy_customized,
119 | notificationIconResource = R.drawable.ic_notification_customized
120 | )
121 | } else {
122 | BubbleLogger.log(
123 | context = this,
124 | title = title,
125 | message = message,
126 | notificationId = NOTIFICATION_ID,
127 | notificationChannelId = CHANNEL_ID_BUBBLE_LOGGER
128 | )
129 | }
130 | }
131 | }
132 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/lib/src/main/java/com/hiking/bubblelogger/screen/BubbleActivity.kt:
--------------------------------------------------------------------------------
1 | package com.hiking.bubblelogger.screen
2 |
3 | import android.os.Bundle
4 | import android.view.MotionEvent
5 | import android.view.View
6 | import androidx.activity.viewModels
7 | import androidx.appcompat.app.AppCompatActivity
8 | import androidx.appcompat.widget.TooltipCompat
9 | import androidx.core.graphics.Insets
10 | import androidx.core.view.ViewCompat
11 | import androidx.core.view.WindowInsetsCompat
12 | import androidx.core.view.updatePadding
13 | import androidx.core.widget.doOnTextChanged
14 | import androidx.lifecycle.Observer
15 | import androidx.recyclerview.widget.DividerItemDecoration
16 | import androidx.recyclerview.widget.LinearLayoutManager
17 | import androidx.recyclerview.widget.RecyclerView
18 | import com.hiking.bubblelogger.BubbleDataHelper
19 | import com.hiking.bubblelogger.R
20 | import com.hiking.bubblelogger.extension.applyEdgeToEdge
21 | import com.hiking.bubblelogger.extension.clearFocusAndHideIme
22 | import kotlinx.android.synthetic.main.activity_bubble.*
23 |
24 | /**
25 | * [AppCompatActivity] for bubble content.
26 | */
27 | class BubbleActivity : AppCompatActivity() {
28 |
29 | private val viewModel: BubbleViewModel by viewModels()
30 | private val adapter = BubbleListAdapter()
31 | private val layoutManager = LinearLayoutManager(this).apply {
32 | reverseLayout = true
33 | stackFromEnd = true
34 | }
35 | private var isScrollingManually = false
36 |
37 | override fun onCreate(savedInstanceState: Bundle?) {
38 | super.onCreate(savedInstanceState)
39 | setContentView(R.layout.activity_bubble)
40 | setupWindow()
41 | setupViews()
42 | setupViewModel()
43 | }
44 |
45 | private fun setupWindow() {
46 | applyEdgeToEdge()
47 | ViewCompat.setOnApplyWindowInsetsListener(rootLayout) { v, insets ->
48 | rootLayout.updatePadding(
49 | left = insets.systemWindowInsetLeft,
50 | right = insets.systemWindowInsetRight
51 | )
52 | recyclerView.updatePadding(
53 | bottom = insets.systemWindowInsetBottom
54 | )
55 | WindowInsetsCompat.Builder(insets)
56 | .setSystemWindowInsets(Insets.of(0, insets.systemWindowInsetTop, 0, 0))
57 | .build()
58 | }
59 | }
60 |
61 | private fun setupViews() {
62 | setupFilterViews()
63 | setupRecyclerView()
64 | }
65 |
66 | private fun setupRecyclerView() {
67 | recyclerView.apply {
68 | adapter = this@BubbleActivity.adapter
69 | layoutManager = this@BubbleActivity.layoutManager
70 | addItemDecoration(DividerItemDecoration(context, DividerItemDecoration.VERTICAL))
71 | addOnScrollListener(object : RecyclerView.OnScrollListener() {
72 | override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
73 | updateScrollToTopButton()
74 | }
75 | })
76 | }
77 | setupRecyclerViewTouchListener()
78 | setupScrollControls()
79 | }
80 |
81 | private fun setupRecyclerViewTouchListener() {
82 | recyclerView.setOnTouchListener { v, event ->
83 | when (event.action) {
84 | MotionEvent.ACTION_DOWN -> {
85 | isScrollingManually = true
86 | filterEditText.clearFocusAndHideIme()
87 | v.isPressed = true
88 | }
89 | MotionEvent.ACTION_UP -> {
90 | isScrollingManually = false
91 | v.performClick()
92 | v.isPressed = false
93 | }
94 | }
95 | false
96 | }
97 | }
98 |
99 | private fun setupScrollControls() {
100 | scrollToTopButton.apply {
101 | TooltipCompat.setTooltipText(this, contentDescription)
102 | setOnClickListener {
103 | it.visibility = View.GONE
104 | scrollToTop()
105 | }
106 | }
107 | }
108 |
109 | private fun setupFilterViews() {
110 | filterEditText.doOnTextChanged { text, _, _, _ ->
111 | adapter.filterStrings = text.toString().trim().split("\\s".toRegex())
112 | updateEmptyState()
113 | resetFilterButton.visibility = if (text.isNullOrEmpty()) View.GONE else View.VISIBLE
114 | }
115 | resetFilterButton.apply {
116 | TooltipCompat.setTooltipText(this, contentDescription)
117 | setOnClickListener {
118 | filterEditText.text.clear()
119 | }
120 | }
121 | clearButton.apply {
122 | TooltipCompat.setTooltipText(this, contentDescription)
123 | setOnClickListener {
124 | BubbleDataHelper.clearLogs()
125 | }
126 | }
127 | }
128 |
129 | private fun setupViewModel() {
130 | viewModel.logs.observe(this, Observer {
131 | updateList()
132 | })
133 | }
134 |
135 | private fun updateList() {
136 | adapter.items = buildListItems()
137 | updateEmptyState()
138 | recyclerView.post { updateScrollToTopButton() }
139 | }
140 |
141 | private fun updateEmptyState() {
142 | nothingTextView.apply {
143 | visibility = if (adapter.displayItems.isNullOrEmpty()) View.VISIBLE else View.GONE
144 | setText(
145 | if (adapter.filterStrings.isEmpty()) R.string.log_empty_message
146 | else R.string.log_empty_filtered_message
147 | )
148 | }
149 | }
150 |
151 | private fun updateScrollToTopButton() {
152 | val couldScrollUp = scrollToTopButton.visibility == View.VISIBLE
153 | val canScrollUp = recyclerView.canScrollVertically(-1)
154 | if (!isScrollingManually && !couldScrollUp && canScrollUp) {
155 | scrollToTop()
156 | } else {
157 | scrollToTopButton.visibility = if (canScrollUp) View.VISIBLE else View.GONE
158 | }
159 | }
160 |
161 | private fun scrollToTop() {
162 | val lastItemPosition = layoutManager.itemCount - 1
163 | val lastVisibleItemPosition = layoutManager.findLastVisibleItemPosition()
164 | recyclerView.apply {
165 | if (lastItemPosition - lastVisibleItemPosition > 10) {
166 | // Too far away. It may takes forever to scroll smoothly.
167 | scrollToPosition(lastItemPosition)
168 | } else {
169 | smoothScrollToPosition(lastItemPosition)
170 | }
171 | }
172 | }
173 |
174 | private fun buildListItems() = viewModel.logs.value?.map {
175 | BubbleListAdapter.Item.Log(log = it)
176 | }
177 | }
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
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 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 | xmlns:android
159 |
160 | ^$
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 | xmlns:.*
170 |
171 | ^$
172 |
173 |
174 | BY_NAME
175 |
176 |
177 |
178 |
179 |
180 |
181 | .*:id
182 |
183 | http://schemas.android.com/apk/res/android
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 | .*:name
193 |
194 | http://schemas.android.com/apk/res/android
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 | name
204 |
205 | ^$
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 | style
215 |
216 | ^$
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 | .*
226 |
227 | ^$
228 |
229 |
230 | BY_NAME
231 |
232 |
233 |
234 |
235 |
236 |
237 | .*
238 |
239 | http://schemas.android.com/apk/res/android
240 |
241 |
242 | ANDROID_ATTRIBUTE_ORDER
243 |
244 |
245 |
246 |
247 |
248 |
249 | .*
250 |
251 | .*
252 |
253 |
254 | BY_NAME
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 |
272 |
273 |
274 |
275 |
276 |
--------------------------------------------------------------------------------