Commit 3a99e204 authored by fallenstardust's avatar fallenstardust

arrange code

parent e3f96e18
APP_ABI := arm64-v8a #armeabi-v7a x86 APP_ABI := arm64-v8a armeabi-v7a x86
APP_PLATFORM := android-21 APP_PLATFORM := android-21
#APP_MODULES := YGOMobile #APP_MODULES := YGOMobile
#NDK_TOOLCHAIN_VERSION=4.8 #NDK_TOOLCHAIN_VERSION=4.8
......
...@@ -118,7 +118,7 @@ public class YGOMobileActivity extends NativeActivity implements ...@@ -118,7 +118,7 @@ public class YGOMobileActivity extends NativeActivity implements
mFullScreenUtils.fullscreen(); mFullScreenUtils.fullscreen();
mFullScreenUtils.onCreate(); mFullScreenUtils.onCreate();
//argv //argv
mArgV = getIntent().getStringArrayExtra(IrrlichtBridge.EXTRA_ARGV); mArgV = IrrlichtBridge.getArgs(getIntent());
// //
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
Log.e("YGOStarter", "跳转完成" + System.currentTimeMillis()); Log.e("YGOStarter", "跳转完成" + System.currentTimeMillis());
...@@ -418,6 +418,7 @@ public class YGOMobileActivity extends NativeActivity implements ...@@ -418,6 +418,7 @@ public class YGOMobileActivity extends NativeActivity implements
options.mArgvList.clear(); options.mArgvList.clear();
if (mArgV != null) { if (mArgV != null) {
options.mArgvList.addAll(Arrays.asList(mArgV)); options.mArgvList.addAll(Arrays.asList(mArgV));
mArgV = null;
} }
return options.toNativeBuffer(); return options.toNativeBuffer();
} }
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
package cn.garymb.ygomobile.core; package cn.garymb.ygomobile.core;
import android.content.Intent;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Color; import android.graphics.Color;
import android.util.Log; import android.util.Log;
...@@ -27,11 +28,16 @@ public final class IrrlichtBridge { ...@@ -27,11 +28,16 @@ public final class IrrlichtBridge {
public static final String ACTION_STOP = "cn.garymb.ygomobile.game.stop"; public static final String ACTION_STOP = "cn.garymb.ygomobile.game.stop";
public static final String EXTRA_PID = "extras.mypid"; public static final String EXTRA_PID = "extras.mypid";
public static final String EXTRA_ARGV = "extras.argv"; public static final String EXTRA_ARGV = "extras.argv";
public static final String EXTRA_ARGV_TIME_OUT = "extras.argv_timeout";
private static final boolean DEBUG = false;
private static final String TAG = IrrlichtBridge.class.getSimpleName();
public static int gPid; public static int gPid;
public static long sNativeHandle;
static { static {
try { try {
System.loadLibrary("YGOMobile"); System.loadLibrary("YGOMobile");
}catch (Throwable e){ } catch (Throwable e) {
//ignore //ignore
} }
} }
...@@ -40,17 +46,21 @@ public final class IrrlichtBridge { ...@@ -40,17 +46,21 @@ public final class IrrlichtBridge {
} }
public static long sNativeHandle;
//显示卡图 //显示卡图
public static native byte[] nativeBpgImage(byte[] data); public static native byte[] nativeBpgImage(byte[] data);
//插入文本(大概是发送消息) //插入文本(大概是发送消息)
private static native void nativeInsertText(long handle, String text); private static native void nativeInsertText(long handle, String text);
//刷新文字 //刷新文字
private static native void nativeRefreshTexture(long handle); private static native void nativeRefreshTexture(long handle);
//忽略时点 //忽略时点
private static native void nativeIgnoreChain(long handle, boolean begin); private static native void nativeIgnoreChain(long handle, boolean begin);
//强制时点 //强制时点
private static native void nativeReactChain(long handle, boolean begin); private static native void nativeReactChain(long handle, boolean begin);
//取消连锁 //取消连锁
private static native void nativeCancelChain(long handle); private static native void nativeCancelChain(long handle);
...@@ -62,8 +72,18 @@ public final class IrrlichtBridge { ...@@ -62,8 +72,18 @@ public final class IrrlichtBridge {
private static native void nativeSetInputFix(long handle, int x, int y); private static native void nativeSetInputFix(long handle, int x, int y);
private static final boolean DEBUG = false; public static void setArgs(Intent intent, String[] args) {
private static final String TAG = IrrlichtBridge.class.getSimpleName(); intent.putExtra(EXTRA_ARGV, args);
intent.putExtra(EXTRA_ARGV_TIME_OUT, (System.currentTimeMillis() + 15 * 1000));
}
public static String[] getArgs(Intent intent) {
long time = intent.getLongExtra(EXTRA_ARGV_TIME_OUT, 0);
if (time > System.currentTimeMillis()) {
return intent.getStringArrayExtra(EXTRA_ARGV);
}
return null;
}
public static Bitmap getBpgImage(InputStream inputStream, Bitmap.Config config) { public static Bitmap getBpgImage(InputStream inputStream, Bitmap.Config config) {
ByteArrayOutputStream outputStream = null; ByteArrayOutputStream outputStream = null;
...@@ -121,7 +141,7 @@ public final class IrrlichtBridge { ...@@ -121,7 +141,7 @@ public final class IrrlichtBridge {
} }
} }
public static void setInputFix(int x, int y){ public static void setInputFix(int x, int y) {
nativeSetInputFix(sNativeHandle, x, y); nativeSetInputFix(sNativeHandle, x, y);
} }
...@@ -166,9 +186,9 @@ public final class IrrlichtBridge { ...@@ -166,9 +186,9 @@ public final class IrrlichtBridge {
String getSetting(String key); String getSetting(String key);
int getIntSetting(String key,int def); int getIntSetting(String key, int def);
void saveIntSetting(String key,int value); void saveIntSetting(String key, int value);
float getScreenWidth(); float getScreenWidth();
......
...@@ -124,6 +124,7 @@ public interface Constants { ...@@ -124,6 +124,7 @@ public interface Constants {
int REQUEST_CHOOSE_FILE = 0x1000 + 0x20; int REQUEST_CHOOSE_FILE = 0x1000 + 0x20;
int REQUEST_CHOOSE_IMG = 0x1000 + 0x21; int REQUEST_CHOOSE_IMG = 0x1000 + 0x21;
int REQUEST_CHOOSE_FOLDER = 0x1000 + 0x22; int REQUEST_CHOOSE_FOLDER = 0x1000 + 0x22;
int REQUEST_SETTINGS_CODE = 0x1000 + 0x23;
int STRING_TYPE_START = 1050; int STRING_TYPE_START = 1050;
int STRING_ATTRIBUTE_START = 1010; int STRING_ATTRIBUTE_START = 1010;
......
package cn.garymb.ygomobile; package cn.garymb.ygomobile;
import android.app.Activity; import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.os.ParcelFileDescriptor; import android.os.ParcelFileDescriptor;
import android.provider.Settings;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.widget.Toast; import android.widget.Toast;
...@@ -18,8 +20,8 @@ import cn.garymb.ygomobile.bean.Deck; ...@@ -18,8 +20,8 @@ import cn.garymb.ygomobile.bean.Deck;
import cn.garymb.ygomobile.lite.R; import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.ui.cards.DeckManagerActivity; import cn.garymb.ygomobile.ui.cards.DeckManagerActivity;
import cn.garymb.ygomobile.ui.preference.SettingsActivity; import cn.garymb.ygomobile.ui.preference.SettingsActivity;
import cn.garymb.ygomobile.utils.ComponentUtils;
import cn.garymb.ygomobile.utils.FileUtils; import cn.garymb.ygomobile.utils.FileUtils;
import cn.garymb.ygomobile.utils.IOUtils;
import ocgcore.DataManager; import ocgcore.DataManager;
import static cn.garymb.ygomobile.Constants.ACTION_OPEN_DECK; import static cn.garymb.ygomobile.Constants.ACTION_OPEN_DECK;
...@@ -27,10 +29,12 @@ import static cn.garymb.ygomobile.Constants.ACTION_OPEN_GAME; ...@@ -27,10 +29,12 @@ import static cn.garymb.ygomobile.Constants.ACTION_OPEN_GAME;
import static cn.garymb.ygomobile.Constants.CORE_REPLAY_PATH; import static cn.garymb.ygomobile.Constants.CORE_REPLAY_PATH;
import static cn.garymb.ygomobile.Constants.CORE_SINGLE_PATH; import static cn.garymb.ygomobile.Constants.CORE_SINGLE_PATH;
import static cn.garymb.ygomobile.Constants.QUERY_NAME; import static cn.garymb.ygomobile.Constants.QUERY_NAME;
import static cn.garymb.ygomobile.Constants.REQUEST_SETTINGS_CODE;
public class GameUriManager { public class GameUriManager {
private Activity activity; private Activity activity;
private String fname;
public GameUriManager(Activity activity) { public GameUriManager(Activity activity) {
this.activity = activity; this.activity = activity;
...@@ -74,18 +78,19 @@ public class GameUriManager { ...@@ -74,18 +78,19 @@ public class GameUriManager {
} }
private String getDeckName(Uri uri) { private String getPathName(String path, boolean withOutEx) {
String path = uri.getPath(); Log.d("ygo", "path=" + path);
Log.i("kk", "path=" + path);
if (path != null) { if (path != null) {
int index = path.lastIndexOf("/"); int index = path.lastIndexOf("/");
if (index > 0) { if (index > 0) {
String name = path.substring(index + 1); String name = path.substring(index + 1);
if (withOutEx) {
index = name.lastIndexOf("."); index = name.lastIndexOf(".");
if (index > 0) { if (index > 0) {
//1.ydk //1.ydk
name = name.substring(0, index); name = name.substring(0, index);
} }
}
return name; return name;
} }
} }
...@@ -118,120 +123,96 @@ public class GameUriManager { ...@@ -118,120 +123,96 @@ public class GameUriManager {
return TextUtils.equals(deck, file.getParentFile().getAbsolutePath()); return TextUtils.equals(deck, file.getParentFile().getAbsolutePath());
} }
private void doUri(Uri uri) { private File toLocalFile(Uri uri) {
Intent startSeting = new Intent(activity, SettingsActivity.class); String path = uri.getPath();
Log.i("ygo", "doUri:"+uri); File remoteFile = null;
if ("file".equals(uri.getScheme())) { if ("file".equals(uri.getScheme())) {
File file = new File(uri.getPath()); remoteFile = new File(uri.getPath());
if (file.getName().toLowerCase(Locale.US).endsWith(".ydk")) { if (getActivity().getApplicationInfo().targetSdkVersion > 28) {
Intent startdeck = new Intent(getActivity(), DeckManagerActivity.getDeckManager()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
if (isDeckDir(file)) { if (Environment.isExternalStorageManager()) {
//deck目录 Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
startdeck.putExtra(Intent.EXTRA_TEXT, file.getAbsolutePath()); intent.setData(Uri.parse("package:$packageName"));
} else { getActivity().startActivityForResult(intent, REQUEST_SETTINGS_CODE);
//非deck目录 return null;
File ydk = getDeckFile(new File(AppsSettings.get().getDeckDir()), getDeckName(uri));
FileUtils.copyFile(file, ydk);
startdeck.putExtra(Intent.EXTRA_TEXT, ydk.getAbsolutePath());
}
activity.startActivity(startdeck);
} else if (file.getName().toLowerCase(Locale.US).endsWith(".ypk")) {
File ypk = new File(AppsSettings.get().getExpansionsPath() + "/" + file.getName());
if (ypk.exists() && file.lastModified() == ypk.lastModified()) {
Toast.makeText(activity, activity.getString(R.string.file_exist), Toast.LENGTH_LONG).show();
} else {
try {
FileUtils.copyFile(file, ypk);
} catch (Throwable e) {
Toast.makeText(activity, activity.getString(R.string.install_failed_bcos) + e, Toast.LENGTH_LONG).show();
} }
} }
if (!AppsSettings.get().isReadExpansions()) {
activity.startActivity(startSeting);
Toast.makeText(activity, R.string.ypk_go_setting, Toast.LENGTH_LONG).show();
} else {
DataManager.get().load(true);
Toast.makeText(activity, R.string.ypk_installed, Toast.LENGTH_LONG).show();
} }
} else if (file.getName().toLowerCase(Locale.US).endsWith(".yrp")) {
File yrp = new File(AppsSettings.get().getResourcePath() + "/" + CORE_REPLAY_PATH + "/" + file.getName());
if (yrp.exists()) {
YGOStarter.startGame(getActivity(), null, "-r", yrp.getName());
Toast.makeText(activity, activity.getString(R.string.file_exist), Toast.LENGTH_LONG).show();
} else {
try { try {
FileUtils.copyFile(file, yrp); if (!remoteFile.canRead()) {
} catch (Throwable e) { Log.w("ygo", "don't read file " + remoteFile.getAbsolutePath());
Toast.makeText(activity, activity.getString(R.string.install_failed_bcos) + e, Toast.LENGTH_LONG).show(); return null;
}
if (!YGOStarter.isGameRunning(getActivity())) {
YGOStarter.startGame(getActivity(), null, "-r", yrp.getName());
Toast.makeText(activity, activity.getString(R.string.file_installed), Toast.LENGTH_LONG).show();
}
} }
} else if (file.getName().toLowerCase(Locale.US).endsWith(".lua")) {
File single = new File(AppsSettings.get().getResourcePath() + "/" + CORE_SINGLE_PATH + "/" + file.getName());
if (single.exists()) {
YGOStarter.startGame(activity, null, "-s", single.getName());
Toast.makeText(activity, activity.getString(R.string.file_exist), Toast.LENGTH_LONG).show();
} else {
try {
FileUtils.copyFile(file, single);
} catch (Throwable e) { } catch (Throwable e) {
Toast.makeText(activity, activity.getString(R.string.install_failed_bcos) + e, Toast.LENGTH_LONG).show(); Log.e("ygo", "don't read file " + remoteFile.getAbsolutePath(), e);
} return null;
if (!YGOStarter.isGameRunning(getActivity())) {
YGOStarter.startGame(activity, null, "-s", single.getName());
Toast.makeText(activity, activity.getString(R.string.file_installed), Toast.LENGTH_LONG).show();
} }
} }
} String name = getPathName(path, false);
} else if ("content".equals(uri.getScheme())) { File local;
File urifile = new File(uri.getPath()); if (name.toLowerCase(Locale.US).endsWith(".ydk")) {
if (urifile.getName().toLowerCase(Locale.US).endsWith(".ydk")) {
try {
File dir = Constants.COPY_YDK_FILE ? new File(AppsSettings.get().getDeckDir()) : new File(getActivity().getApplicationInfo().dataDir, "cache"); File dir = Constants.COPY_YDK_FILE ? new File(AppsSettings.get().getDeckDir()) : new File(getActivity().getApplicationInfo().dataDir, "cache");
File ydk = getDeckFile(dir, getDeckName(uri)); local = getDeckFile(dir, name);
ParcelFileDescriptor pfd = getActivity().getContentResolver().openFileDescriptor(uri, "r"); } else if (name.toLowerCase(Locale.US).endsWith(".ypk")) {
if (pfd == null) { local = new File(AppsSettings.get().getExpansionsPath(), name);
return; } else if (name.toLowerCase(Locale.US).endsWith(".yrp")) {
local = new File(AppsSettings.get().getResourcePath() + "/" + CORE_REPLAY_PATH, name);
} else if (name.toLowerCase(Locale.US).endsWith(".lua")) {
local = new File(AppsSettings.get().getResourcePath() + "/" + CORE_SINGLE_PATH, name);
} else { } else {
try { local = new File(AppsSettings.get().getResourcePath() + "/temp", name);
FileUtils.copyFile(new FileInputStream(pfd.getFileDescriptor()), ydk);
} catch (Throwable e) {
e.printStackTrace();
} finally {
pfd.close();
} }
if (local.exists()) {
Log.w("ygo", "Overwrite file " + local.getAbsolutePath());
} }
Intent startdeck = new Intent(getActivity(), DeckManagerActivity.getDeckManager()); if (remoteFile != null && TextUtils.equals(remoteFile.getAbsolutePath(), local.getAbsolutePath())) {
startdeck.putExtra(Intent.EXTRA_TEXT, ydk.getAbsolutePath()); //is same path
activity.startActivity(startdeck); Log.i("ygo", "is same file " + remoteFile.getAbsolutePath() + "==" + local.getAbsolutePath());
} catch (Throwable e) { return local;
e.printStackTrace();
} }
} else if (urifile.getName().toLowerCase(Locale.US).endsWith(".ypk")) { //copy
ParcelFileDescriptor pfd = null;
FileInputStream input = null;
try { try {
File ypk = new File(AppsSettings.get().getExpansionsPath() + "/" + urifile.getName()); File dir = local.getParentFile();
ParcelFileDescriptor pfd = getActivity().getContentResolver().openFileDescriptor(uri, "r"); if (!dir.exists()) {
if (ypk.exists() && urifile.lastModified() == ypk.lastModified()) { dir.mkdirs();
Toast.makeText(activity, activity.getString(R.string.file_exist), Toast.LENGTH_SHORT).show(); }
} else { if (remoteFile != null) {
if (pfd == null) { FileUtils.copyFile(remoteFile, local);
return;
} else { } else {
try { pfd = getActivity().getContentResolver().openFileDescriptor(uri, "r");
FileUtils.copyFile(new FileInputStream(pfd.getFileDescriptor()), ypk); input = new FileInputStream(pfd.getFileDescriptor());
FileUtils.copyFile(input, local);
}
} catch (Throwable e) { } catch (Throwable e) {
Toast.makeText(activity, activity.getString(R.string.install_failed_bcos) + e, Toast.LENGTH_LONG).show(); Log.w("ygo", "copy file " + path + "->" + local.getAbsolutePath(), e);
return null;
} finally { } finally {
pfd.close(); IOUtils.close(input);
} IOUtils.close(pfd);
} }
return local;
} }
} catch (Throwable e) {
e.printStackTrace(); private void doUri(Uri uri) {
Intent startSeting = new Intent(activity, SettingsActivity.class);
if ("file".equals(uri.getScheme()) || "content".equals(uri.getScheme())) {
File file = toLocalFile(uri);
if (file == null || !file.exists()) {
Toast.makeText(activity, "open file error", Toast.LENGTH_LONG).show();
return;
} }
boolean isYdk = file.getName().toLowerCase(Locale.US).endsWith(".ydk");
boolean isYpk = file.getName().toLowerCase(Locale.US).endsWith(".ypk");
boolean isYrp = file.getName().toLowerCase(Locale.US).endsWith(".yrp");
boolean isLua = file.getName().toLowerCase(Locale.US).endsWith(".lua");
Log.i("ygo", "open file:" + uri + "->" + file.getAbsolutePath());
if (isYdk) {
Intent intent = new Intent(getActivity(), DeckManagerActivity.getDeckManager());
intent.putExtra(Intent.EXTRA_TEXT, file.getAbsolutePath());
activity.startActivity(intent);
} else if (isYpk) {
if (!AppsSettings.get().isReadExpansions()) { if (!AppsSettings.get().isReadExpansions()) {
activity.startActivity(startSeting); activity.startActivity(startSeting);
Toast.makeText(activity, R.string.ypk_go_setting, Toast.LENGTH_LONG).show(); Toast.makeText(activity, R.string.ypk_go_setting, Toast.LENGTH_LONG).show();
...@@ -239,59 +220,19 @@ public class GameUriManager { ...@@ -239,59 +220,19 @@ public class GameUriManager {
DataManager.get().load(true); DataManager.get().load(true);
Toast.makeText(activity, R.string.ypk_installed, Toast.LENGTH_LONG).show(); Toast.makeText(activity, R.string.ypk_installed, Toast.LENGTH_LONG).show();
} }
} else if (urifile.getName().toLowerCase(Locale.US).endsWith(".yrp")) { } else if (isYrp) {
File yrp = new File(AppsSettings.get().getResourcePath() + "/" + CORE_REPLAY_PATH + "/" + urifile.getName());
try {
ParcelFileDescriptor pfd = getActivity().getContentResolver().openFileDescriptor(uri, "r");
if (yrp.exists()) {
YGOStarter.startGame(getActivity(), null, "-r", yrp.getName());
Toast.makeText(activity, activity.getString(R.string.file_exist), Toast.LENGTH_SHORT).show();
} else {
if (pfd == null) {
return;
} else {
try {
FileUtils.copyFile(new FileInputStream(pfd.getFileDescriptor()), yrp);
} catch (Throwable e) {
Toast.makeText(activity, activity.getString(R.string.install_failed_bcos) + e, Toast.LENGTH_LONG).show();
} finally {
pfd.close();
}
}
}
} catch (Throwable e) {
e.printStackTrace();
}
if (!YGOStarter.isGameRunning(getActivity())) { if (!YGOStarter.isGameRunning(getActivity())) {
YGOStarter.startGame(activity, null, "-r", yrp.getName()); YGOStarter.startGame(getActivity(), null, "-r", file.getName());
Toast.makeText(activity, activity.getString(R.string.file_installed), Toast.LENGTH_LONG).show(); Toast.makeText(activity, activity.getString(R.string.file_installed), Toast.LENGTH_LONG).show();
}
} else if (urifile.getName().toLowerCase(Locale.US).endsWith(".lua")) {
File single = new File(AppsSettings.get().getResourcePath() + "/" + CORE_SINGLE_PATH + "/" + urifile.getName());
try {
ParcelFileDescriptor pfd = getActivity().getContentResolver().openFileDescriptor(uri, "r");
if (single.exists()) {
YGOStarter.startGame(getActivity(), null, "-s", single.getName());
Toast.makeText(activity, activity.getString(R.string.file_exist), Toast.LENGTH_SHORT).show();
} else { } else {
if (pfd == null) { Log.w("ygo", "game is running");
return;
} else {
try {
FileUtils.copyFile(new FileInputStream(pfd.getFileDescriptor()), single);
} catch (Throwable e) {
Toast.makeText(activity, activity.getString(R.string.install_failed_bcos) + e, Toast.LENGTH_LONG).show();
} finally {
pfd.close();
}
}
}
} catch (Throwable e) {
e.printStackTrace();
} }
} else if (isLua) {
if (!YGOStarter.isGameRunning(getActivity())) { if (!YGOStarter.isGameRunning(getActivity())) {
YGOStarter.startGame(activity, null, "-s", single.getName()); YGOStarter.startGame(getActivity(), null, "-s", file.getName());
Toast.makeText(activity, activity.getString(R.string.file_installed), Toast.LENGTH_LONG).show(); Toast.makeText(activity, "load single lua file", Toast.LENGTH_LONG).show();
} else {
Log.w("ygo", "game is running");
} }
} }
} else { } else {
...@@ -299,7 +240,6 @@ public class GameUriManager { ...@@ -299,7 +240,6 @@ public class GameUriManager {
// if (!Constants.URI_HOST.equalsIgnoreCase(host)) { // if (!Constants.URI_HOST.equalsIgnoreCase(host)) {
// return; // return;
// } // }
String path = uri.getPath();
if (Constants.URI_HOST.equals(host)) { if (Constants.URI_HOST.equals(host)) {
String name = uri.getQueryParameter(QUERY_NAME); String name = uri.getQueryParameter(QUERY_NAME);
if (!TextUtils.isEmpty(name)) { if (!TextUtils.isEmpty(name)) {
......
...@@ -176,9 +176,7 @@ public class YGOStarter { ...@@ -176,9 +176,7 @@ public class YGOStarter {
intent.putExtra(YGOGameOptions.YGO_GAME_OPTIONS_BUNDLE_KEY, options); intent.putExtra(YGOGameOptions.YGO_GAME_OPTIONS_BUNDLE_KEY, options);
intent.putExtra(YGOGameOptions.YGO_GAME_OPTIONS_BUNDLE_TIME, System.currentTimeMillis()); intent.putExtra(YGOGameOptions.YGO_GAME_OPTIONS_BUNDLE_TIME, System.currentTimeMillis());
} }
if(args != null) { IrrlichtBridge.setArgs(intent, args);
intent.putExtra(IrrlichtBridge.EXTRA_ARGV,args);
}
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Log.e("YGOStarter", "跳转前" + System.currentTimeMillis()); Log.e("YGOStarter", "跳转前" + System.currentTimeMillis());
activity.startActivity(intent); activity.startActivity(intent);
......
...@@ -2,7 +2,6 @@ package cn.garymb.ygomobile.ui.home; ...@@ -2,7 +2,6 @@ package cn.garymb.ygomobile.ui.home;
import android.Manifest; import android.Manifest;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.ComponentName;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.graphics.Color; import android.graphics.Color;
...@@ -22,15 +21,12 @@ import java.io.IOException; ...@@ -22,15 +21,12 @@ import java.io.IOException;
import cn.garymb.ygomobile.AppsSettings; import cn.garymb.ygomobile.AppsSettings;
import cn.garymb.ygomobile.Constants; import cn.garymb.ygomobile.Constants;
import cn.garymb.ygomobile.GameUriManager; import cn.garymb.ygomobile.GameUriManager;
import cn.garymb.ygomobile.YGOMobileActivity;
import cn.garymb.ygomobile.YGOStarter; import cn.garymb.ygomobile.YGOStarter;
import cn.garymb.ygomobile.core.IrrlichtBridge; import cn.garymb.ygomobile.core.IrrlichtBridge;
import cn.garymb.ygomobile.lite.R; import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.ui.activities.PermissionsActivity;
import cn.garymb.ygomobile.ui.activities.WebActivity; import cn.garymb.ygomobile.ui.activities.WebActivity;
import cn.garymb.ygomobile.ui.plus.DialogPlus; import cn.garymb.ygomobile.ui.plus.DialogPlus;
import cn.garymb.ygomobile.ui.plus.VUiKit; import cn.garymb.ygomobile.ui.plus.VUiKit;
import cn.garymb.ygomobile.utils.ComponentUtils;
import cn.garymb.ygomobile.utils.FileUtils; import cn.garymb.ygomobile.utils.FileUtils;
import cn.garymb.ygomobile.utils.IOUtils; import cn.garymb.ygomobile.utils.IOUtils;
import cn.garymb.ygomobile.utils.NetUtils; import cn.garymb.ygomobile.utils.NetUtils;
...@@ -54,13 +50,12 @@ public class MainActivity extends HomeActivity { ...@@ -54,13 +50,12 @@ public class MainActivity extends HomeActivity {
Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE,
}; };
public ConfigManager favConf = DataManager.openConfig(AppsSettings.get().getSystemConfig());
ResCheckTask mResCheckTask; ResCheckTask mResCheckTask;
private GameUriManager mGameUriManager; private GameUriManager mGameUriManager;
private ImageUpdater mImageUpdater; private ImageUpdater mImageUpdater;
private boolean enableStart; private boolean enableStart;
public ConfigManager favConf = DataManager.openConfig(AppsSettings.get().getSystemConfig());
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
...@@ -181,7 +176,7 @@ public class MainActivity extends HomeActivity { ...@@ -181,7 +176,7 @@ public class MainActivity extends HomeActivity {
@Override @Override
protected void onPermission(boolean isOk) { protected void onPermission(boolean isOk) {
super.onPermission(isOk); super.onPermission(isOk);
if (isOk){ if (isOk) {
try { try {
FileUtils.copyDir(ORI_DECK, AppsSettings.get().getDeckDir(), false); FileUtils.copyDir(ORI_DECK, AppsSettings.get().getDeckDir(), false);
} catch (Throwable e) { } catch (Throwable e) {
...@@ -306,6 +301,15 @@ public class MainActivity extends HomeActivity { ...@@ -306,6 +301,15 @@ public class MainActivity extends HomeActivity {
}); });
} }
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == Constants.REQUEST_SETTINGS_CODE) {
//TODO
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
/* checkResourceDownload((result, isNewVersion) -> { /* checkResourceDownload((result, isNewVersion) -> {
Toast.makeText(this, R.string.tip_reset_game_res, Toast.LENGTH_SHORT).show(); Toast.makeText(this, R.string.tip_reset_game_res, Toast.LENGTH_SHORT).show();
});*/ });*/
......
package cn.garymb.ygomobile.utils; package cn.garymb.ygomobile.utils;
import android.util.Log;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
...@@ -79,24 +81,21 @@ public class FileUtils { ...@@ -79,24 +81,21 @@ public class FileUtils {
return true; return true;
} }
public static void copyFile(InputStream in, File out) { public static void copyFile(InputStream in, File out) throws IOException {
FileOutputStream outputStream = null; FileOutputStream outputStream = null;
try {
File dir = out.getParentFile(); File dir = out.getParentFile();
if (!dir.exists()) { if (!dir.exists()) {
dir.mkdirs(); dir.mkdirs();
} }
try {
outputStream = new FileOutputStream(out); outputStream = new FileOutputStream(out);
copy(in, outputStream); copy(in, outputStream);
} catch (Throwable e) {
e.printStackTrace();
} finally { } finally {
IOUtils.close(outputStream); IOUtils.close(outputStream);
IOUtils.close(in);
} }
} }
public static void copyFile(File in, File out) { public static boolean copyFile(File in, File out) {
FileOutputStream outputStream = null; FileOutputStream outputStream = null;
FileInputStream inputStream = null; FileInputStream inputStream = null;
try { try {
...@@ -108,11 +107,13 @@ public class FileUtils { ...@@ -108,11 +107,13 @@ public class FileUtils {
outputStream = new FileOutputStream(out); outputStream = new FileOutputStream(out);
copy(inputStream, outputStream); copy(inputStream, outputStream);
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace(); Log.e("ygo", "copy file", e);
return false;
} finally { } finally {
IOUtils.close(outputStream); IOUtils.close(outputStream);
IOUtils.close(inputStream); IOUtils.close(inputStream);
} }
return true;
} }
public static void copyFile(String oldPath, String newPath, boolean isName) throws FileNotFoundException, IOException { public static void copyFile(String oldPath, String newPath, boolean isName) throws FileNotFoundException, IOException {
......
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