@Override public void register(LSetting s, LazyLoading.Data data) { if (s instanceof AndroidSetting) { this.setting = (AndroidSetting) s; } else { AndroidSetting tmp = new AndroidSetting(); tmp.copy(s); tmp.fullscreen = true; this.setting = tmp; } this.mainData = data; }
@Override public void onMain() { AndroidSetting setting = new AndroidSetting(); setting.isFPS = true; setting.isMemory = true; setting.isLogo = false; setting.fullscreen = true; setting.width = 480; setting.height = 320; // 若启动此模式,则画面等比压缩,不会失真 setting.useRatioScaleFactor = false; // 强制一个显示大小(在android模式下,不填则默认全屏,此模式可能会造成画面失真) // setting.width_zoom = getContainerWidth(); // setting.height_zoom = getContainerHeight(); // 屏幕显示模式 // setting.showMode = LMode.FitFill; setting.logoPath = "loon_logo.png"; setting.fps = 60; setting.fontName = "Dialog"; setting.appName = "test"; setting.emulateTouch = false; setting.lockBackDestroy = false; register( setting, new Data() { @Override public Screen onScreen() { return new TitleScreen(); } }); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Loon.self = this; Context context = getApplicationContext(); this.onMain(); LMode mode = setting.showMode; if (mode == null) { mode = LMode.Fill; } if (setting != null && setting.fullscreen) { this.setFullScreen(setting.fullscreen); } else { int windowFlags = makeWindowFlags(); getWindow().setFlags(windowFlags, windowFlags); } int width = setting.width; int height = setting.height; // 是否按比例缩放屏幕 if (setting.useRatioScaleFactor) { float scale = scaleFactor(); width *= scale; height *= scale; setting.width_zoom = width; setting.height_zoom = height; setting.updateScale(); mode = LMode.MaxRatio; // 若缩放值为无法实现的数值,则默认操作 } else if (setting.width_zoom <= 0 || setting.height_zoom <= 0) { updateViewSize(setting.landscape(), setting.width, setting.height, mode); width = this.maxWidth; height = this.maxHeight; setting.width_zoom = this.maxWidth; setting.height_zoom = this.maxHeight; setting.updateScale(); mode = LMode.Fill; } this.game = createGame(); this.gameView = new AndroidGameViewGL(context, game); this.handler = new Handler(); setContentView(mode, gameView, width, height); setRequestedOrientation(orientation()); createWakeLock(setting.useWakelock); hideStatusBar(setting.hideStatusBar); setImmersiveMode(setting.useImmersiveMode); if (setting.useImmersiveMode && AndroidGame.getSDKVersion() >= 19) { try { Class<?> vlistener = Class.forName("loon.android.AndroidVisibilityListener"); Object o = vlistener.newInstance(); java.lang.reflect.Method method = vlistener.getDeclaredMethod("createListener", AndroidBase.class); method.invoke(o, this); } catch (Exception e) { } } try { final int REQUIRED_CONFIG_CHANGES = android.content.pm.ActivityInfo.CONFIG_ORIENTATION | android.content.pm.ActivityInfo.CONFIG_KEYBOARD_HIDDEN; android.content.pm.ActivityInfo info = this.getPackageManager() .getActivityInfo(new android.content.ComponentName(context, this.getClass()), 0); if ((info.configChanges & REQUIRED_CONFIG_CHANGES) != REQUIRED_CONFIG_CHANGES) { new android.app.AlertDialog.Builder(this) .setMessage( "Loon Tip : Please add the following line to the Activity manifest .\n[configChanges=\"keyboardHidden|orientation\"]") .show(); } } catch (Exception e) { Log.w("Loon", "Cannot access game AndroidManifest.xml file !"); } }