├── .gitignore ├── .idea ├── caches │ └── build_file_checksums.ser ├── codeStyles │ └── Project.xml ├── encodings.xml ├── gradle.xml ├── kotlinc.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── io │ │ └── armcha │ │ └── playtabs │ │ ├── LauncherActivity.kt │ │ ├── RegularActivity.kt │ │ ├── SampleFragment.kt │ │ ├── TabAdapter.kt │ │ └── WithIconActivity.kt │ └── res │ ├── drawable │ ├── android.xml │ ├── audiobook.xml │ ├── book_open_variant.xml │ ├── filmstrip.xml │ ├── google_play.xml │ ├── heart.xml │ └── ic_launcher_background.xml │ ├── layout │ ├── activity_launcher.xml │ ├── activity_main.xml │ ├── activity_with_icon.xml │ └── fragment_sample.xml │ ├── mipmap-anydpi-v26 │ ├── ic_launcher.xml │ └── ic_launcher_round.xml │ ├── mipmap-hdpi │ ├── ic_launcher.png │ ├── ic_launcher_foreground.png │ └── ic_launcher_round.png │ ├── mipmap-mdpi │ ├── ic_launcher.png │ ├── ic_launcher_foreground.png │ └── ic_launcher_round.png │ ├── mipmap-xhdpi │ ├── ic_launcher.png │ ├── ic_launcher_foreground.png │ └── ic_launcher_round.png │ ├── mipmap-xxhdpi │ ├── ic_launcher.png │ ├── ic_launcher_foreground.png │ └── ic_launcher_round.png │ ├── mipmap-xxxhdpi │ ├── ic_launcher.png │ ├── ic_launcher_foreground.png │ └── ic_launcher_round.png │ └── values │ ├── colors.xml │ ├── strings.xml │ └── styles.xml ├── art ├── app.apk ├── regular.gif └── witIcon.gif ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── playtablayout ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── io │ │ └── armcha │ │ └── playtablayout │ │ ├── common │ │ ├── AnimationListenerInternal.kt │ │ ├── Extensions.kt │ │ ├── TypeAlias.kt │ │ └── ViewExtensions.kt │ │ └── core │ │ ├── PlayTabLayout.kt │ │ └── TouchableTabLayout.kt │ └── res │ └── values │ ├── dimens.xml │ ├── strings.xml │ └── values.xml └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/caches/build_file_checksums.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armcha/PlayTabLayout/fa17f00fd5cf5d5e17c0ba2de6c60414e4443eec/.idea/caches/build_file_checksums.ser -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 15 | 16 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/kotlinc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 37 | 38 | 39 | 40 | 41 | 42 | 44 | 45 | 46 | 47 | 48 | 1.8 49 | 50 | 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PlayTabLayout 2 | 3 | PlayTabLayout is a tab layout very similar to Google Play tab layout. The main feature is that ripple shows in a particular place where user taps. 4 | 5 | ![](art/regular.gif)
6 | ![](art/witIcon.gif) 7 | 8 | The current minSDK version is API level 16. 9 | 10 | ### Download 11 | ----------------------- 12 | 13 | Gradle: 14 | ```groovy 15 | implementation 'com.github.armcha:PlayTabLayout:2.0.0' 16 | ``` 17 | 18 | ### Download sample [apk](https://github.com/armcha/PlayTabLayout/tree/master/art/app.apk) 19 | 20 | ## Setup and usage 21 | 22 | 1. Add AutoLinkTextView to your layout 23 | ```xml 24 | 28 | ``` 29 | 30 | 2. Add tab colors 31 | 32 | ```kotlin 33 | playTabLayout.colors = intArrayOf( 34 | R.color.f, 35 | R.color.s, 36 | R.color.t, 37 | R.color.four) 38 | ``` 39 | 40 | ### Note: array must be the same size as your adapter item count 41 | 42 | 3. And you can use it like a regular tab layout 43 | 44 | ```kotlin 45 | viewPager.adapter = TabAdapter(supportFragmentManager) 46 | val tabLayout = playTabLayout.tabLayout 47 | tabLayout.setupWithViewPager(viewPager) 48 | ``` 49 | ### Current limitations: 50 | You can't set 51 | ```java 52 | tabMode="scrollable" 53 | ``` 54 | and 55 | ```java 56 | tabGravity="center" 57 | ``` 58 | 59 | ## Contact 60 | 61 | Pull requests are more than welcome. 62 | 63 | - **Email**: chatikyana@gmail.com 64 | - **Twitter**: https://twitter.com/ArmanChatikyan 65 | - **Google +**: https://plus.google.com/+ArmanChatikyan 66 | - **Website**: https://armcha.github.io/ 67 | - **Medium**: https://medium.com/@chatikyan 68 | 69 | License 70 | -------- 71 | 72 | PlayTabLayout 73 | Copyright (c) 2018 Arman Chatikyan (https://github.com/armcha/PlayTabLayout). 74 | 75 | Licensed under the Apache License, Version 2.0 (the "License"); 76 | you may not use this file except in compliance with the License. 77 | You may obtain a copy of the License at 78 | 79 | http://www.apache.org/licenses/LICENSE-2.0 80 | 81 | Unless required by applicable law or agreed to in writing, software 82 | distributed under the License is distributed on an "AS IS" BASIS, 83 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 84 | See the License for the specific language governing permissions and 85 | limitations under the License. 86 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | apply plugin: 'kotlin-android' 4 | 5 | apply plugin: 'kotlin-android-extensions' 6 | 7 | android { 8 | compileSdkVersion 28 9 | defaultConfig { 10 | applicationId "io.armcha.playtabs" 11 | minSdkVersion 16 12 | targetSdkVersion 28 13 | versionCode 1 14 | versionName "1.0" 15 | vectorDrawables.useSupportLibrary = true 16 | } 17 | buildTypes { 18 | release { 19 | minifyEnabled false 20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 21 | } 22 | } 23 | lintOptions { 24 | abortOnError false 25 | } 26 | } 27 | 28 | dependencies { 29 | implementation fileTree(dir: 'libs', include: ['*.jar']) 30 | implementation 'com.android.support:appcompat-v7:28.0.0' 31 | implementation 'com.android.support:support-v4:28.0.0' 32 | implementation 'com.android.support:design:28.0.0' 33 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' 34 | implementation 'com.android.support:support-v4:28.0.0' 35 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 36 | implementation project(':playtablayout') 37 | } 38 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/java/io/armcha/playtabs/LauncherActivity.kt: -------------------------------------------------------------------------------- 1 | package io.armcha.playtabs 2 | 3 | import android.content.Intent 4 | import android.support.v7.app.AppCompatActivity 5 | import android.os.Bundle 6 | import android.support.design.widget.TabLayout 7 | import kotlinx.android.synthetic.main.activity_launcher.* 8 | 9 | class LauncherActivity : AppCompatActivity() { 10 | 11 | override fun onCreate(savedInstanceState: Bundle?) { 12 | super.onCreate(savedInstanceState) 13 | setContentView(R.layout.activity_launcher) 14 | 15 | regular.setOnClickListener { 16 | startActivity(Intent(this, RegularActivity::class.java)) 17 | } 18 | 19 | withIcon.setOnClickListener { 20 | startActivity(Intent(this, WithIconActivity::class.java)) 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /app/src/main/java/io/armcha/playtabs/RegularActivity.kt: -------------------------------------------------------------------------------- 1 | package io.armcha.playtabs 2 | 3 | import android.graphics.Color 4 | import android.os.Bundle 5 | import android.support.v4.content.ContextCompat 6 | import android.support.v7.app.AppCompatActivity 7 | import kotlinx.android.synthetic.main.activity_main.* 8 | 9 | 10 | class RegularActivity : AppCompatActivity() { 11 | 12 | override fun onCreate(savedInstanceState: Bundle?) { 13 | super.onCreate(savedInstanceState) 14 | setContentView(R.layout.activity_main) 15 | 16 | playTabLayout.colors = intArrayOf( 17 | R.color.f, 18 | R.color.s, 19 | R.color.t, 20 | R.color.four) 21 | 22 | viewPager.adapter = TabAdapter(supportFragmentManager,playTabLayout.colors.size) 23 | 24 | with(playTabLayout.tabLayout) { 25 | setupWithViewPager(viewPager) 26 | setSelectedTabIndicatorHeight(7) 27 | setSelectedTabIndicatorColor(Color.WHITE) 28 | setTabTextColors(ContextCompat.getColor(this@RegularActivity, R.color.unselected_tab_color), Color.WHITE) 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/java/io/armcha/playtabs/SampleFragment.kt: -------------------------------------------------------------------------------- 1 | package io.armcha.playtabs 2 | 3 | 4 | import android.os.Bundle 5 | import android.support.v4.app.Fragment 6 | import android.view.LayoutInflater 7 | import android.view.View 8 | import android.view.ViewGroup 9 | 10 | 11 | class SampleFragment : Fragment() { 12 | 13 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, 14 | savedInstanceState: Bundle?): View? { 15 | return inflater.inflate(R.layout.fragment_sample, container, false) 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /app/src/main/java/io/armcha/playtabs/TabAdapter.kt: -------------------------------------------------------------------------------- 1 | package io.armcha.playtabs 2 | 3 | import android.support.v4.app.FragmentManager 4 | import android.support.v4.app.FragmentPagerAdapter 5 | 6 | /** 7 | * Created by arman.chatikyan on 10/4/2017. 8 | */ 9 | class TabAdapter(fragmentManager: FragmentManager,private val count:Int) : FragmentPagerAdapter(fragmentManager) { 10 | 11 | override fun getItem(position: Int) = SampleFragment() 12 | 13 | override fun getCount() = count 14 | 15 | override fun getPageTitle(position: Int) = when (position) { 16 | 0 -> "Music" 17 | 1 -> "Market" 18 | 2 -> "Films" 19 | 3 -> "Books" 20 | else -> "Android" 21 | } 22 | } -------------------------------------------------------------------------------- /app/src/main/java/io/armcha/playtabs/WithIconActivity.kt: -------------------------------------------------------------------------------- 1 | package io.armcha.playtabs 2 | 3 | import android.graphics.Color 4 | import android.graphics.PorterDuff 5 | import android.graphics.drawable.Drawable 6 | import android.os.Bundle 7 | import android.support.design.widget.TabLayout 8 | import android.support.v4.content.ContextCompat 9 | import android.support.v7.app.AppCompatActivity 10 | import io.armcha.playtablayout.core.TouchableTabLayout 11 | import kotlinx.android.synthetic.main.activity_main.* 12 | 13 | class WithIconActivity : AppCompatActivity(), TouchableTabLayout.OnTabSelectedListener { 14 | 15 | override fun onCreate(savedInstanceState: Bundle?) { 16 | super.onCreate(savedInstanceState) 17 | setContentView(R.layout.activity_with_icon) 18 | 19 | playTabLayout.colors = intArrayOf(R.color.f, 20 | R.color.s, 21 | R.color.t, 22 | R.color.four, 23 | R.color.colorPrimary) 24 | 25 | val tabLayout = playTabLayout.tabLayout 26 | viewPager.adapter = TabAdapter(supportFragmentManager,playTabLayout.colors.size) 27 | 28 | with(tabLayout) { 29 | setupWithViewPager(viewPager) 30 | setSelectedTabIndicatorHeight(7) 31 | setSelectedTabIndicatorColor(Color.WHITE) 32 | tabMode = TabLayout.MODE_FIXED 33 | tabGravity = TabLayout.GRAVITY_FILL 34 | setTabTextColors(ContextCompat.getColor(this@WithIconActivity, R.color.unselected_tab_color), Color.WHITE) 35 | addOnTabSelectedListener(this@WithIconActivity) 36 | } 37 | 38 | fun icon(index: Int, drawableId: Int) { 39 | tabLayout.getTabAt(index)?.setIcon(drawableId) 40 | } 41 | icon(0, R.drawable.audiobook) 42 | icon(1, R.drawable.google_play) 43 | icon(2, R.drawable.filmstrip) 44 | icon(3, R.drawable.book_open_variant) 45 | icon(4, R.drawable.android) 46 | 47 | fun Drawable.tint(color: Int) { 48 | setColorFilter(ContextCompat.getColor(this@WithIconActivity, color), PorterDuff.Mode.SRC_IN) 49 | } 50 | (0 until (viewPager.adapter as TabAdapter).count) 51 | .map { tabLayout.getTabAt(it) } 52 | .map { it?.getIcon() } 53 | .doWhen({ it?.tint(R.color.selected_tab_color) }, { it == viewPager.currentItem }) 54 | .doWhen({ it?.tint(R.color.unselected_tab_color) }, { it != viewPager.currentItem }) 55 | } 56 | 57 | private inline fun Iterable.doWhen(body: (T) -> Unit, predicate: (Int) -> Boolean): Iterable { 58 | var index = 0 59 | return apply { 60 | for (element in this) { 61 | if (predicate(index++)) { 62 | body(element) 63 | } 64 | } 65 | } 66 | } 67 | 68 | override fun onTabSelected(tab: TouchableTabLayout.Tab) { 69 | tab.getIcon()?.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_IN) 70 | } 71 | 72 | override fun onTabUnselected(tab: TouchableTabLayout.Tab) { 73 | tab.getIcon()?.setColorFilter(ContextCompat.getColor(this, R.color.unselected_tab_color), PorterDuff.Mode.SRC_IN); 74 | } 75 | 76 | override fun onTabReselected(tab: TouchableTabLayout.Tab) { 77 | } 78 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable/android.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/audiobook.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/book_open_variant.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/filmstrip.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/google_play.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/heart.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 12 | 17 | 22 | 27 | 32 | 37 | 42 | 47 | 52 | 57 | 62 | 67 | 72 | 77 | 82 | 87 | 92 | 97 | 102 | 107 | 112 | 113 | 114 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 |