Commit 34d96ae1 authored by kenan's avatar kenan

精准点击事件

parent f79deedb
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true # org.gradle.parallel=true
#Mon Aug 31 19:03:54 CST 2020 #Mon Aug 31 19:03:54 CST 2020
org.gradle.jvmargs=-Xmx4096M -Dkotlin.daemon.jvm.options="-Xmx4096M" -Dfile.encoding=UTF-8 org.gradle.jvmargs=-Xmx4096M -Dkotlin.daemon.jvm.options="-Xmx4096M"
org.gradle.parallel=true org.gradle.parallel=true
android.enableJetifier=true android.enableJetifier=true
android.useAndroidX=true android.useAndroidX=true
......
...@@ -868,9 +868,13 @@ void toggleOverlayView(ANDROID_APP app, bool pShow) { ...@@ -868,9 +868,13 @@ void toggleOverlayView(ANDROID_APP app, bool pShow) {
jni->DeleteLocalRef(ClassNativeActivity); jni->DeleteLocalRef(ClassNativeActivity);
app->activity->vm->DetachCurrentThread(); app->activity->vm->DetachCurrentThread();
} }
static bool test = false;
void process_input(ANDROID_APP app, void process_input(ANDROID_APP app,
struct android_poll_source* source) { struct android_poll_source* source) {
if(test == false) {
test = true;
ALOGD("inputQueue:%lld", (jlong) app->inputQueue);
}
AInputEvent* event = NULL; AInputEvent* event = NULL;
if (AInputQueue_getEvent(app->inputQueue, &event) >= 0) { if (AInputQueue_getEvent(app->inputQueue, &event) >= 0) {
int type = AInputEvent_getType(event); int type = AInputEvent_getType(event);
...@@ -908,6 +912,10 @@ void onGameExit(ANDROID_APP app){ ...@@ -908,6 +912,10 @@ void onGameExit(ANDROID_APP app){
} }
s32 handleInput(ANDROID_APP app, AInputEvent* androidEvent) { s32 handleInput(ANDROID_APP app, AInputEvent* androidEvent) {
if(test == false) {
test = true;
ALOGD("inputQueue:%lld", (jlong) app->inputQueue);
}
IrrlichtDevice* device = (IrrlichtDevice*) app->userData; IrrlichtDevice* device = (IrrlichtDevice*) app->userData;
s32 Status = 0; s32 Status = 0;
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
package cn.garymb.ygomobile; package cn.garymb.ygomobile;
import android.annotation.SuppressLint;
import android.app.NativeActivity; import android.app.NativeActivity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
...@@ -19,7 +20,9 @@ import android.os.Process; ...@@ -19,7 +20,9 @@ import android.os.Process;
import android.util.Log; import android.util.Log;
import android.view.Gravity; import android.view.Gravity;
import android.view.HapticFeedbackConstants; import android.view.HapticFeedbackConstants;
import android.view.InputQueue;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.SurfaceHolder; import android.view.SurfaceHolder;
import android.view.SurfaceView; import android.view.SurfaceView;
import android.view.View; import android.view.View;
...@@ -32,6 +35,7 @@ import java.nio.ByteBuffer; ...@@ -32,6 +35,7 @@ import java.nio.ByteBuffer;
import java.util.Arrays; import java.util.Arrays;
import cn.garymb.ygodata.YGOGameOptions; import cn.garymb.ygodata.YGOGameOptions;
import cn.garymb.ygomobile.controller.InputQueueCompat;
import cn.garymb.ygomobile.controller.NetworkController; import cn.garymb.ygomobile.controller.NetworkController;
import cn.garymb.ygomobile.core.IrrlichtBridge; import cn.garymb.ygomobile.core.IrrlichtBridge;
import cn.garymb.ygomobile.lib.R; import cn.garymb.ygomobile.lib.R;
...@@ -59,13 +63,11 @@ public class YGOMobileActivity extends NativeActivity implements ...@@ -59,13 +63,11 @@ public class YGOMobileActivity extends NativeActivity implements
private static final int CHAIN_CONTROL_PANEL_Y_REVERT_POSITION = 100; private static final int CHAIN_CONTROL_PANEL_Y_REVERT_POSITION = 100;
private static final int MAX_REFRESH = 30 * 1000; private static final int MAX_REFRESH = 30 * 1000;
protected final int windowsFlags = protected final int windowsFlags =
Build.VERSION.SDK_INT >= 19 ? ( View.SYSTEM_UI_FLAG_LAYOUT_STABLE
View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) :
View.SYSTEM_UI_FLAG_LOW_PROFILE;
protected View mContentView; protected View mContentView;
protected ComboBoxCompat mGlobalComboBox; protected ComboBoxCompat mGlobalComboBox;
protected EditWindowCompat mGlobalEditText; protected EditWindowCompat mGlobalEditText;
...@@ -87,6 +89,9 @@ public class YGOMobileActivity extends NativeActivity implements ...@@ -87,6 +89,9 @@ public class YGOMobileActivity extends NativeActivity implements
private static boolean USE_SURFACE = true; private static boolean USE_SURFACE = true;
private String[] mArgV; private String[] mArgV;
private boolean onGameExiting; private boolean onGameExiting;
//尝试调准触摸事件
private static final boolean USE_MY_INPUT = true;
private InputQueueCompat inputQueueCompat;
// public static int notchHeight; // public static int notchHeight;
...@@ -111,6 +116,12 @@ public class YGOMobileActivity extends NativeActivity implements ...@@ -111,6 +116,12 @@ public class YGOMobileActivity extends NativeActivity implements
if (USE_SURFACE) { if (USE_SURFACE) {
mSurfaceView = new SurfaceView(this); mSurfaceView = new SurfaceView(this);
} }
if (USE_MY_INPUT) {
inputQueueCompat = new InputQueueCompat();
if (!inputQueueCompat.isValid()) {
inputQueueCompat = null;
}
}
mFullScreenUtils = new FullScreenUtils(this, app().isImmerSiveMode()); mFullScreenUtils = new FullScreenUtils(this, app().isImmerSiveMode());
mFullScreenUtils.fullscreen(); mFullScreenUtils.fullscreen();
mFullScreenUtils.onCreate(); mFullScreenUtils.onCreate();
...@@ -245,6 +256,7 @@ public class YGOMobileActivity extends NativeActivity implements ...@@ -245,6 +256,7 @@ public class YGOMobileActivity extends NativeActivity implements
} }
} }
@SuppressLint("ClickableViewAccessibility")
@Override @Override
public void setContentView(View view) { public void setContentView(View view) {
int[] size = getGameSize(); int[] size = getGameSize();
...@@ -260,10 +272,22 @@ public class YGOMobileActivity extends NativeActivity implements ...@@ -260,10 +272,22 @@ public class YGOMobileActivity extends NativeActivity implements
app().attachGame(this); app().attachGame(this);
changeGameSize(); changeGameSize();
getWindow().takeSurface(null); getWindow().takeSurface(null);
if (USE_MY_INPUT && inputQueueCompat != null) {
getWindow().takeInputQueue(null);
}
replaced = true; replaced = true;
mSurfaceView.getHolder().addCallback(this); mSurfaceView.getHolder().addCallback(this);
mSurfaceView.requestFocus(); mSurfaceView.requestFocus();
getWindow().setGravity(Gravity.CENTER); getWindow().setGravity(Gravity.CENTER);
if (USE_MY_INPUT && inputQueueCompat != null) {
Log.e(IrrlichtBridge.TAG, "use java input queue:" + inputQueueCompat.getNativePtr());
mSurfaceView.setOnTouchListener((v, event) -> {
if (inputQueueCompat != null) {
inputQueueCompat.sendInputEvent(event, v, true);
}
return true;
});
}
} else { } else {
mLayout.addView(view, lp); mLayout.addView(view, lp);
getWindow().setGravity(Gravity.CENTER); getWindow().setGravity(Gravity.CENTER);
...@@ -272,18 +296,25 @@ public class YGOMobileActivity extends NativeActivity implements ...@@ -272,18 +296,25 @@ public class YGOMobileActivity extends NativeActivity implements
} }
private void changeGameSize() { private void changeGameSize() {
//游戏大小
int[] size = getGameSize();
int w = (int) app().getScreenHeight();
int h = (int) app().getScreenWidth();
int spX = (int) ((w - size[0]) / 2.0f);
int spY = (int) ((h - size[1]) / 2.0f);
boolean update = false; boolean update = false;
synchronized (this) { if(USE_MY_INPUT && inputQueueCompat != null) {
if (spX != mPositionX || spY != mPositionY) { //Ignore
mPositionX = spX; update = true;
mPositionY = spY; mPositionX = 0;
update = true; mPositionY = 0;
} else {
//游戏大小
int[] size = getGameSize();
int w = (int) app().getScreenHeight();
int h = (int) app().getScreenWidth();
int spX = (int) ((w - size[0]) / 2.0f);
int spY = (int) ((h - size[1]) / 2.0f);
synchronized (this) {
if (spX != mPositionX || spY != mPositionY) {
mPositionX = spX;
mPositionY = spY;
update = true;
}
} }
} }
if (update) { if (update) {
...@@ -310,9 +341,15 @@ public class YGOMobileActivity extends NativeActivity implements ...@@ -310,9 +341,15 @@ public class YGOMobileActivity extends NativeActivity implements
// Log.e("YGOMobileActivity","窗口变化"+hasFocus); // Log.e("YGOMobileActivity","窗口变化"+hasFocus);
if (hasFocus) { if (hasFocus) {
fullscreen(); fullscreen();
if (inputQueueCompat != null) {
super.onInputQueueCreated(inputQueueCompat.getInputQueue());
}
mContentView.setHapticFeedbackEnabled(true); mContentView.setHapticFeedbackEnabled(true);
} else { } else {
mContentView.setHapticFeedbackEnabled(false); mContentView.setHapticFeedbackEnabled(false);
if (inputQueueCompat != null) {
super.onInputQueueDestroyed(inputQueueCompat.getInputQueue());
}
} }
super.onWindowFocusChanged(hasFocus); super.onWindowFocusChanged(hasFocus);
} }
...@@ -531,15 +568,51 @@ public class YGOMobileActivity extends NativeActivity implements ...@@ -531,15 +568,51 @@ public class YGOMobileActivity extends NativeActivity implements
} }
}); });
} }
//
// @Override
// public boolean onKeyDown(int keyCode, KeyEvent event) {
// if(inputQueueCompat != null) {
// if (keyCode == KeyEvent.KEYCODE_BACK) {
// inputQueueCompat.sendInputEvent(event, this, true);
// return true;
// }
// }
// return super.onKeyDown(keyCode, event);
// }
//
// @Override
// public boolean onKeyUp(int keyCode, KeyEvent event) {
// if(inputQueueCompat != null) {
// if (keyCode == KeyEvent.KEYCODE_BACK) {
// inputQueueCompat.sendInputEvent(event, this, true);
// return true;
// }
// }
// return super.onKeyUp(keyCode, event);
// }
@Override
public void onBackPressed() {
if(mGlobalComboBox != null && mGlobalComboBox.isShowing()){
mGlobalComboBox.dismiss();
return;
}
if(mGlobalEditText != null && mGlobalEditText.isShowing()){
mGlobalEditText.dismiss();
return;
}
super.onBackPressed();
}
@Override @Override
public void onGameExit() { public void onGameExit() {
if(onGameExiting){ if (onGameExiting) {
return; return;
} }
onGameExiting = true; onGameExiting = true;
Log.e(IrrlichtBridge.TAG, "game exit"); Log.e(IrrlichtBridge.TAG, "game exit");
final Intent intent = new Intent(IrrlichtBridge.ACTION_OPEN_GAME_HOME); final Intent intent = new Intent(IrrlichtBridge.ACTION_OPEN_GAME_HOME);
intent.addCategory(Intent.CATEGORY_DEFAULT); intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); intent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
...@@ -558,7 +631,7 @@ public class YGOMobileActivity extends NativeActivity implements ...@@ -558,7 +631,7 @@ public class YGOMobileActivity extends NativeActivity implements
} }
boolean isRoot = isTaskRoot(); boolean isRoot = isTaskRoot();
Log.d(IrrlichtBridge.TAG, "isRoot=" + isRoot + ",kill:" + Process.myPid()); Log.d(IrrlichtBridge.TAG, "isRoot=" + isRoot + ",kill:" + Process.myPid());
if(isRoot) { if (isRoot) {
finishAndRemoveTask(); finishAndRemoveTask();
} else { } else {
finish(); finish();
......
package cn.garymb.ygomobile.controller;
import android.os.Looper;
import android.util.Log;
import android.view.InputEvent;
import android.view.InputQueue;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import cn.garymb.ygomobile.utils.AndroidHideApi;
public class InputQueueCompat implements InvocationHandler {
private static final String TAG = "kk-java";
private static Constructor<InputQueue> InputQueue_ctr;
private static Method getNativePtr_method;
private static Class<?> FinishedInputEventCallback_class;
//sendInputEvent(InputEvent e, Object token, boolean predispatch,
// FinishedInputEventCallback callback)
private static Method sendInputEvent_method;
private FinishedInputEventCallbackCompat finishedInputEventCallbackCompat;
static {
AndroidHideApi.enableHideApi();
try {
Looper.getMainLooper();
InputQueue_ctr = InputQueue.class.getDeclaredConstructor();
// InputQueue_ctr.setAccessible(true);
getNativePtr_method = InputQueue.class.getMethod("getNativePtr");
// getNativePtr_method.setAccessible(true);
FinishedInputEventCallback_class = Class.forName(InputQueue.class.getName() + "$FinishedInputEventCallback");
sendInputEvent_method = InputQueue.class.getMethod("sendInputEvent", InputEvent.class, Object.class, boolean.class,
FinishedInputEventCallback_class);
} catch (Throwable e) {
Log.e(TAG, "InputQueueCompat init", e);
}
}
private final InputQueue inputQueue;
private final Object callback;
public InputQueueCompat(InputQueue inputQueue) {
this.inputQueue = inputQueue;
if(inputQueue != null) {
callback = Proxy.newProxyInstance(InputQueue.class.getClassLoader(), new Class[]{FinishedInputEventCallback_class},
this);
} else {
callback = null;
}
}
@Override
public Object invoke(Object proxy, Method method, Object[] args) {
//void onFinishedInputEvent(Object token, boolean handled);
if ("onFinishedInputEvent".equals(method.getName())) {
Object token = args[0];
boolean handled = (boolean) args[1];
onFinishedInputEvent(token, handled);
return 0;
}
return 0;
}
public InputQueueCompat() {
this(create());
}
public void setFinishedInputEventCallback(FinishedInputEventCallbackCompat finishedInputEventCallbackCompat) {
this.finishedInputEventCallbackCompat = finishedInputEventCallbackCompat;
}
public boolean isValid() {
return inputQueue != null && sendInputEvent_method != null && getNativePtr_method != null;
}
private static InputQueue create() {
try {
return InputQueue_ctr.newInstance();
} catch (Throwable e) {
Log.w(TAG, "InputQueue<init>", e);
return null;
}
}
public long getNativePtr() {
if (getNativePtr_method == null || inputQueue == null) {
return 0;
}
try {
Long ret = (Long) getNativePtr_method.invoke(inputQueue);
if (ret == null) {
return 0;
}
return ret;
} catch (Throwable e) {
Log.w(TAG, "getNativePtr", e);
return 0;
}
}
public InputQueue getInputQueue() {
return inputQueue;
}
public void sendInputEvent(InputEvent e, Object token, boolean predispatch) {
if (sendInputEvent_method == null) {
return;
}
try {
Log.d(TAG, "inputQueue:sendInputEvent:" + e);
sendInputEvent_method.invoke(inputQueue, e, token, predispatch, callback);
} catch (Throwable ex) {
Log.w(TAG, "inputQueue:sendInputEvent", ex);
}
}
public void onFinishedInputEvent(Object token, boolean handled) {
//TODO
Log.d(TAG, "onFinishedInputEvent:" + token + ", handled=" + handled);
if(this.finishedInputEventCallbackCompat != null){
finishedInputEventCallbackCompat.onFinishedInputEvent(token, handled);
}
}
public interface FinishedInputEventCallbackCompat{
void onFinishedInputEvent(Object token, boolean handled);
}
}
package cn.garymb.ygomobile.utils;
import android.os.Build;
import java.lang.reflect.Method;
public class AndroidHideApi {
private static boolean sBypassedP = false;
public static void enableHideApi() {
if (sBypassedP) {
return;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
try {
Method forNameMethod = Class.class.getDeclaredMethod("forName", String.class);
Class<?> clazz = (Class<?>) forNameMethod.invoke(null, "dalvik.system.VMRuntime");
Method getMethodMethod = Class.class.getDeclaredMethod("getDeclaredMethod", String.class, Class[].class);
Method getRuntime = (Method) getMethodMethod.invoke(clazz, "getRuntime", new Class[0]);
Method setHiddenApiExemptions = (Method) getMethodMethod.invoke(clazz, "setHiddenApiExemptions", new Class[]{String[].class});
Object runtime = getRuntime.invoke(null);
setHiddenApiExemptions.invoke(runtime, new Object[]{
new String[]{
"Landroid/",
"Lcom/android/",
"Ljava/lang/",
"Ldalvik/system/",
"Llibcore/io/",
"Lhuawei/"
}
});
} catch (Throwable e) {
e.printStackTrace();
}
}
sBypassedP = true;
}
}
...@@ -18,6 +18,7 @@ import java.util.Arrays; ...@@ -18,6 +18,7 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import cn.garymb.ygomobile.core.IrrlichtBridge;
import cn.garymb.ygomobile.lite.R; import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.ui.preference.PreferenceFragmentPlus; import cn.garymb.ygomobile.ui.preference.PreferenceFragmentPlus;
import cn.garymb.ygomobile.utils.DeckUtil; import cn.garymb.ygomobile.utils.DeckUtil;
...@@ -33,6 +34,7 @@ import static cn.garymb.ygomobile.Constants.DEF_PREF_KEEP_SCALE; ...@@ -33,6 +34,7 @@ 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_NOTCH_HEIGHT;
import static cn.garymb.ygomobile.Constants.DEF_PREF_ONLY_GAME; 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_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_IMMERSIVE_MODE;
import static cn.garymb.ygomobile.Constants.PREF_DEF_SENSOR_REFRESH; import static cn.garymb.ygomobile.Constants.PREF_DEF_SENSOR_REFRESH;
import static cn.garymb.ygomobile.Constants.PREF_FONT_SIZE; import static cn.garymb.ygomobile.Constants.PREF_FONT_SIZE;
...@@ -43,6 +45,7 @@ import static cn.garymb.ygomobile.Constants.PREF_NOTCH_HEIGHT; ...@@ -43,6 +45,7 @@ import static cn.garymb.ygomobile.Constants.PREF_NOTCH_HEIGHT;
import static cn.garymb.ygomobile.Constants.PREF_ONLY_GAME; import static cn.garymb.ygomobile.Constants.PREF_ONLY_GAME;
import static cn.garymb.ygomobile.Constants.PREF_READ_EX; import static cn.garymb.ygomobile.Constants.PREF_READ_EX;
import static cn.garymb.ygomobile.Constants.PREF_SENSOR_REFRESH; import static cn.garymb.ygomobile.Constants.PREF_SENSOR_REFRESH;
import static cn.garymb.ygomobile.Constants.PREF_WINDOW_TOP_BOTTOM;
import static cn.garymb.ygomobile.Constants.WINDBOT_DECK_PATH; import static cn.garymb.ygomobile.Constants.WINDBOT_DECK_PATH;
import static cn.garymb.ygomobile.Constants.WINDBOT_PATH; import static cn.garymb.ygomobile.Constants.WINDBOT_PATH;
import static cn.garymb.ygomobile.Constants.YDK_FILE_EX; import static cn.garymb.ygomobile.Constants.YDK_FILE_EX;
...@@ -134,6 +137,7 @@ public class AppsSettings { ...@@ -134,6 +137,7 @@ public class AppsSettings {
} }
public float getXScale(int w, int h) { public float getXScale(int w, int h) {
//曲面屏
if (isKeepScale()) { if (isKeepScale()) {
float sx = getScreenHeight() / w; float sx = getScreenHeight() / w;
float sy = getScreenWidth() / h; float sy = getScreenWidth() / h;
...@@ -165,7 +169,11 @@ public class AppsSettings { ...@@ -165,7 +169,11 @@ public class AppsSettings {
w = mScreenSize.x; w = mScreenSize.x;
h = mScreenSize.y; h = mScreenSize.y;
} }
return Math.min(w, h); int ret = Math.min(w, h);
//测试代码,曲面屏左右2变需要留空白,但是游戏画面比例不对,需要修改c那边代码
int fix_h = mSharedPreferences.getInt(PREF_WINDOW_TOP_BOTTOM, DEF_PREF_WINDOW_TOP_BOTTOM);
Log.i(IrrlichtBridge.TAG, "get width=" + ret + "->" + (ret - fix_h * 2));
return ret - fix_h * 2;
} }
public float getScreenHeight() { public float getScreenHeight() {
......
...@@ -117,6 +117,10 @@ public interface Constants { ...@@ -117,6 +117,10 @@ public interface Constants {
String PREF_KEEP_SCALE = "pref_settings_keep_scale"; String PREF_KEEP_SCALE = "pref_settings_keep_scale";
boolean DEF_PREF_KEEP_SCALE = false; boolean DEF_PREF_KEEP_SCALE = false;
//dp单位,游戏高度减少,留空白
String PREF_WINDOW_TOP_BOTTOM = "pref_settings_window_top_bottom";
int DEF_PREF_WINDOW_TOP_BOTTOM = 50;
int REQUEST_CUT_IMG = 0x1000 + 0x10; int REQUEST_CUT_IMG = 0x1000 + 0x10;
int REQUEST_CHOOSE_FILE = 0x1000 + 0x20; int REQUEST_CHOOSE_FILE = 0x1000 + 0x20;
int REQUEST_CHOOSE_IMG = 0x1000 + 0x21; int REQUEST_CHOOSE_IMG = 0x1000 + 0x21;
......
...@@ -157,9 +157,9 @@ public class DeckManagerActivity extends BaseCardsActivity implements RecyclerVi ...@@ -157,9 +157,9 @@ public class DeckManagerActivity extends BaseCardsActivity implements RecyclerVi
$(R.id.btn_nav_list).setOnClickListener((v) -> doMenu(R.id.action_card_list)); $(R.id.btn_nav_list).setOnClickListener((v) -> doMenu(R.id.action_card_list));
// //
final File _file; final File _file;
//打开指定卡组 //打开指定卡组
if (!TextUtils.isEmpty(preLoadFile) && (mPreLoadFile = new File(preLoadFile)).exists()) { if (!TextUtils.isEmpty(preLoadFile) && (mPreLoadFile = new File(preLoadFile)).exists()) {
//外面卡组 //外面卡组
_file = mPreLoadFile; _file = mPreLoadFile;
} else { } else {
mPreLoadFile = null; mPreLoadFile = null;
...@@ -167,7 +167,7 @@ public class DeckManagerActivity extends BaseCardsActivity implements RecyclerVi ...@@ -167,7 +167,7 @@ public class DeckManagerActivity extends BaseCardsActivity implements RecyclerVi
if(TextUtils.isEmpty(path)){ if(TextUtils.isEmpty(path)){
_file = null; _file = null;
} else { } else {
//最后卡组 //最后卡组
_file = new File(path); _file = new File(path);
} }
} }
...@@ -260,13 +260,13 @@ public class DeckManagerActivity extends BaseCardsActivity implements RecyclerVi ...@@ -260,13 +260,13 @@ public class DeckManagerActivity extends BaseCardsActivity implements RecyclerVi
DialogPlus dlg = DialogPlus.show(this, null, getString(R.string.loading)); DialogPlus dlg = DialogPlus.show(this, null, getString(R.string.loading));
VUiKit.defer().when(() -> { VUiKit.defer().when(() -> {
DataManager.get().load(true); DataManager.get().load(true);
//默认第一个卡表 //默认第一个卡表
if (mLimitManager.getCount() > 0) { if (mLimitManager.getCount() > 0) {
mCardLoader.setLimitList(mLimitManager.getTopLimit()); mCardLoader.setLimitList(mLimitManager.getTopLimit());
} }
File file = ydk; File file = ydk;
if (file == null || !file.exists()) { if (file == null || !file.exists()) {
//当默认卡组不存在的时候 //当默认卡组不存在的时候
List<File> files = getYdkFiles(); List<File> files = getYdkFiles();
if (files != null && files.size() > 0) { if (files != null && files.size() > 0) {
file = files.get(0); file = files.get(0);
...@@ -288,15 +288,15 @@ public class DeckManagerActivity extends BaseCardsActivity implements RecyclerVi ...@@ -288,15 +288,15 @@ public class DeckManagerActivity extends BaseCardsActivity implements RecyclerVi
mCardSelector.initItems(); mCardSelector.initItems();
initLimitListSpinners(mLimitSpinner, mCardLoader.getLimitList()); initLimitListSpinners(mLimitSpinner, mCardLoader.getLimitList());
initDecksListSpinners(mDeckSpinner, rs.source); initDecksListSpinners(mDeckSpinner, rs.source);
//设置当前卡组 //设置当前卡组
setCurDeck(rs); setCurDeck(rs);
//设置收藏夹 //设置收藏夹
mCardSelector.showFavorites(false); mCardSelector.showFavorites(false);
}); });
} }
/** /**
* 设置当前卡组 * 设置当前卡组
*/ */
private void setCurDeck(DeckInfo deckInfo) { private void setCurDeck(DeckInfo deckInfo) {
if (deckInfo == null) { if (deckInfo == null) {
...@@ -307,7 +307,7 @@ public class DeckManagerActivity extends BaseCardsActivity implements RecyclerVi ...@@ -307,7 +307,7 @@ public class DeckManagerActivity extends BaseCardsActivity implements RecyclerVi
String name = IOUtils.tirmName(file.getName(), Constants.YDK_FILE_EX); String name = IOUtils.tirmName(file.getName(), Constants.YDK_FILE_EX);
setActionBarSubTitle(name); setActionBarSubTitle(name);
// if (inDeckDir(file)) { // if (inDeckDir(file)) {
//记住最后打开的卡组 //记住最后打开的卡组
mSettings.setLastDeckPath(file.getAbsolutePath()); mSettings.setLastDeckPath(file.getAbsolutePath());
tv_deck.setText(name); tv_deck.setText(name);
...@@ -383,7 +383,7 @@ public class DeckManagerActivity extends BaseCardsActivity implements RecyclerVi ...@@ -383,7 +383,7 @@ public class DeckManagerActivity extends BaseCardsActivity implements RecyclerVi
@Override @Override
public void onItemDoubleClick(View view, int pos) { public void onItemDoubleClick(View view, int pos) {
//拖拽中,就不显示 //拖拽中,就不显示
if (isShowDrawer()) { if (isShowDrawer()) {
return; return;
} }
...@@ -627,7 +627,7 @@ public class DeckManagerActivity extends BaseCardsActivity implements RecyclerVi ...@@ -627,7 +627,7 @@ public class DeckManagerActivity extends BaseCardsActivity implements RecyclerVi
// mDeckAdapater.notifyDataSetChanged(); // mDeckAdapater.notifyDataSetChanged();
// break; // break;
case R.id.action_search: case R.id.action_search:
//弹条件对话框 //弹条件对话框
showSearch(true); showSearch(true);
break; break;
case R.id.action_card_list: case R.id.action_card_list:
...@@ -642,7 +642,7 @@ public class DeckManagerActivity extends BaseCardsActivity implements RecyclerVi ...@@ -642,7 +642,7 @@ public class DeckManagerActivity extends BaseCardsActivity implements RecyclerVi
break; break;
case R.id.action_save: case R.id.action_save:
if (mPreLoadFile != null && mPreLoadFile == mDeckAdapater.getYdkFile()) { if (mPreLoadFile != null && mPreLoadFile == mDeckAdapater.getYdkFile()) {
//需要保存到deck文件夹 //需要保存到deck文件夹
inputDeckName(mPreLoadFile, null, true); inputDeckName(mPreLoadFile, null, true);
} else { } else {
if (mDeckAdapater.getYdkFile() == null) { if (mDeckAdapater.getYdkFile() == null) {
...@@ -709,7 +709,7 @@ public class DeckManagerActivity extends BaseCardsActivity implements RecyclerVi ...@@ -709,7 +709,7 @@ public class DeckManagerActivity extends BaseCardsActivity implements RecyclerVi
} }
break; break;
case R.id.action_unsort: case R.id.action_unsort:
//打乱 //打乱
mDeckAdapater.unSort(); mDeckAdapater.unSort();
break; break;
case R.id.action_sort: case R.id.action_sort:
...@@ -729,7 +729,7 @@ public class DeckManagerActivity extends BaseCardsActivity implements RecyclerVi ...@@ -729,7 +729,7 @@ public class DeckManagerActivity extends BaseCardsActivity implements RecyclerVi
builder.setMessageGravity(Gravity.CENTER_HORIZONTAL); builder.setMessageGravity(Gravity.CENTER_HORIZONTAL);
builder.setLeftButtonListener((dlg, rs) -> { builder.setLeftButtonListener((dlg, rs) -> {
dlg.dismiss(); dlg.dismiss();
//复制当前卡组 //复制当前卡组
inputDeckName(old, savePath, true); inputDeckName(old, savePath, true);
}); });
builder.setRightButtonListener((dlg, rs) -> { builder.setRightButtonListener((dlg, rs) -> {
...@@ -757,11 +757,11 @@ public class DeckManagerActivity extends BaseCardsActivity implements RecyclerVi ...@@ -757,11 +757,11 @@ public class DeckManagerActivity extends BaseCardsActivity implements RecyclerVi
builderShareLoading.setMessage(R.string.Pre_share); builderShareLoading.setMessage(R.string.Pre_share);
builderShareLoading.show(); builderShareLoading.show();
//先排序 //先排序
// mDeckAdapater.sort(); // mDeckAdapater.sort();
//保存 //保存
// if (mPreLoadFile != null && mPreLoadFile == mDeckAdapater.getYdkFile()) { // if (mPreLoadFile != null && mPreLoadFile == mDeckAdapater.getYdkFile()) {
// //需要保存到deck文件夹 // //需要保存到deck文件夹
// inputDeckName(mPreLoadFile, null, true); // inputDeckName(mPreLoadFile, null, true);
// } else { // } else {
// if (mDeckAdapater.getYdkFile() == null) { // if (mDeckAdapater.getYdkFile() == null) {
...@@ -770,27 +770,27 @@ public class DeckManagerActivity extends BaseCardsActivity implements RecyclerVi ...@@ -770,27 +770,27 @@ public class DeckManagerActivity extends BaseCardsActivity implements RecyclerVi
// save(mDeckAdapater.getYdkFile()); // save(mDeckAdapater.getYdkFile());
// } // }
// } // }
// //保存成功后重新加载卡组 // //保存成功后重新加载卡组
// File file = getSelectDeck(mDeckSpinner); // File file = getSelectDeck(mDeckSpinner);
// if (file != null) { // if (file != null) {
// loadDeckFromFile(file); // loadDeckFromFile(file);
// } // }
//延时半秒,使整体看起来更流畅 //延时半秒,使整体看起来更流畅
new Handler().postDelayed(this::shareDeck1, 500); new Handler().postDelayed(this::shareDeck1, 500);
} }
private void shareDeck1() { private void shareDeck1() {
//开启绘图缓存 //开启绘图缓存
mRecyclerView.setDrawingCacheEnabled(true); mRecyclerView.setDrawingCacheEnabled(true);
//这个方法可调可不调,因为在getDrawingCache()里会自动判断有没有缓存有没有准备好, //这个方法可调可不调,因为在getDrawingCache()里会自动判断有没有缓存有没有准备好,
//如果没有,会自动调用buildDrawingCache() //如果没有,会自动调用buildDrawingCache()
mRecyclerView.buildDrawingCache(); mRecyclerView.buildDrawingCache();
//获取绘图缓存 这里直接创建了一个新的bitmap //获取绘图缓存 这里直接创建了一个新的bitmap
//因为我们在最后需要释放缓存资源,会释放掉缓存中创建的bitmap对象 //因为我们在最后需要释放缓存资源,会释放掉缓存中创建的bitmap对象
Bitmap bitmap = BitmapUtil.drawBg4Bitmap(Color.parseColor("#e6f3fd"), Bitmap.createBitmap(mRecyclerView.getDrawingCache(), 0, 0, mRecyclerView.getMeasuredWidth(), Bitmap bitmap = BitmapUtil.drawBg4Bitmap(Color.parseColor("#e6f3fd"), Bitmap.createBitmap(mRecyclerView.getDrawingCache(), 0, 0, mRecyclerView.getMeasuredWidth(),
mRecyclerView.getMeasuredHeight())); mRecyclerView.getMeasuredHeight()));
//清理绘图缓存,释放资源 //清理绘图缓存,释放资源
mRecyclerView.destroyDrawingCache(); mRecyclerView.destroyDrawingCache();
// shotRecyclerView(mRecyclerView) // shotRecyclerView(mRecyclerView)
...@@ -817,7 +817,7 @@ public class DeckManagerActivity extends BaseCardsActivity implements RecyclerVi ...@@ -817,7 +817,7 @@ public class DeckManagerActivity extends BaseCardsActivity implements RecyclerVi
stopService(new Intent(this, DuelAssistantService.class)); stopService(new Intent(this, DuelAssistantService.class));
YGOUtil.copyMessage(this, et_code.getText().toString().trim()); YGOUtil.copyMessage(this, et_code.getText().toString().trim());
showToast(getString(R.string.deck_text_copyed)); showToast(getString(R.string.deck_text_copyed));
//复制完毕开启决斗助手 //复制完毕开启决斗助手
YGOUtil.startDuelService(this); YGOUtil.startDuelService(this);
}); });
...@@ -844,7 +844,7 @@ public class DeckManagerActivity extends BaseCardsActivity implements RecyclerVi ...@@ -844,7 +844,7 @@ public class DeckManagerActivity extends BaseCardsActivity implements RecyclerVi
}); });
//复制前关闭决斗助手 //复制前关闭决斗助手
// String label = TextUtils.isEmpty(deck.getName()) ? getString(R.string.share_deck) : deck.getName(); // String label = TextUtils.isEmpty(deck.getName()) ? getString(R.string.share_deck) : deck.getName();
...@@ -1075,9 +1075,9 @@ public class DeckManagerActivity extends BaseCardsActivity implements RecyclerVi ...@@ -1075,9 +1075,9 @@ public class DeckManagerActivity extends BaseCardsActivity implements RecyclerVi
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_deck_backup_n_restore, R.string.deck_backup_n_restore, R.drawable.downloadimages); addMenuButton(mMenuIds, menu, R.id.action_deck_backup_n_restore, R.string.deck_backup_n_restore, R.drawable.downloadimages);
//设置展开或隐藏的延时。 默认值为 800ms。 //设置展开或隐藏的延时。 默认值为 800ms。
menu.setDuration(150); menu.setDuration(150);
//设置每两个子按钮之间动画的延时(ms为单位)。 比如,如果延时设为0,那么所有子按钮都会同时展开或隐藏,默认值为100ms。 //设置每两个子按钮之间动画的延时(ms为单位)。 比如,如果延时设为0,那么所有子按钮都会同时展开或隐藏,默认值为100ms。
menu.setDelay(10); menu.setDelay(10);
menu.setOnBoomListener(new DefaultOnBoomListener() { menu.setOnBoomListener(new DefaultOnBoomListener() {
......
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