SDLEntryTestActivity.java.cmake 3.7 KB

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