The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

a/android: Make MonadoView fullscreen.

+67 -1
+67 -1
src/xrt/auxiliary/android/src/main/java/org/freedesktop/monado/auxiliary/MonadoView.java
··· 13 13 import android.util.Log; 14 14 import android.view.SurfaceHolder; 15 15 import android.view.SurfaceView; 16 + import android.view.View; 16 17 import android.view.WindowManager; 17 18 18 19 import androidx.annotation.Keep; 19 20 import androidx.annotation.NonNull; 20 21 import androidx.annotation.Nullable; 21 22 23 + import java.lang.reflect.InvocationTargetException; 24 + import java.lang.reflect.Method; 22 25 import java.util.Calendar; 23 26 24 27 @Keep 25 28 public class MonadoView extends SurfaceView implements SurfaceHolder.Callback, SurfaceHolder.Callback2 { 26 29 private static final String TAG = "MonadoView"; 30 + @SuppressWarnings("deprecation") 31 + private static final int sysUiVisFlags = 0 32 + // Give us a stable view of content insets 33 + | View.SYSTEM_UI_FLAG_LAYOUT_STABLE 34 + // Be able to do fullscreen and hide navigation 35 + | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN 36 + | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION 37 + | View.SYSTEM_UI_FLAG_FULLSCREEN 38 + | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION 39 + // we want sticky immersive 40 + | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; 27 41 /// The activity we've connected to. 28 42 private final Activity activity; 29 43 30 44 /// Guards currentSurfaceHolder 31 45 private final Object currentSurfaceHolderSync = new Object(); 46 + private final Method viewSetSysUiVis; 32 47 public int width = -1; 33 48 public int height = -1; 34 49 public int format = -1; ··· 39 54 private MonadoView(Activity activity) { 40 55 super(activity); 41 56 this.activity = activity; 57 + Method method; 58 + try { 59 + method = activity.getWindow().getDecorView().getClass().getMethod("setSystemUiVisibility", int.class); 60 + } catch (NoSuchMethodException e) { 61 + // ok 62 + method = null; 63 + } 64 + viewSetSysUiVis = method; 42 65 } 43 66 44 67 /** ··· 49 72 */ 50 73 @NonNull 51 74 @Keep 75 + @SuppressWarnings("deprecation") 52 76 public static MonadoView attachToActivity(@NonNull final Activity activity) { 53 77 Log.i(TAG, "Starting to add a new surface!"); 54 78 ··· 56 80 57 81 activity.runOnUiThread(() -> { 58 82 Log.i(TAG, "Starting runOnUiThread"); 83 + activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 84 + 59 85 WindowManager windowManager = activity.getWindowManager(); 60 - windowManager.addView(view, new WindowManager.LayoutParams()); 86 + windowManager.addView(view, new WindowManager.LayoutParams(WindowManager.LayoutParams.FLAG_FULLSCREEN)); 87 + 61 88 view.requestFocus(); 62 89 SurfaceHolder surfaceHolder = view.getHolder(); 63 90 surfaceHolder.addCallback(view); ··· 100 127 return ret; 101 128 } 102 129 130 + private boolean makeFullscreen() { 131 + if (activity == null) { 132 + return false; 133 + } 134 + if (viewSetSysUiVis == null) { 135 + return false; 136 + } 137 + View decorView = activity.getWindow().getDecorView(); 138 + //! @todo implement with WindowInsetsController to ward off the stink of deprecation 139 + try { 140 + viewSetSysUiVis.invoke(decorView, sysUiVisFlags); 141 + } catch (IllegalAccessException e) { 142 + return false; 143 + } catch (InvocationTargetException e) { 144 + return false; 145 + } 146 + return true; 147 + } 148 + 149 + 150 + /** 151 + * Add a listener so that if our system UI display state doesn't include all we want, we re-apply. 152 + */ 153 + @SuppressWarnings("deprecation") 154 + private void setSystemUiVisChangeListener() { 155 + activity.getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(visibility -> { 156 + // If not fullscreen, fix it. 157 + if (0 == (visibility & View.SYSTEM_UI_FLAG_FULLSCREEN)) { 158 + makeFullscreen(); 159 + } 160 + }); 161 + 162 + } 163 + 103 164 @Override 104 165 public void surfaceCreated(@NonNull SurfaceHolder surfaceHolder) { 105 166 synchronized (currentSurfaceHolderSync) { ··· 107 168 currentSurfaceHolderSync.notifyAll(); 108 169 } 109 170 Log.i(TAG, "surfaceCreated: Got a surface holder!"); 171 + 172 + if (makeFullscreen()) { 173 + // If we could make it full screen, make it really stick. 174 + setSystemUiVisChangeListener(); 175 + } 110 176 } 111 177 112 178 @Override