diff -r 4feced261c68 -r de822cd3df3a project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/util/TextInputDialog.java --- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/util/TextInputDialog.java Tue Jan 21 22:38:13 2014 +0100 +++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/util/TextInputDialog.java Tue Jan 21 22:43:06 2014 +0100 @@ -36,113 +36,113 @@ * interface TextInputDialogListener, which will be called by the dialog if it is submitted or cancelled. */ public class TextInputDialog extends DialogFragment { - private static final String BUNDLE_DIALOG_ID = "dialogId"; - private static final String BUNDLE_TITLE_TEXT = "title"; - private static final String BUNDLE_MESSAGE_TEXT = "message"; - private static final String BUNDLE_HINT_TEXT = "hint"; - - private int dialogId, titleText, messageText, hintText; - private TextInputDialogListener listener; - - public interface TextInputDialogListener { - void onTextInputDialogSubmitted(int dialogId, String text); - void onTextInputDialogCancelled(int dialogId); - } - - /** - * The dialogId is only used for passing back to the callback on the activity, the - * other parameters are text resource IDs. Pass 0 for any of them to not use this - * text. - */ - public TextInputDialog(int dialogId, int titleText, int messageText, int hintText) { - this.dialogId = dialogId; - this.titleText = titleText; - this.messageText = messageText; - this.hintText = hintText; - } - - public TextInputDialog() { - // Only for reflection-based instantiation by the framework - } - - @Override - public void onAttach(Activity activity) { - super.onAttach(activity); - try { - listener = (TextInputDialogListener) activity; - } catch(ClassCastException e) { - throw new ClassCastException("Activity " + activity + " must implement TextInputDialogListener to use TextInputDialog."); - } - } - - @Override - public void onDetach() { - super.onDetach(); - listener = null; - } - - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - if(savedInstanceState != null) { - dialogId = savedInstanceState.getInt(BUNDLE_DIALOG_ID, dialogId); - titleText = savedInstanceState.getInt(BUNDLE_TITLE_TEXT, titleText); - messageText = savedInstanceState.getInt(BUNDLE_MESSAGE_TEXT, messageText); - hintText = savedInstanceState.getInt(BUNDLE_HINT_TEXT, hintText); - } - - final EditText editText = new EditText(getActivity()); - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); - - if(titleText != 0) { - builder.setTitle(titleText); - } - if(messageText != 0) { - builder.setTitle(messageText); - } - if(hintText != 0) { - editText.setHint(hintText); - } - - editText.setId(android.R.id.text1); - editText.setImeOptions(EditorInfo.IME_ACTION_DONE); - editText.setSingleLine(); + private static final String BUNDLE_DIALOG_ID = "dialogId"; + private static final String BUNDLE_TITLE_TEXT = "title"; + private static final String BUNDLE_MESSAGE_TEXT = "message"; + private static final String BUNDLE_HINT_TEXT = "hint"; + + private int dialogId, titleText, messageText, hintText; + private TextInputDialogListener listener; + + public interface TextInputDialogListener { + void onTextInputDialogSubmitted(int dialogId, String text); + void onTextInputDialogCancelled(int dialogId); + } + + /** + * The dialogId is only used for passing back to the callback on the activity, the + * other parameters are text resource IDs. Pass 0 for any of them to not use this + * text. + */ + public TextInputDialog(int dialogId, int titleText, int messageText, int hintText) { + this.dialogId = dialogId; + this.titleText = titleText; + this.messageText = messageText; + this.hintText = hintText; + } + + public TextInputDialog() { + // Only for reflection-based instantiation by the framework + } + + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + try { + listener = (TextInputDialogListener) activity; + } catch(ClassCastException e) { + throw new ClassCastException("Activity " + activity + " must implement TextInputDialogListener to use TextInputDialog."); + } + } + + @Override + public void onDetach() { + super.onDetach(); + listener = null; + } + + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + if(savedInstanceState != null) { + dialogId = savedInstanceState.getInt(BUNDLE_DIALOG_ID, dialogId); + titleText = savedInstanceState.getInt(BUNDLE_TITLE_TEXT, titleText); + messageText = savedInstanceState.getInt(BUNDLE_MESSAGE_TEXT, messageText); + hintText = savedInstanceState.getInt(BUNDLE_HINT_TEXT, hintText); + } - builder.setView(editText); - builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - dialog.cancel(); - } - }); - - editText.setOnEditorActionListener(new OnEditorActionListener() { - public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { - listener.onTextInputDialogSubmitted(dialogId, v.getText().toString()); - dismiss(); - return true; - } - }); - - builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - listener.onTextInputDialogSubmitted(dialogId, editText.getText().toString()); - } - }); + final EditText editText = new EditText(getActivity()); + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + + if(titleText != 0) { + builder.setTitle(titleText); + } + if(messageText != 0) { + builder.setTitle(messageText); + } + if(hintText != 0) { + editText.setHint(hintText); + } + + editText.setId(android.R.id.text1); + editText.setImeOptions(EditorInfo.IME_ACTION_DONE); + editText.setSingleLine(); + + builder.setView(editText); + builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + dialog.cancel(); + } + }); - return builder.create(); - } - - @Override - public void onSaveInstanceState(Bundle icicle) { - super.onSaveInstanceState(icicle); - icicle.putInt(BUNDLE_DIALOG_ID, dialogId); - icicle.putInt(BUNDLE_TITLE_TEXT, titleText); - icicle.putInt(BUNDLE_MESSAGE_TEXT, messageText); - icicle.putInt(BUNDLE_HINT_TEXT, hintText); - } - - @Override - public void onCancel(DialogInterface dialog) { - super.onCancel(dialog); - listener.onTextInputDialogCancelled(dialogId); - } + editText.setOnEditorActionListener(new OnEditorActionListener() { + public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { + listener.onTextInputDialogSubmitted(dialogId, v.getText().toString()); + dismiss(); + return true; + } + }); + + builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + listener.onTextInputDialogSubmitted(dialogId, editText.getText().toString()); + } + }); + + return builder.create(); + } + + @Override + public void onSaveInstanceState(Bundle icicle) { + super.onSaveInstanceState(icicle); + icicle.putInt(BUNDLE_DIALOG_ID, dialogId); + icicle.putInt(BUNDLE_TITLE_TEXT, titleText); + icicle.putInt(BUNDLE_MESSAGE_TEXT, messageText); + icicle.putInt(BUNDLE_HINT_TEXT, hintText); + } + + @Override + public void onCancel(DialogInterface dialog) { + super.onCancel(dialog); + listener.onTextInputDialogCancelled(dialogId); + } }