Giter VIP home page Giter VIP logo

material-drawer-with-kotlin's Introduction

Material_drawer_with_Kotlin

My first project start with new language Kotlin

Ansible Role


# Screenshot MainActivity :

MainActivity

Detail Activity


Social Media

Soussi Mohamed Soussi Mohamed

Licence

Copyright 2017 Soussidev, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

material-drawer-with-kotlin's People

Contributors

datalink747 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

ricots

material-drawer-with-kotlin's Issues

Screenshot

Material Drawer coding with Kotlin


`class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener {
private var viewPager: ViewPager? = null
private var tabLayout: TabLayout? = null


override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    val toolbar = findViewById(R.id.toolbar) as Toolbar?
    setSupportActionBar(toolbar)





    supportActionBar!!.setDisplayHomeAsUpEnabled(true)
    supportActionBar!!.setDisplayShowHomeEnabled(true)

    setupWindowAnimations() // func for animation here

    viewPager = findViewById(R.id.viewpager) as ViewPager?
    tabLayout = findViewById(R.id.tabs1) as TabLayout?

    val fab = findViewById(R.id.fab) as FloatingActionButton?
    fab!!.setOnClickListener { view ->
        Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)

                .setAction("Retour") { Toast.makeText(this@MainActivity, "Retour", Toast.LENGTH_SHORT).show() }.show()
    }

    val drawer = findViewById(R.id.drawer_layout) as DrawerLayout?
    val toggle = ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close)
    drawer!!.setDrawerListener(toggle)
    toggle.syncState()

    val navigationView = findViewById(R.id.nav_view) as NavigationView?
    navigationView!!.setNavigationItemSelectedListener(this)

    //on remplit notre viewpager

    viewPager!!.adapter = object : FragmentPagerAdapter(supportFragmentManager) {
        override fun getItem(position: Int): Fragment? {

            var f: Fragment? = null
            when (position) {
                0 -> f = RecyclerViewFragment.newInstance()
                1 -> f = PlusOneFragment.newInstance()
                2 -> f = RecyclerViewFragment.newInstance()
                3 -> f = RecyclerViewFragment.newInstance()
            }

            return f
        }


        override fun getPageTitle(position: Int): CharSequence {
            var tab_name = ""

            when (position) {
                0 -> tab_name = "tab n 1"
                1 -> tab_name = "tab n 2"
                2 -> tab_name = "tab n 3"
                3 -> tab_name = "tab n 4"
            }
            return tab_name
        }

        override fun getCount(): Int {
            return 4
        }
    }

    //indique au tablayout quel est le viewpager à écouter
    tabLayout!!.setupWithViewPager(viewPager)


}

//animation for window
private fun setupWindowAnimations() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

        val explode = Explode()
        window.exitTransition = explode

        val fade = Fade()
        window.reenterTransition = fade
    }
}

override fun onBackPressed() {
    val drawer = findViewById(R.id.drawer_layout) as DrawerLayout?
    if (drawer!!.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START)
    } else {
        super.onBackPressed()
    }
}

override fun onCreateOptionsMenu(menu: Menu): Boolean {
    // Inflate the menu; this adds items to the action bar if it is present.
    menuInflater.inflate(R.menu.main, menu)
    return true
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    val id = item.itemId


    if (id == R.id.action_settings) {
        return true
    }

    return super.onOptionsItemSelected(item)
}

override fun onNavigationItemSelected(item: MenuItem): Boolean {
    // Handle navigation view item clicks here.
    val id = item.itemId

    if (id == R.id.nav_camara) {
        // Handle the camera action
        Toast.makeText(this@MainActivity, "camera here", Toast.LENGTH_SHORT).show()
    } else if (id == R.id.nav_gallery) {

    } else if (id == R.id.nav_slideshow) {

    } else if (id == R.id.nav_manage) {

    } else if (id == R.id.nav_share) {

    } else if (id == R.id.nav_send) {

    }

    val drawer = findViewById(R.id.drawer_layout) as DrawerLayout?
    drawer!!.closeDrawer(GravityCompat.START)
    return true
}

}`

Screenshot MainActivity :

material_drawer_kotlin1

Screenshot DetailActivity :

material_drawer_kotlin2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.