GifSizeFilter
/** Copyright 2017 Zhihu Inc.** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at** http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*/
package com.zhihu.matisse.sample.image;import android.content.Context;
import android.graphics.Point;import com.zhihu.matisse.MimeType;
import com.zhihu.matisse.filter.Filter;
import com.zhihu.matisse.internal.entity.IncapableCause;
import com.zhihu.matisse.internal.entity.Item;
import com.zhihu.matisse.internal.utils.PhotoMetadataUtils;
import com.zhihu.matisse.sample.R;import java.util.HashSet;
import java.util.Set;public class GifSizeFilter extends Filter {private int mMinWidth;private int mMinHeight;private int mMaxSize;public GifSizeFilter(int minWidth, int minHeight, int maxSizeInBytes) {mMinWidth = minWidth;mMinHeight = minHeight;mMaxSize = maxSizeInBytes;}@Overridepublic Set<MimeType> constraintTypes() {return new HashSet<MimeType>() {{add(MimeType.GIF);}};}@Overridepublic IncapableCause filter(Context context, Item item) {if (!needFiltering(context, item))return null;Point size = PhotoMetadataUtils.getBitmapBound(context.getContentResolver(), item.getContentUri());if (size.x < mMinWidth || size.y < mMinHeight || item.size > mMaxSize) {return new IncapableCause(IncapableCause.DIALOG, context.getString(R.string.error_gif, mMinWidth,String.valueOf(PhotoMetadataUtils.getSizeInMB(mMaxSize))));}return null;}}
glide
Glide4Engine
/** Copyright 2017 Zhihu Inc.** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at** http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*/
package com.zhihu.matisse.sample.image;import android.content.Context;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.widget.ImageView;import com.bumptech.glide.Glide;
import com.bumptech.glide.Priority;
import com.bumptech.glide.request.RequestOptions;
import com.zhihu.matisse.engine.ImageEngine;/*** {@link ImageEngine} implementation using Glide.*/public class Glide4Engine implements ImageEngine {@Overridepublic void loadThumbnail(Context context, int resize, Drawable placeholder, ImageView imageView, Uri uri) {Glide.with(context).asBitmap() // some .jpeg files are actually gif.load(uri).apply(new RequestOptions().override(resize, resize).placeholder(placeholder).centerCrop()).into(imageView);}@Overridepublic void loadGifThumbnail(Context context, int resize, Drawable placeholder, ImageView imageView,Uri uri) {Glide.with(context).asBitmap() // some .jpeg files are actually gif.load(uri).apply(new RequestOptions().override(resize, resize).placeholder(placeholder).centerCrop()).into(imageView);}@Overridepublic void loadImage(Context context, int resizeX, int resizeY, ImageView imageView, Uri uri) {Glide.with(context).load(uri).apply(new RequestOptions().override(resizeX, resizeY).priority(Priority.HIGH).fitCenter()).into(imageView);}@Overridepublic void loadGifImage(Context context, int resizeX, int resizeY, ImageView imageView, Uri uri) {Glide.with(context).asGif().load(uri).apply(new RequestOptions().override(resizeX, resizeY).priority(Priority.HIGH).fitCenter()).into(imageView);}@Overridepublic boolean supportAnimatedGif() {return true;}}