Android Annotations is an open-source framework for accelerating the development of Android applications, allowing you to focus on the implementation of functionality, simplifying code, and improving maintainability.
Characteristics:
- Dependency Injection : Inject views, extras, system services, resources, ...
- Simplified threading Model : Annotate your methods So, they execute on the UI thread or on a background thread.
- Event Bindings : Annotate methods to handle events on views, No more ugly anonymouslistener classes!
- REST Client : Create a Client interface, Androidannotations generates the implementation.
- Androidannotations provide those good things and even more for less than 50kb, without any runtimeperf impact!
@EActivity (r.layout.translate)//sets content view to R.layout.translatepublic class Translateactivity extends Activity { @ViewById//injects r.id.textinput EditText textInput; @ViewById (R.id.mytextview)//injects r.id.mytextview TextView result; @AnimationRes//Injects Android. r.anim.fade_in Animation fadeIn; @Click//When R.id.dotranslate button is clicked void Dotranslate () { Translateinbackground (textinput.gettext (). toString ()); } @Background//Executed in a Background thread void Translateinbackground (String texttotranslate) { string Translatedtext = Callgoogletranslate (texttotranslate); Showresult (Translatedtext); } @UiThread//Executed in the UI thread void Showresult (String translatedtext) { Result.settext (translatedtext ); Result.startanimation (fadeIn); } // [...]}
How to use some common annotations:
@AfterInject defined methods are executed after the constructor method of the class is executed
@AfterTextChange defined method executes after the text property of the TextView and its subclasses is changed
@AfterViews defined methods are executed after Setcontentview
@Background defined methods are executed in the background thread
@BeforeTextChange defined methods are executed before the Text property of the TextView and its subclasses is changed
@Click Define Click Listeners
@EActivity enable annotations in activity
@EProvider enable annotations in ContentProvider
@EReceive enable annotations in Broadcastreceiver
@EService enable annotations in the service
@EView enable annotations in a child class of a custom view
@Fullscreen fullscreen
@NoTitle No title bar
Mastering these gaze is very helpful in reading the code developed with this third-party code, and has a better understanding of the anti-compilation of APK files developed with this code.
Android Annotations (1)