├── .gitignore ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── jem │ │ └── blobbackgrounddemo │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── jem │ │ │ └── blobbackgrounddemo │ │ │ └── MainActivity.kt │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── jem │ └── blobbackgrounddemo │ └── ExampleUnitTest.kt ├── blobbackground ├── .gitignore ├── build.gradle └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── jem │ └── blobbackground │ ├── base │ └── BaseBlobLayout.kt │ ├── handler │ └── BlobLayoutHandler.kt │ ├── layout │ ├── BlobConstraintLayout.kt │ ├── BlobFrameLayout.kt │ └── BlobLinearLayout.kt │ ├── model │ └── Blob.kt │ └── util │ ├── PointUtil.kt │ └── RandomUtil.kt ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── screenrecording └── demo_app.gif └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.aar 4 | *.ap_ 5 | *.aab 6 | 7 | # Files for the ART/Dalvik VM 8 | *.dex 9 | 10 | # Java class files 11 | *.class 12 | 13 | # Generated files 14 | bin/ 15 | gen/ 16 | out/ 17 | # Uncomment the following line in case you need and you don't have the release build type files in your app 18 | # release/ 19 | 20 | # Gradle files 21 | .gradle/ 22 | build/ 23 | 24 | # Local configuration file (sdk path, etc) 25 | local.properties 26 | 27 | # Proguard folder generated by Eclipse 28 | proguard/ 29 | 30 | # Log Files 31 | *.log 32 | 33 | # Android Studio Navigation editor temp files 34 | .navigation/ 35 | 36 | # Android Studio captures folder 37 | captures/ 38 | 39 | # IntelliJ 40 | *.iml 41 | .idea/workspace.xml 42 | .idea/tasks.xml 43 | .idea/gradle.xml 44 | .idea/assetWizardSettings.xml 45 | .idea/dictionaries 46 | .idea/libraries 47 | # Android Studio 3 in .gitignore file. 48 | .idea/caches 49 | .idea/modules.xml 50 | # Comment next line if keeping position of elements in Navigation Editor is relevant for you 51 | .idea/navEditor.xml 52 | 53 | # Keystore files 54 | # Uncomment the following lines if you do not want to check your keystore files in. 55 | #*.jks 56 | #*.keystore 57 | 58 | # External native build folder generated in Android Studio 2.2 and later 59 | .externalNativeBuild 60 | .cxx/ 61 | 62 | # Google Services (e.g. APIs or Firebase) 63 | # google-services.json 64 | 65 | # Freeline 66 | freeline.py 67 | freeline/ 68 | freeline_project_description.json 69 | 70 | # fastlane 71 | fastlane/report.xml 72 | fastlane/Preview.html 73 | fastlane/screenshots 74 | fastlane/test_output 75 | fastlane/readme.md 76 | 77 | # Version control 78 | vcs.xml 79 | 80 | # lint 81 | lint/intermediates/ 82 | lint/generated/ 83 | lint/outputs/ 84 | lint/tmp/ 85 | # lint/reports/ 86 | .idea/* 87 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Chrisvin Jem 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BlobBackgroundLayout 2 | Android Layout Library with animated Blob Background 3 | 4 | [![License: MIT](https://img.shields.io/badge/License-MIT-silver.svg)](https://opensource.org/licenses/MIT) [![](https://jitpack.io/v/Chrisvin/BlobBackgroundLayout.svg)](https://jitpack.io/#Chrisvin/BlobBackgroundLayout) [![API](https://img.shields.io/badge/API-21%2B-blue.svg?style=flat)](https://android-arsenal.com/api?level=21) 5 | 6 | 7 | 8 | ## Demo app 9 | To run the demo project, clone the repository and run it via Android Studio. 10 |
(OR) 11 |
Download the latest demo apk from [releases](https://github.com/Chrisvin/BlobBackgroundLayout/releases). 12 | 13 | ## Usage 14 | #### Set up the dependency 15 | 1. Add the JitPack repository to your root build.gradle at the end of repositories: 16 | ``` 17 | allprojects { 18 | repositories { 19 | ... 20 | maven { url 'https://jitpack.io' } 21 | } 22 | } 23 | ``` 24 | 2. Add the BlobBackgroundLayout dependency in the build.gradle: 25 | ``` 26 | implementation 'com.github.Chrisvin:BlobBackgroundLayout:1.1' 27 | ``` 28 | 29 | #### Use a `BlobLayout` as the base container in your activity/fragments. 30 | ``` 31 | 32 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | ``` 47 | 48 | #### Add blobs in the `BlobLayout` using `addBlob()` 49 | The individual blobs can be customized in `Blob.Configuration`. 50 | ``` 51 | blobLayout.addBlob( 52 | Blob.Configuration( 53 | // Position of the Blobs center point 54 | blobCenterPosition = newBlobCenterPosition, // Optional, Default = PointF(0f, 0f) 55 | 56 | // The number of curve points in the blob 57 | pointCount = newPointCount, // Optional, Default = 16 58 | 59 | // The radius of the blob 60 | radius = newRadius, // Optional, Default = 750f 61 | 62 | // The maximum offset from the radius of the blob 63 | maxOffset = newMaxOffset, // Optional, Default = 100f 64 | 65 | // Should the blob animate/change shape over time 66 | shouldAnimateShape = newShouldAnimateShape, // Optional, Default = true 67 | 68 | // Time taken for blob to fully change from one shape to another 69 | shapeAnimationDuration = newShapeAnimationDuration, // Optional, Default = 2000L 70 | 71 | // The interpolator used for shape animation 72 | shapeAnimationInterpolator = newShapeAnimationInterpolator, // Optional, Default = LinearInterpolator() 73 | 74 | // The paint used to draw the blob, can be used to set color, draw only outline, etc. 75 | paint = newPaint 76 | /* Optional, Default = Paint().apply { 77 | isAntiAlias = true 78 | style = Paint.Style.FILL 79 | color = Color.RED 80 | } 81 | */ 82 | ) 83 | ) 84 | ``` 85 | 86 | ### And you're done with your awesome blobby UI, easy-peasy. ^_^ 87 | 88 | ## Additional functionalities 89 | #### Get blob count 90 | ``` 91 | val blobCount: Int = blobLayout.getBlobCount() 92 | ``` 93 | #### Recreate all blobs with new shapes 94 | ``` 95 | blobLayout.recreateBlobs() 96 | ``` 97 | #### Recreate blob at index with new shape 98 | ``` 99 | blobLayout.recreateBlob(index) 100 | ``` 101 | #### Remove all blobs 102 | ``` 103 | blobLayout.removeBlobs() 104 | ``` 105 | #### Remove blob at index 106 | ``` 107 | blobLayout.removeBlob(index) 108 | ``` 109 | #### Get all blob configurations 110 | ``` 111 | val blobConfigs: Array = blobLayout.getBlobConfigurations() 112 | ``` 113 | #### Get configuration for blob at index 114 | ``` 115 | val blobConfig: Blob.Configuration = blobLayout.getBlobConfiguration(index) 116 | ``` 117 | #### Update all blob configurations 118 | ``` 119 | blobLayout.updateBlobConfigurations(blobConfigs) 120 | ``` 121 | #### Update configuration for blob at index 122 | ``` 123 | blobLayout.updateBlobConfiguration(blobConfig, index) 124 | ``` 125 | 126 | Note: Aforementioned functionalities are supported in all BlobLayouts (`BlobConstraintLayout`,`BlobFrameLayout`,`BlobLinearLayout`) 127 | 128 | ## Bugs and Feedback 129 | For bugs, questions and discussions please use the [Github Issues](https://github.com/Chrisvin/BlobBackgroundLayout/issues). 130 | 131 | ## License 132 | ``` 133 | MIT License 134 | 135 | Copyright (c) 2019 Jem 136 | 137 | Permission is hereby granted, free of charge, to any person obtaining a copy 138 | of this software and associated documentation files (the "Software"), to deal 139 | in the Software without restriction, including without limitation the rights 140 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 141 | copies of the Software, and to permit persons to whom the Software is 142 | furnished to do so, subject to the following conditions: 143 | 144 | The above copyright notice and this permission notice shall be included in all 145 | copies or substantial portions of the Software. 146 | 147 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 148 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 149 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 150 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 151 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 152 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 153 | SOFTWARE. 154 | ``` 155 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-android-extensions' 4 | 5 | android { 6 | compileSdkVersion 29 7 | 8 | defaultConfig { 9 | applicationId "com.jem.blobbackgrounddemo" 10 | minSdkVersion 21 11 | targetSdkVersion 29 12 | versionCode 1 13 | versionName "1.0" 14 | 15 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 16 | } 17 | 18 | buildTypes { 19 | release { 20 | minifyEnabled false 21 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 22 | } 23 | } 24 | } 25 | 26 | dependencies { 27 | implementation fileTree(dir: "libs", include: ["*.jar"]) 28 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 29 | implementation 'androidx.core:core-ktx:1.1.0' 30 | implementation 'androidx.appcompat:appcompat:1.1.0' 31 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3' 32 | testImplementation 'junit:junit:4.12' 33 | androidTestImplementation 'androidx.test.ext:junit:1.1.1' 34 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' 35 | 36 | implementation project(':blobbackground') 37 | // implementation 'com.github.Chrisvin:BlobBackgroundLayout:1.1' 38 | 39 | implementation "androidx.cardview:cardview:1.0.0" 40 | } -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /app/src/androidTest/java/com/jem/blobbackgrounddemo/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.jem.blobbackgrounddemo 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("com.jem.blobbackgrounddemo", appContext.packageName) 23 | } 24 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/jem/blobbackgrounddemo/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.jem.blobbackgrounddemo 2 | 3 | import android.graphics.Color 4 | import android.graphics.Paint 5 | import android.graphics.PointF 6 | import androidx.appcompat.app.AppCompatActivity 7 | import android.os.Bundle 8 | import com.jem.blobbackground.model.Blob 9 | import kotlinx.android.synthetic.main.activity_main.* 10 | import kotlin.math.min 11 | 12 | class MainActivity : AppCompatActivity() { 13 | 14 | override fun onCreate(savedInstanceState: Bundle?) { 15 | super.onCreate(savedInstanceState) 16 | setContentView(R.layout.activity_main) 17 | 18 | blobLayout.viewTreeObserver.addOnGlobalLayoutListener { 19 | val layoutWidth = blobLayout.width.toFloat() 20 | val layoutHeight = blobLayout.height.toFloat() 21 | val minVal = min(layoutWidth, layoutHeight) 22 | blobLayout.removeBlobs() 23 | blobLayout.addBlob( 24 | Blob.Configuration( 25 | pointCount = 32, 26 | blobCenterPosition = PointF(0f, 0f), 27 | radius = minVal - minVal / 4, 28 | maxOffset = (minVal - minVal / 4) / 12, 29 | paint = getPaint(Color.parseColor("#710627")) 30 | ), 31 | Blob.Configuration( 32 | pointCount = 12, 33 | blobCenterPosition = PointF( 34 | layoutWidth, 35 | if (layoutWidth < layoutHeight) layoutHeight / 4 else 0f 36 | ), 37 | radius = minVal / 4, 38 | maxOffset = (minVal / 4) / 8, 39 | shapeAnimationDuration = 1500, 40 | paint = getPaint(Color.parseColor("#0F7173")) 41 | ), 42 | Blob.Configuration( 43 | pointCount = 24, 44 | blobCenterPosition = PointF((layoutWidth * 2) / 3, layoutHeight), 45 | radius = minVal - minVal / 8, 46 | maxOffset = (minVal - minVal / 8) / 8, 47 | paint = getPaint(Color.parseColor("#907AD6")) 48 | ) 49 | ) 50 | } 51 | 52 | animateBlobSwitch.setOnCheckedChangeListener { _, isChecked -> 53 | val blobConfigs = blobLayout.getBlobConfigurations() 54 | for (i in blobConfigs.indices) { 55 | blobConfigs[i].shouldAnimateShape = isChecked 56 | } 57 | blobLayout.updateBlobConfigurations(blobConfigs) 58 | } 59 | 60 | recreateBlobButton.setOnClickListener { 61 | blobLayout.recreateBlobs() 62 | } 63 | } 64 | 65 | private fun getPaint(paintColor: Int): Paint { 66 | return Paint().apply { 67 | isAntiAlias = true 68 | style = Paint.Style.FILL 69 | color = paintColor 70 | } 71 | } 72 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 17 | 18 | 22 | 23 | 40 | 41 | 57 | 58 |