1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
| import android.os.Bundle; import android.os.Handler; import android.os.PowerManager; import android.util.Log; import android.view.WindowManager; import android.widget.FrameLayout;
import org.egret.launcher.egret_android_launcher.NativeActivity; import org.egret.launcher.egret_android_launcher.NativeCallback; import org.egret.launcher.egret_android_launcher.NativeLauncher; import org.egret.runtime.launcherInterface.INativePlayer;
import static android.content.ContentValues.TAG;
public class MainActivity extends NativeActivity { private final String token = "a1f38cac5106f7415d683876caaf495042759ac03d8d2217c2e05577af86e0a7";
/* * 设置是否显示FPS面板 * true: 显示面板 * false: 隐藏面板 * Set whether to show FPS panel * true: show FPS panel * false: hide FPS panel * */ private final boolean showFPS = true;
private FrameLayout rootLayout = null;
private PowerManager.WakeLock mWakeLock;
private Handler handler = new Handler();
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 方法1 //getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); setContentView(R.layout.activity_main); rootLayout = (FrameLayout)findViewById(R.id.rootLayout);
launcher.initViews(rootLayout);
setExternalInterfaces();
/* * 设置是否自动关闭启动页 * 1: 自动关闭启动页 * 0: 手动关闭启动页 * Set whether to close the startup page automatically * 1. close the startup page automatically * 0. close the startup page manually * */ launcher.closeLoadingViewAutomatically = 1;
/* * 设置是否每次启动都重新下载游戏资源 * 0: 版本更新才重新下载 * 1: 每次启动都重新下载 * Set whether to re-download game resources each time the application starts * 0: re-download game resources if version updated * 1: re-download game resources each time the application starts * */ launcher.clearGameCache = 0;
/* * 设置runtime代码log的等级 * 0: Debug * 1: Info * 2: Warning * 3: Error * Set log level for runtime code * 0: Debug * 1: Info * 2: Warning * 3: Error * */ launcher.logLevel = 2;
progressCallback = new NativeCallback() { @Override public void onCallback(String msg, int val) { switch (msg) { case NativeLauncher.RequestingRuntime: /* * 向服务器请求runtime和游戏信息 * Request the server for runtime and game information * */ break; case NativeLauncher.LoadingRuntime: /* * 下载和加载runtime * Download and load runtime * */ break; case NativeLauncher.RetryRequestingRuntime: handler.postDelayed(new Runnable() { @Override public void run() { launcher.loadRuntime(token); } }, 1000); break; case NativeLauncher.LoadingGame: /* * 下载和加载游戏资源 * Download and load game resources * */ launcher.startRuntime(showFPS); break; case NativeLauncher.GameStarted: /* * 游戏启动 * Game started * */ break; case NativeLauncher.LoadRuntimeFailed: /* * 加载runtime和游戏信息失败 * Loading runtime and game resources failed * */ break; default:
break; } } }; launcher.loadRuntime(token); }
// 方法2 @Override protected void onResume() { super.onResume(); PowerManager mPowerManager = (PowerManager) getSystemService(POWER_SERVICE); mWakeLock = mPowerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE,TAG); mWakeLock.acquire(); }
// 方法2 public void onPause(){ super.onPause(); mWakeLock.release(); }
private void setExternalInterfaces() { launcher.setExternalInterface("callNative", new INativePlayer.INativeInterface() { @Override public void callback(String s) { Log.d("Egret Launcher", s); launcher.callExternalInterface("callJS", "message from native"); } }); } }</pre>
|