Android应用开发框架:Android Annotations

jopen 11年前

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);      }        // [...]  }

项目主页:http://www.open-open.com/lib/view/home/1367820981261