Skip to content

Commit

Permalink
README update, minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gdelgadobliss committed Nov 7, 2019
1 parent a548180 commit 73cfc78
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 18 deletions.
File renamed without changes
Binary file added .imgs/rainbow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
60 changes: 52 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# CircularProgressView:
![header](sample1.png)
![header](.imgs/banner.png)

[![Build Status](https://travis-ci.org/GuilhE/android-circular-progress-view.svg?branch=master)](https://travis-ci.org/GuilhE/android-circular-progress-view)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/6cb896704b2648288ec8512a84277c5c)](https://www.codacy.com/app/GuilhE/android-circular-progress-view?utm_source=github.com&utm_medium=referral&utm_content=GuilhE/android-circular-progress-view&utm_campaign=badger) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-CircularProgressView-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/6152) [![Preview-Appetize.io](https://img.shields.io/badge/Preview-Appetize.io-brightgreen.svg?style=flat.svg)](https://appetize.io/app/7367zekaq62q5upw2c3y17wme4)
Expand Down Expand Up @@ -40,27 +40,71 @@ Attributes accepted in xml:
<attr name="progressBarThickness" format="dimension"/>
<attr name="progressBarColor" format="color"/>
<attr name="progressBarColorArray" format="reference"/>
<attr name="progressBarColorArrayPositions" format="reference"/>
<attr name="duplicateFirstColorInArray" format="boolean"/>
<attr name="progressBarRounded" format="boolean"/>
<attr name="backgroundColor" format="color"/>
<attr name="backgroundAlphaEnabled" format="boolean"/>
<attr name="reverse" format="boolean"/>
<attr name="duplicateFirstColorInArray" format="boolean"/>
</declare-styleable>
```
Example:
```xml
<com.github.guilhe.views.CircularProgressView
android:layout_width="100dp"
android:layout_height="100dp"
app:progress="60"
app:progressBarThickness="10dp"
app:progressBarColor="@android:color/holo_purple"/>
android:layout_width="100dp"
android:layout_height="100dp"
app:progress="60"
app:progressBarThickness="10dp"
app:progressBarColor="@android:color/holo_purple"/>
```

### @BindingAdatpers:
You can take advantage of [Binding Adapters (from Data Binding)](https://developer.android.com/topic/libraries/data-binding/binding-adapters#kotlin) to create some helper attributes, example:
```java
@BindingAdapter("progressAnimated")
fun setProgressAnimated(view: CircularProgressView, progress: Int) {
view.setProgress(progress, true);
}
```
```xml
<com.github.guilhe.views.CircularProgressView
app:progressAnimated="@{viewModel.progress}"/>
```

### About gradient as progress color:
For the given array of colors:
```xml
<array name="rainbow">
<item>#FFF60000</item>
<item>#FFFF8C00</item>
<item>#FFFFEE00</item>
<item>#FF4DE94C</item>
<item>#FF3783FF</item>
<item>#FF4815AA</item>
</array>
```
The default result will be (left):
![rainbow](.imgs/rainbow.png)
To achieve the result on the right side you have two options: either copy the first color and add it as last, or use the helper attribute/method that does that for you:
```xml
<attr name="duplicateFirstColorInArray" format="boolean"/>
```
```java
setProgressColors(@NonNull @ColorInt int[] colors, @Nullable float[] positions, boolean duplicateFirst)
```
Finally, you may also use the attribute `progressBarColorArrayPositions` to pass a `float[] positions`:
```xml
<array name="rainbow_positions">
<item type="dimen" format="float">.44</item>
...
</array>
```
__note:__ when using the helper function __and__ `positions[]`, you'll have to add an extra position for the last one being copied.

There are many methods to help you customize this `View` by code. For more details checkout the __sample app__, _javadocs_ or the code itself.

## Sample
<img src="sample.gif" alt="Sample" width="30%"/>
<img src=".imgs/sample.gif" alt="Sample" width="30%"/>

_Animation last update on April, 2019_

Expand Down
2 changes: 1 addition & 1 deletion circular-progress-view/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.3.3"
versionName "1.4.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,23 @@ private void init(Context context, AttributeSet attrs) {
mReverseEnabled = typedArray.getBoolean(R.styleable.CircularProgressView_reverse, false);

int colorsId = typedArray.getResourceId(R.styleable.CircularProgressView_progressBarColorArray, -1);
boolean duplicate = typedArray.getBoolean(R.styleable.CircularProgressView_duplicateFirstColorInArray, true);
boolean duplicate = typedArray.getBoolean(R.styleable.CircularProgressView_duplicateFirstColorInArray, false);
if (colorsId != -1) {
mShaderColors = typedArray.getResources().getIntArray(colorsId);
if (duplicate) {
mShaderColors = duplicateFirstColor(mShaderColors);
}
mInitShader = true;
}
int positionsId = typedArray.getResourceId(R.styleable.CircularProgressView_progressBarColorArrayPositions, -1);
if (positionsId != -1) {
TypedArray floats = typedArray.getResources().obtainTypedArray(positionsId);
mShaderPositions = new float[floats.length()];
for (int i = 0; i < floats.length(); i++) {
mShaderPositions[i] = floats.getFloat(i, 0f);
}
floats.recycle();
}
} finally {
typedArray.recycle();
}
Expand Down Expand Up @@ -282,7 +291,7 @@ public void setProgressColors(@NonNull @ColorInt int[] colors, @Nullable float[]
}

public void setProgressColors(@NonNull @ColorInt int[] colors, @Nullable float[] positions) {
setProgressColors(colors, positions, true);
setProgressColors(colors, positions, false);
}

private int[] duplicateFirstColor(@ColorInt @NonNull int[] colors) {
Expand Down
3 changes: 2 additions & 1 deletion circular-progress-view/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
<attr name="progressBarThickness" format="dimension"/>
<attr name="progressBarColor" format="color"/>
<attr name="progressBarColorArray" format="reference"/>
<attr name="progressBarColorArrayPositions" format="reference"/>
<attr name="duplicateFirstColorInArray" format="boolean"/>
<attr name="progressBarRounded" format="boolean"/>
<attr name="backgroundColor" format="color"/>
<attr name="backgroundAlphaEnabled" format="boolean"/>
<attr name="reverse" format="boolean"/>
<attr name="duplicateFirstColorInArray" format="boolean"/>
</declare-styleable>
</resources>
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ bintrayName = circular-progress-view

libraryName = CircularProgressView
libraryDescription = A fancy CircularProgressView
libraryVersion = 1.3.3
libraryVersion = 1.4.0

siteUrl = https://github.com/GuilhE/android-circular-progress-view
gitUrl = https://github.com/GuilhE/android-circular-progress-view.git
Expand Down
4 changes: 2 additions & 2 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "com.github.guilhe.cicularprogressview.sample"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 5
versionName "1.3.3"
versionCode 6
versionName "1.4.0"
}

dataBinding {
Expand Down
10 changes: 7 additions & 3 deletions sample/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
<color name="colorAccent">#FF4081</color>

<array name="rainbow">
<item>@android:color/holo_red_dark</item>
<item>@android:color/holo_green_dark</item>
<item>@android:color/holo_blue_dark</item>
<item>#FFF60000</item>
<item>#FFFF8C00</item>
<item>#FFFFEE00</item>
<item>#FF4DE94C</item>
<item>#FF3783FF</item>
<item>#FF4815AA</item>
<item>#FFF60000</item>
</array>
</resources>

0 comments on commit 73cfc78

Please sign in to comment.