{"id":26718687,"url":"https://github.com/amitkma/stitch","last_synced_at":"2025-04-14T03:50:31.909Z","repository":{"id":183443903,"uuid":"92133790","full_name":"amitkma/Stitch","owner":"amitkma","description":"Simple threading library using annotations for Android","archived":false,"fork":false,"pushed_at":"2017-05-26T09:45:25.000Z","size":168,"stargazers_count":28,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-27T17:47:15.387Z","etag":null,"topics":["android-library","annotation-processor","threading"],"latest_commit_sha":null,"homepage":null,"language":"Java","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/amitkma.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-05-23T05:41:36.000Z","updated_at":"2023-09-08T17:25:25.000Z","dependencies_parsed_at":"2023-07-24T14:19:43.187Z","dependency_job_id":null,"html_url":"https://github.com/amitkma/Stitch","commit_stats":null,"previous_names":["amitkma/stitch"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amitkma%2FStitch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amitkma%2FStitch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amitkma%2FStitch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amitkma%2FStitch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amitkma","download_url":"https://codeload.github.com/amitkma/Stitch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248819352,"owners_count":21166472,"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-library","annotation-processor","threading"],"created_at":"2025-03-27T17:42:02.359Z","updated_at":"2025-04-14T03:50:31.887Z","avatar_url":"https://github.com/amitkma.png","language":"Java","readme":"# Stitch [![Build Status](https://travis-ci.org/amitkma/Stitch.svg?branch=master)](https://travis-ci.org/amitkma/Stitch) [ ![Download](https://api.bintray.com/packages/amitkma/maven/stitch-lib/images/download.svg) ](https://bintray.com/amitkma/maven/stitch-lib/_latestVersion)[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Stitch-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/5802) [![API](https://img.shields.io/badge/API-9%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=9) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\nSimple threading library using annotations for Android\n\n## Download\n\n```gradle\ndependencies {\n  compile 'com.github.amitkma:stitch-lib:1.0.1'\n  annotationProcessor 'com.github.amitkma:compiler:1.0.1'\n}\n```\n## Usage\nUsing this library is as simple as creating Hello World Android app. Currently, there are three types of annotations which we support.\n- `@CallOnAnyThread` : \nThis annotation annotates a method to execute on any thread from thread pool. This library create a fixed size thread pool on the basis of availbale processors. If all threads of the thread pool are busy, the task will be added to the task queue wait until a thread is available to process that task.\n- `@CallOnNewThread` : \nA method which is annotated with `@CallOnNewThread` will always execute on a new thread. So the task will never have to wait and always start executing immediately.\n- `@CallOnUiThread` :\nWant to do some ui changes like setting text, starting animation or anything else, simply annotate the method with `@CallOnUiThread`.\n\n\nAny method which you want to execute on any particular thread, simply annotate that method like below. \n```Java\n\n\nclass ExampleClass {\n    \n    public ExampleClass() {\n    }\n\n    @CallOnAnyThread\n    public Bitmap getBitmapFromURL(String src) {\n        try {\n            URL url = new URL(src);\n            HttpURLConnection connection = (HttpURLConnection) url.openConnection();\n            connection.setDoInput(true);\n            connection.connect();\n            InputStream input = connection.getInputStream();\n            return BitmapFactory.decodeStream(input);\n        } catch (IOException e) {\n            // Log exception\n            return null;\n        }\n    }\n}\n\n```\nNow, build the project using terminal or by `Build -\u003e Rebuild Project` in android studio. StitchCompiler will generate a new class file for the class in which annotated methods are. The name of generated class will be the name of existing class + \"Stitch\". For example in above case, name of generated file will be \"ExampleClassStitch\".\n\nNext is to get the instance of the generated class (for calling the methods). So to get the instance of generated class, you need to stitch generated class and the required class like below : \n```Java\n// If getting instance in other class.\nExampleClassStitch exampleClassStitch = ExampleClassStitch.stitch(new ExampleClass()); \n\n// Or if getting instance in same class\nExampleClassStitch exampleClassStitch = ExampleClassStitch.stitch(this);.\n```\nAfter that, you can call the method as usual and the method will execute upon the annotated thread.\n``` Java\nexampleClassStitch.getBitmapFromURL(\"https://image.freepik.com/free-vector/android-boot-logo_634639.jpg\");\n```\nThis is it. \n\n## Performance Issue \nThe answer is NO. This is because this library uses compile time processing and generates the code at compile time. So no reflection, No perf issue.\n\n##### Remember - Don't make any change/update UI using @CallOnAnyThread or @CallOnNewThread otherwise android will throw an exception.\n\n## Contribution \nFor contribution guidelines, read [Contribution guidelines for this project](CONTRIBUTING.md)\n\n## License\n```\nCopyright 2017 Amit Kumar\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\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famitkma%2Fstitch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famitkma%2Fstitch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famitkma%2Fstitch/lists"}