SDLEntryTestActivity.java.cmake 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package @ANDROID_MANIFEST_PACKAGE@;
  2. import android.app.Activity;
  3. import android.app.AlertDialog;
  4. import android.content.Context;
  5. import android.content.DialogInterface;
  6. import android.content.Intent;
  7. import android.os.Bundle;
  8. import android.util.Log;
  9. import org.libsdl.app.SDL;
  10. import org.libsdl.app.SDLActivity;
  11. import android.widget.Button;
  12. import android.widget.EditText;
  13. import android.widget.TextView;
  14. import android.view.View;
  15. import android.view.ViewGroup;
  16. import android.view.LayoutInflater;
  17. public class SDLEntryTestActivity extends Activity {
  18. public String MODIFY_ARGUMENTS = "@[email protected]_ARGUMENTS";
  19. boolean isModifyingArguments;
  20. @Override
  21. protected void onCreate(Bundle savedInstanceState) {
  22. Log.v("SDL", "SDLEntryTestActivity onCreate");
  23. super.onCreate(savedInstanceState);
  24. String intent_action = getIntent().getAction();
  25. Log.v("SDL", "SDLEntryTestActivity intent.action = " + intent_action);
  26. if (intent_action == MODIFY_ARGUMENTS) {
  27. isModifyingArguments = true;
  28. createArgumentLayout();
  29. } else {
  30. startChildActivityAndFinish();
  31. }
  32. }
  33. protected void createArgumentLayout() {
  34. LayoutInflater inflater = getLayoutInflater();
  35. View view = inflater.inflate(R.layout.arguments_layout, null);
  36. setContentView(view);
  37. Button button = (Button)requireViewById(R.id.arguments_start_button);
  38. button.setOnClickListener(new View.OnClickListener() {
  39. public void onClick(View v) {
  40. startChildActivityAndFinish();
  41. }
  42. });
  43. }
  44. protected String[] getArguments() {
  45. if (!isModifyingArguments) {
  46. return new String[0];
  47. }
  48. EditText editText = (EditText)findViewById(R.id.arguments_edit);
  49. String text = editText.getText().toString();
  50. String new_text = text.replace("[ \t]*[ \t\n]+[ \t]+", "\n").strip();
  51. Log.v("SDL", "text = " + text + "\n becomes \n" + new_text);
  52. return new_text.split("\n", 0);
  53. }
  54. @Override
  55. protected void onStart() {
  56. Log.v("SDL", "SDLEntryTestActivity onStart");
  57. super.onStart();
  58. }
  59. @Override
  60. protected void onResume() {
  61. Log.v("SDL", "SDLEntryTestActivity onResume");
  62. super.onResume();
  63. }
  64. @Override
  65. protected void onPause() {
  66. Log.v("SDL", "SDLEntryTestActivity onPause");
  67. super.onPause();
  68. }
  69. @Override
  70. protected void onStop() {
  71. Log.v("SDL", "SDLEntryTestActivity onStop");
  72. super.onStop();
  73. }
  74. @Override
  75. protected void onDestroy() {
  76. Log.v("SDL", "SDLEntryTestActivity onDestroy");
  77. super.onDestroy();
  78. }
  79. @Override
  80. protected void onRestoreInstanceState(Bundle savedInstanceState) {
  81. Log.v("SDL", "SDLEntryTestActivity onRestoreInstanceState");
  82. super.onRestoreInstanceState(savedInstanceState);
  83. EditText editText = (EditText)findViewById(R.id.arguments_edit);
  84. editText.setText(savedInstanceState.getCharSequence("args", ""), TextView.BufferType.EDITABLE);
  85. }
  86. @Override
  87. protected void onSaveInstanceState(Bundle outState) {
  88. Log.v("SDL", "SDLEntryTestActivity onSaveInstanceState");
  89. EditText editText = (EditText)findViewById(R.id.arguments_edit);
  90. outState.putCharSequence("args", editText.getText());
  91. super.onSaveInstanceState(outState);
  92. }
  93. private void startChildActivityAndFinish() {
  94. Intent intent = new Intent(Intent.ACTION_MAIN);
  95. intent.addCategory(Intent.CATEGORY_LAUNCHER);
  96. intent.setClassName("@ANDROID_MANIFEST_PACKAGE@", "@[email protected]");
  97. intent.putExtra("arguments", getArguments());
  98. startActivity(intent);
  99. finish();
  100. }
  101. }