├── .gitattributes ├── .gitignore ├── .idea ├── codeStyles │ └── Project.xml ├── inspectionProfiles │ └── Project_Default.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── br │ │ └── vince │ │ └── owlsheetexample │ │ └── MainActivity.java │ └── res │ ├── drawable-v24 │ └── ic_launcher_foreground.xml │ ├── drawable │ ├── fake.png │ ├── ic_format_list_bulleted_black_24dp.xml │ ├── ic_keyboard_arrow_down_black_24dp.xml │ ├── ic_launcher_background.xml │ ├── image_one.jpg │ └── item_image.jpg │ ├── layout │ ├── activity_main.xml │ ├── layout_bottom_sheet_example.xml │ └── layout_bottom_sheet_item.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 ├── build.gradle ├── demo_app.mp4 ├── ezgif.com-crop.gif ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── owlbottomsheet ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── br │ │ └── vince │ │ └── owlbottomsheet │ │ ├── AnimationBuilder.java │ │ ├── OnClickInterceptor.java │ │ ├── OwlBottomSheet.java │ │ └── OwlBottomSheetBase.java │ └── res │ ├── layout │ └── owl_bottom_sheet.xml │ └── values │ └── strings.xml └── settings.gradle /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | # Android Studio captures folder 33 | captures/ 34 | 35 | # IntelliJ 36 | *.iml 37 | .idea/workspace.xml 38 | .idea/tasks.xml 39 | .idea/gradle.xml 40 | .idea/assetWizardSettings.xml 41 | .idea/dictionaries 42 | .idea/libraries 43 | .idea/caches 44 | 45 | # Keystore files 46 | # Uncomment the following line if you do not want to check your keystore files in. 47 | #*.jks 48 | 49 | # External native build folder generated in Android Studio 2.2 and later 50 | .externalNativeBuild 51 | 52 | # Google Services (e.g. APIs or Firebase) 53 | google-services.json 54 | 55 | # Freeline 56 | freeline.py 57 | freeline/ 58 | freeline_project_description.json 59 | 60 | # fastlane 61 | fastlane/report.xml 62 | fastlane/Preview.html 63 | fastlane/screenshots 64 | fastlane/test_output 65 | fastlane/readme.md 66 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 15 | 16 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 119 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 27 | 28 | 29 | 30 | 31 | 32 | 34 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Guilherme Henrique 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 | # OwlBottomSheet 2 | 3 | [![](https://jitpack.io/v/Guilherme-HRamos/OwlBottomSheet.svg)](https://jitpack.io/#Guilherme-HRamos/OwlBottomSheet) 4 | 5 | 6 | 7 | ## Adding the project 8 | 9 | Add it in your root build.gradle at the end of repositories: 10 | ``` 11 | allprojects { 12 | repositories { 13 | ... 14 | maven { url 'https://jitpack.io' } 15 | } 16 | } 17 | ``` 18 | Add the dependency: 19 | ``` 20 | dependencies { 21 | implementation 'com.github.Guilherme-HRamos:OwlBottomSheet:1.01' 22 | } 23 | ``` 24 | 25 | ## Usage 26 | 27 | In your Activity layout: 28 | 29 | ```xlm 30 | 31 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 48 | 49 | 50 | 51 | ``` 52 | 53 | In your Activity: 54 | 55 | ```java 56 | public class MainActivity extends AppCompatActivity { 57 | 58 | // the bottom sheet 59 | private OwlBottomSheet mBottomSheet; 60 | 61 | @Override 62 | protected void onCreate(Bundle savedInstanceState) { 63 | super.onCreate(savedInstanceState); 64 | setContentView(R.layout.activity_main); 65 | 66 | mBottomSheet = findViewById(R.id.owl_bottom_sheet); 67 | 68 | setupView(); 69 | } 70 | 71 | // basic usage 72 | private void setupView() { 73 | 74 | //used to calculate some animations. it's required 75 | mBottomSheet.setActivityView(this); 76 | 77 | //icon to show in collapsed sheet 78 | mBottomSheet.setIcon(R.drawable.ic_keyboard_arrow_down_black_24dp); 79 | 80 | //bottom sheet color 81 | mBottomSheet.setBottomSheetColor(ContextCompat.getColor(this,R.color.colorPrimaryDark)); 82 | 83 | //view shown in bottom sheet 84 | mBottomSheet.attachContentView(R.layout.layout_bottom_sheet_example); 85 | 86 | //getting close button from view shown 87 | mBottomSheet.getContentView().findViewById(R.id.comments_sheet_close_button) 88 | .setOnClickListener(v -> mBottomSheet.collapse()); 89 | } 90 | 91 | 92 | // collapse bottom sheet when back button pressed 93 | @Override 94 | public void onBackPressed() { 95 | if (!mBottomSheet.isExpanded()) 96 | super.onBackPressed(); 97 | else 98 | mBottomSheet.collapse(); 99 | } 100 | } 101 | 102 | ``` 103 | 104 | ## Methods: 105 | 106 | ```java 107 | 108 | /** 109 | * Set icon to show in collapsed sheet 110 | * @param drawable ex R.drawable.collapse_icon 111 | */ 112 | public void setIcon(@DrawableRes int drawable); 113 | 114 | /** 115 | * Color of bottom sheet 116 | * @param color ex: ContextCompat.getColor(getContext(), R.color.colorAccent); 117 | */ 118 | public void setBottomSheetColor(@ColorInt int color); 119 | 120 | /** 121 | * This will make OwlBottomSheet calculate animation from that Activity (required) 122 | */ 123 | public void setActivityView(AppCompatActivity activity); 124 | 125 | /** 126 | * Click listener interceptor from collapse and expand click 127 | */ 128 | public void setOnClickInterceptor(OnClickInterceptor interceptor); 129 | 130 | /** 131 | * Get animation duration 132 | */ 133 | public int getDuration(); 134 | 135 | /** 136 | * Set animation duration. For better results, it's recommended 250~350 137 | */ 138 | public void setDuration(int duration); 139 | 140 | /** 141 | * Get on click interceptor listener 142 | */ 143 | public OnClickInterceptor getOnClickInterceptor(); 144 | 145 | /** 146 | * Collapse bottom sheet 147 | */ 148 | public void collapse(); 149 | 150 | /** 151 | * Expand bottom sheet 152 | */ 153 | public void expand(); 154 | 155 | /** 156 | * Get bottom sheet state 157 | * @return 158 | */ 159 | public boolean isExpanded(); 160 | 161 | /** 162 | * Get view shown 163 | * @return 164 | */ 165 | public View getContentView(); 166 | 167 | /** 168 | * Attach view to show in bottom sheet 169 | * @param view to be added to bottom sheet 170 | */ 171 | public void attachContentView(View view); 172 | 173 | /** 174 | * Attach view to show in bottom sheet 175 | * @param view layout to be inflated on bottom sheet 176 | */ 177 | public void attachContentView(@LayoutRes int view); 178 | 179 | ``` 180 | 181 | ## Finally 182 | 183 | This is a very simple library for usage. There is not a lot customizations yet. I did this because I needed for personal usage, and I decided to share that. 184 | Feel free to contribute ;) 185 | 186 | ## License 187 | 188 | ``` 189 | MIT License 190 | 191 | Copyright (c) 2018 Guilherme Ramos 192 | 193 | Permission is hereby granted, free of charge, to any person obtaining a copy 194 | of this software and associated documentation files (the "Software"), to deal 195 | in the Software without restriction, including without limitation the rights 196 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 197 | copies of the Software, and to permit persons to whom the Software is 198 | furnished to do so, subject to the following conditions: 199 | 200 | The above copyright notice and this permission notice shall be included in all 201 | copies or substantial portions of the Software. 202 | 203 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 204 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 205 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 206 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 207 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 208 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 209 | SOFTWARE. 210 | ``` 211 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 28 5 | defaultConfig { 6 | applicationId "br.vince.owlsheetexample" 7 | minSdkVersion 16 8 | targetSdkVersion 28 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | vectorDrawables.useSupportLibrary = true 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | compileOptions { 21 | sourceCompatibility JavaVersion.VERSION_1_8 22 | targetCompatibility JavaVersion.VERSION_1_8 23 | } 24 | } 25 | 26 | dependencies { 27 | implementation fileTree(include: ['*.jar'], dir: 'libs') 28 | implementation 'com.android.support:appcompat-v7:28.0.0-rc01' 29 | implementation 'com.android.support.constraint:constraint-layout:1.1.2' 30 | testImplementation 'junit:junit:4.12' 31 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 32 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 33 | implementation 'com.android.support:design:28.0.0-rc01' 34 | implementation project(':owlbottomsheet') 35 | } 36 | -------------------------------------------------------------------------------- /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 22 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/br/vince/owlsheetexample/MainActivity.java: -------------------------------------------------------------------------------- 1 | package br.vince.owlsheetexample; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.content.ContextCompat; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.view.View; 7 | 8 | import br.vince.owlbottomsheet.OwlBottomSheet; 9 | 10 | public class MainActivity extends AppCompatActivity { 11 | 12 | private OwlBottomSheet mBottomSheet; 13 | 14 | @Override 15 | protected void onCreate(Bundle savedInstanceState) { 16 | super.onCreate(savedInstanceState); 17 | setContentView(R.layout.activity_main); 18 | mBottomSheet = findViewById(R.id.owl_bottom_sheet); 19 | 20 | setupView(); 21 | } 22 | 23 | private void setupView() { 24 | //used to calculate some animations 25 | mBottomSheet.setActivityView(this); 26 | //icon to show in collapsed sheet 27 | mBottomSheet.setIcon(R.drawable.ic_keyboard_arrow_down_black_24dp); 28 | 29 | mBottomSheet.setBottomSheetColor(ContextCompat.getColor(this,R.color.colorPrimaryDark)); 30 | 31 | //view will show in bottom sheet 32 | mBottomSheet.attachContentView(R.layout.layout_bottom_sheet_example); 33 | 34 | //getting close button from view shown 35 | mBottomSheet.getContentView().findViewById(R.id.comments_sheet_close_button) 36 | .setOnClickListener(v -> mBottomSheet.collapse()); 37 | } 38 | 39 | 40 | // collapse bottom sheet when back button pressed 41 | @Override 42 | public void onBackPressed() { 43 | if (!mBottomSheet.isExpanded()) 44 | super.onBackPressed(); 45 | else 46 | mBottomSheet.collapse(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/fake.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guilherme-HRamos/OwlBottomSheet/e0a506663ef184f22175b642b7b34bebcd5c2bf4/app/src/main/res/drawable/fake.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_format_list_bulleted_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_keyboard_arrow_down_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 11 | 16 | 21 | 26 | 31 | 36 | 41 | 46 | 51 | 56 | 61 | 66 | 71 | 76 | 81 | 86 | 91 | 96 | 101 | 106 | 111 | 116 | 121 | 126 | 131 | 136 | 141 | 146 | 151 | 156 | 161 | 166 | 171 | 172 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/image_one.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guilherme-HRamos/OwlBottomSheet/e0a506663ef184f22175b642b7b34bebcd5c2bf4/app/src/main/res/drawable/image_one.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/item_image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guilherme-HRamos/OwlBottomSheet/e0a506663ef184f22175b642b7b34bebcd5c2bf4/app/src/main/res/drawable/item_image.jpg -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 15 | 16 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_bottom_sheet_example.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 14 | 15 | 23 | 24 | 25 | 43 | 44 | 45 | 50 | 51 | 54 | 55 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_bottom_sheet_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 14 | 15 | 20 | 21 | 31 | 32 | 43 | 44 | 45 | 46 | 47 | 48 | 59 | 60 | 67 | 68 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guilherme-HRamos/OwlBottomSheet/e0a506663ef184f22175b642b7b34bebcd5c2bf4/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guilherme-HRamos/OwlBottomSheet/e0a506663ef184f22175b642b7b34bebcd5c2bf4/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guilherme-HRamos/OwlBottomSheet/e0a506663ef184f22175b642b7b34bebcd5c2bf4/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guilherme-HRamos/OwlBottomSheet/e0a506663ef184f22175b642b7b34bebcd5c2bf4/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guilherme-HRamos/OwlBottomSheet/e0a506663ef184f22175b642b7b34bebcd5c2bf4/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guilherme-HRamos/OwlBottomSheet/e0a506663ef184f22175b642b7b34bebcd5c2bf4/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guilherme-HRamos/OwlBottomSheet/e0a506663ef184f22175b642b7b34bebcd5c2bf4/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guilherme-HRamos/OwlBottomSheet/e0a506663ef184f22175b642b7b34bebcd5c2bf4/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guilherme-HRamos/OwlBottomSheet/e0a506663ef184f22175b642b7b34bebcd5c2bf4/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guilherme-HRamos/OwlBottomSheet/e0a506663ef184f22175b642b7b34bebcd5c2bf4/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #0336ff 4 | #0336ff 5 | #FF0266 6 | #FFFFFF 7 | #000000 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | OwlSheetExample 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | 5 | repositories { 6 | google() 7 | jcenter() 8 | } 9 | dependencies { 10 | classpath 'com.android.tools.build:gradle:3.1.4' 11 | 12 | 13 | // NOTE: Do not place your application dependencies here; they belong 14 | // in the individual module build.gradle files 15 | } 16 | } 17 | 18 | allprojects { 19 | repositories { 20 | google() 21 | jcenter() 22 | } 23 | } 24 | 25 | task clean(type: Delete) { 26 | delete rootProject.buildDir 27 | } 28 | -------------------------------------------------------------------------------- /demo_app.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guilherme-HRamos/OwlBottomSheet/e0a506663ef184f22175b642b7b34bebcd5c2bf4/demo_app.mp4 -------------------------------------------------------------------------------- /ezgif.com-crop.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guilherme-HRamos/OwlBottomSheet/e0a506663ef184f22175b642b7b34bebcd5c2bf4/ezgif.com-crop.gif -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Guilherme-HRamos/OwlBottomSheet/e0a506663ef184f22175b642b7b34bebcd5c2bf4/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sun Aug 26 04:11:11 BRT 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip 7 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /owlbottomsheet/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 28 5 | 6 | defaultConfig { 7 | minSdkVersion 16 8 | targetSdkVersion 28 9 | versionCode 1 10 | versionName "1.0" 11 | vectorDrawables.useSupportLibrary = true 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | compileOptions { 20 | sourceCompatibility JavaVersion.VERSION_1_8 21 | targetCompatibility JavaVersion.VERSION_1_8 22 | } 23 | 24 | } 25 | 26 | dependencies { 27 | implementation fileTree(dir: 'libs', include: ['*.jar']) 28 | 29 | implementation 'com.android.support:appcompat-v7:28.0.0-rc01' 30 | implementation 'com.android.support:design:28.0.0-rc01' 31 | } 32 | -------------------------------------------------------------------------------- /owlbottomsheet/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /owlbottomsheet/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /owlbottomsheet/src/main/java/br/vince/owlbottomsheet/AnimationBuilder.java: -------------------------------------------------------------------------------- 1 | package br.vince.owlbottomsheet; 2 | 3 | import android.support.design.card.MaterialCardView; 4 | 5 | /** 6 | * Classe criada por Guilherme Ramos em Agosto 2018 7 | * Contato: +55 (11) 974049050 8 | */ 9 | public class AnimationBuilder { 10 | 11 | private float toHeight; 12 | private float toWidth; 13 | private float fromHeight; 14 | private float fromWidth; 15 | private float fromX; 16 | private float fromY; 17 | private float toX; 18 | private float toY; 19 | private float fromRadius; 20 | private float toRadius; 21 | private MaterialCardView cardView; 22 | 23 | public float getToHeight() { 24 | return toHeight; 25 | } 26 | 27 | public void setToHeight(final float toHeight) { 28 | this.toHeight = toHeight; 29 | } 30 | 31 | public float getToWidth() { 32 | return toWidth; 33 | } 34 | 35 | public void setToWidth(final float toWidth) { 36 | this.toWidth = toWidth; 37 | } 38 | 39 | public float getFromHeight() { 40 | return fromHeight; 41 | } 42 | 43 | public void setFromHeight(final float fromHeight) { 44 | this.fromHeight = fromHeight; 45 | } 46 | 47 | public float getFromWidth() { 48 | return fromWidth; 49 | } 50 | 51 | public void setFromWidth(final float fromWidth) { 52 | this.fromWidth = fromWidth; 53 | } 54 | 55 | public float getFromX() { 56 | return fromX; 57 | } 58 | 59 | public void setFromX(final float fromX) { 60 | this.fromX = fromX; 61 | } 62 | 63 | public float getFromY() { 64 | return fromY; 65 | } 66 | 67 | public void setFromY(final float fromY) { 68 | this.fromY = fromY; 69 | } 70 | 71 | public float getToX() { 72 | return toX; 73 | } 74 | 75 | public void setToX(final float toX) { 76 | this.toX = toX; 77 | } 78 | 79 | public float getToY() { 80 | return toY; 81 | } 82 | 83 | public void setToY(final float toY) { 84 | this.toY = toY; 85 | } 86 | 87 | public float getFromRadius() { 88 | return fromRadius; 89 | } 90 | 91 | public void setFromRadius(final float fromRadius) { 92 | this.fromRadius = fromRadius; 93 | } 94 | 95 | public float getToRadius() { 96 | return toRadius; 97 | } 98 | 99 | public void setToRadius(final float toRadius) { 100 | this.toRadius = toRadius; 101 | } 102 | 103 | public MaterialCardView getCardView() { 104 | return cardView; 105 | } 106 | 107 | public void setCardView(final MaterialCardView cardView) { 108 | this.cardView = cardView; 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /owlbottomsheet/src/main/java/br/vince/owlbottomsheet/OnClickInterceptor.java: -------------------------------------------------------------------------------- 1 | package br.vince.owlbottomsheet; 2 | 3 | /** 4 | * Classe criada por Guilherme Ramos em Agosto 2018 5 | * Contato: +55 (11) 974049050 6 | */ 7 | public interface OnClickInterceptor { 8 | 9 | void onExpandBottomSheet(); 10 | void onCollapseBottomSheet(); 11 | 12 | } 13 | -------------------------------------------------------------------------------- /owlbottomsheet/src/main/java/br/vince/owlbottomsheet/OwlBottomSheet.java: -------------------------------------------------------------------------------- 1 | package br.vince.owlbottomsheet; 2 | 3 | import android.content.Context; 4 | import android.support.annotation.ColorInt; 5 | import android.support.annotation.DrawableRes; 6 | import android.support.annotation.LayoutRes; 7 | import android.support.annotation.NonNull; 8 | import android.support.annotation.Nullable; 9 | import android.support.v7.app.AppCompatActivity; 10 | import android.util.AttributeSet; 11 | import android.view.View; 12 | 13 | /** 14 | * Classe criada por Guilherme Ramos em Agosto 2018 15 | * Contato: +55 (11) 974049050 16 | */ 17 | public class OwlBottomSheet extends OwlBottomSheetBase { 18 | 19 | public OwlBottomSheet(final Context context, final AttributeSet attrs, final int defStyleAttr) { 20 | super(context, attrs, defStyleAttr); 21 | } 22 | 23 | public OwlBottomSheet(@NonNull final Context context) { 24 | super(context); 25 | } 26 | 27 | public OwlBottomSheet(@NonNull final Context context, @Nullable final AttributeSet attrs) { 28 | super(context, attrs); 29 | } 30 | 31 | /** 32 | * Set icon to show in collapsed sheet 33 | * @param drawable ex R.drawable.collapse_icon 34 | */ 35 | public void setIcon(@DrawableRes int drawable){ 36 | icon.setImageResource(drawable); 37 | } 38 | 39 | /** 40 | * Color of bottom sheet 41 | * @param color ex: ContextCompat.getColor(getContext(), R.color.colorAccent); 42 | */ 43 | public void setBottomSheetColor(@ColorInt int color){ 44 | bottomSheet.setCardBackgroundColor(color); 45 | } 46 | 47 | /** 48 | * This will make OwlBottomSheet calculate animation from that Activity 49 | * @param activity 50 | */ 51 | public void setActivityView(AppCompatActivity activity) { 52 | super.setActivityView(activity); 53 | } 54 | 55 | /** 56 | * Click listener interceptor from collapse and expand click 57 | * @param interceptor 58 | */ 59 | public void setOnClickInterceptor(OnClickInterceptor interceptor) { 60 | this.interceptor = interceptor; 61 | } 62 | 63 | /** 64 | * Get animation duration 65 | * @return 66 | */ 67 | public int getDuration() { 68 | return ANIM_DURATION; 69 | } 70 | 71 | /** 72 | * Set animation duration. For better results, it's recommended 250~350 73 | */ 74 | public void setDuration(int duration) { 75 | ANIM_DURATION = duration; 76 | } 77 | 78 | /** 79 | * Get on click interceptor listener 80 | * @return 81 | */ 82 | public OnClickInterceptor getOnClickInterceptor() { 83 | return interceptor; 84 | } 85 | 86 | /** 87 | * Collapse bottom sheet 88 | */ 89 | public void collapse() { 90 | super.collapse(); 91 | } 92 | 93 | /** 94 | * Expand bottom sheet 95 | */ 96 | public void expand() { 97 | super.expand(); 98 | } 99 | 100 | /** 101 | * Get bottom sheet state 102 | * @return 103 | */ 104 | public boolean isExpanded() { 105 | return isExpanded; 106 | } 107 | 108 | /** 109 | * Get view shown 110 | * @return 111 | */ 112 | public View getContentView() { 113 | return contentView; 114 | } 115 | 116 | /** 117 | * Attach view to show in bottom sheet 118 | * @param view to be added to bottom sheet 119 | */ 120 | public void attachContentView(View view) { 121 | contentView.addView(view); 122 | } 123 | 124 | /** 125 | * Attach view to show in bottom sheet 126 | * @param view layout to be inflated on bottom sheet 127 | */ 128 | public void attachContentView(@LayoutRes int view) { 129 | View.inflate(getContext(), view, contentView); 130 | } 131 | 132 | } 133 | -------------------------------------------------------------------------------- /owlbottomsheet/src/main/java/br/vince/owlbottomsheet/OwlBottomSheetBase.java: -------------------------------------------------------------------------------- 1 | package br.vince.owlbottomsheet; 2 | 3 | import android.animation.ValueAnimator; 4 | import android.content.Context; 5 | import android.support.annotation.NonNull; 6 | import android.support.annotation.Nullable; 7 | import android.support.design.card.MaterialCardView; 8 | import android.support.v4.view.animation.FastOutSlowInInterpolator; 9 | import android.support.v7.app.AppCompatActivity; 10 | import android.support.v7.widget.AppCompatImageView; 11 | import android.util.AttributeSet; 12 | import android.view.LayoutInflater; 13 | import android.view.View; 14 | import android.view.ViewGroup; 15 | import android.view.animation.AccelerateDecelerateInterpolator; 16 | import android.view.animation.DecelerateInterpolator; 17 | import android.widget.FrameLayout; 18 | 19 | /** 20 | * Classe criada por Guilherme Ramos em Agosto 2018 21 | * Contato: +55 (11) 974049050 22 | */ 23 | class OwlBottomSheetBase extends FrameLayout { 24 | 25 | MaterialCardView bottomSheet; 26 | AppCompatImageView icon; 27 | ViewGroup contentView; 28 | View scrimView; 29 | private View mActivityView; 30 | OnClickInterceptor interceptor; 31 | 32 | int ANIM_DURATION = 350; 33 | static boolean isExpanded = false; 34 | private AnimationBuilder animationBuilder; 35 | 36 | public OwlBottomSheetBase(@NonNull final Context context) { 37 | super(context); 38 | init(); 39 | } 40 | 41 | public OwlBottomSheetBase(@NonNull final Context context, @Nullable final AttributeSet attrs) { 42 | super(context, attrs); 43 | init(); 44 | } 45 | 46 | public OwlBottomSheetBase(final Context context, final AttributeSet attrs, final int defStyleAttr) { 47 | super(context, attrs, defStyleAttr); 48 | init(); 49 | } 50 | 51 | private void init() { 52 | LayoutInflater inflater = (LayoutInflater) getContext() 53 | .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 54 | inflater.inflate(R.layout.owl_bottom_sheet, this, true); 55 | 56 | scrimView = getChildAt(0); 57 | 58 | bottomSheet = (MaterialCardView) getChildAt(1); 59 | 60 | icon = (AppCompatImageView) ((ViewGroup) getChildAt(1)).getChildAt(0); 61 | 62 | contentView = (ViewGroup) ((ViewGroup) getChildAt(1)).getChildAt(1); 63 | 64 | setupViews(); 65 | } 66 | 67 | private void setupViews() { 68 | bottomSheet.setOnClickListener(v -> expand()); 69 | contentView.setVisibility(View.GONE); 70 | scrimView.setVisibility(View.GONE); 71 | } 72 | 73 | void collapse() { 74 | if (!isExpanded) 75 | return; 76 | 77 | initAnimBuilder(); 78 | 79 | final ValueAnimator widthMotion = ValueAnimator.ofFloat(0, 1); 80 | widthMotion.setDuration(5 * ANIM_DURATION / 6); // milliseconds 81 | widthMotion.setStartDelay((ANIM_DURATION / 3)); 82 | widthMotion.setInterpolator(new AccelerateDecelerateInterpolator()); 83 | 84 | final ValueAnimator heightMotion = ValueAnimator.ofFloat(0, 1); 85 | heightMotion.setDuration(ANIM_DURATION); // milliseconds 86 | heightMotion.setInterpolator(new FastOutSlowInInterpolator()); 87 | 88 | widthMotion.addUpdateListener(this::expandXAnimation); 89 | 90 | 91 | heightMotion.addUpdateListener(this::expandYAnimation); 92 | 93 | widthMotion.start(); 94 | heightMotion.start(); 95 | 96 | contentView.setAlpha(1); 97 | contentView.setVisibility(View.VISIBLE); 98 | 99 | scrimView.setAlpha(1); 100 | scrimView.setVisibility(View.VISIBLE); 101 | 102 | icon.setAlpha(0f); 103 | icon.setVisibility(View.VISIBLE); 104 | 105 | contentView.animate().alpha(0).setDuration(ANIM_DURATION / 2) 106 | .setStartDelay(0) 107 | .withEndAction(() -> contentView.setVisibility(View.GONE)); 108 | 109 | scrimView.animate().alpha(0).setDuration(ANIM_DURATION / 2) 110 | .setStartDelay(ANIM_DURATION / 2) 111 | .withEndAction(() -> { 112 | scrimView.setVisibility(View.GONE); 113 | if (interceptor != null) 114 | interceptor.onCollapseBottomSheet(); 115 | }); 116 | 117 | icon.animate().alpha(1).setStartDelay(ANIM_DURATION / 2) 118 | .setDuration(ANIM_DURATION / 2).start(); 119 | 120 | bottomSheet.animate().translationY(0) 121 | .setStartDelay(0).setDuration(ANIM_DURATION).start(); 122 | 123 | bottomSheet.animate().translationX(0) 124 | .setStartDelay(ANIM_DURATION / 2) 125 | .setDuration(ANIM_DURATION / 2).start(); 126 | 127 | isExpanded = false; 128 | } 129 | 130 | void expand() { 131 | if (isExpanded) 132 | return; 133 | 134 | initAnimBuilder(); 135 | 136 | final ValueAnimator widthMotion = ValueAnimator.ofFloat(1, 0); 137 | widthMotion.setDuration(ANIM_DURATION / 3); // milliseconds 138 | widthMotion.setInterpolator(new DecelerateInterpolator()); 139 | 140 | final ValueAnimator heightMotion = ValueAnimator.ofFloat(1, 0); 141 | heightMotion.setDuration(ANIM_DURATION); // milliseconds 142 | heightMotion.setInterpolator(new FastOutSlowInInterpolator()); 143 | 144 | widthMotion.addUpdateListener(this::expandXAnimation); 145 | 146 | heightMotion.addUpdateListener(this::expandYAnimation); 147 | 148 | widthMotion.start(); 149 | heightMotion.start(); 150 | 151 | contentView.setAlpha(0); 152 | contentView.setVisibility(View.VISIBLE); 153 | 154 | scrimView.setAlpha(0); 155 | scrimView.setVisibility(View.VISIBLE); 156 | 157 | icon.setAlpha(1f); 158 | 159 | contentView.animate().alpha(1).setStartDelay(ANIM_DURATION / 2).setDuration(ANIM_DURATION / 2).start(); 160 | scrimView.animate().setStartDelay(0).alpha(1).setDuration(ANIM_DURATION / 3).start(); 161 | 162 | icon.animate().alpha(0).setDuration(ANIM_DURATION / 3) 163 | .setStartDelay(0) 164 | .withEndAction(() -> { 165 | icon.setVisibility(View.GONE); 166 | if (interceptor != null) 167 | interceptor.onExpandBottomSheet(); 168 | }); 169 | 170 | bottomSheet.animate().translationY(-dp2px(48)) 171 | .setStartDelay(0).setDuration(ANIM_DURATION).start(); 172 | bottomSheet.animate().translationX(-dp2px(42)) 173 | .setStartDelay(0) 174 | .setDuration(ANIM_DURATION / 3).start(); 175 | 176 | isExpanded = true; 177 | } 178 | 179 | private void expandXAnimation(final ValueAnimator animation) { 180 | 181 | float fraction = (float) animation.getAnimatedValue(); 182 | 183 | animationBuilder.getCardView() 184 | .setRadius(interpolate(animationBuilder.getFromRadius(), 185 | animationBuilder.getToRadius(), fraction)); 186 | 187 | animationBuilder.getCardView().getLayoutParams().width = 188 | (int) ((animationBuilder.getToWidth() - 189 | animationBuilder.getFromWidth()) * (1 - fraction) + 190 | animationBuilder.getFromWidth()); 191 | 192 | animationBuilder.getCardView().requestLayout(); 193 | } 194 | 195 | private void expandYAnimation(final ValueAnimator animation) { 196 | 197 | float fraction = (float) animation.getAnimatedValue(); 198 | 199 | animationBuilder.getCardView().getLayoutParams().height = (int) ((animationBuilder.getToHeight() - 200 | animationBuilder.getFromHeight()) * (1 - fraction) + 201 | animationBuilder.getFromHeight()); 202 | 203 | animationBuilder.getCardView().requestLayout(); 204 | } 205 | 206 | private float interpolate(float from, float to, float fraction) { 207 | return ((from - to) * fraction) + to; 208 | } 209 | 210 | private void initAnimBuilder() { 211 | if (animationBuilder != null) 212 | return; 213 | 214 | animationBuilder = new AnimationBuilder(); 215 | 216 | animationBuilder.setCardView(bottomSheet); 217 | animationBuilder.setFromHeight(bottomSheet.getHeight()); 218 | animationBuilder.setFromRadius(bottomSheet.getRadius()); 219 | animationBuilder.setFromWidth(bottomSheet.getWidth()); 220 | animationBuilder.setFromX(bottomSheet.getX()); 221 | animationBuilder.setFromY(bottomSheet.getY()); 222 | animationBuilder.setToHeight(getContentView().getHeight()); 223 | animationBuilder.setToWidth(getContentView().getWidth()); 224 | animationBuilder.setToRadius(0); 225 | animationBuilder.setToX(0); 226 | animationBuilder.setToY(0); 227 | } 228 | 229 | void setActivityView(AppCompatActivity activity) { 230 | mActivityView = activity.getWindow().getDecorView().findViewById(android.R.id.content) != null ? 231 | activity.getWindow().getDecorView().findViewById(android.R.id.content) : 232 | findViewById(android.R.id.content).getRootView(); 233 | } 234 | 235 | private int dp2px(float dp) { 236 | final float scale = getContext().getResources().getDisplayMetrics().density; 237 | return (int) (dp * scale + 0.5f); 238 | } 239 | 240 | private View getContentView() { 241 | return mActivityView; 242 | } 243 | } 244 | -------------------------------------------------------------------------------- /owlbottomsheet/src/main/res/layout/owl_bottom_sheet.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 12 | 13 | 25 | 26 | 31 | 32 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /owlbottomsheet/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | OwlBottomSheet 3 | 4 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':owlbottomsheet' 2 | --------------------------------------------------------------------------------