├── .gitignore
├── .idea
├── codeStyles
│ ├── Project.xml
│ └── codeStyleConfig.xml
├── gradle.xml
├── misc.xml
├── runConfigurations.xml
└── vcs.xml
├── README.md
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── kbottomnavigation
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── hk
│ │ └── kbottomnavigation
│ │ ├── BezierView.kt
│ │ ├── CellImageView.kt
│ │ ├── KBottomNavigation.kt
│ │ ├── KBottomNavigationCell.kt
│ │ └── Utils.kt
│ └── res
│ ├── layout
│ └── meow_navigation_cell.xml
│ └── values
│ ├── attrs.xml
│ └── strings.xml
├── resources
├── meow-bottom-navigation-low.jpg
├── meow-bottom-navigation-normal.gif
├── meow-bottom-navigation-small.gif
└── meow-bottom-navigation.gif
├── sample
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── hk
│ │ └── kbottomnavigation
│ │ └── ExampleInstrumentedTest.kt
│ ├── main
│ ├── AndroidManifest.xml
│ ├── assets
│ │ └── fonts
│ │ │ ├── SourceSansPro-Regular.ttf
│ │ │ └── SourceSansPro-SemiBold.ttf
│ ├── java
│ │ └── com
│ │ │ └── hk
│ │ │ └── kbottomnavigation
│ │ │ ├── MainActivity.kt
│ │ │ └── MyContextWrapper.kt
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable-xxhdpi
│ │ └── img_meow_large.png
│ │ ├── drawable
│ │ ├── ic_account.xml
│ │ ├── ic_explore.xml
│ │ ├── ic_home.xml
│ │ ├── ic_launcher_background.xml
│ │ ├── ic_message.xml
│ │ ├── ic_notification.xml
│ │ └── tekrevol_logo.png
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── hk
│ └── kbottomnavigation
│ └── ExampleUnitTest.kt
└── 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 | .cxx
15 |
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 | xmlns:android
20 |
21 | ^$
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 | xmlns:.*
31 |
32 | ^$
33 |
34 |
35 | BY_NAME
36 |
37 |
38 |
39 |
40 |
41 |
42 | .*:id
43 |
44 | http://schemas.android.com/apk/res/android
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 | .*:name
54 |
55 | http://schemas.android.com/apk/res/android
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 | name
65 |
66 | ^$
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 | style
76 |
77 | ^$
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 | .*
87 |
88 | ^$
89 |
90 |
91 | BY_NAME
92 |
93 |
94 |
95 |
96 |
97 |
98 | .*
99 |
100 | http://schemas.android.com/apk/res/android
101 |
102 |
103 | ANDROID_ATTRIBUTE_ORDER
104 |
105 |
106 |
107 |
108 |
109 |
110 | .*
111 |
112 | .*
113 |
114 |
115 | BY_NAME
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
--------------------------------------------------------------------------------
/.idea/codeStyles/codeStyleConfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
19 |
20 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Kotlin Bottom Navigation
2 | A simple & curved & material bottom navigation for Android written in kotlin
3 |
4 | [](https://jitpack.io/#hamzaahmedkhan/KBottomNavigation)
5 |
6 |
7 | 
8 |
9 | ## Download
10 | build.gradle (project path)
11 | ```groovy
12 | buildscript {
13 | repositories {
14 | jcenter() // this line need
15 | }
16 | ....
17 | }
18 | ```
19 | build.gradle (module path)
20 | ```groovy
21 | dependencies {
22 | implementation 'com.github.hamzaahmedkhan:KBottomNavigation:1.0.0'
23 | }
24 | ```
25 | use androidx by adding this lines to gradle.properties
26 | ```properties
27 | android.useAndroidX=true
28 | android.enableJetifier=true
29 | ```
30 |
31 | ## Usage
32 | add Kotlin Bottom Navigation in xml
33 | ```xml
34 |
37 | ```
38 |
39 | add menu items in code.
40 |
41 | remember icons must be vector drawable
42 | ```kotlin
43 | companion object {
44 | private const val ID_HOME = 1
45 | private const val ID_EXPLORE = 2
46 | private const val ID_MESSAGE = 3
47 | private const val ID_NOTIFICATION = 4
48 | private const val ID_ACCOUNT = 5
49 | }
50 |
51 | val bottomNavigation = findView(R.id.bottomNavigation)
52 | bottomNavigation.add(KBottomNavigation.Model(ID_HOME, R.drawable.ic_home))
53 | bottomNavigation.add(KBottomNavigation.Model(ID_EXPLORE, R.drawable.ic_explore))
54 | bottomNavigation.add(KBottomNavigation.Model(ID_MESSAGE, R.drawable.ic_message))
55 | bottomNavigation.add(KBottomNavigation.Model(ID_NOTIFICATION, R.drawable.ic_notification))
56 | bottomNavigation.add(KBottomNavigation.Model(ID_ACCOUNT, R.drawable.ic_account))
57 |
58 | // To set count
59 | bottomNavigation.setCount(ID_NOTIFICATION, "115")
60 | ....
61 | ```
62 |
63 | ## Customization
64 | ```xml
65 |
76 | ```
77 |
78 | ## Listeners
79 | ```kotlin
80 | bottomNavigation.setOnShowListener {
81 | val name = when (it.id) {
82 | ID_HOME -> "HOME"
83 | ID_EXPLORE -> "EXPLORE"
84 | ID_MESSAGE -> "MESSAGE"
85 | ID_NOTIFICATION -> "NOTIFICATION"
86 | ID_ACCOUNT -> "ACCOUNT"
87 | else -> ""
88 | }
89 | tv_selected.text = "$name page is selected"
90 | }
91 |
92 | bottomNavigation.setOnClickMenuListener {
93 | val name = when (it.id) {
94 | ID_HOME -> "HOME"
95 | ID_EXPLORE -> "EXPLORE"
96 | ID_MESSAGE -> "MESSAGE"
97 | ID_NOTIFICATION -> "NOTIFICATION"
98 | ID_ACCOUNT -> "ACCOUNT"
99 | else -> ""
100 | }
101 | ```
102 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | ext.compileSdk_version = 28
6 | ext.minSdk_version = 15
7 | ext.targetSdk_version = 28
8 |
9 | ext.kotlin_version = '1.3.61'
10 |
11 | repositories {
12 | google()
13 | jcenter()
14 | }
15 | dependencies {
16 | classpath 'com.android.tools.build:gradle:3.4.1'
17 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
18 | classpath 'com.novoda:bintray-release:0.9.1'
19 | // NOTE: Do not place your application dependencies here; they belong
20 | // in the individual module build.gradle files
21 | }
22 | }
23 |
24 | allprojects {
25 | repositories {
26 | google()
27 | jcenter()
28 | }
29 | }
30 |
31 | task clean(type: Delete) {
32 | delete rootProject.buildDir
33 | }
34 |
--------------------------------------------------------------------------------
/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 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 | # Kotlin code style for this project: "official" or "obsolete":
21 | kotlin.code.style=official
22 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hamzaahmedkhan/KBottomNavigation/45a7da2bb4fc42f5940f2ed177a884e61d5e6cf5/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 23 13:51:59 PKT 2019
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-5.4.1-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 |
--------------------------------------------------------------------------------
/kbottomnavigation/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/kbottomnavigation/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.novoda.bintray-release'
2 | apply plugin: 'com.android.library'
3 |
4 | apply plugin: 'kotlin-android'
5 |
6 | apply plugin: 'kotlin-android-extensions'
7 |
8 | def library_groupId = 'com.hk'
9 | def library_artifactId = 'k-bottom-navigation'
10 | def library_versionCode = 1_0_01_00_00
11 | def library_versionName = '1.0.0'
12 |
13 | publish {
14 |
15 | userOrg = 'hk'
16 | repoName = 'bottomnavigation'
17 | groupId = library_groupId
18 | artifactId = library_artifactId
19 | publishVersion = library_versionName
20 | desc = 'Kotlin Bottom Navigation'
21 | website = 'https://github.com/hamzaahmedkhan/KBottomNavigation'
22 |
23 | }
24 |
25 | android {
26 | compileSdkVersion compileSdk_version
27 |
28 | defaultConfig {
29 | minSdkVersion minSdk_version
30 | targetSdkVersion targetSdk_version
31 | versionCode library_versionCode
32 | versionName library_versionName
33 |
34 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
35 | vectorDrawables.useSupportLibrary = true
36 | }
37 |
38 | buildTypes {
39 | release {
40 | minifyEnabled false
41 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
42 | }
43 | }
44 |
45 | }
46 |
47 | androidExtensions {
48 | experimental = true
49 | }
50 |
51 | dependencies {
52 | implementation "androidx.appcompat:appcompat:1.0.2"
53 | implementation "androidx.core:core-ktx:1.0.2"
54 | }
55 |
--------------------------------------------------------------------------------
/kbottomnavigation/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 |
--------------------------------------------------------------------------------
/kbottomnavigation/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/kbottomnavigation/src/main/java/com/hk/kbottomnavigation/BezierView.kt:
--------------------------------------------------------------------------------
1 | package com.hk.kbottomnavigation
2 |
3 | import android.annotation.SuppressLint
4 | import android.content.Context
5 | import android.graphics.Canvas
6 | import android.graphics.Paint
7 | import android.graphics.Path
8 | import android.graphics.PointF
9 | import android.util.AttributeSet
10 | import android.view.View
11 |
12 | /**
13 | * Created by 1HE on 2/25/2019.
14 | */
15 |
16 | class BezierView : View {
17 |
18 | private var mainPaint: Paint? = null
19 | private var shadowPaint: Paint? = null
20 | private var mainPath: Path? = null
21 | private var shadowPath: Path? = null
22 | private lateinit var outerArray: Array
23 | private lateinit var innerArray: Array
24 | private lateinit var progressArray: Array
25 |
26 | private var width = 0f
27 | private var height = 0f
28 | private var bezierOuterWidth = 0f
29 | private var bezierOuterHeight = 0f
30 | private var bezierInnerWidth = 0f
31 | private var bezierInnerHeight = 0f
32 | private val shadowHeight = dipf(context, 8)
33 |
34 | var color = 0
35 | set(value) {
36 | field = value
37 | mainPaint?.color = field
38 | }
39 | var shadowColor = 0
40 | set(value) {
41 | field = value
42 | shadowPaint?.setShadowLayer(dipf(context, 4), 0f, 0f, shadowColor)
43 | }
44 |
45 | var bezierX = 0f
46 | set(value) {
47 | if (value == field)
48 | return
49 | field = value
50 | invalidate()
51 | }
52 |
53 | var progress = 0f
54 | set(value) {
55 | if (value == field)
56 | return
57 | field = value
58 |
59 | progressArray[1].x = bezierX - bezierInnerWidth / 2
60 | progressArray[2].x = bezierX - bezierInnerWidth / 4
61 | progressArray[3].x = bezierX - bezierInnerWidth / 4
62 | progressArray[4].x = bezierX
63 | progressArray[5].x = bezierX + bezierInnerWidth / 4
64 | progressArray[6].x = bezierX + bezierInnerWidth / 4
65 | progressArray[7].x = bezierX + bezierInnerWidth / 2
66 | for (i in 2..6) {
67 | if (progress <= 1f) {//convert to outer
68 | progressArray[i].y = calculate(innerArray[i].y, outerArray[i].y)
69 | } else {
70 | progressArray[i].y = calculate(outerArray[i].y, innerArray[i].y)
71 | }
72 | }
73 | if (field == 2f)
74 | field = 0f
75 |
76 | invalidate()
77 | }
78 |
79 | @SuppressLint("NewApi")
80 | constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) {
81 | initializeViews()
82 | }
83 |
84 | constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
85 | initializeViews()
86 | }
87 |
88 | constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
89 | initializeViews()
90 | }
91 |
92 | constructor(context: Context) : super(context) {
93 | initializeViews()
94 | }
95 |
96 | private fun initializeViews() {
97 | setWillNotDraw(false)
98 |
99 | mainPath = Path()
100 | shadowPath = Path()
101 | outerArray = Array(11) { PointF() }
102 | innerArray = Array(11) { PointF() }
103 | progressArray = Array(11) { PointF() }
104 |
105 | mainPaint = Paint(Paint.ANTI_ALIAS_FLAG)
106 | mainPaint?.apply {
107 | strokeWidth = 0f
108 | isAntiAlias = true
109 | style = Paint.Style.FILL
110 | color = this@BezierView.color
111 | }
112 |
113 | shadowPaint = Paint(Paint.ANTI_ALIAS_FLAG)
114 | shadowPaint?.apply {
115 | isAntiAlias = true
116 | setShadowLayer(dipf(context, 4), 0f, 0f, shadowColor)
117 | }
118 |
119 | color = color
120 | shadowColor = shadowColor
121 |
122 | setLayerType(View.LAYER_TYPE_SOFTWARE, shadowPaint)
123 | }
124 |
125 | @SuppressLint("DrawAllocation")
126 | override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
127 | super.onMeasure(widthMeasureSpec, heightMeasureSpec)
128 | width = View.MeasureSpec.getSize(widthMeasureSpec).toFloat()
129 | height = View.MeasureSpec.getSize(heightMeasureSpec).toFloat()
130 | bezierOuterWidth = dipf(context, 72)
131 | bezierOuterHeight = dipf(context, 8)
132 | bezierInnerWidth = dipf(context, 124)
133 | bezierInnerHeight = dipf(context, 16)
134 |
135 | val extra = shadowHeight
136 | outerArray[0] = PointF(0f, bezierOuterHeight + extra)
137 | outerArray[1] = PointF((bezierX - bezierOuterWidth / 2), bezierOuterHeight + extra)
138 | outerArray[2] = PointF(bezierX - bezierOuterWidth / 4, bezierOuterHeight + extra)
139 | outerArray[3] = PointF(bezierX - bezierOuterWidth / 4, extra)
140 | outerArray[4] = PointF(bezierX, extra)
141 | outerArray[5] = PointF(bezierX + bezierOuterWidth / 4, extra)
142 | outerArray[6] = PointF(bezierX + bezierOuterWidth / 4, bezierOuterHeight + extra)
143 | outerArray[7] = PointF(bezierX + bezierOuterWidth / 2, bezierOuterHeight + extra)
144 | outerArray[8] = PointF(width, bezierOuterHeight + extra)
145 | outerArray[9] = PointF(width, height)
146 | outerArray[10] = PointF(0f, height)
147 | }
148 |
149 | override fun onDraw(canvas: Canvas) {
150 | super.onDraw(canvas)
151 | mainPath!!.reset()
152 | shadowPath!!.reset()
153 |
154 | if (progress == 0f) {
155 | drawInner(canvas, true)
156 | drawInner(canvas, false)
157 | } else {
158 | drawProgress(canvas, true)
159 | drawProgress(canvas, false)
160 | }
161 | }
162 |
163 | private fun drawInner(canvas: Canvas, isShadow: Boolean) {
164 | val paint = if (isShadow) shadowPaint else mainPaint
165 | val path = if (isShadow) shadowPath else mainPath
166 |
167 | calculateInner()
168 |
169 | path!!.lineTo(innerArray[0].x, innerArray[0].y)
170 | path.lineTo(innerArray[1].x, innerArray[1].y)
171 | path.cubicTo(innerArray[2].x, innerArray[2].y, innerArray[3].x, innerArray[3].y, innerArray[4].x, innerArray[4].y)
172 | path.cubicTo(innerArray[5].x, innerArray[5].y, innerArray[6].x, innerArray[6].y, innerArray[7].x, innerArray[7].y)
173 | path.lineTo(innerArray[8].x, innerArray[8].y)
174 | path.lineTo(innerArray[9].x, innerArray[9].y)
175 | path.lineTo(innerArray[10].x, innerArray[10].y)
176 |
177 | progressArray = innerArray.clone()
178 |
179 | canvas.drawPath(path, paint!!)
180 | }
181 |
182 | private fun calculateInner() {
183 | val extra = shadowHeight
184 | innerArray[0] = PointF(0f, bezierInnerHeight + extra)
185 | innerArray[1] = PointF((bezierX - bezierInnerWidth / 2), bezierInnerHeight + extra)
186 | innerArray[2] = PointF(bezierX - bezierInnerWidth / 4, bezierInnerHeight + extra)
187 | innerArray[3] = PointF(bezierX - bezierInnerWidth / 4, height - extra)
188 | innerArray[4] = PointF(bezierX, height - extra)
189 | innerArray[5] = PointF(bezierX + bezierInnerWidth / 4, height - extra)
190 | innerArray[6] = PointF(bezierX + bezierInnerWidth / 4, bezierInnerHeight + extra)
191 | innerArray[7] = PointF(bezierX + bezierInnerWidth / 2, bezierInnerHeight + extra)
192 | innerArray[8] = PointF(width, bezierInnerHeight + extra)
193 | innerArray[9] = PointF(width, height)
194 | innerArray[10] = PointF(0f, height)
195 | }
196 |
197 | private fun drawProgress(canvas: Canvas, isShadow: Boolean) {
198 | val paint = if (isShadow) shadowPaint else mainPaint
199 | val path = if (isShadow) shadowPath else mainPath
200 |
201 | path!!.lineTo(progressArray[0].x, progressArray[0].y)
202 | path.lineTo(progressArray[1].x, progressArray[1].y)
203 | path.cubicTo(progressArray[2].x, progressArray[2].y, progressArray[3].x, progressArray[3].y, progressArray[4].x, progressArray[4].y)
204 | path.cubicTo(progressArray[5].x, progressArray[5].y, progressArray[6].x, progressArray[6].y, progressArray[7].x, progressArray[7].y)
205 | path.lineTo(progressArray[8].x, progressArray[8].y)
206 | path.lineTo(progressArray[9].x, progressArray[9].y)
207 | path.lineTo(progressArray[10].x, progressArray[10].y)
208 |
209 | canvas.drawPath(path, paint!!)
210 | }
211 |
212 | private fun calculate(start: Float, end: Float): Float {
213 | var p = progress
214 | if (p > 1f)
215 | p = progress - 1f
216 | if (p in 0.9f..1f)
217 | calculateInner()
218 | return (p * (end - start)) + start
219 | }
220 | }
221 |
--------------------------------------------------------------------------------
/kbottomnavigation/src/main/java/com/hk/kbottomnavigation/CellImageView.kt:
--------------------------------------------------------------------------------
1 | package com.hk.kbottomnavigation
2 |
3 | import android.animation.ValueAnimator
4 | import android.content.Context
5 | import android.util.AttributeSet
6 | import androidx.appcompat.widget.AppCompatImageView
7 | import androidx.interpolator.view.animation.FastOutSlowInInterpolator
8 |
9 | /**
10 | * Created by 1HE on 2/23/2019.
11 | */
12 |
13 | @Suppress("unused", "LeakingThis", "MemberVisibilityCanBePrivate")
14 | internal class CellImageView : AppCompatImageView {
15 |
16 | var isBitmap = false
17 | set(value) {
18 | field = value
19 | draw()
20 | }
21 | var useColor = true
22 | set(value) {
23 | field = value
24 | draw()
25 | }
26 | var resource = 0
27 | set(value) {
28 | field = value
29 | draw()
30 | }
31 | var color = 0
32 | set(value) {
33 | field = value
34 | draw()
35 | }
36 | var size = dip(context, 24)
37 | set(value) {
38 | field = value
39 | requestLayout()
40 | }
41 | private var actionBackgroundAlpha = false
42 | private var changeSize = true
43 | private var fitImage = false
44 | private var colorAnimator: ValueAnimator? = null
45 | private var allowDraw = false
46 |
47 | constructor(context: Context) : super(context) {
48 | initializeView()
49 | }
50 |
51 | constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
52 | setAttributeFromXml(context, attrs)
53 | initializeView()
54 | }
55 |
56 | constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
57 | setAttributeFromXml(context, attrs)
58 | initializeView()
59 | }
60 |
61 | private fun setAttributeFromXml(context: Context, attrs: AttributeSet) {
62 | val a = context.theme.obtainStyledAttributes(attrs, R.styleable.CellImageView, 0, 0)
63 | try {
64 | a?.apply {
65 | isBitmap = getBoolean(R.styleable.CellImageView_meow_imageview_isBitmap, isBitmap)
66 | useColor = getBoolean(R.styleable.CellImageView_meow_imageview_useColor, useColor)
67 | resource = getResourceId(R.styleable.CellImageView_meow_imageview_resource, resource)
68 | color = getColor(R.styleable.CellImageView_meow_imageview_color, color)
69 | size = getDimensionPixelSize(R.styleable.CellImageView_meow_imageview_size, size)
70 | actionBackgroundAlpha = getBoolean(R.styleable.CellImageView_meow_imageview_actionBackgroundAlpha, actionBackgroundAlpha)
71 | changeSize = getBoolean(R.styleable.CellImageView_meow_imageview_changeSize, changeSize)
72 | fitImage = getBoolean(R.styleable.CellImageView_meow_imageview_fitImage, fitImage)
73 | }
74 | } finally {
75 | a?.recycle()
76 | }
77 | }
78 |
79 | private fun initializeView() {
80 | allowDraw = true
81 | draw()
82 | }
83 |
84 | private fun draw() {
85 | if (!allowDraw)
86 | return
87 |
88 | if (resource == 0)
89 | return
90 |
91 | if (isBitmap) {
92 | try {
93 | val drawable = if (color == 0) context.getDrawableCompat(resource) else DrawableHelper.changeColorDrawableRes(context, resource, color)
94 | setImageDrawable(drawable)
95 | } catch (e: Exception) {
96 | e.printStackTrace()
97 | }
98 | return
99 | }
100 |
101 | if (useColor && color == 0)
102 | return
103 |
104 | val c = if (useColor) color else -2
105 | try {
106 | setImageDrawable(DrawableHelper.changeColorDrawableVector(context, resource, c))
107 | } catch (e: Exception) {
108 | e.printStackTrace()
109 | }
110 | }
111 |
112 | fun changeColorByAnim(newColor: Int, d: Long = 250L) {
113 | if (color == 0) {
114 | color = newColor
115 | return
116 | }
117 | val lastColor = color
118 |
119 | colorAnimator?.cancel()
120 |
121 | colorAnimator = ValueAnimator.ofFloat(0f, 1f)
122 | colorAnimator?.apply {
123 | duration = d
124 | interpolator = FastOutSlowInInterpolator()
125 | addUpdateListener { animation ->
126 | val f = animation.animatedFraction
127 | color = ColorHelper.mixTwoColors(newColor, lastColor, f)
128 | }
129 | start()
130 | }
131 | }
132 |
133 | override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
134 | if (fitImage) {
135 | val d = drawable
136 | if (d != null) {
137 | val width = MeasureSpec.getSize(widthMeasureSpec)
138 | val height = Math.ceil((width.toFloat() * d.intrinsicHeight.toFloat() / d.intrinsicWidth).toDouble()).toInt()
139 | setMeasuredDimension(width, height)
140 | } else {
141 | super.onMeasure(widthMeasureSpec, heightMeasureSpec)
142 | }
143 | return
144 | }
145 |
146 | if (isBitmap || !changeSize) {
147 | super.onMeasure(widthMeasureSpec, heightMeasureSpec)
148 | return
149 | }
150 |
151 | val newSize = MeasureSpec.makeMeasureSpec(size, MeasureSpec.EXACTLY)
152 | super.onMeasure(newSize, newSize)
153 | }
154 |
155 | }
--------------------------------------------------------------------------------
/kbottomnavigation/src/main/java/com/hk/kbottomnavigation/KBottomNavigation.kt:
--------------------------------------------------------------------------------
1 | @file:Suppress("unused")
2 |
3 | package com.hk.kbottomnavigation
4 |
5 | import android.animation.ValueAnimator
6 | import android.content.Context
7 | import android.graphics.Color
8 | import android.graphics.Typeface
9 | import android.os.Build
10 | import android.util.AttributeSet
11 | import android.util.LayoutDirection
12 | import android.view.Gravity
13 | import android.widget.FrameLayout
14 | import android.widget.LinearLayout
15 | import androidx.interpolator.view.animation.FastOutSlowInInterpolator
16 |
17 | /**
18 | * Created by 1HE on 10/23/2018.
19 | */
20 |
21 | internal typealias IBottomNavigationListener = (model: KBottomNavigation.Model) -> Unit
22 |
23 | @Suppress("MemberVisibilityCanBePrivate")
24 | class KBottomNavigation : FrameLayout {
25 |
26 | var models = ArrayList()
27 | var cells = ArrayList()
28 | var callListenerWhenIsSelected = false
29 |
30 | private var selectedId = -1
31 |
32 | private var mOnClickedListener: IBottomNavigationListener = {}
33 | private var mOnShowListener: IBottomNavigationListener = {}
34 |
35 | private var heightCell = 0
36 | private var isAnimating = false
37 |
38 | private var defaultIconColor = Color.parseColor("#757575")
39 | private var selectedIconColor = Color.parseColor("#2196f3")
40 | private var backgroundBottomColor = Color.parseColor("#ffffff")
41 | private var shadowColor = -0x454546
42 | private var countTextColor = Color.parseColor("#ffffff")
43 | private var countBackgroundColor = Color.parseColor("#ff0000")
44 | private var countTypeface: Typeface? = null
45 | private var rippleColor = Color.parseColor("#757575")
46 |
47 | @Suppress("PrivatePropertyName")
48 | private lateinit var ll_cells: LinearLayout
49 | private lateinit var bezierView: BezierView
50 |
51 | init {
52 | heightCell = dip(context, 72)
53 | }
54 |
55 | constructor(context: Context) : super(context) {
56 | initializeViews()
57 | }
58 |
59 | constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
60 | setAttributeFromXml(context, attrs)
61 | initializeViews()
62 | }
63 |
64 | constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
65 | setAttributeFromXml(context, attrs)
66 | initializeViews()
67 | }
68 |
69 | private fun setAttributeFromXml(context: Context, attrs: AttributeSet) {
70 | val a = context.theme.obtainStyledAttributes(attrs, R.styleable.KBottomNavigation, 0, 0)
71 | try {
72 | a?.apply {
73 | defaultIconColor = getColor(R.styleable.KBottomNavigation_mbn_defaultIconColor, defaultIconColor)
74 | selectedIconColor = getColor(R.styleable.KBottomNavigation_mbn_selectedIconColor, selectedIconColor)
75 | backgroundBottomColor = getColor(R.styleable.KBottomNavigation_mbn_backgroundBottomColor, backgroundBottomColor)
76 | countTextColor = getColor(R.styleable.KBottomNavigation_mbn_countTextColor, countTextColor)
77 | countBackgroundColor = getColor(R.styleable.KBottomNavigation_mbn_countBackgroundColor, countBackgroundColor)
78 | val typeface = getString(R.styleable.KBottomNavigation_mbn_countTypeface)
79 | rippleColor = getColor(R.styleable.KBottomNavigation_mbn_rippleColor, rippleColor)
80 | shadowColor = getColor(R.styleable.KBottomNavigation_mbn_shadowColor, shadowColor)
81 |
82 | if (typeface != null && typeface.isNotEmpty())
83 | countTypeface = Typeface.createFromAsset(context.assets, typeface)
84 | }
85 | } finally {
86 | a?.recycle()
87 | }
88 | }
89 |
90 | private fun initializeViews() {
91 | ll_cells = LinearLayout(context)
92 | ll_cells.apply {
93 | val params = LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, heightCell)
94 | params.gravity = Gravity.BOTTOM
95 | layoutParams = params
96 | orientation = LinearLayout.HORIZONTAL
97 | clipChildren = false
98 | clipToPadding = false
99 | }
100 |
101 | bezierView = BezierView(context)
102 | bezierView.apply {
103 | layoutParams = LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, heightCell)
104 | color = backgroundBottomColor
105 | shadowColor = this@KBottomNavigation.shadowColor
106 | }
107 |
108 | addView(bezierView)
109 | addView(ll_cells)
110 | }
111 |
112 | override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
113 | super.onMeasure(widthMeasureSpec, heightMeasureSpec)
114 | if (selectedId == -1) {
115 | bezierView.bezierX = if (Build.VERSION.SDK_INT >= 17 && layoutDirection == LayoutDirection.RTL) measuredWidth + dipf(context, 72) else -dipf(context, 72)
116 | }
117 | if (selectedId != -1) {
118 | show(selectedId, false)
119 | }
120 | }
121 |
122 | fun add(model: Model) {
123 | val cell = KBottomNavigationCell(context)
124 | cell.apply {
125 | val params = LinearLayout.LayoutParams(0, heightCell, 1f)
126 | layoutParams = params
127 | icon = model.icon
128 | count = model.count
129 | circleColor = this@KBottomNavigation.backgroundBottomColor
130 | countTextColor = this@KBottomNavigation.countTextColor
131 | countBackgroundColor = this@KBottomNavigation.countBackgroundColor
132 | countTypeface = this@KBottomNavigation.countTypeface
133 | rippleColor = this@KBottomNavigation.rippleColor
134 | defaultIconColor = this@KBottomNavigation.defaultIconColor
135 | selectedIconColor = this@KBottomNavigation.selectedIconColor
136 | onClickListener = {
137 | if (!cell.isEnabledCell && !isAnimating) {
138 | show(model.id)
139 | mOnClickedListener(model)
140 | } else {
141 | if (callListenerWhenIsSelected)
142 | mOnClickedListener(model)
143 | }
144 | }
145 | disableCell()
146 | ll_cells.addView(this)
147 | }
148 |
149 | cells.add(cell)
150 | models.add(model)
151 | }
152 |
153 | fun show(id: Int, enableAnimation: Boolean = true) {
154 | for (i in models.indices) {
155 | val model = models[i]
156 | val cell = cells[i]
157 | if (model.id == id) {
158 | anim(cell, id, enableAnimation)
159 | cell.enableCell()
160 | mOnShowListener(model)
161 | } else {
162 | cell.disableCell()
163 | }
164 | }
165 | selectedId = id
166 | }
167 |
168 | private fun anim(cell: KBottomNavigationCell, id: Int, enableAnimation: Boolean = true) {
169 | isAnimating = true
170 |
171 | val pos = getModelPosition(id)
172 | val nowPos = getModelPosition(selectedId)
173 |
174 | val nPos = if (nowPos < 0) 0 else nowPos
175 | val dif = Math.abs(pos - nPos)
176 | val d = (dif) * 100L + 150L
177 |
178 | val animDuration = if (enableAnimation) d else 1L
179 | val animInterpolator = FastOutSlowInInterpolator()
180 |
181 | val anim = ValueAnimator.ofFloat(0f, 1f)
182 | anim.apply {
183 | duration = animDuration
184 | interpolator = animInterpolator
185 | val beforeX = bezierView.bezierX
186 | addUpdateListener {
187 | val f = it.animatedFraction
188 | val newX = cell.x + (cell.measuredWidth / 2)
189 | if (newX > beforeX)
190 | bezierView.bezierX = f * (newX - beforeX) + beforeX
191 | else
192 | bezierView.bezierX = beforeX - f * (beforeX - newX)
193 | if (f == 1f)
194 | isAnimating = false
195 | }
196 | start()
197 | }
198 |
199 | if (Math.abs(pos - nowPos) > 1) {
200 | val progressAnim = ValueAnimator.ofFloat(0f, 1f)
201 | progressAnim.apply {
202 | duration = animDuration
203 | interpolator = animInterpolator
204 | addUpdateListener {
205 | val f = it.animatedFraction
206 | bezierView.progress = f * 2f
207 | }
208 | start()
209 | }
210 | }
211 |
212 | cell.isFromLeft = pos > nowPos
213 | cells.forEach {
214 | it.duration = d
215 | }
216 | }
217 |
218 | fun isShowing(id: Int): Boolean {
219 | return selectedId == id
220 | }
221 |
222 | fun getModelById(id: Int): Model? {
223 | models.forEach {
224 | if (it.id == id)
225 | return it
226 | }
227 | return null
228 | }
229 |
230 | fun getCellById(id: Int): KBottomNavigationCell? {
231 | return cells[getModelPosition(id)]
232 | }
233 |
234 | fun getModelPosition(id: Int): Int {
235 | for (i in models.indices) {
236 | val item = models[i]
237 | if (item.id == id)
238 | return i
239 | }
240 | return -1
241 | }
242 |
243 | fun setCount(id: Int, count: String) {
244 | val model = getModelById(id) ?: return
245 | val pos = getModelPosition(id)
246 | model.count = count
247 | cells[pos].count = count
248 | }
249 |
250 | fun setOnShowListener(listener: IBottomNavigationListener) {
251 | mOnShowListener = listener
252 | }
253 |
254 | fun setOnClickMenuListener(listener: IBottomNavigationListener) {
255 | mOnClickedListener = listener
256 | }
257 |
258 | class Model(var id: Int, var icon: Int) {
259 |
260 | var count: String = KBottomNavigationCell.EMPTY_VALUE
261 |
262 | }
263 | }
--------------------------------------------------------------------------------
/kbottomnavigation/src/main/java/com/hk/kbottomnavigation/KBottomNavigationCell.kt:
--------------------------------------------------------------------------------
1 | package com.hk.kbottomnavigation
2 |
3 | import android.animation.ValueAnimator
4 | import android.content.Context
5 | import android.content.res.ColorStateList
6 | import android.graphics.Color
7 | import android.graphics.Typeface
8 | import android.graphics.drawable.GradientDrawable
9 | import android.graphics.drawable.RippleDrawable
10 | import android.os.Build
11 | import android.util.AttributeSet
12 | import android.view.LayoutInflater
13 | import android.view.View
14 | import android.widget.RelativeLayout
15 | import androidx.core.view.ViewCompat
16 | import androidx.interpolator.view.animation.FastOutSlowInInterpolator
17 | import kotlinx.android.extensions.LayoutContainer
18 | import kotlinx.android.synthetic.main.meow_navigation_cell.view.*
19 |
20 | /**
21 | * Created by 1HE on 2/23/2019.
22 | */
23 |
24 | @Suppress("unused")
25 | class KBottomNavigationCell : RelativeLayout, LayoutContainer {
26 |
27 | companion object {
28 | const val EMPTY_VALUE = "empty"
29 | }
30 |
31 | var defaultIconColor = 0
32 | var selectedIconColor = 0
33 | var circleColor = 0
34 |
35 | var icon = 0
36 | set(value) {
37 | field = value
38 | if (allowDraw)
39 | iv.resource = value
40 | }
41 |
42 | var count: String? = EMPTY_VALUE
43 | set(value) {
44 | field = value
45 | if (allowDraw) {
46 | if (count != null && count == EMPTY_VALUE) {
47 | tv_count.text = ""
48 | tv_count.visibility = View.INVISIBLE
49 | } else {
50 | if (count != null && count?.length ?: 0 >= 3) {
51 | field = count?.substring(0, 1) + ".."
52 | }
53 | tv_count.text = count
54 | tv_count.visibility = View.VISIBLE
55 | val scale = if (count?.isEmpty() == true) 0.5f else 1f
56 | tv_count.scaleX = scale
57 | tv_count.scaleY = scale
58 | }
59 | }
60 | }
61 |
62 | private var iconSize = dip(context, 48)
63 | set(value) {
64 | field = value
65 | if (allowDraw) {
66 | iv.size = value
67 | iv.pivotX = iconSize / 2f
68 | iv.pivotY = iconSize / 2f
69 | }
70 | }
71 |
72 | var countTextColor = 0
73 | set(value) {
74 | field = value
75 | if (allowDraw)
76 | tv_count.setTextColor(field)
77 | }
78 |
79 | var countBackgroundColor = 0
80 | set(value) {
81 | field = value
82 | if (allowDraw) {
83 | val d = GradientDrawable()
84 | d.setColor(field)
85 | d.shape = GradientDrawable.OVAL
86 | ViewCompat.setBackground(tv_count, d)
87 | }
88 | }
89 |
90 | var countTypeface: Typeface? = null
91 | set(value) {
92 | field = value
93 | if (allowDraw && field != null)
94 | tv_count.typeface = field
95 | }
96 |
97 | var rippleColor = 0
98 | set(value) {
99 | field = value
100 | if (allowDraw) {
101 |
102 | }
103 | }
104 |
105 | var isFromLeft = false
106 | var duration = 0L
107 | private var progress = 0f
108 | set(value) {
109 | field = value
110 | fl.y = (1f - progress) * dip(context, 18) + dip(context, -2)
111 |
112 | iv.color = if (progress == 1f) selectedIconColor else defaultIconColor
113 | val scale = (1f - progress) * (-0.2f) + 1f
114 | iv.scaleX = scale
115 | iv.scaleY = scale
116 |
117 | val d = GradientDrawable()
118 | d.setColor(circleColor)
119 | d.shape = GradientDrawable.OVAL
120 |
121 | ViewCompat.setBackground(v_circle, d)
122 |
123 | ViewCompat.setElevation(v_circle, if (progress > 0.7f) dipf(context, progress * 4f) else 0f)
124 |
125 | val m = dip(context, 24)
126 | v_circle.x = (1f - progress) * (if (isFromLeft) -m else m) + ((measuredWidth - dip(context, 48)) / 2f)
127 | v_circle.y = (1f - progress) * measuredHeight + dip(context, 6)
128 | }
129 |
130 | var isEnabledCell = false
131 | set(value) {
132 | field = value
133 | val d = GradientDrawable()
134 | d.setColor(circleColor)
135 | d.shape = GradientDrawable.OVAL
136 | if (Build.VERSION.SDK_INT >= 21 && !isEnabledCell) {
137 | fl.background = RippleDrawable(ColorStateList.valueOf(rippleColor), null, d)
138 | } else {
139 | fl.runAfterDelay(200) {
140 | fl.setBackgroundColor(Color.TRANSPARENT)
141 | }
142 | }
143 | }
144 |
145 | var onClickListener: () -> Unit = {}
146 | set(value) {
147 | field = value
148 | iv?.setOnClickListener {
149 | onClickListener()
150 | }
151 | }
152 |
153 | override lateinit var containerView: View
154 | private var allowDraw = false
155 |
156 | constructor(context: Context) : super(context) {
157 | initializeView()
158 | }
159 |
160 | constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
161 | setAttributeFromXml(context, attrs)
162 | initializeView()
163 | }
164 |
165 | constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
166 | setAttributeFromXml(context, attrs)
167 | initializeView()
168 | }
169 |
170 | @Suppress("UNUSED_PARAMETER")
171 | private fun setAttributeFromXml(context: Context, attrs: AttributeSet) {
172 | }
173 |
174 | private fun initializeView() {
175 | allowDraw = true
176 | containerView = LayoutInflater.from(context).inflate(R.layout.meow_navigation_cell, this)
177 | draw()
178 | }
179 |
180 | private fun draw() {
181 | if (!allowDraw)
182 | return
183 |
184 | icon = icon
185 | count = count
186 | iconSize = iconSize
187 | countTextColor = countTextColor
188 | countBackgroundColor = countBackgroundColor
189 | countTypeface = countTypeface
190 | rippleColor = rippleColor
191 | onClickListener = onClickListener
192 | }
193 |
194 | override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
195 | super.onMeasure(widthMeasureSpec, heightMeasureSpec)
196 | progress = progress
197 | }
198 |
199 | fun disableCell() {
200 | if (isEnabledCell)
201 | animateProgress(false)
202 | isEnabledCell = false
203 | }
204 |
205 | fun enableCell(isAnimate: Boolean = true) {
206 | if (!isEnabledCell)
207 | animateProgress(true, isAnimate)
208 | isEnabledCell = true
209 | }
210 |
211 | private fun animateProgress(enableCell: Boolean, isAnimate: Boolean = true) {
212 | val d = if (enableCell) duration else 250
213 | val anim = ValueAnimator.ofFloat(0f, 1f)
214 | anim.apply {
215 | startDelay = if (enableCell) d / 4 else 0L
216 | duration = if (isAnimate) d else 1L
217 | interpolator = FastOutSlowInInterpolator()
218 | addUpdateListener {
219 | val f = it.animatedFraction
220 | progress = if (enableCell)
221 | f
222 | else
223 | 1f - f
224 | }
225 | start()
226 | }
227 | }
228 | }
--------------------------------------------------------------------------------
/kbottomnavigation/src/main/java/com/hk/kbottomnavigation/Utils.kt:
--------------------------------------------------------------------------------
1 | package com.hk.kbottomnavigation
2 |
3 | import android.content.Context
4 | import android.graphics.PorterDuff
5 | import android.graphics.drawable.Drawable
6 | import android.view.View
7 | import androidx.core.content.ContextCompat
8 | import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat
9 | import java.lang.Exception
10 |
11 | /**
12 | * Created by 1HE on 2/23/2019.
13 | */
14 |
15 | private fun getDP(context: Context) = context.resources.displayMetrics.density
16 |
17 | internal fun dipf(context: Context,f: Float) = f * getDP(context)
18 |
19 | internal fun dipf(context: Context,i: Int) = i * getDP(context)
20 |
21 | internal fun dip(context: Context,i: Int) = (i * getDP(context)).toInt()
22 |
23 | internal object DrawableHelper{
24 |
25 | fun changeColorDrawableVector(c: Context?, resDrawable: Int, color: Int): Drawable? {
26 | if (c == null)
27 | return null
28 |
29 | val d = VectorDrawableCompat.create(c.resources, resDrawable, null) ?: return null
30 | d.mutate()
31 | if (color != -2)
32 | d.setColorFilter(color, PorterDuff.Mode.SRC_IN)
33 | return d
34 | }
35 |
36 | fun changeColorDrawableRes(c: Context?, resDrawable: Int, color: Int): Drawable? {
37 | if (c == null)
38 | return null
39 |
40 | val d = ContextCompat.getDrawable(c, resDrawable) ?: return null
41 | d.mutate()
42 | if (color != -2)
43 | d.setColorFilter(color, PorterDuff.Mode.SRC_IN)
44 | return d
45 | }
46 | }
47 |
48 | internal object ColorHelper{
49 |
50 | fun mixTwoColors(color1: Int, color2: Int, amount: Float): Int {
51 | val alphaChannel = 24
52 | val redChannel = 16
53 | val greenChannel = 8
54 |
55 | val inverseAmount = 1.0f - amount
56 |
57 | val a = ((color1 shr alphaChannel and 0xff).toFloat() * amount + (color2 shr alphaChannel and 0xff).toFloat() * inverseAmount).toInt() and 0xff
58 | val r = ((color1 shr redChannel and 0xff).toFloat() * amount + (color2 shr redChannel and 0xff).toFloat() * inverseAmount).toInt() and 0xff
59 | val g = ((color1 shr greenChannel and 0xff).toFloat() * amount + (color2 shr greenChannel and 0xff).toFloat() * inverseAmount).toInt() and 0xff
60 | val b = ((color1 and 0xff).toFloat() * amount + (color2 and 0xff).toFloat() * inverseAmount).toInt() and 0xff
61 |
62 | return a shl alphaChannel or (r shl redChannel) or (g shl greenChannel) or b
63 | }
64 | }
65 |
66 | internal fun Context.getDrawableCompat(res: Int) = ContextCompat.getDrawable(this, res)
67 |
68 | internal inline fun T.runAfterDelay(delay: Long, crossinline f: T.() -> Unit) {
69 | this?.postDelayed({
70 | try { f() }catch (e:Exception){}
71 | }, delay)
72 | }
73 |
--------------------------------------------------------------------------------
/kbottomnavigation/src/main/res/layout/meow_navigation_cell.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
10 |
11 |
19 |
20 |
27 |
28 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/kbottomnavigation/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/kbottomnavigation/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | MeowBottomNavigation
3 |
4 |
--------------------------------------------------------------------------------
/resources/meow-bottom-navigation-low.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hamzaahmedkhan/KBottomNavigation/45a7da2bb4fc42f5940f2ed177a884e61d5e6cf5/resources/meow-bottom-navigation-low.jpg
--------------------------------------------------------------------------------
/resources/meow-bottom-navigation-normal.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hamzaahmedkhan/KBottomNavigation/45a7da2bb4fc42f5940f2ed177a884e61d5e6cf5/resources/meow-bottom-navigation-normal.gif
--------------------------------------------------------------------------------
/resources/meow-bottom-navigation-small.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hamzaahmedkhan/KBottomNavigation/45a7da2bb4fc42f5940f2ed177a884e61d5e6cf5/resources/meow-bottom-navigation-small.gif
--------------------------------------------------------------------------------
/resources/meow-bottom-navigation.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hamzaahmedkhan/KBottomNavigation/45a7da2bb4fc42f5940f2ed177a884e61d5e6cf5/resources/meow-bottom-navigation.gif
--------------------------------------------------------------------------------
/sample/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/sample/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 | compileSdkVersion 29
9 | buildToolsVersion "29.0.2"
10 | defaultConfig {
11 | applicationId "com.github.kbottomnavigation"
12 | minSdkVersion 21
13 | targetSdkVersion 29
14 | versionCode 1
15 | versionName "1.0"
16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17 | }
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 | }
25 |
26 | dependencies {
27 | implementation fileTree(dir: 'libs', include: ['*.jar'])
28 | implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
29 | implementation 'androidx.appcompat:appcompat:1.1.0'
30 | implementation 'androidx.core:core-ktx:1.1.0'
31 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
32 | testImplementation 'junit:junit:4.12'
33 | androidTestImplementation 'androidx.test.ext:junit:1.1.0'
34 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
35 |
36 | implementation project(':kbottomnavigation')
37 | }
38 |
--------------------------------------------------------------------------------
/sample/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 |
--------------------------------------------------------------------------------
/sample/src/androidTest/java/com/hk/kbottomnavigation/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.hk.kbottomnavigation
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.github.kbottomnavigation", appContext.packageName)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/sample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/sample/src/main/assets/fonts/SourceSansPro-Regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hamzaahmedkhan/KBottomNavigation/45a7da2bb4fc42f5940f2ed177a884e61d5e6cf5/sample/src/main/assets/fonts/SourceSansPro-Regular.ttf
--------------------------------------------------------------------------------
/sample/src/main/assets/fonts/SourceSansPro-SemiBold.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hamzaahmedkhan/KBottomNavigation/45a7da2bb4fc42f5940f2ed177a884e61d5e6cf5/sample/src/main/assets/fonts/SourceSansPro-SemiBold.ttf
--------------------------------------------------------------------------------
/sample/src/main/java/com/hk/kbottomnavigation/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.hk.kbottomnavigation
2 | import android.graphics.Typeface
3 | import android.os.Bundle
4 | import androidx.appcompat.app.AppCompatActivity
5 | import kotlinx.android.synthetic.main.activity_main.*
6 |
7 | class MainActivity : AppCompatActivity() {
8 |
9 | companion object {
10 | private const val ID_HOME = 1
11 | private const val ID_EXPLORE = 2
12 | private const val ID_MESSAGE = 3
13 | private const val ID_NOTIFICATION = 4
14 | private const val ID_ACCOUNT = 5
15 | }
16 |
17 | // @SuppressLint("NewApi")
18 | // @RequiresApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
19 | // @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
20 | // override fun attachBaseContext(newBase: Context?) {
21 | // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
22 | // super.attachBaseContext(MyContextWrapper.wrap(newBase, "fa"))
23 | // } else {
24 | // super.attachBaseContext(newBase)
25 | // }
26 | // }
27 |
28 | override fun onCreate(savedInstanceState: Bundle?) {
29 | super.onCreate(savedInstanceState)
30 | setContentView(R.layout.activity_main)
31 |
32 | tv_selected.typeface = Typeface.createFromAsset(assets, "fonts/SourceSansPro-Regular.ttf")
33 |
34 | bottomNavigation.add(KBottomNavigation.Model(ID_HOME, R.drawable.ic_home))
35 | bottomNavigation.add(KBottomNavigation.Model(ID_EXPLORE, R.drawable.ic_explore))
36 | bottomNavigation.add(KBottomNavigation.Model(ID_MESSAGE, R.drawable.ic_message))
37 | bottomNavigation.add(KBottomNavigation.Model(ID_NOTIFICATION, R.drawable.ic_notification))
38 | bottomNavigation.add(KBottomNavigation.Model(ID_ACCOUNT, R.drawable.ic_account))
39 |
40 | bottomNavigation.setCount(ID_NOTIFICATION, "115")
41 |
42 | bottomNavigation.setOnShowListener {
43 | val name = when (it.id) {
44 | ID_HOME -> "HOME"
45 | ID_EXPLORE -> "EXPLORE"
46 | ID_MESSAGE -> "MESSAGE"
47 | ID_NOTIFICATION -> "NOTIFICATION"
48 | ID_ACCOUNT -> "ACCOUNT"
49 | else -> ""
50 | }
51 | tv_selected.text = "$name page is selected"
52 | }
53 |
54 | bottomNavigation.setOnClickMenuListener {
55 | val name = when (it.id) {
56 | ID_HOME -> "HOME"
57 | ID_EXPLORE -> "EXPLORE"
58 | ID_MESSAGE -> "MESSAGE"
59 | ID_NOTIFICATION -> "NOTIFICATION"
60 | ID_ACCOUNT -> "ACCOUNT"
61 | else -> ""
62 | }
63 | // Toast.makeText(this, "$name is clicked", Toast.LENGTH_SHORT).show()
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/hk/kbottomnavigation/MyContextWrapper.kt:
--------------------------------------------------------------------------------
1 | package com.hk.kbottomnavigation
2 |
3 | import android.annotation.SuppressLint
4 | import android.annotation.TargetApi
5 | import android.content.Context
6 | import android.content.ContextWrapper
7 | import android.content.res.Configuration
8 | import android.os.Build
9 | import androidx.annotation.RequiresApi
10 | import java.util.*
11 |
12 | @Suppress("DEPRECATION", "unused")
13 | class MyContextWrapper(base: Context) : ContextWrapper(base) {
14 |
15 | companion object {
16 |
17 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
18 | @RequiresApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
19 | @SuppressLint("ObsoleteSdkInt")
20 | fun wrap(contextParam: Context?, language: String): ContextWrapper? {
21 | var context = contextParam ?: return null
22 | val config = context.resources.configuration
23 | if (language != "") {
24 | val locale = Locale(language)
25 | Locale.setDefault(locale)
26 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
27 | setSystemLocale(config, locale)
28 | } else {
29 | setSystemLocaleLegacy(config, locale)
30 | }
31 | config.setLayoutDirection(locale)
32 | }
33 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
34 | context = context.createConfigurationContext(config)
35 | } else {
36 | context.resources.updateConfiguration(config, context.resources.displayMetrics)
37 | }
38 | return MyContextWrapper(context)
39 | }
40 |
41 | private fun getSystemLocaleLegacy(config: Configuration): Locale {
42 | return config.locale
43 | }
44 |
45 | @TargetApi(Build.VERSION_CODES.N)
46 | private fun getSystemLocale(config: Configuration): Locale {
47 | return config.locales.get(0)
48 | }
49 |
50 | private fun setSystemLocaleLegacy(config: Configuration, locale: Locale) {
51 | config.locale = locale
52 | }
53 |
54 | @TargetApi(Build.VERSION_CODES.N)
55 | private fun setSystemLocale(config: Configuration, locale: Locale) {
56 | config.setLocale(locale)
57 | }
58 | }
59 | }
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xxhdpi/img_meow_large.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hamzaahmedkhan/KBottomNavigation/45a7da2bb4fc42f5940f2ed177a884e61d5e6cf5/sample/src/main/res/drawable-xxhdpi/img_meow_large.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/ic_account.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/ic_explore.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/ic_home.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
10 |
12 |
14 |
16 |
18 |
20 |
22 |
24 |
26 |
28 |
30 |
32 |
34 |
36 |
38 |
40 |
42 |
44 |
46 |
48 |
50 |
52 |
54 |
56 |
58 |
60 |
62 |
64 |
66 |
68 |
70 |
72 |
74 |
75 |
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/ic_message.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/ic_notification.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/tekrevol_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hamzaahmedkhan/KBottomNavigation/45a7da2bb4fc42f5940f2ed177a884e61d5e6cf5/sample/src/main/res/drawable/tekrevol_logo.png
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
19 |
20 |
28 |
29 |
30 |
31 |
44 |
45 |
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hamzaahmedkhan/KBottomNavigation/45a7da2bb4fc42f5940f2ed177a884e61d5e6cf5/sample/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hamzaahmedkhan/KBottomNavigation/45a7da2bb4fc42f5940f2ed177a884e61d5e6cf5/sample/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hamzaahmedkhan/KBottomNavigation/45a7da2bb4fc42f5940f2ed177a884e61d5e6cf5/sample/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hamzaahmedkhan/KBottomNavigation/45a7da2bb4fc42f5940f2ed177a884e61d5e6cf5/sample/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hamzaahmedkhan/KBottomNavigation/45a7da2bb4fc42f5940f2ed177a884e61d5e6cf5/sample/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hamzaahmedkhan/KBottomNavigation/45a7da2bb4fc42f5940f2ed177a884e61d5e6cf5/sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hamzaahmedkhan/KBottomNavigation/45a7da2bb4fc42f5940f2ed177a884e61d5e6cf5/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hamzaahmedkhan/KBottomNavigation/45a7da2bb4fc42f5940f2ed177a884e61d5e6cf5/sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hamzaahmedkhan/KBottomNavigation/45a7da2bb4fc42f5940f2ed177a884e61d5e6cf5/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hamzaahmedkhan/KBottomNavigation/45a7da2bb4fc42f5940f2ed177a884e61d5e6cf5/sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #18c0d4
4 | #18c0d4
5 | #D81B60
6 |
7 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | KBottomNavigation
3 |
4 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/sample/src/test/java/com/hk/kbottomnavigation/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.hk.kbottomnavigation
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':sample', ':kbottomnavigation'
2 | rootProject.name='KBottomNavigation'
3 |
--------------------------------------------------------------------------------