android: jni: Fix how we handle orientation changes.
- This previously broke Jave to C++ bindings.
This commit is contained in:
parent
487acf8821
commit
e9b3596f52
@ -7,6 +7,8 @@
|
|||||||
package org.citra.citra_android;
|
package org.citra.citra_android;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
|
import android.content.res.Configuration;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
import android.view.Surface;
|
import android.view.Surface;
|
||||||
|
|
||||||
import org.citra.citra_android.activities.EmulationActivity;
|
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 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,
|
public static boolean displayAlertMsg(final String caption, final String text,
|
||||||
final boolean yesNo) {
|
final boolean yesNo) {
|
||||||
Log.error("[NativeLibrary] Alert: " + text);
|
Log.error("[NativeLibrary] Alert: " + text);
|
||||||
|
@ -335,12 +335,12 @@ public final class EmulationActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// These must match what is defined in src/core/settings.h
|
// These must match what is defined in src/core/settings.h
|
||||||
private static final int LayoutOption_Default = 0;
|
public static final int LayoutOption_Default = 0;
|
||||||
private static final int LayoutOption_SingleScreen = 1;
|
public static final int LayoutOption_SingleScreen = 1;
|
||||||
private static final int LayoutOption_LargeScreen = 2;
|
public static final int LayoutOption_LargeScreen = 2;
|
||||||
private static final int LayoutOption_SideScreen = 3;
|
public static final int LayoutOption_SideScreen = 3;
|
||||||
private static final int LayoutOption_MobilePortrait = 4;
|
public static final int LayoutOption_MobilePortrait = 4;
|
||||||
private static final int LayoutOption_MobileLandscape = 5;
|
public static final int LayoutOption_MobileLandscape = 5;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
|
@ -328,15 +328,6 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener {
|
|||||||
for (InputOverlayDrawableJoystick joystick : overlayJoysticks) {
|
for (InputOverlayDrawableJoystick joystick : overlayJoysticks) {
|
||||||
joystick.draw(canvas);
|
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
|
@Override
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#include "input_common/main.h"
|
#include "input_common/main.h"
|
||||||
#include "input_common/motion_emu.h"
|
#include "input_common/motion_emu.h"
|
||||||
#include "jni/button_manager.h"
|
#include "jni/button_manager.h"
|
||||||
|
#include "jni/id_cache.h"
|
||||||
#include "jni/emu_window/emu_window.h"
|
#include "jni/emu_window/emu_window.h"
|
||||||
#include "jni/ndk_helper/GLContext.h"
|
#include "jni/ndk_helper/GLContext.h"
|
||||||
#include "network/network.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));
|
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() {
|
void EmuWindow_Android::OnFramebufferSizeChanged() {
|
||||||
int width, height;
|
int width, height;
|
||||||
width = gl_context->GetScreenWidth();
|
width = gl_context->GetScreenWidth();
|
||||||
height = gl_context->GetScreenHeight();
|
height = gl_context->GetScreenHeight();
|
||||||
UpdateCurrentFramebufferLayout(width, height);
|
UpdateLandscapeScreenLayout();
|
||||||
|
UpdateCurrentFramebufferLayout(width, height, IsPortraitMode());
|
||||||
}
|
}
|
||||||
|
|
||||||
EmuWindow_Android::EmuWindow_Android(ANativeWindow* surface) {
|
EmuWindow_Android::EmuWindow_Android(ANativeWindow* surface) {
|
||||||
|
@ -17,6 +17,8 @@ static JavaVM* s_java_vm;
|
|||||||
|
|
||||||
static jclass s_native_library_class;
|
static jclass s_native_library_class;
|
||||||
static jmethodID s_display_alert_msg;
|
static jmethodID s_display_alert_msg;
|
||||||
|
static jmethodID s_is_portrait_mode;
|
||||||
|
static jmethodID s_landscape_screen_layout;
|
||||||
|
|
||||||
namespace IDCache {
|
namespace IDCache {
|
||||||
|
|
||||||
@ -47,6 +49,14 @@ jmethodID GetDisplayAlertMsg() {
|
|||||||
return s_display_alert_msg;
|
return s_display_alert_msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jmethodID GetIsPortraitMode() {
|
||||||
|
return s_is_portrait_mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
jmethodID GetLandscapeScreenLayout() {
|
||||||
|
return s_landscape_screen_layout;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace IDCache
|
} // namespace IDCache
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#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_native_library_class = reinterpret_cast<jclass>(env->NewGlobalRef(native_library_class));
|
||||||
s_display_alert_msg = env->GetStaticMethodID(s_native_library_class, "displayAlertMsg",
|
s_display_alert_msg = env->GetStaticMethodID(s_native_library_class, "displayAlertMsg",
|
||||||
"(Ljava/lang/String;Ljava/lang/String;Z)Z");
|
"(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;
|
return JNI_VERSION;
|
||||||
}
|
}
|
||||||
|
@ -11,5 +11,7 @@ namespace IDCache {
|
|||||||
JNIEnv* GetEnvForThread();
|
JNIEnv* GetEnvForThread();
|
||||||
jclass GetNativeLibraryClass();
|
jclass GetNativeLibraryClass();
|
||||||
jmethodID GetDisplayAlertMsg();
|
jmethodID GetDisplayAlertMsg();
|
||||||
|
jmethodID GetIsPortraitMode();
|
||||||
|
jmethodID GetLandscapeScreenLayout();
|
||||||
|
|
||||||
} // namespace IDCache
|
} // namespace IDCache
|
||||||
|
Loading…
x
Reference in New Issue
Block a user