-
-
Notifications
You must be signed in to change notification settings - Fork 325
0. Get Started
to start work with SpeedView, add the Library to dependencies to download it, see how you can do that in SpeedView - Download.
first add one of Speedometers to your xml Layout
"choose one of speedometer
Here" like so:
<com.github.anastr.speedviewlib.SpeedView
android:id="@+id/speedometer"
android:layout_width="250dp"
android:layout_height="wrap_content" />
All Speedometers extends Speedometer
class ⚡.
So, we can define any Speedometer
object from your Activity
, Fragment
or anywhere by simple line:
Speedometer speedometer = (Speedometer) findViewById(R.id.speedometer);
or maybe you want to create programmatically and add it to layout:
// AwesomeSpeedometer example:
AwesomeSpeedometer speedometer = new AwesomeSpeedometer (this);
// define ViewGroup, and add AwesomeSpeedometer to it.
LinearLayout layout = (LinearLayout) findViewById(R.id.linear_layout);
layout.add(speedometer);
rotate indicator to correct value(speed), Easy ! by simple line:
// move to 50 Km/s
speedometer.speedTo(50);
// or move to 50 Km/s with Duration = 4 sec
speedometer.speedTo(50, 4000);
Or maybe you don't know the speed to move indicator, so you can move indicator to percent value, for example lets move it to 30%
by this method :
// move indicator to percent value (30%)
speedometer.speedPercentTo(30);
main and max value, the number in speedTo(int)
method should be between [minSpeed
, maxSpeed
] if you put number bigger than maxSpeed
indicator will move to maxSpeed
..., by default minSpeed=0
and maxSpeed=100
, you can change these values simply in XML:
app:minSpeed="50"
app:maxSpeed="125"
or in code:
speedometer.setMinSpeed(-30);
speedometer.setMaxSpeed(30);
as you can see, Values can be Negative.
you can get the speed any time by many ways, use getCorrectSpeed()
or getCorrectIntSpeed()
methods to know what correct speed is now, or use the getSpeed()
method to get last speed which you set by speedTo()
, speedPercentTo()
methods or if you stop speedometer By stop()
method.
// use getCorrectSpeed() method (recommend)
Log.e("speed know", speedometer.getCorrectSpeed()+"");
// to handle speed value, you can use getCorrectIntSpeed() method.
we have OnSpeedChangeListener:
A callback that notifies clients when the speed has been changed (just when speed change in integer).
example:
speedometer.setOnSpeedChangeListener(new OnSpeedChangeListener() {
@Override
public void onSpeedChange(Speedometer speedometer, boolean isSpeedUp, boolean isByTremble) {
float speed = speedometer.getCorrectSpeed();
Log.e("Speedometer Listener", speed + "");
}
});
it have three parameter:
- speedometer: the speedometer who change.
- isSpeedUp: if speed increase.
- isByTremble: true if speed has changed by Tremble.
and OnSectionChangeListener:
A callback that notifies clients when the the indicator move to new section, what is sections ?.
example:
speedometer.setOnSectionChangeListener(new OnSectionChangeListener() {
@Override
public void onSectionChangeListener(byte oldSection, byte newSection) {
if (newSection == Speedometer.HIGH_SECTION)
Toast.makeText(getApplicationContext(), "Slow Down !!", Toast.LENGTH_LONG).show();
}
});
Tremble is an option to increases and decreases speed value around correct speed, which means that indicator will move to add some reality to speedometer.
to stop it, just use app:withTremble="false"
Attribute, or speedometer.setWithTremble(false);
method.
you can also change trembleDegree and trembleDuration by their methods or setTrembleData () method.
Go to Style page to make speedometer
more beautiful.
now you can jump to Advanced Usage.
if you have any idea, image, template please open new issue and give me the image , and i well try to add it to the Library, it must be possible to drawn, if you like this library you can support it.