Android: Use Cover Resource Dimensions to calculate sample size

This commit is contained in:
Mahmood(Thunder07) 2017-06-19 06:07:53 +01:00
parent 6423b610e4
commit 1549d8b1ba
2 changed files with 8 additions and 22 deletions

View File

@ -8,11 +8,9 @@ import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.virtualapplications.play.database.GameInfo;
@ -113,12 +111,10 @@ public class GameInfoEditActivity extends AppCompatActivity {
private int calculateInSampleSize(BitmapFactory.Options options) {
final int height = options.outHeight;
final int width = options.outWidth;
View v = LayoutInflater.from(this).inflate(R.layout.game_list_item, null, false);
v.measure(0, 0);
int reqWidth = viewHolder.gameImageView.getMeasuredWidth();
int reqHeight = viewHolder.gameImageView.getMeasuredHeight();
// TODO: Find a calculated width and height without ImageView
int reqWidth = (int) getResources().getDimension(R.dimen.cover_width);
int reqHeight = (int) getResources().getDimension(R.dimen.cover_height);
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {

View File

@ -21,7 +21,6 @@ import android.os.Build;
import android.util.LruCache;
import android.view.View;
import android.view.View.OnLongClickListener;
import android.widget.ImageView;
import com.virtualapplications.play.GameInfoEditActivity;
import com.virtualapplications.play.GameInfoStruct;
@ -159,7 +158,6 @@ public class GameInfo {
private GamesAdapter.CoverViewHolder viewHolder;
private String key;
private ImageView preview;
private String boxart;
private int pos;
@ -168,23 +166,15 @@ public class GameInfo {
this.boxart = boxart;
this.pos = pos;
}
protected void onPreExecute() {
if (viewHolder != null) {
preview = viewHolder.gameImageView;
}
}
private int calculateInSampleSize(BitmapFactory.Options options) {
final int height = options.outHeight;
final int width = options.outWidth;
int reqHeight = 420;
int reqWidth = 360;
if (preview != null) {
reqHeight = preview.getMeasuredHeight();
reqWidth = preview.getMeasuredWidth();
}
// TODO: Find a calculated width and height without ImageView
int reqHeight = (int) mContext.getResources().getDimension(R.dimen.cover_height);
int reqWidth = (int) mContext.getResources().getDimension(R.dimen.cover_width);
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {