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

Commit efd0811a authored by Chris Yerga's avatar Chris Yerga
Browse files

Fix content width calculation for Spinner control.

The width of the dropdown was only taking into account
the width of the items and not background padding.

Change-Id: If27291c96191d4ac1f3e9200c6f6f585a19008c3
parent 717143ca
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.res.TypedArray;
import android.database.DataSetObserver;
import android.graphics.drawable.Drawable;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.Gravity;
@@ -632,6 +634,7 @@ public class Spinner extends AbsSpinner implements OnClickListener {
    private class DropdownPopup extends ListPopupWindow implements SpinnerPopup {
        private CharSequence mHintText;
        private int mPopupMaxWidth;
        private Rect mTempRect = new Rect();

        public DropdownPopup(Context context, AttributeSet attrs, int defStyleRes) {
            super(context, attrs, 0, defStyleRes);
@@ -699,6 +702,14 @@ public class Spinner extends AbsSpinner implements OnClickListener {
                itemView.measure(widthMeasureSpec, heightMeasureSpec);
                width = Math.max(width, itemView.getMeasuredWidth());
            }

            // Add background padding to measured width
            Drawable popupBackground = getBackground();
            if (popupBackground != null) {
                popupBackground.getPadding(mTempRect);
                width += mTempRect.left + mTempRect.right;
            }

            return width;
        }