Android應用開發框架:Android Annotations
Android Annotations是一個開源的框架,用于加速 Android應用的開發,可以讓你把重點放在功能的實現上,簡化了代碼,提升了可維護性。
特性:
- 依賴注入: inject views, extras, system services, resources, ...
- 簡化的線程模型: annotate your methods so that they execute on the UI thread or on a background thread.
- Event 綁定: annotate methods to handle events on views, no more ugly anonymous listener classes!
- REST 客戶端: create a client interface, AndroidAnnotations generates the implementation.
- AndroidAnnotations provide those good things and even more for less than 50kb, without any runtime perf impact!
@EActivity(R.layout.translate) // Sets content view to R.layout.translate
public 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);
}
// [...]
}
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!