From 0dea7a4b7bc0fbcc7a298646be839a490131f0a0 Mon Sep 17 00:00:00 2001 From: Anas Altair Date: Tue, 1 Nov 2016 11:40:41 +0200 Subject: [PATCH] new PointerSpeedometer --- .idea/dictionaries/my_pc.xml | 3 - .idea/inspectionProfiles/Project_Default.xml | 10 - .../inspectionProfiles/profiles_settings.xml | 7 - .idea/misc.xml | 16 + README.md | 43 +- app/src/main/AndroidManifest.xml | 3 +- .../anastr/speedview/DeluxeSpeedActivity.java | 4 +- .../github/anastr/speedview/MainActivity.java | 5 + .../anastr/speedview/PointerActivity.java | 55 +++ .../github/anastr/speedview/RayActivity.java | 15 +- app/src/main/res/layout/activity_main.xml | 7 + app/src/main/res/layout/activity_pointer.xml | 52 ++ app/src/main/res/values/styles.xml | 3 +- images/PointerSpeedometer.gif | Bin 0 -> 419132 bytes images/PointerSpeedometer.png | Bin 0 -> 26215 bytes images/new4.png | Bin 57713 -> 0 bytes speedviewlib/build.gradle | 6 +- .../speedviewlib/AwesomeSpeedometer.java | 37 +- .../anastr/speedviewlib/DeluxeSpeedView.java | 41 +- .../speedviewlib/PointerSpeedometer.java | 256 ++++++++++ .../anastr/speedviewlib/RaySpeedometer.java | 42 +- .../github/anastr/speedviewlib/SpeedView.java | 26 +- .../anastr/speedviewlib/Speedometer.java | 443 +++++++++++++----- .../util/OnSpeedChangeListener.java | 21 + speedviewlib/src/main/res/values/attrs.xml | 27 +- 25 files changed, 852 insertions(+), 270 deletions(-) delete mode 100644 .idea/dictionaries/my_pc.xml delete mode 100644 .idea/inspectionProfiles/Project_Default.xml delete mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 app/src/main/java/com/github/anastr/speedview/PointerActivity.java create mode 100644 app/src/main/res/layout/activity_pointer.xml create mode 100644 images/PointerSpeedometer.gif create mode 100644 images/PointerSpeedometer.png delete mode 100644 images/new4.png create mode 100644 speedviewlib/src/main/java/com/github/anastr/speedviewlib/PointerSpeedometer.java create mode 100644 speedviewlib/src/main/java/com/github/anastr/speedviewlib/util/OnSpeedChangeListener.java diff --git a/.idea/dictionaries/my_pc.xml b/.idea/dictionaries/my_pc.xml deleted file mode 100644 index 3fba4d5..0000000 --- a/.idea/dictionaries/my_pc.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index 480ac3b..0000000 --- a/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml deleted file mode 100644 index 3b31283..0000000 --- a/.idea/inspectionProfiles/profiles_settings.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 1dccf50..b983d57 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -27,6 +27,22 @@ + + + + + + + + + + + Android + + + + + diff --git a/README.md b/README.md index b5f50c9..a44ef19 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ Library Size ~ 12 Kb.
+ # Download @@ -21,7 +22,7 @@ Library Size ~ 12 Kb. ```gradle dependencies { - compile 'com.github.anastr:speedviewlib:1.0.8' + compile 'com.github.anastr:speedviewlib:1.0.9' } ``` @@ -32,13 +33,13 @@ for **maven** com.github.anastr speedviewlib - 1.0.8 + 1.0.9 pom ``` # Usage -we have 4 views : +we have 5 views : ## 1st SpeedView @@ -151,7 +152,7 @@ awesomeSpeedometer.setSpeedometerColor(Color.RED); -**add AwesomeSpeedometer to your layout** +**add RaySpeedometer to your layout** ```xml @@ -162,13 +163,34 @@ awesomeSpeedometer.setSpeedometerColor(Color.RED); ``` the same methods in SpeedView.
-special methods for AwesomeSpeedometer : +special methods for RaySpeedometer : ```java raySpeedometer.setDegreeBetweenMark(3); //def : 5 raySpeedometer.setMarkWidth(2); //def : 3dp raySpeedometer.setRayColor(Color.RED); ``` +## 5th PointerSpeedometer + + + +**add PointerSpeedometer to your layout** + +```xml + + + +``` +the same methods in SpeedView.
+special methods for PointerSpeedometer : +```java +pointerSpeedometer.setUnitTextSize(15); //def : 5dp +pointerSpeedometer.setPointerColor(Color.RED); +``` + # Attributes and also you can change everything in XML, see this Attributes for **all Speedometers** : @@ -222,13 +244,22 @@ app:markWidth="5dp" ``` +Attributes just for **PointerSpeedometer** : + +```xml + +app:speedometerColor="#ffb26b" +app:pointerColor="#ffff00" +app:unitTextSize="15dp" + +``` + ## Coming Soon ... i well try to draw this Speedometer. 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. - # LICENSE ``` diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c17f2ee..7f4987b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -19,7 +19,8 @@ - + + \ No newline at end of file diff --git a/app/src/main/java/com/github/anastr/speedview/DeluxeSpeedActivity.java b/app/src/main/java/com/github/anastr/speedview/DeluxeSpeedActivity.java index 594a02d..3c22a6f 100644 --- a/app/src/main/java/com/github/anastr/speedview/DeluxeSpeedActivity.java +++ b/app/src/main/java/com/github/anastr/speedview/DeluxeSpeedActivity.java @@ -11,6 +11,8 @@ import com.github.anastr.speedviewlib.DeluxeSpeedView; +import java.util.Locale; + public class DeluxeSpeedActivity extends AppCompatActivity { DeluxeSpeedView deluxeSpeedView; @@ -55,7 +57,7 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { - textSpeed.setText(String.format("%d", progress)); + textSpeed.setText(String.format(Locale.getDefault(), "%d", progress)); } @Override diff --git a/app/src/main/java/com/github/anastr/speedview/MainActivity.java b/app/src/main/java/com/github/anastr/speedview/MainActivity.java index 23c8889..0aeeb82 100644 --- a/app/src/main/java/com/github/anastr/speedview/MainActivity.java +++ b/app/src/main/java/com/github/anastr/speedview/MainActivity.java @@ -32,4 +32,9 @@ public void openRaySpeedometerActivity(View view) { Intent intent = new Intent (MainActivity.this, RayActivity.class); startActivity(intent); } + + public void openPointerSpeedometerActivity(View view) { + Intent intent = new Intent (MainActivity.this, PointerActivity.class); + startActivity(intent); + } } diff --git a/app/src/main/java/com/github/anastr/speedview/PointerActivity.java b/app/src/main/java/com/github/anastr/speedview/PointerActivity.java new file mode 100644 index 0000000..691de92 --- /dev/null +++ b/app/src/main/java/com/github/anastr/speedview/PointerActivity.java @@ -0,0 +1,55 @@ +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.PointerSpeedometer; + +import java.util.Locale; + +public class PointerActivity extends AppCompatActivity { + + PointerSpeedometer pointerSpeedometer; + SeekBar seekBarSpeed; + Button ok; + TextView textSpeed; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_pointer); + + pointerSpeedometer = (PointerSpeedometer) findViewById(R.id.pointerSpeedometer); + seekBarSpeed = (SeekBar) findViewById(R.id.seekBarSpeed); + ok = (Button) findViewById(R.id.ok); + textSpeed = (TextView) findViewById(R.id.textSpeed); + + ok.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + pointerSpeedometer.speedTo(seekBarSpeed.getProgress()); + } + }); + + seekBarSpeed.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + textSpeed.setText(String.format(Locale.getDefault(), "%d", progress)); + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + + } + }); + } +} diff --git a/app/src/main/java/com/github/anastr/speedview/RayActivity.java b/app/src/main/java/com/github/anastr/speedview/RayActivity.java index d53d332..6f7fb63 100644 --- a/app/src/main/java/com/github/anastr/speedview/RayActivity.java +++ b/app/src/main/java/com/github/anastr/speedview/RayActivity.java @@ -9,6 +9,8 @@ import com.github.anastr.speedviewlib.RaySpeedometer; +import java.util.Locale; + public class RayActivity extends AppCompatActivity { RaySpeedometer raySpeedometer; @@ -40,7 +42,7 @@ public void onClick(View v) { seekBarSpeed.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { - textSpeed.setText(String.format("%d", progress)); + textSpeed.setText(String.format(Locale.getDefault(), "%d", progress)); } @Override @@ -57,7 +59,7 @@ 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)); + textDegree.setText(String.format(Locale.getDefault(), "%d", progress)); raySpeedometer.setDegreeBetweenMark(progress); } @@ -73,8 +75,9 @@ 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)); + textWidth.setText(String.format(Locale.getDefault(), "%ddp", progress)); + + raySpeedometer.setMarkWidth((int) raySpeedometer.dpTOpx(progress)); } @Override @@ -86,8 +89,4 @@ public void onStopTrackingTouch(SeekBar seekBar) { } }); } - - float dpTOpx(float dp) { - return dp * getResources().getDisplayMetrics().density; - } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 9fd1c88..76fccbd 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -38,4 +38,11 @@ android:text="Ray Speedometer View" style="@style/Base.Widget.AppCompat.Button.Colored"/> +