Stitch


Source link: https://github.com/amitkma/Stitch

Stitch

Simple threading library using annotations for Android

Download

dependencies {

compile 'com.github.amitkma:stitch-lib:1.0.1'
annotationProcessor 'com.github.amitkma:compiler:1.0.1' 
}

Usage

Using this library is as simple as creating Hello World Android app. Currently, there are three types of annotations which we support.

  • @CallOnAnyThread : This 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.
  • @CallOnNewThread : A 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.
  • @CallOnUiThread : Want to do some ui changes like setting text, starting animation or anything else, simply annotate the method with @CallOnUiThread.

Any method which you want to execute on any particular thread, simply annotate that method like below.

class ExampleClass {

 public ExampleClass() {

  
}

@CallOnAnyThread
  public Bitmap getBitmapFromURL(String src) {

try {

 URL url = new URL(src);

 HttpURLConnection connection = (HttpURLConnection) url.openConnection();

 connection.setDoInput(true);

 connection.connect();

 InputStream input = connection.getInputStream();

 return BitmapFactory.decodeStream(input);

}
 catch (IOException e) {

 // Log exception

 return null;

}

  
}
 
}
 

Now, build the project using terminal or by Build -> 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".

Next 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 :

// If getting instance in other class. ExampleClassStitch exampleClassStitch = ExampleClassStitch.stitch(new ExampleClass());

// Or if getting instance in same class ExampleClassStitch exampleClassStitch = ExampleClassStitch.stitch(this);
.

After that, you can call the method as usual and the method will execute upon the annotated thread.

exampleClassStitch.getBitmapFromURL("https://image.freepik.com/free-vector/android-boot-logo_634639.jpg");

This is it.

Performance Issue

The 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.

Remember - Don't make any change/update UI using @CallOnAnyThread or @CallOnNewThread otherwise android will throw an exception.

Contribution

For contribution guidelines, read Contribution guidelines for this project

License

Copyright 2017 Amit Kumar  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. 

Resources

The open picker is the fastest way to get files from OneDrive and OneDrive for Business into your Android app. OneDrive-Picker-Android provides a set of Java APIs that your app can use to browse, select, and download files stored in your user's OneDrive.

You can also get shareable links to files - great for sending to friends, coworkers, and relatives. The open picker also lets your app get thumbnails of image and video files so you don't have to build them yourself.

This is a sample app that is part of a blog post about how to architect android application using the Uncle Bob's clean architecture approach.

The in app purchase system provided by Google is missing one very important thing. This tool will allow app developers to provide their users with codes to be redeemed in app for extra content.

This system uses Parse.com as a simple and free backend to manage your users and codes. All you need to do is create a free account and setup your app. Once you have your client and application keys, you are ready to go.

A SwipeMenu for ListView.

This Java library provides an implementation of macaroons, which are flexible authorization tokens that work great in distributed systems.

Like cookies, macaroons are bearer tokens that enable applications to ascertain whether their holders' actions are authorized. But macaroons are better than cookies!

This project shows how to make simple Burger buttons (animated menu buttons).

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes