{"id":3728,"url":"https://github.com/jmartinesp/SwissKnife","last_synced_at":"2025-08-03T23:32:06.046Z","repository":{"id":19915490,"uuid":"23181293","full_name":"jmartinesp/SwissKnife","owner":"jmartinesp","description":"A multi-purpose library containing view injection and threading for Android using annotations","archived":false,"fork":false,"pushed_at":"2015-11-25T12:03:04.000Z","size":16286,"stargazers_count":255,"open_issues_count":4,"forks_count":24,"subscribers_count":29,"default_branch":"master","last_synced_at":"2024-04-14T16:03:09.814Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Groovy","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/jmartinesp.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":"2014-08-21T09:21:27.000Z","updated_at":"2024-03-02T18:57:09.000Z","dependencies_parsed_at":"2022-08-17T15:11:19.781Z","dependency_job_id":null,"html_url":"https://github.com/jmartinesp/SwissKnife","commit_stats":null,"previous_names":["arasthel/swissknife"],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmartinesp%2FSwissKnife","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmartinesp%2FSwissKnife/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmartinesp%2FSwissKnife/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmartinesp%2FSwissKnife/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jmartinesp","download_url":"https://codeload.github.com/jmartinesp/SwissKnife/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":[],"created_at":"2024-01-05T20:16:49.739Z","updated_at":"2024-12-07T06:31:36.796Z","avatar_url":"https://github.com/jmartinesp.png","language":"Groovy","funding_links":[],"categories":["Development Alternatives"],"sub_categories":["Groovy"],"readme":"SwissKnife [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.arasthel/swissknife/badge.svg?style=flat)](https://maven-badges.herokuapp.com/maven-central/com.arasthel/swissknife)\n==========\n\n[![Join the chat at https://gitter.im/Arasthel/SwissKnife](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/Arasthel/SwissKnife?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\n\n\u003cdiv align=\"center\"\u003e\u003cimg src=\"./SwissKnife.png\"\u003e\u003c/div\u003e\n\nA multi-purpose *Groovy* library containing view injection and threading for Android using annotations. It's based on both [ButterKnife](https://github.com/JakeWharton/butterknife/) and [AndroidAnnotations](https://github.com/excilys/androidannotations).\n\nWith **SwissKnife** you can:\n\n* Inject views dynamically on *any Object* as long a you have a View to find them. No more ``findViewById`` and **you don't have to extend any classes**.\n* Add callback methods to several actions using ``@OnClick``, ``@OnItemClick``, etc.\n* Execute methods in the UI Thread or a background one using ``@OnUIThread`` and ``@OnBackground``.\n* Make your variables persistent across state changes **without messing with** `onSaveInstanceState`.\n* Make anything Parcelable with the `@Parcelable` annotation - which can be used with `@SaveInstance` to automatize data persistance. **NO MORE PARCELABLES! YAY!**\n* Inject resources into your classes with `@Res` annotations (`@StringRes`, `@AnontationRes`, etc.).\n* Read intent extras automatically with `@Extra` annotation.\n\nYou can see an example here:\n\n```groovy\nclass MyActivity extends Activity {\n\n  @StringRes(R.string.important_message)\n  String reallyImportantMessage\n\n  @Extra(\"api_key\")\n  String apiKey\n\n  @SaveInstance\n  public String myString;\n\n  @OnClick(R.id.button)\n  public void onButtonClicked(Button button) {\n    Toast.makeText(this, \"Button clicked\", Toast.LENGTH_SHOT).show();\n  }\n\n  @OnBackground\n  public void doSomeProcessing(URL url) {\n    // Contents will be executed on background\n    ...\n  }\n\n  @Override\n    protected void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        setContentView(R.layout.activity_main);\n        // This must be called for injection of views and callbacks to take place\n        SwissKnife.inject(this);\n\n        // This must be called for saved state restoring\n        SwissKnife.restoreState(this, savedInstanceState);\n\n        // This mus be called for automatic parsing of intent extras\n        SwissKnife.loadExtras(this)\n    }\n}\n```\n\n## Collaborators\n\nI'd really want to thank:\n\n* [Mario García](https://github.com/mariogarcia) for his help on the new GH-Pages based documentation.\n* [Dexafree](https://github.com/dexafree) for adding `@SaveInstance` annotation and helping with the testing.\n* [Eugene Kamenev](https://github.com/eugene-kamenev) for adding DSL functionality to *[android-dsl](https://github.com/Arasthel/SwissKnife/tree/android-dsl)* branch.\n* [Karol](https://github.com/OrdonTeam) for injection on any object.\n* [Andrew Reitz](https://github.com/pieces029) for keeping the build files up to date.\n* [Pavel](https://github.com/MrBIMC) for his resource injection AST transforms.\n\nYou all make SwissKnife the great tool it is!\n\n## Documentation\n\nIf you want to learn more, you can check [Swissknife's docs page](http://arasthel.github.io/SwissKnife).\n\nIt contains info about the install instructions, all the annotations, DSLs, configurations, etc.\n\nYou can find all the releases and their changes here: [RELEASES](https://github.com/Arasthel/SwissKnife/releases)\n\n## Using it\n\nTo use SwissKnife **you must use Groovy on your Android project** as the code generation is done using AST processing, which is a Groovy feature. You can learn how to do that using [this plugin](https://github.com/melix/groovy-android-gradle-plugin) on the [wiki pages](https://github.com/Arasthel/SwissKnife/wiki/How-to-use-Groovy).\n\nOnce your project App Module is configured to use Groovy you can add this library as a dependency cloning it with ``git clone`` or as a maven library on the **build.gradle** of your App Module:\n\n```groovy\ndependencies {\n    ...\n    compile \"com.arasthel:swissknife:1.4.0\"\n    ...\n}\n```\n\nIf you want *SwissKnife* to update automatically, you could just type:\n\n```groovy\ndependencies {\n    ...\n    compile \"com.arasthel:swissknife:+\"\n    ...\n}\n```\n\nBut make sure you remember to clear Gradle's cache to get the latest version.\n\nAlso, [there is an IntelliJ IDEA plugin](https://github.com/Arasthel/SwissKnife/wiki/SwissKnife-IDEA-Plugin) *compatible with Android Studio* that lets you auto-generate the annotations and compatible method declarations.\n\n![IDEA plugin](https://camo.githubusercontent.com/ffe3a4e6c05f0846162e93ed4d8abfd532b7f826/687474703a2f2f692e696d6775722e636f6d2f5564704e3634652e6a7067)\n\n## License\n\nSwissKnife is licensed under Apache v2 License, which means that it is Open Source and free to use and modify.\n\n```\nCopyright 2014 Jorge Martín Espinosa (Arasthel)\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n   http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjmartinesp%2FSwissKnife","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjmartinesp%2FSwissKnife","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjmartinesp%2FSwissKnife/lists"}