Skip to content

Commit d93e758

Browse files
authored
Remove more deprecated android code and unify openal settings (#2776)
* cleanup android backend and normalize settings * set emulated input in every android example * remove legacy audio backend handling in android backend * add deprecation notices * refactor audio renderer handling and deprecate legacy methods
1 parent 7bd65d6 commit d93e758

18 files changed

Lines changed: 62 additions & 1514 deletions

File tree

jme3-android-examples/build.gradle

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,12 @@ tasks.register('runAndroidExamples', Exec) {
123123

124124
def exampleClass = project.findProperty('example')?.toString()?.trim()
125125
if (exampleClass) {
126+
def verboseLogging = project.findProperty('verboseLogging')?.toString()?.trim() ?: 'false'
127+
126128
args 'shell', 'am', 'start',
127129
'-n', 'org.jmonkeyengine.jme3androidexamples/.TestActivity',
128130
'--es', 'Selected_App_Class', exampleClass,
129-
'--ez', 'Enable_Mouse_Events', 'true',
130-
'--ez', 'Enable_Joystick_Events', 'false',
131-
'--ez', 'Enable_Key_Events', 'true',
132-
'--ez', 'Verbose_Logging', 'false'
131+
'--ez', 'Verbose_Logging', verboseLogging
133132
} else {
134133
args 'shell', 'am', 'start',
135134
'-n', 'org.jmonkeyengine.jme3androidexamples/.MainActivity'

jme3-android-examples/src/main/java/org/jmonkeyengine/jme3androidexamples/JmeFragment.java

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
*/
1313
public class JmeFragment extends AndroidHarnessFragment {
1414
private String appClass;
15-
private boolean joystickEventsEnabled;
16-
private boolean keyEventsEnabled = true;
17-
private boolean mouseEventsEnabled = true;
1815

1916
public JmeFragment() {
2017
finishOnAppStop = true;
@@ -27,13 +24,8 @@ public void onCreate(Bundle savedInstanceState) {
2724

2825
appClass = bundle.getString(MainActivity.SELECTED_APP_CLASS);
2926
// Log.d(this.getClass().getSimpleName(), "AppClass: " + appClass);
30-
joystickEventsEnabled = bundle.getBoolean(MainActivity.ENABLE_JOYSTICK_EVENTS);
31-
// Log.d(this.getClass().getSimpleName(), "JoystickEventsEnabled: " + joystickEventsEnabled);
32-
keyEventsEnabled = bundle.getBoolean(MainActivity.ENABLE_KEY_EVENTS);
33-
// Log.d(this.getClass().getSimpleName(), "KeyEventsEnabled: " + keyEventsEnabled);
34-
mouseEventsEnabled = bundle.getBoolean(MainActivity.ENABLE_MOUSE_EVENTS);
35-
// Log.d(this.getClass().getSimpleName(), "MouseEventsEnabled: " + mouseEventsEnabled);
36-
boolean verboseLogging = bundle.getBoolean(MainActivity.VERBOSE_LOGGING);
27+
boolean verboseLogging = bundle.getBoolean(MainActivity.VERBOSE_LOGGING,
28+
MainActivity.DEFAULT_VERBOSE_LOGGING);
3729
// Log.d(this.getClass().getSimpleName(), "VerboseLogging: " + verboseLogging);
3830
if (verboseLogging) {
3931
// Set the default logging level (default=Level.INFO, Level.ALL=All Debug Info)
@@ -49,21 +41,12 @@ public void onCreate(Bundle savedInstanceState) {
4941
@Override
5042
protected LegacyApplication createApplication() throws Exception {
5143
Class<?> clazz = Class.forName(appClass);
52-
return (LegacyApplication) clazz.getDeclaredConstructor().newInstance();
44+
LegacyApplication application = (LegacyApplication) clazz.getDeclaredConstructor().newInstance();
45+
AppSettings settings = new AppSettings(true);
46+
settings.setEmulateMouse(true);
47+
settings.setEmulateKeyboard(true);
48+
application.setSettings(settings);
49+
return application;
5350
}
5451

55-
@Override
56-
protected void configureSettings(AppSettings settings) {
57-
settings.setEmulateMouse(mouseEventsEnabled);
58-
settings.setUseJoysticks(joystickEventsEnabled);
59-
settings.setEmulateKeyboard(keyEventsEnabled);
60-
61-
settings.setBitsPerPixel(24);
62-
settings.setAlphaBits(0);
63-
settings.setGammaCorrection(true);
64-
settings.setDepthBits(16);
65-
settings.setSamples(4);
66-
settings.setStencilBits(0);
67-
settings.setFrameRate(-1);
68-
}
6952
}

jme3-android-examples/src/main/java/org/jmonkeyengine/jme3androidexamples/MainActivity.java

Lines changed: 4 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -48,29 +48,12 @@ public class MainActivity extends Activity implements OnItemClickListener, View.
4848
*/
4949
public static final String SELECTED_LIST_POSITION = "Selected_List_Position";
5050

51-
/**
52-
* Static String to pass the key for the setting for enabling mouse events to the
53-
* savedInstanceState Bundle.
54-
*/
55-
public static final String ENABLE_MOUSE_EVENTS = "Enable_Mouse_Events";
56-
57-
/**
58-
* Static String to pass the key for the setting for enabling joystick events to the
59-
* savedInstanceState Bundle.
60-
*/
61-
public static final String ENABLE_JOYSTICK_EVENTS = "Enable_Joystick_Events";
62-
63-
/**
64-
* Static String to pass the key for the setting for enabling key events to the
65-
* savedInstanceState Bundle.
66-
*/
67-
public static final String ENABLE_KEY_EVENTS = "Enable_Key_Events";
68-
6951
/**
7052
* Static String to pass the key for the setting for verbose logging to the
7153
* savedInstanceState Bundle.
7254
*/
7355
public static final String VERBOSE_LOGGING = "Verbose_Logging";
56+
public static final boolean DEFAULT_VERBOSE_LOGGING = false;
7457

7558
/* Fields to contain the current position and display contents of the spinner */
7659
private int currentPosition = 0;
@@ -93,10 +76,7 @@ public class MainActivity extends Activity implements OnItemClickListener, View.
9376
EditText editFilterText;
9477

9578
/* Custom settings for the test app */
96-
private boolean enableMouseEvents = true;
97-
private boolean enableJoystickEvents = false;
98-
private boolean enableKeyEvents = true;
99-
private boolean verboseLogging = false;
79+
private boolean verboseLogging = DEFAULT_VERBOSE_LOGGING;
10080

10181

10282
/**
@@ -113,10 +93,7 @@ public void onCreate(Bundle savedInstanceState) {
11393
);
11494
currentPosition = savedInstanceState.getInt(SELECTED_LIST_POSITION, 0);
11595
currentSelection = savedInstanceState.getString(SELECTED_APP_CLASS);
116-
enableMouseEvents = savedInstanceState.getBoolean(ENABLE_MOUSE_EVENTS, true);
117-
enableJoystickEvents = savedInstanceState.getBoolean(ENABLE_JOYSTICK_EVENTS, false);
118-
enableKeyEvents = savedInstanceState.getBoolean(ENABLE_KEY_EVENTS, true);
119-
verboseLogging = savedInstanceState.getBoolean(VERBOSE_LOGGING, true);
96+
verboseLogging = savedInstanceState.getBoolean(VERBOSE_LOGGING, DEFAULT_VERBOSE_LOGGING);
12097
}
12198

12299

@@ -224,25 +201,12 @@ public void onClick(View view) {
224201
/* Get selected class, pack it in the intent and start the test app */
225202
Log.d(TAG, "User selected OK for class: " + currentSelection);
226203
Intent intent = new Intent(this, TestActivity.class);
227-
// intent.putExtra(SELECTED_APP_CLASS, currentSelection);
228-
// intent.putExtra(ENABLE_MOUSE_EVENTS, enableMouseEvents);
229-
// intent.putExtra(ENABLE_JOYSTICK_EVENTS, enableJoystickEvents);
230-
// intent.putExtra(ENABLE_KEY_EVENTS, enableKeyEvents);
231204

232205
Bundle args = new Bundle();
233206

234207
args.putString(MainActivity.SELECTED_APP_CLASS, currentSelection);
235208
// Log.d(this.getClass().getSimpleName(), "AppClass="+currentSelection);
236209

237-
args.putBoolean(MainActivity.ENABLE_MOUSE_EVENTS, enableMouseEvents);
238-
// Log.d(TestActivity.class.getSimpleName(), "MouseEnabled="+enableMouseEvents);
239-
240-
args.putBoolean(MainActivity.ENABLE_JOYSTICK_EVENTS, enableJoystickEvents);
241-
// Log.d(TestActivity.class.getSimpleName(), "JoystickEnabled="+enableJoystickEvents);
242-
243-
args.putBoolean(MainActivity.ENABLE_KEY_EVENTS, enableKeyEvents);
244-
// Log.d(TestActivity.class.getSimpleName(), "KeyEnabled="+enableKeyEvents);
245-
246210
args.putBoolean(MainActivity.VERBOSE_LOGGING, verboseLogging);
247211
// Log.d(TestActivity.class.getSimpleName(), "VerboseLogging="+verboseLogging);
248212

@@ -329,19 +293,13 @@ public void onSaveInstanceState(Bundle savedInstanceState) {
329293
Log.d(TAG, "Saving selections in onSaveInstanceState: "
330294
+ "position: " + currentPosition + ", "
331295
+ "class: " + currentSelection + ", "
332-
+ "mouseEvents: " + enableMouseEvents + ", "
333-
+ "joystickEvents: " + enableJoystickEvents + ", "
334-
+ "keyEvents: " + enableKeyEvents + ", "
335296
+ "VerboseLogging: " + verboseLogging + ", "
336297
);
337298
// Save current selections to the savedInstanceState.
338299
// This bundle will be passed to onCreate if the process is
339300
// killed and restarted.
340301
savedInstanceState.putString(SELECTED_APP_CLASS, currentSelection);
341302
savedInstanceState.putInt(SELECTED_LIST_POSITION, currentPosition);
342-
savedInstanceState.putBoolean(ENABLE_MOUSE_EVENTS, enableMouseEvents);
343-
savedInstanceState.putBoolean(ENABLE_JOYSTICK_EVENTS, enableJoystickEvents);
344-
savedInstanceState.putBoolean(ENABLE_KEY_EVENTS, enableKeyEvents);
345303
savedInstanceState.putBoolean(VERBOSE_LOGGING, verboseLogging);
346304
}
347305

@@ -388,36 +346,6 @@ public boolean onCreateOptionsMenu(Menu menu) {
388346
public boolean onPrepareOptionsMenu (Menu menu) {
389347
MenuItem item;
390348

391-
item = menu.findItem(R.id.optionMouseEvents);
392-
if (item != null) {
393-
Log.d(TAG, "Found EnableMouseEvents menu item");
394-
if (enableMouseEvents) {
395-
item.setTitle(R.string.strOptionDisableMouseEventsTitle);
396-
} else {
397-
item.setTitle(R.string.strOptionEnableMouseEventsTitle);
398-
}
399-
}
400-
401-
item = menu.findItem(R.id.optionJoystickEvents);
402-
if (item != null) {
403-
Log.d(TAG, "Found EnableJoystickEvents menu item");
404-
if (enableJoystickEvents) {
405-
item.setTitle(R.string.strOptionDisableJoystickEventsTitle);
406-
} else {
407-
item.setTitle(R.string.strOptionEnableJoystickEventsTitle);
408-
}
409-
}
410-
411-
item = menu.findItem(R.id.optionKeyEvents);
412-
if (item != null) {
413-
Log.d(TAG, "Found EnableKeyEvents menu item");
414-
if (enableKeyEvents) {
415-
item.setTitle(R.string.strOptionDisableKeyEventsTitle);
416-
} else {
417-
item.setTitle(R.string.strOptionEnableKeyEventsTitle);
418-
}
419-
}
420-
421349
item = menu.findItem(R.id.optionVerboseLogging);
422350
if (item != null) {
423351
Log.d(TAG, "Found EnableVerboseLogging menu item");
@@ -434,16 +362,7 @@ public boolean onPrepareOptionsMenu (Menu menu) {
434362
@Override
435363
public boolean onOptionsItemSelected(MenuItem item) {
436364
int itemId = item.getItemId();
437-
if (itemId == R.id.optionMouseEvents) {
438-
enableMouseEvents = !enableMouseEvents;
439-
Log.d(TAG, "enableMouseEvents set to: " + enableMouseEvents);
440-
} else if (itemId == R.id.optionJoystickEvents) {
441-
enableJoystickEvents = !enableJoystickEvents;
442-
Log.d(TAG, "enableJoystickEvents set to: " + enableJoystickEvents);
443-
} else if (itemId == R.id.optionKeyEvents) {
444-
enableKeyEvents = !enableKeyEvents;
445-
Log.d(TAG, "enableKeyEvents set to: " + enableKeyEvents);
446-
} else if (itemId == R.id.optionVerboseLogging) {
365+
if (itemId == R.id.optionVerboseLogging) {
447366
verboseLogging = !verboseLogging;
448367
Log.d(TAG, "verboseLogging set to: " + verboseLogging);
449368
} else {

jme3-android-examples/src/main/java/org/jmonkeyengine/jme3androidexamples/TestActivity.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,8 @@ protected void onCreate(Bundle savedInstanceState) {
3030
args.putString(MainActivity.SELECTED_APP_CLASS, appClass);
3131
// Log.d(TestActivity.class.getSimpleName(), "AppClass="+appClass);
3232

33-
boolean mouseEnabled = bundle.getBoolean(MainActivity.ENABLE_MOUSE_EVENTS, true);
34-
args.putBoolean(MainActivity.ENABLE_MOUSE_EVENTS, mouseEnabled);
35-
// Log.d(TestActivity.class.getSimpleName(), "MouseEnabled="+mouseEnabled);
36-
37-
boolean joystickEnabled = bundle.getBoolean(MainActivity.ENABLE_JOYSTICK_EVENTS, true);
38-
args.putBoolean(MainActivity.ENABLE_JOYSTICK_EVENTS, joystickEnabled);
39-
// Log.d(TestActivity.class.getSimpleName(), "JoystickEnabled="+joystickEnabled);
40-
41-
boolean keyEnabled = bundle.getBoolean(MainActivity.ENABLE_KEY_EVENTS, true);
42-
args.putBoolean(MainActivity.ENABLE_KEY_EVENTS, keyEnabled);
43-
// Log.d(TestActivity.class.getSimpleName(), "KeyEnabled="+keyEnabled);
44-
45-
boolean verboseLogging = bundle.getBoolean(MainActivity.VERBOSE_LOGGING, true);
33+
boolean verboseLogging = bundle.getBoolean(MainActivity.VERBOSE_LOGGING,
34+
MainActivity.DEFAULT_VERBOSE_LOGGING);
4635
args.putBoolean(MainActivity.VERBOSE_LOGGING, verboseLogging);
4736
// Log.d(TestActivity.class.getSimpleName(), "VerboseLogging="+verboseLogging);
4837

jme3-android-examples/src/main/res/menu/menu_items.xml

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,6 @@
22
xmlns:tools="http://schemas.android.com/tools"
33
tools:context="org.jmonkeyengine.jme3androidexamples.MainActivity">
44

5-
<item
6-
android:id="@+id/optionMouseEvents"
7-
android:orderInCategory="100"
8-
android:title="@string/strOptionEnableMouseEventsTitle"
9-
android:showAsAction="never" />
10-
<item
11-
android:id="@+id/optionJoystickEvents"
12-
android:orderInCategory="200"
13-
android:title="@string/strOptionEnableJoystickEventsTitle"
14-
android:showAsAction="never" />
15-
<item
16-
android:id="@+id/optionKeyEvents"
17-
android:orderInCategory="300"
18-
android:title="@string/strOptionEnableKeyEventsTitle"
19-
android:showAsAction="never" />
20-
215
<item
226
android:id="@+id/optionVerboseLogging"
237
android:orderInCategory="300"

jme3-android-examples/src/main/res/values/strings.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@
1010
<string name="strBtnCancel">Cancel</string>
1111

1212
<!-- MainActivity Menu Labels -->
13-
<string name="strOptionEnableMouseEventsTitle">Enable Mouse Events</string>
14-
<string name="strOptionDisableMouseEventsTitle">Disable Mouse Events</string>
15-
<string name="strOptionEnableJoystickEventsTitle">Enable Joystick Events</string>
16-
<string name="strOptionDisableJoystickEventsTitle">Disable Joystick Events</string>
17-
<string name="strOptionEnableKeyEventsTitle">Enable Key Events</string>
18-
<string name="strOptionDisableKeyEventsTitle">Disable Key Events</string>
1913
<string name="strOptionEnableVerboseLoggingTitle">Enable Verbose Logging</string>
2014
<string name="strOptionDisableVerboseLoggingTitle">Disable Verbose Logging</string>
2115

jme3-android/src/main/java/com/jme3/app/AndroidHarnessFragment.java

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,7 @@ public void onCreate(Bundle savedInstanceState) {
9696

9797
try {
9898
app = createApplication();
99-
100-
AppSettings settings = createSettings();
101-
configureSettings(settings);
102-
app.setSettings(settings);
10399
app.start();
104-
105100
OGLESContext context = (OGLESContext) app.getContext();
106101
context.setSystemListener(this);
107102
} catch (Exception exception) {
@@ -117,25 +112,6 @@ public void onCreate(Bundle savedInstanceState) {
117112
*/
118113
protected abstract LegacyApplication createApplication() throws Exception;
119114

120-
/**
121-
* Creates the default Android settings. Subclasses can override this when
122-
* they need to replace the settings object rather than adjust it.
123-
*
124-
* @return default settings for Android
125-
*/
126-
protected AppSettings createSettings() {
127-
AppSettings settings = new AppSettings(true);
128-
settings.setAudioRenderer(AppSettings.ANDROID_OPENAL_SOFT);
129-
return settings;
130-
}
131-
132-
/**
133-
* Customizes the settings before the application starts.
134-
*
135-
* @param settings the settings to customize
136-
*/
137-
protected void configureSettings(AppSettings settings) {
138-
}
139115

140116
@Override
141117
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

jme3-android/src/main/java/com/jme3/system/android/JmeAndroidSystem.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
public class JmeAndroidSystem extends JmeSystemDelegate {
3333

3434
private static View view;
35-
private static String audioRendererType = AppSettings.ANDROID_OPENAL_SOFT;
3635

3736
static {
3837
try {
@@ -52,6 +51,18 @@ public JmeAndroidSystem(){
5251
});
5352
});
5453
}
54+
55+
/**
56+
* Returns the default Android audio renderer type.
57+
*
58+
* @return the default Android audio renderer type
59+
* @deprecated Use {@link AppSettings#getAudioRenderer()} and
60+
* {@link AppSettings#OPENAL} instead.
61+
*/
62+
@Deprecated
63+
public String getAudioRendererType() {
64+
return AppSettings.OPENAL;
65+
}
5566

5667
@Override
5768
public URL getPlatformAssetConfigURL() {
@@ -80,16 +91,6 @@ public void writeImageFile(OutputStream outStream, String format, ByteBuffer ima
8091
@Override
8192
@SuppressWarnings("deprecation")
8293
public JmeContext newContext(AppSettings settings, Type contextType) {
83-
if (settings.getAudioRenderer() == null) {
84-
audioRendererType = null;
85-
} else if (settings.getAudioRenderer().equals(AppSettings.ANDROID_MEDIAPLAYER)) {
86-
audioRendererType = AppSettings.ANDROID_MEDIAPLAYER;
87-
} else if (settings.getAudioRenderer().equals(AppSettings.ANDROID_OPENAL_SOFT)) {
88-
audioRendererType = AppSettings.ANDROID_OPENAL_SOFT;
89-
} else {
90-
logger.log(Level.INFO, "AudioRenderer not set. Defaulting to OpenAL Soft");
91-
audioRendererType = AppSettings.ANDROID_OPENAL_SOFT;
92-
}
9394
initialize(settings);
9495
JmeContext ctx = new OGLESContext();
9596
ctx.setSettings(settings);
@@ -207,10 +208,6 @@ public static View getView() {
207208
return view;
208209
}
209210

210-
public static String getAudioRendererType() {
211-
return audioRendererType;
212-
}
213-
214211
@Override
215212
public void showSoftKeyboard(final boolean show) {
216213
view.getHandler().post(new Runnable() {

0 commit comments

Comments
 (0)