Coder Social home page Coder Social logo

kotlin-vs-java's Introduction

kotlin-vs-java

#####A simple example to show Kotlin vs Java code in Android

See MainActivity vs MainActivityJava to compare funtionally equivalent implementations of an activity with some very basic animations. This example demonstrations how Kotlin extensions, higher-order functions, and Anko combine to provide really powerful features with concise syntax.

Provided are examples of View extensions, Animator extensions, and Context extensions. Additionally, there are examples of using single-line functions and higher-order functions.

Here's the content of the Kotlin MainActivity for convenience:

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        button.backgroundCircle(R.color.colorAccent)

        runDelayed(2000) { button.alphaAnimator(0f, 1f, 500).start() }
        atleastLollipop { button.onClick { reveal() } }
    }

    fun reveal() {
        overlay.circularRevealAnimator(centerX(), centerY(), 300)
            .animationEnd { button.onClick { hide() } }
            .start()
    }

    fun hide() {
        overlay.circularHideAnimator(centerX(), centerY(), 300)
            .animationEnd { button.onClick { reveal() } }
            .start()
    }

    fun centerX() = overlay.width / 2

    fun centerY() = overlay.height / 2
}

kotlin-vs-java's People

Contributors

jayohms avatar

Watchers

James Cloos avatar  avatar

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.