Exemplo n.º 1
0
 @Override
 public void onWindowFocusChanged(boolean hasFocus) {
   AndroidGame.debugLog("onWindowFocusChanged(" + hasFocus + ")");
   if (setting != null) {
     setImmersiveMode(setting.useImmersiveMode);
     hideStatusBar(setting.hideStatusBar);
   }
   if (game != null && game.assets != null && game.assets._audio != null) {
     if (hasFocus) {
       game.assets.getNativeAudio().onResume();
     } else {
       game.assets.getNativeAudio().onPause();
     }
   }
 }
Exemplo n.º 2
0
  @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 !");
    }
  }