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

Commit c0ffcc4e authored by Riley Jones's avatar Riley Jones Committed by Android (Google) Code Review
Browse files

Merge "Add RTL support for A11yMenu ViewPager." into main

parents d1b3cd33 44acf3b0
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ android_app {
        "androidx.coordinatorlayout_coordinatorlayout",
        "androidx.core_core",
        "androidx.preference_preference",
        "androidx.viewpager_viewpager",
        "androidx.viewpager2_viewpager2",
        "com_android_systemui_flags_lib",
        "SettingsLibDisplayUtils",
        "SettingsLibSettingsTheme",
+2 −2
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@
      android:orientation="horizontal">

    <ImageButton
        android:id="@+id/menu_prev_button"
        android:id="@+id/menu_left_button"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
@@ -38,7 +38,7 @@
        android:background="?android:attr/listDivider"/>

    <ImageButton
        android:id="@+id/menu_next_button"
        android:id="@+id/menu_right_button"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
+1 −1
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/gridview"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_height="match_parent"
    android:horizontalSpacing="@dimen/a11ymenu_grid_layout_margin"
    android:listSelector="@android:color/transparent"
    android:numColumns="3"
+2 −4
Original line number Diff line number Diff line
@@ -6,18 +6,16 @@
    android:background="@drawable/view_background"
    >
  <LinearLayout
      android:layout_width="@dimen/row_width"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical">

    <androidx.viewpager.widget.ViewPager
    <androidx.viewpager2.widget.ViewPager2
        android:id="@+id/view_pager"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="@dimen/table_margin_top"
        android:paddingBottom="@dimen/a11ymenu_layout_margin"
        android:paddingLeft="@dimen/a11ymenu_layout_margin"
        android:paddingRight="@dimen/a11ymenu_layout_margin"
        android:layout_gravity="center"
        android:gravity="center"
        />
+35 −16
Original line number Diff line number Diff line
@@ -16,7 +16,11 @@

package com.android.systemui.accessibility.accessibilitymenu.view;

import static android.view.View.LAYOUT_DIRECTION_LTR;

import android.content.res.Configuration;
import android.graphics.Rect;
import android.text.TextUtils;
import android.view.TouchDelegate;
import android.view.View;
import android.view.View.OnClickListener;
@@ -37,46 +41,61 @@ public class A11yMenuFooter {
    public interface A11yMenuFooterCallBack {

        /** Calls back when user clicks the left button. */
        void onLeftButtonClicked();
        void onNextButtonClicked();

        /** Calls back when user clicks the right button. */
        void onRightButtonClicked();
        void onPreviousButtonClicked();
    }

    private final FooterButtonClickListener mFooterButtonClickListener;

    private ImageButton mPreviousPageBtn;
    private ImageButton mNextPageBtn;
    private ImageButton mPageLeftBtn;
    private ImageButton mPageRightBtn;
    private View mTopListDivider;
    private View mBottomListDivider;
    private final A11yMenuFooterCallBack mCallBack;
    private final ViewGroup mMenuLayout;
    private int mRightToLeftDirection = LAYOUT_DIRECTION_LTR;

    public A11yMenuFooter(ViewGroup menuLayout, A11yMenuFooterCallBack callBack) {
        this.mCallBack = callBack;
        mFooterButtonClickListener = new FooterButtonClickListener();
        configureFooterLayout(menuLayout);
        mMenuLayout = menuLayout;
    }

    public @Nullable ImageButton getPreviousPageBtn() {
        return mPreviousPageBtn;
        return mRightToLeftDirection == LAYOUT_DIRECTION_LTR
                ? mPageLeftBtn : mPageRightBtn;
    }

    public @Nullable ImageButton getNextPageBtn() {
        return mNextPageBtn;
        return mRightToLeftDirection == LAYOUT_DIRECTION_LTR
                ? mPageRightBtn : mPageLeftBtn;
    }

    /** Sets right to left direction of footer. */
    public void updateRightToLeftDirection(Configuration configuration) {
        mRightToLeftDirection = TextUtils.getLayoutDirectionFromLocale(
                configuration.getLocales().get(0));
        getPreviousPageBtn().setContentDescription(mMenuLayout.getResources().getString(
                R.string.previous_button_content_description));
        getNextPageBtn().setContentDescription(mMenuLayout.getResources().getString(
                R.string.next_button_content_description));
    }

    private void configureFooterLayout(ViewGroup menuLayout) {
        ViewGroup footerContainer = menuLayout.findViewById(R.id.footerlayout);
        footerContainer.setVisibility(View.VISIBLE);

        mPreviousPageBtn = menuLayout.findViewById(R.id.menu_prev_button);
        mNextPageBtn = menuLayout.findViewById(R.id.menu_next_button);
        mPageLeftBtn = menuLayout.findViewById(R.id.menu_left_button);
        mPageRightBtn = menuLayout.findViewById(R.id.menu_right_button);
        mTopListDivider = menuLayout.findViewById(R.id.top_listDivider);
        mBottomListDivider = menuLayout.findViewById(R.id.bottom_listDivider);

        // Registers listeners for footer buttons.
        setListener(mPreviousPageBtn);
        setListener(mNextPageBtn);
        setListener(mPageLeftBtn);
        setListener(mPageRightBtn);

        menuLayout
                .getViewTreeObserver()
@@ -85,8 +104,8 @@ public class A11yMenuFooter {
                            @Override
                            public void onGlobalLayout() {
                                menuLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                                expandBtnTouchArea(mPreviousPageBtn, menuLayout);
                                expandBtnTouchArea(mNextPageBtn, (View) mNextPageBtn.getParent());
                                expandBtnTouchArea(mPageLeftBtn, menuLayout);
                                expandBtnTouchArea(mPageRightBtn, (View) mPageRightBtn.getParent());
                            }
                        });
    }
@@ -115,10 +134,10 @@ public class A11yMenuFooter {
    private class FooterButtonClickListener implements OnClickListener {
        @Override
        public void onClick(View view) {
            if (view.getId() == R.id.menu_prev_button) {
                mCallBack.onLeftButtonClicked();
            } else if (view.getId() == R.id.menu_next_button) {
                mCallBack.onRightButtonClicked();
            if (view.getId() == getPreviousPageBtn().getId()) {
                mCallBack.onPreviousButtonClicked();
            } else if (view.getId() == getNextPageBtn().getId()) {
                mCallBack.onNextButtonClicked();
            }
        }
    }
Loading