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;
......
......@@ -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