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

Commit 9f4c8e9a authored by Romain Guy's avatar Romain Guy Committed by Android (Google) Code Review
Browse files

Merge "Resize AutoCompleteTextView's dropdown when the list content changes. Bug #2517711"

parents a5bd1221 6a678102
Loading
Loading
Loading
Loading
+31 −59
Original line number Original line Diff line number Diff line
@@ -18,6 +18,7 @@ package android.widget;


import android.content.Context;
import android.content.Context;
import android.content.res.TypedArray;
import android.content.res.TypedArray;
import android.database.DataSetObserver;
import android.graphics.Rect;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Drawable;
import android.text.Editable;
import android.text.Editable;
@@ -129,10 +130,11 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe


    private boolean mBlockCompletion;
    private boolean mBlockCompletion;


    private AutoCompleteTextView.ListSelectorHider mHideSelector;
    private ListSelectorHider mHideSelector;
    private Runnable mShowDropDownRunnable;
    private Runnable mShowDropDownRunnable;


    private AutoCompleteTextView.PassThroughClickListener mPassThroughClickListener;
    private PassThroughClickListener mPassThroughClickListener;
    private PopupDataSetObserver mObserver;


    public AutoCompleteTextView(Context context) {
    public AutoCompleteTextView(Context context) {
        this(context, null);
        this(context, null);
@@ -217,14 +219,6 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe
        }
        }
    }
    }


    /**
     * Sets this to be single line; a separate method so
     * MultiAutoCompleteTextView can skip this.
     */
    /* package */ void finishInit() {
        setSingleLine();
    }

    /**
    /**
     * <p>Sets the optional hint text that is displayed at the bottom of the
     * <p>Sets the optional hint text that is displayed at the bottom of the
     * the matching list.  This can be used as a cue to the user on how to
     * the matching list.  This can be used as a cue to the user on how to
@@ -590,10 +584,16 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe
     * @see android.widget.ListAdapter
     * @see android.widget.ListAdapter
     */
     */
    public <T extends ListAdapter & Filterable> void setAdapter(T adapter) {
    public <T extends ListAdapter & Filterable> void setAdapter(T adapter) {
        if (mObserver == null) {
            mObserver = new PopupDataSetObserver();
        } else if (mAdapter != null) {
            mAdapter.unregisterDataSetObserver(mObserver);
        }
        mAdapter = adapter;
        mAdapter = adapter;
        if (mAdapter != null) {
        if (mAdapter != null) {
            //noinspection unchecked
            //noinspection unchecked
            mFilter = ((Filterable) mAdapter).getFilter();
            mFilter = ((Filterable) mAdapter).getFilter();
            adapter.registerDataSetObserver(mObserver);
        } else {
        } else {
            mFilter = null;
            mFilter = null;
        }
        }
@@ -866,16 +866,6 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe
        return ListView.INVALID_POSITION;
        return ListView.INVALID_POSITION;
    }
    }



    /**
     * @hide
     * @return {@link android.widget.ListView#getChildCount()} of the drop down if it is showing,
     *         otherwise 0.
     */
    protected int getDropDownChildCount() {
        return mDropDownList == null ? 0 : mDropDownList.getChildCount();
    }

    /**
    /**
     * <p>Starts filtering the content of the drop down list. The filtering
     * <p>Starts filtering the content of the drop down list. The filtering
     * pattern is the content of the edit box. Subclasses should override this
     * pattern is the content of the edit box. Subclasses should override this
@@ -977,24 +967,6 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe
        }
        }
    }
    }


    /**
     * Like {@link #setTextKeepState(CharSequence)}, except that it can disable filtering.
     *
     * @param filter If <code>false</code>, no filtering will be performed
     *        as a result of this call.
     * 
     * @hide Pending API council approval.
     */
    public void setTextKeepState(CharSequence text, boolean filter) {
        if (filter) {
            setTextKeepState(text);
        } else {
            mBlockCompletion = true;
            setTextKeepState(text);
            mBlockCompletion = false;
        }
    }
    
    /**
    /**
     * <p>Performs the text completion by replacing the current text by the
     * <p>Performs the text completion by replacing the current text by the
     * selected item. Subclasses should override this method to avoid replacing
     * selected item. Subclasses should override this method to avoid replacing
@@ -1523,24 +1495,6 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe
            return view;
            return view;
        }
        }


        /**
         * <p>Returns the top padding of the currently selected view.</p>
         *
         * @return the height of the top padding for the selection
         */
        public int getSelectionPaddingTop() {
            return mSelectionTopPadding;
        }

        /**
         * <p>Returns the bottom padding of the currently selected view.</p>
         *
         * @return the height of the bottom padding for the selection
         */
        public int getSelectionPaddingBottom() {
            return mSelectionBottomPadding;
        }

        @Override
        @Override
        public boolean isInTouchMode() {
        public boolean isInTouchMode() {
            // WARNING: Please read the comment where mListSelectionHidden is declared
            // WARNING: Please read the comment where mListSelectionHidden is declared
@@ -1639,4 +1593,22 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe
        }
        }
    }
    }


    private class PopupDataSetObserver extends DataSetObserver {
        @Override
        public void onChanged() {
            if (isPopupShowing()) {
                // This will resize the popup to fit the new adapter's content
                showDropDown();
            }
        }

        @Override
        public void onInvalidated() {
            if (!mDropDownAlwaysVisible) {
                // There's no data to display so make sure we're not showing
                // the drop down and its list
                dismissDropDown();
            }
        }
    }
}
}