Android: Improve handling of portrait mode
This commit is contained in:
parent
5cc91dc78b
commit
9b942de47e
|
@ -723,3 +723,10 @@ DEFINE_JNI_ARGS_METHOD(void, AndroidHostInterface_saveState, jobject obj, jboole
|
||||||
AndroidHostInterface* hi = AndroidHelpers::GetNativeClass(env, obj);
|
AndroidHostInterface* hi = AndroidHelpers::GetNativeClass(env, obj);
|
||||||
hi->RunOnEmulationThread([hi, global, slot]() { hi->SaveState(global, slot); });
|
hi->RunOnEmulationThread([hi, global, slot]() { hi->SaveState(global, slot); });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DEFINE_JNI_ARGS_METHOD(void, AndroidHostInterface_setDisplayAlignment, jobject obj, jint alignment)
|
||||||
|
{
|
||||||
|
AndroidHostInterface* hi = AndroidHelpers::GetNativeClass(env, obj);
|
||||||
|
hi->RunOnEmulationThread([hi, alignment]() { hi->GetDisplay()->SetDisplayAlignment(static_cast<HostDisplay::Alignment>(alignment)); });
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,8 @@
|
||||||
android:configChanges="orientation|keyboardHidden|screenSize"
|
android:configChanges="orientation|keyboardHidden|screenSize"
|
||||||
android:label="@string/title_activity_emulation"
|
android:label="@string/title_activity_emulation"
|
||||||
android:parentActivityName=".MainActivity"
|
android:parentActivityName=".MainActivity"
|
||||||
android:theme="@style/FullscreenTheme">
|
android:theme="@style/FullscreenTheme"
|
||||||
|
android:immersive="true">
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="android.support.PARENT_ACTIVITY"
|
android:name="android.support.PARENT_ACTIVITY"
|
||||||
android:value="com.github.stenzek.duckstation.MainActivity" />
|
android:value="com.github.stenzek.duckstation.MainActivity" />
|
||||||
|
|
|
@ -9,6 +9,10 @@ import android.widget.Toast;
|
||||||
import com.google.android.material.snackbar.Snackbar;
|
import com.google.android.material.snackbar.Snackbar;
|
||||||
|
|
||||||
public class AndroidHostInterface {
|
public class AndroidHostInterface {
|
||||||
|
public final static int DISPLAY_ALIGNMENT_TOP_OR_LEFT = 0;
|
||||||
|
public final static int DISPLAY_ALIGNMENT_CENTER = 1;
|
||||||
|
public final static int DISPLAY_ALIGNMENT_RIGHT_OR_BOTTOM = 2;
|
||||||
|
|
||||||
private long mNativePointer;
|
private long mNativePointer;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
|
||||||
|
@ -57,6 +61,8 @@ public class AndroidHostInterface {
|
||||||
|
|
||||||
public native void applySettings();
|
public native void applySettings();
|
||||||
|
|
||||||
|
public native void setDisplayAlignment(int alignment);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
System.loadLibrary("duckstation-native");
|
System.loadLibrary("duckstation-native");
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,12 +2,14 @@ package com.github.stenzek.duckstation;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.app.ActionBar;
|
import androidx.appcompat.app.ActionBar;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.res.Configuration;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
@ -102,6 +104,7 @@ public class EmulationActivity extends AppCompatActivity implements SurfaceHolde
|
||||||
// Once we get a surface, we can boot.
|
// Once we get a surface, we can boot.
|
||||||
if (AndroidHostInterface.getInstance().isEmulationThreadRunning()) {
|
if (AndroidHostInterface.getInstance().isEmulationThreadRunning()) {
|
||||||
AndroidHostInterface.getInstance().surfaceChanged(holder.getSurface(), format, width, height);
|
AndroidHostInterface.getInstance().surfaceChanged(holder.getSurface(), format, width, height);
|
||||||
|
updateOrientation();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,6 +113,7 @@ public class EmulationActivity extends AppCompatActivity implements SurfaceHolde
|
||||||
final String bootSaveStatePath = getIntent().getStringExtra("saveStatePath");
|
final String bootSaveStatePath = getIntent().getStringExtra("saveStatePath");
|
||||||
|
|
||||||
AndroidHostInterface.getInstance().startEmulationThread(this, holder.getSurface(), bootPath, resumeState, bootSaveStatePath);
|
AndroidHostInterface.getInstance().startEmulationThread(this, holder.getSurface(), bootPath, resumeState, bootSaveStatePath);
|
||||||
|
updateOrientation();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -227,6 +231,27 @@ public class EmulationActivity extends AppCompatActivity implements SurfaceHolde
|
||||||
showSystemUI();
|
showSystemUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onConfigurationChanged(@NonNull Configuration newConfig) {
|
||||||
|
super.onConfigurationChanged(newConfig);
|
||||||
|
updateOrientation(newConfig.orientation);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateOrientation() {
|
||||||
|
final int orientation = getResources().getConfiguration().orientation;
|
||||||
|
updateOrientation(orientation);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateOrientation(int newOrientation) {
|
||||||
|
if (!AndroidHostInterface.getInstance().isEmulationThreadRunning())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (newOrientation == Configuration.ORIENTATION_PORTRAIT)
|
||||||
|
AndroidHostInterface.getInstance().setDisplayAlignment(AndroidHostInterface.DISPLAY_ALIGNMENT_TOP_OR_LEFT);
|
||||||
|
else
|
||||||
|
AndroidHostInterface.getInstance().setDisplayAlignment(AndroidHostInterface.DISPLAY_ALIGNMENT_CENTER);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Some older devices needs a small delay between UI widget updates
|
* Some older devices needs a small delay between UI widget updates
|
||||||
* and a change of the status and navigation bar.
|
* and a change of the status and navigation bar.
|
||||||
|
|
Loading…
Reference in New Issue