[androidkit] add seekTime and seekFrame for SkottieView util view

Change-Id: Ic714c0be2f63f62485e9d44f1db1e708f3c04dcd
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/433056
Commit-Queue: Jorge Betancourt <jmbetancourt@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
This commit is contained in:
Jorge Betancourt 2021-07-29 09:27:46 -04:00 committed by SkCQ
parent d665999b0d
commit 14c4206d25
2 changed files with 18 additions and 10 deletions

View File

@ -11,10 +11,8 @@ import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.util.Log;
import android.view.SurfaceView;
import android.view.TextureView;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import java.io.InputStream;
@ -76,9 +74,8 @@ class SkottieRenderer extends SurfaceRenderer {
}
}
// TODO: adjust the super time base (otherwise onRenderFrame will overwrite via seekTime).
void seekFrame(double f) {
mAnimation.seekFrame(f);
SkottieAnimation getAnimation() {
return mAnimation;
}
@Override
@ -179,8 +176,14 @@ public class SkottieView extends FrameLayout {
mRenderer.pause();
}
// TODO: track the time base locally
public void seekFrame(float frame) {
mRenderer.seekFrame(frame);
public void seekTime(double t) {
mRenderer.setBaseTime(java.lang.System.currentTimeMillis() - ((long)t * 1000));
}
public void seekFrame(double f) {
double totalFrames = mRenderer.getAnimation().getFrameCount();
double totalTime = mRenderer.getAnimation().getDuration();
double targetTime = (f % totalFrames) / totalFrames * totalTime;
seekTime(targetTime);
}
}

View File

@ -21,6 +21,7 @@ public abstract class SurfaceRenderer implements SurfaceHolder.Callback, Runnabl
private android.view.Surface mAndroidSurface;
private Thread mRenderThread;
private boolean mThreadRunning;
private long mTimeBase;
/**
* Initialization callback.
@ -44,10 +45,10 @@ public abstract class SurfaceRenderer implements SurfaceHolder.Callback, Runnabl
Surface surface = Surface.CreateGL(mAndroidSurface);
onSurfaceInitialized(surface);
long time_base = java.lang.System.currentTimeMillis();
mTimeBase = java.lang.System.currentTimeMillis();
while (mThreadRunning) {
long timestamp = java.lang.System.currentTimeMillis() - time_base;
long timestamp = java.lang.System.currentTimeMillis() - mTimeBase;
onRenderFrame(surface.getCanvas(), timestamp);
surface.flushAndSubmit();
}
@ -93,6 +94,10 @@ public abstract class SurfaceRenderer implements SurfaceHolder.Callback, Runnabl
}
}
public void setBaseTime(long millis) {
mTimeBase = millis;
}
public void release() {
stopRenderThread();
}