mirror of
https://github.com/nextcloud/android.git
synced 2024-11-28 02:17:43 +03:00
Fixed bug. Check if bitmap exceed the 2048x2048 size and set the imageview layer type to software one in order to avoid problems with OpenGL texture
This commit is contained in:
parent
aa354e5d73
commit
c376eef2e7
1 changed files with 29 additions and 3 deletions
|
@ -19,10 +19,12 @@ package com.owncloud.android.ui.preview;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
|
|
||||||
import android.accounts.Account;
|
import android.accounts.Account;
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.FragmentStatePagerAdapter;
|
import android.support.v4.app.FragmentStatePagerAdapter;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
@ -56,9 +58,15 @@ import com.owncloud.android.ui.fragment.FileFragment;
|
||||||
* @author David A. Velasco
|
* @author David A. Velasco
|
||||||
*/
|
*/
|
||||||
public class PreviewImageFragment extends FileFragment {
|
public class PreviewImageFragment extends FileFragment {
|
||||||
|
|
||||||
|
private static final boolean IS_HONEYCOMB_OR_HIGHER = Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB;
|
||||||
|
|
||||||
public static final String EXTRA_FILE = "FILE";
|
public static final String EXTRA_FILE = "FILE";
|
||||||
public static final String EXTRA_ACCOUNT = "ACCOUNT";
|
public static final String EXTRA_ACCOUNT = "ACCOUNT";
|
||||||
|
|
||||||
|
public static final int MAX_OPENGL_TEXTURE_WIDTH = 2048;
|
||||||
|
public static final int MAX_OPENGL_TEXTURE_HEIGHT = 2048;
|
||||||
|
|
||||||
private View mView;
|
private View mView;
|
||||||
private Account mAccount;
|
private Account mAccount;
|
||||||
private TouchImageView mImageView;
|
private TouchImageView mImageView;
|
||||||
|
@ -399,10 +407,16 @@ public class PreviewImageFragment extends FileFragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("InlinedApi")
|
||||||
private void showLoadedImage(Bitmap result) {
|
private void showLoadedImage(Bitmap result) {
|
||||||
if (mImageViewRef != null) {
|
if (mImageViewRef != null) {
|
||||||
final ImageView imageView = mImageViewRef.get();
|
final ImageView imageView = mImageViewRef.get();
|
||||||
if (imageView != null) {
|
if (imageView != null) {
|
||||||
|
if(IS_HONEYCOMB_OR_HIGHER && checkIfMaximumBitmapExceed(result)) {
|
||||||
|
// Set layer type to software one for avoiding exceed
|
||||||
|
// and problems in visualization
|
||||||
|
imageView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
|
||||||
|
}
|
||||||
imageView.setImageBitmap(result);
|
imageView.setImageBitmap(result);
|
||||||
imageView.setVisibility(View.VISIBLE);
|
imageView.setVisibility(View.VISIBLE);
|
||||||
mBitmap = result;
|
mBitmap = result;
|
||||||
|
@ -467,4 +481,16 @@ public class PreviewImageFragment extends FileFragment {
|
||||||
return mImageView;
|
return mImageView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if current bitmaps exceed the maximum OpenGL texture size limit
|
||||||
|
* @param bitmap
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
private boolean checkIfMaximumBitmapExceed(Bitmap bitmap) {
|
||||||
|
if (bitmap.getWidth() > MAX_OPENGL_TEXTURE_WIDTH
|
||||||
|
|| bitmap.getHeight() > MAX_OPENGL_TEXTURE_HEIGHT) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue