├── .gitignore ├── LICENSE.txt ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── github │ │ └── heyalex │ │ └── bottomdrawerexample │ │ ├── GoogleTaskExampleDialog.kt │ │ ├── GoogleTaskJavaSampleDialog.java │ │ ├── MainActivity.kt │ │ ├── PullExampleDialog.kt │ │ ├── RotateExampleDialog.kt │ │ └── handle │ │ └── RotateHandleView.kt │ └── res │ ├── drawable-v24 │ └── ic_launcher_foreground.xml │ ├── drawable │ ├── circular_background.xml │ ├── ic_close_black_24dp.xml │ ├── ic_expand_less_black_24dp.xml │ ├── ic_launcher_background.xml │ ├── ic_person_add_black_24dp.xml │ └── ic_settings_black_24dp.xml │ ├── layout │ ├── activity_main.xml │ ├── compact_profile_header.xml │ ├── content_view.xml │ ├── example_layout.xml │ ├── google_task_example_layout.xml │ ├── profile_content.xml │ ├── profile_header.xml │ └── rotate_task_example_layout.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-v21 │ └── styles.xml │ ├── values-v23 │ └── styles.xml │ ├── values-v29 │ └── styles.xml │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── bottomdrawer ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── github │ │ └── heyalex │ │ ├── bottomdrawer │ │ ├── BottomDrawer.kt │ │ ├── BottomDrawerDialog.kt │ │ ├── BottomDrawerFragment.kt │ │ └── TranslationUpdater.kt │ │ ├── handle │ │ ├── PlainHandleView.kt │ │ └── PullHandleView.kt │ │ └── utils │ │ ├── BottomDrawerDelegate.kt │ │ └── DialogFragmentExtension.kt │ └── res │ ├── layout │ └── bottom_drawer_layout.xml │ ├── values-v21 │ └── styles.xml │ ├── values-v23 │ └── styles.xml │ ├── values-v27 │ └── styles.xml │ └── values │ ├── attrs.xml │ ├── colors.xml │ ├── dimens.xml │ ├── ids.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── raw ├── ceramic mug.jpg ├── dinner_set.jpg ├── linen napkins.jpeg ├── sample_custom_arrow.gif ├── sample_custom_pull.gif ├── sample_google_task.gif └── wine_glass.webp └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2019 Alex Fialko 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. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

Bottom Drawer

2 |

Easy way to make Bottom Sheet with animation

3 |

4 | 5 | ## Usage 6 | To customize Bottom Drawer you need to define a new style with extending BottomDialogTheme 7 | 8 | You can use the following properties in your BottomDrawer Theme. 9 | 10 | | Properties | Type | Default | 11 | | ------------------------ | --------------------------------- | ------- | 12 | | `should_draw_under_status_bar` | boolean | false | 13 | | `should_draw_content_under_handle_view` | boolean | false | 14 | | `bottom_sheet_corner_radius` | dimension | 10dp | 15 | | `bottom_sheet_extra_padding` | dimension | 4dp | 16 | | `bottom_drawer_background` | color | WHITE | 17 | 18 | 19 | It will be something like: 20 | ```xml 21 | 25 | ``` 26 | You can make your own HandleView and implement TranslationUpdater interface for getting callbacks. 27 | Or you can use defined handle views by library like PlainHandleView or PullHandleView (check sample app). 28 | 29 | After customizing theme and choosing handle view, you need to override configureBottomDrawer method and pass theme, handle view to BottomDrawerFragment. 30 | 31 | So the following example will make Google Tasks fragment like on main preview: 32 | ```kotlin 33 | class GoogleTaskExampleDialog : BottomDrawerFragment() { 34 | 35 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { 36 | super.onCreateView(inflater, container, savedInstanceState) 37 | return inflater.inflate(R.layout.your_layout, container, false) 38 | } 39 | 40 | override fun configureBottomDrawer(): BottomDrawerDialog { 41 | return BottomDrawerDialog.build(context!!) { 42 | theme = R.style.Plain 43 | //configure handle view 44 | handleView = PlainHandleView(context).apply { 45 | val widthHandle = 46 | resources.getDimensionPixelSize(R.dimen.bottom_sheet_handle_width) 47 | val heightHandle = 48 | resources.getDimensionPixelSize(R.dimen.bottom_sheet_handle_height) 49 | val params = 50 | FrameLayout.LayoutParams(widthHandle, heightHandle, Gravity.CENTER_HORIZONTAL) 51 | 52 | params.topMargin = 53 | resources.getDimensionPixelSize(R.dimen.bottom_sheet_handle_top_margin) 54 | 55 | layoutParams = params 56 | } 57 | } 58 | } 59 | } 60 | ``` 61 | 62 | 63 | You also can change color and corner by code in BottomDrawerFragment: 64 | ```kotlin 65 | changeCornerRadius(radius: Float) 66 | changeBackgroundColor(color: Int) 67 | ``` 68 | 69 | ## Integration 70 | 71 | This library is available on **jitpack**, so you need to add this repository to your root build.gradle: 72 | 73 | ```groovy 74 | allprojects { 75 | repositories { 76 | ... 77 | maven { url 'https://jitpack.io' } 78 | } 79 | } 80 | ``` 81 | 82 | Add the dependency: 83 | 84 | ```groovy 85 | dependencies { 86 | implementation 'com.github.HeyAlex:BottomDrawer:v1.0.0' 87 | } 88 | ``` 89 | 90 | ## Samples 91 | You can find more samples in app module, to understand functionality of library. 92 | 93 | ![](/raw/sample_custom_pull.gif) 94 | ![](/raw/sample_custom_arrow.gif) 95 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | apply plugin: 'kotlin-android' 4 | 5 | apply plugin: 'kotlin-android-extensions' 6 | 7 | android { 8 | compileSdk 31 9 | defaultConfig { 10 | applicationId "com.github.heyalex.bottomdrawerexample" 11 | minSdkVersion 16 12 | targetSdkVersion 31 13 | versionCode 1 14 | versionName "1.0" 15 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 16 | } 17 | buildTypes { 18 | release { 19 | minifyEnabled false 20 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 21 | } 22 | } 23 | 24 | repositories { 25 | maven { url "https://jitpack.io" } 26 | } 27 | 28 | compileOptions { 29 | sourceCompatibility JavaVersion.VERSION_1_8 30 | targetCompatibility JavaVersion.VERSION_1_8 31 | } 32 | 33 | kotlinOptions { 34 | jvmTarget = "1.8" 35 | } 36 | } 37 | 38 | allprojects { 39 | repositories { 40 | maven { url 'https://jitpack.io' } 41 | } 42 | } 43 | 44 | dependencies { 45 | implementation fileTree(dir: 'libs', include: ['*.jar']) 46 | implementation project(':bottomdrawer') 47 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 48 | implementation 'com.github.HeyAlex:ExapandableCardView:-SNAPSHOT' 49 | implementation 'androidx.appcompat:appcompat:1.4.1' 50 | implementation 'androidx.constraintlayout:constraintlayout:2.1.3' 51 | implementation 'com.google.android.material:material:1.5.0' 52 | testImplementation 'junit:junit:4.13.2' 53 | androidTestImplementation 'androidx.test:runner:1.4.0' 54 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' 55 | implementation 'com.github.rtugeek:colorseekbar:1.7.5' 56 | } 57 | -------------------------------------------------------------------------------- /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 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/heyalex/bottomdrawerexample/GoogleTaskExampleDialog.kt: -------------------------------------------------------------------------------- 1 | package com.github.heyalex.bottomdrawerexample 2 | 3 | import android.os.Bundle 4 | import android.view.Gravity 5 | import android.view.LayoutInflater 6 | import android.view.View 7 | import android.view.ViewGroup 8 | import android.widget.FrameLayout 9 | import android.widget.ImageView 10 | import android.widget.SeekBar 11 | import androidx.appcompat.widget.AppCompatCheckBox 12 | import androidx.appcompat.widget.AppCompatSeekBar 13 | import com.github.heyalex.bottomdrawer.BottomDrawerDialog 14 | import com.github.heyalex.bottomdrawer.BottomDrawerFragment 15 | import com.github.heyalex.handle.PlainHandleView 16 | import com.github.heyalex.utils.changeNavigationIconColor 17 | import com.github.heyalex.utils.changeStatusBarIconColor 18 | import com.rtugeek.android.colorseekbar.ColorSeekBar 19 | 20 | class GoogleTaskExampleDialog : BottomDrawerFragment() { 21 | 22 | private var alphaCancelButton = 0f 23 | private lateinit var cancelButton: ImageView 24 | 25 | private lateinit var cornerRadiusSeekBar: AppCompatSeekBar 26 | 27 | private lateinit var navigation: AppCompatCheckBox 28 | private lateinit var statusBar: AppCompatCheckBox 29 | private lateinit var colorSeekBar: ColorSeekBar 30 | 31 | override fun onCreateView( 32 | inflater: LayoutInflater, 33 | container: ViewGroup?, 34 | savedInstanceState: Bundle? 35 | ): View { 36 | val view = inflater.inflate(R.layout.google_task_example_layout, container, false) 37 | cancelButton = view.findViewById(R.id.cancel) 38 | val percent = 0.65f 39 | addBottomSheetCallback { 40 | onSlide { _, slideOffset -> 41 | val alphaTemp = (slideOffset - percent) * (1f / (1f - percent)) 42 | alphaCancelButton = if (alphaTemp >= 0) { 43 | alphaTemp 44 | } else { 45 | 0f 46 | } 47 | cancelButton.alpha = alphaCancelButton 48 | cancelButton.isEnabled = alphaCancelButton > 0 49 | } 50 | } 51 | cancelButton.setOnClickListener { dismissWithBehavior() } 52 | 53 | cornerRadiusSeekBar = view.findViewById(R.id.corner_radius_seek_bar) 54 | cornerRadiusSeekBar.max = 200 55 | cornerRadiusSeekBar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { 56 | override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { 57 | changeCornerRadius(progress.toFloat()) 58 | } 59 | 60 | override fun onStartTrackingTouch(seekBar: SeekBar?) { 61 | } 62 | 63 | override fun onStopTrackingTouch(seekBar: SeekBar?) { 64 | } 65 | 66 | }) 67 | 68 | navigation = view.findViewById(R.id.navigation_bar_accent) 69 | navigation.setOnCheckedChangeListener { _, isChecked -> 70 | changeNavigationIconColor(isChecked) 71 | } 72 | statusBar = view.findViewById(R.id.status_bar_accent) 73 | statusBar.setOnCheckedChangeListener { _, isChecked -> 74 | changeStatusBarIconColor(isChecked) 75 | } 76 | 77 | colorSeekBar = view.findViewById(R.id.colorSlider) 78 | colorSeekBar.setOnColorChangeListener { _, _, color -> 79 | if (!colorSeekBar.isFirstDraw) { 80 | changeBackgroundColor(color) 81 | } 82 | } 83 | 84 | return view 85 | } 86 | 87 | override fun configureBottomDrawer(): BottomDrawerDialog { 88 | return BottomDrawerDialog.build(context!!) { 89 | theme = R.style.Plain 90 | handleView = PlainHandleView(context).apply { 91 | val widthHandle = 92 | resources.getDimensionPixelSize(R.dimen.bottom_sheet_handle_width) 93 | val heightHandle = 94 | resources.getDimensionPixelSize(R.dimen.bottom_sheet_handle_height) 95 | val params = 96 | FrameLayout.LayoutParams(widthHandle, heightHandle, Gravity.CENTER_HORIZONTAL) 97 | 98 | params.topMargin = 99 | resources.getDimensionPixelSize(R.dimen.bottom_sheet_handle_top_margin) 100 | 101 | layoutParams = params 102 | } 103 | } 104 | } 105 | 106 | override fun onSaveInstanceState(outState: Bundle) { 107 | super.onSaveInstanceState(outState) 108 | outState.putFloat("alphaCancelButton", alphaCancelButton) 109 | } 110 | 111 | override fun onViewStateRestored(savedInstanceState: Bundle?) { 112 | super.onViewStateRestored(savedInstanceState) 113 | alphaCancelButton = savedInstanceState?.getFloat("alphaCancelButton") ?: 0f 114 | cancelButton.alpha = alphaCancelButton 115 | cancelButton.isEnabled = alphaCancelButton > 0 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/heyalex/bottomdrawerexample/GoogleTaskJavaSampleDialog.java: -------------------------------------------------------------------------------- 1 | package com.github.heyalex.bottomdrawerexample; 2 | 3 | import android.os.Bundle; 4 | import android.view.Gravity; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.CompoundButton; 9 | import android.widget.FrameLayout; 10 | import android.widget.ImageView; 11 | import android.widget.SeekBar; 12 | 13 | import com.github.heyalex.bottomdrawer.BottomDrawerDialog; 14 | import com.github.heyalex.bottomdrawer.BottomDrawerFragment; 15 | import com.github.heyalex.handle.PlainHandleView; 16 | import com.github.heyalex.utils.BottomDrawerDelegate; 17 | import com.github.heyalex.utils.DialogFragmentExtensionKt; 18 | import com.rtugeek.android.colorseekbar.ColorSeekBar; 19 | 20 | import org.jetbrains.annotations.NotNull; 21 | 22 | import androidx.annotation.NonNull; 23 | import androidx.annotation.Nullable; 24 | import androidx.appcompat.widget.AppCompatCheckBox; 25 | import androidx.appcompat.widget.AppCompatSeekBar; 26 | import kotlin.Unit; 27 | import kotlin.jvm.functions.Function1; 28 | import kotlin.jvm.functions.Function2; 29 | 30 | public class GoogleTaskJavaSampleDialog extends BottomDrawerFragment { 31 | 32 | float alphaCancelButton = 0f; 33 | ImageView cancelButton; 34 | AppCompatSeekBar cornerRadiusSeekBar; 35 | AppCompatCheckBox navigation; 36 | AppCompatCheckBox statusBar; 37 | ColorSeekBar colorSeekBar; 38 | 39 | @Nullable 40 | @Override 41 | public View onCreateView(@NonNull LayoutInflater inflater, 42 | @Nullable ViewGroup container, 43 | @Nullable Bundle savedInstanceState) { 44 | 45 | View view = inflater.inflate(R.layout.google_task_example_layout, container, false); 46 | cancelButton = view.findViewById(R.id.cancel); 47 | final float percent = 0.65f; 48 | 49 | addBottomSheetCallback(new Function1() { 50 | @Override 51 | public Unit invoke(BottomDrawerDelegate.BottomSheetCallback bottomSheetCallback) { 52 | bottomSheetCallback.onSlide(new Function2() { 53 | @Override 54 | public Unit invoke(View view, Float slideOffset) { 55 | float alphaTemp = (slideOffset - percent) * (1.0F / (1.0F - percent)); 56 | GoogleTaskJavaSampleDialog.this.alphaCancelButton = alphaTemp >= (float) 0 ? alphaTemp : 0.0F; 57 | GoogleTaskJavaSampleDialog.this.cancelButton.setAlpha(GoogleTaskJavaSampleDialog.this.alphaCancelButton); 58 | GoogleTaskJavaSampleDialog.this.cancelButton.setEnabled(GoogleTaskJavaSampleDialog.this.alphaCancelButton > 0); 59 | return Unit.INSTANCE; 60 | } 61 | }); 62 | return Unit.INSTANCE; 63 | } 64 | }); 65 | cancelButton.setOnClickListener(new View.OnClickListener() { 66 | @Override 67 | public void onClick(View v) { 68 | dismissWithBehavior(); 69 | } 70 | }); 71 | 72 | cornerRadiusSeekBar = view.findViewById(R.id.corner_radius_seek_bar); 73 | cornerRadiusSeekBar.setMax(200); 74 | cornerRadiusSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { 75 | 76 | @Override 77 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { 78 | changeCornerRadius(progress); 79 | } 80 | 81 | @Override 82 | public void onStartTrackingTouch(SeekBar seekBar) { 83 | 84 | } 85 | 86 | @Override 87 | public void onStopTrackingTouch(SeekBar seekBar) { 88 | 89 | } 90 | }); 91 | 92 | navigation = view.findViewById(R.id.navigation_bar_accent); 93 | navigation.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 94 | @Override 95 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 96 | DialogFragmentExtensionKt.changeNavigationIconColor(GoogleTaskJavaSampleDialog.this, isChecked); 97 | } 98 | }); 99 | statusBar = view.findViewById(R.id.status_bar_accent); 100 | statusBar.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 101 | @Override 102 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 103 | DialogFragmentExtensionKt.changeStatusBarIconColor(GoogleTaskJavaSampleDialog.this, isChecked); 104 | } 105 | }); 106 | 107 | colorSeekBar = view.findViewById(R.id.colorSlider); 108 | colorSeekBar.setOnColorChangeListener(new ColorSeekBar.OnColorChangeListener() { 109 | @Override 110 | public void onColorChangeListener(int colorBarPosition, 111 | int alphaBarPosition, 112 | int color) { 113 | if (!colorSeekBar.isFirstDraw()) { 114 | changeBackgroundColor(color); 115 | } 116 | } 117 | }); 118 | 119 | return view; 120 | } 121 | 122 | @NotNull 123 | @Override 124 | public BottomDrawerDialog configureBottomDrawer() { 125 | BottomDrawerDialog.Builder builder = new BottomDrawerDialog.Builder(requireContext()); 126 | 127 | View handleView = new PlainHandleView(requireContext()); 128 | int widthHandle = getResources().getDimensionPixelSize(R.dimen.bottom_sheet_handle_width); 129 | int heightHandle = 130 | getResources().getDimensionPixelSize(R.dimen.bottom_sheet_handle_height); 131 | FrameLayout.LayoutParams params = 132 | new FrameLayout.LayoutParams(widthHandle, heightHandle, Gravity.CENTER_HORIZONTAL); 133 | 134 | params.topMargin = 135 | getResources().getDimensionPixelSize(R.dimen.bottom_sheet_handle_top_margin); 136 | handleView.setLayoutParams(params); 137 | 138 | builder.setHandleView(handleView); 139 | 140 | return builder.build(); 141 | } 142 | 143 | @Override 144 | public void onSaveInstanceState(@NonNull @NotNull Bundle outState) { 145 | super.onSaveInstanceState(outState); 146 | outState.putFloat("alphaCancelButton", alphaCancelButton); 147 | } 148 | 149 | @Override 150 | public void onViewStateRestored(@Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) { 151 | super.onViewStateRestored(savedInstanceState); 152 | this.alphaCancelButton = savedInstanceState != null ? savedInstanceState.getFloat("alphaCancelButton") : 0.0F; 153 | cancelButton.setAlpha(this.alphaCancelButton); 154 | cancelButton.setEnabled(this.alphaCancelButton > 0); 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/heyalex/bottomdrawerexample/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.github.heyalex.bottomdrawerexample 2 | 3 | import android.graphics.Color 4 | import android.os.Build 5 | import android.os.Bundle 6 | import android.view.View 7 | import android.view.WindowManager 8 | import androidx.appcompat.app.AppCompatActivity 9 | import kotlinx.android.synthetic.main.activity_main.* 10 | 11 | 12 | class MainActivity : AppCompatActivity() { 13 | 14 | override fun onCreate(savedInstanceState: Bundle?) { 15 | super.onCreate(savedInstanceState) 16 | setContentView(R.layout.activity_main) 17 | 18 | window.let { 19 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 20 | window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) 21 | } 22 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 23 | // for drawing behind status bar 24 | window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) 25 | } 26 | 27 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 28 | //make system bar to be translucent 29 | window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or 30 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE 31 | 32 | //make status bar color transparent 33 | window.statusBarColor = Color.TRANSPARENT 34 | 35 | var flags = it.decorView.systemUiVisibility 36 | // make dark status bar icons 37 | flags = 38 | flags xor View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR 39 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 40 | // make dark navigation bar icons 41 | flags = 42 | flags xor View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR 43 | } 44 | window.decorView.systemUiVisibility = flags 45 | } 46 | } 47 | 48 | show_button.setOnClickListener { 49 | supportFragmentManager.beginTransaction().add(GoogleTaskExampleDialog(), "test") 50 | .commit() 51 | } 52 | 53 | show_button_sample.setOnClickListener { 54 | supportFragmentManager.beginTransaction().add(PullExampleDialog(), "test1") 55 | .commit() 56 | } 57 | 58 | show_button_second_sample.setOnClickListener { 59 | supportFragmentManager.beginTransaction().add(RotateExampleDialog(), "test1") 60 | .commit() 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/heyalex/bottomdrawerexample/PullExampleDialog.kt: -------------------------------------------------------------------------------- 1 | package com.github.heyalex.bottomdrawerexample 2 | 3 | import android.os.Bundle 4 | import android.view.Gravity 5 | import android.view.LayoutInflater 6 | import android.view.View 7 | import android.view.ViewGroup 8 | import android.widget.FrameLayout 9 | import android.widget.ImageView 10 | import android.widget.SeekBar 11 | import androidx.appcompat.widget.AppCompatCheckBox 12 | import androidx.appcompat.widget.AppCompatSeekBar 13 | import com.github.heyalex.bottomdrawer.BottomDrawerDialog 14 | import com.github.heyalex.bottomdrawer.BottomDrawerFragment 15 | import com.github.heyalex.handle.PullHandleView 16 | import com.github.heyalex.utils.changeNavigationIconColor 17 | import com.github.heyalex.utils.changeStatusBarIconColor 18 | import com.rtugeek.android.colorseekbar.ColorSeekBar 19 | 20 | class PullExampleDialog : BottomDrawerFragment() { 21 | 22 | private var alphaCancelButton = 0f 23 | private lateinit var cancelButton: ImageView 24 | 25 | private lateinit var cornerRadiusSeekBar: AppCompatSeekBar 26 | 27 | private lateinit var navigation: AppCompatCheckBox 28 | private lateinit var statusBar: AppCompatCheckBox 29 | private lateinit var colorSeekBar: ColorSeekBar 30 | 31 | override fun onCreateView( 32 | inflater: LayoutInflater, 33 | container: ViewGroup?, 34 | savedInstanceState: Bundle? 35 | ): View { 36 | val view = inflater.inflate(R.layout.google_task_example_layout, container, false) 37 | cancelButton = view.findViewById(R.id.cancel) 38 | addBottomSheetCallback { 39 | onSlide { _, slideOffset -> 40 | alphaCancelButton = (slideOffset - PERCENT) * (1f / (1f - PERCENT)) 41 | cancelButton.alpha = alphaCancelButton 42 | cancelButton.isEnabled = alphaCancelButton > 0 43 | } 44 | } 45 | cancelButton.setOnClickListener { dismissWithBehavior() } 46 | 47 | cornerRadiusSeekBar = view.findViewById(R.id.corner_radius_seek_bar) 48 | cornerRadiusSeekBar.max = 80 49 | cornerRadiusSeekBar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { 50 | override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { 51 | changeCornerRadius(progress.toFloat()) 52 | } 53 | 54 | override fun onStartTrackingTouch(seekBar: SeekBar?) { 55 | } 56 | 57 | override fun onStopTrackingTouch(seekBar: SeekBar?) { 58 | } 59 | 60 | }) 61 | 62 | navigation = view.findViewById(R.id.navigation_bar_accent) 63 | navigation.setOnCheckedChangeListener { _, isChecked -> 64 | changeNavigationIconColor(isChecked) 65 | } 66 | statusBar = view.findViewById(R.id.status_bar_accent) 67 | statusBar.setOnCheckedChangeListener { _, isChecked -> 68 | changeStatusBarIconColor(isChecked) 69 | } 70 | 71 | colorSeekBar = view.findViewById(R.id.colorSlider) 72 | colorSeekBar.setOnColorChangeListener { _, _, color -> 73 | if (!colorSeekBar.isFirstDraw) { 74 | changeBackgroundColor(color) 75 | } 76 | } 77 | 78 | return view 79 | } 80 | 81 | override fun configureBottomDrawer(): BottomDrawerDialog { 82 | return BottomDrawerDialog.build(context!!) { 83 | theme = R.style.Pull 84 | handleView = PullHandleView(context).apply { 85 | val widthHandle = 86 | resources.getDimensionPixelSize(R.dimen.sample_bottom_sheet_handle_width) 87 | val heightHandle = 88 | resources.getDimensionPixelSize(R.dimen.sample_bottom_sheet_handle_height) 89 | val params = 90 | FrameLayout.LayoutParams(widthHandle, heightHandle, Gravity.CENTER_HORIZONTAL) 91 | 92 | params.topMargin = 93 | resources.getDimensionPixelSize(R.dimen.sample_bottom_sheet_handle_top_margin) 94 | 95 | layoutParams = params 96 | } 97 | } 98 | } 99 | 100 | override fun onSaveInstanceState(outState: Bundle) { 101 | super.onSaveInstanceState(outState) 102 | outState.putFloat("alphaCancelButton", alphaCancelButton) 103 | } 104 | 105 | override fun onViewStateRestored(savedInstanceState: Bundle?) { 106 | super.onViewStateRestored(savedInstanceState) 107 | alphaCancelButton = savedInstanceState?.getFloat("alphaCancelButton") ?: 0f 108 | } 109 | 110 | companion object { 111 | const val PERCENT = 0.65f 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/heyalex/bottomdrawerexample/RotateExampleDialog.kt: -------------------------------------------------------------------------------- 1 | package com.github.heyalex.bottomdrawerexample 2 | 3 | import android.os.Bundle 4 | import android.view.Gravity 5 | import android.view.LayoutInflater 6 | import android.view.View 7 | import android.view.ViewGroup 8 | import android.widget.FrameLayout 9 | import android.widget.SeekBar 10 | import androidx.appcompat.widget.AppCompatCheckBox 11 | import androidx.appcompat.widget.AppCompatSeekBar 12 | import androidx.core.content.ContextCompat 13 | import com.github.heyalex.bottomdrawer.BottomDrawerDialog 14 | import com.github.heyalex.bottomdrawer.BottomDrawerFragment 15 | import com.github.heyalex.bottomdrawerexample.handle.RotateHandleView 16 | import com.github.heyalex.utils.changeNavigationIconColor 17 | import com.github.heyalex.utils.changeStatusBarIconColor 18 | import com.google.android.material.bottomsheet.BottomSheetBehavior 19 | import com.rtugeek.android.colorseekbar.ColorSeekBar 20 | 21 | class RotateExampleDialog : BottomDrawerFragment() { 22 | 23 | private lateinit var cornerRadiusSeekBar: AppCompatSeekBar 24 | 25 | private lateinit var navigation: AppCompatCheckBox 26 | private lateinit var statusBar: AppCompatCheckBox 27 | private lateinit var colorSeekBar: ColorSeekBar 28 | 29 | override fun onCreateView( 30 | inflater: LayoutInflater, 31 | container: ViewGroup?, 32 | savedInstanceState: Bundle? 33 | ): View { 34 | 35 | val view = inflater.inflate(R.layout.rotate_task_example_layout, container, false) 36 | cornerRadiusSeekBar = view.findViewById(R.id.corner_radius_seek_bar) 37 | cornerRadiusSeekBar.max = 80 38 | cornerRadiusSeekBar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { 39 | override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { 40 | changeCornerRadius(progress.toFloat()) 41 | } 42 | 43 | override fun onStartTrackingTouch(seekBar: SeekBar?) { 44 | } 45 | 46 | override fun onStopTrackingTouch(seekBar: SeekBar?) { 47 | } 48 | 49 | }) 50 | 51 | navigation = view.findViewById(R.id.navigation_bar_accent) 52 | navigation.setOnCheckedChangeListener { _, isChecked -> 53 | changeNavigationIconColor(isChecked) 54 | } 55 | statusBar = view.findViewById(R.id.status_bar_accent) 56 | statusBar.setOnCheckedChangeListener { _, isChecked -> 57 | changeStatusBarIconColor(isChecked) 58 | } 59 | 60 | colorSeekBar = view.findViewById(R.id.colorSlider) 61 | colorSeekBar.setOnColorChangeListener { _, _, color -> 62 | if (!colorSeekBar.isFirstDraw) { 63 | changeBackgroundColor(color) 64 | } 65 | } 66 | 67 | return view 68 | } 69 | 70 | override fun configureBottomDrawer(): BottomDrawerDialog { 71 | return BottomDrawerDialog.build(context!!) { 72 | theme = R.style.Rotate 73 | handleView = RotateHandleView(context).apply { 74 | val widthHandle = 75 | resources.getDimensionPixelSize(R.dimen.rotate_sample_bottom_sheet_handle_width) 76 | val heightHandle = 77 | resources.getDimensionPixelSize(R.dimen.rotate_sample_bottom_sheet_handle_height) 78 | val params = 79 | FrameLayout.LayoutParams(widthHandle, heightHandle, Gravity.END) 80 | 81 | params.topMargin = 82 | resources.getDimensionPixelSize(R.dimen.rotate_sample_bottom_sheet_handle_margin) 83 | 84 | params.rightMargin = 85 | resources.getDimensionPixelSize(R.dimen.rotate_sample_bottom_sheet_handle_margin) 86 | 87 | layoutParams = params 88 | background = 89 | ContextCompat.getDrawable(context, R.drawable.ic_expand_less_black_24dp) 90 | 91 | setOnClickListener { 92 | when (getCurrentState()) { 93 | BottomSheetBehavior.STATE_EXPANDED -> dismissWithBehavior() 94 | BottomSheetBehavior.STATE_COLLAPSED, 95 | BottomSheetBehavior.STATE_HALF_EXPANDED -> expandWithBehaivor() 96 | 97 | } 98 | } 99 | } 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/heyalex/bottomdrawerexample/handle/RotateHandleView.kt: -------------------------------------------------------------------------------- 1 | package com.github.heyalex.bottomdrawerexample.handle 2 | 3 | import android.content.Context 4 | import androidx.appcompat.widget.AppCompatImageView 5 | import com.github.heyalex.bottomdrawer.TranslationUpdater 6 | 7 | class RotateHandleView(context: Context) : AppCompatImageView(context), TranslationUpdater { 8 | override fun updateTranslation(value: Float) { 9 | this.rotation = -180 * value 10 | } 11 | } -------------------------------------------------------------------------------- /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/circular_background.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 7 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_close_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 7 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_expand_less_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /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/drawable/ic_person_add_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 7 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_settings_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 7 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 |