diff --git a/platform_tools/android/apps/skar_java/src/main/java/com/google/ar/core/examples/java/helloskar/DrawManager.java b/platform_tools/android/apps/skar_java/src/main/java/com/google/ar/core/examples/java/helloskar/DrawManager.java index 00243193cd..c448ffeb42 100644 --- a/platform_tools/android/apps/skar_java/src/main/java/com/google/ar/core/examples/java/helloskar/DrawManager.java +++ b/platform_tools/android/apps/skar_java/src/main/java/com/google/ar/core/examples/java/helloskar/DrawManager.java @@ -75,6 +75,22 @@ public class DrawManager { canvas.restore(); } + // Sample function for drawing an animated round rect + public void drawAnimatedRoundRect(Canvas canvas, float radius) { + if (modelMatrices.isEmpty()) { + return; + } + Paint p = new Paint(); + p.setColorFilter(lightFilter); + p.setARGB(180, 100, 0, 100); + + canvas.save(); + canvas.setMatrix(SkARMatrix.createPerspectiveMatrix(modelMatrices.get(0), + viewMatrix, projectionMatrix, viewportWidth, viewportHeight)); + canvas.drawRoundRect(0,0, 0.5f, 0.5f, radius, radius, p); + canvas.restore(); + } + // Sample function for drawing a rect public void drawRect(Canvas canvas) { if (modelMatrices.isEmpty()) { diff --git a/platform_tools/android/apps/skar_java/src/main/java/com/google/ar/core/examples/java/helloskar/HelloSkARActivity.java b/platform_tools/android/apps/skar_java/src/main/java/com/google/ar/core/examples/java/helloskar/HelloSkARActivity.java index b2d3cfd534..7bd4085ff8 100644 --- a/platform_tools/android/apps/skar_java/src/main/java/com/google/ar/core/examples/java/helloskar/HelloSkARActivity.java +++ b/platform_tools/android/apps/skar_java/src/main/java/com/google/ar/core/examples/java/helloskar/HelloSkARActivity.java @@ -16,6 +16,8 @@ package com.google.ar.core.examples.java.helloskar; +import android.animation.PropertyValuesHolder; +import android.animation.ValueAnimator; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.PorterDuff; @@ -94,6 +96,11 @@ public class HelloSkARActivity extends AppCompatActivity implements GLSurfaceVie // Anchors created from taps used for object placing. private final ArrayList anchors = new ArrayList<>(); + // Animation fields + float radius; + String PROPERTY_RADIUS = "radius"; + ValueAnimator animator; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -115,6 +122,21 @@ public class HelloSkARActivity extends AppCompatActivity implements GLSurfaceVie glSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY); installRequested = false; + + // Animator set up + PropertyValuesHolder propertyRadius = PropertyValuesHolder.ofFloat(PROPERTY_RADIUS, 0, 0.5f); + animator = new ValueAnimator(); + animator.setValues(propertyRadius); + animator.setDuration(1000); + animator.setRepeatCount(ValueAnimator.INFINITE); + animator.setRepeatMode(ValueAnimator.REVERSE); + animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { + @Override + public void onAnimationUpdate(ValueAnimator animation) { + radius = (float) animation.getAnimatedValue(PROPERTY_RADIUS); + } + }); + animator.start(); } @Override @@ -359,6 +381,7 @@ public class HelloSkARActivity extends AppCompatActivity implements GLSurfaceVie drawManager.drawRect(canvas); drawManager.drawCircle(canvas); + drawManager.drawAnimatedRoundRect(canvas, radius); drawManager.drawText(canvas, "HelloSkAR"); } }