編輯:關於android開發
一套可以直接復制使用的MVP框架
通過對MVP設計模式學習,對MVP也有了一個初步的認識,以登錄Login模塊為例,封裝MVP如下:
package com.example.administrator.frameapp.api; /** * 存放url的接口 * Created by Zyh on 2016/11/17. */ public interface ApiUrl { String IP="http://192.168.8.4/tp3/"; String BASEURL=IP+"api.php/Home/"; }
package com.example.administrator.frameapp.api; import io.reactivex.Flowable; import retrofit2.http.Field; import retrofit2.http.FormUrlEncoded; import retrofit2.http.POST; /** * Created by Zyh on 2016/11/17. */ public interface ApiService { @FormUrlEncoded @POST("login/login") Flowable<ApiResult> login(@Field("name") String name, @Field("password") String password); }
package com.example.administrator.frameapp.api; /** * Created by Zyh on 2016/11/17. */ public class ApiResult<T> { private int code; private String Msg; private T data; public int getCode() { return code; } @Override public String toString() { return "ApiResult{" + "code=" + code + ", Msg='" + Msg + '\'' + ", data=" + data + '}'; } public void setCode(int code) { this.code = code; } public String getMsg() { return Msg; } public void setMsg(String msg) { Msg = msg; } public T getData() { return data; } public void setData(T data) { this.data = data; } }
package com.example.administrator.frameapp.api; import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; import okhttp3.OkHttpClient; import okhttp3.logging.HttpLoggingInterceptor; import retrofit2.Retrofit; import retrofit2.converter.gson.GsonConverterFactory; /** * Created by Zyh on 2016/11/17. */ public class Api { private Retrofit mRetrofit; public ApiService mApiservice; private Api() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);//請求的內容和響應的內容都存在這個系統的BODY中 OkHttpClient mOkHttpClient = new OkHttpClient.Builder().addInterceptor(interceptor).build(); mRetrofit = new Retrofit.Builder() .client(mOkHttpClient) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .addConverterFactory(GsonConverterFactory.create()) .baseUrl(ApiUrl.BASEURL) .build(); mApiservice = mRetrofit.create(ApiService.class); } //靜態內部類的單例模式:內部類決定了什麼時候加載他就什麼時候進行加載, private static class SingleHolder { private static final Api INSTANCE = new Api(); } public static Api getInstance() { return SingleHolder.INSTANCE; } }
package com.example.administrator.frameapp.ui.base; /** * 創建base類是為了統一管理 * BasePresent是抽象類 * 將model和view關聯起來 * Created by Zyh on 2016/11/17. */ public abstract class BasePresent<M,V> { public M mModel; public V mView; public void setVM(V v,M m){ //這個方法將LoginPresenter中方法中類型映射成具體的類型 this.mModel=m; this.mView=v; } }
package com.example.administrator.frameapp.ui.base; /** * Created by Zyh on 2016/11/17. */ public interface BaseView { }
package com.example.administrator.frameapp.ui.base; /** * Created by Zyh on 2016/11/17. */ public interface BaseModel { }
Android官方多媒體API Mediacodec翻譯(一),androidmediacodec 本文章為根據Android Mediacodec官方英文版
WebView上實現Java與JavaScript交互,webviewjavascript 在安卓開發上,考慮
Android插件化基礎(4),動態啟動插件中的Activity Android插件化基礎(4),動態啟動插件中的Activity Author:鄭海波-莫川 簡介 如何
Android自定義控件系列案例【四】 案例效果: 模擬器上運行有些鋸齒,真機上和預期一樣好 案例分析: 看效果,第一直覺肯定是Android原生態控件中沒有這樣的控