Commit bd0682d2 authored by feihuaduo's avatar feihuaduo

优化软件启动速度

parent 250ff94b
......@@ -20,12 +20,13 @@ public abstract class GameApplication extends Application implements IrrlichtBri
private Map<String, Integer> mSoundIdMap;
private static GameApplication sGameApplication;
private boolean isInitSoundEffectPool=false;
@Override
public void onCreate() {
super.onCreate();
sGameApplication = this;
initSoundEffectPool();
// initSoundEffectPool();
}
public static GameApplication get() {
......@@ -43,8 +44,16 @@ public abstract class GameApplication extends Application implements IrrlichtBri
mSoundEffectPool.release();
}
public boolean isInitSoundEffectPool() {
return isInitSoundEffectPool;
}
protected void setInitSoundEffectPool(boolean initSoundEffectPool) {
isInitSoundEffectPool = initSoundEffectPool;
}
@SuppressWarnings("deprecation")
protected void initSoundEffectPool() {
public void initSoundEffectPool() {
mSoundEffectPool = new SoundPool(2, AudioManager.STREAM_MUSIC, 0);
AssetManager am = getAssets();
String[] sounds;
......
......@@ -86,8 +86,6 @@ dependencies {
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 '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'
......
......@@ -12,6 +12,11 @@ public class App extends GameApplication {
super.onCreate();
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
AppsSettings.init(this);
if (AppsSettings.get().isSoundEffect()) {
initSoundEffectPool();
setInitSoundEffectPool(true);
}
// QbSdk.initX5Environment(this, null);
// QbSdk.setCurrentID("");
}
......
......@@ -37,7 +37,7 @@ public class LogoActivity extends Activity {
finish();
}
};
handler.postDelayed(runnable, 1500);
handler.postDelayed(runnable, 1000);
Toast.makeText(LogoActivity.this, R.string.logo_text, Toast.LENGTH_SHORT).show();
}
}
......
......@@ -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_quit, R.string.quit, R.drawable.quit);
//设置展开或隐藏的延时。 默认值为 800ms。
menu.setDuration(150);
//设置每两个子按钮之间动画的延时(ms为单位)。 比如,如果延时设为0,那么所有子按钮都会同时展开或隐藏,默认值为100ms。
menu.setDelay(10);
menu.setOnBoomListener(new DefaultOnBoomListener() {
@Override
public void onClicked(int index, BoomButton boomButton) {
......
......@@ -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.nav_donation, R.string.donation, R.drawable.about);
//设置展开或隐藏的延时。 默认值为 800ms。
menu.setDuration(220);
//设置每两个子按钮之间动画的延时(ms为单位)。 比如,如果延时设为0,那么所有子按钮都会同时展开或隐藏,默认值为100ms。
menu.setDelay(20);
menu.setOnBoomListener(new DefaultOnBoomListener() {
@Override
public void onClicked(int index, BoomButton boomButton) {
......
......@@ -59,16 +59,16 @@ public class MainActivity extends HomeActivity{
ActivityCompat.requestPermissions(this, PERMISSIONS, 0);
}
@SuppressLint("StringFormatMatches")
@SuppressLint({"StringFormatMatches", "StringFormatInvalid"})
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
for(int i=0;i<permissions.length;i++){
if(grantResults[i] == PackageManager.PERMISSION_DENIED){
showToast(getString(R.string.tip_no_permission,permissions[i]));
break;
}
}
// for(int i=0;i<permissions.length;i++){
// if(grantResults[i] == PackageManager.PERMISSION_DENIED){
// showToast(getString(R.string.tip_no_permission,permissions[i]));
// break;
// }
// }
//资源复制
checkRes();
}
......
......@@ -222,6 +222,8 @@ public class ServiceDuelAssistant extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (intent==null)
return super.onStartCommand(intent,flags,startId);
String action = intent.getAction();
Log.d(TAG, "rev action:" + action);
if (DUEL_ASSISTANT_SERVICE_ACTION.equals(action)) {
......
......@@ -33,6 +33,7 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import cn.garymb.ygomobile.App;
import cn.garymb.ygomobile.AppsSettings;
import cn.garymb.ygomobile.Constants;
import cn.garymb.ygomobile.lite.R;
......@@ -96,9 +97,9 @@ public class SettingFragment extends PreferenceFragmentPlus {
addPreferencesFromResource(R.xml.preference_game);
bind(PREF_GAME_PATH, mSettings.getResourcePath());
// 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()) + ")");
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_LOCK_SCREEN, mSettings.isLockSreenOrientation());
bind(PREF_FONT_ANTIALIAS, mSettings.isFontAntiAlias());
......@@ -116,7 +117,7 @@ public class SettingFragment extends PreferenceFragmentPlus {
}
bind(PREF_DECK_DELETE_DILAOG, mSettings.isDialogDelete());
//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_CARD_BG, new File(mSettings.getCoreSkinPath(), Constants.CORE_SKIN_BG).getAbsolutePath());
bind(PREF_FONT_SIZE, mSettings.getFontSize());
......@@ -158,10 +159,19 @@ public class SettingFragment extends PreferenceFragmentPlus {
CheckBoxPreference checkBoxPreference = (CheckBoxPreference) preference;
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);
}
//如果是音效开关
if (preference.getKey().equals(PREF_SOUND_EFFECT)) {
//如果打勾开启音效
if (checkBoxPreference.isChecked()) {
//如果未初始化音效
if (App.get().isInitSoundEffectPool())
App.get().initSoundEffectPool();
}
}
return true;
}
boolean rs = super.onPreferenceChange(preference, value);
......@@ -186,7 +196,7 @@ public class SettingFragment extends PreferenceFragmentPlus {
.show();
}
if (PREF_CHECK_UPDATE.equals(key)) {
HomeActivity.checkPgyerUpdateSilent(getActivity(),true,true,true);
HomeActivity.checkPgyerUpdateSilent(getActivity(), true, true, true);
}
if (PREF_PENDULUM_SCALE.equals(key)) {
CheckBoxPreference checkBoxPreference = (CheckBoxPreference) preference;
......@@ -203,14 +213,14 @@ public class SettingFragment extends PreferenceFragmentPlus {
View viewDialog = dialog.getContentView();
ImageView avatar1 = viewDialog.findViewById(R.id.me);
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_OPPONENT, CORE_SKIN_AVATAR_SIZE[0],CORE_SKIN_AVATAR_SIZE[1],avatar2);
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);
avatar1.setOnClickListener((v) -> {
//打开系统文件相册
String outFile = new File(mSettings.getCoreSkinPath(), Constants.CORE_SKIN_AVATAR_ME).getAbsolutePath();
showImageDialog(preference, getString(R.string.settings_game_avatar),
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();
});
avatar2.setOnClickListener((v) -> {
......@@ -218,10 +228,10 @@ public class SettingFragment extends PreferenceFragmentPlus {
String outFile = new File(mSettings.getCoreSkinPath(), Constants.CORE_SKIN_AVATAR_OPPONENT).getAbsolutePath();
showImageDialog(preference, getString(R.string.settings_game_avatar),
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();
});
}else if (SETTINGS_COVER.equals(key)) {
} else if (SETTINGS_COVER.equals(key)) {
//显示卡背图片对话框
final DialogPlus dialog = new DialogPlus(getContext());
dialog.setContentView(R.layout.dialog_cover_select);
......@@ -230,8 +240,8 @@ public class SettingFragment extends PreferenceFragmentPlus {
View viewDialog = dialog.getContentView();
ImageView cover1 = viewDialog.findViewById(R.id.cover1);
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_COVER2, CORE_SKIN_CARD_COVER_SIZE[0],CORE_SKIN_CARD_COVER_SIZE[1],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_COVER2, CORE_SKIN_CARD_COVER_SIZE[0], CORE_SKIN_CARD_COVER_SIZE[1], cover2);
cover1.setOnClickListener((v) -> {
//打开系统文件相册
String outFile = new File(mSettings.getCoreSkinPath(), Constants.CORE_SKIN_COVER).getAbsolutePath();
......@@ -258,9 +268,9 @@ public class SettingFragment extends PreferenceFragmentPlus {
ImageView bg = viewDialog.findViewById(R.id.bg);
ImageView bg_menu = viewDialog.findViewById(R.id.bg_menu);
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_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, 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_DECK, CORE_SKIN_BG_SIZE[0], CORE_SKIN_BG_SIZE[1], bg_deck);
bg.setOnClickListener((v) -> {
//打开系统文件相册
String outFile = new File(mSettings.getCoreSkinPath(), Constants.CORE_SKIN_BG).getAbsolutePath();
......@@ -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);
if (img.exists()) {
Glide.with(this).load(img).signature(new StringSignature(img.getName() + img.lastModified()))
......
......@@ -48,7 +48,7 @@
<ImageView
android:id="@+id/cube"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_height="41dp"
android:layout_gravity="center"
app:srcCompat="@drawable/cube" />
</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