SkAR Java: Animation support
Bug: skia: Change-Id: Ia43ccd7d9969e5167e6cd6f561b2d6d604e700a1 Reviewed-on: https://skia-review.googlesource.com/141100 Reviewed-by: Mike Reed <reed@google.com>
This commit is contained in:
parent
0df21136e3
commit
be396c05f9
@ -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()) {
|
||||
|
@ -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<Anchor> 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");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user