Remove unnecessary delete buttons in contact editor
- Don't offer the delete button until the user has typed something
into the field
Change-Id: I37585565b77f3d6a06677341191bb0f0cc72e508
diff --git a/res/layout/edit_date_picker.xml b/res/layout/edit_date_picker.xml
index ca5e281..c18d607 100644
--- a/res/layout/edit_date_picker.xml
+++ b/res/layout/edit_date_picker.xml
@@ -23,5 +23,6 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="@dimen/editor_field_left_padding"
+ android:layout_marginRight="@dimen/editor_field_right_padding"
android:textAppearance="?android:attr/textAppearanceMedium"
style="@android:style/Widget.Holo.Light.Spinner" />
\ No newline at end of file
diff --git a/res/layout/edit_field_list.xml b/res/layout/edit_field_list.xml
index ba715c7..f9e6565 100644
--- a/res/layout/edit_field_list.xml
+++ b/res/layout/edit_field_list.xml
@@ -23,4 +23,5 @@
android:layout_weight="1"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/editor_field_left_padding"
+ android:paddingRight="@dimen/editor_field_right_padding"
android:orientation="vertical" />
\ No newline at end of file
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 207a255..3bc1bc6 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -50,6 +50,9 @@
<!-- Left padding of a field in the Editor -->
<dimen name="editor_field_left_padding">5dip</dimen>
+ <!-- Right padding of a field in the Editor -->
+ <dimen name="editor_field_right_padding">5dip</dimen>
+
<!-- Top padding of a field in the Editor -->
<dimen name="editor_field_top_padding">10dip</dimen>
diff --git a/src/com/android/contacts/editor/EventFieldEditorView.java b/src/com/android/contacts/editor/EventFieldEditorView.java
index bf93d26..41d564a 100644
--- a/src/com/android/contacts/editor/EventFieldEditorView.java
+++ b/src/com/android/contacts/editor/EventFieldEditorView.java
@@ -106,6 +106,9 @@
String data = DateUtils.formatDate(getContext(), getEntry().getAsString(column));
if (TextUtils.isEmpty(data)) {
data = " ";
+ setDeleteButtonVisible(false);
+ } else {
+ setDeleteButtonVisible(true);
}
mDateView.setText(data);
}
diff --git a/src/com/android/contacts/editor/KindSectionView.java b/src/com/android/contacts/editor/KindSectionView.java
index b472279..8ca7a05 100644
--- a/src/com/android/contacts/editor/KindSectionView.java
+++ b/src/com/android/contacts/editor/KindSectionView.java
@@ -194,9 +194,9 @@
if (view instanceof Editor) {
Editor editor = (Editor) view;
+ editor.setDeletable(true);
editor.setValues(mKind, entry, mState, mReadOnly, mViewIdGenerator);
editor.setEditorListener(this);
- editor.setDeletable(true);
}
mEditors.addView(view);
return view;
diff --git a/src/com/android/contacts/editor/LabeledEditorView.java b/src/com/android/contacts/editor/LabeledEditorView.java
index af5ae65..ddecf5a 100644
--- a/src/com/android/contacts/editor/LabeledEditorView.java
+++ b/src/com/android/contacts/editor/LabeledEditorView.java
@@ -73,6 +73,7 @@
private EntityDelta mState;
private boolean mReadOnly;
private boolean mWasEmpty = true;
+ private boolean mIsDeletable = true;
private EditType mType;
@@ -185,8 +186,8 @@
/**
* Creates or removes the remove button. Doesn't do anything if already correctly configured
*/
- private void setupDeleteButton(boolean shouldExist) {
- if (shouldExist) {
+ private void setupDeleteButton() {
+ if (mIsDeletable) {
mDeleteContainer.setVisibility(View.VISIBLE);
mDelete.setEnabled(!mReadOnly && isEnabled());
} else {
@@ -194,6 +195,12 @@
}
}
+ public void setDeleteButtonVisible(boolean visible) {
+ if (mIsDeletable) {
+ mDeleteContainer.setVisibility(visible ? View.VISIBLE : View.GONE);
+ }
+ }
+
protected void onOptionalFieldVisibilityChange() {
if (mListener != null) {
mListener.onRequest(EditorListener.EDITOR_FORM_CHANGED);
@@ -207,7 +214,8 @@
@Override
public void setDeletable(boolean deletable) {
- setupDeleteButton(deletable);
+ mIsDeletable = deletable;
+ setupDeleteButton();
}
@Override
@@ -267,8 +275,10 @@
if (mWasEmpty != isEmpty) {
if (isEmpty) {
mListener.onRequest(EditorListener.FIELD_TURNED_EMPTY);
+ if (mIsDeletable) mDeleteContainer.setVisibility(View.GONE);
} else {
mListener.onRequest(EditorListener.FIELD_TURNED_NON_EMPTY);
+ if (mIsDeletable) mDeleteContainer.setVisibility(View.VISIBLE);
}
mWasEmpty = isEmpty;
}
diff --git a/src/com/android/contacts/editor/TextFieldsEditorView.java b/src/com/android/contacts/editor/TextFieldsEditorView.java
index a689a0c..ad1c7b6 100644
--- a/src/com/android/contacts/editor/TextFieldsEditorView.java
+++ b/src/com/android/contacts/editor/TextFieldsEditorView.java
@@ -195,6 +195,9 @@
final String value = entry.getAsString(column);
fieldView.setText(value);
+ // Show the delete button if we have a non-null value
+ setDeleteButtonVisible(value != null);
+
// Prepare listener for writing changes
fieldView.addTextChangedListener(new TextWatcher() {
@Override