Merge "Don't save empty quick responses; show keyboard on phone"

This commit is contained in:
Jorge Lugo 2011-07-15 15:20:48 -07:00 committed by Android (Google) Code Review
commit fad7378031

View File

@ -28,15 +28,19 @@ import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.WindowManager;
import android.widget.EditText; import android.widget.EditText;
/** /**
* Dialog to edit the text of a given or new quick response * Dialog to edit the text of a given or new quick response
*/ */
public class EditQuickResponseDialog extends DialogFragment public class EditQuickResponseDialog extends DialogFragment
implements DialogInterface.OnClickListener { implements DialogInterface.OnClickListener, TextWatcher {
private EditText mQuickResponseEditText; private EditText mQuickResponseEditText;
private QuickResponse mQuickResponse; private QuickResponse mQuickResponse;
private AlertDialog mDialog;
private static final String QUICK_RESPONSE_EDITED_STRING = "quick_response_edited_string"; private static final String QUICK_RESPONSE_EDITED_STRING = "quick_response_edited_string";
private static final String QUICK_RESPONSE = "quick_response"; private static final String QUICK_RESPONSE = "quick_response";
@ -66,11 +70,9 @@ public class EditQuickResponseDialog extends DialogFragment
@Override @Override
public Dialog onCreateDialog(Bundle savedInstanceState) { public Dialog onCreateDialog(Bundle savedInstanceState) {
final Context context = getActivity(); final Context context = getActivity();
final AlertDialog.Builder b = new AlertDialog.Builder(context);
mQuickResponseEditText = new EditText(context);
mQuickResponse = (QuickResponse) getArguments().getParcelable(QUICK_RESPONSE); mQuickResponse = (QuickResponse) getArguments().getParcelable(QUICK_RESPONSE);
mQuickResponseEditText = new EditText(context);
if (savedInstanceState != null) { if (savedInstanceState != null) {
String quickResponseSavedString = String quickResponseSavedString =
savedInstanceState.getString(QUICK_RESPONSE_EDITED_STRING); savedInstanceState.getString(QUICK_RESPONSE_EDITED_STRING);
@ -81,14 +83,41 @@ public class EditQuickResponseDialog extends DialogFragment
mQuickResponseEditText.setText(mQuickResponse.toString()); mQuickResponseEditText.setText(mQuickResponse.toString());
} }
mQuickResponseEditText.setSelection(mQuickResponseEditText.length()); mQuickResponseEditText.setSelection(mQuickResponseEditText.length());
mQuickResponseEditText.addTextChangedListener(this);
final AlertDialog.Builder b = new AlertDialog.Builder(context);
b.setTitle(getResources().getString(R.string.edit_quick_response_dialog)) b.setTitle(getResources().getString(R.string.edit_quick_response_dialog))
.setView(mQuickResponseEditText) .setView(mQuickResponseEditText)
.setNegativeButton(R.string.cancel_action, this) .setNegativeButton(R.string.cancel_action, this)
.setPositiveButton(R.string.save_action, this); .setPositiveButton(R.string.save_action, this);
return b.create(); mDialog = b.create();
return mDialog;
} }
@Override
public void onResume() {
super.onResume();
mDialog.getWindow()
.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
if (mQuickResponseEditText.length() == 0) {
mDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
}
}
// implements TextWatcher
@Override
public void afterTextChanged(Editable s) {
mDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(s.length() > 0);
}
// implements TextWatcher
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
// implements TextWatcher
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {}
// Saves contents during orientation change // Saves contents during orientation change
@Override @Override
public void onSaveInstanceState(Bundle outState) { public void onSaveInstanceState(Bundle outState) {