Skip to content

Commit

Permalink
Merge branch 'google' into 'master'
Browse files Browse the repository at this point in the history
  • Loading branch information
hoisie committed Mar 29, 2024
2 parents 8ba90c1 + 4421bed commit c048ea2
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 63 deletions.
1 change: 0 additions & 1 deletion .github/workflows/copybara_build_and_test.yml
Expand Up @@ -40,6 +40,5 @@ jobs:
-Drobolectric.alwaysIncludeVariantMarkersInTestName=true \
-Drobolectric.enabledSdks=34 \
-Dorg.gradle.workers.max=2 \
-Drobolectric.usePreinstrumentedJars=false \
-x :integration_tests:nativegraphics:test \
)
1 change: 0 additions & 1 deletion .github/workflows/tests.yml
Expand Up @@ -68,7 +68,6 @@ jobs:
--no-watch-fs \
-Drobolectric.enabledSdks=${{ matrix.api-versions }} \
-Drobolectric.alwaysIncludeVariantMarkersInTestName=true \
-Drobolectric.usePreinstrumentedJars=false \
-Dorg.gradle.workers.max=2 \
-x :integration_tests:nativegraphics:test \
-x :integration_tests:roborazzi:test
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/groovy/AndroidSdk.groovy
@@ -1,5 +1,5 @@
class AndroidSdk implements Comparable<AndroidSdk> {
static final PREINSTRUMENTED_VERSION = 5
static final PREINSTRUMENTED_VERSION = 6

static final KITKAT = new AndroidSdk(19, "4.4_r1", "r2")
static final LOLLIPOP = new AndroidSdk(21, "5.0.2_r3", "r0")
Expand Down
Expand Up @@ -46,7 +46,7 @@ public class DefaultSdkProvider implements SdkProvider {

private static final int RUNNING_JAVA_VERSION = Util.getJavaVersion();

private static final int PREINSTRUMENTED_VERSION = 5;
private static final int PREINSTRUMENTED_VERSION = 6;

private final DependencyResolver dependencyResolver;

Expand Down
Expand Up @@ -10,6 +10,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

/** Collection of helper methods for calling methods and accessing fields reflectively. */
@SuppressWarnings(value = {"unchecked", "TypeParameterUnusedInFormals", "NewApi"})
Expand Down Expand Up @@ -400,6 +401,22 @@ public static Class<?> loadClass(ClassLoader classLoader, String fullyQualifiedC
}
}

/**
* Attempt to load a class.
*
* @param classLoader The class loader.
* @param fullyQualifiedClassName The fully qualified class name.
* @return The class object, or null if class is not found.
*/
public static Optional<Class<?>> attemptLoadClass(
ClassLoader classLoader, String fullyQualifiedClassName) {
try {
return Optional.of(classLoader.loadClass(fullyQualifiedClassName));
} catch (ClassNotFoundException e) {
return Optional.empty();
}
}

/**
* Create a new instance of a class
*
Expand Down
Expand Up @@ -37,25 +37,16 @@
public class ShadowViewConfiguration {

private static final int SCROLL_BAR_SIZE = 10;
private static final int SCROLL_BAR_FADE_DURATION = 250;
private static final int SCROLL_BAR_DEFAULT_DELAY = 300;
private static final int FADING_EDGE_LENGTH = 12;
private static final int PRESSED_STATE_DURATION = 125;
private static final int LONG_PRESS_TIMEOUT = 500;
private static final int GLOBAL_ACTIONS_KEY_TIMEOUT = 500;
private static final int TAP_TIMEOUT = 115;
private static final int JUMP_TAP_TIMEOUT = 500;
private static final int DOUBLE_TAP_TIMEOUT = 300;
private static final int ZOOM_CONTROLS_TIMEOUT = 3000;
private static final int EDGE_SLOP = 12;
private static final int TOUCH_SLOP = 16;
private static final int PAGING_TOUCH_SLOP = TOUCH_SLOP * 2;
private static final int DOUBLE_TAP_SLOP = 100;
private static final int WINDOW_TOUCH_SLOP = 16;
private static final int MINIMUM_FLING_VELOCITY = 50;
private static final int MAXIMUM_FLING_VELOCITY = 4000;
private static final int MAXIMUM_DRAWING_CACHE_SIZE = 320 * 480 * 4;
private static final float SCROLL_FRICTION = 0.015f;

private int edgeSlop;
private int fadingEdgeLength;
Expand All @@ -72,10 +63,10 @@ private void setup(Context context) {
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
float density = metrics.density;

edgeSlop = (int) (density * EDGE_SLOP + 0.5f);
fadingEdgeLength = (int) (density * FADING_EDGE_LENGTH + 0.5f);
minimumFlingVelocity = (int) (density * MINIMUM_FLING_VELOCITY + 0.5f);
maximumFlingVelocity = (int) (density * MAXIMUM_FLING_VELOCITY + 0.5f);
edgeSlop = (int) (density * ViewConfiguration.getEdgeSlop() + 0.5f);
fadingEdgeLength = (int) (density * ViewConfiguration.getFadingEdgeLength() + 0.5f);
minimumFlingVelocity = (int) (density * ViewConfiguration.getMinimumFlingVelocity() + 0.5f);
maximumFlingVelocity = (int) (density * ViewConfiguration.getMaximumFlingVelocity() + 0.5f);
scrollbarSize = (int) (density * SCROLL_BAR_SIZE + 0.5f);
touchSlop = (int) (density * TOUCH_SLOP + 0.5f);
pagingTouchSlop = (int) (density * PAGING_TOUCH_SLOP + 0.5f);
Expand Down Expand Up @@ -107,21 +98,6 @@ protected int getScaledScrollBarSize() {
return scrollbarSize;
}

@Implementation
protected static int getScrollBarFadeDuration() {
return SCROLL_BAR_FADE_DURATION;
}

@Implementation
protected static int getScrollDefaultDelay() {
return SCROLL_BAR_DEFAULT_DELAY;
}

@Implementation
protected static int getFadingEdgeLength() {
return FADING_EDGE_LENGTH;
}

@Implementation
protected int getScaledFadingEdgeLength() {
return fadingEdgeLength;
Expand All @@ -142,21 +118,11 @@ protected static int getTapTimeout() {
return TAP_TIMEOUT;
}

@Implementation
protected static int getJumpTapTimeout() {
return JUMP_TAP_TIMEOUT;
}

@Implementation
protected static int getDoubleTapTimeout() {
return DOUBLE_TAP_TIMEOUT;
}

@Implementation
protected static int getEdgeSlop() {
return EDGE_SLOP;
}

@Implementation
protected int getScaledEdgeSlop() {
return edgeSlop;
Expand Down Expand Up @@ -192,11 +158,6 @@ protected int getScaledWindowTouchSlop() {
return windowTouchSlop;
}

@Implementation
protected static int getMinimumFlingVelocity() {
return MINIMUM_FLING_VELOCITY;
}

@Implementation
protected int getScaledMinimumFlingVelocity() {
return minimumFlingVelocity;
Expand All @@ -217,21 +178,6 @@ protected static int getMaximumDrawingCacheSize() {
return MAXIMUM_DRAWING_CACHE_SIZE;
}

@Implementation
protected static long getZoomControlsTimeout() {
return ZOOM_CONTROLS_TIMEOUT;
}

@Implementation
protected static long getGlobalActionKeyTimeout() {
return GLOBAL_ACTIONS_KEY_TIMEOUT;
}

@Implementation
protected static float getScrollFriction() {
return SCROLL_FRICTION;
}

@Implementation
protected boolean hasPermanentMenuKey() {
return hasPermanentMenuKey;
Expand Down
Expand Up @@ -25,6 +25,7 @@
import android.view.WindowManager;
import android.window.ClientWindowFrames;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Optional;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Implementation;
Expand Down Expand Up @@ -123,7 +124,46 @@ protected int relayoutWindow(
}

public void callDispatchResized() {
if (RuntimeEnvironment.getApiLevel() > VERSION_CODES.TIRAMISU) {
Optional<Class<?>> activityWindowInfoClass =
ReflectionHelpers.attemptLoadClass(
this.getClass().getClassLoader(), "android.window.ActivityWindowInfo");
if (RuntimeEnvironment.getApiLevel() > VERSION_CODES.UPSIDE_DOWN_CAKE
&& activityWindowInfoClass.isPresent()) {
Display display = getDisplay();
Rect frame = new Rect();
display.getRectSize(frame);

ClientWindowFrames frames = new ClientWindowFrames();
// set the final field
ReflectionHelpers.setField(frames, "frame", frame);
final ClassParameter<?>[] parameters =
new ClassParameter<?>[] {
ClassParameter.from(ClientWindowFrames.class, frames),
ClassParameter.from(boolean.class, true), /* reportDraw */
ClassParameter.from(
MergedConfiguration.class, new MergedConfiguration()), /* mergedConfiguration */
ClassParameter.from(InsetsState.class, new InsetsState()), /* insetsState */
ClassParameter.from(boolean.class, false), /* forceLayout */
ClassParameter.from(boolean.class, false), /* alwaysConsumeSystemBars */
ClassParameter.from(int.class, 0), /* displayId */
ClassParameter.from(int.class, 0), /* syncSeqId */
ClassParameter.from(boolean.class, false), /* dragResizing */
ClassParameter.from(
activityWindowInfoClass.get(),
ReflectionHelpers.newInstance(
activityWindowInfoClass.get())) /* activityWindowInfo */
};
try {
ReflectionHelpers.callInstanceMethod(
ViewRootImpl.class, realObject, "dispatchResized", parameters);
} catch (RuntimeException ex) {
ReflectionHelpers.callInstanceMethod(
ViewRootImpl.class,
realObject,
"dispatchResized",
Arrays.copyOfRange(parameters, 0, parameters.length - 1));
}
} else if (RuntimeEnvironment.getApiLevel() > VERSION_CODES.TIRAMISU) {
Display display = getDisplay();
Rect frame = new Rect();
display.getRectSize(frame);
Expand Down
2 changes: 2 additions & 0 deletions testapp/src/main/res/font/downloadable.xml
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:ignore="FontValidation"
android:fontProviderAuthority="com.example.fontprovider.authority"
android:fontProviderPackage="com.example.fontprovider"
android:fontProviderQuery="example font"/>

0 comments on commit c048ea2

Please sign in to comment.