Skip to content

Instantly share code, notes, and snippets.

View ValCanBuild's full-sized avatar

Valentin Hinov ValCanBuild

View GitHub Profile
@ValCanBuild
ValCanBuild / build.gradle
Last active November 8, 2018 08:28
TravisAndroidArticle starting gradle file
android {
// rest of file cut for readability
signingConfigs {
release
}
buildTypes {
release {
minifyEnabled false
@ValCanBuild
ValCanBuild / .travis.yml
Last active March 1, 2018 17:00
TravisAndrodArticle deploy part of .travis.yml
deploy:
provider: releases
skip_cleanup: true
overwrite: true
api_key:
secure: oVvKZhQGC9fhquSLNuYclzH7XdZusVclYJBNHc4MUHkcUJTcTZdQHb1NYFGeaWH1BXvQ9Po58bhpJefHLqMeWvy3/6yyLYPXCQMvT4b7Xi3rkinNVjvoM/RaYHun9R6BAxK/mw8mIC9uVTJHD4jj/rLQsG4Jq/ZEDJyKA8SeHLmDxS82u/1nhDVNZrxd1nMdribkkrxUnsOy2ErH4gJv8O+nbQS3w8JJry26zkh13EKovPrSBe3ogmIlF3gYRZuBbpMAoTYeSQ1uPAapMJEwqIdyeBasTyFmU29Qec3OG/Ud4MB3tK3FF3IFTjygM6SNO4MLn5x8VLnSlthlou9BOXXogqpg5smF1N91/bSWuiDfiRH1nqBX9k7sLy4UjCOaGfP74YAOF8GWHtYVEC2UOvWS4KtZX46gq6ejFibl4gRvtjqLYemBb5M/aczSjJXRMFXOx/X8zxpJ8Dx4K2ioyFqraaFhdyIm5Be3JQmwDr7GfkTapwnbV1ru3UPiXoRdfYgh9yxnSeehUES1m73Fsd29IWlHYZfhCFBF7wOgI5z7P3mKEVPpt/Xx9TBOnoZrS3PhabuG6BmSRhIfPd3s2j6U8YH5Pu/DRANBqJuK7+YlFtEBOP8txUuYzLDU0lLDGyOK/EzIm1jguxUMVfhk5OlracL/3kOeMETXP7+VCw8=
file_glob: true
file: /home/travis/build/ValCanBuild/TravisAndroidExample/app/build/outputs/apk/release/*
on:
repo: ValCanBuild/TravisAndroidExample
@ValCanBuild
ValCanBuild / BottomNavigationBehavior.kt
Created March 14, 2018 05:07
BottomNavigationView Behavior - no snackbar support
class BottomNavigationBehavior<V : View>(context: Context, attrs: AttributeSet) :
CoordinatorLayout.Behavior<V>(context, attrs) {
override fun onStartNestedScroll(
coordinatorLayout: CoordinatorLayout, child: V, directTargetChild: View, target: View, axes: Int, type: Int
): Boolean {
return axes == ViewCompat.SCROLL_AXIS_VERTICAL
}
override fun onNestedPreScroll(
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:layout_behavior="com.mypackage.BottomNavigationBehavior"
app:menu="@menu/my_menu"/>
class BottomNavigationBehavior<V : View>(context: Context, attrs: AttributeSet) :
CoordinatorLayout.Behavior<V>(context, attrs) {
// Rest of the code is the same
override fun layoutDependsOn(parent: CoordinatorLayout?, child: V, dependency: View?): Boolean {
if (dependency is Snackbar.SnackbarLayout) {
updateSnackbar(child, dependency)
}
return super.layoutDependsOn(parent, child, dependency)
@ValCanBuild
ValCanBuild / BottomNavigationBehavior.kt
Last active December 18, 2023 00:04
Full code of a BottomNavigationBehavior which hides itself on scroll and handles Snackbars, FAB and snapping. https://medium.com/@ValCanBuild/scroll-your-bottom-navigation-view-away-with-10-lines-of-code-346f1ed40e9e
/**
MIT License
Copyright (c) 2018 Valentin Hinov
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.design.widget.AppBarLayout
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:src="@drawable/ic_add_black_24dp"
app:fabSize="normal"
app:layout_anchor="@id/navigation"
app:layout_anchorGravity="top|end"
app:layout_behavior="com.mypackage.BottomNavigationFABBehavior"
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:src="@drawable/ic_add_black_24dp"
app:fabSize="normal"
app:layout_anchor="@id/navigation"
app:layout_anchorGravity="top|end"
app:useCompatPadding="true"/>
class BottomNavigationFABBehavior(context: Context?, attrs: AttributeSet?) : CoordinatorLayout.Behavior<View>(context, attrs) {
override fun layoutDependsOn(parent: CoordinatorLayout, child: View, dependency: View): Boolean {
return dependency is Snackbar.SnackbarLayout
}
override fun onDependentViewRemoved(parent: CoordinatorLayout, child: View, dependency: View) {
child.translationY = 0f
}