android.animation.TimeAnimator Java Examples

The following examples show how to use android.animation.TimeAnimator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GenericTouchGesture.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private Runnable createJBRunnable() {
    // On JB, we rely on TimeAnimator to send events tied with vsync.
    return new Runnable() {
        @Override
        public void run() {
            mTimeAnimator = new TimeAnimator();
            mTimeAnimator.setTimeListener(new TimeListener() {
                @Override
                public void onTimeUpdate(TimeAnimator animation, long totalTime,
                        long deltaTime) {
                    if (!sendEvent(mStartTime + totalTime)) {
                        mTimeAnimator.end();
                    }
                }
            });
            mTimeAnimator.start();
        }
    };
}
 
Example #2
Source File: GenericTouchGesture.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private Runnable createJBRunnable() {
    // On JB, we rely on TimeAnimator to send events tied with vsync.
    return new Runnable() {
        @Override
        public void run() {
            mTimeAnimator = new TimeAnimator();
            mTimeAnimator.setTimeListener(new TimeListener() {
                @Override
                public void onTimeUpdate(TimeAnimator animation, long totalTime,
                        long deltaTime) {
                    if (!sendEvent(mStartTime + totalTime)) {
                        mTimeAnimator.end();
                    }
                }
            });
            mTimeAnimator.start();
        }
    };
}
 
Example #3
Source File: ToolbarProgressBar.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public void onTimeUpdate(TimeAnimator animation, long totalTimeMs, long deltaTimeMs) {
    // Cap progress bar animation frame time so that it doesn't jump too much even when
    // the animation is janky.
    float progress = mAnimationLogic.updateProgress(mTargetProgress,
            Math.min(deltaTimeMs, PROGRESS_FRAME_TIME_CAP_MS) * 0.001f, getWidth());
    progress = Math.max(progress, 0);
    ToolbarProgressBar.super.setProgress(progress);

    if (mAnimatingView != null) {
        int width = Math.abs(
                getDrawable().getBounds().right - getDrawable().getBounds().left);
        mAnimatingView.update(progress * width);
    }

    if (getProgress() == mTargetProgress) {
        if (!mIsStarted) postOnAnimationDelayed(mHideRunnable, mHidingDelayMs);
        mProgressAnimator.end();
        return;
    }
}
 
Example #4
Source File: ToolbarProgressBar.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void onTimeUpdate(TimeAnimator animation, long totalTimeMs, long deltaTimeMs) {
    // Cap progress bar animation frame time so that it doesn't jump too much even when
    // the animation is janky.
    float progress = mAnimationLogic.updateProgress(mTargetProgress,
            Math.min(deltaTimeMs, PROGRESS_FRAME_TIME_CAP_MS) * 0.001f, getWidth());
    progress = Math.max(progress, 0);
    ToolbarProgressBar.super.setProgress(progress);

    if (mAnimatingView != null) {
        int width = Math.abs(
                getDrawable().getBounds().right - getDrawable().getBounds().left);
        mAnimatingView.update(progress * width);
    }

    if (getProgress() == mTargetProgress) {
        if (!mIsStarted) postOnAnimationDelayed(mHideRunnable, mHidingDelayMs);
        mProgressAnimator.end();
        return;
    }
}
 
Example #5
Source File: ToolbarProgressBar.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public void onTimeUpdate(TimeAnimator animation, long totalTimeMs, long deltaTimeMs) {
    // Cap progress bar animation frame time so that it doesn't jump too much even when
    // the animation is janky.
    float progress = mAnimationLogic.updateProgress(mTargetProgress,
            Math.min(deltaTimeMs, PROGRESS_FRAME_TIME_CAP_MS) * 0.001f, getWidth());
    progress = Math.max(progress, 0);
    ToolbarProgressBar.super.setProgress(progress);

    if (mAnimatingView != null) {
        int width = Math.abs(
                getDrawable().getBounds().right - getDrawable().getBounds().left);
        mAnimatingView.update(progress * width);
    }

    if (getProgress() == mTargetProgress) {
        if (!mIsStarted) postOnAnimationDelayed(mHideRunnable, mHidingDelayMs);
        mProgressAnimator.end();
        return;
    }
}
 
Example #6
Source File: AppMenuDragHelper.java    From 365browser with Apache License 2.0 5 votes vote down vote up
AppMenuDragHelper(Activity activity, AppMenu appMenu, int itemRowHeight) {
    mActivity = activity;
    mAppMenu = appMenu;
    mItemRowHeight = itemRowHeight;
    Resources res = mActivity.getResources();
    mAutoScrollFullVelocity = res.getDimensionPixelSize(R.dimen.auto_scroll_full_velocity);
    // If user is dragging and the popup ListView is too big to display at once,
    // mDragScrolling animator scrolls mPopup.getListView() automatically depending on
    // the user's touch position.
    mDragScrolling.setTimeListener(new TimeAnimator.TimeListener() {
        @Override
        public void onTimeUpdate(TimeAnimator animation, long totalTime, long deltaTime) {
            ListPopupWindow popup = mAppMenu.getPopup();
            if (popup == null || popup.getListView() == null) return;

            // We keep both mDragScrollOffset and mDragScrollOffsetRounded because
            // the actual scrolling is by the rounded value but at the same time we also
            // want to keep the precise scroll value in float.
            mDragScrollOffset += (deltaTime * 0.001f) * mDragScrollingVelocity;
            int diff = Math.round(mDragScrollOffset - mDragScrollOffsetRounded);
            mDragScrollOffsetRounded += diff;
            popup.getListView().smoothScrollBy(diff, 0);

            // Force touch move event to highlight items correctly for the scrolled position.
            if (!Float.isNaN(mLastTouchX) && !Float.isNaN(mLastTouchY)) {
                menuItemAction(Math.round(mLastTouchX), Math.round(mLastTouchY),
                        ITEM_ACTION_HIGHLIGHT);
            }
        }
    });

    // We use medium timeout, the average of tap and long press timeouts. This is consistent
    // with ListPopupWindow#ForwardingListener implementation.
    mTapTimeout =
            (ViewConfiguration.getTapTimeout() + ViewConfiguration.getLongPressTimeout()) / 2;
    mScaledTouchSlop = ViewConfiguration.get(activity).getScaledTouchSlop();
}
 
Example #7
Source File: PropertyAnimation09.java    From cogitolearning-examples with MIT License 5 votes vote down vote up
@Override
@SuppressLint("NewApi")
protected void onCreate(Bundle savedInstanceState)
{
  super.onCreate(savedInstanceState);
  setContentView(R.layout.property_animations09);

  if (android.os.Build.VERSION.SDK_INT >= 19)
  {
    ImageView someImage = (ImageView) findViewById(R.id.some_image);

    ObjectAnimator rotateAnim = ObjectAnimator.ofFloat(someImage, "rotation", 0, 360);
    rotateAnim.setDuration(1000);
    rotateAnim.setRepeatCount(5);
    rotateAnim.setRepeatMode(ObjectAnimator.RESTART);

    fpsText = (TextView) findViewById(R.id.fps_text);
    FpsTimeListener listener = new FpsTimeListener(fpsText);
    
    final TimeAnimator timeAnim = new TimeAnimator();
    timeAnim.setTimeListener(listener);
    
    anim = new AnimatorSet();
    anim.play(rotateAnim).with(timeAnim);
    rotateAnim.addListener(new AnimatorListenerAdapter()
    {
      @Override
      public void onAnimationEnd(Animator animation)
      {
        timeAnim.end(); 
      }
    });
  }
}
 
Example #8
Source File: FpsTimeListener.java    From cogitolearning-examples with MIT License 5 votes vote down vote up
public void onTimeUpdate(TimeAnimator animation, long totalTime, long deltaTime)
{

  double currentFps;
  if (deltaTime != 0)
    currentFps = 1000.0 / (double) deltaTime;
  else
    currentFps = 0.9 * fps;
  if (fps < 0.0)
    fps = currentFps;
  else
    fps = 0.9 * fps + 0.1 * currentFps;
  textView.setText(String.format("fps: %.2f", fps));
}
 
Example #9
Source File: FocusHighlightHelper.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
@Override
public void onTimeUpdate(TimeAnimator animation, long totalTime, long deltaTime) {
    float fraction;
    if (totalTime >= mDuration) {
        fraction = 1;
        mAnimator.end();
    } else {
        fraction = (float) (totalTime / (double) mDuration);
    }
    if (mInterpolator != null) {
        fraction = mInterpolator.getInterpolation(fraction);
    }
    setFocusLevel(mFocusLevelStart + fraction * mFocusLevelDelta);
}
 
Example #10
Source File: Bouncer.java    From androidtv-daydream with Apache License 2.0 5 votes vote down vote up
public void onTimeUpdate(TimeAnimator animation, long elapsed, long dt_ms) {
    final float dt = dt_ms / 1000f; // seconds
    for (int i=0; i<getChildCount(); i++) {
        final View view = getChildAt(i);
        final PointF v = (PointF) view.getTag();

        // step view for velocity * time
        view.setX(view.getX() + v.x * dt);
        view.setY(view.getY() + v.y * dt);

        // handle reflections
        final float l = view.getX();
        final float t = view.getY();
        final float r = l + view.getWidth();
        final float b = t + view.getHeight();
        boolean flipX = false, flipY = false;
        if (r > mWidth) {
            view.setX(view.getX() - 2 * (r - mWidth));
            flipX = true;
        } else if (l < 0) {
            view.setX(-l);
            flipX = true;
        }
        if (b > mHeight) {
            view.setY(view.getY() - 2 * (b - mHeight));
            flipY = true;
        } else if (t < 0) {
            view.setY(-t);
            flipY = true;
        }
        if (flipX) v.x *= -1;
        if (flipY) v.y *= -1;
    }
}
 
Example #11
Source File: BugView.java    From Bugstick with MIT License 5 votes vote down vote up
private void init(Context context) {
    animator = new TimeAnimator();
    animator.setTimeListener(this);

    paint = new Paint();
    paint.setColor(Color.WHITE);

    density = getResources().getDisplayMetrics().density;

    path = new Path();
    pathMeasure = new PathMeasure();
    position = new PointF();
    velocity = new PointF();
}
 
Example #12
Source File: AnimationFrameTimeHistogram.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onTimeUpdate(TimeAnimator animation, long totalTime, long deltaTime) {
    if (mFrameTimesCount == mFrameTimesMs.length) {
        mAnimator.end();
        cleanUp();
        Log.w(TAG, "Animation frame time recording reached the maximum number. It's either"
                + "the animation took too long or recording end is not called.");
        return;
    }

    // deltaTime is 0 for the first frame.
    if (deltaTime > 0) {
        mFrameTimesMs[mFrameTimesCount++] = deltaTime;
    }
}
 
Example #13
Source File: AppMenuDragHelper.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
AppMenuDragHelper(Activity activity, AppMenu appMenu, int itemRowHeight) {
    mActivity = activity;
    mAppMenu = appMenu;
    mItemRowHeight = itemRowHeight;
    Resources res = mActivity.getResources();
    mAutoScrollFullVelocity = res.getDimensionPixelSize(R.dimen.auto_scroll_full_velocity);
    // If user is dragging and the popup ListView is too big to display at once,
    // mDragScrolling animator scrolls mPopup.getListView() automatically depending on
    // the user's touch position.
    mDragScrolling.setTimeListener(new TimeAnimator.TimeListener() {
        @Override
        public void onTimeUpdate(TimeAnimator animation, long totalTime, long deltaTime) {
            ListPopupWindow popup = mAppMenu.getPopup();
            if (popup == null || popup.getListView() == null) return;

            // We keep both mDragScrollOffset and mDragScrollOffsetRounded because
            // the actual scrolling is by the rounded value but at the same time we also
            // want to keep the precise scroll value in float.
            mDragScrollOffset += (deltaTime * 0.001f) * mDragScrollingVelocity;
            int diff = Math.round(mDragScrollOffset - mDragScrollOffsetRounded);
            mDragScrollOffsetRounded += diff;
            popup.getListView().smoothScrollBy(diff, 0);

            // Force touch move event to highlight items correctly for the scrolled position.
            if (!Float.isNaN(mLastTouchX) && !Float.isNaN(mLastTouchY)) {
                menuItemAction(Math.round(mLastTouchX), Math.round(mLastTouchY),
                        ITEM_ACTION_HIGHLIGHT);
            }
        }
    });

    // We use medium timeout, the average of tap and long press timeouts. This is consistent
    // with ListPopupWindow#ForwardingListener implementation.
    mTapTimeout =
            (ViewConfiguration.getTapTimeout() + ViewConfiguration.getLongPressTimeout()) / 2;
    mScaledTouchSlop = ViewConfiguration.get(activity).getScaledTouchSlop();
}
 
Example #14
Source File: XDripDreamService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Every TimeAnimator frame, nudge each bouncing view along.
 */
public void onTimeUpdate(TimeAnimator animation, long elapsed, long dt_ms) {
    final float dt = dt_ms / 1000f; // seconds
    for (int i = 0; i < getChildCount(); i++) {
        final View view = getChildAt(i);
        final PointF v = (PointF) view.getTag();

        // step view for velocity * time
        view.setX(view.getX() + v.x * dt);
        view.setY(view.getY() + v.y * dt);

        // handle reflections
        final float l = view.getX();
        final float t = view.getY();
        final float r = l + view.getWidth();
        final float b = t + view.getHeight();
        boolean flipX = false, flipY = false;
        if (r > mWidth) {
            view.setX(view.getX() - 2 * (r - mWidth));
            flipX = true;
        } else if (l < 0) {
            view.setX(-l);
            flipX = true;
        }
        if (b > mHeight) {
            view.setY(view.getY() - 2 * (b - mHeight));
            flipY = true;
        } else if (t < 0) {
            view.setY(-t);
            flipY = true;
        }
        if (flipX) v.x *= -1;
        if (flipY) v.y *= -1;
    }
}
 
Example #15
Source File: XDripDreamService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Every TimeAnimator frame, nudge each bouncing view along.
 */
public void onTimeUpdate(TimeAnimator animation, long elapsed, long dt_ms) {
    final float dt = dt_ms / 1000f; // seconds
    for (int i = 0; i < getChildCount(); i++) {
        final View view = getChildAt(i);
        final PointF v = (PointF) view.getTag();

        // step view for velocity * time
        view.setX(view.getX() + v.x * dt);
        view.setY(view.getY() + v.y * dt);

        // handle reflections
        final float l = view.getX();
        final float t = view.getY();
        final float r = l + view.getWidth();
        final float b = t + view.getHeight();
        boolean flipX = false, flipY = false;
        if (r > mWidth) {
            view.setX(view.getX() - 2 * (r - mWidth));
            flipX = true;
        } else if (l < 0) {
            view.setX(-l);
            flipX = true;
        }
        if (b > mHeight) {
            view.setY(view.getY() - 2 * (b - mHeight));
            flipY = true;
        } else if (t < 0) {
            view.setY(-t);
            flipY = true;
        }
        if (flipX) v.x *= -1;
        if (flipY) v.y *= -1;
    }
}
 
Example #16
Source File: AppMenuDragHelper.java    From delion with Apache License 2.0 5 votes vote down vote up
AppMenuDragHelper(Activity activity, AppMenu appMenu, int itemRowHeight) {
    mActivity = activity;
    mAppMenu = appMenu;
    mItemRowHeight = itemRowHeight;
    Resources res = mActivity.getResources();
    mAutoScrollFullVelocity = res.getDimensionPixelSize(R.dimen.auto_scroll_full_velocity);
    // If user is dragging and the popup ListView is too big to display at once,
    // mDragScrolling animator scrolls mPopup.getListView() automatically depending on
    // the user's touch position.
    mDragScrolling.setTimeListener(new TimeAnimator.TimeListener() {
        @Override
        public void onTimeUpdate(TimeAnimator animation, long totalTime, long deltaTime) {
            ListPopupWindow popup = mAppMenu.getPopup();
            if (popup == null || popup.getListView() == null) return;

            // We keep both mDragScrollOffset and mDragScrollOffsetRounded because
            // the actual scrolling is by the rounded value but at the same time we also
            // want to keep the precise scroll value in float.
            mDragScrollOffset += (deltaTime * 0.001f) * mDragScrollingVelocity;
            int diff = Math.round(mDragScrollOffset - mDragScrollOffsetRounded);
            mDragScrollOffsetRounded += diff;
            popup.getListView().smoothScrollBy(diff, 0);

            // Force touch move event to highlight items correctly for the scrolled position.
            if (!Float.isNaN(mLastTouchX) && !Float.isNaN(mLastTouchY)) {
                menuItemAction(Math.round(mLastTouchX), Math.round(mLastTouchY),
                        ITEM_ACTION_HIGHLIGHT);
            }
        }
    });

    // We use medium timeout, the average of tap and long press timeouts. This is consistent
    // with ListPopupWindow#ForwardingListener implementation.
    mTapTimeout =
            (ViewConfiguration.getTapTimeout() + ViewConfiguration.getLongPressTimeout()) / 2;
    mScaledTouchSlop = ViewConfiguration.get(activity).getScaledTouchSlop();
}
 
Example #17
Source File: FocusHighlightHelper.java    From TvRecyclerView with Apache License 2.0 5 votes vote down vote up
@Override
public void onTimeUpdate(TimeAnimator animation, long totalTime, long deltaTime) {
    float fraction;
    if (totalTime >= mDuration) {
        fraction = 1;
        mAnimator.end();
    } else {
        fraction = (float) (totalTime / (double) mDuration);
    }
    if (mInterpolator != null) {
        fraction = mInterpolator.getInterpolation(fraction);
    }
    setFocusLevel(mFocusLevelStart + fraction * mFocusLevelDelta);
}
 
Example #18
Source File: AnimationFrameTimeHistogram.java    From cronet with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void onTimeUpdate(TimeAnimator animation, long totalTime, long deltaTime) {
    if (mFrameTimesCount == mFrameTimesMs.length) {
        mAnimator.end();
        cleanUp();
        Log.w(TAG, "Animation frame time recording reached the maximum number. It's either"
                + "the animation took too long or recording end is not called.");
        return;
    }

    // deltaTime is 0 for the first frame.
    if (deltaTime > 0) {
        mFrameTimesMs[mFrameTimesCount++] = deltaTime;
    }
}
 
Example #19
Source File: ContinuousExampleComponentSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
private static Animator createRotationAnimator(final DynamicValue<Float> rotation) {
  final TimeAnimator animator = new TimeAnimator();
  final FloatEvaluator floatEvaluator = new FloatEvaluator();
  animator.setTimeListener(
      new TimeAnimator.TimeListener() {
        @Override
        public void onTimeUpdate(TimeAnimator animation, long totalTime, long deltaTime) {
          float fraction =
              Float.valueOf(totalTime % ANIMATION_DURATION_MS) / ANIMATION_DURATION_MS;
          rotation.set(fraction * 360);
        }
      });
  return animator;
}
 
Example #20
Source File: MyFocusHighlightHelper.java    From LeanbackTvSample with MIT License 5 votes vote down vote up
@Override
public void onTimeUpdate(TimeAnimator animation, long totalTime, long deltaTime) {
    float fraction;
    if (totalTime >= mDuration) {
        fraction = 1;
        mAnimator.end();
    } else {
        fraction = (float) (totalTime / (double) mDuration);
    }
    if (mInterpolator != null) {
        fraction = mInterpolator.getInterpolation(fraction);
    }
    setFocusLevel(mFocusLevelStart + fraction * mFocusLevelDelta);
}
 
Example #21
Source File: MainActivity.java    From media-samples with Apache License 2.0 4 votes vote down vote up
public void startPlayback() {

        // Construct a URI that points to the video resource that we want to play
        Uri videoUri = Uri.parse("android.resource://"
                + getPackageName() + "/"
                + R.raw.vid_bigbuckbunny);

        try {

            // BEGIN_INCLUDE(initialize_extractor)
            mExtractor.setDataSource(this, videoUri, null);
            int nTracks = mExtractor.getTrackCount();

            // Begin by unselecting all of the tracks in the extractor, so we won't see
            // any tracks that we haven't explicitly selected.
            for (int i = 0; i < nTracks; ++i) {
                mExtractor.unselectTrack(i);
            }


            // Find the first video track in the stream. In a real-world application
            // it's possible that the stream would contain multiple tracks, but this
            // sample assumes that we just want to play the first one.
            for (int i = 0; i < nTracks; ++i) {
                // Try to create a video codec for this track. This call will return null if the
                // track is not a video track, or not a recognized video format. Once it returns
                // a valid MediaCodecWrapper, we can break out of the loop.
                mCodecWrapper = MediaCodecWrapper.fromVideoFormat(mExtractor.getTrackFormat(i),
                        new Surface(mPlaybackView.getSurfaceTexture()));
                if (mCodecWrapper != null) {
                    mExtractor.selectTrack(i);
                    break;
                }
            }
            // END_INCLUDE(initialize_extractor)




            // By using a {@link TimeAnimator}, we can sync our media rendering commands with
            // the system display frame rendering. The animator ticks as the {@link Choreographer}
            // receives VSYNC events.
            mTimeAnimator.setTimeListener(new TimeAnimator.TimeListener() {
                @Override
                public void onTimeUpdate(final TimeAnimator animation,
                                         final long totalTime,
                                         final long deltaTime) {

                    boolean isEos = ((mExtractor.getSampleFlags() & MediaCodec
                            .BUFFER_FLAG_END_OF_STREAM) == MediaCodec.BUFFER_FLAG_END_OF_STREAM);

                    // BEGIN_INCLUDE(write_sample)
                    if (!isEos) {
                        // Try to submit the sample to the codec and if successful advance the
                        // extractor to the next available sample to read.
                        boolean result = mCodecWrapper.writeSample(mExtractor, false,
                                mExtractor.getSampleTime(), mExtractor.getSampleFlags());

                        if (result) {
                            // Advancing the extractor is a blocking operation and it MUST be
                            // executed outside the main thread in real applications.
                            mExtractor.advance();
                        }
                    }
                    // END_INCLUDE(write_sample)

                    // Examine the sample at the head of the queue to see if its ready to be
                    // rendered and is not zero sized End-of-Stream record.
                    MediaCodec.BufferInfo out_bufferInfo = new MediaCodec.BufferInfo();
                    mCodecWrapper.peekSample(out_bufferInfo);

                    // BEGIN_INCLUDE(render_sample)
                    if (out_bufferInfo.size <= 0 && isEos) {
                        mTimeAnimator.end();
                        mCodecWrapper.stopAndRelease();
                        mExtractor.release();
                    } else if (out_bufferInfo.presentationTimeUs / 1000 < totalTime) {
                        // Pop the sample off the queue and send it to {@link Surface}
                        mCodecWrapper.popSample(true);
                    }
                    // END_INCLUDE(render_sample)

                }
            });

            // We're all set. Kick off the animator to process buffers and render video frames as
            // they become available
            mTimeAnimator.start();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
 
Example #22
Source File: XDripDreamService.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
public Bouncer(Context context, AttributeSet attrs, int flags) {
    super(context, attrs, flags);
    mAnimator = new TimeAnimator();
    mAnimator.setTimeListener(this);
}
 
Example #23
Source File: Bouncer.java    From androidtv-daydream with Apache License 2.0 4 votes vote down vote up
public Bouncer(Context context, AttributeSet attrs, int flags) {
    super(context, attrs, flags);
    mAnimator = new TimeAnimator();
    mAnimator.setTimeListener(this);
}
 
Example #24
Source File: XDripDreamService.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
public Bouncer(Context context, AttributeSet attrs, int flags) {
    super(context, attrs, flags);
    mAnimator = new TimeAnimator();
    mAnimator.setTimeListener(this);
}
 
Example #25
Source File: RowsSupportFragment.java    From adt-leanback-support with Apache License 2.0 4 votes vote down vote up
@Override
public void onTimeUpdate(TimeAnimator animation, long totalTime, long deltaTime) {
    if (mSelectAnimator.isRunning()) {
        updateSelect(totalTime, deltaTime);
    }
}
 
Example #26
Source File: RowsFragment.java    From adt-leanback-support with Apache License 2.0 4 votes vote down vote up
@Override
public void onTimeUpdate(TimeAnimator animation, long totalTime, long deltaTime) {
    if (mSelectAnimator.isRunning()) {
        updateSelect(totalTime, deltaTime);
    }
}
 
Example #27
Source File: MainActivity.java    From android-BasicMediaDecoder with Apache License 2.0 4 votes vote down vote up
public void startPlayback() {

        // Construct a URI that points to the video resource that we want to play
        Uri videoUri = Uri.parse("android.resource://"
                + getPackageName() + "/"
                + R.raw.vid_bigbuckbunny);

        try {

            // BEGIN_INCLUDE(initialize_extractor)
            mExtractor.setDataSource(this, videoUri, null);
            int nTracks = mExtractor.getTrackCount();

            // Begin by unselecting all of the tracks in the extractor, so we won't see
            // any tracks that we haven't explicitly selected.
            for (int i = 0; i < nTracks; ++i) {
                mExtractor.unselectTrack(i);
            }


            // Find the first video track in the stream. In a real-world application
            // it's possible that the stream would contain multiple tracks, but this
            // sample assumes that we just want to play the first one.
            for (int i = 0; i < nTracks; ++i) {
                // Try to create a video codec for this track. This call will return null if the
                // track is not a video track, or not a recognized video format. Once it returns
                // a valid MediaCodecWrapper, we can break out of the loop.
                mCodecWrapper = MediaCodecWrapper.fromVideoFormat(mExtractor.getTrackFormat(i),
                        new Surface(mPlaybackView.getSurfaceTexture()));
                if (mCodecWrapper != null) {
                    mExtractor.selectTrack(i);
                    break;
                }
            }
            // END_INCLUDE(initialize_extractor)




            // By using a {@link TimeAnimator}, we can sync our media rendering commands with
            // the system display frame rendering. The animator ticks as the {@link Choreographer}
            // receives VSYNC events.
            mTimeAnimator.setTimeListener(new TimeAnimator.TimeListener() {
                @Override
                public void onTimeUpdate(final TimeAnimator animation,
                                         final long totalTime,
                                         final long deltaTime) {

                    boolean isEos = ((mExtractor.getSampleFlags() & MediaCodec
                            .BUFFER_FLAG_END_OF_STREAM) == MediaCodec.BUFFER_FLAG_END_OF_STREAM);

                    // BEGIN_INCLUDE(write_sample)
                    if (!isEos) {
                        // Try to submit the sample to the codec and if successful advance the
                        // extractor to the next available sample to read.
                        boolean result = mCodecWrapper.writeSample(mExtractor, false,
                                mExtractor.getSampleTime(), mExtractor.getSampleFlags());

                        if (result) {
                            // Advancing the extractor is a blocking operation and it MUST be
                            // executed outside the main thread in real applications.
                            mExtractor.advance();
                        }
                    }
                    // END_INCLUDE(write_sample)

                    // Examine the sample at the head of the queue to see if its ready to be
                    // rendered and is not zero sized End-of-Stream record.
                    MediaCodec.BufferInfo out_bufferInfo = new MediaCodec.BufferInfo();
                    mCodecWrapper.peekSample(out_bufferInfo);

                    // BEGIN_INCLUDE(render_sample)
                    if (out_bufferInfo.size <= 0 && isEos) {
                        mTimeAnimator.end();
                        mCodecWrapper.stopAndRelease();
                        mExtractor.release();
                    } else if (out_bufferInfo.presentationTimeUs / 1000 < totalTime) {
                        // Pop the sample off the queue and send it to {@link Surface}
                        mCodecWrapper.popSample(true);
                    }
                    // END_INCLUDE(render_sample)

                }
            });

            // We're all set. Kick off the animator to process buffers and render video frames as
            // they become available
            mTimeAnimator.start();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
 
Example #28
Source File: BugView.java    From Bugstick with MIT License 3 votes vote down vote up
@Override
public void onTimeUpdate(TimeAnimator animation, long totalTime, long deltaTime) {
    final float dt = deltaTime / 1000f; // seconds

    position.x += velocity.x * dt;
    position.y += velocity.y * dt;

    bound();

    path.lineTo(position.x, position.y);

    invalidate();
}