override fun onCreate(savedInstanceState: Bundle?){
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
//100000 lines
}
override fun onCreate(savedInstanceState: Bundle?){
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
try{
//100000 lines
} catch (exception: Exception){
//handle
}
}
MVC | MVP | MVVM | |
---|---|---|---|
Google daddy support | Yes | No | No |
Learning curve | Easy | Normal | Normal |
Testability | Hard | Easy | Easy |
Lifecycle-aware | Hard | Hard | Easy |
Really have no time for development... so I stop project maintaining since Nov 27 :(
UIL [27.11.2011 - 27.11.2015]
Thanks to all developers for your support :)
Picasso | Fresco | Glide | |
---|---|---|---|
Support gif | No | Yes | Yes |
Circle image | No | Yes | Yes(4.0+) |
Support webP | Yes | Yes | Yes |
Android lifecycle | No | No | Yes |
Cache | Large | Normal | Small |
Container | ImageView | DraweeView | ImageView |
public static final String TABLE_NAME = "item";
public static final String KEY_ID = "_id";
public static final String DATETIME_COLUMN = "datetime";
public static final String COLOR_COLUMN = "color";
public static final String CREATE_TABLE =
"CREATE TABLE " + TABLE_NAME + " (" +
KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
DATETIME_COLUMN + " INTEGER NOT NULL)";
@DatabaseTable(tableName = "User")
public class User {
@DatabaseField(generatedId = true) private int id;
@DatabaseField private String name;
@DatabaseField private int sort;
@ForeignCollectionField private ForeignCollection<Group> groups;
}
@Dao
interface MyDao {
@Query(
"SELECT user.name AS userName, pet.name AS petName " +
"FROM user, pet " +
"WHERE user.id = pet.user_id"
)
fun loadUserAndPetNames(): LiveData<List<UserPet>>
// You can also define this class in a separate file.
data class UserPet(val userName: String?, val petName: String?)
}
For Gingerbread and better, HttpURLConnection is the best choice. New applications should use HttpURLConnection.
@GET("group/{id}/users")
Call<List<User>> groupList(@Path("id") int groupId);
@GET("group/{id}/users")
Call<List<User>> groupList(@Path("id") int groupId, @Query("sort") String sort);
@GET("group/{id}/users")
Call<List<User>> groupList(@Path("id") int groupId, @QueryMap Map<String, String> options);
@POST("users/new")
Call<User> createUser(@Body User user);
class User{
@SerializedName("user_name")
private String userName;
@SerializedName("user_age")
private int userAge;
}
interface ApiService {
@GET("/posts")
fun getPosts(): Single<List<Posts>>
}
fun loadInfo(): Single<List<Posts>> {
return apiService.getPosts()
}
HttpURLConnection | Volley | OkHttp | |
---|---|---|---|
Callback | No | Yes | Yes |
Easy to use | No | Yes | Yes |
Interceptor | No | No | Yes |
API Interface | No | No | Yes |
RxJava | No | No | Yes |
public interface OnClickListener {
void onClick(View var1);
}
public interface OnCapturedPointerListener {
boolean onCapturedPointer(View var1, MotionEvent var2);
}
public interface OnApplyWindowInsetsListener {
WindowInsets onApplyWindowInsets(View var1, WindowInsets var2);
}
public interface OnKeyListener {
boolean onKey(View var1, int var2, KeyEvent var3);
}
public class Callback<T> {
public void onResult(T result);
}
subscribe(Consumer<? super T> onNext,
Consumer<? super Throwable> onError, Action onComplete,
Consumer<? super Disposable> onSubscribe)
subscribe(final Consumer<? super T> onSuccess,
final Consumer<? super Throwable> onError)
subscribe(Consumer<? super T> onSuccess)
Thread {
//do something
runOnUiThread {
//update ui
Thread {
//do something
runOnUiThread {
//update ui
}
}
}
}
Observable.just(1,2,3)
.subscribeOn(Schedulers.newThread())
.map{}
.observeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe{}
RxView.clicks(throttleFirstButton)
.throttleFirst(ANIMATION_TIME, TimeUnit.MILLISECONDS)
.subscribe{
}
class A{
fun main(){
B().bListener()
.subscribe{}
}
}
class B{
fun test(){
C().bListener()
.subscribe{}
}
fun bListener():Single<CData>{
return getData()
}
}
class C{
fun cListener():Single<CData>{
retrun service()
}
}
Item name | Better choice |
---|---|
Architecture | MVVM |
Http Connection | Retrofit |
Database | Room |
Image Process | Glide |
ReactiveX | RxJava |