From 305e3f25e0330e7bc958e7dcd15d0fb22741b49c Mon Sep 17 00:00:00 2001 From: "iwg..ic" Date: Tue, 12 Feb 2013 02:45:21 +0000 Subject: [PATCH] SDK: Updates to JME3 Tests for Android Template - Add Android menu for enabling/disabling mouse events and joystick events - Exclude some of the mobile directories in the template zip file - Extract the uif labels as resource strings - Disable OK button on main activity until a test case is selected git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10392 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../mobile/res/layout/test_chooser_layout.xml | 10 +- .../mobile/res/menu/optionsmenu.xml | 9 ++ .../mobile/res/values/strings.xml | 14 +++ .../tests/CustomArrayAdapter.java | 1 + .../com/jmonkeyengine/tests/MainActivity.java | 92 +++++++++++++++++-- .../com/jmonkeyengine/tests/TestsHarness.java | 7 ++ sdk/build.xml | 4 +- 7 files changed, 125 insertions(+), 12 deletions(-) create mode 100644 sdk/JME3TestsTemplateAndroid/mobile/res/menu/optionsmenu.xml diff --git a/sdk/JME3TestsTemplateAndroid/mobile/res/layout/test_chooser_layout.xml b/sdk/JME3TestsTemplateAndroid/mobile/res/layout/test_chooser_layout.xml index 5df242f3e..cfa8c309d 100644 --- a/sdk/JME3TestsTemplateAndroid/mobile/res/layout/test_chooser_layout.xml +++ b/sdk/JME3TestsTemplateAndroid/mobile/res/layout/test_chooser_layout.xml @@ -15,7 +15,7 @@ android:layout_marginTop="10dp" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" - android:text="Choose a demo to start:" + android:text="@string/strLblTitle" android:textSize="20sp" android:textColor="#000000" /> @@ -37,7 +37,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="10dp" - android:text="Find:" + android:text="@string/strLblFindTitle" android:textSize="20sp" android:textColor="#000000" /> @@ -48,7 +48,7 @@ android:layout_height="wrap_content" android:layout_weight="1" android:ems="10" - android:hint="Enter a Filter" + android:hint="@string/strTxtFilterHint" android:inputType="text" android:textSize="20sp" android:textColor="#000000" @@ -71,7 +71,7 @@ android:id="@+id/btnOK" android:layout_width="100dp" android:layout_height="wrap_content" - android:text="OK" + android:text="@string/strBtnOK" android:layout_marginRight="20dp" android:textSize="20sp" android:textColor="#000000" @@ -81,7 +81,7 @@ android:id="@+id/btnCancel" android:layout_width="100dp" android:layout_height="wrap_content" - android:text="Cancel" + android:text="@string/strBtnCancel" android:layout_marginLeft="20dp" android:textSize="20sp" android:textColor="#000000" diff --git a/sdk/JME3TestsTemplateAndroid/mobile/res/menu/optionsmenu.xml b/sdk/JME3TestsTemplateAndroid/mobile/res/menu/optionsmenu.xml new file mode 100644 index 000000000..ee09ea9be --- /dev/null +++ b/sdk/JME3TestsTemplateAndroid/mobile/res/menu/optionsmenu.xml @@ -0,0 +1,9 @@ + + + + + \ No newline at end of file diff --git a/sdk/JME3TestsTemplateAndroid/mobile/res/values/strings.xml b/sdk/JME3TestsTemplateAndroid/mobile/res/values/strings.xml index c95eae549..3927854c6 100644 --- a/sdk/JME3TestsTemplateAndroid/mobile/res/values/strings.xml +++ b/sdk/JME3TestsTemplateAndroid/mobile/res/values/strings.xml @@ -1,4 +1,18 @@ + jMonkeyEngine Test Applications + + + Choose a demo to start: + Find: + Enter a Filter + OK + Cancel + + + Enable Mouse Events + Disable Mouse Events + Enable Joystick Events + Disable Joystick Events diff --git a/sdk/JME3TestsTemplateAndroid/mobile/src/com/jmonkeyengine/tests/CustomArrayAdapter.java b/sdk/JME3TestsTemplateAndroid/mobile/src/com/jmonkeyengine/tests/CustomArrayAdapter.java index 72dc2556a..64134eb6f 100644 --- a/sdk/JME3TestsTemplateAndroid/mobile/src/com/jmonkeyengine/tests/CustomArrayAdapter.java +++ b/sdk/JME3TestsTemplateAndroid/mobile/src/com/jmonkeyengine/tests/CustomArrayAdapter.java @@ -49,6 +49,7 @@ public class CustomArrayAdapter extends ArrayAdapter { /** Setter for selected item position */ public void setSelectedPosition(int selectedPosition) { this.selectedPosition = selectedPosition; + Log.i(TAG, "Setting position to: " + this.selectedPosition); } /** Setter for selected item background color */ diff --git a/sdk/JME3TestsTemplateAndroid/mobile/src/com/jmonkeyengine/tests/MainActivity.java b/sdk/JME3TestsTemplateAndroid/mobile/src/com/jmonkeyengine/tests/MainActivity.java index 3609ce2f3..ca6a586f7 100644 --- a/sdk/JME3TestsTemplateAndroid/mobile/src/com/jmonkeyengine/tests/MainActivity.java +++ b/sdk/JME3TestsTemplateAndroid/mobile/src/com/jmonkeyengine/tests/MainActivity.java @@ -11,13 +11,15 @@ import android.os.Bundle; import android.text.Editable; import android.text.TextWatcher; import android.util.Log; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.ListView; -import android.widget.Toast; import com.jme3.app.Application; import dalvik.system.DexFile; import java.io.IOException; @@ -25,9 +27,7 @@ import java.util.ArrayList; import java.util.Enumeration; import java.util.List; -//TODO: Add settings menu items for MouseEvents, JoystickEvents, and device orientation //TODO: Create onscreen virtual keypad for triggering normal mapped keys used by test apps or modify test apps for touch with onscreen keypad -//TODO: Go through each test and see if any classes need to be added to the exclusions list /** * Main Activity started by the application. Users select different jME3 test @@ -51,6 +51,18 @@ public class MainActivity extends Activity implements OnItemClickListener, View. */ public static final String SELECTED_LIST_POSITION = "Selected_List_Position"; + /** + * Static String to pass the key for the setting for enabling mouse events to the + * savedInstanceState Bundle. + */ + public static final String ENABLE_MOUSE_EVENTS = "Enable_Mouse_Events"; + + /** + * Static String to pass the key for the setting for enabling joystick events to the + * savedInstanceState Bundle. + */ + public static final String ENABLE_JOYSTICK_EVENTS = "Enable_Joystick_Events"; + /* Fields to contain the current position and display contents of the spinner */ private int currentPosition = 0; private String currentSelection = ""; @@ -71,6 +83,10 @@ public class MainActivity extends Activity implements OnItemClickListener, View. /* Filter Edit Box */ EditText editFilterText; + /* Custom settings for the test app */ + private boolean enableMouseEvents = true; + private boolean enableJoystickEvents = false; + /** * Called when the activity is first created. @@ -86,6 +102,8 @@ public class MainActivity extends Activity implements OnItemClickListener, View. ); currentPosition = savedInstanceState.getInt(SELECTED_LIST_POSITION, 0); currentSelection = savedInstanceState.getString(SELECTED_APP_CLASS); + enableMouseEvents = savedInstanceState.getBoolean(ENABLE_MOUSE_EVENTS, true); + enableJoystickEvents = savedInstanceState.getBoolean(ENABLE_JOYSTICK_EVENTS, false); } @@ -192,6 +210,8 @@ public class MainActivity extends Activity implements OnItemClickListener, View. Log.i(TAG, "User selected OK for class: " + currentSelection); Intent intent = new Intent(this, TestsHarness.class); intent.putExtra(SELECTED_APP_CLASS, currentSelection); + intent.putExtra(ENABLE_MOUSE_EVENTS, enableMouseEvents); + intent.putExtra(ENABLE_JOYSTICK_EVENTS, enableJoystickEvents); startActivity(intent); } else if (view.equals(btnCancel)) { /* Exit */ @@ -250,14 +270,16 @@ public class MainActivity extends Activity implements OnItemClickListener, View. private void setSelection(int position) { if (position == -1) { - arrayAdapter.setSelectedPosition(0); + arrayAdapter.setSelectedPosition(-1); currentPosition = -1; currentSelection = ""; + btnOK.setEnabled(false); listClasses.invalidateViews(); } else { arrayAdapter.setSelectedPosition(position); currentPosition = position; currentSelection = arrayAdapter.getItem(position); + btnOK.setEnabled(true); listClasses.invalidateViews(); } } @@ -267,13 +289,17 @@ public class MainActivity extends Activity implements OnItemClickListener, View. super.onSaveInstanceState(savedInstanceState); Log.i(TAG, "Saving selections in onSaveInstanceState: " + "position: " + currentPosition + ", " - + "class: " + currentSelection + + "class: " + currentSelection + ", " + + "mouseEvents: " + enableMouseEvents + ", " + + "joystickEvents: " + enableJoystickEvents + ", " ); // Save current selections to the savedInstanceState. // This bundle will be passed to onCreate if the process is // killed and restarted. savedInstanceState.putString(SELECTED_APP_CLASS, currentSelection); savedInstanceState.putInt(SELECTED_LIST_POSITION, currentPosition); + savedInstanceState.putBoolean(ENABLE_MOUSE_EVENTS, enableMouseEvents); + savedInstanceState.putBoolean(ENABLE_JOYSTICK_EVENTS, enableJoystickEvents); } @Override @@ -294,8 +320,8 @@ public class MainActivity extends Activity implements OnItemClickListener, View. public void onTextChanged(CharSequence cs, int startPos, int beforePos, int count) { Log.i(TAG, "onTextChanged with cs: " + cs + ", startPos: " + startPos + ", beforePos: " + beforePos + ", count: " + count); -// setSelection(-1); arrayAdapter.getFilter().filter(cs.toString()); + setSelection(-1); } public void afterTextChanged(Editable edtbl) { @@ -307,4 +333,58 @@ public class MainActivity extends Activity implements OnItemClickListener, View. editFilterText.removeTextChangedListener(this); } + @Override + public boolean onCreateOptionsMenu(Menu menu) { + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.optionsmenu, menu); + + return true; +} + + @Override + public boolean onPrepareOptionsMenu (Menu menu) { + MenuItem item; + + item = menu.findItem(R.id.optionEnableMouseEvents); + if (item != null) { + Log.i(TAG, "Found EnableMouseEvents menu item"); + if (enableMouseEvents) { + item.setTitle(R.string.strOptionDisableMouseEventsTitle); + } else { + item.setTitle(R.string.strOptionEnableMouseEventsTitle); + } + } + + item = menu.findItem(R.id.optionEnableJoystickEvents); + if (item != null) { + Log.i(TAG, "Found EnableJoystickEvents menu item"); + if (enableJoystickEvents) { + item.setTitle(R.string.strOptionDisableJoystickEventsTitle); + } else { + item.setTitle(R.string.strOptionEnableJoystickEventsTitle); + } + } + + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.optionEnableMouseEvents: + enableMouseEvents = !enableMouseEvents; + Log.i(TAG, "enableMouseEvents set to: " + enableMouseEvents); + break; + case R.id.optionEnableJoystickEvents: + enableJoystickEvents = !enableJoystickEvents; + Log.i(TAG, "enableJoystickEvents set to: " + enableJoystickEvents); + break; + default: + return super.onOptionsItemSelected(item); + } + + return true; + + } + } diff --git a/sdk/JME3TestsTemplateAndroid/mobile/src/com/jmonkeyengine/tests/TestsHarness.java b/sdk/JME3TestsTemplateAndroid/mobile/src/com/jmonkeyengine/tests/TestsHarness.java index df2147482..f38fa102a 100644 --- a/sdk/JME3TestsTemplateAndroid/mobile/src/com/jmonkeyengine/tests/TestsHarness.java +++ b/sdk/JME3TestsTemplateAndroid/mobile/src/com/jmonkeyengine/tests/TestsHarness.java @@ -26,6 +26,8 @@ public class TestsHarness extends AndroidHarness{ // Enable verbose logging eglConfigVerboseLogging = false; // Choose screen orientation + // This test project also set the Activity to Landscape in the AndroidManifest.xml + // If you modify this, also modify AndroidManifest.xml screenOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; // Invert the MouseEvents X (default = true) mouseEventsInvertX = true; @@ -37,12 +39,17 @@ public class TestsHarness extends AndroidHarness{ joystickEventsEnabled = false; // Simulate mouse events with Android touch input (default = true) mouseEventsEnabled = true; + mouseEventsInvertX = false; + mouseEventsInvertY = false; + } @Override public void onCreate(Bundle savedInstanceState) { Intent intent = getIntent(); appClass = intent.getStringExtra(MainActivity.SELECTED_APP_CLASS); + mouseEventsEnabled = intent.getBooleanExtra(MainActivity.ENABLE_MOUSE_EVENTS, mouseEventsEnabled); + joystickEventsEnabled = intent.getBooleanExtra(MainActivity.ENABLE_JOYSTICK_EVENTS, joystickEventsEnabled); super.onCreate(savedInstanceState); } diff --git a/sdk/build.xml b/sdk/build.xml index 9750c6c83..20cb60877 100644 --- a/sdk/build.xml +++ b/sdk/build.xml @@ -63,8 +63,10 @@ - + + +