Giter VIP home page Giter VIP logo

android-ktx's Introduction

Android KTX

A set of Kotlin extensions for Android app development. The goal of Android KTX is to make Android development with Kotlin more concise, pleasant, and idiomatic by leveraging the features of the language such as extension functions/properties, lambdas, named parameters, and parameter defaults. It is an explicit goal of this project to not add any new features to the existing Android APIs.

Kotlin:

val uri = Uri.parse(myUriString)

Kotlin with Android KTX:

val uri = myUriString.toUri()

Kotlin:

sharedPreferences.edit()
    .putBoolean("key", value)
    .apply()

Kotlin with Android KTX:

sharedPreferences.edit {
    putBoolean("key", value)
}

Kotlin:

val pathDifference = Path(myPath1).apply {
    op(myPath2, Path.Op.DIFFERENCE)
}

canvas.apply {
  val checkpoint = save()
  translate(0F, 100F)
  drawPath(pathDifference, myPaint)
  restoreToCount(checkpoint)
}

Kotlin with Android KTX:

val pathDifference = myPath1 - myPath2

canvas.withTranslation(y = 100F) {
    drawPath(pathDifference, myPaint)
}

Kotlin:

view.viewTreeObserver.addOnPreDrawListener(
    object : ViewTreeObserver.OnPreDrawListener {
        override fun onPreDraw(): Boolean {
            viewTreeObserver.removeOnPreDrawListener(this)
            actionToBeTriggered()
            return true
        }
    })

Kotlin with Android KTX:

view.doOnPreDraw {
     actionToBeTriggered()
}

Getting Started

To add Android KTX to your project, add the following to your app module's build.gradle:

repositories {
    google()
}

dependencies {
    implementation 'androidx.core:core-ktx:1.0.0-alpha1'
}

Then, in your Kotlin files where you'd like to use the extensions, import the appropriate packages.

Project Status

This project is currently in preview, and we are seeking feedback from the community. We encourage you to try Android KTX so you can suggest ideas and report issues. Please see the "How to Contribute" section if you would like to contribute.

During the preview period, the Android KTX APIs may change at anytime. When the project reaches a stable state, we will update it to version 1.0 (or later). From that point forward, we will be much more rigorous and careful about maintaining API compatibility.

This project does not currently cover the Android Support Library or Architecture Components APIs.

Links

How to Contribute

We welcome your contributions to this project. There are various ways to contribute:

Reporting issues

Help improve the project by reporting issues that you find by filing a new issue at the Android KTX issue tracker.

Features suggestions

You can also add feature suggestions by filing a new issue at the Android KTX issue tracker.

Documentation

You can help by adding or improving existing documentation. Simply send us a pull request for us to consider your proposed changes.

Bug fixes

Pull requests are welcome for minor bug fixes that do not involve any changes to existing API. These changes should ideally be accompanied by a test case that would have otherwise failed without the fix.

New API or API changes

Pull requests for new APIs or changes to existing APIs are welcome, but may require a bit of discussion. Consider creating an issue to discuss any changes before you implement the change.

Before submitting,

  • If you are making an API change, run ./gradlew updateApi and commit any changes in the api/ directory.
  • Check that lint, unit tests, and code style enforcement all pass by running ./gradlew check.
  • Check that instrumentation tests pass by starting an API 26 or newer emulator and running ./gradlew connectedCheck

Note: First-time contributors to a Google or Android project will be required to sign a CLA.

License

Copyright 2018 The Android Open Source Project

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.

android-ktx's People

Contributors

ataulm avatar chrisbanes avatar dsteve595 avatar florina-muntenescu avatar hendraanggrian avatar hluhovskyi avatar jakewharton avatar jaredsburrows avatar jawnnypoo avatar jitinsharma avatar jmslau avatar jutikorn avatar jzoran avatar landerlyoung avatar louiscad avatar mattprecious avatar mightyfrog avatar panpanini avatar ramv13 avatar romainguy avatar romtsn avatar sathawale27 avatar savinmike avatar shyiko avatar simonschiller avatar tiembo avatar toshihirooya avatar tougee avatar umang91 avatar yanglinzhen avatar

Watchers

 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.