Android: Add getter method for NativeLibrary.sEmulationActivity

Also makes sEmulationActivity private.
This commit is contained in:
Stenzek 2019-01-22 22:44:30 +10:00
parent e9b02e7dd0
commit 82fd923a4e
3 changed files with 13 additions and 4 deletions

View File

@ -21,7 +21,16 @@ import java.lang.ref.WeakReference;
*/ */
public final class NativeLibrary public final class NativeLibrary
{ {
public static WeakReference<EmulationActivity> sEmulationActivity = new WeakReference<>(null); private static WeakReference<EmulationActivity> sEmulationActivity = new WeakReference<>(null);
/**
* Returns the current instance of EmulationActivity.
* There should only ever be one EmulationActivity instantiated.
*/
public static EmulationActivity getEmulationActivity()
{
return sEmulationActivity.get();
}
/** /**
* Button type for use in onTouchEvent * Button type for use in onTouchEvent

View File

@ -31,7 +31,7 @@ public class Java_GCAdapter
private static void RequestPermission() private static void RequestPermission()
{ {
Context context = NativeLibrary.sEmulationActivity.get(); Context context = NativeLibrary.getEmulationActivity();
if (context != null) if (context != null)
{ {
HashMap<String, UsbDevice> devices = manager.getDeviceList(); HashMap<String, UsbDevice> devices = manager.getDeviceList();
@ -141,7 +141,7 @@ public class Java_GCAdapter
} }
} }
final Activity emulationActivity = NativeLibrary.sEmulationActivity.get(); final Activity emulationActivity = NativeLibrary.getEmulationActivity();
if (emulationActivity != null) if (emulationActivity != null)
{ {
emulationActivity.runOnUiThread(() -> Toast.makeText(emulationActivity, emulationActivity.runOnUiThread(() -> Toast.makeText(emulationActivity,

View File

@ -34,7 +34,7 @@ public class Java_WiimoteAdapter
private static void RequestPermission() private static void RequestPermission()
{ {
Context context = NativeLibrary.sEmulationActivity.get(); Context context = NativeLibrary.getEmulationActivity();
if (context != null) if (context != null)
{ {
HashMap<String, UsbDevice> devices = manager.getDeviceList(); HashMap<String, UsbDevice> devices = manager.getDeviceList();