{"id":3733,"url":"https://github.com/pawegio/KAndroid","last_synced_at":"2025-08-03T22:32:13.639Z","repository":{"id":29410963,"uuid":"32946447","full_name":"pawegio/KAndroid","owner":"pawegio","description":"Kotlin library for Android","archived":false,"fork":false,"pushed_at":"2024-08-02T11:56:11.000Z","size":1387,"stargazers_count":896,"open_issues_count":6,"forks_count":81,"subscribers_count":31,"default_branch":"master","last_synced_at":"2024-08-16T15:39:41.283Z","etag":null,"topics":["android","kotlin","kotlin-android","kotlin-extensions","kotlin-library"],"latest_commit_sha":null,"homepage":null,"language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pawegio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-03-26T19:03:16.000Z","updated_at":"2024-08-16T06:13:24.000Z","dependencies_parsed_at":"2022-08-19T02:01:27.294Z","dependency_job_id":null,"html_url":"https://github.com/pawegio/KAndroid","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pawegio%2FKAndroid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pawegio%2FKAndroid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pawegio%2FKAndroid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pawegio%2FKAndroid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pawegio","download_url":"https://codeload.github.com/pawegio/KAndroid/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228571844,"owners_count":17938772,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","kotlin","kotlin-android","kotlin-extensions","kotlin-library"],"created_at":"2024-01-05T20:16:49.881Z","updated_at":"2024-12-07T06:30:48.198Z","avatar_url":"https://github.com/pawegio.png","language":"Kotlin","funding_links":[],"categories":["Libraries","Kotlin","开源库和框架","Development Alternatives","\u003ca name=\"android\"\u003e\u003c/a\u003eAndroid \u003csup\u003e[Back ⇈](#android-category)\u003c/sup\u003e","开源库","\u003ca name=\"utility\"\u003e\u003c/a\u003eUtility \u003csup\u003e[Back ⇈](#contents)\u003c/sup\u003e","[](https://github.com/JStumpp/awesome-android/blob/master/readme.md#development-alternatives)非Java开发安卓应用"],"sub_categories":["Android","Android 开发","Kotlin","\u003ca name=\"android-libraries\"\u003e\u003c/a\u003eLibraries \u003csup\u003e[Back ⇈](#android-libraries-subcategory)\u003c/sup\u003e","扩展","[](https://github.com/JStumpp/awesome-android/blob/master/readme.md#kotlin)Kotlin"],"readme":"[ ![Download](https://api.bintray.com/packages/pawegio/maven/com.pawegio.kandroid%3Akandroid/images/download.svg) ](https://bintray.com/pawegio/maven/com.pawegio.kandroid%3Akandroid/_latestVersion) [![Build Status](https://travis-ci.org/pawegio/KAndroid.svg?branch=master)](https://travis-ci.org/pawegio/KAndroid) [![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/pawegio/KAndroid.svg)](http://isitmaintained.com/project/pawegio/KAndroid \"Average time to resolve an issue\") [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-KAndroid-brightgreen.svg?style=flat)](http://android-arsenal.com/details/1/1705) [![](https://img.shields.io/badge/AndroidWeekly-%23148-blue.svg)](http://androidweekly.net/issues/issue-148) \u003ca href=\"http://www.methodscount.com/?lib=com.pawegio.kandroid%3Akandroid%3A0.8.3\"\u003e\u003cimg src=\"https://img.shields.io/badge/Methods count-407-e91e63.svg\"/\u003e\u003c/a\u003e\n\n# KAndroid\n\u003cimg src=\"art/logo.png\" width=\"160px\"\u003e\n\nKotlin library for Android providing useful extensions to eliminate boilerplate code in Android SDK and focus on productivity.\n\nDownload\n--------\n\nDownload latest version with Gradle:\n```groovy\nallprojects { \n    repositories {\n        maven { url \"https://jitpack.io\" }\n    }\n}\n\ndependencies {\n    implementation 'com.github.pawegio:KAndroid:0.8.7@aar'\n}\n```\n\nUsage\n-----\n#### Binding views\n```kotlin\n// instead of findViewById(R.id.textView) as TextView\nval textView = find\u003cTextView\u003e(R.id.textView)\n```\n#### Accessing ViewGroup children\n```kotlin\n/* instead of:\nfor (i in 0..layout - 1) {\n    layout.getChildAt(i).visibility = View.GONE\n}\n*/\nlayout.views.forEach { it.visibility = View.GONE }\n```\n#### TextWatcher\n```kotlin\n/* instead of:\neditText.addTextChangedListener(object : TextWatcher {\n    override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {\n        before()\n    }\n    override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {\n        onChange()\n    }\n    override fun afterTextChanged(s: Editable?) {\n        after()\n    }\n}) */\neditText.textWatcher {\n    beforeTextChanged { text, start, count, after -\u003e before() }\n    onTextChanged { text, start, before, count -\u003e onChange() }\n    afterTextChanged { text -\u003e after() }\n}\n```\n\n#### SearchView extensions\n```kotlin\n/* instead of:\nsearchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {\n    override fun onQueryTextChange(q: String): Boolean {\n        update(q)\n        return false\n    }\n    \n    override fun onQueryTextSubmit(q: String): Boolean {\n        return false\n    }\n}) */\nsearchView.onQueryChange { query -\u003e update(query) }\n\n/* instead of:\nsearchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {\n    override fun onQueryTextChange(q: String): Boolean {\n        return false\n    }\n    \n    override fun onQueryTextSubmit(q: String): Boolean {\n        update(q)\n        return false\n    }\n}) */\nsearchView.onQuerySubmit { query -\u003e update(query) }\n```\n#### SeekBar extension\n```kotlin\n/* instead of:\nseekBar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {\n    override fun onStopTrackingTouch(seekBar: SeekBar) {\n\n    }\n\n    override fun onStartTrackingTouch(seekBar: SeekBar?) {\n\n    }\n\n    override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {\n        mediaPlayer.seekTo(progress)\n    }\n\n}) */\nseekBar.onProgressChanged { progress, fromUser -\u003e \n    if (fromUser) mediaPlayer.seekTo(progress) \n}\n```\n#### Using system services\n```kotlin\n// instead of getSystemService(Context.WINDOW_SERVICE) as WindowManager?\nwindowManager\n// instead of getSystemService(Context.POWER_SERVICE) as PowerManager?\npowerManager\n// instead of getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager?\nnotificationManager\n// instead of getSystemService(Context.USER_SERVICE) as UserManager?\nuserManager\n// etc.\n```\n#### Toast messages\n```kotlin\nlongToast(\"I'm long toast message!\")\ntoast(\"Hi, I'm short one!\")\n\nlongToast(R.string.my_string)\ntoast(R.string.my_string)\n```\n#### Layout inflater\n```kotlin\n// instead of LayoutInflater.from(context).inflate(R.layout.some_layout, null, false)\ncontext.inflateLayout(R.layout.some_layout)\n// or\ncontext.inflateLayout(R.layout.some_layout, attachToRoot = true)\n```\n#### Using Intents\n```kotlin\n// instead of Intent(this, javaClass\u003cSampleActivity\u003e())\nval intent = IntentFor\u003cSampleActivity\u003e(this)\n// instead of startActivity(Intent(this, javaClass\u003cSampleActivity\u003e()))\nstartActivity\u003cSampleActivity\u003e()\n// instead of startActivityForResult(Intent(this, javaClass\u003cSampleActivity\u003e()), REQUEST_CODE)\nstartActivityForResult\u003cSampleActivity\u003e(REQUEST_CODE)\n```\n#### Logging\n```kotlin\n// using javaClass.simpleName as a TAG\nw(\"Warn log message\")\ne(\"Error log message\")\nwtf(\"WTF log message\")\n// using lambda log method\nv { \"Verbose log message\" }\nd { \"Debug log message\" }\ni { \"Info log message\" }\n// or with custom TAG\nv(\"CustomTag\", \"Verbose log message with custom tag\") \n```\n#### Threading\n```kotlin\n// instead of Thread(Runnable { /* long execution */ }).start()\nrunAsync {\n    // long execution\n}\n\n// delayed run (e.g. after 1000 millis)\n// equals Handler().postDelayed(Runnable { /* delayed execution */ }, delayMillis)\nrunDelayed(1000) {\n    // delayed execution\n}\n\n// run on Main Thread outside Activity\n// equals Handler(Looper.getMainLooper()).post(Runnable { /* UI update */ })\nrunOnUiThread {\n    // UI update\n}\n\n// delayed run on Main Thread\n// equals Handler(Looper.getMainLooper()).postDelayed(Runnable { /* delayed UI update */ }, delayMillis)\nrunDelayedOnUiThread(5000) {\n    // delayed UI update\n}\n```\n#### From/To API SDK\n```kotlin\n// instead of if (Build.VERSION.SDK_INT \u003e= 21) { /* run methods available since API 21 */ }\nfromApi(21) {\n    // run methods available since API 21\n}\n\n// instead of if (Build.VERSION.SDK_INT \u003c 16) { /* handle devices using older APIs */ }\ntoApi(16) {\n    // handle devices running older APIs\n}\n// or\n// instead of if (Build.VERSION.SDK_INT \u003c= 16) { /* handle devices using older APIs */ }\ntoApi(16, inclusive = true) {\n    // handle devices running older APIs\n}\n```\n#### Loading animation from xml\n```kotlin\n// instead of AnimationUtils.loadAnimation(applicationContext, R.anim.slide_in_left)\nloadAnimation(R.anim.slide_in_left)\n```\n#### Animation listener\n```kotlin\n\n/*instead of:\nanimation.setAnimationListener(object : Animation.AnimationListener{\n\toverride fun onAnimationStart(animation: Animation?) {\n\t\tonStart()\n\t}\n\toverride fun onAnimationEnd(animation: Animation?) {\n\t\tonEnd()\n\t}\n\toverride fun onAnimationRepeat(animation: Animation) {\n\t\tonRepeat()\n\t}\n})*/\n\nanimation.animListener {\n\tonAnimationStart { onStart() }\n\tonAnimationEnd { onEnd() }\n\tonAnimationRepeat { onRepeat() }\n}\n```\n#### Web intents with url validation\n```kotlin\n// instead of Intent(Intent.ACTION_VIEW, Uri.parse(\"http://github.com\"))\nWebIntent(\"http://github.com\")\n```\n#### More\nUnder development so expect soon.\nApps using KAndroid\n-------\n(contact me or create new pull request to add your apps)\n* [Recorder](https://play.google.com/store/apps/details?id=com.pawegio.recandsave)\n\nLicense\n-------\n\n    Copyright 2015-2017 Paweł Gajda\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpawegio%2FKAndroid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpawegio%2FKAndroid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpawegio%2FKAndroid/lists"}