@@ -141,7 +141,7 @@ protected void onRestart() {
141141 }
142142 }
143143
144- private class HarnessFragment extends AndroidHarnessFragment
144+ public static class HarnessFragment extends AndroidHarnessFragment
145145 implements TouchListener , DialogInterface .OnClickListener {
146146
147147 private static final String ESCAPE_EVENT = "TouchEscape" ;
@@ -150,52 +150,59 @@ private class HarnessFragment extends AndroidHarnessFragment
150150 private ImageView splashImageView ;
151151 private boolean firstDrawFrame = true ;
152152
153+ private AndroidHarness harness () {
154+ return (AndroidHarness ) requireActivity ();
155+ }
156+
153157 @ Override
154158 protected LegacyApplication createApplication () throws Exception {
155- Class <?> clazz = Class .forName (appClass );
156- app = (LegacyApplication ) clazz .getDeclaredConstructor ().newInstance ();
157- return app ;
159+ AndroidHarness harness = harness ();
160+ Class <?> clazz = Class .forName (harness .appClass );
161+ harness .app = (LegacyApplication ) clazz .getDeclaredConstructor ().newInstance ();
162+ return harness .app ;
158163 }
159164
160165 @ Override
161166 protected AppSettings createSettings () {
162167 AppSettings settings = super .createSettings ();
163- settings .setAudioRenderer (audioRendererType );
168+ settings .setAudioRenderer (harness (). audioRendererType );
164169 return settings ;
165170 }
166171
167172 @ Override
168173 protected void configureSettings (AppSettings settings ) {
169- settings .setEmulateMouse (mouseEventsEnabled );
170- settings .setEmulateMouseFlipAxis (mouseEventsInvertX , mouseEventsInvertY );
171- settings .setUseJoysticks (joystickEventsEnabled );
172- settings .setEmulateKeyboard (keyEventsEnabled );
174+ AndroidHarness harness = harness ();
175+ settings .setEmulateMouse (harness .mouseEventsEnabled );
176+ settings .setEmulateMouseFlipAxis (harness .mouseEventsInvertX , harness .mouseEventsInvertY );
177+ settings .setUseJoysticks (harness .joystickEventsEnabled );
178+ settings .setEmulateKeyboard (harness .keyEventsEnabled );
173179
174- settings .setBitsPerPixel (eglBitsPerPixel );
175- settings .setAlphaBits (eglAlphaBits );
176- settings .setDepthBits (eglDepthBits );
177- settings .setSamples (eglSamples );
178- settings .setStencilBits (eglStencilBits );
179- settings .setFrameRate (frameRate );
180+ settings .setBitsPerPixel (harness . eglBitsPerPixel );
181+ settings .setAlphaBits (harness . eglAlphaBits );
182+ settings .setDepthBits (harness . eglDepthBits );
183+ settings .setSamples (harness . eglSamples );
184+ settings .setStencilBits (harness . eglStencilBits );
185+ settings .setFrameRate (harness . frameRate );
180186 }
181187
182188 @ Override
183189 public View onCreateView (android .view .LayoutInflater inflater ,
184190 ViewGroup container , Bundle savedInstanceState ) {
185191 View jmeView = super .onCreateView (inflater , container , savedInstanceState );
186- if (splashPicID == 0 || app == null ) {
192+ AndroidHarness harness = harness ();
193+ if (harness .splashPicID == 0 || harness .app == null ) {
187194 return jmeView ;
188195 }
189196
190- frameLayout = new FrameLayout (AndroidHarness . this );
197+ frameLayout = new FrameLayout (harness );
191198 frameLayout .addView (jmeView );
192199
193- splashImageView = new ImageView (AndroidHarness . this );
194- Drawable drawable = getResources ().getDrawable (splashPicID );
200+ splashImageView = new ImageView (harness );
201+ Drawable drawable = getResources ().getDrawable (harness . splashPicID );
195202 if (drawable instanceof NinePatchDrawable ) {
196203 splashImageView .setBackgroundDrawable (drawable );
197204 } else {
198- splashImageView .setImageResource (splashPicID );
205+ splashImageView .setImageResource (harness . splashPicID );
199206 }
200207
201208 FrameLayout .LayoutParams layoutParams = new FrameLayout .LayoutParams (
@@ -222,12 +229,13 @@ public void onDestroyView() {
222229 @ Override
223230 public void initialize () {
224231 super .initialize ();
225- if (handleExitHook ) {
226- if (app .getInputManager ().hasMapping (SimpleApplication .INPUT_MAPPING_EXIT )) {
227- app .getInputManager ().deleteMapping (SimpleApplication .INPUT_MAPPING_EXIT );
232+ AndroidHarness harness = harness ();
233+ if (harness .handleExitHook ) {
234+ if (harness .app .getInputManager ().hasMapping (SimpleApplication .INPUT_MAPPING_EXIT )) {
235+ harness .app .getInputManager ().deleteMapping (SimpleApplication .INPUT_MAPPING_EXIT );
228236 }
229- app .getInputManager ().addMapping (ESCAPE_EVENT , new TouchTrigger (TouchInput .KEYCODE_BACK ));
230- app .getInputManager ().addListener (this , new String []{ESCAPE_EVENT });
237+ harness . app .getInputManager ().addMapping (ESCAPE_EVENT , new TouchTrigger (TouchInput .KEYCODE_BACK ));
238+ harness . app .getInputManager ().addListener (this , new String []{ESCAPE_EVENT });
231239 }
232240 }
233241
@@ -243,12 +251,13 @@ public void update() {
243251 @ Override
244252 public void onTouch (String name , TouchEvent event , float tpf ) {
245253 if (ESCAPE_EVENT .equals (name ) && event .getType () == TouchEvent .Type .KEY_UP ) {
246- runOnUiThread (new Runnable () {
254+ harness (). runOnUiThread (new Runnable () {
247255 @ Override
248256 public void run () {
249- new AlertDialog .Builder (AndroidHarness .this )
250- .setTitle (exitDialogTitle )
251- .setMessage (exitDialogMessage )
257+ AndroidHarness harness = harness ();
258+ new AlertDialog .Builder (harness )
259+ .setTitle (harness .exitDialogTitle )
260+ .setMessage (harness .exitDialogMessage )
252261 .setPositiveButton ("Yes" , HarnessFragment .this )
253262 .setNegativeButton ("No" , HarnessFragment .this )
254263 .create ()
@@ -261,17 +270,18 @@ public void run() {
261270 @ Override
262271 public void onClick (DialogInterface dialog , int whichButton ) {
263272 if (whichButton != DialogInterface .BUTTON_NEGATIVE ) {
264- if (app != null ) {
265- app .stop (true );
273+ AndroidHarness harness = harness ();
274+ if (harness .app != null ) {
275+ harness .app .stop (true );
266276 }
267- app = null ;
268- finish ();
277+ harness . app = null ;
278+ harness . finish ();
269279 }
270280 }
271281
272282 private void removeSplashScreen () {
273283 if (splashImageView != null && frameLayout != null ) {
274- runOnUiThread (new Runnable () {
284+ harness (). runOnUiThread (new Runnable () {
275285 @ Override
276286 public void run () {
277287 splashImageView .setVisibility (View .INVISIBLE );
0 commit comments