您的位置:首页 > 其它

第三方库写能看的文档有多重要?

2015-09-25 15:51 323 查看
最近赶项目,用到一些第三方库,发现一些看起来比原来的使用更好的库

例如加载图片,可以说几乎是我们必备的一个工具。

看下下面两个

Android-Universal-Image-LoaderFacebook开源的一个Fresco

后者
Fresco
支持:

(1) 支持流式,可以类似网页上模糊渐进式显示图片

(2) 对多帧动画图片支持更好,如 Gif、WebP

(3) 更多样的显示,如圆角、进度条、点击重试、自定义对焦点

(4) 更多样的加载,如支持 EXIF、全面支持 WebP

(5) 支持 Android 2.3+

牛逼吧?,我看了也流口水,Facebook就是大法好,功能多,AUIL只支持图片的加载显示功能啊,太单一了! 必须使用。在来看下介绍详细页面:

比较介绍页面

1. AUIL的Usage

Acceptable URIs examples

"http://site.com/image.png" // from Web
"file:///mnt/sdcard/image.png" // from SD card
"file:///mnt/sdcard/video.mp4" // from SD card (video thumbnail)
"content://media/external/images/media/13" // from content provider
"content://media/external/video/media/13" // from content provider (video thumbnail)
"assets://image.png" // from assets
"drawable://" + R.drawable.img // from drawables (non-9patch images)


NOTE: Use
drawable://
only if you really need it! Always consider the native way to load drawables -
ImageView.setImageResource(...)
instead of using of
ImageLoader
.

Simple

ImageLoader imageLoader = ImageLoader.getInstance(); // Get singleton instance


// Load image, decode it to Bitmap and display Bitmap in ImageView (or any other view
//  which implements ImageAware interface)
imageLoader.displayImage(imageUri, imageView);


// Load image, decode it to Bitmap and return Bitmap to callback
imageLoader.loadImage(imageUri, new SimpleImageLoadingListener() {
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
// Do whatever you want with Bitmap
}
});


// Load image, decode it to Bitmap and return Bitmap synchronously
Bitmap bmp = imageLoader.loadImageSync(imageUri);


Complete

// Load image, decode it to Bitmap and display Bitmap in ImageView (or any other view
//  which implements ImageAware interface)
imageLoader.displayImage(imageUri, imageView, options, new ImageLoadingListener() {
@Override
public void onLoadingStarted(String imageUri, View view) {
...
}
@Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
...
}
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
...
}
@Override
public void onLoadingCancelled(String imageUri, View view) {
...
}
}, new ImageLoadingProgressListener() {
@Override
public void onProgressUpdate(String imageUri, View view, int current, int total) {
...
}
});


// Load image, decode it to Bitmap and return Bitmap to callback
ImageSize targetSize = new ImageSize(80, 50); // result Bitmap will be fit to this size
imageLoader.loadImage(imageUri, targetSize, options, new SimpleImageLoadingListener() {
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
// Do whatever you want with Bitmap
}
});


// Load image, decode it to Bitmap and return Bitmap synchronously
ImageSize targetSize = new ImageSize(80, 50); // result Bitmap will be fit to this size
Bitmap bmp = imageLoader.loadImageSync(imageUri, targetSize, options);


AUIL小结

好,快速的看了下,会用了,就两行代码。

ImageLoader imageLoader = ImageLoader.getInstance(); // Get singleton instance
imageLoader.displayImage(imageUri, imageView);


2. Fresco

接着来看下我们的Fresco表现

## Using Fresco in your application

If you are building with Gradle, simply add the following line to the
dependencies
section of your
build.gradle
file:

compile 'com.facebook.fresco:fresco:0.7.0+'


For full details, visit the documentation on our web site, available in English, Chinese, and Korean:







小结

啊。。。挺好的,还有三种语言的版本。行了,找别的库看看去了,这个下次有空再点击连接来看吧。

另外推荐一个库:

3. Glide

Glide

它可以最大性能地在 Android 设备上读取、解码、显示图片和视频。

Glide 可以将远程的图片、视频、动画图片等缓存在设备本地便于提高用户浏览图片的流畅体验。

特点:

(1) GIF 动画的解码

(2) 本地视频剧照的解码

(3) 支持缩略图

(4) Activity 生命周期的集成

(5) 转码的支持

(6) 动画的支持

(7) OkHttp 和 Volley 的支持

看看他的README怎么写的

Glide





Glide is a fast and efficient open source media management and image loading framework for Android that wraps media

decoding, memory and disk caching, and resource pooling into a simple and easy to use interface.



Glide supports fetching, decoding, and displaying video stills, images, and animated GIFs. Glide includes a flexible API

that allows developers to plug in to almost any network stack. By default Glide uses a custom
HttpUrlConnection
based

stack, but also includes utility libraries plug in to Google’s Volley project or Square’s OkHttp library instead.

Glide’s primary focus is on making scrolling any kind of a list of images as smooth and fast as possible, but Glide is

also effective for almost any case where you need to fetch, resize, and display a remote image.

Download

You can download a jar from GitHub’s releases page.

Or use Gradle:

repositories {
mavenCentral()
}

dependencies {
compile 'com.github.bumptech.glide:glide:3.6.1'
compile 'com.android.support:support-v4:19.1.0'
}


Or Maven:

<dependency>
<groupId>com.github.bumptech.glide</groupId>
<artifactId>glide</artifactId>
<version>3.6.1</version>
<type>aar</type>
</dependency>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>support-v4</artifactId>
<version>r7</version>
</dependency>


Proguard

Depending on your proguard config and usage, you may need to include the following lines in your proguard.cfg:

-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
**[] $VALUES;
public *;
}


How do I use Glide?

Checkout the GitHub wiki for pages on a variety of topics, and see the javadocs.

Simple use cases will look something like this:

// For a simple view:
@Override
public void onCreate(Bundle savedInstanceState) {
...
ImageView imageView = (ImageView) findViewById(R.id.my_image_view);

Glide.with(this).load("http://goo.gl/gEgYUd").into(imageView);
}

// For a simple image list:
@Override
public View getView(int position, View recycled, ViewGroup container) {
final ImageView myImageView;
if (recycled == null) {
myImageView = (ImageView) inflater.inflate(R.layout.my_image_view, container, false);
} else {
myImageView = (ImageView) recycled;
}

String url = myUrls.get(position);

Glide.with(myFragment)
.load(url)
.centerCrop()
.placeholder(R.drawable.loading_spinner)
.crossFade()
.into(myImageView);

return myImageView;
}


OkHttp and Volley

Support for OkHttp and Volley is provided by integration libraries you can optionally include as dependencies.

The integration libraries are available via Maven or the releases page.

For instructions on including either the OkHttp or the Volley integration libraries, see the Integration Libraries wiki page.

Android SDK Version

Glide requires a minimum SDK version of 10.

License

BSD, part MIT and Apache 2.0. See the LICENSE file for details.

Status

Version 3 is a stable public release used in multiple open source projects at Google including in the Android Camera

app and in the 2014 Google IO app. Version 4 is currently under development on the
master
branch.

Comments/bugs/questions/pull requests welcome!

Build

Building Glide with gradle is fairly straight forward:

git clone git@github.com:bumptech/glide.git # use https://github.com/bumptech/glide.git if "Permission Denied"
cd glide
git submodule init && git submodule update
./gradlew jar


Note: Make sure your Android SDK has the Android Support Repository installed, and that your
$ANDROID_HOME
environment

variable is pointing at the SDK or add a
local.properties
file in the root project with a
sdk.dir=...
line.

Samples

Follow the steps in the Build section to setup the project and then:

./gradlew :samples:flickr:run
./gradlew :samples:giphy:run
./gradlew :samples:svg:run


You may also find precompiled APKs on the releases page.

Development

Follow the steps in the Build section to setup the project and then edit the files however you wish.

Intellij IDEA 14 cleanly imports both Glide’s source and tests and is the recommended way to work with Glide.

To open the project in Intellij 14:

Go to File menu or the Welcome Screen

Click on Open…

Navigate to Glide’s root directory.

Select
build.gradle


Getting Help

To report a specific problem or feature request, open a new issue on Github. For questions, suggestions, or

anything else, join or email Glide’s discussion group, or join our IRC channel: irc.freenode.net#glide-library.

Contributing

Before submitting pull requests, contributors must sign Google’s individual contributor license agreement.

Thanks

The Android team and Jake Wharton for the disk cache implementation Glide’s disk cache is based on.

Dave Smith for the gif decoder gist Glide’s gif decoder is based on.

Chris Banes for his gradle-mvn-push script.

Corey Hall for Glide’s amazing logo.

Everyone who has contributed code and reported issues!

Author

Sam Judd - @samajudd

Disclaimer

This is not an official Google product.

屌屌的,不错,Fresco这个就弃用了。其实打开他们的文档网站看了,还是很清晰的,

不过如果可以还是写在你的README里面吧,

简单直接,对我友好我就多看几眼,不行我不是逼不得已不会用。

这可能是为何AUIL是最受欢迎的原因啊。直接写着怎么用啊。

另外要想编译Fresco来运行一次,那还真的不容易,不信你试下。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: