Don't save empty quick responses; show keyboard on phone
While creating or editing a quick response, disables the save button when the edit text is empty. Also, now shows the keyboard on the phone as soon as the dialog box pops up to edit/create a quick response. Bug: 5011277 Change-Id: I9926d07cae0e527a7c08a4cc556a9569a91d2f33
This commit is contained in:
parent
04bd9aa8b3
commit
7920f5809c
@ -28,15 +28,19 @@ import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.EditText;
|
||||
|
||||
/**
|
||||
* Dialog to edit the text of a given or new quick response
|
||||
*/
|
||||
public class EditQuickResponseDialog extends DialogFragment
|
||||
implements DialogInterface.OnClickListener {
|
||||
implements DialogInterface.OnClickListener, TextWatcher {
|
||||
private EditText mQuickResponseEditText;
|
||||
private QuickResponse mQuickResponse;
|
||||
private AlertDialog mDialog;
|
||||
|
||||
private static final String QUICK_RESPONSE_EDITED_STRING = "quick_response_edited_string";
|
||||
private static final String QUICK_RESPONSE = "quick_response";
|
||||
@ -66,11 +70,9 @@ public class EditQuickResponseDialog extends DialogFragment
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
final Context context = getActivity();
|
||||
final AlertDialog.Builder b = new AlertDialog.Builder(context);
|
||||
|
||||
mQuickResponseEditText = new EditText(context);
|
||||
mQuickResponse = (QuickResponse) getArguments().getParcelable(QUICK_RESPONSE);
|
||||
|
||||
mQuickResponseEditText = new EditText(context);
|
||||
if (savedInstanceState != null) {
|
||||
String quickResponseSavedString =
|
||||
savedInstanceState.getString(QUICK_RESPONSE_EDITED_STRING);
|
||||
@ -81,14 +83,41 @@ public class EditQuickResponseDialog extends DialogFragment
|
||||
mQuickResponseEditText.setText(mQuickResponse.toString());
|
||||
}
|
||||
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))
|
||||
.setView(mQuickResponseEditText)
|
||||
.setNegativeButton(R.string.cancel_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
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
|
Loading…
Reference in New Issue
Block a user