aboutsummaryrefslogtreecommitdiff
path: root/shadows/framework/src/main/java/org/robolectric/shadows/ShadowNativePathMeasure.java
blob: fd450e9121b7a9bfa7f4acffb0891db8b1ac826f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package org.robolectric.shadows;

import static android.os.Build.VERSION_CODES.O;

import android.graphics.PathMeasure;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.nativeruntime.DefaultNativeRuntimeLoader;
import org.robolectric.nativeruntime.PathMeasureNatives;
import org.robolectric.shadows.ShadowNativePathMeasure.Picker;

/** Shadow for {@link PathMeasure} that is backed by native code */
@Implements(
    value = PathMeasure.class,
    minSdk = O,
    shadowPicker = Picker.class,
    isInAndroidSdk = false)
public class ShadowNativePathMeasure {

  @Implementation(minSdk = O)
  protected static long native_create(long nativePath, boolean forceClosed) {
    DefaultNativeRuntimeLoader.injectAndLoad();
    return PathMeasureNatives.native_create(nativePath, forceClosed);
  }

  @Implementation(minSdk = O)
  protected static void native_setPath(long nativeInstance, long nativePath, boolean forceClosed) {
    PathMeasureNatives.native_setPath(nativeInstance, nativePath, forceClosed);
  }

  @Implementation(minSdk = O)
  protected static float native_getLength(long nativeInstance) {
    return PathMeasureNatives.native_getLength(nativeInstance);
  }

  @Implementation(minSdk = O)
  protected static boolean native_getPosTan(
      long nativeInstance, float distance, float[] pos, float[] tan) {
    return PathMeasureNatives.native_getPosTan(nativeInstance, distance, pos, tan);
  }

  @Implementation(minSdk = O)
  protected static boolean native_getMatrix(
      long nativeInstance, float distance, long nativeMatrix, int flags) {
    return PathMeasureNatives.native_getMatrix(nativeInstance, distance, nativeMatrix, flags);
  }

  @Implementation(minSdk = O)
  protected static boolean native_getSegment(
      long nativeInstance, float startD, float stopD, long nativePath, boolean startWithMoveTo) {
    return PathMeasureNatives.native_getSegment(
        nativeInstance, startD, stopD, nativePath, startWithMoveTo);
  }

  @Implementation(minSdk = O)
  protected static boolean native_isClosed(long nativeInstance) {
    return PathMeasureNatives.native_isClosed(nativeInstance);
  }

  @Implementation(minSdk = O)
  protected static boolean native_nextContour(long nativeInstance) {
    return PathMeasureNatives.native_nextContour(nativeInstance);
  }

  @Implementation(minSdk = O)
  protected static void native_destroy(long nativeInstance) {
    PathMeasureNatives.native_destroy(nativeInstance);
  }

  /** Shadow picker for {@link PathMeasure}. */
  public static final class Picker extends GraphicsShadowPicker<Object> {
    public Picker() {
      super(ShadowPathMeasure.class, ShadowNativePathMeasure.class);
    }
  }
}