android: jni: Fix how we handle orientation changes.

- This previously broke Jave to C++ bindings.
This commit is contained in:
bunnei 2019-08-24 17:26:04 -04:00
parent 17558258a7
commit 48d3879ec5
6 changed files with 56 additions and 16 deletions

View File

@ -7,6 +7,8 @@
package org.citra.citra_android;
import android.app.AlertDialog;
import android.content.res.Configuration;
import android.preference.PreferenceManager;
import android.view.Surface;
import org.citra.citra_android.activities.EmulationActivity;
@ -276,6 +278,16 @@ public final class NativeLibrary {
*/
public static native void SwapScreens(boolean is_portrait_mode);
public static boolean isPortraitMode() {
return DolphinApplication.getAppContext().getResources().getConfiguration().orientation ==
Configuration.ORIENTATION_PORTRAIT;
}
public static int landscapeScreenLayout() {
return PreferenceManager.getDefaultSharedPreferences(DolphinApplication.getAppContext())
.getInt("LandscapeScreenLayout", EmulationActivity.LayoutOption_MobileLandscape);
}
public static boolean displayAlertMsg(final String caption, final String text,
final boolean yesNo) {
Log.error("[NativeLibrary] Alert: " + text);

View File

@ -335,12 +335,12 @@ public final class EmulationActivity extends AppCompatActivity {
}
// These must match what is defined in src/core/settings.h
private static final int LayoutOption_Default = 0;
private static final int LayoutOption_SingleScreen = 1;
private static final int LayoutOption_LargeScreen = 2;
private static final int LayoutOption_SideScreen = 3;
private static final int LayoutOption_MobilePortrait = 4;
private static final int LayoutOption_MobileLandscape = 5;
public static final int LayoutOption_Default = 0;
public static final int LayoutOption_SingleScreen = 1;
public static final int LayoutOption_LargeScreen = 2;
public static final int LayoutOption_SideScreen = 3;
public static final int LayoutOption_MobilePortrait = 4;
public static final int LayoutOption_MobileLandscape = 5;
@Override
public boolean onCreateOptionsMenu(Menu menu) {

View File

@ -328,15 +328,6 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener {
for (InputOverlayDrawableJoystick joystick : overlayJoysticks) {
joystick.draw(canvas);
}
// This is a convenient place to handle changes to orientation
HandleOrientationChange();
}
private void HandleOrientationChange() {
final int layoutOption = mPreferences.getInt("LandscapeScreenLayout", 5 /*LayoutOption_MobileLandscape*/);
final boolean isPortrait = getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
NativeLibrary.NotifyOrientationChange(layoutOption, isPortrait);
}
@Override

View File

@ -15,6 +15,7 @@
#include "input_common/main.h"
#include "input_common/motion_emu.h"
#include "jni/button_manager.h"
#include "jni/id_cache.h"
#include "jni/emu_window/emu_window.h"
#include "jni/ndk_helper/GLContext.h"
#include "network/network.h"
@ -35,11 +36,32 @@ void EmuWindow_Android::OnTouchMoved(int x, int y) {
TouchMoved((unsigned)std::max(x, 0), (unsigned)std::max(y, 0));
}
static bool IsPortraitMode()
{
JNIEnv* env = IDCache::GetEnvForThread();
// Execute the Java method.
jboolean result = env->CallStaticBooleanMethod(
IDCache::GetNativeLibraryClass(), IDCache::GetIsPortraitMode());
return result != JNI_FALSE;
}
static void UpdateLandscapeScreenLayout()
{
JNIEnv* env = IDCache::GetEnvForThread();
// Execute the Java method.
Settings::values.layout_option = static_cast<Settings::LayoutOption>(env->CallStaticIntMethod(
IDCache::GetNativeLibraryClass(), IDCache::GetLandscapeScreenLayout()));
}
void EmuWindow_Android::OnFramebufferSizeChanged() {
int width, height;
width = gl_context->GetScreenWidth();
height = gl_context->GetScreenHeight();
UpdateCurrentFramebufferLayout(width, height);
UpdateLandscapeScreenLayout();
UpdateCurrentFramebufferLayout(width, height, IsPortraitMode());
}
EmuWindow_Android::EmuWindow_Android(ANativeWindow* surface) {

View File

@ -17,6 +17,8 @@ static JavaVM* s_java_vm;
static jclass s_native_library_class;
static jmethodID s_display_alert_msg;
static jmethodID s_is_portrait_mode;
static jmethodID s_landscape_screen_layout;
namespace IDCache {
@ -47,6 +49,14 @@ jmethodID GetDisplayAlertMsg() {
return s_display_alert_msg;
}
jmethodID GetIsPortraitMode() {
return s_is_portrait_mode;
}
jmethodID GetLandscapeScreenLayout() {
return s_landscape_screen_layout;
}
} // namespace IDCache
#ifdef __cplusplus
@ -75,6 +85,9 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved) {
s_native_library_class = reinterpret_cast<jclass>(env->NewGlobalRef(native_library_class));
s_display_alert_msg = env->GetStaticMethodID(s_native_library_class, "displayAlertMsg",
"(Ljava/lang/String;Ljava/lang/String;Z)Z");
s_is_portrait_mode = env->GetStaticMethodID(s_native_library_class, "isPortraitMode", "()Z");
s_landscape_screen_layout =
env->GetStaticMethodID(s_native_library_class, "landscapeScreenLayout", "()I");
return JNI_VERSION;
}

View File

@ -11,5 +11,7 @@ namespace IDCache {
JNIEnv* GetEnvForThread();
jclass GetNativeLibraryClass();
jmethodID GetDisplayAlertMsg();
jmethodID GetIsPortraitMode();
jmethodID GetLandscapeScreenLayout();
} // namespace IDCache