Commit 7a92d476 authored by qq247321453's avatar qq247321453

ImageLoader

parent e98a7e0c
......@@ -3,7 +3,6 @@ package cn.garymb.ygomobile;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Point;
import android.os.ParcelFileDescriptor;
import android.text.TextUtils;
import android.util.Log;
import android.view.WindowManager;
......@@ -36,7 +35,6 @@ import static cn.garymb.ygomobile.Constants.DEF_PREF_KEEP_SCALE;
import static cn.garymb.ygomobile.Constants.DEF_PREF_NOTCH_HEIGHT;
import static cn.garymb.ygomobile.Constants.DEF_PREF_ONLY_GAME;
import static cn.garymb.ygomobile.Constants.DEF_PREF_READ_EX;
import static cn.garymb.ygomobile.Constants.DEF_PREF_WINDOW_TOP_BOTTOM;
import static cn.garymb.ygomobile.Constants.PREF_DEF_IMMERSIVE_MODE;
import static cn.garymb.ygomobile.Constants.PREF_DEF_SENSOR_REFRESH;
import static cn.garymb.ygomobile.Constants.PREF_FONT_SIZE;
......
......@@ -92,6 +92,7 @@ public interface Constants {
String UNKNOWN_IMAGE = "unknown.jpg";
String YDK_FILE_EX = ".ydk";
int[] CORE_SKIN_BG_SIZE = new int[]{1280, 720};
int[] CORE_SKIN_CARD_MINI_SIZE = new int[]{177, 254};
int[] CORE_SKIN_CARD_COVER_SIZE = new int[]{177, 254};
int[] CORE_SKIN_AVATAR_SIZE = new int[]{128, 128};
boolean SUPPORT_BPG = true;
......
package cn.garymb.ygomobile.loader;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.util.Log;
import android.widget.ImageView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.bumptech.glide.DrawableTypeRequest;
import com.bumptech.glide.load.ResourceDecoder;
import com.bumptech.glide.load.engine.Resource;
......@@ -15,7 +17,7 @@ import com.bumptech.glide.load.model.ImageVideoWrapper;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import com.bumptech.glide.load.resource.gifbitmap.GifBitmapWrapper;
import com.bumptech.glide.load.resource.gifbitmap.GifBitmapWrapperResource;
import com.bumptech.glide.request.target.GlideDrawableImageViewTarget;
import com.bumptech.glide.signature.MediaStoreSignature;
import com.bumptech.glide.signature.StringSignature;
import java.io.ByteArrayOutputStream;
......@@ -33,91 +35,104 @@ import java.util.zip.ZipFile;
import cn.garymb.ygomobile.AppsSettings;
import cn.garymb.ygomobile.Constants;
import cn.garymb.ygomobile.core.IrrlichtBridge;
import cn.garymb.ygomobile.lite.BuildConfig;
import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.utils.BitmapUtil;
import cn.garymb.ygomobile.utils.FileUtils;
import cn.garymb.ygomobile.utils.IOUtils;
import cn.garymb.ygomobile.utils.MD5Util;
import cn.garymb.ygomobile.utils.NetUtils;
import static cn.garymb.ygomobile.Constants.CORE_SKIN_BG_SIZE;
import static com.bumptech.glide.Glide.with;
public class ImageLoader implements Closeable {
private static final String TAG = ImageLoader.class.getSimpleName();
private ZipFile mZipFile;
private List<ZipFile> zipFileList;
private LruBitmapPool mLruBitmapPool;
// private ExecutorService mExecutorService = Executors.newSingleThreadExecutor();
private boolean isClose = false;
private Context mContext;
private static final Map<Context, ImageLoader> IMAGE_LOADER_MAP = new ConcurrentHashMap<>();
public static ImageLoader get(Context context) {
ImageLoader imageLoader = IMAGE_LOADER_MAP.get(context);
if (imageLoader == null) {
synchronized (IMAGE_LOADER_MAP) {
imageLoader = IMAGE_LOADER_MAP.get(context);
if (imageLoader == null) {
imageLoader = new ImageLoader(context);
IMAGE_LOADER_MAP.put(context, imageLoader);
}
}
}
return imageLoader;
public static final ImageLoader sImageLoader = new ImageLoader();
public static ImageLoader get() {
return sImageLoader;
}
public static void onDestory(Context context) {
synchronized (IMAGE_LOADER_MAP) {
IMAGE_LOADER_MAP.remove(context);
private static class Cache{
private final byte[] data;
private final String name;
public Cache(byte[] data, String name) {
this.data = data;
this.name = name;
}
}
private ImageLoader(Context context) {
mContext = context;
mLruBitmapPool = new LruBitmapPool(100);
zipFileList=new ArrayList<>();
private final boolean useCache;
private static final String TAG = ImageLoader.class.getSimpleName();
private final Map<String, ZipFile> zipFileCache = new ConcurrentHashMap<>();
private final LruBitmapPool mLruBitmapPool = new LruBitmapPool(128);
private final Map<Long, Cache> zipDataCache = new ConcurrentHashMap<>();
private ZipFile mDefaultZipFile;
private File mPicsFile;
public ImageLoader(){
this(false);
}
private class BpgResourceDecoder implements ResourceDecoder<ImageVideoWrapper, GifBitmapWrapper> {
String id;
public ImageLoader(boolean useCache) {
this.useCache = useCache;
}
private BpgResourceDecoder(String id) {
this.id = id;
private ZipFile openPicsZip() {
if(mPicsFile == null) {
mPicsFile = new File(AppsSettings.get().getResourcePath(), Constants.CORE_PICS_ZIP);
}
@Override
public Resource<GifBitmapWrapper> decode(ImageVideoWrapper source, int width, int height) throws IOException {
// Log.i("kk", "decode source:"+source);
Bitmap bitmap = IrrlichtBridge.getBpgImage(source.getStream(), Bitmap.Config.RGB_565);
// Log.i("kk", "decode bitmap:"+bitmap);
BitmapResource resource = new BitmapResource(bitmap, mLruBitmapPool);
return new GifBitmapWrapperResource(new GifBitmapWrapper(resource, null));
if (mDefaultZipFile == null) {
if (mPicsFile.exists()) {
try {
mDefaultZipFile = new ZipFile(mPicsFile);
} catch (IOException e) {
//Ignore
}
}
}
return mDefaultZipFile;
}
@Override
public String getId() {
return id;
public void resume(){
}
public void pause(){
//关闭zip
for (ZipFile zipFile : zipFileCache.values()) {
IOUtils.closeZip(zipFile);
}
zipFileCache.clear();
if (mDefaultZipFile != null) {
IOUtils.closeZip(mDefaultZipFile);
}
}
@Override
public void close() throws IOException {
isClose = true;
// if (!mExecutorService.isShutdown()) {
// mExecutorService.shutdown();
// }
public void close() {
if (BuildConfig.DEBUG_MODE) {
Log.d(TAG, "close and clean cache");
}
pause();
zipDataCache.clear();
}
private void bind(final byte[] data, String name, ImageView imageview, Drawable pre, int[] size) {
if (BuildConfig.DEBUG_MODE) {
Log.d(TAG, "bind data:" + name + ", size=" + (size == null ? "null" : size[0] + "x" + size[1]));
}
bindT(data, name, imageview, pre, size);
}
private Bitmap loadImage(String path, int w, int h) {
File file = new File(path);
if (file.exists()) {
return BitmapUtil.getBitmapFromFile(file.getAbsolutePath(), CORE_SKIN_BG_SIZE[0], CORE_SKIN_BG_SIZE[1]);
private void bind(final Uri uri, String name, ImageView imageview, Drawable pre, int[] size) {
if (BuildConfig.DEBUG_MODE) {
Log.d(TAG, "bind uri:" + name + ", size=" + (size == null ? "null" : size[0] + "x" + size[1]));
}
return null;
bindT(uri, name, imageview, pre, size);
}
private void bind(byte[] data, ImageView imageview, boolean isbpg, long code, Drawable pre, boolean isBig) {
DrawableTypeRequest<byte[]> resource = with(mContext).load(data);
private <T> void setDefaults(@NonNull DrawableTypeRequest<T> resource, String name,
@Nullable com.bumptech.glide.load.Key signature,
@Nullable Drawable pre,
@Nullable int[] size) {
if (pre != null) {
resource.placeholder(pre);
} else {
......@@ -125,29 +140,26 @@ public class ImageLoader implements Closeable {
}
resource.error(R.drawable.unknown);
resource.animate(R.anim.push_in);
// if(isbpg){
// resource.override(Constants.CORE_SKIN_CARD_COVER_SIZE[0], Constants.CORE_SKIN_CARD_COVER_SIZE[1]);
// }
resource.signature(new StringSignature(MD5Util.getStringMD5(data.length + "_" + code + "_" + isBig)));
if (isbpg) {
resource.decoder(new BpgResourceDecoder("bpg@" + code));
if (size != null) {
resource.override(size[0], size[1]);
}
if(signature != null) {
resource.signature(signature);
}
String ex = FileUtils.getFileExpansion(name);
if ("bpg".equals(ex)) {
resource.decoder(new BpgResourceDecoder(name, mLruBitmapPool));
}
resource.into(imageview);
}
public void bind(final File file, ImageView imageview, boolean isbpg, long code, Drawable pre, boolean isBig) {
private <T> void bindT(final T data, String name, ImageView imageview, Drawable pre, int[] size) {
try {
DrawableTypeRequest<File> resource = with(mContext).load(file);
if (pre != null) {
resource.placeholder(pre);
DrawableTypeRequest<T> resource = with(imageview.getContext()).load(data);
if (size == null) {
setDefaults(resource, name, new StringSignature(name), pre, size);
resource.signature(new StringSignature(name));
} else {
resource.placeholder(R.drawable.unknown);
}
resource.error(R.drawable.unknown);
resource.animate(R.anim.push_in);
resource.signature(new StringSignature(MD5Util.getStringMD5(file.length() + code + "_" + isBig)));
if (isbpg) {
resource.decoder(new BpgResourceDecoder("bpg@" + code));
setDefaults(resource, name, new StringSignature(name + ":" + size[0] + "x" + size[1]), pre, size);
}
resource.into(imageview);
} catch (Exception e) {
......@@ -155,122 +167,175 @@ public class ImageLoader implements Closeable {
}
}
private void bind(final String url, ImageView imageview, long code, Drawable pre, boolean isBig) {
DrawableTypeRequest<Uri> resource = with(mContext).load(Uri.parse(url));
if (pre != null) {
resource.placeholder(pre);
} else {
resource.placeholder(R.drawable.unknown);
private void bind(final File file, ImageView imageview, Drawable pre, int[] size) {
if (BuildConfig.DEBUG_MODE) {
Log.d(TAG, "bind file:" + file.getPath() + ", size=" + (size == null ? "null" : size[0] + "x" + size[1]));
}
try {
DrawableTypeRequest<File> resource = with(imageview.getContext()).load(file);
long key = size == null ? 0:(size[0] * size[1]);
setDefaults(resource, file.getName(),
new MediaStoreSignature("image/*",
file.lastModified() + key, 0), pre, size);
resource.into(imageview);
} catch (Exception e) {
Log.e(TAG, "$", e);
}
resource.error(R.drawable.unknown);
resource.override(Constants.CORE_SKIN_CARD_COVER_SIZE[0], Constants.CORE_SKIN_CARD_COVER_SIZE[1]);
resource.signature(new StringSignature("" + code));
resource.into(new GlideDrawableImageViewTarget(imageview));
}
public void bindImage(ImageView imageview, long code) {
bindImage(imageview, code, null);
private boolean bindInZip(ImageView imageView, long code, Drawable pre, ZipFile zipFile, String nameWithEx, int[] size) {
ZipEntry entry;
InputStream inputStream = null;
ByteArrayOutputStream outputStream;
boolean bind = false;
try {
entry = zipFile.getEntry(nameWithEx);
if (entry != null) {
inputStream = zipFile.getInputStream(entry);
outputStream = new ByteArrayOutputStream();
IOUtils.copy(inputStream, outputStream);
byte[] data = outputStream.toByteArray();
if(useCache){
zipDataCache.put(code, new Cache(data, nameWithEx));
}
bind(data, nameWithEx, imageView, pre, size);
bind = true;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
IOUtils.close(inputStream);
}
return bind;
}
private void cleanInValidZips() {
List<String> removes = new ArrayList<>();
for (String old : zipFileCache.keySet()) {
if (!FileUtils.isExist(old)) {
removes.add(old);
}
}
for (String key : removes) {
zipFileCache.remove(key);
}
}
public void bindImage(ImageView imageview, long code, Drawable pre) {
bindImage(imageview, code, pre, false);
/**
* 177x254
*/
public void bindImage(ImageView imageview, long code) {
bindImage(imageview, code, null, Constants.CORE_SKIN_CARD_MINI_SIZE);
}
/**
* @param big true则是原始大小
*/
@Deprecated
public void bindImage(ImageView imageview, long code, Drawable pre, boolean big) {
bindImage(imageview, code, pre, big ? null : Constants.CORE_SKIN_CARD_MINI_SIZE);
}
public void bindImage(ImageView imageview, long code, Drawable pre, boolean isBig) {
public void bindImage(ImageView imageview, long code, Drawable pre, int[] size) {
if (BuildConfig.DEBUG_MODE) {
Log.d(TAG, "bind image:" + code + ", size=" + (size == null ? "null" : size[0] + "x" + size[1]));
}
String name = Constants.CORE_IMAGE_PATH + "/" + code;
String name_ex = Constants.CORE_EXPANSIONS_IMAGE_PATH + "/" + code;
String path = AppsSettings.get().getResourcePath();
boolean bind = false;
File zip = new File(path, Constants.CORE_PICS_ZIP);
List<File> zipList=new ArrayList<>();
//1.图片文件
for (String ex : Constants.IMAGE_EX) {
File file = new File(AppsSettings.get().getResourcePath(), name + ex);
File file_ex = new File(AppsSettings.get().getResourcePath(), name_ex + ex);
if (file_ex.exists()) {
bind(file_ex, imageview, Constants.BPG.equals(ex), code, pre, isBig);
bind = true;
return;
} else
if (file.exists()) {
bind(file, imageview, Constants.BPG.equals(ex), code, pre, isBig);
bind = true;
bind(file_ex, imageview, pre, size);
return;
} else if (file.exists()) {
bind(file, imageview, pre, size);
return;
}
}
if (zip.exists()) {
ZipEntry entry = null;
InputStream inputStream = null;
ByteArrayOutputStream outputStream = null;
try {
if (mZipFile == null) {
mZipFile = new ZipFile(zip);
}
//cache
if(useCache) {
Cache cache = zipDataCache.get(code);
if (cache != null) {
bind(cache.data, cache.name, imageview, pre, size);
return;
}
}
//2.zip
{
ZipFile pics = openPicsZip();
if (pics != null) {
for (String ex : Constants.IMAGE_EX) {
entry = mZipFile.getEntry(name + ex);
if (entry != null) {
inputStream = mZipFile.getInputStream(entry);
outputStream = new ByteArrayOutputStream();
IOUtils.copy(inputStream, outputStream);
bind(outputStream.toByteArray(), imageview, Constants.BPG.equals(ex), code, pre, isBig);
bind = true;
break;
if (bindInZip(imageview, code, pre, pics, name + ex, size)) {
return;
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
IOUtils.close(inputStream);
}
}
if (!bind) {
File[] files = new File(AppsSettings.get().getResourcePath(), Constants.CORE_EXPANSIONS).listFiles();
if (files != null) {
for (File file :files) {
if (file.isFile() && (file.getName().endsWith(".zip") || file.getName().endsWith(".ypk"))) {
ZipEntry entry = null;
InputStream inputStream = null;
ByteArrayOutputStream outputStream = null;
//3.
//zips
File[] files = new File(AppsSettings.get().getResourcePath(), Constants.CORE_EXPANSIONS)
.listFiles((dir, name1) -> name1.endsWith(".zip") || name1.endsWith(".ypk"));
cleanInValidZips();
if (files != null) {
for (File file : files) {
if (file.isFile()) {
ZipFile zipFile = useCache ? zipFileCache.get(file.getAbsolutePath()) : null;
if (zipFile == null) {
try {
ZipFile zipFile = null;
for(ZipFile zipFile1:zipFileList){
if (zipFile1.getName().equals(file.getAbsolutePath())){
zipFile=zipFile1;
break;
}
zipFile = new ZipFile(file);
if(useCache) {
zipFileCache.put(file.getAbsolutePath(), zipFile);
}
if (zipFile==null){
zipFile=new ZipFile(file.getAbsoluteFile());
zipFileList.add(zipFile);
}
for (String ex : Constants.IMAGE_EX) {
entry = zipFile.getEntry(name + ex);
if (entry != null) {
inputStream = zipFile.getInputStream(entry);
outputStream = new ByteArrayOutputStream();
IOUtils.copy(inputStream, outputStream);
bind(outputStream.toByteArray(), imageview, Constants.BPG.equals(ex), code, pre, isBig);
bind = true;
break;
}
}
if (bind)
break;
} catch (Exception e) {
e.printStackTrace();
} finally {
IOUtils.close(inputStream);
} catch (Throwable e) {
//Ignore
}
}
if (zipFile == null) {
continue;
}
for (String ex : Constants.IMAGE_EX) {
if (bindInZip(imageview, code, pre, zipFile, name + ex, size)) {
return;
}
}
}
}
}
if (!bind) {
if (Constants.NETWORK_IMAGE && NetUtils.isWifiConnected(imageview.getContext())) {
bind(String.format(Constants.IMAGE_URL, "" + code), imageview, code, pre, isBig);
} else {
imageview.setImageResource(R.drawable.unknown);
//4 http
if (Constants.NETWORK_IMAGE && NetUtils.isWifiConnected(imageview.getContext())) {
bind(Uri.parse(String.format(Constants.IMAGE_URL, "" + code)), code + ".jpg", imageview, pre, size);
} else {
imageview.setImageResource(R.drawable.unknown);
}
}
private static class BpgResourceDecoder implements ResourceDecoder<ImageVideoWrapper, GifBitmapWrapper> {
private final String id;
private final LruBitmapPool mLruBitmapPool;
private BpgResourceDecoder(String id, LruBitmapPool lruBitmapPool) {
this.id = id;
this.mLruBitmapPool = lruBitmapPool;
}
@Override
public Resource<GifBitmapWrapper> decode(ImageVideoWrapper source, int width, int height) {
Bitmap bitmap = IrrlichtBridge.getBpgImage(source.getStream(), Bitmap.Config.RGB_565);
if (bitmap == null) {
return null;
}
BitmapResource resource = new BitmapResource(bitmap, mLruBitmapPool);
return new GifBitmapWrapperResource(new GifBitmapWrapper(resource, null));
}
@Override
public String getId() {
return id;
}
}
}
......@@ -24,7 +24,6 @@ import com.app.hubert.guide.model.HighLight;
import com.app.hubert.guide.model.HighlightOptions;
import com.bumptech.glide.Glide;
import java.io.IOException;
import java.util.List;
import cn.garymb.ygomobile.Constants;
......@@ -45,7 +44,7 @@ public abstract class BaseCardsActivity extends BaseActivity implements CardLoad
protected CardListAdapter mCardListAdapter;
protected CardLoader mCardLoader;
protected boolean isLoad = false;
private ImageLoader mImageLoader;
protected ImageLoader mImageLoader;
protected StringManager mStringManager = DataManager.get().getStringManager();
protected LimitManager mLimitManager = DataManager.get().getLimitManager();
protected int screenWidth;
......@@ -55,7 +54,7 @@ public abstract class BaseCardsActivity extends BaseActivity implements CardLoad
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_deck_cards);
AnimationShake2();
mImageLoader = ImageLoader.get(this);
mImageLoader = new ImageLoader(true);
mDrawerLayout = $(R.id.drawer_layout);
screenWidth = getResources().getDisplayMetrics().widthPixels;
mListView = $(R.id.list_cards);
......@@ -217,14 +216,22 @@ public abstract class BaseCardsActivity extends BaseActivity implements CardLoad
}
}
@Override
protected void onResume() {
// mImageLoader.resume();
super.onResume();
}
@Override
protected void onPause() {
//仅退出的时候才关闭zip
// mImageLoader.pause();
super.onPause();
}
@Override
protected void onDestroy() {
ImageLoader.onDestory(this);
try {
mImageLoader.close();
} catch (IOException e) {
e.printStackTrace();
}
mImageLoader.close();
super.onDestroy();
}
......
......@@ -16,26 +16,28 @@ import ocgcore.data.Card;
import ocgcore.enums.CardType;
import static android.view.View.inflate;
import static android.view.View.resolveSize;
public class CardDetailRandom {
private static View viewCardDetail;
private static ImageView cardImage;
private static TextView name;
private static TextView desc;
private static TextView level;
private static TextView type;
private static TextView race;
private static TextView cardAtk;
private static TextView cardDef;
private static TextView attrView;
private static View monsterlayout;
private static View atkdefView, textdefView;
private static ImageLoader imageLoader;
private static StringManager mStringManager;
private View viewCardDetail;
private ImageView cardImage;
private TextView name;
private TextView desc;
private TextView level;
private TextView type;
private TextView race;
private TextView cardAtk;
private TextView cardDef;
private TextView attrView;
private View monsterlayout;
private View atkdefView, textdefView;
private StringManager mStringManager;
private Context mContext;
public static void RandomCardDetail(Context context, Card cardInfo) {
if (cardInfo == null) return;
imageLoader = ImageLoader.get(context);
private static CardDetailRandom sCardDetailRandom = null;
private CardDetailRandom(Context context, Card cardInfo) {
mContext = context;
viewCardDetail = inflate(context, R.layout.dialog_cardinfo_small, null);
cardImage = viewCardDetail.findViewById(R.id.card_image_toast);
name = viewCardDetail.findViewById(R.id.card_name_toast);
......@@ -51,7 +53,6 @@ public class CardDetailRandom {
desc = viewCardDetail.findViewById(R.id.text_desc_toast);
mStringManager = DataManager.get().getStringManager();
imageLoader.bindImage(cardImage, cardInfo.Code);
name.setText(cardInfo.Name);
type.setText(CardUtils.getAllTypeString(cardInfo, mStringManager).replace("/", "|"));
attrView.setText(mStringManager.getAttributeString(cardInfo.Attribute));
......@@ -88,8 +89,24 @@ public class CardDetailRandom {
viewCardDetail.setRotationY(5);
}
public static void showRandromCardDetailToast(Context context) {
Toast toast = new Toast(context);
public static CardDetailRandom genRandomCardDetail(Context context, ImageLoader imageLoader, Card cardInfo) {
if (cardInfo == null) return null;
CardDetailRandom cardDetailRandom = new CardDetailRandom(context, cardInfo);
cardDetailRandom.bindCardImage(imageLoader, cardInfo.Alias != 0 ? cardInfo.Alias : cardInfo.Code);
sCardDetailRandom = cardDetailRandom;
return cardDetailRandom;
}
public void bindCardImage(ImageLoader imageLoader, long code) {
imageLoader.bindImage(cardImage, code, null, true);
}
public View getView() {
return viewCardDetail;
}
public void show(){
Toast toast = new Toast(mContext);
toast.setView(viewCardDetail);
toast.setDuration(Toast.LENGTH_LONG);
toast.setGravity(Gravity.LEFT, 0, 0);
......
......@@ -27,7 +27,6 @@ import com.app.hubert.guide.model.HighlightOptions;
import com.bumptech.glide.Glide;
import com.ourygo.assistant.util.DuelAssistantManagement;
import java.io.IOException;
import java.util.List;
import cn.garymb.ygomobile.Constants;
......@@ -77,7 +76,7 @@ public class CardSearchActivity extends BaseActivity implements CardLoader.CallB
// setSupportActionBar(toolbar);
enableBackHome();
mDrawerlayout = $(R.id.drawer_layout);
mImageLoader = ImageLoader.get(this);
mImageLoader = new ImageLoader(true);
mListView = $(R.id.list_cards);
mCardListAdapter = new CardListAdapter(this, mImageLoader);
mCardListAdapter.setItemBg(true);
......@@ -190,12 +189,7 @@ public class CardSearchActivity extends BaseActivity implements CardLoader.CallB
@Override
protected void onDestroy() {
ImageLoader.onDestory(this);
try {
mImageLoader.close();
} catch (IOException e) {
e.printStackTrace();
}
mImageLoader.close();
super.onDestroy();
}
......
......@@ -47,7 +47,6 @@ import com.ourygo.assistant.base.listener.OnDuelAssistantListener;
import com.ourygo.assistant.util.DuelAssistantManagement;
import com.ourygo.assistant.util.Util;
import com.tencent.bugly.beta.Beta;
import com.tencent.smtt.export.external.TbsCoreSettings;
import com.tencent.smtt.sdk.QbSdk;
import com.tubb.smrv.SwipeMenuRecyclerView;
......@@ -58,7 +57,6 @@ import org.greenrobot.eventbus.ThreadMode;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import cn.garymb.ygodata.YGOGameOptions;
......@@ -71,6 +69,7 @@ import cn.garymb.ygomobile.bean.ServerList;
import cn.garymb.ygomobile.bean.events.ServerInfoEvent;
import cn.garymb.ygomobile.lite.BuildConfig;
import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.loader.ImageLoader;
import cn.garymb.ygomobile.ui.activities.BaseActivity;
import cn.garymb.ygomobile.ui.activities.FileLogActivity;
import cn.garymb.ygomobile.ui.activities.WebActivity;
......@@ -108,13 +107,15 @@ public abstract class HomeActivity extends BaseActivity implements NavigationVie
private ServerListManager mServerListManager;
private DuelAssistantManagement duelAssistantManagement;
private CardManager mCardManager;
private SparseArray<Card> cards;
private CardDetailRandom mCardDetailRandom;
private ImageLoader mImageLoader;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
setExitAnimEnable(false);
mImageLoader = new ImageLoader(false);
mCardManager = DataManager.get().getCardManager();
//server list
initServerlist();
......@@ -158,10 +159,17 @@ public abstract class HomeActivity extends BaseActivity implements NavigationVie
@Override
protected void onResume() {
mImageLoader.resume();
super.onResume();
BacktoDuel();
}
@Override
protected void onPause() {
mImageLoader.pause();
super.onPause();
}
private void duelAssistantCheck() {
if (AppsSettings.get().isServiceDuelAssistant()) {
Handler handler = new Handler();
......@@ -304,7 +312,9 @@ public abstract class HomeActivity extends BaseActivity implements NavigationVie
break;
case R.id.action_game:
setRandomCardDetail();
CardDetailRandom.showRandromCardDetailToast(this);
if(mCardDetailRandom != null){
mCardDetailRandom.show();
}
openGame();
break;
case R.id.action_settings: {
......@@ -665,12 +675,12 @@ public abstract class HomeActivity extends BaseActivity implements NavigationVie
//加载数据库中所有卡片卡片
mCardManager.loadCards();
//mCardManager = DataManager.get().getCardManager();
cards = mCardManager.getAllCards();
SparseArray<Card> cards = mCardManager.getAllCards();
int y = (int) (Math.random() * cards.size());
Card cardInfo = cards.valueAt(y);
if (cardInfo == null)
return;
CardDetailRandom.RandomCardDetail(this, cardInfo);
mCardDetailRandom = CardDetailRandom.genRandomCardDetail(this, mImageLoader, cardInfo);
}
public void showTipsToast() {
......
......@@ -13,7 +13,9 @@ import androidx.annotation.Nullable;
import java.util.List;
import cn.garymb.ygomobile.Constants;
import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.loader.ImageLoader;
import cn.garymb.ygomobile.ui.cards.deck.ImageTop;
import ocgcore.data.Card;
import ocgcore.data.LimitList;
......@@ -23,8 +25,13 @@ public class CardGroupView extends FrameLayout {
private int mLineLimit = 10;
private int mOrgLineLimit = 10;
private int mLineMaxCount = 15;
private int mCardWidth = 177, mCardHeight = 255;
private int mCardWidth = Constants.CORE_SKIN_CARD_MINI_SIZE[0], mCardHeight = Constants.CORE_SKIN_CARD_MINI_SIZE[1];
private boolean mPausePadding;
private ImageLoader mImageLoader;
public void setImageLoader(ImageLoader imageLoader) {
mImageLoader = imageLoader;
}
//region init
public CardGroupView(@NonNull Context context) {
......@@ -219,7 +226,7 @@ public class CardGroupView extends FrameLayout {
refreshLayoutParams(count + 1);
}
CardView cardView = new CardView(getContext());
cardView.showCard(card);
cardView.showCard(mImageLoader, card);
addView(cardView, index);
return true;
}
......
......@@ -91,11 +91,11 @@ public class CardView extends FrameLayout {
}
}
public void showCard(Card cardInfo) {
public void showCard(ImageLoader imageLoader, Card cardInfo) {
if (mCard != null && mCard.equals(cardInfo)) return;
mCard = cardInfo;
if (cardInfo != null) {
ImageLoader.get(getContext()).bindImage(mCardView, cardInfo.Code);
if (cardInfo != null && imageLoader != null) {
imageLoader.bindImage(mCardView, cardInfo.Code, null, true);
} else {
mTopImage.setVisibility(View.GONE);
mCardView.setImageBitmap(null);
......
......@@ -20,6 +20,7 @@ import java.util.Map;
import cn.garymb.ygomobile.Constants;
import cn.garymb.ygomobile.bean.DeckInfo;
import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.loader.ImageLoader;
import cn.garymb.ygomobile.ui.cards.deck.ImageTop;
import cn.garymb.ygomobile.ui.cards.deck.LabelInfo;
import ocgcore.data.Card;
......@@ -43,6 +44,11 @@ public class DeckGroupView extends FrameLayout implements View.OnClickListener {
private CardView mLastView;
private boolean mAutoSort;
private EditMode mEditMode;
private ImageLoader mImageLoader;
public void setImageLoader(ImageLoader imageLoader) {
mImageLoader = imageLoader;
}
public enum EditMode {
None,
......@@ -257,7 +263,7 @@ public class DeckGroupView extends FrameLayout implements View.OnClickListener {
cardView.setSelected(false);
if (i < mDeckInfo.getExtraCount()) {
if (i == index && count > 0) {
cardView.showCard(mDeckInfo.getExtraCard(i));
cardView.showCard(mImageLoader, mDeckInfo.getExtraCard(i));
index++;
count--;
}
......@@ -265,7 +271,7 @@ public class DeckGroupView extends FrameLayout implements View.OnClickListener {
cardView.updateLimit(getImageTop(), mLimitList);
}
} else {
cardView.showCard(null);
cardView.showCard(mImageLoader, null);
}
}
resizePadding(Type.Extra, mExtraViews);
......@@ -278,11 +284,11 @@ public class DeckGroupView extends FrameLayout implements View.OnClickListener {
cardView.setSelected(false);
orgPos = i % Constants.DECK_WIDTH_MAX_COUNT;
if (orgPos >= mMainLimit) {
cardView.showCard(null);
cardView.showCard(mImageLoader, null);
} else {
if (index < mDeckInfo.getMainCount()) {
if (targetIndex == i && count > 0) {
cardView.showCard(mDeckInfo.getMainCard(index));
cardView.showCard(mImageLoader, mDeckInfo.getMainCard(index));
index++;
targetIndex = (index / mMainLimit) * Constants.DECK_WIDTH_MAX_COUNT + (index % mMainLimit);
count--;
......@@ -295,7 +301,7 @@ public class DeckGroupView extends FrameLayout implements View.OnClickListener {
mMainViews.get(i).updateLimit(getImageTop(), mLimitList);
}
} else {
cardView.showCard(null);
cardView.showCard(mImageLoader, null);
}
}
}
......@@ -307,7 +313,7 @@ public class DeckGroupView extends FrameLayout implements View.OnClickListener {
cardView.setSelected(false);
if (i < mDeckInfo.getSideCount()) {
if (i == index && count > 0) {
cardView.showCard(mDeckInfo.getSideCard(i));
cardView.showCard(mImageLoader, mDeckInfo.getSideCard(i));
index++;
count--;
}
......@@ -315,7 +321,7 @@ public class DeckGroupView extends FrameLayout implements View.OnClickListener {
cardView.updateLimit(getImageTop(), mLimitList);
}
} else {
cardView.showCard(null);
cardView.showCard(mImageLoader, null);
}
}
resizePadding(Type.Side, mSideViews);
......
......@@ -7,6 +7,7 @@ import android.widget.LinearLayout;
import androidx.annotation.Nullable;
import cn.garymb.ygomobile.bean.DeckInfo;
import cn.garymb.ygomobile.loader.ImageLoader;
import cn.garymb.ygomobile.ui.cards.deck.ImageTop;
import cn.garymb.ygomobile.ui.cards.deck.LabelInfo;
import ocgcore.data.Card;
......@@ -20,6 +21,8 @@ public class DeckView extends LinearLayout {
private final ImageTop mImageTop;
private boolean mAutoSort, mEditMode, mLimitChanged;
private ImageLoader mImageLoader;
//region init
public DeckView(Context context) {
this(context, null);
......@@ -40,6 +43,7 @@ public class DeckView extends LinearLayout {
mMainGroup = new CardGroupView(context);
mExtraGroup = new CardGroupView(context);
mSideGroup = new CardGroupView(context);
int cardWidth = 0;
int cardHeight = 0;
if (cardWidth <= 0) {
......@@ -67,6 +71,13 @@ public class DeckView extends LinearLayout {
addView(mSideGroup, new LayoutParams(LayoutParams.MATCH_PARENT, cardHeight));
}
public void setImageLoader(ImageLoader imageLoader) {
mImageLoader = imageLoader;
mMainGroup.setImageLoader(imageLoader);
mExtraGroup.setImageLoader(imageLoader);
mSideGroup.setImageLoader(imageLoader);
}
public ImageTop getImageTop() {
return mImageTop;
}
......
......@@ -27,6 +27,19 @@ import cn.garymb.ygomobile.Constants;
public class FileUtils {
public static boolean isExist(String path){
return path != null && new File(path).exists();
}
public static String getFileExpansion(String path){
int index = path.lastIndexOf(".");
if(index>0){
return path.substring(index+1).toLowerCase();
}
return "";
}
public static void closeQuietly(Closeable closeable) {
if (closeable != null) {
try {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment