• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.airbnb.lottie.samples
2 
3 import android.os.Bundle
4 import android.view.MenuItem
5 import androidx.appcompat.app.AppCompatActivity
6 import androidx.appcompat.app.AppCompatDelegate
7 import androidx.browser.customtabs.CustomTabsIntent
8 import androidx.core.net.toUri
9 import androidx.fragment.app.Fragment
10 import com.google.android.material.bottomnavigation.BottomNavigationView
11 import kotlinx.android.synthetic.main.activity_main.*
12 
13 class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemSelectedListener {
onCreatenull14     override fun onCreate(savedInstanceState: Bundle?) {
15         AppCompatDelegate.setCompatVectorFromResourcesEnabled(true)
16         super.onCreate(savedInstanceState)
17         setContentView(R.layout.activity_main)
18         bottomNavigation.setOnNavigationItemSelectedListener(this)
19 
20         savedInstanceState ?: showFragment(ShowcaseFragment())
21     }
22 
onNavigationItemSelectednull23     override fun onNavigationItemSelected(item: MenuItem): Boolean {
24         when (item.itemId) {
25             R.id.showcase -> showFragment(ShowcaseFragment())
26             R.id.preview -> showFragment(PreviewFragment())
27             R.id.lottiefiles -> showFragment(LottiefilesFragment())
28             R.id.learn -> showShowcase()
29             else -> return false
30         }
31         return true
32     }
33 
showShowcasenull34     private fun showShowcase() {
35         val intent = CustomTabsIntent.Builder().build()
36         intent.launchUrl(this, "http://airbnb.io/lottie/#/android".toUri())
37     }
38 
showFragmentnull39     private fun showFragment(fragment: Fragment) {
40         supportFragmentManager.beginTransaction()
41                 .replace(R.id.content, fragment)
42                 .commit()
43     }
44 }
45