v0.6.1: added support for multi window mode and refactored ui flag system

This commit is contained in:
Evan Debenham 2017-07-23 16:31:20 -04:00 committed by Evan Debenham
parent b1f6c2dde3
commit 673ad28c5d
4 changed files with 41 additions and 35 deletions

View File

@ -145,8 +145,8 @@ public class Game extends Activity implements GLSurfaceView.Renderer, View.OnTou
} }
@Override @Override
public void onResume() { public void onStart() {
super.onResume(); super.onStart();
now = 0; now = 0;
view.onResume(); view.onResume();
@ -156,8 +156,8 @@ public class Game extends Activity implements GLSurfaceView.Renderer, View.OnTou
} }
@Override @Override
public void onPause() { public void onStop() {
super.onPause(); super.onStop();
if (scene != null) { if (scene != null) {
scene.pause(); scene.pause();

View File

@ -9,7 +9,7 @@
<uses-sdk <uses-sdk
android:minSdkVersion="8" android:minSdkVersion="8"
android:targetSdkVersion="25"/> android:targetSdkVersion="26"/>
<uses-feature <uses-feature
android:glEsVersion="0x00020000"/> android:glEsVersion="0x00020000"/>
@ -25,12 +25,12 @@
<application <application
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" android:theme="@android:style/Theme.Black.NoTitleBar"
android:allowBackup="false"> android:allowBackup="false">
<activity <activity
android:label="@string/app_name" android:label="@string/app_name"
android:name=".ShatteredPixelDungeon" android:name=".ShatteredPixelDungeon"
android:configChanges="keyboardHidden|orientation|screenSize" android:configChanges="keyboardHidden|orientation|screenSize|smallestScreenSize|screenLayout"
android:screenOrientation="nosensor"> android:screenOrientation="nosensor">
<intent-filter > <intent-filter >
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
@ -39,4 +39,4 @@
</activity> </activity>
</application> </application>
</manifest> </manifest>

View File

@ -27,6 +27,7 @@ import android.os.Bundle;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import android.view.WindowManager;
import com.shatteredpixel.shatteredpixeldungeon.messages.Languages; import com.shatteredpixel.shatteredpixeldungeon.messages.Languages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
@ -93,7 +94,7 @@ public class ShatteredPixelDungeon extends Game {
protected void onCreate( Bundle savedInstanceState ) { protected void onCreate( Bundle savedInstanceState ) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
updateImmersiveMode(); updateSystemUI();
if (Preferences.INSTANCE.contains( Preferences.KEY_LANDSCAPE )){ if (Preferences.INSTANCE.contains( Preferences.KEY_LANDSCAPE )){
landscape ( Preferences.INSTANCE.getBoolean( Preferences.KEY_LANDSCAPE, false)); landscape ( Preferences.INSTANCE.getBoolean( Preferences.KEY_LANDSCAPE, false));
@ -172,12 +173,14 @@ public class ShatteredPixelDungeon extends Game {
@Override @Override
public void onWindowFocusChanged( boolean hasFocus ) { public void onWindowFocusChanged( boolean hasFocus ) {
super.onWindowFocusChanged( hasFocus ); super.onWindowFocusChanged( hasFocus );
if (hasFocus) updateSystemUI();
}
if (hasFocus) { @Override
updateImmersiveMode(); public void onMultiWindowModeChanged(boolean isInMultiWindowMode) {
} super.onMultiWindowModeChanged(isInMultiWindowMode);
updateSystemUI();
} }
public static void switchNoFade(Class<? extends PixelScene> c){ public static void switchNoFade(Class<? extends PixelScene> c){
@ -223,8 +226,7 @@ public class ShatteredPixelDungeon extends Game {
instance.runOnUiThread( new Runnable() { instance.runOnUiThread( new Runnable() {
@Override @Override
public void run() { public void run() {
updateImmersiveMode(); updateSystemUI();
immersiveModeChanged = true;
//ensures surfacechanged is called if the view was previously set to be fixed. //ensures surfacechanged is called if the view was previously set to be fixed.
((ShatteredPixelDungeon)instance).view.getHolder().setSizeFromLayout(); ((ShatteredPixelDungeon)instance).view.getHolder().setSizeFromLayout();
} }
@ -238,10 +240,6 @@ public class ShatteredPixelDungeon extends Game {
updateDisplaySize(); updateDisplaySize();
if (immersiveModeChanged) {
requestedReset = true;
immersiveModeChanged = false;
}
} }
private void updateDisplaySize(){ private void updateDisplaySize(){
@ -295,24 +293,32 @@ public class ShatteredPixelDungeon extends Game {
} }
} }
public static void updateImmersiveMode() { public static void updateSystemUI() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
try { boolean fullscreen = Build.VERSION.SDK_INT < Build.VERSION_CODES.N
// Sometime NullPointerException happens here || !instance.isInMultiWindowMode();
if (fullscreen){
instance.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
} else {
instance.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){
if (fullscreen && immersed()) {
instance.getWindow().getDecorView().setSystemUiVisibility( instance.getWindow().getDecorView().setSystemUiVisibility(
immersed() ? View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION );
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | } else {
View.SYSTEM_UI_FLAG_FULLSCREEN | instance.getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY View.SYSTEM_UI_FLAG_LAYOUT_STABLE );
:
0 );
} catch (Exception e) {
reportException( e );
} }
} }
} }
public static boolean immersed() { public static boolean immersed() {

View File

@ -204,7 +204,7 @@ public class WndTextInput extends Window {
imm.hideSoftInputFromWindow(textInput.getWindowToken(), 0); imm.hideSoftInputFromWindow(textInput.getWindowToken(), 0);
//Soft keyboard sometimes triggers software buttons, so make sure to reassert immersive //Soft keyboard sometimes triggers software buttons, so make sure to reassert immersive
ShatteredPixelDungeon.updateImmersiveMode(); ShatteredPixelDungeon.updateSystemUI();
textInput = null; textInput = null;
} }