Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9f9d78e4 authored by Walter Jang's avatar Walter Jang
Browse files

Hide types on contact editors until associated field focused/clicked

Bug 19624274

Change-Id: I8add22fa23e395507fce60f177f4cf48bcc29191
parent 5a7a23bd
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -82,6 +82,9 @@ public class EventFieldEditorView extends LabeledEditorView {
        mDateView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!isTypeVisible()) {
                    showType();
                }
                showDialog(R.id.dialog_event_date_picker);
            }
        });
@@ -129,6 +132,9 @@ public class EventFieldEditorView extends LabeledEditorView {
            mDateView.setText(data);
            mDateView.setTextColor(mPrimaryTextColor);
            setDeleteButtonVisible(true);
            if (!isTypeVisible()) {
                showType();
            }
        }
    }

+4 −0
Original line number Diff line number Diff line
@@ -194,6 +194,10 @@ public class KindSectionView extends LinearLayout implements EditorListener {
                    layoutResId + " for MIME type " + mKind.mimeType +
                    " with error " + e.toString());
        }
        // Hide the types drop downs until the associated edit field is focused
        if (view instanceof LabeledEditorView) {
            ((LabeledEditorView) view).setHideTypeInitially(true);
        }

        view.setEnabled(isEnabled());

+32 −3
Original line number Diff line number Diff line
@@ -79,6 +79,8 @@ public abstract class LabeledEditorView extends LinearLayout implements Editor,
    private boolean mWasEmpty = true;
    private boolean mIsDeletable = true;
    private boolean mIsAttachedToWindow;
    private boolean mHideTypeInitially;
    private boolean mHasTypes;

    private EditType mType;

@@ -232,6 +234,30 @@ public abstract class LabeledEditorView extends LinearLayout implements Editor,
        }
    }

    /**
     * Whether to hide the type dropdown after values have been set.
     * By default the drop down is always displayed if there are types to display.
     */
    public void setHideTypeInitially(boolean hideTypeInitially) {
        mHideTypeInitially = hideTypeInitially;
    }

    /**
     * Whether the type drop down is visible.
     */
    public boolean isTypeVisible() {
        return mLabel == null ? false : mLabel.getVisibility() == View.VISIBLE;
    }

    /**
     * Makes the type drop down visible if it is not already so, and there are types to display.
     */
    public void showType() {
        if (mHasTypes && mLabel != null && mLabel.getVisibility() != View.VISIBLE) {
            mLabel.setVisibility(View.VISIBLE);
        }
    }

    protected void onOptionalFieldVisibilityChange() {
        if (mListener != null) {
            mListener.onRequest(EditorListener.EDITOR_FORM_CHANGED);
@@ -379,12 +405,15 @@ public abstract class LabeledEditorView extends LinearLayout implements Editor,
        setVisibility(View.VISIBLE);

        // Display label selector if multiple types available
        final boolean hasTypes = RawContactModifier.hasEditTypes(kind);
        setupLabelButton(hasTypes);
        mHasTypes = RawContactModifier.hasEditTypes(kind);
        setupLabelButton(mHasTypes);
        mLabel.setEnabled(!readOnly && isEnabled());
        if (hasTypes) {
        if (mHasTypes) {
            mType = RawContactModifier.getCurrentType(entry, kind);
            rebuildLabel();
            if (mHideTypeInitially) {
                mLabel.setVisibility(View.GONE);
            }
        }
    }

+10 −1
Original line number Diff line number Diff line
@@ -153,10 +153,14 @@ public class TextFieldsEditorView extends LabeledEditorView {
        public void onFocusChange(View v, boolean hasFocus) {
            // Check whether this field contains focus by calling findFocus() instead of
            // hasFocus(). The hasFocus() value is not necessarily up to date.
            setHintColorDark(TextFieldsEditorView.this.findFocus() != null);
            final boolean foundFocus = TextFieldsEditorView.this.findFocus() != null;
            setHintColorDark(foundFocus);
            if (getEditorListener() != null) {
                getEditorListener().onRequest(EditorListener.EDITOR_FOCUS_CHANGED);
            }
            if (foundFocus && !isTypeVisible()) {
                showType();
            }
            // Rebuild the label spinner using the new colors.
            rebuildLabel();
        }
@@ -266,6 +270,11 @@ public class TextFieldsEditorView extends LabeledEditorView {
            final String value = entry.getAsString(column);
            fieldView.setText(value);

            // Show the type drop down if we have a non-empty value.
            if (!isTypeVisible() && !TextUtils.isEmpty(value)) {
                showType();
            }

            // Show the delete button if we have a non-null value
            setDeleteButtonVisible(value != null);