Skip to content

Commit

Permalink
Merge pull request #102 from anastr/V1.3.0
Browse files Browse the repository at this point in the history
V1.3.0
  • Loading branch information
anastr authored Sep 21, 2018
2 parents 8242045 + d3c568d commit 5887bd4
Show file tree
Hide file tree
Showing 23 changed files with 165 additions and 50 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Library Size just ~ 51 KB.
```gradle
dependencies {
compile 'com.github.anastr:speedviewlib:1.2.0'
implementation 'com.github.anastr:speedviewlib:1.3.0'
}
```
Expand All @@ -38,7 +38,7 @@ for **maven**
<dependency>
<groupId>com.github.anastr</groupId>
<artifactId>speedviewlib</artifactId>
<version>1.2.0</version>
<version>1.3.0</version>
<type>pom</type>
</dependency>
```
Expand Down
13 changes: 8 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 27
buildToolsVersion '27.0.0'
compileSdkVersion 28
buildToolsVersion '28.0.2'

defaultConfig {
applicationId "com.github.anastr.speedview"
minSdkVersion 14
targetSdkVersion 27
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
Expand All @@ -23,6 +23,9 @@ android {
}

dependencies {
compile 'com.android.support:appcompat-v7:27.+'
compile project(':speedviewlib')
implementation 'com.android.support:appcompat-v7:28.+'
implementation 'com.android.support:cardview-v7:28.+'
implementation 'com.android.support:recyclerview-v7:28.+'
implementation project(':speedviewlib')
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
}
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<activity android:name=".lineargauge.ProgressiveGaugeActivity" />
<activity android:name=".lineargauge.ImageLinearGaugeActivity" />
<activity android:name=".TickActivity" />
<activity android:name=".RecyclerActivity"></activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ protected void onCreate(Bundle savedInstanceState) {
"Work With Start and End Degree",
"Work With Modes",
"Speed Text Position",
"Work With Ticks"
"Work With Ticks",
"SpeedView with Recycler"
};

ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
Expand Down Expand Up @@ -98,6 +99,9 @@ public void onItemClick(AdapterView<?> adapterView, View view, int position, lon
case 15:
intent.setClass(MainActivity.this, TickActivity.class);
break;
case 16:
intent.setClass(MainActivity.this, RecyclerActivity.class);
break;
}
startActivity(intent);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.github.anastr.speedview;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.github.anastr.speedviewlib.Speedometer;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class RecyclerActivity extends AppCompatActivity {

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

RecyclerView recyclerView = findViewById(R.id.recyclerView);
GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 2);
recyclerView.setLayoutManager(gridLayoutManager);
recyclerView.setHasFixedSize(true);
List<Integer> speeds = new ArrayList<>();
for (int i=0; i<100; i++)
speeds.add(new Random().nextInt(99)+1);
recyclerView.setAdapter(new RVAdapter(speeds));
}

public class RVAdapter extends RecyclerView.Adapter<RVAdapter.MyViewHolder> {

List<Integer> speeds;

RVAdapter(List<Integer> speeds) {
this.speeds = speeds;
}

@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.card_view, viewGroup, false);
return new MyViewHolder(v);
}

@Override
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
holder.speedometer.speedTo(speeds.get(position));
}

@Override
public int getItemCount() {
return speeds.size();
}

class MyViewHolder extends RecyclerView.ViewHolder{

Speedometer speedometer;

MyViewHolder(View itemView) {
super(itemView);
speedometer = itemView.findViewById(R.id.speedometer);
}
}
}
}
15 changes: 15 additions & 0 deletions app/src/main/res/layout/activity_recycler.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
tools:context=".RecyclerActivity">

<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent" />

</FrameLayout>
17 changes: 17 additions & 0 deletions app/src/main/res/layout/card_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:cardCornerRadius="8dp"
app:cardBackgroundColor="#e2e2e2">

<com.github.anastr.speedviewlib.SpeedView
android:id="@+id/speedometer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:layout_gravity="center"/>

</android.support.v7.widget.CardView>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
classpath "com.github.dcendents:android-maven-gradle-plugin:1.4.1"

Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Nov 01 17:22:05 EET 2017
#Wed Sep 19 14:40:40 EEST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
Binary file modified images/AwesomeSpeedometer.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/DeluxeSpeedView.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/ImageLinearGauge.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/ImageLinearGauge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/PointerSpeedometer.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/SpeedView.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/SpeedView2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/SpeedView4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/usage/WorkWithNote.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions speedviewlib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ apply plugin: 'com.jfrog.bintray'
apply plugin: 'com.github.dcendents.android-maven'

android {
compileSdkVersion 27
buildToolsVersion '27.0.0'
compileSdkVersion 28
buildToolsVersion '28.0.2'

defaultConfig {
minSdkVersion 8
targetSdkVersion 27
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
Expand Down Expand Up @@ -49,7 +49,7 @@ Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())

group = 'com.github.anastr'
version = '1.2.0'
version = '1.3.0'

bintray {
user = properties.getProperty("bintray.user")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,12 @@ public abstract class Gauge extends View {

/** draw speed text as <b>integer</b> .*/
public static final byte INTEGER_FORMAT = 0;
/** draw speed text as <b>float</b>. */
/** draw speed text as <b>.1 float</b>. */
public static final byte FLOAT_FORMAT = 1;
private byte speedTextFormat = FLOAT_FORMAT;
private byte tickTextFormat = INTEGER_FORMAT;
/** number of decimal places */
private int speedTextFormat = FLOAT_FORMAT;
/** number of decimal places */
private int tickTextFormat = INTEGER_FORMAT;

public Gauge(Context context) {
this(context, null);
Expand Down Expand Up @@ -205,10 +207,10 @@ private void initAttributeSet(Context context, AttributeSet attrs) {
int position = a.getInt(R.styleable.Gauge_sv_speedTextPosition, -1);
if (position != -1)
setSpeedTextPosition(Position.values()[position]);
byte speedFormat = (byte) a.getInt(R.styleable.Gauge_sv_speedTextFormat, -1);
int speedFormat = a.getInt(R.styleable.Gauge_sv_speedTextFormat, -1);
if (speedFormat != -1)
setSpeedTextFormat(speedFormat);
byte tickFormat = (byte) a.getInt(R.styleable.Gauge_sv_tickTextFormat, -1);
int tickFormat = a.getInt(R.styleable.Gauge_sv_tickTextFormat, -1);
if (tickFormat != -1)
setTickTextFormat(tickFormat);
a.recycle();
Expand Down Expand Up @@ -708,6 +710,8 @@ private float getSpeedValue(float percentSpeed) {
protected void onAttachedToWindow() {
super.onAttachedToWindow();
attachedToWindow = true;
updateBackgroundBitmap();
invalidate();
}

@Override
Expand Down Expand Up @@ -772,15 +776,16 @@ public void setTrembleData (float trembleDegree, int trembleDuration) {
/**
* @return speed text's format, [{@link #INTEGER_FORMAT} or {@link #FLOAT_FORMAT}].
*/
public byte getSpeedTextFormat() {
public int getSpeedTextFormat() {
return speedTextFormat;
}

/**
* change speed text's format [{@link #INTEGER_FORMAT} or {@link #FLOAT_FORMAT}].
* change speed text's format [{@link #INTEGER_FORMAT} or {@link #FLOAT_FORMAT}]
* or number of decimal places you want.
* @param speedTextFormat new format.
*/
public void setSpeedTextFormat(byte speedTextFormat) {
public void setSpeedTextFormat(int speedTextFormat) {
this.speedTextFormat = speedTextFormat;
if (!attachedToWindow)
return;
Expand All @@ -791,15 +796,16 @@ public void setSpeedTextFormat(byte speedTextFormat) {
/**
* @return tick text's format, [{@link #INTEGER_FORMAT} or {@link #FLOAT_FORMAT}].
*/
public byte getTickTextFormat() {
public int getTickTextFormat() {
return tickTextFormat;
}

/**
* change tick text's format [{@link #INTEGER_FORMAT} or {@link #FLOAT_FORMAT}].
* change tick text's format [{@link #INTEGER_FORMAT} or {@link #FLOAT_FORMAT}]
* or number of decimal places you want.
* @param tickTextFormat new format.
*/
public void setTickTextFormat(byte tickTextFormat) {
public void setTickTextFormat(int tickTextFormat) {
this.tickTextFormat = tickTextFormat;
if (!attachedToWindow)
return;
Expand All @@ -812,26 +818,23 @@ public void setTickTextFormat(byte tickTextFormat) {
* @return current speed to draw.
*/
protected String getSpeedText() {
return speedTextFormat == FLOAT_FORMAT ? String.format(locale, "%.1f", currentSpeed)
: String.format(locale, "%d", currentIntSpeed);
return String.format(locale, "%."+speedTextFormat+"f", currentSpeed);
}

/**
* get Max speed as string to <b>Draw</b>.
* @return Max speed to draw.
*/
protected String getMaxSpeedText() {
return tickTextFormat == FLOAT_FORMAT ? String.format(locale, "%.1f", maxSpeed)
: String.format(locale, "%d", (int) maxSpeed);
return String.format(locale, "%."+tickTextFormat+"f", maxSpeed);
}

/**
* get Min speed as string to <b>Draw</b>.
* @return Min speed to draw.
*/
protected String getMinSpeedText() {
return tickTextFormat == FLOAT_FORMAT ? String.format(locale, "%.1f", minSpeed)
: String.format(locale, "%d", (int) minSpeed);
return String.format(locale, "%."+tickTextFormat+"f", minSpeed);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ protected void onDraw(Canvas canvas) {
drawIndicator(canvas);

int c = getCenterCircleColor();
circlePaint.setColor(Color.argb(120, Color.red(c), Color.green(c), Color.blue(c)));
circlePaint.setColor(Color.argb((int)(Color.alpha(c)*.5f), Color.red(c), Color.green(c), Color.blue(c)));
canvas.drawCircle(getSize() *.5f, getSize() *.5f, getWidthPa()/14f, circlePaint);
circlePaint.setColor(c);
canvas.drawCircle(getSize() *.5f, getSize() *.5f, getWidthPa()/22f, circlePaint);
Expand Down
Loading

0 comments on commit 5887bd4

Please sign in to comment.