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

Commit f287c587 authored by Biswarup Pal's avatar Biswarup Pal
Browse files

Add non-static methods in ViewConfiguration

... for tapTimeout, doubleTapTimeout, doubelTapMinTime, scrollFriction.
These values are derived from resources, which can be overlaid
per deviceId (go/runtime-resource-overlay-per-deviceid-and-displayid).
The static methods use application context internally, which means that
an app having activities running on two devices together (eg: one
activity on the phone and another on a Chromebook at the same time)
would get a single value on both devices, and result in unexpected
behaviour in one of the devices (Note that application context has
the deviceId of the most recently launched activity). Hence we add
non-static versions of the same methods to fetch the appropriate
overlaid resource value based on the deviceId of the context with which
the ViewConfiguration has been constructed (instead of using the
application context).

A follow-up CL will migrate usages of the static methods from various
places in the framework (wherever possible) to use the non-static ones.

Test: atest ViewConfigurationTest
Flag: android.companion.virtualdevice.flags.viewconfiguration_apis
Bug: 405726390
Change-Id: Ia4c3bc8e54492328adc1fc87a08a914c692d2fea
parent 54b6b308
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -54931,6 +54931,7 @@ package android.view {
    method @Deprecated @FloatRange(from=1.0) public static float getAmbiguousGestureMultiplier();
    method public static long getDefaultActionModeHideDuration();
    method public static int getDoubleTapTimeout();
    method @FlaggedApi("android.companion.virtualdevice.flags.viewconfiguration_apis") public int getDoubleTapTimeoutMillis();
    method @Deprecated public static int getEdgeSlop();
    method @Deprecated public static int getFadingEdgeLength();
    method @Deprecated public static long getGlobalActionKeyTimeout();
@@ -54968,7 +54969,9 @@ package android.view {
    method @Deprecated public static int getScrollBarSize();
    method public static int getScrollDefaultDelay();
    method public static float getScrollFriction();
    method @FlaggedApi("android.companion.virtualdevice.flags.viewconfiguration_apis") public float getScrollFrictionAmount();
    method public static int getTapTimeout();
    method @FlaggedApi("android.companion.virtualdevice.flags.viewconfiguration_apis") public int getTapTimeoutMillis();
    method @Deprecated public static int getTouchSlop();
    method @Deprecated public static int getWindowTouchSlop();
    method public static long getZoomControlsTimeout();
+58 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.view;

import android.annotation.FlaggedApi;
import android.annotation.FloatRange;
import android.annotation.NonNull;
import android.annotation.TestApi;
@@ -387,6 +388,10 @@ public class ViewConfiguration {
    private final int mSmartSelectionInitializingTimeout;
    private final boolean mPreferKeepClearForFocusEnabled;
    private final boolean mViewBasedRotaryEncoderScrollHapticsEnabledConfig;
    private final int mTapTimeoutMillis;
    private final int mDoubleTapTimeoutMillis;
    private final int mDoubleTapMinTimeMillis;
    private final float mScrollFriction;

    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 123768915)
    private boolean sHasPermanentMenuKey;
@@ -394,8 +399,7 @@ public class ViewConfiguration {
    private boolean sHasPermanentMenuKeySet;

    @UnsupportedAppUsage
    static final SparseArray<ViewConfiguration> sConfigurations =
            new SparseArray<ViewConfiguration>(2);
    static final SparseArray<ViewConfiguration> sConfigurations = new SparseArray<>(2);

    /**
     * @deprecated Use {@link android.view.ViewConfiguration#get(android.content.Context)} instead.
@@ -441,6 +445,11 @@ public class ViewConfiguration {
        mSmartSelectionInitializingTimeout = SMART_SELECTION_INITIALIZING_TIMEOUT_IN_MILLISECOND;
        mPreferKeepClearForFocusEnabled = false;
        mViewTouchScreenHapticScrollFeedbackEnabled = false;

        mTapTimeoutMillis = sResourceCache.getTapTimeout();
        mDoubleTapTimeoutMillis = sResourceCache.getDoubleTapTimeout();
        mDoubleTapMinTimeMillis = sResourceCache.getDoubleTapMinTime();
        mScrollFriction = sResourceCache.getScrollFriction();
    }

    /**
@@ -579,6 +588,11 @@ public class ViewConfiguration {
                Flags.enableScrollFeedbackForTouch()
                        ? res.getBoolean(R.bool.config_viewTouchScreenHapticScrollFeedbackEnabled)
                        : false;

        mTapTimeoutMillis = res.getInteger(R.integer.config_tapTimeoutMillis);
        mDoubleTapTimeoutMillis = res.getInteger(R.integer.config_doubleTapTimeoutMillis);
        mDoubleTapMinTimeMillis = res.getInteger(R.integer.config_doubleTapMinTimeMillis);
        mScrollFriction = res.getFloat(R.dimen.config_scrollFriction);
    }

    /**
@@ -739,6 +753,16 @@ public class ViewConfiguration {
        return sResourceCache.getTapTimeout();
    }

    /**
     * @return the duration in milliseconds we will wait to see if a touch event
     * is a tap or a scroll. If the user does not move within this interval, it is
     * considered to be a tap.
     */
    @FlaggedApi(android.companion.virtualdevice.flags.Flags.FLAG_VIEWCONFIGURATION_APIS)
    public int getTapTimeoutMillis() {
        return mTapTimeoutMillis;
    }

    /**
     * @return the duration in milliseconds we will wait to see if a touch event
     * is a jump tap. If the user does not move within this interval, it is
@@ -757,6 +781,16 @@ public class ViewConfiguration {
        return sResourceCache.getDoubleTapTimeout();
    }

    /**
     * @return the duration in milliseconds between the first tap's up event and
     * the second tap's down event for an interaction to be considered a
     * double-tap.
     */
    @FlaggedApi(android.companion.virtualdevice.flags.Flags.FLAG_VIEWCONFIGURATION_APIS)
    public int getDoubleTapTimeoutMillis() {
        return mDoubleTapTimeoutMillis;
    }

    /**
     * @return the minimum duration in milliseconds between the first tap's
     * up event and the second tap's down event for an interaction to be considered a
@@ -769,6 +803,17 @@ public class ViewConfiguration {
        return sResourceCache.getDoubleTapMinTime();
    }

    /**
     * @return the minimum duration in milliseconds between the first tap's
     * up event and the second tap's down event for an interaction to be considered a
     * double-tap.
     *
     * @hide
     */
    public int getDoubleTapMinTimeMillis() {
        return mDoubleTapMinTimeMillis;
    }

    /**
     * @return the maximum duration in milliseconds between a touch pad
     * touch and release for a given touch to be considered a tap (click) as
@@ -1100,6 +1145,17 @@ public class ViewConfiguration {
        return sResourceCache.getScrollFriction();
    }

    /**
     * The amount of friction applied to scrolls and flings.
     *
     * @return A scalar dimensionless value representing the coefficient of
     *         friction.
     */
    @FlaggedApi(android.companion.virtualdevice.flags.Flags.FLAG_VIEWCONFIGURATION_APIS)
    public float getScrollFrictionAmount() {
        return mScrollFriction;
    }

    /**
     * @return the default duration in milliseconds for {@link ActionMode#hide(long)}.
     */