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

Commit 5f51fd69 authored by Fabrice Di Meglio's avatar Fabrice Di Meglio Committed by Android (Google) Code Review
Browse files

Merge "Make Spinner widget RTL-aware (part 2)" into jb-mr2-dev

parents 8e440a6c f80ceed4
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -200,9 +200,7 @@ public abstract class AbsSpinner extends AdapterView<SpinnerAdapter> {
            if (view != null) {
                // Put in recycler for re-measuring and/or layout
                mRecycler.put(selectedPosition, view);
            }

            if (view != null) {
                if (view.getLayoutParams() == null) {
                    mBlockLayoutRequests = true;
                    view.setLayoutParams(generateDefaultLayoutParams());
+17 −12
Original line number Diff line number Diff line
@@ -608,7 +608,7 @@ public class Spinner extends AbsSpinner implements OnClickListener {
            handled = true;

            if (!mPopup.isShowing()) {
                mPopup.show();
                mPopup.show(getTextDirection(), getTextAlignment());
            }
        }

@@ -719,7 +719,7 @@ public class Spinner extends AbsSpinner implements OnClickListener {
                    @Override
                    public void onGlobalLayout() {
                        if (!mPopup.isShowing()) {
                            mPopup.show();
                            mPopup.show(getTextDirection(), getTextAlignment());
                        }
                        final ViewTreeObserver vto = getViewTreeObserver();
                        if (vto != null) {
@@ -799,8 +799,7 @@ public class Spinner extends AbsSpinner implements OnClickListener {
        }

        public View getDropDownView(int position, View convertView, ViewGroup parent) {
            return mAdapter == null ? null :
                    mAdapter.getDropDownView(position, convertView, parent);
            return (mAdapter == null) ? null : mAdapter.getDropDownView(position, convertView, parent);
        }

        public boolean hasStableIds() {
@@ -868,7 +867,7 @@ public class Spinner extends AbsSpinner implements OnClickListener {
        /**
         * Show the popup
         */
        public void show();
        public void show(int textDirection, int textAlignment);

        /**
         * Dismiss the popup
@@ -922,13 +921,17 @@ public class Spinner extends AbsSpinner implements OnClickListener {
            return mPrompt;
        }

        public void show() {
        public void show(int textDirection, int textAlignment) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
            if (mPrompt != null) {
                builder.setTitle(mPrompt);
            }
            mPopup = builder.setSingleChoiceItems(mListAdapter,
                    getSelectedItemPosition(), this).show();
                    getSelectedItemPosition(), this).create();
            final ListView listView = mPopup.getListView();
            listView.setTextDirection(textDirection);
            listView.setTextAlignment(textAlignment);
            mPopup.show();
        }
        
        public void onClick(DialogInterface dialog, int which) {
@@ -1044,15 +1047,17 @@ public class Spinner extends AbsSpinner implements OnClickListener {
            setHorizontalOffset(hOffset);
        }

        @Override
        public void show() {
        public void show(int textDirection, int textAlignment) {
            final boolean wasShowing = isShowing();

            computeContentWidth();

            setInputMethodMode(ListPopupWindow.INPUT_METHOD_NOT_NEEDED);
            super.show();
            getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
            final ListView listView = getListView();
            listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
            listView.setTextDirection(textDirection);
            listView.setTextAlignment(textAlignment);
            setSelection(Spinner.this.getSelectedItemPosition());

            if (wasShowing) {
+48 −65
Original line number Diff line number Diff line
@@ -432,10 +432,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener

    private int mMarqueeRepeatLimit = 3;

    // The alignment to pass to Layout, or null if not resolved.
    private Layout.Alignment mLayoutAlignment;
    private int mResolvedTextAlignment;

    private int mLastLayoutDirection = -1;

    /**
@@ -2859,7 +2855,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener

        if (gravity != mGravity) {
            invalidate();
            mLayoutAlignment = null;
        }

        mGravity = gravity;
@@ -5805,68 +5800,56 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                      physicalWidth, false);
    }

    @Override
    public void onRtlPropertiesChanged(int layoutDirection) {
        if (mLayoutAlignment != null) {
            if (mResolvedTextAlignment == TEXT_ALIGNMENT_VIEW_START ||
                    mResolvedTextAlignment == TEXT_ALIGNMENT_VIEW_END) {
                mLayoutAlignment = null;
            }
        }
    }

    private Layout.Alignment getLayoutAlignment() {
        if (mLayoutAlignment == null) {
            mResolvedTextAlignment = getTextAlignment();
            switch (mResolvedTextAlignment) {
        Layout.Alignment alignment;
        switch (getTextAlignment()) {
            case TEXT_ALIGNMENT_GRAVITY:
                switch (mGravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) {
                    case Gravity.START:
                            mLayoutAlignment = Layout.Alignment.ALIGN_NORMAL;
                        alignment = Layout.Alignment.ALIGN_NORMAL;
                        break;
                    case Gravity.END:
                            mLayoutAlignment = Layout.Alignment.ALIGN_OPPOSITE;
                        alignment = Layout.Alignment.ALIGN_OPPOSITE;
                        break;
                    case Gravity.LEFT:
                            mLayoutAlignment = Layout.Alignment.ALIGN_LEFT;
                        alignment = Layout.Alignment.ALIGN_LEFT;
                        break;
                    case Gravity.RIGHT:
                            mLayoutAlignment = Layout.Alignment.ALIGN_RIGHT;
                        alignment = Layout.Alignment.ALIGN_RIGHT;
                        break;
                    case Gravity.CENTER_HORIZONTAL:
                            mLayoutAlignment = Layout.Alignment.ALIGN_CENTER;
                        alignment = Layout.Alignment.ALIGN_CENTER;
                        break;
                    default:
                            mLayoutAlignment = Layout.Alignment.ALIGN_NORMAL;
                        alignment = Layout.Alignment.ALIGN_NORMAL;
                        break;
                }
                break;
            case TEXT_ALIGNMENT_TEXT_START:
                    mLayoutAlignment = Layout.Alignment.ALIGN_NORMAL;
                alignment = Layout.Alignment.ALIGN_NORMAL;
                break;
            case TEXT_ALIGNMENT_TEXT_END:
                    mLayoutAlignment = Layout.Alignment.ALIGN_OPPOSITE;
                alignment = Layout.Alignment.ALIGN_OPPOSITE;
                break;
            case TEXT_ALIGNMENT_CENTER:
                    mLayoutAlignment = Layout.Alignment.ALIGN_CENTER;
                alignment = Layout.Alignment.ALIGN_CENTER;
                break;
            case TEXT_ALIGNMENT_VIEW_START:
                    mLayoutAlignment = (getLayoutDirection() == LAYOUT_DIRECTION_RTL) ?
                alignment = (getLayoutDirection() == LAYOUT_DIRECTION_RTL) ?
                        Layout.Alignment.ALIGN_RIGHT : Layout.Alignment.ALIGN_LEFT;
                break;
            case TEXT_ALIGNMENT_VIEW_END:
                    mLayoutAlignment = (getLayoutDirection() == LAYOUT_DIRECTION_RTL) ?
                alignment = (getLayoutDirection() == LAYOUT_DIRECTION_RTL) ?
                        Layout.Alignment.ALIGN_LEFT : Layout.Alignment.ALIGN_RIGHT;
                break;
            case TEXT_ALIGNMENT_INHERIT:
                // This should never happen as we have already resolved the text alignment
                // but better safe than sorry so we just fall through
            default:
                    mLayoutAlignment = Layout.Alignment.ALIGN_NORMAL;
                alignment = Layout.Alignment.ALIGN_NORMAL;
                break;
        }
        }
        return mLayoutAlignment;
        return alignment;
    }

    /**
+2 −1
Original line number Diff line number Diff line
@@ -23,4 +23,5 @@
    android:singleLine="true"
    android:layout_width="match_parent"
    android:layout_height="?android:attr/dropdownListPreferredItemHeight"
    android:ellipsize="marquee" />
    android:ellipsize="marquee"
    android:textAlignment="inherit"/>
+2 −1
Original line number Diff line number Diff line
@@ -23,4 +23,5 @@
    android:singleLine="true"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ellipsize="marquee" />
    android:ellipsize="marquee"
    android:textAlignment="inherit"/>