{"id":17979010,"url":"https://github.com/lykhonis/kotlinandroidlib","last_synced_at":"2025-07-16T02:40:02.353Z","repository":{"id":3378108,"uuid":"4425821","full_name":"lykhonis/kotlinAndroidLib","owner":"lykhonis","description":"Kotlin \"sugar\" for Android","archived":false,"fork":false,"pushed_at":"2015-03-10T16:15:35.000Z","size":193,"stargazers_count":124,"open_issues_count":3,"forks_count":17,"subscribers_count":11,"default_branch":"master","last_synced_at":"2024-10-29T15:01:15.399Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://vladimirlichonos.com","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lykhonis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-05-23T21:55:41.000Z","updated_at":"2022-11-18T17:53:48.000Z","dependencies_parsed_at":"2022-09-07T07:30:47.843Z","dependency_job_id":null,"html_url":"https://github.com/lykhonis/kotlinAndroidLib","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lykhonis%2FkotlinAndroidLib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lykhonis%2FkotlinAndroidLib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lykhonis%2FkotlinAndroidLib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lykhonis%2FkotlinAndroidLib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lykhonis","download_url":"https://codeload.github.com/lykhonis/kotlinAndroidLib/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222089539,"owners_count":16929173,"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":[],"created_at":"2024-10-29T17:35:56.192Z","updated_at":"2024-10-29T17:35:56.270Z","avatar_url":"https://github.com/lykhonis.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"Kotlin for Android\n=============\n\nHelps not to write boilerplate code with instantiating abstract or interfaces instances.\nThe purpose of the library is to save time of writing code using Android SDK wrapping as much as possible\ncommon functionality.\n\nThe library uses one of the coolest feature of the Kotlin language `inline` almost everywhere, that prevents overhead code.\n\nWarning\n-------\n\nThis project is not relative to JetBrains company or their products. Use this project as is, no author nor anybody else\nis responsible for any damage.\n\nLinking to Android project\n--------------------------\n\n1. Create regular or use existing Android project in IDEA\n2. Select `File` from menu and click on `Project Structure...`\n3. Select `Libraries` section and add new Java library\n4. Choose the source `src` folder of kotlinAndroidLib and click `Ok`\n5. Choose category `sources` and click `Ok`\n6. Select and name the library `kotlinAndroidLib`\n7. Add new file to the library `^N` and choose classes.jar of kotlinAndroidLib\n8. Add import to your kotlin files in the android project `import com.vlad.android.kotlin.*`\n\nUsage\n-----\n\nSmall example of usage most of the functions and also some examples like how to create Parcelable.\nSee [Sample Activity](https://github.com/vladlichonos/kotlinAndroidLib/blob/master/SampleActivity.kt)\n\n* `findViewById` replacement for Activity and View:\n\n        val myButton = findView\u003cButton\u003e(R.id.my_button)\n\n* `setOnClickListener` for Views:\n\n        myView?.setOnClickListener { /* code here */ }\n        myView?.setOnClickListener { view -\u003e /* code here with view: View? argument */ }\n        val onClickListener = OnClickListener { view -\u003e /* code here */ }\n\n        myView?.setOnTouchListener { view, event -\u003e false /* with view: View? and event: MotionEvent? */ }\n        val onTouchListener = OnTouchListener { view, event -\u003e false }\n\n* `runOnUiThread` for Activities:\n\n    It can be used without the library:\n\n        runOnUiThread(runnable { /* action */})\n\n    Library just remove runnable call and can be used as:\n\n        runOnUiThread { /* action */ }\n\n* Short definition of `BroadcastReceiver`:\n\n    Library just wraps `onReceive` call:\n\n        val myBroadcastReceiver = BroadcastReceiver { context, intent -\u003e\n            /* handle intent here */\n        }\n\n* `setPositiveButton` and `setNegativeButton` for AlertDialog.Builder:\n\n        AlertDialog.Builder(this).setTitle(\"Hello\")\n            ?.setMessage(\"Want to say hello to world?\")\n            ?.setPositiveButton(\"Yes\", { dialog, which -\u003e /* hello */ })\n            ?.setNegativeButton(\"No\", { dialog, which -\u003e /* no hello now */ })\n            ?.create()\n\n        val positiveButton = dialogOnClickListener { dialog, which -\u003e }\n\n* Short definition of `OnEditorActionListener`:\n\n    Library just wraps `onEditorAction` call:\n\n        val myEditorActionListener = OnEditorActionListener { v, actionId, event -\u003e\n            /* handle actionId and/or event */\n            false\n        }\n\n        myEditText?.setOnEditorActionListener /* OnEditorActionListener */ { v, actionId, event -\u003e\n            false\n        }\n\n* `getSystemService` with or without casting for known services:\n\n    Library allows call with casting for specific name of the service or call directly for known services:\n\n        val inputMethodManager = getSystemServiceAs\u003cInputMethodManager\u003e(Context.INPUT_METHOD_SERVICE)\n        val inputMethodManager = getInputMethodService()\n\n* `AdapterView\u003cout Adapter?\u003e.setOnItemClickListener` and `AdapterView\u003cout Adapter?\u003e.setOnItemLongClickListener`:\n\n        listView.setOnItemClickListener { parent, view, position, id -\u003e }\n        listView.setOnItemLongClickListener { parent, view, position, id -\u003e false }\n\n* Wrap calls without runnable() for `Handler`:\n\n        val handler = Handler()\n        handler.post { /* code here */ }\n        handler.postDelayed(100) { /* code here */ }\n        handler.postAtFrontOfQueue { /* code here */ }\n        handler.postAtTime(System.currentTimeMillis() + 100) { /* code here */ }\n\n    Also easy to create handler with callback to handle messages:\n\n        val handler = Handler { message -\u003e\n            when (message.what) {\n                1 -\u003e handleMessage1(message.getData())\n                else -\u003e false\n            }\n        }\n\n* Wrap `SQLiteDatabase` functionality:\n\n    * Wrap pattern: beginTransaction -\u003e setTransactionSuccessful -\u003e endTransaction with try and finally:\n\n            sqliteDatabase.transaction {\n                // call any method of SQLiteDatabase without . or ?.\n                execSQL(\"ALTER TABLE table_1 RENAME TO table_2\")\n            }\n\n    * Wrap pattern: cursor not null -\u003e moveToFirst -\u003e moveToNext in do-while loop -\u003e close with try and finally:\n\n            // query call with same arguments + last argument is a body in the loop\n            val collection /* of String */ = sqliteDatabase.query\u003cString\u003e(\"people\", array(\"first_name\"), null, null, null, null, null, null) {\n                /* Cursor namespace */\n                getString(getColumnIndexOrThrow(\"first_name\"))\n            }\n\n        Support also queryWithFactory, rawQuery and rawQueryWithFactory.\n\n    * Wrap ContentValues for insert and update:\n\n            sqliteDatabase?.insert(\"table_name\", null) {\n                // ContentValues namespace\n                put(\"column_text\", \"Hello\")\n                put(\"column_int\", 12.toInt())\n                put(\"column_float\", 13.toFloat())\n            }\n\n            sqliteDatabase?.update(\"table_name\", \"ID = ?\", array(\"3\")) {\n                // ContentValues namespace\n                put(\"column_text\", \"Hello World\")\n            }\n\n* Wrap `Cursor` pattern moveToFirst -\u003e moveToNext in do-while loop:\n\n    Possible to call all functions on Cursor?, if Cursor? == null, returns empty collection\n\n        try {\n            val collection /* Of String? */ = cursor.map {\n                getString(getColumnIndexOrThrow(\"first_name\"))\n            }\n        } finally {\n            cursor?.close()\n        }\n\n    or\n\n        val collection = LinkedList\u003cString?\u003e()\n        try {\n            cursor.mapTo(collection) {\n                getString(getColumnIndexOrThrow(\"first_name\"))\n            }\n        } finally {\n            cursor?.close()\n        }\n\n    or\n\n        val collection /* Of String? */ = cursor.mapAndClose {\n            getString(getColumnIndexOrThrow(\"first_name\"))\n        }\n\n* `ExecutorService`:\n\n        executorService.execute { /* code here */ }\n        val future = executorService.submit\u003cAny?\u003e { /* code here and no result */ }\n        val future = executorService.submit\u003cString?\u003e { /* code here */ \"Result\" }\n        val future = executorService.submit\u003cString?\u003e(\"Result\") { /* code here and result */ }\n\n* Wrap `Intent`, now easy to create new `Intent` without defining new variable:\n\n        sendBroadcast(Intent() { setAction(Intent.ACTION_DEFAULT) })\n        startActivity(Intent(Intent.ACTION_VIEW) { setDataAndType(Uri.parse(\"http://example.com/audio.mp3\"), \"audio/mpeg\") })\n\n    or make it even nicer if you have an action and it's a `String` value:\n\n        \"my.application.intent.action.ACTION_MINE\" toIntent {\n            /* namespace of Intent */\n        }\n\n    or just convert `String` to `Intent`:\n\n        \"my.application.intent.action.ACTION_MINE\".toIntent()\n\n* Wrap `IntentFilter`, now easy to create new `IntentFilter` without defining new variable:\n\n        registerReceiver(broadcastReceiver, IntentFilter {\n            addAction(ACTION_HELLO)\n        })\n\n* Wrap `Bundle`, now easy to create new `Bundle` without defining new variable:\n\n        Bundle { putString(\"result\", \"Some result!\") }\n\n* Short definition of `ResultReceiver`:\n\n    Library just wraps `onReceiveResult` call:\n\n        val myResultReceiver = ResultReceiver(Hanlder()) { code, data -\u003e\n            /* handle result here */\n        }\n\n    or automatically create new `Hanlder`\n\n        val myResultReceiver = ResultReceiver { code, data -\u003e\n            /* handle result here */\n        }\n\n* Wrap 'CREATOR' for `Parcelable`. Example of usage:\n\n    WARNING: It might wrong or not supported yet!\n\n        class MyParcelable(val number: Int, val text: String?) : Parcelable {\n\n            public override fun writeToParcel(p0: Parcel?, p1: Int) = if (p0 != null) {\n                p0.writeInt(number)\n                p0.writeString(text)\n            }\n\n            public override fun describeContents(): Int = 0\n\n            class object {\n\n                val CREATOR = CreateParcelable\u003cMyParcelable\u003e { MyParcelable(it.readInt(), it.readString()) }\n            }\n        }\n\n* Wrap `Thread`, `run` and call `start` method:\n\n        async {\n            // some code here\n        }\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flykhonis%2Fkotlinandroidlib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flykhonis%2Fkotlinandroidlib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flykhonis%2Fkotlinandroidlib/lists"}