├── 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 | 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 | 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 | 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 | [![Build Status](https://travis-ci.org/hiking93/android-bubble-logger.svg?branch=master)](https://travis-ci.org/hiking93/android-bubble-logger) 4 | [![JitPack](https://jitpack.io/v/hiking93/android-bubble-logger.svg)](https://jitpack.io/#hiking93/android-bubble-logger) 5 | [![Codacy Badge](https://app.codacy.com/project/badge/Grade/c81779120b3f4bf295722b27886493d1)](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 | [![Maintainability](https://api.codeclimate.com/v1/badges/d4af1e818beda48e37d1/maintainability)](https://codeclimate.com/github/hiking93/android-bubble-logger/maintainability) 7 | 8 | A tool to display logs within a floating bubble. 9 | 10 | ![Hero image](https://user-images.githubusercontent.com/3449834/85727654-caab7d80-b729-11ea-9b80-42b5d829279f.png) 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 | ![Sample](https://user-images.githubusercontent.com/3449834/85727699-d139f500-b729-11ea-8150-2c4041569e0c.png) 28 | ![Filter](https://user-images.githubusercontent.com/3449834/85727691-d008c800-b729-11ea-900b-06d41d6c1287.png) 29 | ![Customized](https://user-images.githubusercontent.com/3449834/85727685-ced79b00-b729-11ea-8d45-0e6d8b59a615.png) 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 |