Commit cc4da97f authored by fallenstardust's avatar fallenstardust

remove game receiver

parent e35f4fa0
......@@ -5,6 +5,7 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application>
<activity
......@@ -23,13 +24,6 @@
android:name="android.app.lib_name"
android:value="YGOMobile"/>
</activity>
<receiver android:name="cn.garymb.ygomobile.GameReceiver"
android:process=":gamehelper" >
<intent-filter>
<action android:name="cn.garymb.ygomobile.game.start"/>
<action android:name="cn.garymb.ygomobile.game.stop"/>
</intent-filter>
</receiver>
</application>
</manifest>
package cn.garymb.ygomobile;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import cn.garymb.ygomobile.core.IrrlichtBridge;
import static cn.garymb.ygomobile.core.IrrlichtBridge.ACTION_START;
import static cn.garymb.ygomobile.core.IrrlichtBridge.ACTION_STOP;
public class GameReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (ACTION_START.equals(action)) {
//
IrrlichtBridge.gPid = intent.getIntExtra(IrrlichtBridge.EXTRA_PID, 0);
// Log.w("ygo", "pid=" + IrrlichtBridge.gPid);
} else if (ACTION_STOP.equals(action)) {
int pid = intent.getIntExtra(IrrlichtBridge.EXTRA_PID, 0);
if (pid == 0 && IrrlichtBridge.gPid != 0) {
pid = IrrlichtBridge.gPid;
// Log.w("ygo", "will kill last pid=" + pid);
}
if (pid == 0) {
pid = android.os.Process.myPid();
// Log.w("ygo", "will kill now pid=" + pid);
}
try {
// Log.w("ygo", "kill pid=" + pid);
android.os.Process.killProcess(pid);
} catch (Exception e) {
//ignore
}
}
}
}
......@@ -43,8 +43,6 @@ import cn.garymb.ygomobile.widget.overlay.OverlayOvalView;
import cn.garymb.ygomobile.widget.overlay.OverlayView;
import static cn.garymb.ygomobile.core.IrrlichtBridge.ACTION_SHARE_FILE;
import static cn.garymb.ygomobile.core.IrrlichtBridge.ACTION_START;
import static cn.garymb.ygomobile.core.IrrlichtBridge.ACTION_STOP;
/**
* @author mabin
......@@ -131,9 +129,6 @@ public class YGOMobileActivity extends NativeActivity implements
mPM = (PowerManager) getSystemService(Context.POWER_SERVICE);
mNetController = new NetworkController(getApplicationContext());
handleExternalCommand(getIntent());
sendBroadcast(new Intent(ACTION_START)
.putExtra(IrrlichtBridge.EXTRA_PID, android.os.Process.myPid())
.setPackage(getPackageName()));
}
//电池管理
......@@ -194,14 +189,6 @@ public class YGOMobileActivity extends NativeActivity implements
super.onDestroy();
}
@Override
public void finish() {
super.finish();
sendBroadcast(new Intent(ACTION_STOP)
.putExtra(IrrlichtBridge.EXTRA_PID, android.os.Process.myPid())
.setPackage(getPackageName()));
}
private void handleExternalCommand(Intent intent) {
YGOGameOptions options = intent
.getParcelableExtra(YGOGameOptions.YGO_GAME_OPTIONS_BUNDLE_KEY);
......@@ -291,7 +278,6 @@ public class YGOMobileActivity extends NativeActivity implements
int h = (int) app().getScreenWidth();
int spX = (int) ((w - size[0]) / 2.0f);
int spY = (int) ((h - size[1]) / 2.0f);
// Log.i("ygo", "Android command 1:posX=" + spX + ",posY=" + spY);
boolean update = false;
synchronized (this) {
if (spX != mPositionX || spY != mPositionY) {
......@@ -301,7 +287,6 @@ public class YGOMobileActivity extends NativeActivity implements
}
}
if (update) {
// Log.i("ygo", "Android command setInputFix2:posX=" + spX + ",posY=" + spY);
IrrlichtBridge.setInputFix(mPositionX, mPositionY);
}
}
......@@ -527,15 +512,15 @@ public class YGOMobileActivity extends NativeActivity implements
}
@Override
public void shareFile(final String title, final String ext) {
public void shareFile(final String type, final String name) {
//TODO 分享文件
runOnUiThread(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(ACTION_SHARE_FILE);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.putExtra(IrrlichtBridge.EXTRA_SHARE_TYPE, title);
intent.putExtra(IrrlichtBridge.EXTRA_SHARE_FILE, ext);
intent.putExtra(IrrlichtBridge.EXTRA_SHARE_TYPE, type);
intent.putExtra(IrrlichtBridge.EXTRA_SHARE_FILE, name);
intent.setPackage(getPackageName());
try {
startActivity(intent);
......@@ -553,20 +538,31 @@ public class YGOMobileActivity extends NativeActivity implements
return;
}
onGameExiting = true;
Log.e("ygomobile", "game exit");
final Intent intent = new Intent("ygomobile.intent.action.GAME");
Log.e(IrrlichtBridge.TAG, "game exit");
final Intent intent = new Intent(IrrlichtBridge.ACTION_OPEN_GAME_HOME);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
intent.putExtra("game_exit_time", System.currentTimeMillis());
// intent.putExtra(IrrlichtBridge.EXTRA_PID, Process.myPid());
// intent.putExtra(IrrlichtBridge.EXTRA_TASK_ID, getTaskId());
// intent.putExtra(IrrlichtBridge.EXTRA_GAME_EXIT_TIME, System.currentTimeMillis());
intent.setPackage(getPackageName());
runOnUiThread(new Runnable() {
@Override
public void run() {
try {
startActivity(intent);
} catch (Throwable ignore) {}
finishAndRemoveTask();
Log.d(IrrlichtBridge.TAG, "open home ok");
} catch (Throwable e) {
Log.w(IrrlichtBridge.TAG, "open home", e);
}
boolean isRoot = isTaskRoot();
Log.d(IrrlichtBridge.TAG, "isRoot=" + isRoot + ",kill:" + Process.myPid());
if(isRoot) {
finishAndRemoveTask();
} else {
finish();
}
Process.killProcess(Process.myPid());
}
});
......
......@@ -17,6 +17,8 @@ import java.io.InputStream;
import java.nio.ByteBuffer;
import java.util.Arrays;
import cn.garymb.ygodata.YGOGameOptions;
import static cn.garymb.ygomobile.utils.ByteUtils.byte2int;
import static cn.garymb.ygomobile.utils.ByteUtils.byte2uint;
......@@ -24,8 +26,7 @@ import static cn.garymb.ygomobile.utils.ByteUtils.byte2uint;
* @author mabin
*/
public final class IrrlichtBridge {
public static final String ACTION_START = "cn.garymb.ygomobile.game.start";
public static final String ACTION_STOP = "cn.garymb.ygomobile.game.stop";
public static final String ACTION_OPEN_GAME_HOME = "ygomobile.intent.action.GAME";
/**
* @see #EXTRA_SHARE_FILE
* @see #EXTRA_SHARE_TYPE
......@@ -37,8 +38,11 @@ public final class IrrlichtBridge {
public static final String EXTRA_PID = "extras.mypid";
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 final String EXTRA_GAME_EXIT_TIME = "game_exit_time";
public static final String EXTRA_TASK_ID = "extras.taskid";
public static final String TAG = "ygo-java";
public static int gPid;
public static long sNativeHandle;
......@@ -80,14 +84,16 @@ public final class IrrlichtBridge {
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) {
intent.putExtra(EXTRA_ARGV, args);
intent.putExtra(EXTRA_ARGV_TIME_OUT, (System.currentTimeMillis() + 15 * 1000));
}
public static String[] getArgs(Intent intent) {
public static String[] getArgs(Intent intent){
long time = intent.getLongExtra(EXTRA_ARGV_TIME_OUT, 0);
if (time > System.currentTimeMillis()) {
if(time > System.currentTimeMillis()){
return intent.getStringArrayExtra(EXTRA_ARGV);
}
return null;
......@@ -202,7 +208,7 @@ public final class IrrlichtBridge {
float getScreenHeight();
void runWindbot(String args);
void runWindbot(String args);
float getXScale();
......
......@@ -4,6 +4,8 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application>
<activity
android:name="cn.garymb.ygomobile.YGOMobileActivity"
......@@ -25,13 +27,6 @@
android:name="android.notch_support"
android:value="true"/>
</activity>
<receiver android:name="cn.garymb.ygomobile.GameReceiver"
android:process=":game" >
<intent-filter>
<action android:name="cn.garymb.ygomobile.game.start"/>
<action android:name="cn.garymb.ygomobile.game.stop"/>
</intent-filter>
</receiver>
</application>
</manifest>
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