簡化開發的Android注解框架:AndroidAnnotations
AndroidAnnotations是一個利用注解方式來簡化代碼結構,提高開發效率的開源框架。另外,針對REST的使用,框架提供了類似Spring IOC的機制,非常方便。
相比原生的Android開發,確實能夠讓你少些很多代碼,它的首頁也給出了一個簡單
的例子,通過例子也可以看到代碼比之前幾乎少寫了一半。由于是開源,所以大家都可以直接拿來使用,這里給
出AndroidAnnotations首頁 和github上的項目地址AndroidAnnotations Github。
使用這個開源框架有什么好處(只有不到50k大小),特性:
1、使用依賴注入(Dependency Injection)#本博接來下幾篇的文章將要介紹的開源組件都使用DI, 不熟悉
的可以了解一下Inversion of Control(IoC)
2、簡化的線程模型(Simplified threading model)
3、事件綁定(Event binding)
4、REST Client
5、No Magic [不知道為什么這樣稱呼,直譯過來就是:無魔法,它的意思是:AndroidAnnotations在編譯
的時候會產生一個子類(接下來你會明白),你查看這個子類,可以看到它是如何工作的]
以下是一個塊簡單的代碼片段:
@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); } // [...] } </pre> <div>官網:<a href="/misc/goto?guid=4958822865200979980" target="_blank">http://androidannotations.org/</a></div>
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!