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 android.widget.ImageView;
|
||||||
|
|
||||||
import com.owncloud.android.datamodel.OCFile;
|
import com.owncloud.android.datamodel.OCFile;
|
||||||
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -73,14 +74,7 @@ public class ImageViewCustom extends ImageView {
|
||||||
|
|
||||||
mGifMovie.setTime((int) mMovieRunDuration);
|
mGifMovie.setTime((int) mMovieRunDuration);
|
||||||
|
|
||||||
float scale;
|
float scale = getScaleToViewFactor(mGifMovie, canvas);
|
||||||
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());
|
|
||||||
}
|
|
||||||
|
|
||||||
canvas.scale(scale, scale);
|
canvas.scale(scale, scale);
|
||||||
canvas.translate(((float) getWidth() / scale - (float) mGifMovie.width()) / 2f,
|
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
|
@Override
|
||||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
if (mGifMovie == null){
|
if (mGifMovie == null){
|
||||||
|
@ -125,7 +134,7 @@ public class ImageViewCustom extends ImageView {
|
||||||
super.setImageBitmap(bm);
|
super.setImageBitmap(bm);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setGifImage(OCFile file){
|
public void setGIFImage(OCFile file) {
|
||||||
try {
|
try {
|
||||||
InputStream gifInputStream = new FileInputStream(file.getStoragePath());
|
InputStream gifInputStream = new FileInputStream(file.getStoragePath());
|
||||||
setLayerType(View.LAYER_TYPE_SOFTWARE, null);
|
setLayerType(View.LAYER_TYPE_SOFTWARE, null);
|
||||||
|
@ -136,7 +145,7 @@ public class ImageViewCustom extends ImageView {
|
||||||
mMovieHeight = mGifMovie.height();
|
mMovieHeight = mGifMovie.height();
|
||||||
mMovieDuration = mGifMovie.duration();
|
mMovieDuration = mGifMovie.duration();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
Log_OC.e(TAG, "Failed to set GIF image");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -499,13 +499,13 @@ public class PreviewImageFragment extends FileFragment {
|
||||||
Log_OC.d(TAG, "Showing image with resolution " + bitmap.getWidth() + "x" +
|
Log_OC.d(TAG, "Showing image with resolution " + bitmap.getWidth() + "x" +
|
||||||
bitmap.getHeight());
|
bitmap.getHeight());
|
||||||
|
|
||||||
if (result.ocFile.getMimetype().equalsIgnoreCase("image/png")){
|
if (result.ocFile.getMimetype().equalsIgnoreCase("image/png")) {
|
||||||
Drawable backrepeat = getResources().getDrawable(R.drawable.backrepeat);
|
Drawable backrepeat = getResources().getDrawable(R.drawable.backrepeat);
|
||||||
imageView.setBackground(backrepeat);
|
imageView.setBackground(backrepeat);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.ocFile.getMimetype().equalsIgnoreCase("image/gif")){
|
if (result.ocFile.getMimetype().equalsIgnoreCase("image/gif")) {
|
||||||
imageView.setGifImage(result.ocFile);
|
imageView.setGIFImage(result.ocFile);
|
||||||
} else {
|
} else {
|
||||||
imageView.setImageBitmap(bitmap);
|
imageView.setImageBitmap(bitmap);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue