Delay the type value change until the custom value is correct.
Also make createCustomDialog() private, as
- This method is used only by createLableDialog()
- This method heavily depends on the state of private instances (mKind, mType),
so I thought external objects should not touch this method directly.
Internal issue number: 1752454
diff --git a/src/com/android/contacts/ui/widget/GenericEditorView.java b/src/com/android/contacts/ui/widget/GenericEditorView.java
index 4490fbf..53dd2e0 100644
--- a/src/com/android/contacts/ui/widget/GenericEditorView.java
+++ b/src/com/android/contacts/ui/widget/GenericEditorView.java
@@ -74,6 +74,8 @@
protected boolean mHideOptional = true;
protected EditType mType;
+ // Used only when a user tries to use custom label.
+ private EditType mPendingType;
public GenericEditorView(Context context) {
super(context);
@@ -221,7 +223,7 @@
* If the final value is empty, this change request is ignored;
* no empty text is allowed in any custom label.
*/
- public Dialog createCustomDialog() {
+ private Dialog createCustomDialog() {
final EditText customType = new EditText(mContext);
customType.setInputType(INPUT_TYPE_CUSTOM);
customType.requestFocus();
@@ -234,6 +236,10 @@
public void onClick(DialogInterface dialog, int which) {
final String customText = customType.getText().toString().trim();
if (!TextUtils.isEmpty(customText)) {
+ // Now we're sure it's ok to actually change the type value.
+ mType = mPendingType;
+ mPendingType = null;
+ mEntry.put(mKind.typeColumn, mType.rawValue);
mEntry.put(mType.customColumn, customText);
rebuildLabel();
}
@@ -274,18 +280,22 @@
}
};
- final DialogInterface.OnClickListener clickListener = new DialogInterface.OnClickListener() {
+ final DialogInterface.OnClickListener clickListener =
+ new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
- // User picked type, so write to entry
- mType = validTypes.get(which);
- mEntry.put(mKind.typeColumn, mType.rawValue);
-
if (mType.customColumn != null) {
- // Show custom label dialog if requested by type
+ // Show custom label dialog if requested by type.
+ //
+ // Only when the custum value input in the next step is correct one.
+ // this method also set the type value to what the user requested here.
+ mPendingType = validTypes.get(which);
createCustomDialog().show();
} else {
+ // User picked type, and we're sure it's ok to actually write the entry.
+ mType = validTypes.get(which);
+ mEntry.put(mKind.typeColumn, mType.rawValue);
rebuildLabel();
}
}