Copyright (c) 2014, Ford Motor Company
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are m...
If you think the Android project sdl_tester_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 com.livio.sdl.viewhelpers;
//www.java2s.com/**
* Performs math operations commonly used with SeekBar views. Performs calculations
* to translate a progress value to a real-world value and vice-versa.
*
* @author Mike Burke
*
*/publicclass SeekBarCalculator {
privatestaticfinalint PROGRESS_MIN = 0; // standard Android seekbars start from 0
privateint min, max;
privatefloat divisor;
public SeekBarCalculator(int min, int max){
this(min, max, 1.0f);
}
public SeekBarCalculator(int min, int max, float divisor) {
this.min = min;
this.max = max;
this.divisor = divisor;
}
publicint getMinValue() {
return min;
}
publicvoid setMinValue(int min){
this.min = min;
}
publicint getMaxValue() {
return max;
}
publicvoid setMaxValue(int max){
this.max = max;
}
publicfloat getDivisor() {
return divisor;
}
publicvoid setDivisor(float divisor){
this.divisor = divisor;
}
/**
* Determines the maximum progress value based on the min and max values.
*
* @return The max value of the progress bar
*/publicint getMaxProgress(){
return (max - min);
}
/**
* Determines the minimum progress value. A typical Android SeekBar, this value is always 0.
*
* @return The min value of the progress bar
*/publicint getMinProgress(){
return PROGRESS_MIN;
}
/**
* Calculates the SeekBar progress value for the input real-world value.
*
* @param value Real-world value to calculate progress for
* @return The progress value of the input real-world value
*/publicint calculateProgress(float value){
value *= divisor;
if(value < getMinValue() || value > getMaxValue()){
thrownew IllegalArgumentException("Value out of seekbar range");
}
int result = (int) (value - getMinValue());
return result;
}
/**
* Calculates the real-world value for the input progress value.
*
* @param progress Progress value to calculate real-world value for
* @return The real-world value of the input progress value
*/publicfloat calculateValue(int progress){
if(progress < getMinProgress() || progress > getMaxProgress()){
thrownew IllegalArgumentException("Progress out of seekbar range");
}
float result = (progress + getMinValue()) / divisor;
return result;
}
}