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