×

LinearEasingCurve.java

/**
 * Copyright (c) 2013 Nokia Corporation. All rights reserved.
 * Nokia and Nokia Connecting People are registered trademarks of Nokia Corporation. 
 * Oracle and Java are trademarks or registered trademarks of Oracle and/or its
 * affiliates. Other product and company names mentioned herein may be trademarks
 * or trade names of their respective owners. 
 * See LICENSE.TXT for license information.
 */

package com.nokia.example.statusshout.animations;

/**
 * Implements a linear easing curve.
 */
public class LinearEasingCurve extends EasingCurve {
    public boolean calculate(int first, int last, int duration) {
        _duration = duration;
        _steps = _duration / IntAnimation.UPDATE_INTERVAL;
        
        if (_steps < 3) {
            _values = null;
            return false;
        }
        
        _values = new int[_steps];
        _currentStepIndex = 0;
        final int stepLength = (last - first) / (_steps - 1);
        
        _values[0] = first;
        _values[_steps - 1] = last;
        
        for (int i = 1; i < _steps - 1; ++i) {
            _values[i] = first + stepLength * i; 
        }
        
        System.out.print("LinearEasingCurve.calculate(): Duration is "
            + _duration + " ms. The animation has "+ _steps + " steps: { ");
        for (int i = 0; i < _steps; ++i) { System.out.print(_values[i]);
            if (i < _steps - 1) System.out.print(", "); }
        System.out.println(" }");
        
        return true;
    }
}

Last updated 9 October 2013

Back to top

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×