在Android的开发过程中,每个开发者或多或少的都使用过第三方的开源库,使用第三方的开源库可以给开发者节省大量的精力和时间,进而更好的关注应用本身的业务逻辑
下面列出一些开发者们非常常用的开源库
另外Fresco还提供了一些其他的开源库支持 Gif,WebP等
dependencies { // If your app supports Android versions before Ice Cream Sandwich (API level 14)
compile 'com.facebook.fresco:animated-base-support:1.0.1'
// For animated GIF support
compile 'com.facebook.fresco:animated-gif:1.0.1'
// For WebP support, including animated WebP
compile 'com.facebook.fresco:animated-webp:1.0.1'
compile 'com.facebook.fresco:webpsupport:1.0.1'
// For WebP support, without animations
compile 'com.facebook.fresco:webpsupport:1.0.1'
// Provide the Android support library (you might already have this or a similar dependency)
compile 'com.android.support:support-core-utils:24.2.1'}
Glide
Glide是一个快速高效的多媒体管理和图片加载框架,封装了多媒体的解码、内存和硬盘缓存,接口友好
dependencies {
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.android.support:support-v4:19.1.0'}
OkHttp
OkHttp是一个为Android提供 HTTP+HTTP/2
的客户端,很好的封装了对网络的请求连接
dependencies {
compile 'com.squareup.okhttp3:okhttp:3.6.0'}
FastAndroidNetworking
FastAndroidNetworking是基于 OkHttp
的一个网络引擎
dependencies {
compile 'com.amitshekhar.android:android-networking:0.4.0'}
RxJava
RxJava-Reactive Extensions for the JVM
dependencies {
compile 'io.reactivex.rxjava2:rxjava:2.0.5'}
package rxjava.examples;import io.reactivex.*;public class HelloWorld { public static void main(String[] args) {
Flowable.just("Hello world").subscribe(System.out::println);
}
}
如果你使用的平台还没有支持Java 8的lambda,可以使用下面的代码
Flowable.just("Hello world")
.subscribe(new Consumer<String>() { @Override public void accept(String s) {
System.out.println(s);
}
);
定义事件
public static class MessageEvent { /* Additional fields if needed */ }
准备订阅者
@Subscribe(threadMode = ThreadMode.MAIN)
public void onMessageEvent(MessageEvent event) {/* Do something */};
注册和注销订阅者
@Overridepublic void onStart() { super.onStart();
EventBus.getDefault().register(this);
}@Overridepublic void onStop() { super.onStop();
EventBus.getDefault().unregister(this);
}
发送事件
EventBus.getDefault().post(new MessageEvent());
Device Year Class
Device Year Class 是一个Android库,提供了一些更好的方法来基于手机的硬件进行应用的修改
compile 'com.facebook.device.yearclass:yearclass:2.0.0
int year = YearClass.get(getApplicationContext());if (year >= 2013) { // Do advanced animation} else if (year > 2010) { // Do simple animation} else { // Phone too slow, don't do any animations}
Network Connection Class
监听网路连接质量的一个Android开源库,用户可以根据网络的连接质量来调节应用的一些行为(加载低质量的图片和视频等)
compile 'com.facebook.network.connectionclass:connectionclass:1.0.1'
Android Debug Database
Android Debug Database是一个强大的开源库,开发者通过它可以调试数据库和 SharedPreferences
,可以直接通过浏览器查看数据库和 SharedPreferences
debugCompile 'com.amitshekhar.android:debug-db:0.5.0'
LeakCanary
LeakCanary是一个检测内存溢出的开源库
dependencies {
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5'
testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5'}
public class ExampleApplication extends Application { @Override public void onCreate() { super.onCreate(); if (LeakCanary.isInAnalyzerProcess(this)) { // This process is dedicated to LeakCanary for heap analysis.
// You should not init your app in this process.
return;
}
LeakCanary.install(this); // Normal app init code...
}
}
MPAndroidChart
一个强大的制作图表的开源库,支持 线图、饼状图、雷达图、气泡图等
dependencies {
compile 'com.github.PhilJay:MPAndroidChart:v3.0.1'}
ButterKnife
ButterKnife是一个视图的绑定工具,通过注释生成一些相应的代码,更简洁的代码
dependencies {
compile 'com.jakewharton:butterknife:8.5.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'}
class ExampleActivity extends Activity { @BindView(R.id.user) EditText username; @BindView(R.id.pass) EditText password; @BindString(R.string.login_error) String loginErrorMessage; @OnClick(R.id.submit) void submit() { // TODO call server...
} @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.simple_activity);
ButterKnife.bind(this); // TODO Use fields...
}
}
Dagger
一个注入框架
dependencies {
compile 'com.google.dagger:dagger:2.x'
annotationProcessor 'com.google.dagger:dagger-compiler:2.x'}
GreenDao
GreenDao是一个开源的Android ORM框架,更好的操作SQlite,提供友好的接口操作底层数据库的操作
Realm
简单快速的存储,节省更多的开发时间,是一个移动设备的数据库
Hugo
也是一个log框架
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.jakewharton.hugo:hugo-plugin:1.2.1'
}
}
apply plugin: 'com.android.application'apply plugin: 'com.jakewharton.hugo'
Androig GPU Image
提供了基于 OpenGL的图像滤镜框架
repositories {
jcenter()
}
dependencies {
compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.4.1'}
@Overridepublic void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.activity);
Uri imageUri = ...;
mGPUImage = new GPUImage(this);
mGPUImage.setGLSurfaceView((GLSurfaceView) findViewById(R.id.surfaceView));
mGPUImage.setImage(imageUri); // this loads image on the current thread, should be run in a thread
mGPUImage.setFilter(new GPUImageSepiaFilter()); // Later when image should be saved saved:
mGPUImage.saveToPictures("GPUImage", "ImageWithFilter.jpg", null);
}
没有缩略图
Uri imageUri = ...;
mGPUImage = new GPUImage(context);
mGPUImage.setFilter(new GPUImageSobelEdgeDetection());
mGPUImage.setImage(imageUri);
mGPUImage.saveToPictures("GPUImage", "ImageWithFilter.jpg", null);
GSON
JSON的解析和封装框架
作者:CodeMiner
链接:https://www.jianshu.com/p/e31a92fdff35
HTTP+HTTP/2
的客户端,很好的封装了对网络的请求连接OkHttp
的一个网络引擎定义事件
public static class MessageEvent { /* Additional fields if needed */ }
准备订阅者
@Subscribe(threadMode = ThreadMode.MAIN) public void onMessageEvent(MessageEvent event) {/* Do something */};
注册和注销订阅者
@Overridepublic void onStart() { super.onStart(); EventBus.getDefault().register(this); }@Overridepublic void onStop() { super.onStop(); EventBus.getDefault().unregister(this); }
发送事件
EventBus.getDefault().post(new MessageEvent());
Device Year Class
Device Year Class 是一个Android库,提供了一些更好的方法来基于手机的硬件进行应用的修改
compile 'com.facebook.device.yearclass:yearclass:2.0.0
int year = YearClass.get(getApplicationContext());if (year >= 2013) { // Do advanced animation} else if (year > 2010) { // Do simple animation} else { // Phone too slow, don't do any animations}
Network Connection Class
监听网路连接质量的一个Android开源库,用户可以根据网络的连接质量来调节应用的一些行为(加载低质量的图片和视频等)
compile 'com.facebook.network.connectionclass:connectionclass:1.0.1'
Android Debug Database
Android Debug Database是一个强大的开源库,开发者通过它可以调试数据库和 SharedPreferences
,可以直接通过浏览器查看数据库和 SharedPreferences
debugCompile 'com.amitshekhar.android:debug-db:0.5.0'
LeakCanary
LeakCanary是一个检测内存溢出的开源库
dependencies { debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5' releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5' testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5'}
public class ExampleApplication extends Application { @Override public void onCreate() { super.onCreate(); if (LeakCanary.isInAnalyzerProcess(this)) { // This process is dedicated to LeakCanary for heap analysis. // You should not init your app in this process. return; } LeakCanary.install(this); // Normal app init code... } }
MPAndroidChart
一个强大的制作图表的开源库,支持 线图、饼状图、雷达图、气泡图等
dependencies { compile 'com.github.PhilJay:MPAndroidChart:v3.0.1'}
ButterKnife
ButterKnife是一个视图的绑定工具,通过注释生成一些相应的代码,更简洁的代码
dependencies { compile 'com.jakewharton:butterknife:8.5.1' annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'}
class ExampleActivity extends Activity { @BindView(R.id.user) EditText username; @BindView(R.id.pass) EditText password; @BindString(R.string.login_error) String loginErrorMessage; @OnClick(R.id.submit) void submit() { // TODO call server... } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.simple_activity); ButterKnife.bind(this); // TODO Use fields... } }
Dagger
一个注入框架
dependencies { compile 'com.google.dagger:dagger:2.x' annotationProcessor 'com.google.dagger:dagger-compiler:2.x'}
GreenDao
GreenDao是一个开源的Android ORM框架,更好的操作SQlite,提供友好的接口操作底层数据库的操作
Realm
简单快速的存储,节省更多的开发时间,是一个移动设备的数据库
Hugo
也是一个log框架
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.jakewharton.hugo:hugo-plugin:1.2.1'
}
}
apply plugin: 'com.android.application'apply plugin: 'com.jakewharton.hugo'
Androig GPU Image
提供了基于 OpenGL的图像滤镜框架
repositories {
jcenter()
}
dependencies {
compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.4.1'}
@Overridepublic void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.activity);
Uri imageUri = ...;
mGPUImage = new GPUImage(this);
mGPUImage.setGLSurfaceView((GLSurfaceView) findViewById(R.id.surfaceView));
mGPUImage.setImage(imageUri); // this loads image on the current thread, should be run in a thread
mGPUImage.setFilter(new GPUImageSepiaFilter()); // Later when image should be saved saved:
mGPUImage.saveToPictures("GPUImage", "ImageWithFilter.jpg", null);
}
没有缩略图
Uri imageUri = ...;
mGPUImage = new GPUImage(context);
mGPUImage.setFilter(new GPUImageSobelEdgeDetection());
mGPUImage.setImage(imageUri);
mGPUImage.saveToPictures("GPUImage", "ImageWithFilter.jpg", null);
GSON
JSON的解析和封装框架
作者:CodeMiner
链接:https://www.jianshu.com/p/e31a92fdff35
作者:CodeMiner
链接:https://www.jianshu.com/p/e31a92fdff35
共同學習,寫下你的評論
評論加載中...
作者其他優質文章