Skip to content

Commit

Permalink
new RaySpeedometer
Browse files Browse the repository at this point in the history
  • Loading branch information
anastr committed Sep 7, 2016
1 parent ee22914 commit 9157a70
Show file tree
Hide file tree
Showing 5 changed files with 514 additions and 7 deletions.
93 changes: 93 additions & 0 deletions app/src/main/java/com/github/anastr/speedview/RayActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package com.github.anastr.speedview;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.TextView;

import com.github.anastr.speedviewlib.RaySpeedometer;

public class RayActivity extends AppCompatActivity {

RaySpeedometer raySpeedometer;
SeekBar seekBarSpeed, seekBarDegree, seekBarWidth;
Button ok;
TextView textSpeed, textDegree, textWidth;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ray);

raySpeedometer = (RaySpeedometer) findViewById(R.id.raySpeedometer);
seekBarSpeed = (SeekBar) findViewById(R.id.seekBarSpeed);
seekBarDegree = (SeekBar) findViewById(R.id.seekBarDegree);
seekBarWidth = (SeekBar) findViewById(R.id.seekBarWidth);
ok = (Button) findViewById(R.id.ok);
textSpeed = (TextView) findViewById(R.id.textSpeed);
textDegree = (TextView) findViewById(R.id.textDegree);
textWidth = (TextView) findViewById(R.id.textWidth);

ok.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
raySpeedometer.speedTo(seekBarSpeed.getProgress());
}
});

seekBarSpeed.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
textSpeed.setText(String.format("%d", progress));
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {

}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {

}
});

seekBarDegree.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
textDegree.setText(String.format("%d", progress));
raySpeedometer.setDegreeBetweenMark(progress);
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});

seekBarWidth.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
textWidth.setText(String.format("%d", progress) + "dp");
raySpeedometer.setMarkWidth((int) dpTOpx(progress));
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
}

float dpTOpx(float dp) {
return dp * getResources().getDisplayMetrics().density;
}
}
7 changes: 7 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,11 @@
android:text="Awesome Speedometer View"
style="@style/Base.Widget.AppCompat.Button.Colored"/>

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="openRaySpeedometerActivity"
android:text="Ray Speedometer View"
style="@style/Base.Widget.AppCompat.Button.Colored"/>

</LinearLayout>
113 changes: 113 additions & 0 deletions app/src/main/res/layout/activity_ray.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context="com.github.anastr.speedview.RayActivity">

<com.github.anastr.speedviewlib.RaySpeedometer
android:id="@+id/raySpeedometer"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
app:backgroundCircleColor="#f0ff4c"
app:markColor="#414141"
app:textColor="#000"
app:rayColor="#d8ff0000"
app:lowSpeedColor="#3ada00"
app:mediumSpeedColor="#ff7700"
app:highSpeedColor="#ce0000"
app:degreeBetweenMark="5"
app:markWidth="3dp"/>

<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<SeekBar
android:id="@+id/seekBarSpeed"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:max="100"
android:layout_gravity="center_vertical"/>

<TextView
android:id="@+id/textSpeed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
tools:text="50" />

<Button
android:id="@+id/ok"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ok" />
</LinearLayout>

<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">

<SeekBar
android:id="@+id/seekBarDegree"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:max="20"
android:layout_gravity="center_vertical"/>

<TextView
android:id="@+id/textDegree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
tools:text="50" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text=" Degree" />
</LinearLayout>

<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">

<SeekBar
android:id="@+id/seekBarWidth"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:max="10"
android:layout_gravity="center_vertical"/>

<TextView
android:id="@+id/textWidth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
tools:text="50dp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text=" MarkWidth" />
</LinearLayout>

</LinearLayout>
Loading

0 comments on commit 9157a70

Please sign in to comment.