-
-
## Screenshots
+
## Playground app
+
-Download the playground app from Google Play, with this app you can try out all features and even generate XML with your selected configuration.
+Download the playground app from Google Play, with this app you can try out all features and even
+generate XML with your selected configuration.
## Contents
+
- [Getting started](#getting-started)
- [Managing tabs](#managing-tabs)
- [Usage with ViewPager](#usage-with-viewpager)
@@ -36,51 +41,43 @@ Download the playground app from Google Play, with this app you can try out all
## Getting started
-This library is available on Maven Central, install it by adding the following dependency to your build.gradle:
+This library is available on Maven Central, install it by adding the following dependency to
+your build.gradle:
+
```gradle
implementation 'nl.joery.animatedbottombar:library:1.1.0'
```
-*Versions 1.0.x can only be used with jCenter, versions 1.1.x and up can be used with Maven Central.*
+*Versions 1.0.x can only be used with jCenter, versions 1.1.x and up can be used with Maven
+Central.*
Define `AnimatedBottomBar` in your XML layout with custom attributes.
+
```xml
-
```
Create a file named `tabs.xml` in the `res/menu/` resources folder:
+
```xml
+
```
Get notified when the selected tab changes by setting callbacks:
+
```kotlin
bottom_bar.onTabSelected = {
Log.d("bottom_bar", "Selected tab: " + it.title)
@@ -91,6 +88,7 @@ bottom_bar.onTabReselected = {
```
Or set a listener if you need more detailed information:
+
```kotlin
bottom_bar.setOnTabSelectListener(object : AnimatedBottomBar.OnTabSelectListener {
override fun onTabSelected(
@@ -110,9 +108,11 @@ bottom_bar.setOnTabSelectListener(object : AnimatedBottomBar.OnTabSelectListener
```
## Managing tabs
+
Short overview on how to manage tabs using code.
### Creating new tabs
+
```kotlin
// Creating a tab by passing values
val bottomBarTab1 = AnimatedBottomBar.createTab(drawable, "Tab 1")
@@ -120,7 +120,9 @@ val bottomBarTab1 = AnimatedBottomBar.createTab(drawable, "Tab 1")
// Creating a tab by passing resources
val bottomBarTab2 = AnimatedBottomBar.createTab(R.drawable.ic_home, R.string.tab_2, R.id.tab_home)
```
+
### Adding new tabs
+
```kotlin
// Adding a tab at the end
AnimatedBottomBar.addTab(bottomBarTab1)
@@ -130,6 +132,7 @@ AnimatedBottomBar.addTabAt(1, bottomBarTab2)
```
### Removing tabs
+
```kotlin
// Removing a tab by object reference
val tabToRemove = AnimatedBottomBar.tabs[1]
@@ -143,6 +146,7 @@ AnimatedBottomBar.removeTabById(R.id.tab_home)
```
### Selecting tabs
+
```kotlin
// Selecting a tab by object reference
val tabToSelect = AnimatedBottomBar.tabs[1]
@@ -156,6 +160,7 @@ AnimatedBottomBar.selectTabById(R.id.tab_home)
```
### Enabling / disabling tabs
+
```kotlin
// Disabling a tab by object reference
val tabToDisable = AnimatedBottomBar.tabs[1]
@@ -169,7 +174,10 @@ AnimatedBottomBar.setTabEnabledById(R.id.tab_home, false)
```
### Intercepting tabs
-This could be useful for example restricting access to a premium area. You can use a callback or a more detailed listener:
+
+This could be useful for example restricting access to a premium area. You can use a callback or a
+more detailed listener:
+
```kotlin
bottom_bar.onTabIntercepted = {
if (newTab.id == R.id.tab_pro_feature && !hasProVersion) {
@@ -181,6 +189,7 @@ bottom_bar.onTabIntercepted = {
```
Detailed listener:
+
```kotlin
bottom_bar.setOnTabInterceptListener(object : AnimatedBottomBar.OnTabInterceptListener {
override fun onTabIntercepted(
@@ -199,9 +208,12 @@ bottom_bar.setOnTabInterceptListener(object : AnimatedBottomBar.OnTabInterceptLi
```
## Tab badges
-Instructions on how to set badges for tabs, a `AnimatedBottomBar.Badge` object should be supplied to the BottomBar, note that it is also possible to add badges without text.
+
+Instructions on how to set badges for tabs, a `AnimatedBottomBar.Badge` object should be supplied to
+the BottomBar, note that it is also possible to add badges without text.
### Adding badges
+
```kotlin
// Adding a badge by tab reference
val tabToAddBadgeAt = AnimatedBottomBar.tabs[1]
@@ -215,6 +227,7 @@ AnimatedBottomBar.setBadgeAtTabId(R.id.tab_home, AnimatedBottomBar.Badge("99"))
```
### Removing badges
+
```kotlin
// Removing a badge by tab reference
val tabToRemoveBadgeFrom = AnimatedBottomBar.tabs[1]
@@ -228,20 +241,45 @@ AnimatedBottomBar.clearBadgeAtTabId(R.id.tab_home, AnimatedBottomBar.Badge("99")
```
### Styling individual badges
+
Additionally there is also the possibility to individually style badges.
+
```kotlin
AnimatedBottomBar.Badge(
text = "99",
backgroundColor = Color.RED,
textColor = Color.GREEN,
- textSize = 12.spPx // in pixels
+ textSize = 12.spPx // in pixels
)
```
+## Usage with Navigation Components
+
+It is easy to use BottomBar with Navigation Components, you can simply use
+the `setUpWithNavController()` method. Usually you don't need a menu object to connect bottom
+navigation bar with navController, but here you need it.
+
+Usage
+
+```kotlin
+//create a PopUp menu
+val popUpMenu = PopupMenu(this, null)
+
+//inflate the PopUp menu with the menu.xml you created
+popUpMenu.inflate(R.menu.clock_tabs)
+
+//connecting BottomBar with navController
+bottom_bar.setupWithNavController(popUpMenu.menu, navController)
+```
+
## Usage with ViewPager
-It is easy to use the BottomBar with a ViewPager or ViewPager2, you can simply use the `setupWithViewPager()` method. Please note that the number of tabs and ViewPager pages need to be identical in order for it to function properly.
+
+It is easy to use the BottomBar with a ViewPager or ViewPager2, you can simply use
+the `setupWithViewPager()` method. Please note that the number of tabs and ViewPager pages need to
+be identical in order for it to function properly.
Usage
+
```kotlin
// For ViewPager use:
bottom_bar.setupWithViewPager(yourViewPager)
@@ -251,9 +289,12 @@ bottom_bar.setupWithViewPager2(yourViewPager2)
```
## Configuration
-An overview of all configuration options. All options can also be accessed and set programmatically, by their equivalent name.
+
+An overview of all configuration options. All options can also be accessed and set programmatically,
+by their equivalent name.
### Tabs
+
Attribute
@@ -288,6 +329,7 @@ An overview of all configuration options. All options can also be accessed and s
### Tab appearance
+
Attribute
@@ -366,6 +408,7 @@ An overview of all configuration options. All options can also be accessed and s
### Badges
+
Attribute
@@ -413,6 +456,7 @@ An overview of all configuration options. All options can also be accessed and s
### Animations
+
Attribute
@@ -464,6 +508,7 @@ An overview of all configuration options. All options can also be accessed and s
### Indicator
+
Attribute
@@ -525,14 +570,17 @@ An overview of all configuration options. All options can also be accessed and s
## Featured in
+
- [Android Weekly: Issue 404](https://androidweekly.net/issues/issue-404)
- [Medium: The 25 Best Android Libraries and Projects of 2020](https://medium.com/better-programming/25-best-android-libraries-projects-of-2020-summer-edition-dfb030a7fb0a)
- [Medium: The Top 5 Trending Android Libraries From Q1 2020](https://medium.com/better-programming/the-top-5-trending-android-libraries-from-q1-2020-45deda73af0f)
## Credits
+
- [Dribble: Readable Tab Bar](https://dribbble.com/shots/6130593-Readable-Tab-Bar)
## License
+
```
MIT License
diff --git a/demo/src/androidTest/java/nl/joery/demo/animatedbottombar/ExampleInstrumentedTest.kt b/demo/src/androidTest/java/nl/joery/demo/animatedbottombar/ExampleInstrumentedTest.kt
index 355ed9c..6d3746a 100644
--- a/demo/src/androidTest/java/nl/joery/demo/animatedbottombar/ExampleInstrumentedTest.kt
+++ b/demo/src/androidTest/java/nl/joery/demo/animatedbottombar/ExampleInstrumentedTest.kt
@@ -19,4 +19,4 @@ class ExampleInstrumentedTest {
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("nl.joery.animatedbottombar", appContext.packageName)
}
-}
\ No newline at end of file
+}
diff --git a/demo/src/main/AndroidManifest.xml b/demo/src/main/AndroidManifest.xml
index 65e65d9..5fb2be2 100644
--- a/demo/src/main/AndroidManifest.xml
+++ b/demo/src/main/AndroidManifest.xml
@@ -11,9 +11,7 @@
android:theme="@style/AppTheme"
android:versionCode="3"
android:versionName="1.0.2">
-
-
+
@@ -101,4 +100,4 @@ class ExampleActivity : AppCompatActivity() {
}
})
}
-}
\ No newline at end of file
+}
diff --git a/demo/src/main/java/nl/joery/demo/animatedbottombar/Extensions.kt b/demo/src/main/java/nl/joery/demo/animatedbottombar/Extensions.kt
index 32aabdb..683cdcb 100644
--- a/demo/src/main/java/nl/joery/demo/animatedbottombar/Extensions.kt
+++ b/demo/src/main/java/nl/joery/demo/animatedbottombar/Extensions.kt
@@ -10,4 +10,4 @@ internal val Int.sp: Int
internal val Int.dpPx: Int
get() = (this * Resources.getSystem().displayMetrics.density).roundToInt()
internal val Int.spPx: Int
- get() = (this * Resources.getSystem().displayMetrics.scaledDensity).roundToInt()
\ No newline at end of file
+ get() = (this * Resources.getSystem().displayMetrics.scaledDensity).roundToInt()
diff --git a/demo/src/main/java/nl/joery/demo/animatedbottombar/ReflectionUtils.kt b/demo/src/main/java/nl/joery/demo/animatedbottombar/ReflectionUtils.kt
index 0b7e6d3..898e562 100644
--- a/demo/src/main/java/nl/joery/demo/animatedbottombar/ReflectionUtils.kt
+++ b/demo/src/main/java/nl/joery/demo/animatedbottombar/ReflectionUtils.kt
@@ -38,4 +38,4 @@ internal object ReflectionUtils {
return sb.toString().toLowerCase()
}
-}
\ No newline at end of file
+}
diff --git a/demo/src/main/java/nl/joery/demo/animatedbottombar/bottomsheet/BottomSheetActivity.kt b/demo/src/main/java/nl/joery/demo/animatedbottombar/bottomsheet/BottomSheetActivity.kt
index f41f3c1..80030e7 100644
--- a/demo/src/main/java/nl/joery/demo/animatedbottombar/bottomsheet/BottomSheetActivity.kt
+++ b/demo/src/main/java/nl/joery/demo/animatedbottombar/bottomsheet/BottomSheetActivity.kt
@@ -8,7 +8,6 @@ import kotlinx.android.synthetic.main.activity_bottom_sheet.*
import nl.joery.demo.animatedbottombar.R
import nl.joery.demo.animatedbottombar.dpPx
-
class BottomSheetActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@@ -20,4 +19,4 @@ class BottomSheetActivity : AppCompatActivity() {
val bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet)
bottomSheetBehavior.peekHeight = 150.dpPx
}
-}
\ No newline at end of file
+}
diff --git a/demo/src/main/java/nl/joery/demo/animatedbottombar/navcontroller/FirstFragment.kt b/demo/src/main/java/nl/joery/demo/animatedbottombar/navcontroller/FirstFragment.kt
index f6cda99..2c003fb 100644
--- a/demo/src/main/java/nl/joery/demo/animatedbottombar/navcontroller/FirstFragment.kt
+++ b/demo/src/main/java/nl/joery/demo/animatedbottombar/navcontroller/FirstFragment.kt
@@ -9,10 +9,11 @@ import nl.joery.demo.animatedbottombar.R
class FirstFragment : Fragment() {
override fun onCreateView(
- inflater: LayoutInflater, container: ViewGroup?,
+ inflater: LayoutInflater,
+ container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_first, container, false)
}
-}
\ No newline at end of file
+}
diff --git a/demo/src/main/java/nl/joery/demo/animatedbottombar/navcontroller/FourthFragment.kt b/demo/src/main/java/nl/joery/demo/animatedbottombar/navcontroller/FourthFragment.kt
index 4a650aa..741eab8 100644
--- a/demo/src/main/java/nl/joery/demo/animatedbottombar/navcontroller/FourthFragment.kt
+++ b/demo/src/main/java/nl/joery/demo/animatedbottombar/navcontroller/FourthFragment.kt
@@ -9,10 +9,11 @@ import nl.joery.demo.animatedbottombar.R
class FourthFragment : Fragment() {
override fun onCreateView(
- inflater: LayoutInflater, container: ViewGroup?,
+ inflater: LayoutInflater,
+ container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_fourth, container, false)
}
-}
\ No newline at end of file
+}
diff --git a/demo/src/main/java/nl/joery/demo/animatedbottombar/navcontroller/NavControllerActivity.kt b/demo/src/main/java/nl/joery/demo/animatedbottombar/navcontroller/NavControllerActivity.kt
index 72067af..d2ab7dd 100644
--- a/demo/src/main/java/nl/joery/demo/animatedbottombar/navcontroller/NavControllerActivity.kt
+++ b/demo/src/main/java/nl/joery/demo/animatedbottombar/navcontroller/NavControllerActivity.kt
@@ -1,7 +1,7 @@
package nl.joery.demo.animatedbottombar.navcontroller
import android.os.Bundle
-import android.view.Menu
+import android.widget.PopupMenu
import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.NavController
import androidx.navigation.findNavController
@@ -9,23 +9,23 @@ import androidx.navigation.ui.setupActionBarWithNavController
import kotlinx.android.synthetic.main.activity_nav_controller.*
import nl.joery.demo.animatedbottombar.R
-
class NavControllerActivity : AppCompatActivity(R.layout.activity_nav_controller) {
private lateinit var navController: NavController
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
navController = findNavController(R.id.main_fragment)
setupActionBarWithNavController(navController)
+ setUpBottomBar()
}
- override fun onCreateOptionsMenu(menu: Menu?): Boolean {
- menuInflater.inflate(R.menu.clock_tabs, menu)
- bottom_bar.setupWithNavController(menu!!, navController)
- return true
+ private fun setUpBottomBar() {
+ val popUpMenu = PopupMenu(this, null)
+ popUpMenu.inflate(R.menu.clock_tabs)
+ bottom_bar.setupWithNavController(popUpMenu.menu, navController)
}
override fun onSupportNavigateUp(): Boolean {
navController.navigateUp()
return true
}
-}
\ No newline at end of file
+}
diff --git a/demo/src/main/java/nl/joery/demo/animatedbottombar/navcontroller/SecondFragment.kt b/demo/src/main/java/nl/joery/demo/animatedbottombar/navcontroller/SecondFragment.kt
index 39f0dea..f1c88cf 100644
--- a/demo/src/main/java/nl/joery/demo/animatedbottombar/navcontroller/SecondFragment.kt
+++ b/demo/src/main/java/nl/joery/demo/animatedbottombar/navcontroller/SecondFragment.kt
@@ -9,10 +9,11 @@ import nl.joery.demo.animatedbottombar.R
class SecondFragment : Fragment() {
override fun onCreateView(
- inflater: LayoutInflater, container: ViewGroup?,
+ inflater: LayoutInflater,
+ container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_second, container, false)
}
-}
\ No newline at end of file
+}
diff --git a/demo/src/main/java/nl/joery/demo/animatedbottombar/navcontroller/ThirdFragment.kt b/demo/src/main/java/nl/joery/demo/animatedbottombar/navcontroller/ThirdFragment.kt
index 81adfd0..caf0ea2 100644
--- a/demo/src/main/java/nl/joery/demo/animatedbottombar/navcontroller/ThirdFragment.kt
+++ b/demo/src/main/java/nl/joery/demo/animatedbottombar/navcontroller/ThirdFragment.kt
@@ -9,10 +9,11 @@ import nl.joery.demo.animatedbottombar.R
class ThirdFragment : Fragment() {
override fun onCreateView(
- inflater: LayoutInflater, container: ViewGroup?,
+ inflater: LayoutInflater,
+ container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_third, container, false)
}
-}
\ No newline at end of file
+}
diff --git a/demo/src/main/java/nl/joery/demo/animatedbottombar/playground/PlaygroundActivity.kt b/demo/src/main/java/nl/joery/demo/animatedbottombar/playground/PlaygroundActivity.kt
index b2f3495..0788c40 100644
--- a/demo/src/main/java/nl/joery/demo/animatedbottombar/playground/PlaygroundActivity.kt
+++ b/demo/src/main/java/nl/joery/demo/animatedbottombar/playground/PlaygroundActivity.kt
@@ -25,7 +25,6 @@ import nl.joery.demo.animatedbottombar.R
import nl.joery.demo.animatedbottombar.playground.properties.*
import nl.joery.demo.animatedbottombar.spPx
-
class PlaygroundActivity : AppCompatActivity() {
private lateinit var properties: ArrayList
@@ -34,7 +33,8 @@ class PlaygroundActivity : AppCompatActivity() {
setContentView(R.layout.activity_playground)
bottom_bar.setBadgeAtTabIndex(
- 1, AnimatedBottomBar.Badge(
+ 1,
+ AnimatedBottomBar.Badge(
text = "99",
backgroundColor = Color.RED,
textColor = Color.GREEN,
@@ -269,4 +269,4 @@ class PlaygroundActivity : AppCompatActivity() {
Html.fromHtml(html)
}
}
-}
\ No newline at end of file
+}
diff --git a/demo/src/main/java/nl/joery/demo/animatedbottombar/playground/PropertyAdapter.kt b/demo/src/main/java/nl/joery/demo/animatedbottombar/playground/PropertyAdapter.kt
index 081c28a..8bde66a 100644
--- a/demo/src/main/java/nl/joery/demo/animatedbottombar/playground/PropertyAdapter.kt
+++ b/demo/src/main/java/nl/joery/demo/animatedbottombar/playground/PropertyAdapter.kt
@@ -23,7 +23,6 @@ import nl.joery.animatedbottombar.AnimatedBottomBar
import nl.joery.demo.animatedbottombar.*
import nl.joery.demo.animatedbottombar.playground.properties.*
-
internal class PropertyAdapter(
private val bottomBar: AnimatedBottomBar,
private val properties: List
@@ -148,9 +147,11 @@ internal class PropertyAdapter(
.setSingleChoiceItems(
items, items.indexOf(getValue())
) { dialog, item ->
- setValue(enumValues.first {
- it.name == items[item].toUpperCase()
- })
+ setValue(
+ enumValues.first {
+ it.name == items[item].toUpperCase()
+ }
+ )
dialog.dismiss()
}
.show()
@@ -288,12 +289,14 @@ internal class PropertyAdapter(
.setSingleChoiceItems(
interpolatorNames, interpolatorNames.indexOf(getValue())
) { dialog, item ->
- setValue(InterpolatorProperty.interpolators.first {
- it::class.java.simpleName == interpolatorNames[item]
- })
+ setValue(
+ InterpolatorProperty.interpolators.first {
+ it::class.java.simpleName == interpolatorNames[item]
+ }
+ )
dialog.dismiss()
}
.show()
}
}
-}
\ No newline at end of file
+}
diff --git a/demo/src/main/java/nl/joery/demo/animatedbottombar/playground/XmlGenerator.kt b/demo/src/main/java/nl/joery/demo/animatedbottombar/playground/XmlGenerator.kt
index ad92e1b..d00c114 100644
--- a/demo/src/main/java/nl/joery/demo/animatedbottombar/playground/XmlGenerator.kt
+++ b/demo/src/main/java/nl/joery/demo/animatedbottombar/playground/XmlGenerator.kt
@@ -84,4 +84,4 @@ object XmlGenerator {
private fun coloredText(text: String, color: String): String {
return "$text"
}
-}
\ No newline at end of file
+}
diff --git a/demo/src/main/java/nl/joery/demo/animatedbottombar/playground/properties/BooleanProperty.kt b/demo/src/main/java/nl/joery/demo/animatedbottombar/playground/properties/BooleanProperty.kt
index f233c9e..1a2bac0 100644
--- a/demo/src/main/java/nl/joery/demo/animatedbottombar/playground/properties/BooleanProperty.kt
+++ b/demo/src/main/java/nl/joery/demo/animatedbottombar/playground/properties/BooleanProperty.kt
@@ -1,4 +1,3 @@
package nl.joery.demo.animatedbottombar.playground.properties
-
-class BooleanProperty(name: String) : Property(name)
\ No newline at end of file
+class BooleanProperty(name: String) : Property(name)
diff --git a/demo/src/main/java/nl/joery/demo/animatedbottombar/playground/properties/CategoryProperty.kt b/demo/src/main/java/nl/joery/demo/animatedbottombar/playground/properties/CategoryProperty.kt
index 67ac38f..511985d 100644
--- a/demo/src/main/java/nl/joery/demo/animatedbottombar/playground/properties/CategoryProperty.kt
+++ b/demo/src/main/java/nl/joery/demo/animatedbottombar/playground/properties/CategoryProperty.kt
@@ -1,4 +1,3 @@
package nl.joery.demo.animatedbottombar.playground.properties
-
-class CategoryProperty(name: String) : Property(name)
\ No newline at end of file
+class CategoryProperty(name: String) : Property(name)
diff --git a/demo/src/main/java/nl/joery/demo/animatedbottombar/playground/properties/ColorProperty.kt b/demo/src/main/java/nl/joery/demo/animatedbottombar/playground/properties/ColorProperty.kt
index 1d1f287..4177cb1 100644
--- a/demo/src/main/java/nl/joery/demo/animatedbottombar/playground/properties/ColorProperty.kt
+++ b/demo/src/main/java/nl/joery/demo/animatedbottombar/playground/properties/ColorProperty.kt
@@ -1,4 +1,3 @@
package nl.joery.demo.animatedbottombar.playground.properties
-
-class ColorProperty(name: String) : Property(name)
\ No newline at end of file
+class ColorProperty(name: String) : Property(name)
diff --git a/demo/src/main/java/nl/joery/demo/animatedbottombar/playground/properties/EnumProperty.kt b/demo/src/main/java/nl/joery/demo/animatedbottombar/playground/properties/EnumProperty.kt
index 4248d28..32f165a 100644
--- a/demo/src/main/java/nl/joery/demo/animatedbottombar/playground/properties/EnumProperty.kt
+++ b/demo/src/main/java/nl/joery/demo/animatedbottombar/playground/properties/EnumProperty.kt
@@ -1,4 +1,3 @@
package nl.joery.demo.animatedbottombar.playground.properties
-
-class EnumProperty(name: String, val enumClass: Class<*>) : Property(name)
\ No newline at end of file
+class EnumProperty(name: String, val enumClass: Class<*>) : Property(name)
diff --git a/demo/src/main/java/nl/joery/demo/animatedbottombar/playground/properties/IntegerProperty.kt b/demo/src/main/java/nl/joery/demo/animatedbottombar/playground/properties/IntegerProperty.kt
index 422dac3..ec0caeb 100644
--- a/demo/src/main/java/nl/joery/demo/animatedbottombar/playground/properties/IntegerProperty.kt
+++ b/demo/src/main/java/nl/joery/demo/animatedbottombar/playground/properties/IntegerProperty.kt
@@ -2,5 +2,4 @@ package nl.joery.demo.animatedbottombar.playground.properties
import android.util.TypedValue
-
-class IntegerProperty(name: String, val density: Int = TypedValue.DENSITY_NONE) : Property(name)
\ No newline at end of file
+class IntegerProperty(name: String, val density: Int = TypedValue.DENSITY_NONE) : Property(name)
diff --git a/demo/src/main/java/nl/joery/demo/animatedbottombar/playground/properties/InterpolatorProperty.kt b/demo/src/main/java/nl/joery/demo/animatedbottombar/playground/properties/InterpolatorProperty.kt
index 4bbdc7a..6c307a8 100644
--- a/demo/src/main/java/nl/joery/demo/animatedbottombar/playground/properties/InterpolatorProperty.kt
+++ b/demo/src/main/java/nl/joery/demo/animatedbottombar/playground/properties/InterpolatorProperty.kt
@@ -3,7 +3,6 @@ package nl.joery.demo.animatedbottombar.playground.properties
import android.view.animation.*
import androidx.interpolator.view.animation.FastOutSlowInInterpolator
-
class InterpolatorProperty(name: String) : Property(name) {
companion object {
val interpolators: List by lazy {
@@ -20,4 +19,4 @@ class InterpolatorProperty(name: String) : Property(name) {
}
}
}
-}
\ No newline at end of file
+}
diff --git a/demo/src/main/java/nl/joery/demo/animatedbottombar/playground/properties/Property.kt b/demo/src/main/java/nl/joery/demo/animatedbottombar/playground/properties/Property.kt
index 9e99f27..38a14da 100644
--- a/demo/src/main/java/nl/joery/demo/animatedbottombar/playground/properties/Property.kt
+++ b/demo/src/main/java/nl/joery/demo/animatedbottombar/playground/properties/Property.kt
@@ -11,4 +11,4 @@ abstract class Property(val name: String) {
const val TYPE_INTERPOLATOR = 5
const val TYPE_CATEGORY = 6
}
-}
\ No newline at end of file
+}
diff --git a/demo/src/main/java/nl/joery/demo/animatedbottombar/viewpager/SampleFragment.kt b/demo/src/main/java/nl/joery/demo/animatedbottombar/viewpager/SampleFragment.kt
index f266e38..559bc54 100644
--- a/demo/src/main/java/nl/joery/demo/animatedbottombar/viewpager/SampleFragment.kt
+++ b/demo/src/main/java/nl/joery/demo/animatedbottombar/viewpager/SampleFragment.kt
@@ -8,7 +8,6 @@ import androidx.fragment.app.Fragment
import kotlinx.android.synthetic.main.fragment_sample.*
import nl.joery.demo.animatedbottombar.R
-
class SampleFragment : Fragment() {
companion object {
fun newInstance(position: Int): SampleFragment {
@@ -33,4 +32,4 @@ class SampleFragment : Fragment() {
val position = arguments?.getInt("position", -1) ?: -1
text_content.text = getString(R.string.sample_fragment_content, position)
}
-}
\ No newline at end of file
+}
diff --git a/demo/src/main/java/nl/joery/demo/animatedbottombar/viewpager/ViewPagerActivity.kt b/demo/src/main/java/nl/joery/demo/animatedbottombar/viewpager/ViewPagerActivity.kt
index 1ef999c..3b07804 100644
--- a/demo/src/main/java/nl/joery/demo/animatedbottombar/viewpager/ViewPagerActivity.kt
+++ b/demo/src/main/java/nl/joery/demo/animatedbottombar/viewpager/ViewPagerActivity.kt
@@ -10,7 +10,6 @@ import androidx.viewpager2.adapter.FragmentStateAdapter
import kotlinx.android.synthetic.main.activity_view_pager.*
import nl.joery.demo.animatedbottombar.R
-
class ViewPagerActivity : FragmentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@@ -62,4 +61,4 @@ class ViewPagerActivity : FragmentActivity() {
return SampleFragment.newInstance(position)
}
}
-}
\ No newline at end of file
+}
diff --git a/demo/src/main/res/layout/activity_bottom_sheet.xml b/demo/src/main/res/layout/activity_bottom_sheet.xml
index 3ff9f56..6938bc1 100644
--- a/demo/src/main/res/layout/activity_bottom_sheet.xml
+++ b/demo/src/main/res/layout/activity_bottom_sheet.xml
@@ -12,7 +12,7 @@
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/holo_purple"
- android:orientation="horizontal"/>
+ android:orientation="horizontal" />
+ app:abb_tabs="@menu/clock_tabs" />
+
= 0 && index < adapter.tabs.size) {
+ if (index >= 0 && index < adapter.tabs.size) {
selectTabAt(index, false)
}
} else {
@@ -363,11 +368,10 @@ class AnimatedBottomBar @JvmOverloads constructor(
throw IllegalArgumentException("Icon drawable cannot be null.")
}
- if(iconSize < -1 || iconSize == 0) {
+ if (iconSize < -1 || iconSize == 0) {
throw IllegalArgumentException("iconSize should be either -1 or positive value")
}
-
return Tab(icon, iconSize, title, id)
}
@@ -380,7 +384,12 @@ class AnimatedBottomBar @JvmOverloads constructor(
* Unlike [AnimatedBottomBar.iconSize], sets size of icon only for this tab.
* Should be either -1 to use [AnimatedBottomBar.iconSize] or positive value
*/
- fun createTab(@DrawableRes iconRes: Int, title: String, @IdRes id: Int = -1, iconSize: Int = -1): Tab {
+ fun createTab(
+ @DrawableRes iconRes: Int,
+ title: String,
+ @IdRes id: Int = -1,
+ iconSize: Int = -1
+ ): Tab {
val icon = ContextCompat.getDrawable(context, iconRes)
return createTab(icon, title, id, iconSize)
}
@@ -395,7 +404,12 @@ class AnimatedBottomBar @JvmOverloads constructor(
* Unlike [AnimatedBottomBar.iconSize], sets size of icon only for this tab.
* Should be either -1 to use [AnimatedBottomBar.iconSize] or positive value
*/
- fun createTab(@DrawableRes iconRes: Int, @StringRes titleRes: Int, @IdRes id: Int = -1, iconSize: Int = -1): Tab {
+ fun createTab(
+ @DrawableRes iconRes: Int,
+ @StringRes titleRes: Int,
+ @IdRes id: Int = -1,
+ iconSize: Int = -1
+ ): Tab {
val title = context.getString(titleRes)
return createTab(iconRes, title, id, iconSize)
}
@@ -457,7 +471,7 @@ class AnimatedBottomBar @JvmOverloads constructor(
*/
fun removeTabById(@IdRes id: Int) {
val tabIndex = indexOfTabWithId(id)
- if(tabIndex < 0) {
+ if (tabIndex < 0) {
throw IllegalArgumentException("Tab with id $id does not exist.")
}
@@ -493,7 +507,7 @@ class AnimatedBottomBar @JvmOverloads constructor(
*/
fun selectTabById(@IdRes id: Int, animate: Boolean = true) {
val tabIndex = indexOfTabWithId(id)
- if(tabIndex < 0) {
+ if (tabIndex < 0) {
throw IllegalArgumentException("Tab with id $id does not exist.")
}
adapter.selectTabAt(tabIndex, animate)
@@ -537,7 +551,7 @@ class AnimatedBottomBar @JvmOverloads constructor(
*/
fun setTabEnabledById(@IdRes id: Int, enabled: Boolean) {
val index = indexOfTabWithId(id)
- if(index < 0) {
+ if (index < 0) {
throw IllegalArgumentException("Tab with id $id does not exist.")
}
@@ -579,7 +593,7 @@ class AnimatedBottomBar @JvmOverloads constructor(
*/
fun setBadgeAtTabId(@IdRes id: Int, badge: Badge? = null) {
val index = indexOfTabWithId(id)
- if(index >= 0) {
+ if (index >= 0) {
throw IllegalArgumentException("Tab with id $id does not exist.")
}
setBadgeAtTabIndex(index, badge)
@@ -618,7 +632,7 @@ class AnimatedBottomBar @JvmOverloads constructor(
*/
fun clearBadgeAtTabId(@IdRes id: Int) {
val index = indexOfTabWithId(id)
- if(index < 0) {
+ if (index < 0) {
throw IllegalArgumentException("Tab with id $id does not exist.")
}
clearBadgeAtTabIndex(index)
@@ -641,7 +655,7 @@ class AnimatedBottomBar @JvmOverloads constructor(
* @param iconSize Should be either -1 (to use [AnimatedBottomBar.iconSize] value) or positive value.
*/
fun setIconSizeAtTab(tab: Tab, iconSize: Int) {
- if(iconSize < -1 || iconSize == 0) {
+ if (iconSize < -1 || iconSize == 0) {
throw IllegalArgumentException("iconSize should be either -1 or positive value.")
}
@@ -656,11 +670,11 @@ class AnimatedBottomBar @JvmOverloads constructor(
* @param iconSize Should be either -1 (to use [AnimatedBottomBar.iconSize] value) or positive value.
*/
fun setIconSizeAtTabIndex(tabIndex: Int, iconSize: Int) {
- if(tabIndex < 0 || tabIndex >= adapter.tabs.size) {
+ if (tabIndex < 0 || tabIndex >= adapter.tabs.size) {
throw IllegalArgumentException("Tab index is out of bounds.")
}
- if(iconSize < -1 || iconSize == 0) {
+ if (iconSize < -1 || iconSize == 0) {
throw IllegalArgumentException("iconSize should be either -1 or positive value.")
}
@@ -676,7 +690,7 @@ class AnimatedBottomBar @JvmOverloads constructor(
*/
fun setIconSizeAtTabId(@IdRes id: Int, iconSize: Int) {
val index = indexOfTabWithId(id)
- if(index < 0) {
+ if (index < 0) {
throw IllegalArgumentException("Tab with id $id does not exist.")
}
@@ -707,12 +721,12 @@ class AnimatedBottomBar @JvmOverloads constructor(
override fun onPageScrollStateChanged(state: Int) {
// Use Scroll state to detect whether the user is sliding
- if (previousState == ViewPager.SCROLL_STATE_DRAGGING
- && state == ViewPager.SCROLL_STATE_SETTLING
+ if (previousState == ViewPager.SCROLL_STATE_DRAGGING &&
+ state == ViewPager.SCROLL_STATE_SETTLING
) {
userScrollChange = true
- } else if (previousState == ViewPager.SCROLL_STATE_SETTLING
- && state == ViewPager.SCROLL_STATE_IDLE
+ } else if (previousState == ViewPager.SCROLL_STATE_SETTLING &&
+ state == ViewPager.SCROLL_STATE_IDLE
) {
userScrollChange = false
}
@@ -753,12 +767,12 @@ class AnimatedBottomBar @JvmOverloads constructor(
override fun onPageScrollStateChanged(state: Int) {
super.onPageScrollStateChanged(state)
// Use Scroll state to detect whether the user is sliding
- if (previousState == ViewPager2.SCROLL_STATE_DRAGGING
- && state == ViewPager2.SCROLL_STATE_SETTLING
+ if (previousState == ViewPager2.SCROLL_STATE_DRAGGING &&
+ state == ViewPager2.SCROLL_STATE_SETTLING
) {
userScrollChange = true
- } else if (previousState == ViewPager2.SCROLL_STATE_SETTLING
- && state == ViewPager2.SCROLL_STATE_IDLE
+ } else if (previousState == ViewPager2.SCROLL_STATE_SETTLING &&
+ state == ViewPager2.SCROLL_STATE_IDLE
) {
userScrollChange = false
}
@@ -788,8 +802,8 @@ class AnimatedBottomBar @JvmOverloads constructor(
private fun indexOfTabWithId(@IdRes id: Int): Int {
val tabs = adapter.tabs
- for(i in tabs.indices) {
- if(tabs[i].id == id) {
+ for (i in tabs.indices) {
+ if (tabs[i].id == id) {
return i
}
}
@@ -866,7 +880,6 @@ class AnimatedBottomBar @JvmOverloads constructor(
animationInterpolator = AnimationUtils.loadInterpolator(context, value)
}
-
var rippleEnabled
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
get() = tabStyle.rippleEnabled
@@ -894,7 +907,6 @@ class AnimatedBottomBar @JvmOverloads constructor(
rippleColor = ContextCompat.getColor(context, value)
}
-
var tabColorSelected
@ColorInt
get() = tabStyle.tabColorSelected
@@ -1194,4 +1206,4 @@ class AnimatedBottomBar @JvmOverloads constructor(
interface OnTabInterceptListener {
fun onTabIntercepted(lastIndex: Int, lastTab: Tab?, newIndex: Int, newTab: Tab): Boolean
}
-}
\ No newline at end of file
+}
diff --git a/library/src/main/java/nl/joery/animatedbottombar/BadgeView.kt b/library/src/main/java/nl/joery/animatedbottombar/BadgeView.kt
index 6520fc6..6c566db 100644
--- a/library/src/main/java/nl/joery/animatedbottombar/BadgeView.kt
+++ b/library/src/main/java/nl/joery/animatedbottombar/BadgeView.kt
@@ -4,7 +4,6 @@ import android.animation.Animator
import android.animation.ValueAnimator
import android.content.Context
import android.graphics.*
-import android.os.Build
import android.text.TextPaint
import android.util.AttributeSet
import android.view.View
@@ -14,7 +13,9 @@ import nl.joery.animatedbottombar.utils.dpPx
import kotlin.math.max
class BadgeView @JvmOverloads constructor(
- context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
+ context: Context,
+ attrs: AttributeSet? = null,
+ defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr) {
private val backgroundPaint = Paint(Paint.ANTI_ALIAS_FLAG or Paint.DITHER_FLAG)
private val textPaint = TextPaint(Paint.ANTI_ALIAS_FLAG or Paint.DITHER_FLAG).apply {
@@ -142,18 +143,18 @@ class BadgeView @JvmOverloads constructor(
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
val textWidth = if (text == null) 0f else textPaint.measureText(text)
val newWidth =
- max(textWidth.toInt() + horizontalPadding, 16.dpPx) + paddingLeft + paddingRight
+ max(textWidth.toInt() + horizontalPadding, 16.dpPx) + paddingLeft + paddingRight
val newHeight = 16.dpPx + paddingTop + paddingBottom
if (animationType == AnimatedBottomBar.BadgeAnimation.SCALE) {
super.onMeasure(
- MeasureSpec.makeMeasureSpec((newWidth * fraction).toInt(), MeasureSpec.EXACTLY),
- MeasureSpec.makeMeasureSpec((newHeight * fraction).toInt(), MeasureSpec.EXACTLY)
+ MeasureSpec.makeMeasureSpec((newWidth * fraction).toInt(), MeasureSpec.EXACTLY),
+ MeasureSpec.makeMeasureSpec((newHeight * fraction).toInt(), MeasureSpec.EXACTLY)
)
} else {
super.onMeasure(
- MeasureSpec.makeMeasureSpec(newWidth, MeasureSpec.EXACTLY),
- MeasureSpec.makeMeasureSpec(newHeight, MeasureSpec.EXACTLY)
+ MeasureSpec.makeMeasureSpec(newWidth, MeasureSpec.EXACTLY),
+ MeasureSpec.makeMeasureSpec(newHeight, MeasureSpec.EXACTLY)
)
}
}
@@ -171,10 +172,10 @@ class BadgeView @JvmOverloads constructor(
}
canvas.drawCircle(
- middleX,
- middleY,
- 4.dpPx.toFloat(),
- backgroundPaint
+ middleX,
+ middleY,
+ 4.dpPx.toFloat(),
+ backgroundPaint
)
if (animationType == AnimatedBottomBar.BadgeAnimation.SCALE) {
@@ -234,7 +235,7 @@ class BadgeView @JvmOverloads constructor(
animator.run {
duration = _animationDuration.toLong()
- if(isEnabled) {
+ if (isEnabled) {
start()
} else {
reverse()
@@ -263,4 +264,4 @@ class BadgeView @JvmOverloads constructor(
return fraction
}
-}
\ No newline at end of file
+}
diff --git a/library/src/main/java/nl/joery/animatedbottombar/BottomBarStyle.kt b/library/src/main/java/nl/joery/animatedbottombar/BottomBarStyle.kt
index 228159a..c4d7709 100644
--- a/library/src/main/java/nl/joery/animatedbottombar/BottomBarStyle.kt
+++ b/library/src/main/java/nl/joery/animatedbottombar/BottomBarStyle.kt
@@ -68,4 +68,4 @@ object BottomBarStyle {
ICON,
BADGE
}
-}
\ No newline at end of file
+}
diff --git a/library/src/main/java/nl/joery/animatedbottombar/NoCopyArrayList.kt b/library/src/main/java/nl/joery/animatedbottombar/NoCopyArrayList.kt
index a27d700..2ee1ee9 100644
--- a/library/src/main/java/nl/joery/animatedbottombar/NoCopyArrayList.kt
+++ b/library/src/main/java/nl/joery/animatedbottombar/NoCopyArrayList.kt
@@ -1,6 +1,6 @@
package nl.joery.animatedbottombar
-internal class NoCopyArrayList(private val data: Array): AbstractList() {
+internal class NoCopyArrayList(private val data: Array) : AbstractList() {
override val size: Int
get() = data.size
@@ -25,8 +25,8 @@ internal class NoCopyArrayList(private val data: Array): AbstractList<
override fun toArray(): Array = data as Array
override fun equals(other: Any?): Boolean {
- if(other === this) return true
- if(other == null || javaClass !== other.javaClass) return false
+ if (other === this) return true
+ if (other == null || javaClass !== other.javaClass) return false
other as NoCopyArrayList<*>
@@ -41,10 +41,10 @@ internal class NoCopyArrayList(private val data: Array): AbstractList<
return data.contentToString()
}
- private class IteratorImpl(private val data: Array): Iterator {
+ private class IteratorImpl(private val data: Array) : Iterator {
private var index = 0
override fun hasNext(): Boolean = index < data.size
override fun next(): T = data[index]
}
-}
\ No newline at end of file
+}
diff --git a/library/src/main/java/nl/joery/animatedbottombar/SavedState.kt b/library/src/main/java/nl/joery/animatedbottombar/SavedState.kt
index 6098e44..78ef25f 100644
--- a/library/src/main/java/nl/joery/animatedbottombar/SavedState.kt
+++ b/library/src/main/java/nl/joery/animatedbottombar/SavedState.kt
@@ -4,14 +4,14 @@ import android.os.Parcel
import android.os.Parcelable
import android.view.View
-internal class SavedState: View.BaseSavedState {
+internal class SavedState : View.BaseSavedState {
var selectedIndex: Int = 0
- constructor(source: Parcel): super(source) {
+ constructor(source: Parcel) : super(source) {
selectedIndex = source.readInt()
}
- constructor(superState: Parcelable?): super(superState)
+ constructor(superState: Parcelable?) : super(superState)
override fun writeToParcel(out: Parcel, flags: Int) {
super.writeToParcel(out, flags)
@@ -20,9 +20,9 @@ internal class SavedState: View.BaseSavedState {
companion object {
@JvmField
- val CREATOR = object: Parcelable.Creator {
+ val CREATOR = object : Parcelable.Creator {
override fun createFromParcel(source: Parcel) = SavedState(source)
override fun newArray(size: Int) = arrayOfNulls(size)
}
}
-}
\ No newline at end of file
+}
diff --git a/library/src/main/java/nl/joery/animatedbottombar/TabAdapter.kt b/library/src/main/java/nl/joery/animatedbottombar/TabAdapter.kt
index f28f6b4..3edb9d1 100644
--- a/library/src/main/java/nl/joery/animatedbottombar/TabAdapter.kt
+++ b/library/src/main/java/nl/joery/animatedbottombar/TabAdapter.kt
@@ -86,7 +86,7 @@ internal class TabAdapter(
fun addTabs(values: Collection, tabIndex: Int = -1) {
val startIndex: Int
- if(tabIndex == -1) {
+ if (tabIndex == -1) {
startIndex = tabs.size
tabs.addAll(values)
} else {
@@ -99,7 +99,7 @@ internal class TabAdapter(
fun removeTab(tab: AnimatedBottomBar.Tab) {
val index = tabs.indexOf(tab)
- if(index < 0) {
+ if (index < 0) {
return
}
removeTabAt(index)
@@ -117,7 +117,7 @@ internal class TabAdapter(
fun selectTab(tab: AnimatedBottomBar.Tab, animate: Boolean) {
val index = tabs.indexOf(tab)
- if(index >= 0) {
+ if (index >= 0) {
selectTabAt(index, animate)
}
}
@@ -171,7 +171,7 @@ internal class TabAdapter(
fun applyTabBadge(tab: AnimatedBottomBar.Tab, badge: AnimatedBottomBar.Badge?) {
val index = tabs.indexOf(tab)
- if(index >= 0) {
+ if (index >= 0) {
applyTabBadgeAt(index, badge)
}
}
@@ -197,7 +197,7 @@ internal class TabAdapter(
fun applyIconSize(tab: AnimatedBottomBar.Tab, iconSize: Int) {
val index = tabs.indexOf(tab)
- if(index >= 0) {
+ if (index >= 0) {
applyIconSize(index, iconSize)
}
}
@@ -268,4 +268,4 @@ internal class TabAdapter(
private const val PAYLOAD_DESELECT = 3
private const val PAYLOAD_APPLY_ICON_SIZE = 4
}
-}
\ No newline at end of file
+}
diff --git a/library/src/main/java/nl/joery/animatedbottombar/TabIndicator.kt b/library/src/main/java/nl/joery/animatedbottombar/TabIndicator.kt
index 473ccb2..fcbbb3f 100644
--- a/library/src/main/java/nl/joery/animatedbottombar/TabIndicator.kt
+++ b/library/src/main/java/nl/joery/animatedbottombar/TabIndicator.kt
@@ -52,7 +52,7 @@ internal class TabIndicator(
var currentWidth = newViewWidth
- when(bottomBar.indicatorAnimation) {
+ when (bottomBar.indicatorAnimation) {
AnimatedBottomBar.IndicatorAnimation.SLIDE -> {
if (isAnimating && lastView != null) {
val lastViewWidth = lastView.width.toFloat()
@@ -97,14 +97,14 @@ internal class TabIndicator(
val indicatorLeft = viewLeft + indicatorMargin
val indicatorRight = viewLeft + viewWidth - indicatorMargin
- val indicatorHeight = bottomBar.indicatorStyle.indicatorHeight.toFloat()
+ val indicatorHeight = bottomBar.indicatorStyle.indicatorHeight.toFloat()
- when(bottomBar.indicatorStyle.indicatorAppearance) {
+ when (bottomBar.indicatorStyle.indicatorAppearance) {
AnimatedBottomBar.IndicatorAppearance.SQUARE -> {
val top: Float
val bottom: Float
- when(bottomBar.indicatorStyle.indicatorLocation) {
+ when (bottomBar.indicatorStyle.indicatorLocation) {
AnimatedBottomBar.IndicatorLocation.TOP -> {
top = 0f
bottom = indicatorHeight
@@ -128,7 +128,7 @@ internal class TabIndicator(
val top: Float
val bottom: Float
- when(bottomBar.indicatorStyle.indicatorLocation) {
+ when (bottomBar.indicatorStyle.indicatorLocation) {
AnimatedBottomBar.IndicatorLocation.TOP -> {
top = -indicatorHeight
bottom = indicatorHeight
@@ -186,8 +186,8 @@ internal class TabIndicator(
}
companion object {
- private val CURRENT_LEFT_PROPERTY = if(Build.VERSION.SDK_INT >= 24) {
- object: FloatProperty("currentLeft") {
+ private val CURRENT_LEFT_PROPERTY = if (Build.VERSION.SDK_INT >= 24) {
+ object : FloatProperty("currentLeft") {
override fun get(o: TabIndicator): Float = o.currentLeft
override fun setValue(o: TabIndicator, value: Float) {
o.currentLeft = value
@@ -195,7 +195,7 @@ internal class TabIndicator(
}
}
} else {
- object: Property(Float::class.java, "currentLeft") {
+ object : Property(Float::class.java, "currentLeft") {
override fun get(o: TabIndicator): Float = o.currentLeft
override fun set(o: TabIndicator, value: Float) {
o.currentLeft = value
@@ -204,4 +204,4 @@ internal class TabIndicator(
}
}
}
-}
\ No newline at end of file
+}
diff --git a/library/src/main/java/nl/joery/animatedbottombar/TabView.kt b/library/src/main/java/nl/joery/animatedbottombar/TabView.kt
index 955895a..18831ff 100644
--- a/library/src/main/java/nl/joery/animatedbottombar/TabView.kt
+++ b/library/src/main/java/nl/joery/animatedbottombar/TabView.kt
@@ -116,83 +116,95 @@ internal class TabView @JvmOverloads constructor(
}
private fun initLayout() {
- addView(LinearLayout(context).apply {
- layoutParams = LayoutParams(
- LayoutParams.MATCH_PARENT,
- LayoutParams.WRAP_CONTENT
- ).apply {
+ addView(
+ LinearLayout(context).apply {
+ layoutParams = LayoutParams(
+ LayoutParams.MATCH_PARENT,
+ LayoutParams.WRAP_CONTENT
+ ).apply {
+ gravity = Gravity.CENTER
+ }
gravity = Gravity.CENTER
- }
- gravity = Gravity.CENTER
- orientation = LinearLayout.HORIZONTAL
+ orientation = LinearLayout.HORIZONTAL
+
+ textLayout = this
- textLayout = this
+ addView(
+ AppCompatTextView(context).apply {
+ layoutParams = LinearLayout.LayoutParams(
+ LinearLayout.LayoutParams.WRAP_CONTENT,
+ LinearLayout.LayoutParams.WRAP_CONTENT
+ )
- addView(AppCompatTextView(context).apply {
- layoutParams = LinearLayout.LayoutParams(
- LinearLayout.LayoutParams.WRAP_CONTENT,
- LinearLayout.LayoutParams.WRAP_CONTENT
+ textView = this
+ ellipsize = TextUtils.TruncateAt.END
+ isSingleLine = true
+ }
)
- textView = this
- ellipsize = TextUtils.TruncateAt.END
- isSingleLine = true
- })
+ addView(
+ BadgeView(context).apply {
+ layoutParams = LinearLayout.LayoutParams(
+ LinearLayout.LayoutParams.WRAP_CONTENT,
+ LinearLayout.LayoutParams.WRAP_CONTENT
+ )
- addView(BadgeView(context).apply {
- layoutParams = LinearLayout.LayoutParams(
- LinearLayout.LayoutParams.WRAP_CONTENT,
- LinearLayout.LayoutParams.WRAP_CONTENT
+ textBadge = this
+ val padding = 4.dpPx
+ setPadding(padding, 0, 0, 0)
+ }
)
-
- textBadge = this
- val padding = 4.dpPx
- setPadding(padding, 0, 0, 0)
- })
- })
-
- addView(LinearLayout(context).apply {
- layoutParams = LayoutParams(
- LayoutParams.WRAP_CONTENT,
- LayoutParams.WRAP_CONTENT
- ).apply {
- gravity = Gravity.CENTER
}
+ )
- iconLayout = this
-
- val padding = 8.dpPx
- setPadding(0, padding, 0, padding)
-
- clipToPadding = false
- visibility = View.GONE
-
- addView(AppCompatImageView(context).apply {
- layoutParams = LinearLayout.LayoutParams(
- LinearLayout.LayoutParams.WRAP_CONTENT,
- LinearLayout.LayoutParams.WRAP_CONTENT,
+ addView(
+ LinearLayout(context).apply {
+ layoutParams = LayoutParams(
+ LayoutParams.WRAP_CONTENT,
+ LayoutParams.WRAP_CONTENT
).apply {
gravity = Gravity.CENTER
}
- orientation = LinearLayout.HORIZONTAL
- iconView = this
- scaleType = ImageView.ScaleType.FIT_CENTER
- })
-
- addView(BadgeView(context).apply {
- layoutParams = LinearLayout.LayoutParams(
- LinearLayout.LayoutParams.WRAP_CONTENT,
- LinearLayout.LayoutParams.WRAP_CONTENT
+ iconLayout = this
+
+ val padding = 8.dpPx
+ setPadding(0, padding, 0, padding)
+
+ clipToPadding = false
+ visibility = View.GONE
+
+ addView(
+ AppCompatImageView(context).apply {
+ layoutParams = LinearLayout.LayoutParams(
+ LinearLayout.LayoutParams.WRAP_CONTENT,
+ LinearLayout.LayoutParams.WRAP_CONTENT,
+ ).apply {
+ gravity = Gravity.CENTER
+ }
+
+ orientation = LinearLayout.HORIZONTAL
+ iconView = this
+ scaleType = ImageView.ScaleType.FIT_CENTER
+ }
)
- val translation = (-8).dpPx.toFloat()
- translationX = translation
- translationY = translation
+ addView(
+ BadgeView(context).apply {
+ layoutParams = LinearLayout.LayoutParams(
+ LinearLayout.LayoutParams.WRAP_CONTENT,
+ LinearLayout.LayoutParams.WRAP_CONTENT
+ )
+
+ val translation = (-8).dpPx.toFloat()
+ translationX = translation
+ translationY = translation
- iconBadge = this
- })
- })
+ iconBadge = this
+ }
+ )
+ }
+ )
}
fun applyStyle(style: BottomBarStyle.Tab) {
@@ -241,7 +253,7 @@ internal class TabView @JvmOverloads constructor(
val tabColor: Int
val tabColorSelected: Int
- if(isEnabled) {
+ if (isEnabled) {
tabColor = style.tabColor
tabColorSelected = style.tabColorSelected
} else {
@@ -252,7 +264,7 @@ internal class TabView @JvmOverloads constructor(
val iconTint: Int
val textColor: Int
- when(style.selectedTabType) {
+ when (style.selectedTabType) {
AnimatedBottomBar.TabType.ICON -> {
iconTint = tabColorSelected
textColor = tabColor
@@ -296,7 +308,7 @@ internal class TabView @JvmOverloads constructor(
}
private fun updateIcon() {
- val size = if(iconSize > 0) iconSize else style.iconSize
+ val size = if (iconSize > 0) iconSize else style.iconSize
iconView.run {
layoutParams = layoutParams.apply {
@@ -405,7 +417,7 @@ internal class TabView @JvmOverloads constructor(
val valueTo: Float
val animationType = if (selected) style.tabAnimationSelected else style.tabAnimation
- when(animationType) {
+ when (animationType) {
AnimatedBottomBar.TabAnimation.SLIDE -> {
if (selected) {
valueFrom = when {
@@ -466,7 +478,7 @@ internal class TabView @JvmOverloads constructor(
crossinline onStart: () -> Unit = {},
crossinline onEnd: () -> Unit = {}
): Animation.AnimationListener {
- return object: Animation.AnimationListener {
+ return object : Animation.AnimationListener {
override fun onAnimationStart(animation: Animation?) {
onStart()
}
@@ -480,4 +492,4 @@ internal class TabView @JvmOverloads constructor(
}
}
}
-}
\ No newline at end of file
+}
diff --git a/library/src/main/java/nl/joery/animatedbottombar/utils/Extensions.kt b/library/src/main/java/nl/joery/animatedbottombar/utils/Extensions.kt
index 44c1bc6..3267587 100644
--- a/library/src/main/java/nl/joery/animatedbottombar/utils/Extensions.kt
+++ b/library/src/main/java/nl/joery/animatedbottombar/utils/Extensions.kt
@@ -23,7 +23,8 @@ internal fun Context.getTextColor(@AttrRes id: Int): Int {
val typedValue = TypedValue()
theme.resolveAttribute(id, typedValue, true)
val arr = obtainStyledAttributes(
- typedValue.data, intArrayOf(
+ typedValue.data,
+ intArrayOf(
id
)
)
@@ -49,4 +50,4 @@ internal val Int.dpPx: Int
get() = (this * Resources.getSystem().displayMetrics.density).roundToInt()
internal val Int.spPx: Int
- get() = (this * Resources.getSystem().displayMetrics.scaledDensity).roundToInt()
\ No newline at end of file
+ get() = (this * Resources.getSystem().displayMetrics.scaledDensity).roundToInt()
diff --git a/library/src/main/java/nl/joery/animatedbottombar/utils/MenuParser.kt b/library/src/main/java/nl/joery/animatedbottombar/utils/MenuParser.kt
index 68c1518..2375405 100644
--- a/library/src/main/java/nl/joery/animatedbottombar/utils/MenuParser.kt
+++ b/library/src/main/java/nl/joery/animatedbottombar/utils/MenuParser.kt
@@ -5,13 +5,14 @@ import android.os.Build
import android.view.MenuInflater
import android.widget.PopupMenu
import androidx.annotation.MenuRes
-import androidx.core.view.iterator
import nl.joery.animatedbottombar.AnimatedBottomBar
-import nl.joery.animatedbottombar.NoCopyArrayList
-
internal object MenuParser {
- fun parse(context: Context, @MenuRes resId: Int, exception: Boolean): Array {
+ fun parse(
+ context: Context,
+ @MenuRes resId: Int,
+ exception: Boolean
+ ): Array {
val p = PopupMenu(context, null)
MenuInflater(context).inflate(resId, p.menu)
val menu = p.menu
@@ -41,4 +42,4 @@ internal object MenuParser {
)
}
}
-}
\ No newline at end of file
+}
diff --git a/library/src/main/java/nl/joery/animatedbottombar/utils/NavigationComponentHelper.kt b/library/src/main/java/nl/joery/animatedbottombar/utils/NavigationComponentHelper.kt
index 7831dd8..0f6d047 100644
--- a/library/src/main/java/nl/joery/animatedbottombar/utils/NavigationComponentHelper.kt
+++ b/library/src/main/java/nl/joery/animatedbottombar/utils/NavigationComponentHelper.kt
@@ -35,29 +35,29 @@ internal object NavigationComponentHelper {
val weakReference = WeakReference(bottomBar)
navController.addOnDestinationChangedListener(object :
- NavController.OnDestinationChangedListener {
+ NavController.OnDestinationChangedListener {
- override fun onDestinationChanged(
- controller: NavController,
- destination: NavDestination,
- arguments: Bundle?
- ) {
- val view = weakReference.get()
+ override fun onDestinationChanged(
+ controller: NavController,
+ destination: NavDestination,
+ arguments: Bundle?
+ ) {
+ val view = weakReference.get()
- if (view == null) {
- navController.removeOnDestinationChangedListener(this)
- return
- }
+ if (view == null) {
+ navController.removeOnDestinationChangedListener(this)
+ return
+ }
- for (h in 0 until menu.size()) {
- val menuItem = menu.getItem(h)
- if (matchDestination(destination, menuItem.itemId)) {
- menuItem.isChecked = true
- bottomBar.selectTabAt(h)
+ for (h in 0 until menu.size()) {
+ val menuItem = menu.getItem(h)
+ if (matchDestination(destination, menuItem.itemId)) {
+ menuItem.isChecked = true
+ bottomBar.selectTabAt(h)
+ }
}
}
- }
- })
+ })
}
private fun matchDestination(
@@ -70,4 +70,4 @@ internal object NavigationComponentHelper {
}
return currentDestination.id == destId
}
-}
\ No newline at end of file
+}
diff --git a/library/src/main/java/nl/joery/animatedbottombar/utils/Utils.kt b/library/src/main/java/nl/joery/animatedbottombar/utils/Utils.kt
index 050b8e4..b6a354b 100644
--- a/library/src/main/java/nl/joery/animatedbottombar/utils/Utils.kt
+++ b/library/src/main/java/nl/joery/animatedbottombar/utils/Utils.kt
@@ -9,7 +9,8 @@ import androidx.annotation.AnimRes
internal object Utils {
@SuppressLint("ResourceType")
fun loadInterpolator(
- context: Context, @AnimRes resId: Int,
+ context: Context,
+ @AnimRes resId: Int,
defaultInterpolator: Interpolator
): Interpolator {
if (resId > 0) {
@@ -18,4 +19,4 @@ internal object Utils {
return defaultInterpolator
}
-}
\ No newline at end of file
+}
diff --git a/library/src/test/java/nl/joery/animatedbottombar/ExampleUnitTest.kt b/library/src/test/java/nl/joery/animatedbottombar/ExampleUnitTest.kt
index 90f91e9..10d5b27 100644
--- a/library/src/test/java/nl/joery/animatedbottombar/ExampleUnitTest.kt
+++ b/library/src/test/java/nl/joery/animatedbottombar/ExampleUnitTest.kt
@@ -13,4 +13,4 @@ class ExampleUnitTest {
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
-}
\ No newline at end of file
+}