using UnityEngine; namespace Unity.XR.XREAL { /// Interface for managing Android floating window operations. public interface IFloatingViewProxy { /// Creates native floating view object. /// AndroidJavaObject representing the view. AndroidJavaObject CreateFloatingView(); /// Displays the floating window. void Show(); /// Hides the floating window. void Hide(); /// Destroys the floating window resources. void DestroyFloatingView(); } /// Default implementation for XREAL floating window management. public class XREALDefaultFloatingViewProxy : IFloatingViewProxy { private AndroidJavaObject mJavaProxyObject; /// Initializes Android proxy with Unity activity context. public XREALDefaultFloatingViewProxy() { var clsUnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); var activity = clsUnityPlayer.GetStatic("currentActivity"); mJavaProxyObject = new AndroidJavaObject("ai.nreal.activitylife.NRDefaultFloatingViewProxy", activity); } /// Creates floating view through JNI. public AndroidJavaObject CreateFloatingView() { return mJavaProxyObject.Call("CreateFloatingView"); } /// Hides floating view via native call. public void Hide() { mJavaProxyObject.Call("Hide"); } /// Shows floating view via native call. public void Show() { mJavaProxyObject.Call("Show"); } /// Destroys floating view resources via native call. public void DestroyFloatingView() { mJavaProxyObject.Call("DestroyFloatingView"); } } /// Singleton manager for floating view lifecycle. public class XREALFloatingViewProvider : Singleton { /// Cached Java instance of floating view manager. protected AndroidJavaObject mJavaFloatingViewManager; /// Lazy-loaded Android floating manager singleton. protected AndroidJavaObject JavaFloatingViewManager { get { if (mJavaFloatingViewManager == null) { var cls = new AndroidJavaClass("ai.nreal.activitylife.FloatingManager"); mJavaFloatingViewManager = cls.CallStatic("getInstance"); } return mJavaFloatingViewManager; } } /// Proxy wrapper for C#/Java interop. protected class XREALFloatingViewProxyWrapper : AndroidJavaProxy { private IFloatingViewProxy mProxy; /// Get associated proxy instance. public IFloatingViewProxy FloatingViewProxy => mProxy; /// Initialize proxy bridge with implementation. /// Concrete proxy implementation. public XREALFloatingViewProxyWrapper(IFloatingViewProxy proxy) : base("ai.nreal.activitylife.IFloatingViewProxy") { mProxy = proxy; } /// Delegate create call to proxy. public AndroidJavaObject CreateFloatingView() { return mProxy?.CreateFloatingView(); } /// Delegate show call to proxy. public void Show() { mProxy?.Show(); } /// Delegate hide call to proxy. public void Hide() { mProxy?.Hide(); } /// Delegate destroy call to proxy. public void DestroyFloatingView() { mProxy?.DestroyFloatingView(); } } private XREALFloatingViewProxyWrapper mProxyWrapper = null; /// Register proxy implementation with Android system. /// Proxy implementation to register. public void RegisterFloatViewProxy(IFloatingViewProxy proxy) { mProxyWrapper = new XREALFloatingViewProxyWrapper(proxy); JavaFloatingViewManager.Call("setFloatingViewProxy", mProxyWrapper); } /// Get currently active proxy instance. /// Registered proxy or null. public IFloatingViewProxy GetCurrentFloatViewProxy() { return mProxyWrapper?.FloatingViewProxy; } } }