Android Open Source - helsinki-testbed2-android Seek Bar Util






From Project

Back to project page helsinki-testbed2-android.

License

The source code is released under:

GNU General Public License

If you think the Android project helsinki-testbed2-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package fi.testbed2.util;
//  w  w w  . ja  v  a 2s . c  om
import java.math.BigDecimal;

public class SeekBarUtil {

    /**
     * Returns the frame index from the given seek bar progress value. In other words,
     * from the total number of frames, returns the frame number which should be displayed when
     * giving a progress value between 0-100. Value 100 means the last frame, value 0 the first frame.
     * The seek bar progress value must be a value between 0-100.
     *
     * @param seekBarProgress Progress between 0...100
     * @param totalFrames Total number of frames, must be greater than 0
     * @return Frame number, starting from zero. Rounds up to the closes frame. Returns -1 if given
     * parameters are invalid.
     */
    public static int getFrameIndexFromSeekBarValue(int seekBarProgress, int totalFrames) {

        if (totalFrames==0 || seekBarProgress<0 || seekBarProgress>100) {
            return -1;
        }

        int frameNumberToGo = 0;
        if (seekBarProgress!=0) {
            double frameNumberToGoDouble = (totalFrames-1)/(100.0/seekBarProgress);
            BigDecimal bd = new BigDecimal(frameNumberToGoDouble);
            BigDecimal rounded = bd.setScale(2, BigDecimal.ROUND_HALF_UP);
            frameNumberToGo = rounded.intValue();
        }

        return frameNumberToGo;

    }

    /**
     * Returns the seek bar value from the given frame number. In other words,
     * returns a progress value between 0...100 for the given frame index.
     * For example, if there are total of 10 frames and the current frame index is
     * 4 (5th frame), return 50.
     *
     * @param currentFrameIndex
     * @param totalFrames
     * @return
     */
    public static int getSeekBarValueFromFrameNumber(int currentFrameIndex, int totalFrames) {

        if (totalFrames==0 || currentFrameIndex>=totalFrames) {
            return -1;
        }

        if (totalFrames==1) {
            return 0;
        }

        int seekBarValue;
        double seekBarValueDouble = 100.0*(1.0*currentFrameIndex/(1.0*totalFrames-1));
        BigDecimal bd = new BigDecimal(seekBarValueDouble);
        BigDecimal rounded = bd.setScale(2, BigDecimal.ROUND_HALF_UP);
        seekBarValue = rounded.intValue();
        return seekBarValue;

    }

}




Java Source Code List

com.larvalabs.svgandroid.ParserHelper.java
com.larvalabs.svgandroid.SVGParseException.java
com.larvalabs.svgandroid.SVGParser.java
com.larvalabs.svgandroid.SVG.java
com.robobunny.SeekBarPreference.java
com.threefiftynice.android.preference.ListPreferenceMultiSelect.java
fi.testbed2.MainModule.java
fi.testbed2.android.activity.AbstractActivity.java
fi.testbed2.android.activity.AnimationActivity.java
fi.testbed2.android.activity.MainActivity.java
fi.testbed2.android.activity.ParsingActivity.java
fi.testbed2.android.activity.TestbedPreferenceActivity.java
fi.testbed2.android.app.Logger.java
fi.testbed2.android.app.MainApplication.java
fi.testbed2.android.task.AbstractTask.java
fi.testbed2.android.task.DownloadImagesTask.java
fi.testbed2.android.task.ParseAndInitTask.java
fi.testbed2.android.task.Task.java
fi.testbed2.android.task.exception.DownloadTaskException.java
fi.testbed2.android.task.exception.TaskCancelledException.java
fi.testbed2.android.ui.dialog.AlertDialogBuilder.java
fi.testbed2.android.ui.dialog.DialogBuilder.java
fi.testbed2.android.ui.svg.LocationMarkerSVG.java
fi.testbed2.android.ui.svg.MunicipalityMarkerSVG.java
fi.testbed2.android.ui.view.AnimationViewPlayer.java
fi.testbed2.android.ui.view.AnimationView.java
fi.testbed2.android.ui.view.MapScaleInfo.java
fi.testbed2.android.ui.view.util.AnimationViewBoundsUtil.java
fi.testbed2.android.ui.view.util.AnimationViewCanvasUtil.java
fi.testbed2.android.ui.view.util.AnimationViewScaleAndGestureUtil.java
fi.testbed2.domain.MapLocationGPS.java
fi.testbed2.domain.MapLocationXY.java
fi.testbed2.domain.Municipality.java
fi.testbed2.domain.TestbedMapImage.java
fi.testbed2.domain.TestbedParsedPage.java
fi.testbed2.robotium.MainActivityRobotiumTest.java
fi.testbed2.service.BitmapService.java
fi.testbed2.service.CoordinateService.java
fi.testbed2.service.HttpUrlService.java
fi.testbed2.service.LocationService.java
fi.testbed2.service.MunicipalityService.java
fi.testbed2.service.PageService.java
fi.testbed2.service.SettingsService.java
fi.testbed2.service.impl.ApacheHttpUrlService.java
fi.testbed2.service.impl.InlineMunicipalityService.java
fi.testbed2.service.impl.LruCacheBitmapService.java
fi.testbed2.service.impl.LruCachePageService.java
fi.testbed2.service.impl.MercatorCoordinateService.java
fi.testbed2.service.impl.PreferenceBasedLocationService.java
fi.testbed2.service.impl.SharedPreferenceSettingsService.java
fi.testbed2.util.ColorUtil.java
fi.testbed2.util.MathUtil.java
fi.testbed2.util.SeekBarUtil.java
fi.testbed2.util.TimeUtil.java
net.margaritov.preference.colorpicker.AlphaPatternDrawable.java
net.margaritov.preference.colorpicker.ColorPickerDialog.java
net.margaritov.preference.colorpicker.ColorPickerPanelView.java
net.margaritov.preference.colorpicker.ColorPickerPreference.java
net.margaritov.preference.colorpicker.ColorPickerView.java