Commit bd0682d2 authored by feihuaduo's avatar feihuaduo

优化软件启动速度

parent 250ff94b
...@@ -20,12 +20,13 @@ public abstract class GameApplication extends Application implements IrrlichtBri ...@@ -20,12 +20,13 @@ public abstract class GameApplication extends Application implements IrrlichtBri
private Map<String, Integer> mSoundIdMap; private Map<String, Integer> mSoundIdMap;
private static GameApplication sGameApplication; private static GameApplication sGameApplication;
private boolean isInitSoundEffectPool=false;
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
sGameApplication = this; sGameApplication = this;
initSoundEffectPool(); // initSoundEffectPool();
} }
public static GameApplication get() { public static GameApplication get() {
...@@ -43,8 +44,16 @@ public abstract class GameApplication extends Application implements IrrlichtBri ...@@ -43,8 +44,16 @@ public abstract class GameApplication extends Application implements IrrlichtBri
mSoundEffectPool.release(); mSoundEffectPool.release();
} }
public boolean isInitSoundEffectPool() {
return isInitSoundEffectPool;
}
protected void setInitSoundEffectPool(boolean initSoundEffectPool) {
isInitSoundEffectPool = initSoundEffectPool;
}
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
protected void initSoundEffectPool() { public void initSoundEffectPool() {
mSoundEffectPool = new SoundPool(2, AudioManager.STREAM_MUSIC, 0); mSoundEffectPool = new SoundPool(2, AudioManager.STREAM_MUSIC, 0);
AssetManager am = getAssets(); AssetManager am = getAssets();
String[] sounds; String[] sounds;
......
...@@ -86,8 +86,6 @@ dependencies { ...@@ -86,8 +86,6 @@ dependencies {
implementation 'com.android.support:design:' + rootProject.ext.supportVersion implementation 'com.android.support:design:' + rootProject.ext.supportVersion
implementation 'org.jdeferred:jdeferred-android-aar:1.2.4' implementation 'org.jdeferred:jdeferred-android-aar:1.2.4'
implementation 'org.jdeferred:jdeferred-android-aar:1.2.4'
implementation 'com.github.bumptech.glide:glide:3.7.0'
implementation 'com.github.bumptech.glide:glide:3.7.0' implementation 'com.github.bumptech.glide:glide:3.7.0'
implementation('com.github.chrisbanes.photoview:library:1.2.4') { implementation('com.github.chrisbanes.photoview:library:1.2.4') {
implementation 'com.github.chrisbanes.photoview:library:1.2.4' implementation 'com.github.chrisbanes.photoview:library:1.2.4'
......
...@@ -12,6 +12,11 @@ public class App extends GameApplication { ...@@ -12,6 +12,11 @@ public class App extends GameApplication {
super.onCreate(); super.onCreate();
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
AppsSettings.init(this); AppsSettings.init(this);
if (AppsSettings.get().isSoundEffect()) {
initSoundEffectPool();
setInitSoundEffectPool(true);
}
// QbSdk.initX5Environment(this, null); // QbSdk.initX5Environment(this, null);
// QbSdk.setCurrentID(""); // QbSdk.setCurrentID("");
} }
......
...@@ -37,7 +37,7 @@ public class LogoActivity extends Activity { ...@@ -37,7 +37,7 @@ public class LogoActivity extends Activity {
finish(); finish();
} }
}; };
handler.postDelayed(runnable, 1500); handler.postDelayed(runnable, 1000);
Toast.makeText(LogoActivity.this, R.string.logo_text, Toast.LENGTH_SHORT).show(); Toast.makeText(LogoActivity.this, R.string.logo_text, Toast.LENGTH_SHORT).show();
} }
} }
......
...@@ -873,6 +873,11 @@ class DeckManagerActivityImpl extends BaseCardsAcitivity implements RecyclerView ...@@ -873,6 +873,11 @@ class DeckManagerActivityImpl extends BaseCardsAcitivity implements RecyclerView
addMenuButton(mMenuIds, menu, R.id.action_sort, R.string.sort, R.drawable.sort); addMenuButton(mMenuIds, menu, R.id.action_sort, R.string.sort, R.drawable.sort);
addMenuButton(mMenuIds, menu, R.id.action_quit, R.string.quit, R.drawable.quit); addMenuButton(mMenuIds, menu, R.id.action_quit, R.string.quit, R.drawable.quit);
//设置展开或隐藏的延时。 默认值为 800ms。
menu.setDuration(150);
//设置每两个子按钮之间动画的延时(ms为单位)。 比如,如果延时设为0,那么所有子按钮都会同时展开或隐藏,默认值为100ms。
menu.setDelay(10);
menu.setOnBoomListener(new DefaultOnBoomListener() { menu.setOnBoomListener(new DefaultOnBoomListener() {
@Override @Override
public void onClicked(int index, BoomButton boomButton) { public void onClicked(int index, BoomButton boomButton) {
......
...@@ -400,6 +400,11 @@ public abstract class HomeActivity extends BaseActivity implements NavigationVie ...@@ -400,6 +400,11 @@ public abstract class HomeActivity extends BaseActivity implements NavigationVie
addMenuButton(mMenuIds, menu, R.id.action_settings, R.string.settings, R.drawable.setting); addMenuButton(mMenuIds, menu, R.id.action_settings, R.string.settings, R.drawable.setting);
addMenuButton(mMenuIds, menu, R.id.nav_donation, R.string.donation, R.drawable.about); addMenuButton(mMenuIds, menu, R.id.nav_donation, R.string.donation, R.drawable.about);
//设置展开或隐藏的延时。 默认值为 800ms。
menu.setDuration(220);
//设置每两个子按钮之间动画的延时(ms为单位)。 比如,如果延时设为0,那么所有子按钮都会同时展开或隐藏,默认值为100ms。
menu.setDelay(20);
menu.setOnBoomListener(new DefaultOnBoomListener() { menu.setOnBoomListener(new DefaultOnBoomListener() {
@Override @Override
public void onClicked(int index, BoomButton boomButton) { public void onClicked(int index, BoomButton boomButton) {
......
...@@ -59,16 +59,16 @@ public class MainActivity extends HomeActivity{ ...@@ -59,16 +59,16 @@ public class MainActivity extends HomeActivity{
ActivityCompat.requestPermissions(this, PERMISSIONS, 0); ActivityCompat.requestPermissions(this, PERMISSIONS, 0);
} }
@SuppressLint("StringFormatMatches") @SuppressLint({"StringFormatMatches", "StringFormatInvalid"})
@Override @Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults); super.onRequestPermissionsResult(requestCode, permissions, grantResults);
for(int i=0;i<permissions.length;i++){ // for(int i=0;i<permissions.length;i++){
if(grantResults[i] == PackageManager.PERMISSION_DENIED){ // if(grantResults[i] == PackageManager.PERMISSION_DENIED){
showToast(getString(R.string.tip_no_permission,permissions[i])); // showToast(getString(R.string.tip_no_permission,permissions[i]));
break; // break;
} // }
} // }
//资源复制 //资源复制
checkRes(); checkRes();
} }
......
...@@ -222,6 +222,8 @@ public class ServiceDuelAssistant extends Service { ...@@ -222,6 +222,8 @@ public class ServiceDuelAssistant extends Service {
@Override @Override
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
if (intent==null)
return super.onStartCommand(intent,flags,startId);
String action = intent.getAction(); String action = intent.getAction();
Log.d(TAG, "rev action:" + action); Log.d(TAG, "rev action:" + action);
if (DUEL_ASSISTANT_SERVICE_ACTION.equals(action)) { if (DUEL_ASSISTANT_SERVICE_ACTION.equals(action)) {
......
...@@ -33,6 +33,7 @@ import java.io.FileInputStream; ...@@ -33,6 +33,7 @@ import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import cn.garymb.ygomobile.App;
import cn.garymb.ygomobile.AppsSettings; import cn.garymb.ygomobile.AppsSettings;
import cn.garymb.ygomobile.Constants; import cn.garymb.ygomobile.Constants;
import cn.garymb.ygomobile.lite.R; import cn.garymb.ygomobile.lite.R;
...@@ -96,9 +97,9 @@ public class SettingFragment extends PreferenceFragmentPlus { ...@@ -96,9 +97,9 @@ public class SettingFragment extends PreferenceFragmentPlus {
addPreferencesFromResource(R.xml.preference_game); addPreferencesFromResource(R.xml.preference_game);
bind(PREF_GAME_PATH, mSettings.getResourcePath()); bind(PREF_GAME_PATH, mSettings.getResourcePath());
// bind(PREF_GAME_VERSION, mSettings.getVersionString(mSettings.getGameVersion())); // bind(PREF_GAME_VERSION, mSettings.getVersionString(mSettings.getGameVersion()));
bind(PREF_CHANGE_LOG,SystemUtils.getVersionName(getActivity()) bind(PREF_CHANGE_LOG, SystemUtils.getVersionName(getActivity())
+ "(" + SystemUtils.getVersion(getActivity()) + ")"); + "(" + SystemUtils.getVersion(getActivity()) + ")");
bind(PREF_CHECK_UPDATE,getString(R.string.settings_about_author_pref)+" : "+getString(R.string.settings_author)); bind(PREF_CHECK_UPDATE, getString(R.string.settings_about_author_pref) + " : " + getString(R.string.settings_author));
bind(PREF_SOUND_EFFECT, mSettings.isSoundEffect()); bind(PREF_SOUND_EFFECT, mSettings.isSoundEffect());
bind(PREF_LOCK_SCREEN, mSettings.isLockSreenOrientation()); bind(PREF_LOCK_SCREEN, mSettings.isLockSreenOrientation());
bind(PREF_FONT_ANTIALIAS, mSettings.isFontAntiAlias()); bind(PREF_FONT_ANTIALIAS, mSettings.isFontAntiAlias());
...@@ -116,7 +117,7 @@ public class SettingFragment extends PreferenceFragmentPlus { ...@@ -116,7 +117,7 @@ public class SettingFragment extends PreferenceFragmentPlus {
} }
bind(PREF_DECK_DELETE_DILAOG, mSettings.isDialogDelete()); bind(PREF_DECK_DELETE_DILAOG, mSettings.isDialogDelete());
//bind(PREF_USE_EXTRA_CARD_CARDS, mSettings.isUseExtraCards()); //bind(PREF_USE_EXTRA_CARD_CARDS, mSettings.isUseExtraCards());
bind(SETTINGS_AVATAR, new File(mSettings.getCoreSkinPath(),Constants.CORE_SKIN_AVATAR_ME).getAbsolutePath()); bind(SETTINGS_AVATAR, new File(mSettings.getCoreSkinPath(), Constants.CORE_SKIN_AVATAR_ME).getAbsolutePath());
bind(SETTINGS_COVER, new File(mSettings.getCoreSkinPath(), Constants.CORE_SKIN_COVER).getAbsolutePath()); bind(SETTINGS_COVER, new File(mSettings.getCoreSkinPath(), Constants.CORE_SKIN_COVER).getAbsolutePath());
bind(SETTINGS_CARD_BG, new File(mSettings.getCoreSkinPath(), Constants.CORE_SKIN_BG).getAbsolutePath()); bind(SETTINGS_CARD_BG, new File(mSettings.getCoreSkinPath(), Constants.CORE_SKIN_BG).getAbsolutePath());
bind(PREF_FONT_SIZE, mSettings.getFontSize()); bind(PREF_FONT_SIZE, mSettings.getFontSize());
...@@ -158,10 +159,19 @@ public class SettingFragment extends PreferenceFragmentPlus { ...@@ -158,10 +159,19 @@ public class SettingFragment extends PreferenceFragmentPlus {
CheckBoxPreference checkBoxPreference = (CheckBoxPreference) preference; CheckBoxPreference checkBoxPreference = (CheckBoxPreference) preference;
mSharedPreferences.edit().putBoolean(preference.getKey(), checkBoxPreference.isChecked()).apply(); mSharedPreferences.edit().putBoolean(preference.getKey(), checkBoxPreference.isChecked()).apply();
//如果事设置额外卡库的选项 //如果事设置额外卡库的选项
if (preference.getKey().equals(PREF_READ_EX)){ if (preference.getKey().equals(PREF_READ_EX)) {
//设置使用额外卡库后重新加载卡片数据 //设置使用额外卡库后重新加载卡片数据
DataManager.get().load(true); DataManager.get().load(true);
} }
//如果是音效开关
if (preference.getKey().equals(PREF_SOUND_EFFECT)) {
//如果打勾开启音效
if (checkBoxPreference.isChecked()) {
//如果未初始化音效
if (App.get().isInitSoundEffectPool())
App.get().initSoundEffectPool();
}
}
return true; return true;
} }
boolean rs = super.onPreferenceChange(preference, value); boolean rs = super.onPreferenceChange(preference, value);
...@@ -186,7 +196,7 @@ public class SettingFragment extends PreferenceFragmentPlus { ...@@ -186,7 +196,7 @@ public class SettingFragment extends PreferenceFragmentPlus {
.show(); .show();
} }
if (PREF_CHECK_UPDATE.equals(key)) { if (PREF_CHECK_UPDATE.equals(key)) {
HomeActivity.checkPgyerUpdateSilent(getActivity(),true,true,true); HomeActivity.checkPgyerUpdateSilent(getActivity(), true, true, true);
} }
if (PREF_PENDULUM_SCALE.equals(key)) { if (PREF_PENDULUM_SCALE.equals(key)) {
CheckBoxPreference checkBoxPreference = (CheckBoxPreference) preference; CheckBoxPreference checkBoxPreference = (CheckBoxPreference) preference;
...@@ -203,14 +213,14 @@ public class SettingFragment extends PreferenceFragmentPlus { ...@@ -203,14 +213,14 @@ public class SettingFragment extends PreferenceFragmentPlus {
View viewDialog = dialog.getContentView(); View viewDialog = dialog.getContentView();
ImageView avatar1 = viewDialog.findViewById(R.id.me); ImageView avatar1 = viewDialog.findViewById(R.id.me);
ImageView avatar2 = viewDialog.findViewById(R.id.opponent); ImageView avatar2 = viewDialog.findViewById(R.id.opponent);
setImage(mSettings.getCoreSkinPath()+ "/" + Constants.CORE_SKIN_AVATAR_ME, CORE_SKIN_AVATAR_SIZE[0],CORE_SKIN_AVATAR_SIZE[1],avatar1); setImage(mSettings.getCoreSkinPath() + "/" + Constants.CORE_SKIN_AVATAR_ME, CORE_SKIN_AVATAR_SIZE[0], CORE_SKIN_AVATAR_SIZE[1], avatar1);
setImage(mSettings.getCoreSkinPath()+ "/" + Constants.CORE_SKIN_AVATAR_OPPONENT, CORE_SKIN_AVATAR_SIZE[0],CORE_SKIN_AVATAR_SIZE[1],avatar2); setImage(mSettings.getCoreSkinPath() + "/" + Constants.CORE_SKIN_AVATAR_OPPONENT, CORE_SKIN_AVATAR_SIZE[0], CORE_SKIN_AVATAR_SIZE[1], avatar2);
avatar1.setOnClickListener((v) -> { avatar1.setOnClickListener((v) -> {
//打开系统文件相册 //打开系统文件相册
String outFile = new File(mSettings.getCoreSkinPath(), Constants.CORE_SKIN_AVATAR_ME).getAbsolutePath(); String outFile = new File(mSettings.getCoreSkinPath(), Constants.CORE_SKIN_AVATAR_ME).getAbsolutePath();
showImageDialog(preference, getString(R.string.settings_game_avatar), showImageDialog(preference, getString(R.string.settings_game_avatar),
outFile, outFile,
true, CORE_SKIN_AVATAR_SIZE[0],CORE_SKIN_AVATAR_SIZE[1]); true, CORE_SKIN_AVATAR_SIZE[0], CORE_SKIN_AVATAR_SIZE[1]);
dialog.dismiss(); dialog.dismiss();
}); });
avatar2.setOnClickListener((v) -> { avatar2.setOnClickListener((v) -> {
...@@ -218,10 +228,10 @@ public class SettingFragment extends PreferenceFragmentPlus { ...@@ -218,10 +228,10 @@ public class SettingFragment extends PreferenceFragmentPlus {
String outFile = new File(mSettings.getCoreSkinPath(), Constants.CORE_SKIN_AVATAR_OPPONENT).getAbsolutePath(); String outFile = new File(mSettings.getCoreSkinPath(), Constants.CORE_SKIN_AVATAR_OPPONENT).getAbsolutePath();
showImageDialog(preference, getString(R.string.settings_game_avatar), showImageDialog(preference, getString(R.string.settings_game_avatar),
outFile, outFile,
true, CORE_SKIN_AVATAR_SIZE[0],CORE_SKIN_AVATAR_SIZE[1]); true, CORE_SKIN_AVATAR_SIZE[0], CORE_SKIN_AVATAR_SIZE[1]);
dialog.dismiss(); dialog.dismiss();
}); });
}else if (SETTINGS_COVER.equals(key)) { } else if (SETTINGS_COVER.equals(key)) {
//显示卡背图片对话框 //显示卡背图片对话框
final DialogPlus dialog = new DialogPlus(getContext()); final DialogPlus dialog = new DialogPlus(getContext());
dialog.setContentView(R.layout.dialog_cover_select); dialog.setContentView(R.layout.dialog_cover_select);
...@@ -230,8 +240,8 @@ public class SettingFragment extends PreferenceFragmentPlus { ...@@ -230,8 +240,8 @@ public class SettingFragment extends PreferenceFragmentPlus {
View viewDialog = dialog.getContentView(); View viewDialog = dialog.getContentView();
ImageView cover1 = viewDialog.findViewById(R.id.cover1); ImageView cover1 = viewDialog.findViewById(R.id.cover1);
ImageView cover2 = viewDialog.findViewById(R.id.cover2); ImageView cover2 = viewDialog.findViewById(R.id.cover2);
setImage(mSettings.getCoreSkinPath()+ "/" + Constants.CORE_SKIN_COVER, CORE_SKIN_CARD_COVER_SIZE[0],CORE_SKIN_CARD_COVER_SIZE[1],cover1); setImage(mSettings.getCoreSkinPath() + "/" + Constants.CORE_SKIN_COVER, CORE_SKIN_CARD_COVER_SIZE[0], CORE_SKIN_CARD_COVER_SIZE[1], cover1);
setImage(mSettings.getCoreSkinPath()+ "/" + Constants.CORE_SKIN_COVER2, CORE_SKIN_CARD_COVER_SIZE[0],CORE_SKIN_CARD_COVER_SIZE[1],cover2); setImage(mSettings.getCoreSkinPath() + "/" + Constants.CORE_SKIN_COVER2, CORE_SKIN_CARD_COVER_SIZE[0], CORE_SKIN_CARD_COVER_SIZE[1], cover2);
cover1.setOnClickListener((v) -> { cover1.setOnClickListener((v) -> {
//打开系统文件相册 //打开系统文件相册
String outFile = new File(mSettings.getCoreSkinPath(), Constants.CORE_SKIN_COVER).getAbsolutePath(); String outFile = new File(mSettings.getCoreSkinPath(), Constants.CORE_SKIN_COVER).getAbsolutePath();
...@@ -258,9 +268,9 @@ public class SettingFragment extends PreferenceFragmentPlus { ...@@ -258,9 +268,9 @@ public class SettingFragment extends PreferenceFragmentPlus {
ImageView bg = viewDialog.findViewById(R.id.bg); ImageView bg = viewDialog.findViewById(R.id.bg);
ImageView bg_menu = viewDialog.findViewById(R.id.bg_menu); ImageView bg_menu = viewDialog.findViewById(R.id.bg_menu);
ImageView bg_deck = viewDialog.findViewById(R.id.bg_deck); ImageView bg_deck = viewDialog.findViewById(R.id.bg_deck);
setImage(mSettings.getCoreSkinPath()+ "/" + Constants.CORE_SKIN_BG, CORE_SKIN_BG_SIZE[0], CORE_SKIN_BG_SIZE[1],bg); setImage(mSettings.getCoreSkinPath() + "/" + Constants.CORE_SKIN_BG, CORE_SKIN_BG_SIZE[0], CORE_SKIN_BG_SIZE[1], bg);
setImage(mSettings.getCoreSkinPath()+ "/" + Constants.CORE_SKIN_BG_MENU, CORE_SKIN_BG_SIZE[0], CORE_SKIN_BG_SIZE[1],bg_menu); setImage(mSettings.getCoreSkinPath() + "/" + Constants.CORE_SKIN_BG_MENU, CORE_SKIN_BG_SIZE[0], CORE_SKIN_BG_SIZE[1], bg_menu);
setImage(mSettings.getCoreSkinPath()+ "/" + Constants.CORE_SKIN_BG_DECK, CORE_SKIN_BG_SIZE[0], CORE_SKIN_BG_SIZE[1],bg_deck); setImage(mSettings.getCoreSkinPath() + "/" + Constants.CORE_SKIN_BG_DECK, CORE_SKIN_BG_SIZE[0], CORE_SKIN_BG_SIZE[1], bg_deck);
bg.setOnClickListener((v) -> { bg.setOnClickListener((v) -> {
//打开系统文件相册 //打开系统文件相册
String outFile = new File(mSettings.getCoreSkinPath(), Constants.CORE_SKIN_BG).getAbsolutePath(); String outFile = new File(mSettings.getCoreSkinPath(), Constants.CORE_SKIN_BG).getAbsolutePath();
...@@ -349,13 +359,13 @@ public class SettingFragment extends PreferenceFragmentPlus { ...@@ -349,13 +359,13 @@ public class SettingFragment extends PreferenceFragmentPlus {
ViewGroup.LayoutParams.WRAP_CONTENT); ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams.gravity = Gravity.CENTER_HORIZONTAL; layoutParams.gravity = Gravity.CENTER_HORIZONTAL;
frameLayout.addView(imageView, layoutParams); frameLayout.addView(imageView, layoutParams);
// builder.setContentView(frameLayout); // builder.setContentView(frameLayout);
//builder.setLeftButtonText(R.string.settings); //builder.setLeftButtonText(R.string.settings);
//builder.setLeftButtonListener((dlg, s) -> { //builder.setLeftButtonListener((dlg, s) -> {
showImageCropChooser(preference, getString(R.string.dialog_select_image), outFile, showImageCropChooser(preference, getString(R.string.dialog_select_image), outFile,
isJpeg, outWidth, outHeight); isJpeg, outWidth, outHeight);
//dlg.dismiss(); //dlg.dismiss();
// }); // });
// builder.setOnCancelListener((dlg) -> { // builder.setOnCancelListener((dlg) -> {
// BitmapUtil.destroy(imageView.getDrawable()); // BitmapUtil.destroy(imageView.getDrawable());
// }); // });
...@@ -369,7 +379,7 @@ public class SettingFragment extends PreferenceFragmentPlus { ...@@ -369,7 +379,7 @@ public class SettingFragment extends PreferenceFragmentPlus {
} }
} }
public void setImage(String outFile,int outWidth,int outHeight,ImageView imageView){ public void setImage(String outFile, int outWidth, int outHeight, ImageView imageView) {
File img = new File(outFile); File img = new File(outFile);
if (img.exists()) { if (img.exists()) {
Glide.with(this).load(img).signature(new StringSignature(img.getName() + img.lastModified())) Glide.with(this).load(img).signature(new StringSignature(img.getName() + img.lastModified()))
......
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
<ImageView <ImageView
android:id="@+id/cube" android:id="@+id/cube"
android:layout_width="40dp" android:layout_width="40dp"
android:layout_height="40dp" android:layout_height="41dp"
android:layout_gravity="center" android:layout_gravity="center"
app:srcCompat="@drawable/cube" /> app:srcCompat="@drawable/cube" />
</com.nightonke.boommenu.BoomMenuButton> </com.nightonke.boommenu.BoomMenuButton>
......
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