mirror of
https://github.com/nextcloud/android.git
synced 2024-11-25 22:55:46 +03:00
changes due to CR
This commit is contained in:
parent
7e583891f0
commit
4adecc96e8
2 changed files with 22 additions and 13 deletions
|
@ -11,6 +11,7 @@ import android.view.View;
|
|||
import android.widget.ImageView;
|
||||
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
|
@ -73,14 +74,7 @@ public class ImageViewCustom extends ImageView {
|
|||
|
||||
mGifMovie.setTime((int) mMovieRunDuration);
|
||||
|
||||
float scale;
|
||||
if(mGifMovie.height() > getHeight() || mGifMovie.width() > getWidth()) {
|
||||
scale = (1f / Math.min(canvas.getHeight() / mGifMovie.height(),
|
||||
canvas.getWidth() / mGifMovie.width())) + 0.25f;
|
||||
} else {
|
||||
scale = Math.min(canvas.getHeight() / mGifMovie.height(),
|
||||
canvas.getWidth() / mGifMovie.width());
|
||||
}
|
||||
float scale = getScaleToViewFactor(mGifMovie, canvas);
|
||||
|
||||
canvas.scale(scale, scale);
|
||||
canvas.translate(((float) getWidth() / scale - (float) mGifMovie.width()) / 2f,
|
||||
|
@ -93,6 +87,21 @@ public class ImageViewCustom extends ImageView {
|
|||
}
|
||||
}
|
||||
|
||||
private float getScaleToViewFactor(Movie movie, Canvas canvas){
|
||||
float scale;
|
||||
|
||||
if (movie.height() > getHeight() || movie.width() > getWidth()) {
|
||||
float offset = 0.25f;
|
||||
scale = (1f / Math.min(canvas.getHeight() / movie.height(),
|
||||
canvas.getWidth() / movie.width())) + offset;
|
||||
} else {
|
||||
scale = Math.min(canvas.getHeight() / movie.height(),
|
||||
canvas.getWidth() / movie.width());
|
||||
}
|
||||
|
||||
return scale;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
if (mGifMovie == null){
|
||||
|
@ -125,7 +134,7 @@ public class ImageViewCustom extends ImageView {
|
|||
super.setImageBitmap(bm);
|
||||
}
|
||||
|
||||
public void setGifImage(OCFile file){
|
||||
public void setGIFImage(OCFile file) {
|
||||
try {
|
||||
InputStream gifInputStream = new FileInputStream(file.getStoragePath());
|
||||
setLayerType(View.LAYER_TYPE_SOFTWARE, null);
|
||||
|
@ -136,7 +145,7 @@ public class ImageViewCustom extends ImageView {
|
|||
mMovieHeight = mGifMovie.height();
|
||||
mMovieDuration = mGifMovie.duration();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Log_OC.e(TAG, "Failed to set GIF image");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -505,7 +505,7 @@ public class PreviewImageFragment extends FileFragment {
|
|||
}
|
||||
|
||||
if (result.ocFile.getMimetype().equalsIgnoreCase("image/gif")) {
|
||||
imageView.setGifImage(result.ocFile);
|
||||
imageView.setGIFImage(result.ocFile);
|
||||
} else {
|
||||
imageView.setImageBitmap(bitmap);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue