<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ## 一.簡介(Introduction): AndroidAnnotations是一個能夠讓你快速進行Android開發的開源框架,它可以讓我更加專注于業務功能開發。并且使代碼更加精簡,使項目更加容易維護,它的目標就是“Fast Android Development.Easymaintainance”。相信采用清晰意圖且簡單的代碼來實現我們的功能目標。 它的首頁地址是(http://androidannotations.org/)大家如果有興趣可以去官網看一下,并且首頁他們提供了一個例子,進行原生開發以及使用注入框架開發的代碼對比。例子也可以看到代碼比之前幾乎少寫了一半。這樣看來其中一個優點就不言而喻了直接代碼量減少了很多,便于我們項目開發以及維護。項目框架介紹wiki地址:https://github.com/excilys/androidannotations/wiki。項目源代碼Github地址:https://github.com/excilys/androidannotations.。大家都可以去下載下來學習一下。 Robert C. Martin寫到: Theratio of time spent reading [code] versus writing is well over 10 to 1[therefore] making it easy to read makes it easier to write. 官網這樣寫到:當我們在進行開發Android程序的時候,我們常常在想:為什么我們總是需要一遍又一遍的寫重復的代碼?為什么我們的應用項目越來越難維護?Context,Activity和對象Object,復雜的線程,難以調用的API,加載的匿名listener,大量不需要的casts….難道我們不能改善這些? 基于如下項目開發中遇到的各種各樣的問題,我們可以使用今天我們要講得東西。使用java?annotations,開發者可以更加專注業務功能開發。讓AndroidAnnotations在編譯的時候來生成運行的代碼。 ## 二.框架特點(Features): 1、使用依賴注入(Dependency Injection)可以注入views,extras,system service,resource等等 2、簡化的線程模型(Simplified ?threadingmodel) ?,可以進行annotate方法,讓他們在UI線程上執行或在一個后臺線程。 3、事件綁定(Event binding),annotate方法來處理views的事件,這樣我們就不用再寫很多丑陋的匿名監聽器類 4、REST Client??創建一個客戶端接口,AndroidAnnotations生成實現。 5、No Magic ?AndroidAnnotations在編譯的時候會產生一個子類(接下來你會明白),你查看這個子類,可以看到它是如何工作的] AndroidAnnotations提供了這樣的超強功能,但是整個項目都不超過159KB并且對運行時的性能沒有任何影響。 ## 三.官方代碼示例(CodeSample): 朋友你寫得Android代碼容易寫,閱讀和維護嗎?來看一下下面的例子: ~~~ @EActivity(R.layout.translate) // Sets content view toR.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); } // [...] } ~~~ 看了以上的例子,對于控件初始化,資源獲取,點擊事件處理,后臺任務處理,線程處理都全部有相關的Annotations,有沒有感覺要實現同樣的功能,以前寫代碼的方式是不是非常的蛋疼,來吧一起跟我來學習Android?Annotations的使用。 ## 四.項目配置(Android Studio為例Configuration): 我們這邊采用Android Studio進行項目開發所以這邊講解Grade配置build方法 配置Android-apt 4.1.在項目全局build.grade進行如下配置 ![](https://box.kancloud.cn/2016-01-18_569c8eb22e366.jpg) 4.2.在moudle內部build.grade中進行如下配置 ~~~ apply plugin: 'com.android.application' apply plugin: 'android-apt' defAAVersion = 'XXX' 這邊填寫版本號,現在AndroidAnnotations的發布版本已經到了3.3.2 dependencies { apt "org.androidannotations:androidannotations:$AAVersion" compile "org.androidannotations:androidannotations-api:$AAVersion" } apt { arguments { androidManifestFile variant.outputs[0].processResources.manifestFile // if you have multiple outputs (whenusing splits), you may want to have other index than 0 // you should set your package namehere if you are using different application IDs // resourcePackageName"your.package.name" // You can set optional annotationprocessing options here, like these commented options: // logLevel 'INFO' // logFile '/var/log/aa.log' } } ~~~ ? ? ?完成以上的步驟操作,那我們項目的AndroidAnnotations環境就已經配置搭建好了,下一篇我們著重進行將注入框架的基本使用。 本注入框架使用例子會加入到正在開發的框架項目中,可以可以去github站點clone下載 [https://github.com/jiangqqlmj/FastDev4Android](https://github.com/jiangqqlmj/FastDev4Android)? 同時歡迎大家star和fork整個開源快速開發框架項目~如果有什么意見和反饋,歡迎留言,必定第一時間回復。也歡迎有同樣興趣的童鞋加入到該項目中來,一起維護該項目。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看