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

Commit 0ad372a7 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix context menu position for RTL"

parents 3bcddc94 d959c9d2
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -256,7 +256,7 @@ public class MenuPopupHelper implements MenuHelper {
            final int hgrav = Gravity.getAbsoluteGravity(mDropDownGravity,
                    mAnchorView.getLayoutDirection()) & Gravity.HORIZONTAL_GRAVITY_MASK;
            if (hgrav == Gravity.RIGHT) {
                xOffset += mAnchorView.getWidth();
                xOffset -= mAnchorView.getWidth();
            }

            popup.setHorizontalOffset(xOffset);
+10 −2
Original line number Diff line number Diff line
@@ -263,7 +263,6 @@ final class StandardMenuPopup extends MenuPopup implements OnDismissListener, On
                    mShownAnchorView, mOverflowOnly, mPopupStyleAttr, mPopupStyleRes);
            subPopup.setPresenterCallback(mPresenterCallback);
            subPopup.setForceShowIcon(MenuPopup.shouldPreserveIconSpacing(subMenu));
            subPopup.setGravity(mDropDownGravity);

            // Pass responsibility for handling onDismiss to the submenu.
            subPopup.setOnDismissListener(mOnDismissListener);
@@ -273,8 +272,17 @@ final class StandardMenuPopup extends MenuPopup implements OnDismissListener, On
            mMenu.close(false /* closeAllMenus */);

            // Show the new sub-menu popup at the same location as this popup.
            final int horizontalOffset = mPopup.getHorizontalOffset();
            int horizontalOffset = mPopup.getHorizontalOffset();
            final int verticalOffset = mPopup.getVerticalOffset();

            // As xOffset of parent menu popup is subtracted with Anchor width for Gravity.RIGHT,
            // So, again to display sub-menu popup in same xOffset, add the Anchor width.
            final int hgrav = Gravity.getAbsoluteGravity(mDropDownGravity,
                mAnchorView.getLayoutDirection()) & Gravity.HORIZONTAL_GRAVITY_MASK;
            if (hgrav == Gravity.RIGHT) {
              horizontalOffset += mAnchorView.getWidth();
            }

            if (subPopup.tryShow(horizontalOffset, verticalOffset)) {
                if (mPresenterCallback != null) {
                    mPresenterCallback.onOpenSubMenu(subMenu);
+7 −0
Original line number Diff line number Diff line
@@ -1045,6 +1045,13 @@
            </intent-filter>
        </activity>

        <activity android:name="android.view.menu.ContextMenuActivity" android:label="ContextMenu" android:theme="@android:style/Theme.Material">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST" />
            </intent-filter>
        </activity>

        <activity android:name="android.view.menu.MenuWith1Item" android:label="MenuWith1Item">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
+54 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
**
** Copyright 2018, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
-->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <LinearLayout
            android:id="@+id/context_menu_target_ltr"
            android:orientation="horizontal"
            android:layoutDirection="ltr"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="50px"
            android:layout_marginEnd="50px">
        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="LTR"/>
    </LinearLayout>

    <LinearLayout
            android:id="@+id/context_menu_target_rtl"
            android:orientation="horizontal"
            android:layoutDirection="rtl"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="50px"
            android:layout_marginEnd="50px">
        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="RTL"/>
    </LinearLayout>

</LinearLayout>
+104 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.util;

import org.junit.Assert;

/**
 * Utility used for testing that allows to poll for a certain condition to happen within a timeout.
 *
 * Code copied from com.android.compatibility.common.util.PollingCheck
 */
public abstract class PollingCheck {

    private static final long DEFAULT_TIMEOUT = 3000;
    private static final long TIME_SLICE = 50;
    private final long mTimeout;

    /**
     * The condition that the PollingCheck should use to proceed successfully.
     */
    public interface PollingCheckCondition {

        /**
         * @return Whether the polling condition has been met.
         */
        boolean canProceed();
    }

    public PollingCheck(long timeout) {
        mTimeout = timeout;
    }

    protected abstract boolean check();

    /**
     * Start running the polling check.
     */
    public void run() {
        if (check()) {
            return;
        }

        long timeout = mTimeout;
        while (timeout > 0) {
            try {
                Thread.sleep(TIME_SLICE);
            } catch (InterruptedException e) {
                Assert.fail("unexpected InterruptedException");
            }

            if (check()) {
                return;
            }

            timeout -= TIME_SLICE;
        }

        Assert.fail("unexpected timeout");
    }

    /**
     * Instantiate and start polling for a given condition with a default 3000ms timeout.
     *
     * @param condition The condition to check for success.
     */
    public static void waitFor(final PollingCheckCondition condition) {
        new PollingCheck(DEFAULT_TIMEOUT) {
            @Override
            protected boolean check() {
                return condition.canProceed();
            }
        }.run();
    }

    /**
     * Instantiate and start polling for a given condition.
     *
     * @param timeout Time out in ms
     * @param condition The condition to check for success.
     */
    public static void waitFor(long timeout, final PollingCheckCondition condition) {
        new PollingCheck(timeout) {
            @Override
            protected boolean check() {
                return condition.canProceed();
            }
        }.run();
    }
}
Loading