Skip to content

Commit

Permalink
Remove immersive mode, make some minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
artemdevel committed Jan 7, 2018
1 parent 6d2fd0f commit 7e404ce
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,19 @@
*/
package com.github.artemdevel.pixeldungeon;

import javax.microedition.khronos.opengles.GL10;

import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;

import com.github.artemdevel.pixeldungeon.game.common.Game;
import com.github.artemdevel.pixeldungeon.game.common.audio.Music;
import com.github.artemdevel.pixeldungeon.game.common.audio.Sample;
import com.github.artemdevel.pixeldungeon.scenes.GameScene;
import com.github.artemdevel.pixeldungeon.scenes.PixelScene;
import com.github.artemdevel.pixeldungeon.scenes.TitleScene;
import com.github.artemdevel.pixeldungeon.utils.Utils;

public class PixelDungeon extends Game {

private static boolean immersiveModeChanged = false;

public PixelDungeon() {
super(TitleScene.class);
}
Expand All @@ -44,8 +38,6 @@ public PixelDungeon() {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

updateImmersiveMode();

DisplayMetrics metrics = new DisplayMetrics();
instance.getWindowManager().getDefaultDisplay().getMetrics(metrics);
boolean landscape = metrics.widthPixels > metrics.heightPixels;
Expand Down Expand Up @@ -106,72 +98,20 @@ protected void onCreate(Bundle savedInstanceState) {
Assets.SND_MIMIC);
}

@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);

if (hasFocus) {
updateImmersiveMode();
}
}

public static void switchNoFade(Class<? extends PixelScene> c) {
PixelScene.noFade = true;
switchScene(c);
}

public static void landscape(boolean value) {
Game.instance.setRequestedOrientation(value ?
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE :
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Game.instance.setRequestedOrientation(value ? ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE : ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Preferences.INSTANCE.put(Preferences.KEY_LANDSCAPE, value);
}

public static boolean landscape() {
return width > height;
}

public static void immerse(boolean value) {
Preferences.INSTANCE.put(Preferences.KEY_IMMERSIVE, value);

instance.runOnUiThread(new Runnable() {
@Override
public void run() {
updateImmersiveMode();
immersiveModeChanged = true;
}
});
}

@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
super.onSurfaceChanged(gl, width, height);

if (immersiveModeChanged) {
requestedReset = true;
immersiveModeChanged = false;
}
}

public static void updateImmersiveMode() {
if (android.os.Build.VERSION.SDK_INT >= 19) {
try {
// Sometime NullPointerException happens here
instance.getWindow().getDecorView().setSystemUiVisibility(
immersed() ?
View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_FULLSCREEN |
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
: 0);
} catch (Exception e) {
Utils.reportException(e);
}
}
}

public static boolean immersed() {
return Preferences.INSTANCE.getBoolean(Preferences.KEY_IMMERSIVE, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.github.artemdevel.pixeldungeon.game.input.Keys;
import com.github.artemdevel.pixeldungeon.game.utils.Signal;

// NOTE: One scene can be active at a time.
public class Scene extends Group {

private Signal.Listener<Keys.Key> keyListener;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import com.github.artemdevel.pixeldungeon.game.common.TouchArea;
import com.github.artemdevel.pixeldungeon.PixelDungeon;
import com.github.artemdevel.pixeldungeon.effects.Flare;
import com.github.artemdevel.pixeldungeon.ui.Archs;
import com.github.artemdevel.pixeldungeon.ui.Arches;
import com.github.artemdevel.pixeldungeon.ui.ExitButton;
import com.github.artemdevel.pixeldungeon.ui.Icons;
import com.github.artemdevel.pixeldungeon.ui.Window;
Expand Down Expand Up @@ -80,7 +80,7 @@ protected void onClick(Touch touch) {

new Flare(7, 64).color(0x112233, true).show(wata, 0).angularSpeed = +20;

Archs archs = new Archs();
Arches archs = new Arches();
archs.setSize(Camera.main.width, Camera.main.height);
addToBack(archs);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import com.github.artemdevel.pixeldungeon.Badges;
import com.github.artemdevel.pixeldungeon.PixelDungeon;
import com.github.artemdevel.pixeldungeon.effects.BadgeBanner;
import com.github.artemdevel.pixeldungeon.ui.Archs;
import com.github.artemdevel.pixeldungeon.ui.Arches;
import com.github.artemdevel.pixeldungeon.ui.ExitButton;
import com.github.artemdevel.pixeldungeon.ui.Window;
import com.github.artemdevel.pixeldungeon.windows.WndBadge;
Expand All @@ -53,7 +53,7 @@ public void create() {
int w = Camera.main.width;
int h = Camera.main.height;

Archs archs = new Archs();
Arches archs = new Arches();
archs.setSize(w, h);
add(archs);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import com.github.artemdevel.pixeldungeon.effects.Flare;
import com.github.artemdevel.pixeldungeon.sprites.ItemSprite;
import com.github.artemdevel.pixeldungeon.sprites.ItemSpriteSheet;
import com.github.artemdevel.pixeldungeon.ui.Archs;
import com.github.artemdevel.pixeldungeon.ui.Arches;
import com.github.artemdevel.pixeldungeon.ui.ExitButton;
import com.github.artemdevel.pixeldungeon.ui.Icons;
import com.github.artemdevel.pixeldungeon.ui.Window;
Expand All @@ -53,7 +53,7 @@ public class RankingsScene extends PixelScene {

private static final float GAP = 4;

private Archs archs;
private Arches archs;

@Override
public void create() {
Expand All @@ -67,7 +67,7 @@ public void create() {
int w = Camera.main.width;
int h = Camera.main.height;

archs = new Archs();
archs = new Arches();
archs.setSize(w, h);
add(archs);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import com.github.artemdevel.pixeldungeon.effects.BannerSprites;
import com.github.artemdevel.pixeldungeon.effects.Speck;
import com.github.artemdevel.pixeldungeon.effects.BannerSprites.Type;
import com.github.artemdevel.pixeldungeon.ui.Archs;
import com.github.artemdevel.pixeldungeon.ui.Arches;
import com.github.artemdevel.pixeldungeon.ui.ExitButton;
import com.github.artemdevel.pixeldungeon.ui.Icons;
import com.github.artemdevel.pixeldungeon.ui.RedButton;
Expand Down Expand Up @@ -112,7 +112,7 @@ public void create() {
float top = (h - height) / 2;
float bottom = h - top;

Archs archs = new Archs();
Arches archs = new Arches();
archs.setSize(w, h);
add(archs);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import com.github.artemdevel.pixeldungeon.Badges;
import com.github.artemdevel.pixeldungeon.Dungeon;
import com.github.artemdevel.pixeldungeon.actors.hero.HeroClass;
import com.github.artemdevel.pixeldungeon.ui.Archs;
import com.github.artemdevel.pixeldungeon.ui.Arches;
import com.github.artemdevel.pixeldungeon.ui.RedButton;
import com.github.artemdevel.pixeldungeon.game.utils.Point;
import com.github.artemdevel.pixeldungeon.game.utils.Random;
Expand Down Expand Up @@ -75,7 +75,7 @@ public void create() {
int w = Camera.main.width;
int h = Camera.main.height;

Archs archs = new Archs();
Arches archs = new Arches();
archs.reversed = true;
archs.setSize(w, h);
add(archs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import com.github.artemdevel.pixeldungeon.PixelDungeon;
import com.github.artemdevel.pixeldungeon.effects.BannerSprites;
import com.github.artemdevel.pixeldungeon.effects.Fireball;
import com.github.artemdevel.pixeldungeon.ui.Archs;
import com.github.artemdevel.pixeldungeon.ui.Arches;
import com.github.artemdevel.pixeldungeon.ui.ExitButton;
import com.github.artemdevel.pixeldungeon.ui.PrefsButton;

Expand All @@ -55,15 +55,14 @@ public void create() {
int w = Camera.main.width;
int h = Camera.main.height;

Archs archs = new Archs();
Arches archs = new Arches();
archs.setSize(w, h);
add(archs);

Image title = BannerSprites.get(BannerSprites.Type.PIXEL_DUNGEON);
add(title);

float height = title.height +
(PixelDungeon.landscape() ? DashboardItem.SIZE : DashboardItem.SIZE * 2);
float height = title.height + (PixelDungeon.landscape() ? DashboardItem.SIZE : DashboardItem.SIZE * 2);

title.x = (w - title.width()) / 2;
title.y = (h - height) / 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.github.artemdevel.pixeldungeon.game.common.ui.Component;
import com.github.artemdevel.pixeldungeon.Assets;

public class Archs extends Component {
public class Arches extends Component {

private static final float SCROLL_SPEED = 20f;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.github.artemdevel.pixeldungeon.ui.RedButton;
import com.github.artemdevel.pixeldungeon.ui.Toolbar;
import com.github.artemdevel.pixeldungeon.ui.Window;
import com.github.artemdevel.pixeldungeon.utils.GLog;

public class WndSettings extends Window {

Expand Down Expand Up @@ -102,7 +103,7 @@ protected void onClick() {
@Override
protected void onClick() {
super.onClick();
PixelDungeon.immerse(checked());
GLog.logInfo("Immersive mode was disabled");
}
};
btnImmersive.setRect(0, btnScaleUp.bottom() + GAP, WIDTH, BTN_HEIGHT);
Expand Down

0 comments on commit 7e404ce

Please sign in to comment.